X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=rc6.c;h=9145c9d18d8c135da880c6ef4ae3aaf810fd610a;hb=0f66a12e93ed43904c30810ac33c79c87befafe7;hp=29889a20235573a20861cf100f2e177aa634638a;hpb=083d7d2a1375304e61c08048426a80e2cc41c55d;p=avr-crypto-lib.git
diff --git a/rc6.c b/rc6.c
index 29889a2..9145c9d 100644
--- a/rc6.c
+++ b/rc6.c
@@ -1,3 +1,21 @@
+/* rc6.c */
+/*
+ This file is part of the Crypto-avr-lib/microcrypt-lib.
+ Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
/*
* File: rc6.c
* Author: Daniel Otte
@@ -10,30 +28,30 @@
* THIS ONLY WORKS FOR LITTEL ENDIAN!!!
*/
- #include
- #include
- #include "rc6.h"
- #include "config.h"
+#include
+#include
+#include "rc6.h"
+#include "config.h"
- #define P32 0xB7E15163 /* e -2 */
- #define Q32 0x9E3779B9 /* Golden Ratio -1 */
+#define P32 0xB7E15163 /* e -2 */
+#define Q32 0x9E3779B9 /* Golden Ratio -1 */
uint32_t rotl32(uint32_t a, uint8_t n){
n &= 0x1f; /* higher rotates would not bring anything */
return ( (a<>(32-n)) );
- }
+}
uint32_t rotr32(uint32_t a, uint8_t n){
n &= 0x1f; /* higher rotates would not bring anything */
return ( (a>>n)| (a<<(32-n)) );
- }
+}
- uint8_t rc6_init(rc6_ctx_t *s,void* key, uint16_t keylength){
- return rc6_initl(s, key, keylength, 20);
- }
+uint8_t rc6_init(void* key, uint16_t keylength_b, rc6_ctx_t *s){
+ return rc6_initl(key, keylength_b, 20, s);
+}
- uint8_t rc6_initl(rc6_ctx_t *s,void* key, uint16_t keylength, uint8_t rounds){
+uint8_t rc6_initl(void* key, uint16_t keylength_b, uint8_t rounds, rc6_ctx_t *s){
uint8_t i,j;
uint16_t v,p,c;
uint32_t a,b, l=0;
@@ -44,11 +62,11 @@ uint32_t rotr32(uint32_t a, uint8_t n){
s->rounds=rounds;
- c = keylength/32;
- if (keylength%32){
+ c = keylength_b/32;
+ if (keylength_b%32){
++c;
- j=(keylength%32)/8;
- if(keylength%8)
+ j=(keylength_b%32)/8;
+ if(keylength_b%8)
++j;
for (i=0; iS);
- }
+}
- #define LG_W 5
- #define A (((uint32_t*)block)[0])
- #define B (((uint32_t*)block)[1])
- #define C (((uint32_t*)block)[2])
- #define D (((uint32_t*)block)[3])
+#define LG_W 5
+#define A (((uint32_t*)block)[0])
+#define B (((uint32_t*)block)[1])
+#define C (((uint32_t*)block)[2])
+#define D (((uint32_t*)block)[3])
- void rc6_enc(rc6_ctx_t *s, void* block){
+void rc6_enc(void* block, rc6_ctx_t *s){
uint8_t i;
uint32_t t,u,x; /* greetings to Linux? */
B += s->S[0];
@@ -104,10 +122,9 @@ uint32_t rotr32(uint32_t a, uint8_t n){
}
A += s->S[2*s->rounds+2];
C += s->S[2*s->rounds+3];
- }
+}
- void rc6_dec(rc6_ctx_t *s, void* block)
- {
+void rc6_dec(void* block, rc6_ctx_t *s){
uint8_t i;
uint32_t t,u,x; /* greetings to Linux? */
@@ -127,5 +144,5 @@ uint32_t rotr32(uint32_t a, uint8_t n){
}
D -= s->S[1];
B -= s->S[0];
- }
+}