From: bg Date: Sat, 19 Jul 2008 16:15:55 +0000 (+0000) Subject: some changings to make API more consistent X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=94cad47618f03baf3d750d75c20860c89ac91dbe;p=avr-crypto-lib.git some changings to make API more consistent --- diff --git a/arcfour.h b/arcfour.h index 030c014..38ab40d 100644 --- a/arcfour.h +++ b/arcfour.h @@ -21,9 +21,18 @@ * 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_ @@ -35,6 +44,7 @@ typedef struct { } arcfour_ctx_t; + void arcfour_init(arcfour_ctx_t *c, uint8_t *key, uint8_t length); uint8_t arcfour_gen(arcfour_ctx_t *c); diff --git a/camellia.c b/camellia.c index a6a88d2..a561d4e 100644 --- a/camellia.c +++ b/camellia.c @@ -49,7 +49,7 @@ uint64_t PROGMEM camellia_sigma[6]={ / * 64 byte table * / 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, @@ -130,7 +130,8 @@ void camellia128_keyop_inv(camellia128_ctx_t* s, int8_t q); #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); /*****************************************************************************/ @@ -140,7 +141,7 @@ void camellia128_enc(void* block, camellia128_ctx_t* s){ #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 */ diff --git a/camellia_C.c b/camellia_C.c index 862c6d3..1eea731 100644 --- a/camellia_C.c +++ b/camellia_C.c @@ -356,8 +356,8 @@ void camellia128_enc(camellia128_ctx_t* s, void* block){ #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; @@ -450,8 +450,8 @@ void camellia128_dec(camellia128_ctx_t* s, void* block){ #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; diff --git a/cast5.c b/cast5.c index b4736c8..8a71e6d 100644 --- a/cast5.c +++ b/cast5.c @@ -272,8 +272,8 @@ uint32_t cast5_f3(uint32_t d, uint32_t m, uint8_t r){ /** * \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; @@ -301,8 +301,8 @@ void cast5_enc(void* block, cast5_ctx_t *s){ /** * \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; diff --git a/des.c b/des.c index d4b8ce1..33e6a76 100644 --- a/des.c +++ b/des.c @@ -302,7 +302,7 @@ uint32_t des_f(uint32_t r, uint8_t* kr){ /******************************************************************************/ -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])) @@ -335,7 +335,7 @@ 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 des_dec(uint8_t* out, uint8_t* in, uint8_t* key){ #define R *((uint32_t*)&(data[4])) #define L *((uint32_t*)&(data[0])) @@ -371,18 +371,18 @@ void des_decrypt(uint8_t* out, uint8_t* in, uint8_t* key){ /******************************************************************************/ -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); } /******************************************************************************/ diff --git a/des.h b/des.h index 6fec6d3..61bcd36 100644 --- a/des.h +++ b/des.h @@ -31,12 +31,12 @@ #include /* 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_*/ diff --git a/main-camellia-test.c b/main-camellia-test.c index cf4ed4e..4d64a50 100644 --- a/main-camellia-test.c +++ b/main-camellia-test.c @@ -60,7 +60,7 @@ void testrun_nessie_camellia(void){ } -void test_performance_cast5(void){ +void test_performance_camellia(void){ uint64_t t; char str[6]; uint8_t key[16], data[16]; @@ -120,7 +120,7 @@ int main (void){ 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;} diff --git a/main-des-test.c b/main-des-test.c index 6a0e428..714781c 100644 --- a/main-des-test.c +++ b/main-des-test.c @@ -45,11 +45,11 @@ void des_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ } 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){ @@ -79,14 +79,14 @@ void testrun_performance_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); diff --git a/main-seed-test.c b/main-seed-test.c index ff4ccab..678d132 100644 --- a/main-seed-test.c +++ b/main-seed-test.c @@ -54,8 +54,8 @@ void testrun_nessie_seed(void){ 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(); @@ -84,7 +84,7 @@ void testrun_performance_seed(void){ 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); @@ -92,7 +92,7 @@ void testrun_performance_seed(void){ 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); @@ -112,7 +112,7 @@ void testencrypt(uint8_t* block, uint8_t* key){ 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); } @@ -124,7 +124,7 @@ void testdecrypt(uint8_t* block, uint8_t* key){ 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); } diff --git a/main-serpent-test.c b/main-serpent-test.c index fc86035..5c450b6 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -41,7 +41,7 @@ char* cipher_name = "Serpent"; * 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){ @@ -76,7 +76,7 @@ void testrun_performance_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); diff --git a/main-tdes-test.c b/main-tdes-test.c index c741237..d5ae1a0 100644 --- a/main-tdes-test.c +++ b/main-tdes-test.c @@ -45,11 +45,11 @@ void tdes_init_dummy(const void* key, uint16_t keysize_b, void* ctx){ } 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){ @@ -79,14 +79,14 @@ void testrun_performance_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); diff --git a/seed.c b/seed.c index 29cd991..ba26fa2 100644 --- a/seed.c +++ b/seed.c @@ -229,7 +229,7 @@ void seed_init(uint8_t * key, seed_ctx_t * ctx){ #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){ @@ -262,7 +262,7 @@ void seed_encrypt(void * buffer, seed_ctx_t * ctx){ #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){ diff --git a/seed.h b/seed.h index 04b3566..4ee1d8b 100644 --- a/seed.h +++ b/seed.h @@ -37,7 +37,7 @@ typedef struct{ /******************************************************************************/ 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_*/ diff --git a/serpent.c b/serpent.c index 7042a41..8c33bbe 100644 --- a/serpent.c +++ b/serpent.c @@ -92,7 +92,7 @@ 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(void * key, uint8_t keysize, serpent_ctx_t * ctx){ uint32_t buffer[8]; uint8_t i,j; if(keysize){ diff --git a/serpent.h b/serpent.h index ce266ed..084b87a 100644 --- a/serpent.h +++ b/serpent.h @@ -39,7 +39,7 @@ typedef struct serpent_ctx_st { /* 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);