X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=whirlpool%2Fwhirlpool.c;h=d46c4bdb49f7e1c1def2e48851550df6325f9eb9;hp=cd41ccea3f60f7cb48d9aef8ba8d606bdeccb615;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=3f759a542ce8ba4ffbeb6d336a3557a8abbd3ad4 diff --git a/whirlpool/whirlpool.c b/whirlpool/whirlpool.c index cd41cce..d46c4bd 100644 --- a/whirlpool/whirlpool.c +++ b/whirlpool/whirlpool.c @@ -1,7 +1,7 @@ /* whirlpool.c */ /* This file is part of the AVR-Crypto-Lib. - Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 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 @@ -43,13 +43,13 @@ u 0 1 2 3 4 5 6 7 8 9 A B C D E F E(u) 1 B 9 C D 6 F 3 E 8 7 4 A 2 5 0 E -1(u) F 0 D 7 B E 5 A 9 2 C 1 3 4 8 6 */ -static uint8_t eeinv_box[16] PROGMEM = { +static const uint8_t eeinv_box[16] PROGMEM = { /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ 0x1F, 0xB0, 0x9D, 0xC7, 0xDB, 0x6E, 0xF5, 0x3A, 0xE9, 0x82, 0x7C, 0x41, 0xA3, 0x24, 0x58, 0x06 }; -static uint8_t r_box[16] PROGMEM = { +static const uint8_t r_box[16] PROGMEM = { 0x77, 0xCC, 0xBB, 0xDD, 0xEE, 0x44, 0x99, 0xFF, 0x66, 0x33, 0x88, 0xAA, 0x22, 0x55, 0x11, 0x00 }; @@ -68,7 +68,7 @@ static uint8_t whirlpool_sbox(uint8_t a){ #else #if WHIRLPOOL_0 -static uint8_t sbox[256] PROGMEM = { +static const uint8_t sbox[256] PROGMEM = { 0x68, 0xd0, 0xeb, 0x2b, 0x48, 0x9d, 0x6a, 0xe4, 0xe3, 0xa3, 0x56, 0x81, 0x7d, 0xf1, 0x85, 0x9e, 0x2c, 0x8e, 0x78, 0xca, 0x17, 0xa9, 0x61, 0xd5, 0x5d, 0x0b, 0x8c, 0x3c, 0x77, 0x51, 0x22, 0x42, 0x3f, 0x54, 0x41, 0x80, 0xcc, 0x86, 0xb3, 0x18, 0x2e, 0x57, 0x06, 0x62, 0xf4, 0x36, 0xd1, 0x6b, @@ -87,7 +87,7 @@ static uint8_t sbox[256] PROGMEM = { 0x13, 0xbb, 0xf7, 0x6f, 0xb9, 0x47, 0x2f, 0xee, 0xb8, 0x7b, 0x89, 0x30, 0xd3, 0x7f, 0x76, 0x82 }; #else -static uint8_t sbox[256] PROGMEM = { +static const uint8_t sbox[256] PROGMEM = { 0x18, 0x23, 0xC6, 0xE8, 0x87, 0xB8, 0x01, 0x4F, 0x36, 0xA6, 0xD2, 0xF5, 0x79, 0x6F, 0x91, 0x52, 0x60, 0xBC, 0x9B, 0x8E, 0xA3, 0x0C, 0x7B, 0x35, 0x1D, 0xE0, 0xD7, 0xC2, 0x2E, 0x4B, 0xFE, 0x57, 0x15, 0x77, 0x37, 0xE5, 0x9F, 0xF0, 0x4A, 0xDA, 0x58, 0xC9, 0x29, 0x0A, 0xB1, 0xA0, 0x6B, 0x85, @@ -111,7 +111,7 @@ static uint8_t sbox[256] PROGMEM = { #endif -static void gamma(uint8_t* a){ +static void gamma_1(uint8_t *a){ uint8_t i; for(i=0; i<64; ++i){ *a = whirlpool_sbox(*a); @@ -119,7 +119,7 @@ static void gamma(uint8_t* a){ } } -static void pi(uint8_t* a){ +static void pi(uint8_t *a){ uint8_t b[8]; uint8_t i,j; for(i=1; i<8; ++i){ @@ -133,18 +133,18 @@ static void pi(uint8_t* a){ } #if WHIRLPOOL_0 || WHIRLPOOL_T -static uint8_t theta_matrix[8] PROGMEM = { +static const uint8_t theta_matrix[8] PROGMEM = { 0x1, 0x1, 0x3, 0x1, 0x5, 0x8, 0x9, 0x5 }; #else -static uint8_t theta_matrix[8] PROGMEM = { +static const uint8_t theta_matrix[8] PROGMEM = { 0x1, 0x1, 0x4, 0x1, 0x8, 0x5, 0x2, 0x9 }; #endif #define POLYNOM 0x1D -static void theta(uint8_t* a){ +static void theta(uint8_t *a){ uint8_t b[8], c, accu; uint8_t i,j,k; for(i=0; i<8; ++i){ @@ -160,8 +160,8 @@ static void theta(uint8_t* a){ } } -static void w_round(uint8_t* a, const uint8_t* k){ - gamma(a); +static void w_round(uint8_t *a, const uint8_t *k){ + gamma_1(a); #if DEBUG cli_putstr_P(PSTR("\r\n pre-pi:")); cli_hexdump_block(a, 64, 4, 8); @@ -179,7 +179,7 @@ static void w_round(uint8_t* a, const uint8_t* k){ memxor(a, k, 64); } -static void w_enc(uint8_t *a, const uint8_t* k){ +static void w_enc(uint8_t *a, const uint8_t *k){ #if DEBUG cli_putstr_P(PSTR("\r\n== w_enc ==\r\n w'_00:")); cli_hexdump_block(a, 64, 4, 8); @@ -215,12 +215,12 @@ static void w_enc(uint8_t *a, const uint8_t* k){ } } -void whirlpool_init(whirlpool_ctx_t* ctx){ +void whirlpool_init(whirlpool_ctx_t *ctx){ memset(ctx->s, 0, 64); ctx->blocks = 0; } -void whirlpool_nextBlock(whirlpool_ctx_t* ctx, const void* block){ +void whirlpool_nextBlock(whirlpool_ctx_t *ctx, const void *block){ uint8_t state[64]; ctx->blocks += 1; memcpy(state, block, 64); @@ -229,7 +229,7 @@ void whirlpool_nextBlock(whirlpool_ctx_t* ctx, const void* block){ memxor((ctx->s), block, 64); } -void whirlpool_lastBlock(whirlpool_ctx_t* ctx, const void* block, uint16_t length_b){ +void whirlpool_lastBlock(whirlpool_ctx_t *ctx, const void *block, uint16_t length_b){ while(length_b>=512){ whirlpool_nextBlock(ctx, block); block = (uint8_t*)block + 64; @@ -253,6 +253,6 @@ void whirlpool_lastBlock(whirlpool_ctx_t* ctx, const void* block, uint16_t lengt whirlpool_nextBlock(ctx, buffer); } -void whirlpool_ctx2hash(void* dest, const whirlpool_ctx_t* ctx){ +void whirlpool_ctx2hash(void *dest, const whirlpool_ctx_t *ctx){ memcpy(dest, (ctx->s), 64); }