]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - arcfour.c
renaming to AVR-Crypto-Lib
[avr-crypto-lib.git] / arcfour.c
index 13fb159e7aff4e559e69e91327935e2feb93aca9..bc9a6dd0cbe7a4127ac686a96eddf133e15f0ad4 100644 (file)
--- a/arcfour.c
+++ b/arcfour.c
@@ -1,6 +1,6 @@
 /* arcfour.c */
 /*
-    This file is part of the Crypto-avr-lib/microcrypt-lib.
+    This file is part of the 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
     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-/* 
+/*
  * File:        arcfour.c
  * Author:      Daniel Otte
  * email:       daniel.otte@rub.de
  * Date:        2006-06-07
  * License:     GPLv3 or later
  * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
- * 
+ *
  */
+
 #include <stdint.h>
 #include "arcfour.h"
 
  * length is length of key in bytes!
  */
 
-void arcfour_init(arcfour_ctx_t *ctx, void *key, uint8_t length_B){
+void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx){
        uint8_t t;
-       unsigned x,y=0;
+       uint16_t x,y=0;
        for(x=0; x<= 255; ++x)
                ctx->s[x]=x;
-       
+
        for(x=0; x<= 255; ++x){
                y += ctx->s[x] + ((uint8_t*)key)[x % length_B];
                y &= 0xff;
+               /* ctx->s[y] <--> ctx->s[x] */
                t = ctx->s[y];
                ctx->s[y] = ctx->s[x];
                ctx->s[x] = t;
-       }       
+       }
        ctx->i = ctx->j = 0;
 }
 
@@ -53,6 +54,7 @@ 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;