* Author: Daniel Otte
* Date: 2006-06-07
* License: GPL
- * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
- *
+ * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
*/
+/*
+ * \file arcfour.h
+ * \author Daniel Otte
+ * \date 2006-06-07
+ * \par License
+ * GPL
+ * \brief Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
+ */
+
+
#ifndef ARCFOUR_H_
#define ARCFOUR_H_
} arcfour_ctx_t;
+
void arcfour_init(arcfour_ctx_t *c, uint8_t *key, uint8_t length);
uint8_t arcfour_gen(arcfour_ctx_t *c);
0xB05688C2B3E6C1FDLL
};
*/
-uint32_t PROGMEM camellia_sigma[12]={ /* 64 byte table */
+uint32_t PROGMEM camellia_sigma[12]={ /* 48 byte table */
0x3BCC908BL, 0xA09E667FL,
0x4CAA73B2L, 0xB67AE858L,
0xE94F82BEL, 0xC6EF372FL,
#define KEY_ROL17 0x08
#define KEY_ROL15 0x00
-void camellia_6rounds(camellia128_ctx_t* s, uint64_t* bl, uint64_t* br, uint8_t roundop, uint8_t keychoice);
+void camellia_6rounds(camellia128_ctx_t* s, uint64_t* bl, uint64_t* br,
+ uint8_t roundop, uint8_t keychoice);
/*****************************************************************************/
#define BR (((uint64_t*)block)[1])
/* endian adjustment */
/*BL*/
- /* 1 2 3 4 5 6 7 8
+ /* 1 2 3 4 5 6 7 8
* 8 7 6 5 4 3 2 1
*/
#define BR (((uint64_t*)block)[1])
/* endian adjustment */
/*BL*/
- /* 1 2 3 4 5 6 7 8
- * 8 7 6 5 4 3 2 1
+ /* 1 2 3 4 5 6 7 8
+ * 8 7 6 5 4 3 2 1
*/
uint64_t temp64;
#define BR (((uint64_t*)block)[0])
/* endian adjustment */
/*BL*/
- /* 1 2 3 4 5 6 7 8
- * 8 7 6 5 4 3 2 1
+ /* 1 2 3 4 5 6 7 8
+ * 8 7 6 5 4 3 2 1
*/
uint64_t temp64;
/**
* \brief encrypts a datablock with cast5
- * @param s Pointer to cast5 roundkeys (context)
* @param block Pointer to datablock
+ * @param s Pointer to cast5 roundkeys (context)
*/
void cast5_enc(void* block, cast5_ctx_t *s){
uint32_t l,r, x, y;
/**
* \brief decrypts a datablock with cast5
- * @param s Pointer to cast5 roundkeys (context)
* @param block Pointer to datablock
+ * @param s Pointer to cast5 roundkeys (context)
*/
void cast5_dec(void* block, cast5_ctx_t *s){
uint32_t l,r, x, y;
/******************************************************************************/
-void des_encrypt(uint8_t* out, uint8_t* in, uint8_t* key){
+void des_enc(uint8_t* out, uint8_t* in, uint8_t* key){
#define R *((uint32_t*)&(data[4]))
#define L *((uint32_t*)&(data[0]))
/******************************************************************************/
-void des_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){
+void des_dec(uint8_t* out, uint8_t* in, uint8_t* key){
#define R *((uint32_t*)&(data[4]))
#define L *((uint32_t*)&(data[0]))
/******************************************************************************/
-void tdes_encrypt(uint8_t* out, uint8_t* in, uint8_t* key){
- des_encrypt(out, in, key + 0);
- des_decrypt(out, out, key + 8);
- des_encrypt(out, out, key +16);
+void tdes_enc(uint8_t* out, uint8_t* in, uint8_t* key){
+ des_enc(out, in, key + 0);
+ des_dec(out, out, key + 8);
+ des_enc(out, out, key +16);
}
/******************************************************************************/
-void tdes_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){
- des_decrypt(out, in, key + 0);
- des_encrypt(out, out, key + 8);
- des_decrypt(out, out, key +16);
+void tdes_dec(uint8_t* out, uint8_t* in, uint8_t* key){
+ des_dec(out, in, key + 0);
+ des_enc(out, out, key + 8);
+ des_dec(out, out, key +16);
}
/******************************************************************************/
#include <stdint.h>
/* the FIPS 46-3 (1999-10-25) name for triple DES is triple data encryption algorithm so TDEA.
* Also we only implement the three key mode */
-#define tdea_encrypt tdes_encrypt
-#define tdea_decrypt tdes_decrypt
+#define tdea_enc tdes_enc
+#define tdea_dec tdes_dec
-void des_encrypt(uint8_t* out, uint8_t* in, uint8_t* key);
-void des_decrypt(uint8_t* out, uint8_t* in, uint8_t* key);
-void tdes_encrypt(uint8_t* out, uint8_t* in, uint8_t* key);
-void tdes_decrypt(uint8_t* out, uint8_t* in, uint8_t* key);
+void des_enc(uint8_t* out, uint8_t* in, uint8_t* key);
+void des_dec(uint8_t* out, uint8_t* in, uint8_t* key);
+void tdes_enc(uint8_t* out, uint8_t* in, uint8_t* key);
+void tdes_dec(uint8_t* out, uint8_t* in, uint8_t* key);
#endif /*DES_H_*/
}
-void test_performance_cast5(void){
+void test_performance_camellia(void){
uint64_t t;
char str[6];
uint8_t key[16], data[16];
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
PGM_P u = PSTR("nessie\0test\0performance\0");
- void_fpt v[] = {testrun_nessie_camellia, testrun_nessie_camellia, test_performance_cast5};
+ void_fpt v[] = {testrun_nessie_camellia, testrun_nessie_camellia, test_performance_camellia};
while(1){
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
}
void des_enc_dummy(void* buffer, void* ctx){
- des_encrypt(buffer, buffer, ctx);
+ des_enc(buffer, buffer, ctx);
}
void des_dec_dummy(void* buffer, void* ctx){
- des_decrypt(buffer, buffer, ctx);
+ des_dec(buffer, buffer, ctx);
}
void testrun_nessie_des(void){
memset(data, 0, 8);
startTimer(1);
- des_encrypt(data, data, key);
+ des_enc(data, data, key);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
ultoa((unsigned long)t, str, 10);
uart_putstr(str);
startTimer(1);
- des_decrypt(data, data, key);
+ des_dec(data, data, key);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
ultoa((unsigned long)t, str, 10);
nessie_bc_ctx.keysize_b = 128;
nessie_bc_ctx.name = cipher_name;
nessie_bc_ctx.ctx_size_B = sizeof(seed_ctx_t);
- nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)seed_encrypt;
- nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_decrypt;
+ nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)seed_enc;
+ nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)seed_dec;
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)seed_genctx_dummy;
nessie_bc_run();
startTimer(1);
- seed_encrypt(data, &ctx);
+ seed_enc(data, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
ultoa((unsigned long)t, str, 10);
startTimer(1);
- seed_decrypt(data, &ctx);
+ seed_dec(data, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
ultoa((unsigned long)t, str, 10);
seed_init(key, &ctx);
uart_putstr("\r\n plain: ");
uart_hexdump(block,16);
- seed_encrypt(block, &ctx);
+ seed_enc(block, &ctx);
uart_putstr("\r\n crypt: ");
uart_hexdump(block,16);
}
seed_init(key, &ctx);
uart_putstr("\r\n crypt: ");
uart_hexdump(block,16);
- seed_decrypt(block, &ctx);
+ seed_dec(block, &ctx);
uart_putstr("\r\n plain: ");
uart_hexdump(block,16);
}
* additional validation-functions *
*****************************************************************************/
void serpent_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){
- serpent_genctx(key, keysize&0xff, ctx);
+ serpent_init(key, keysize&0xff, ctx);
}
void testrun_nessie_serpent(void){
memset(data, 0, 16);
startTimer(1);
- serpent_genctx(key, 0, &ctx);
+ serpent_init(key, 0, &ctx);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
ultoa((unsigned long)t, str, 10);
}
void tdes_enc_dummy(void* buffer, void* ctx){
- tdes_encrypt(buffer, buffer, ctx);
+ tdes_enc(buffer, buffer, ctx);
}
void tdes_dec_dummy(void* buffer, void* ctx){
- tdes_decrypt(buffer, buffer, ctx);
+ tdes_dec(buffer, buffer, ctx);
}
void testrun_nessie_tdes(void){
memset(data, 0, 8);
startTimer(1);
- tdes_encrypt(data, data, key);
+ tdes_enc(data, data, key);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
ultoa((unsigned long)t, str, 10);
uart_putstr(str);
startTimer(1);
- tdes_decrypt(data, data, key);
+ tdes_dec(data, data, key);
t = stopTimer();
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
ultoa((unsigned long)t, str, 10);
#define L (((uint64_t*)buffer)[0])
#define R (((uint64_t*)buffer)[1])
-void seed_encrypt(void * buffer, seed_ctx_t * ctx){
+void seed_enc(void * buffer, seed_ctx_t * ctx){
uint8_t r;
keypair_t k;
for(r=0; r<8; ++r){
#define L (((uint64_t*)buffer)[0])
#define R (((uint64_t*)buffer)[1])
-void seed_decrypt(void * buffer, seed_ctx_t * ctx){
+void seed_dec(void * buffer, seed_ctx_t * ctx){
int8_t r;
keypair_t k;
for(r=7; r>=0; --r){
/******************************************************************************/
void seed_init(uint8_t * key, seed_ctx_t * ctx);
-void seed_encrypt(void * buffer, seed_ctx_t * ctx);
-void seed_decrypt(void * buffer, seed_ctx_t * ctx);
+void seed_enc(void * buffer, seed_ctx_t * ctx);
+void seed_dec(void * buffer, seed_ctx_t * ctx);
#endif /*SEED_H_*/
}
/* key must be 256bit (32 byte) large! */
-void serpent_genctx(void * key, uint8_t keysize, serpent_ctx_t * ctx){
+void serpent_init(void * key, uint8_t keysize, serpent_ctx_t * ctx){
uint32_t buffer[8];
uint8_t i,j;
if(keysize){
/* key must be 256bit (32 byte) large! */
-void serpent_genctx(void * key, uint8_t keysize, serpent_ctx_t * ctx);
+void serpent_init(void * key, uint8_t keysize, serpent_ctx_t * ctx);
void serpent_enc(void * buffer, serpent_ctx_t * ctx);
void serpent_dec(void * buffer, serpent_ctx_t * ctx);