X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=inline;f=serpent.c;h=8056eb41d03e1b9623d026e30d2b48db8548e1a7;hb=11a70cc550260f2f35c6e0d106bf38c3e97e5720;hp=91e5158f38941d2b4959478730e33195c9e06824;hpb=158bb85c89631984291c93a9217ca84345349a46;p=avr-crypto-lib.git
diff --git a/serpent.c b/serpent.c
index 91e5158..8056eb4 100644
--- a/serpent.c
+++ b/serpent.c
@@ -1,3 +1,21 @@
+/* serpent.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 .
+*/
/* serpent.c
* a bitsliced implementation of the serpent cipher for avr microcontrollers
* author: Daniel Otte
@@ -8,21 +26,12 @@
#include
#include /* memset() */
#include
+#include "memxor.h"
#include "serpent.h"
#include "serpent-sboxes.h"
/******************************************************************************/
-void memxor(void * dest, void * src, uint8_t size){
- while(size--){
- *((uint8_t*)dest) ^= *((uint8_t*)src);
- dest = (uint8_t*)dest +1;
- src = (uint8_t*)src +1;
- }
-}
-
-/******************************************************************************/
-
uint32_t rotl32(uint32_t a, uint8_t n){
return ((a<>(32-n)));
}
@@ -74,10 +83,10 @@ static uint32_t gen_w(uint32_t * b, uint8_t i){
}
/* key must be 256bit (32 byte) large! */
-void serpent_genctx(void * key, uint8_t keysize, serpent_ctx_t * ctx){
+void serpent_init(const void* key, uint16_t keysize, serpent_ctx_t* ctx){
uint32_t buffer[8];
uint8_t i,j;
- if(keysize){
+ if(keysize<256){
/* keysize is less than 256 bit, padding needed */
memset(buffer, 0, 32);
memcpy(buffer, key, (keysize+7)/8);
@@ -99,7 +108,7 @@ void serpent_genctx(void * key, uint8_t keysize, serpent_ctx_t * ctx){
}
-void serpent_enc(void* buffer, serpent_ctx_t * ctx){
+void serpent_enc(void* buffer, const serpent_ctx_t* ctx){
uint8_t i;
for(i=0; i<31; ++i){
memxor((uint8_t*)buffer, ctx->k[i], 16);
@@ -112,7 +121,7 @@ void serpent_enc(void* buffer, serpent_ctx_t * ctx){
memxor((uint8_t*)buffer, ctx->k[i], 16);
}
-void serpent_dec(void* buffer, serpent_ctx_t * ctx){
+void serpent_dec(void* buffer, const serpent_ctx_t* ctx){
int8_t i=32;
memxor((uint8_t*)buffer, ctx->k[i], 16);