X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=arcfour%2Farcfour.c;h=3f155a597e18803d8523e992553f5d93fd6bc41a;hb=f63427e84c047aafe16f6ab3b5452d4d2993241d;hp=ba66c165dd44e89e2d5691b2c3b0414fbe3b1d9f;hpb=701cee0d98aab48dd3192c8cc7c77eb42581bc56;p=avr-crypto-lib.git
diff --git a/arcfour/arcfour.c b/arcfour/arcfour.c
index ba66c16..3f155a5 100644
--- a/arcfour/arcfour.c
+++ b/arcfour/arcfour.c
@@ -1,21 +1,21 @@
/* arcfour.c */
/*
- This file is part of the AVR-Crypto-Lib.
- Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
+ This file is part of the AVR-Crypto-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 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.
+ 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 .
-*/
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
/*
* File: arcfour.c
* Author: Daniel Otte
@@ -33,40 +33,42 @@
* length is length of key in bytes!
*/
-void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx){
- uint8_t t;
- const uint8_t length_B = length_b/8;
- uint8_t nidx = length_B;
- uint8_t x=0,y=0;
- const uint8_t *kptr = (const uint8_t*)key;
- do{
- ctx->s[x]=x;
- }while((uint8_t)++x);
+void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx)
+{
+ uint8_t t;
+ const uint8_t length_B = length_b / 8;
+ uint8_t nidx = length_B;
+ uint8_t x = 0, y = 0;
+ const uint8_t *kptr = (const uint8_t*) key;
+ do {
+ ctx->s[x] = x;
+ } while ((uint8_t) ++x);
- do{
- y += ctx->s[x] + *kptr++;
- if(!--nidx){
- kptr = (const uint8_t*)key;
- nidx = length_B;
- }
- y &= 0xff;
- /* ctx->s[y] <--> ctx->s[x] */
- t = ctx->s[y];
- ctx->s[y] = ctx->s[x];
- ctx->s[x] = t;
- }while((uint8_t)++x);
+ do {
+ y += ctx->s[x] + *kptr++;
+ if (!--nidx) {
+ kptr = (const uint8_t*) key;
+ nidx = length_B;
+ }
+ y &= 0xff;
+ /* ctx->s[y] <--> ctx->s[x] */
+ t = ctx->s[y];
+ ctx->s[y] = ctx->s[x];
+ ctx->s[x] = t;
+ } while ((uint8_t) ++x);
- ctx->i = ctx->j = 0;
+ ctx->i = ctx->j = 0;
}
-uint8_t arcfour_gen(arcfour_ctx_t *ctx){
- uint8_t t;
- ctx->i++;
- ctx->j += ctx->s[ctx->i];
- /* ctx->s[i] <--> ctx->s[j] */
- t = ctx->s[ctx->j];
- ctx->s[ctx->j] = ctx->s[ctx->i];
- ctx->s[ctx->i] = t;
- return ctx->s[(ctx->s[ctx->j] + ctx->s[ctx->i]) & 0xff];
+uint8_t arcfour_gen(arcfour_ctx_t *ctx)
+{
+ uint8_t t;
+ ctx->i++;
+ ctx->j += ctx->s[ctx->i];
+ /* ctx->s[i] <--> ctx->s[j] */
+ t = ctx->s[ctx->j];
+ ctx->s[ctx->j] = ctx->s[ctx->i];
+ ctx->s[ctx->i] = t;
+ return ctx->s[(ctx->s[ctx->j] + ctx->s[ctx->i]) & 0xff];
}