Browse Source

now with rsassa-pkcs1v15 (old rsa signatures) + many new things

master
bg 10 years ago
parent
commit
1cdc772d04
  1. 2
      arm-makefile.inc
  2. 7
      bcal/bcal_camellia128.c
  3. 1
      bcal/bcal_camellia128.h
  4. 52
      bigint/bigint.c
  5. 10
      bigint/bigint.h
  6. 23
      blake/blake_large.c
  7. 26
      blake/blake_small.c
  8. 31
      bmw/bmw_large.c
  9. 31
      bmw/bmw_large_speed.c
  10. 36
      bmw/bmw_small.c
  11. 36
      bmw/bmw_small_speed.c
  12. 34
      host/rsaes_oaep_check.rb
  13. 73
      host/rsaes_pkcs1v15_check.rb
  14. 440
      host/rsassa_pkcs1v15_check.rb
  15. 24
      host/shavs_test2.rb
  16. 6
      jh/jh_simple_speed_core.c
  17. 23
      md5/md5.c
  18. 36
      md5/md5_sbox.c
  19. 16
      md5/md5_sbox.h
  20. 12
      mkfiles/md5_c.mk
  21. 6
      mkfiles/rsaes_oaep.mk
  22. 14
      mkfiles/rsaes_pkcs1v15.mk
  23. 14
      mkfiles/rsassa_pkcs1v15.mk
  24. 3
      mkfiles/zzz_lib.mk
  25. 26
      present/present.c
  26. 33
      rsa/rsa_basic.c
  27. 12
      rsa/rsa_basic.h
  28. 228
      rsa/rsa_oaep.c
  29. 54
      rsa/rsa_oaep.h
  30. 142
      rsa/rsa_pkcs15.c
  31. 35
      rsa/rsa_pkcs15.h
  32. 197
      rsa/rsassa_pkcs1v15.c
  33. 46
      rsa/rsassa_pkcs1v15.h
  34. 30
      salsa20/salsa20.c
  35. 5
      salsa20/salsa20.h
  36. 4
      sha1/sha1.c
  37. 7
      sha1/sha1.h
  38. 2
      test_src/dbz_strings.c
  39. 2
      test_src/dbz_strings.h
  40. 32
      test_src/main-md5-test.c
  41. 841
      test_src/main-rsa_oaep-test.c
  42. 633
      test_src/main-rsassa_pkcs1v15-test.c
  43. 10
      test_src/main-salsa20-test.c
  44. 2
      test_src/nessie_hash_test.c
  45. 4
      test_src/string-extras.c
  46. 1
      test_src/string-extras.h
  47. 6212
      testvectors/Md5-128.unverified.test-vectors
  48. 9049
      testvectors/rsa-pkcs-1v2-1-vec/pkcs1v15sign-vectors.txt

2
arm-makefile.inc

@ -16,7 +16,7 @@ TEST_DIR = test/#
BIN_DIR = bin/#
TESTSRC_DIR = test_src/#
ERASECMD =
TESTPORT = /dev/ttyUSB1
TESTPORT = /dev/ttyUSB2
TESTPORTBAUDR = 115200
TESTLOG_DIR = testlog/#
TESTPREFIX = nessie-#

7
bcal/bcal_camellia128.c

@ -25,18 +25,17 @@
*
*/
#include <avr/pgmspace.h>
#include <stdlib.h>
#include "blockcipher_descriptor.h"
#include "camellia.h"
#include "keysize_descriptor.h"
const char camellia128_str[] PROGMEM = "Camellia-128";
const char camellia128_str[] = "Camellia-128";
const uint8_t camellia128_keysize_desc[] PROGMEM = { KS_TYPE_LIST, 1, KS_INT(128),
const uint8_t camellia128_keysize_desc[] = { KS_TYPE_LIST, 1, KS_INT(128),
KS_TYPE_TERMINATOR };
const bcdesc_t camellia128_desc PROGMEM = {
const bcdesc_t camellia128_desc = {
BCDESC_TYPE_BLOCKCIPHER,
BC_INIT_TYPE_2,
camellia128_str,

1
bcal/bcal_camellia128.h

@ -25,7 +25,6 @@
*
*/
#include <avr/pgmspace.h>
#include "blockcipher_descriptor.h"
#include "camellia.h"
#include "keysize_descriptor.h"

52
bigint/bigint.c

@ -53,9 +53,9 @@
#define SET_NEG(a) (a)->info |= BIGINT_NEG_MASK
#define SET_POS(a) (a)->info &= ~BIGINT_NEG_MASK
#define XCHG(a,b) do{(a)^=(b); (b)^=(a); (a)^=(b);}while(0)
#define XCHG_PTR(a,b) do{ a = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b))); \
b = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b))); \
a = (void*)(((bigint_ptr_int_t)(a)) ^ ((bigint_ptr_int_t)(b)));}while(0)
#define XCHG_PTR(a,b) do{ a = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b))); \
b = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b))); \
a = (void*)(((intptr_t)(a)) ^ ((intptr_t)(b)));}while(0)
#define GET_SIGN(a) ((a)->info&BIGINT_NEG_MASK)
@ -80,7 +80,7 @@ void bigint_adjust(bigint_t* a){
/******************************************************************************/
uint16_t bigint_length_b(bigint_t* a){
uint16_t bigint_length_b(const bigint_t* a){
if(!a->length_B || a->length_B==0){
return 0;
}
@ -89,13 +89,13 @@ uint16_t bigint_length_b(bigint_t* a){
/******************************************************************************/
uint16_t bigint_length_B(bigint_t* a){
uint16_t bigint_length_B(const bigint_t* a){
return a->length_B * sizeof(bigint_word_t);
}
/******************************************************************************/
uint32_t bigint_get_first_set_bit(bigint_t* a){
uint32_t bigint_get_first_set_bit(const bigint_t* a){
if(a->length_B==0){
return (uint32_t)(-1);
}
@ -105,7 +105,7 @@ uint32_t bigint_get_first_set_bit(bigint_t* a){
/******************************************************************************/
uint32_t bigint_get_last_set_bit(bigint_t* a){
uint32_t bigint_get_last_set_bit(const bigint_t* a){
uint32_t r=0;
uint8_t b=0;
bigint_word_t x=1;
@ -403,7 +403,7 @@ int8_t bigint_cmp_s(const bigint_t* a, const bigint_t* b){
/******************************************************************************/
void bigint_shiftleft(bigint_t* a, uint16_t shift){
uint16_t byteshift, word_alloc;
uint16_t byteshift, word_alloc, words_to_shift;
int16_t i;
uint8_t bitshift;
bigint_word_t *p;
@ -417,14 +417,15 @@ void bigint_shiftleft(bigint_t* a, uint16_t shift){
a->wordv[a->length_B+i] = 0;
}
if(byteshift){
memmove(((uint8_t*)a->wordv)+byteshift, a->wordv, a->length_B*sizeof(bigint_word_t));
memmove(((uint8_t*)a->wordv) + byteshift, a->wordv, a->length_B * sizeof(bigint_word_t));
memset(a->wordv, 0, byteshift);
}
p = (bigint_word_t*)(((uint8_t*)a->wordv)+byteshift);
word_alloc = a->length_B+(byteshift+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t)+1;
p = a->wordv + byteshift / sizeof(bigint_word_t);
words_to_shift = a->length_B + (byteshift % sizeof(bigint_word_t)?1:0);
word_alloc = a->length_B + (byteshift + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t) + 1;
a->wordv[word_alloc-1]=0;
if(bitshift!=0){
for(i=0; i<a->length_B; ++i){
for(i=0; i < words_to_shift; ++i){
t |= ((bigint_wordplus_t)p[i])<<bitshift;
p[i] = (bigint_word_t)t;
t >>= BIGINT_WORD_SIZE;
@ -444,30 +445,29 @@ void bigint_shiftright(bigint_t* a, uint16_t shift){
bigint_wordplus_t t=0;
byteshift = shift/8;
bitshift = shift&7;
if(byteshift >= a->length_B*sizeof(bigint_word_t)){ /* we would shift out more than we have */
if(byteshift >= a->length_B * sizeof(bigint_word_t)){ /* we would shift out more than we have */
bigint_set_zero(a);
return;
}
if(byteshift == a->length_B*sizeof(bigint_word_t)-1 && bitshift>GET_FBS(a)){
if(byteshift == a->length_B * sizeof(bigint_word_t) - 1 && bitshift > GET_FBS(a)){
bigint_set_zero(a);
return;
}
if(byteshift){
memmove(a->wordv, (uint8_t*)a->wordv+byteshift, a->length_B-byteshift);
memset((uint8_t*)a->wordv+a->length_B-byteshift, 0, byteshift);
memmove(a->wordv, (uint8_t*)a->wordv + byteshift, a->length_B * sizeof(bigint_word_t) - byteshift);
memset((uint8_t*)a->wordv + a->length_B * sizeof(bigint_word_t) - byteshift, 0, byteshift);
}
byteshift /= sizeof(bigint_word_t);
if(bitshift!=0){
a->length_B -= (byteshift + sizeof(bigint_word_t) - 1) / sizeof(bigint_word_t);
if(bitshift != 0 && a->length_B){
/* shift to the right */
for(i=a->length_B-byteshift-1; i>0; --i){
t |= ((bigint_wordplus_t)(a->wordv[i]))<<(BIGINT_WORD_SIZE-bitshift);
a->wordv[i] = (bigint_word_t)(t>>BIGINT_WORD_SIZE);
i = a->length_B - 1;
do{
t |= ((bigint_wordplus_t)(a->wordv[i])) << (BIGINT_WORD_SIZE - bitshift);
a->wordv[i] = (bigint_word_t)(t >> BIGINT_WORD_SIZE);
t <<= BIGINT_WORD_SIZE;
}
t |= ((bigint_wordplus_t)(a->wordv[0]))<<(BIGINT_WORD_SIZE-bitshift);
a->wordv[0] = (bigint_word_t)(t>>BIGINT_WORD_SIZE);
}while(i--);
}
a->length_B -= ((shift/8)+sizeof(bigint_word_t)-1)/sizeof(bigint_word_t);
bigint_adjust(a);
}
@ -792,12 +792,12 @@ void bigint_expmod_u(bigint_t* dest, const bigint_t* a, const bigint_t* exp, con
if(flag){
bigint_square(&res, &res);
bigint_reduce(&res, r);
if(t & (1<<(BIGINT_WORD_SIZE-1))){
if(t & (1 << (BIGINT_WORD_SIZE - 1))){
bigint_mul_u(&res, &res, &base);
bigint_reduce(&res, r);
}
}
t<<=1;
t <<= 1;
}
}

10
bigint/bigint.h

@ -43,15 +43,13 @@ typedef struct{
bigint_word_t *wordv; /* word vector, pointing to the LSB */
}bigint_t;
typedef uint32_t bigint_ptr_int_t;
/******************************************************************************/
void bigint_adjust(bigint_t* a);
uint32_t bigint_get_first_set_bit(bigint_t* a);
uint32_t bigint_get_last_set_bit(bigint_t* a);
uint16_t bigint_length_b(bigint_t* a);
uint16_t bigint_length_B(bigint_t* a);
uint32_t bigint_get_first_set_bit(const bigint_t* a);
uint32_t bigint_get_last_set_bit(const bigint_t* a);
uint16_t bigint_length_b(const bigint_t* a);
uint16_t bigint_length_B(const bigint_t* a);
void bigint_copy(bigint_t* dest, const bigint_t* src);
void bigint_add_u(bigint_t* dest, const bigint_t* a, const bigint_t* b);
void bigint_add_scale_u(bigint_t* dest, const bigint_t* a, uint16_t scale);

23
blake/blake_large.c

@ -137,21 +137,24 @@ void blake_large_lastBlock(blake_large_ctx_t* ctx, const void* msg, uint16_t len
msg = (uint8_t*)msg + BLAKE_LARGE_BLOCKSIZE_B;
length_b -= BLAKE_LARGE_BLOCKSIZE;
}
uint8_t buffer[128];
union {
uint8_t v8[128];
uint64_t v64[ 16];
} buffer;
uint64_t v[16];
uint64_t ctr;
ctr = ctx->counter*1024+length_b;
memset(buffer, 0, 128);
memcpy(buffer, msg, (length_b+7)/8);
buffer[length_b/8] |= 0x80 >> (length_b&0x7);
blake_large_changeendian(buffer, buffer);
memset(buffer.v8, 0, 128);
memcpy(buffer.v8, msg, (length_b+7)/8);
buffer.v8[length_b/8] |= 0x80 >> (length_b&0x7);
blake_large_changeendian(buffer.v8, buffer.v8);
blake_large_expand(v, ctx);
if(length_b>1024-128-2){
v[12] ^= ctr;
v[13] ^= ctr;
blake_large_compress(v, buffer);
blake_large_compress(v, buffer.v8);
blake_large_collapse(ctx, v);
memset(buffer, 0, 128-8);
memset(buffer.v8, 0, 128-8);
blake_large_expand(v, ctx);
} else {
if(length_b){
@ -160,9 +163,9 @@ void blake_large_lastBlock(blake_large_ctx_t* ctx, const void* msg, uint16_t len
}
}
if(ctx->appendone)
buffer[128-16-8] |= 0x01;
*((uint64_t*)(&(buffer[128-8]))) = ctr;
blake_large_compress(v, buffer);
buffer.v8[128-16-8] |= 0x01;
buffer.v64[15] = ctr;
blake_large_compress(v, buffer.v8);
blake_large_collapse(ctx, v);
}

26
blake/blake_small.c

@ -133,26 +133,30 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len
msg = (uint8_t*)msg + BLAKE_SMALL_BLOCKSIZE_B;
length_b -= BLAKE_SMALL_BLOCKSIZE;
}
uint8_t buffer[64];
union {
uint8_t v8[64];
uint32_t v32[16];
uint64_t v64[ 8];
} buffer;
uint32_t v[16];
union {
uint64_t v64;
uint32_t v32[2];
}ctr;
ctr.v64 = ctx->counter*512+length_b;
memset(buffer, 0, 64);
memcpy(buffer, msg, (length_b+7)/8);
buffer[length_b/8] |= 0x80 >> (length_b&0x7);
blake_small_changeendian(buffer, buffer);
memset(buffer.v8, 0, 64);
memcpy(buffer.v8, msg, (length_b+7)/8);
buffer.v8[length_b/8] |= 0x80 >> (length_b&0x7);
blake_small_changeendian(buffer.v8, buffer.v8);
blake_small_expand(v, ctx);
if(length_b>512-64-2){
v[12] ^= ctr.v32[0];
v[13] ^= ctr.v32[0];
v[14] ^= ctr.v32[1];
v[15] ^= ctr.v32[1];
blake_small_compress(v, buffer);
blake_small_compress(v, buffer.v8);
blake_small_collapse(ctx, v);
memset(buffer, 0, 64-8);
memset(buffer.v8, 0, 64-8);
blake_small_expand(v, ctx);
}else{
if(length_b){
@ -163,10 +167,10 @@ void blake_small_lastBlock(blake_small_ctx_t* ctx, const void* msg, uint16_t len
}
}
if(ctx->appendone)
buffer[64-8-4] |= 0x01;
*((uint32_t*)(&(buffer[64-8]))) = ctr.v32[1];
*((uint32_t*)(&(buffer[64-4]))) = ctr.v32[0];
blake_small_compress(v, buffer);
buffer.v8[64-8-4] |= 0x01;
buffer.v32[14] = ctr.v32[1];
buffer.v32[15] = ctr.v32[0];
blake_small_compress(v, buffer.v8);
blake_small_collapse(ctx, v);
}

31
bmw/bmw_large.c

@ -520,33 +520,36 @@ void bmw_large_nextBlock(bmw_large_ctx_t* ctx, const void* block){
}
void bmw_large_lastBlock(bmw_large_ctx_t* ctx, const void* block, uint16_t length_b){
uint8_t buffer[128];
union {
uint8_t v8[128];
uint64_t v64[ 16];
} buffer;
while(length_b >= BMW_LARGE_BLOCKSIZE){
bmw_large_nextBlock(ctx, block);
length_b -= BMW_LARGE_BLOCKSIZE;
block = (uint8_t*)block + BMW_LARGE_BLOCKSIZE_B;
}
memset(buffer, 0, 128);
memcpy(buffer, block, (length_b+7)/8);
buffer[length_b>>3] |= 0x80 >> (length_b&0x07);
memset(buffer.v8, 0, 128);
memcpy(buffer.v8, block, (length_b+7)/8);
buffer.v8[length_b>>3] |= 0x80 >> (length_b&0x07);
if(length_b+1>128*8-64){
bmw_large_nextBlock(ctx, buffer);
memset(buffer, 0, 128-8);
bmw_large_nextBlock(ctx, buffer.v8);
memset(buffer.v8, 0, 128-8);
ctx->counter -= 1;
}
*((uint64_t*)&(buffer[128-8])) = (uint64_t)(ctx->counter*1024LL)+(uint64_t)length_b;
bmw_large_nextBlock(ctx, buffer);
buffer.v64[15] = (uint64_t)(ctx->counter*1024LL)+(uint64_t)length_b;
bmw_large_nextBlock(ctx, buffer.v8);
#if TWEAK
uint8_t i;
uint64_t q[32];
memset(buffer, 0xaa, 128);
memset(buffer.v8, 0xaa, 128);
for(i=0; i<16; ++i){
buffer[8*i] = i + 0xa0;
buffer.v8[8*i] = i + 0xa0;
}
bmw_large_f0(q, (uint64_t*)buffer, ctx->h);
bmw_large_f1(q, ctx->h, (uint64_t*)buffer);
bmw_large_f2((uint64_t*)buffer, q, ctx->h);
memcpy(ctx->h, buffer, 128);
bmw_large_f0(q, buffer.v64, ctx->h);
bmw_large_f1(q, ctx->h, buffer.v64);
bmw_large_f2(buffer.v64, q, ctx->h);
memcpy(ctx->h, buffer.v8, 128);
#endif
}

31
bmw/bmw_large_speed.c

@ -226,32 +226,35 @@ void bmw_large_nextBlock(bmw_large_ctx_t* ctx, const void* block){
}
void bmw_large_lastBlock(bmw_large_ctx_t* ctx, const void* block, uint16_t length_b){
uint8_t buffer[128];
union {
uint8_t v8[128];
uint64_t v64[ 16];
} buffer;
while(length_b >= BMW_LARGE_BLOCKSIZE){
bmw_large_nextBlock(ctx, block);
length_b -= BMW_LARGE_BLOCKSIZE;
block = (uint8_t*)block + BMW_LARGE_BLOCKSIZE_B;
}
memset(buffer, 0, 128);
memcpy(buffer, block, (length_b+7)/8);
buffer[length_b>>3] |= 0x80 >> (length_b&0x07);
memset(buffer.v8, 0, 128);
memcpy(buffer.v8, block, (length_b+7)/8);
buffer.v8[length_b>>3] |= 0x80 >> (length_b&0x07);
if(length_b+1>128*8-64){
bmw_large_nextBlock(ctx, buffer);
memset(buffer, 0, 128-8);
bmw_large_nextBlock(ctx, buffer.v8);
memset(buffer.v8, 0, 128-8);
ctx->counter -= 1;
}
*((uint64_t*)&(buffer[128-8])) = (uint64_t)(ctx->counter*1024LL)+(uint64_t)length_b;
bmw_large_nextBlock(ctx, buffer);
buffer.v64[15] = (uint64_t)(ctx->counter*1024LL)+(uint64_t)length_b;
bmw_large_nextBlock(ctx, buffer.v8);
uint8_t i;
uint64_t q[32];
memset(buffer, 0xaa, 128);
memset(buffer.v8, 0xaa, 128);
for(i=0; i<16; ++i){
buffer[8*i] = i + 0xa0;
buffer.v8[8*i] = i + 0xa0;
}
bmw_large_f0(q, (uint64_t*)buffer, ctx->h);
bmw_large_f1(q, ctx->h, (uint64_t*)buffer);
bmw_large_f2((uint64_t*)buffer, q, ctx->h);
memcpy(ctx->h, buffer, 128);
bmw_large_f0(q, buffer.v64, ctx->h);
bmw_large_f1(q, ctx->h, buffer.v64);
bmw_large_f2(buffer.v64, q, ctx->h);
memcpy(ctx->h, buffer.v8, 128);
}
void bmw384_init(bmw384_ctx_t* ctx){

36
bmw/bmw_small.c

@ -401,38 +401,42 @@ void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){
}
void bmw_small_lastBlock(bmw_small_ctx_t* ctx, const void* block, uint16_t length_b){
uint8_t buffer[64];
union {
uint8_t v8[64];
uint32_t v32[16];
uint64_t v64[ 8];
} buffer;
while(length_b >= BMW_SMALL_BLOCKSIZE){
bmw_small_nextBlock(ctx, block);
length_b -= BMW_SMALL_BLOCKSIZE;
block = (uint8_t*)block + BMW_SMALL_BLOCKSIZE_B;
}
memset(buffer, 0, 64);
memcpy(buffer, block, (length_b+7)/8);
buffer[length_b>>3] |= 0x80 >> (length_b&0x07);
memset(buffer.v8, 0, 64);
memcpy(buffer.v8, block, (length_b+7)/8);
buffer.v8[length_b>>3] |= 0x80 >> (length_b&0x07);
if(length_b+1>64*8-64){
bmw_small_nextBlock(ctx, buffer);
memset(buffer, 0, 64-8);
bmw_small_nextBlock(ctx, buffer.v8);
memset(buffer.v8, 0, 64-8);
ctx->counter -= 1;
}
*((uint64_t*)&(buffer[64-8])) = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b;
bmw_small_nextBlock(ctx, buffer);
buffer.v64[7] = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b;
bmw_small_nextBlock(ctx, buffer.v8);
#if TWEAK
uint8_t i;
uint32_t q[32];
memset(buffer, 0xaa, 64);
memset(buffer.v8, 0xaa, 64);
for(i=0; i<16;++i){
buffer[i*4] = i+0xa0;
buffer.v8[i*4] = i+0xa0;
}
// dump_x(buffer, 16, 'A');
// dump_x(buffer.v8, 16, 'A');
dump_x(ctx->h, 16, 'M');
bmw_small_f0(q, (uint32_t*)buffer, ctx->h);
dump_x(buffer, 16, 'a');
bmw_small_f0(q, buffer.v32, ctx->h);
dump_x(buffer.v8, 16, 'a');
dump_x(q, 16, 'Q');
bmw_small_f1(q, ctx->h, (uint32_t*)buffer);
bmw_small_f1(q, ctx->h, buffer.v32);
dump_x(q, 32, 'Q');
bmw_small_f2((uint32_t*)buffer, q, ctx->h);
memcpy(ctx->h, buffer, 64);
bmw_small_f2(buffer.v32, q, ctx->h);
memcpy(ctx->h, buffer.v8, 64);
#endif
}

36
bmw/bmw_small_speed.c

@ -228,37 +228,41 @@ void bmw_small_nextBlock(bmw_small_ctx_t* ctx, const void* block){
}
void bmw_small_lastBlock(bmw_small_ctx_t* ctx, const void* block, uint16_t length_b){
uint8_t buffer[64];
union {
uint8_t v8[64];
uint32_t v32[16];
uint64_t v64[ 8];
} buffer;
while(length_b >= BMW_SMALL_BLOCKSIZE){
bmw_small_nextBlock(ctx, block);
length_b -= BMW_SMALL_BLOCKSIZE;
block = (uint8_t*)block + BMW_SMALL_BLOCKSIZE_B;
}
memset(buffer, 0, 64);
memcpy(buffer, block, (length_b+7)/8);
buffer[length_b>>3] |= 0x80 >> (length_b&0x07);
memset(buffer.v8, 0, 64);
memcpy(buffer.v8, block, (length_b+7)/8);
buffer.v8[length_b>>3] |= 0x80 >> (length_b&0x07);
if(length_b+1>64*8-64){
bmw_small_nextBlock(ctx, buffer);
memset(buffer, 0, 64-8);
bmw_small_nextBlock(ctx, buffer.v8);
memset(buffer.v8, 0, 64-8);
ctx->counter -= 1;
}
*((uint64_t*)&(buffer[64-8])) = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b;
bmw_small_nextBlock(ctx, buffer);
buffer.v64[7] = (uint64_t)(ctx->counter*512LL)+(uint64_t)length_b;
bmw_small_nextBlock(ctx, buffer.v8);
uint8_t i;
uint32_t q[32];
memset(buffer, 0xaa, 64);
memset(buffer.v8, 0xaa, 64);
for(i=0; i<16;++i){
buffer[i*4] = i+0xa0;
buffer.v8[i*4] = i+0xa0;
}
// dump_x(buffer, 16, 'A');
// dump_x(buffer.v8, 16, 'A');
dump_x(ctx->h, 16, 'M');
bmw_small_f0(q, (uint32_t*)buffer, ctx->h);
dump_x(buffer, 16, 'a');
bmw_small_f0(q, buffer.v32, ctx->h);
dump_x(buffer.v8, 16, 'a');
dump_x(q, 16, 'Q');
bmw_small_f1(q, ctx->h, (uint32_t*)buffer);
bmw_small_f1(q, ctx->h, buffer.v32);
dump_x(q, 32, 'Q');
bmw_small_f2((uint32_t*)buffer, q, ctx->h);
memcpy(ctx->h, buffer, 64);
bmw_small_f2(buffer.v32, q, ctx->h);
memcpy(ctx->h, buffer.v8, 64);
}
void bmw224_init(bmw224_ctx_t* ctx){

34
host/rsa_oaep_check.rb → host/rsaes_oaep_check.rb

@ -1,5 +1,5 @@
#!/usr/bin/ruby
# rsa_oaep_check.rb
# rsaes_oaep_check.rb
=begin
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
@ -353,7 +353,7 @@ end
########################################
opts = Getopt::Std.getopts("dc:f:il:s:")
opts = Getopt::Std.getopts("dc:f:il:s:n:")
conf = Hash.new
conf = readconfigfile("/etc/testport.conf", conf)
@ -397,10 +397,38 @@ else
sv = 1
end
if opts['l']
if opts['l'] && ! opts['n']
$logfile = File.open(opts['l'], 'w')
end
base_name = 'rsaes_oaep'
if opts['n']
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
if File.exists?(logfilename)
i=1
begin
logfilename = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i, '.txt')
i+=1
end while(File.exists?(logfilename))
while(i>2) do
n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-2, '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
i-=1
end
n1 = sprintf('%s%s', conf['PORT']['testlogbase'], base_name + '_' + opts['n'] + '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', 1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
end
printf("logging to %s", logfilename)
$logfile = File.open(logfilename, 'w')
end
$logfile = STDOUT if ! $logfile
$logfile.sync = true
reset_system()

73
host/rsa_pkcs15_check.rb → host/rsaes_pkcs1v15_check.rb

@ -1,5 +1,5 @@
#!/usr/bin/ruby
# rsa_pkcs15_check.rb
# rsaes_pkcs1v15_check.rb
=begin
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
@ -21,10 +21,12 @@
require 'rubygems'
require 'serialport'
require 'getopt/std'
require 'fileutils'
$buffer_size = 0 # set automatically in init_system
$conffile_check = Hash.new
$conffile_check.default = 0
$progress_dots = false
$debug = false
$logfile = nil
@ -94,10 +96,15 @@ end
def read_block(f)
d = Array.new
begin
v = false
l = f.gets
x = l.split.collect { |e| e.to_i(16) }
# x = l.split.collect { |e| e.to_i(16) }
t = l.split
t.each { |e| v = true if e.length != 2 }
x = []
x = t.collect { |e| e.to_i(16) } if ! v
d += x
end while x.length == 16
end while x.length == 16 && ! v
return d
end
@ -238,7 +245,7 @@ def load_bigint(d)
if i % 60 == 0
# we should now wait for incomming dot
wait_for_dot()
print('.')
print('.') if $progress_dots
end
end
end
@ -300,7 +307,11 @@ def check_tv(tv)
test_enc = ''
loop do
l = read_line_from_device()
break if ! /([0-9A-Fa-f]{2}\s*)+/.match(l)
t = l.split
v = false
t.each { |e| v = true if e.length != 2 }
x = t.collect { |e| e.to_i(16) }
break if v
test_enc += l if l
end
test_enc_a = Array.new
@ -329,9 +340,23 @@ end
########################################
# MAIN
########################################
opts = Getopt::Std.getopts('dc:f:il:s:')
help_text = <<EOF
Usage of 'rsaes_pkcs1v15_check':
>ruby rsaes_pkcs1v15_check -f <file> [-c <file>] [-s <a>.<b>] [-n <name> | -l <file>]
-d enable debugging (logging all received text, not only responses)
-c <file> use <file> as configuration file
-f <file> read testvectors from <file>
-s <a>.<b> start with testvector <a>.<b>
-n <name> log to a file which name is based on <name>
EOF
opts = Getopt::Std.getopts('dc:f:l:s:n:')
if !opts['f']
print help_text
exit 0
end
conf = Hash.new
conf = readconfigfile("/etc/testport.conf", conf)
@ -367,14 +392,42 @@ $sp.flow_control = SerialPort::SOFT
$debug = true if opts['d']
if opts['l']
if opts['l'] && ! opts['n']
$logfile = File.open(opts['l'], 'w')
end
base_name = 'rsaes_pkcs1v15'
if opts['n']
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
if File.exists?(logfilename)
i=1
begin
logfilename = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_',i,'.txt')
i+=1
end while(File.exists?(logfilename))
while(i>2) do
n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-2, '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
i-=1
end
n1 = sprintf('%s%s', conf['PORT']['testlogbase'], base_name + '_' + opts['n'] + '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', 1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
end
printf("logging to %s", logfilename)
$logfile = File.open(logfilename, 'w')
end
$logfile = STDOUT if ! $logfile
$logfile.sync = true
reset_system()
if opts['s'] && m = opts['s'].match(/([\d]+\.([\d]+))/)
if opts['s'] && ( m = opts['s'].match(/([\d]+)\.([\d]+)/) )
sk = m[1].to_i
sv = m[2].to_i
else

440
host/rsassa_pkcs1v15_check.rb

@ -0,0 +1,440 @@
#!/usr/bin/ruby
# rsassa_pkcs1v15_check.rb
=begin
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.
=end
require 'rubygems'
require 'serialport'
require 'getopt/std'
require 'fileutils'
$buffer_size = 0 # set automatically in init_system
$conffile_check = Hash.new
$conffile_check.default = 0
$debug = false
$progress_dots = false
$logfile = nil
################################################################################
# readconfigfile #
################################################################################
def read_line_from_device()
repeat_counter = 10000
l = nil
s = ''
begin
l = $sp.gets()
repeat_counter -= 1
end while !l && repeat_counter > 0
t = Time.new
$logfile.printf("DBG: (%02d:%02d:%02d)<< %s\n", t.hour, t.min, t.sec, l.inspect) if $debug
if l && l.include?("AVR-Crypto-Lib")
$logfile.printf("DBG: system crashed !!!\n")
exit(false)
end
return l
end
def readconfigfile(fname, conf)
return conf if $conffile_check[fname]==1
$conffile_check[fname]=1
section = "default"
if not File.exists?(fname)
return conf
end
file = File.open(fname, "r")
until file.eof
line = file.gets()
next if /[\s]*#/.match(line)
if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line)
section=m[1]
conf[m[1]] = Hash.new
next
end
next if ! /=/.match(line)
m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
if m[1]=="include"
Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
else
conf[section][m[1]] = m[2]
end
end
file.close()
return conf
end
################################################################################
# reset_system #
################################################################################
def reset_system
$sp.print("\r")
sleep 0.1
$sp.print("\r")
sleep 0.1
$sp.print("echo off\r")
sleep 0.1
end
def read_block(f)
d = Array.new
begin
v = false
l = f.gets
# x = l.split.collect { |e| e.to_i(16) }
t = l.split
t.each { |e| v = true if e.length != 2 }
x = []
x = t.collect { |e| e.to_i(16) } if ! v
d += x
end while x.length == 16 && ! v
return d
end
=begin
# Modulus:
# Exponent:
# Modulus:
# Public exponent:
# Exponent:
# Prime 1:
# Prime 2:
# Prime exponent 1:
# Prime exponent 2:
# Coefficient:
# Message:
# Seed:
# Encryption:
=end
def get_next_block(f)
ret = Hash.new
data = Array.new
begin
l = f.gets
end while l && ! m= l.match(/^#[\s](.*):[\s]*$/)
return nil if ! l
ret['tag'] = m[1]
ret['line'] = f.lineno
data = read_block(f)
ret['data'] = data
return ret
end
$key_sequence = [
'Modulus', # 0
'Exponent', # 1
'Modulus', # 2
'Public exponent', # 3
'Exponent', # 4
'Prime 1', # 5
'Prime 2', # 6
'Prime exponent 1', # 7
'Prime exponent 2', # 8
'Coefficient', # 9
]
def key_consitency_check(k)
return true
end
def process_file(f, skip_key=1, skip_vec=1)
a = get_next_block(f)
key_no = 0
ok_counter = 0
fail_counter = 0
begin
if !a || ! a['tag'] == 'Modulus'
printf("ERROR: a = %s %d\n", a.inspect, __LINE__)
return
end
k_seq = Array.new
k_seq[0] = a
(1..($key_sequence.length-1)).each do |i|
a = get_next_block(f)
if ! a || a['tag'] != $key_sequence[i]
printf("ERROR: (expecting: %s) a = %s %d\n", $key_sequence[i], a.inspect, __LINE__)
end
k_seq[i] = a
end
key = convert_key(k_seq)
printf("ERROR: %d\n", __LINE__) if ! key
key_no += 1
vec_no = 0
printf("\n run %3d: ", key_no)
skip_key_flag = (key_no < skip_key)
load_key(key) if ! skip_key_flag
test_seq = Array.new
a = get_next_block(f)
printf("ERROR: %d\n", __LINE__) if ! a
begin
vec_no += 1
b = get_next_block(f)
tv = Hash.new
tv['msg'] = a['data']
tv['sign'] = b['data']
skip_vec_flag = (skip_key_flag || (key_no == skip_key && vec_no < skip_vec))
if skip_vec_flag
printf('o')
else
v = check_tv(tv)
if(v == true)
printf('*')
$logfile.printf("[[Test %2d.%02d = OK]]\n", key_no, vec_no)
ok_counter += 1
else
printf('%c', v ? '*' : '!')
$logfile.printf("[[Test %2d.%02d = FAIL]]\n", key_no, vec_no)
fail_counter += 1
end
end
a = get_next_block(f)
end while a && a['tag'] == 'Message to be signed'
end while a && a['tag'] = 'Modulus'
# printf("\nResult: %d OK / %d FAIL ==> %s \nFinished\n", ok_counter, fail_counter, fail_counter==0 ? ':-)' : ':-(')
return ok_counter,fail_counter
end
def convert_key(k_seq)
l = ['n', 'e', 'd', 'p', 'q', 'dP', 'dQ', 'qInv']
r = Hash.new
return nil if k_seq[0]['data'] != k_seq[2]['data']
return nil if k_seq[1]['data'] != k_seq[3]['data']
8.times do |i|
r[l[i]] = k_seq[2 + i]['data']
end
return r
end
def wait_for_dot
begin
s = $sp.gets()
end while !s || !s.include?('.')
end
def load_bigint(d)
$sp.printf("%d\r", d.length)
while l = read_line_from_device()
break if /data:/.match(l)
end
printf "ERROR: got no answer from system!" if !l
i = 0
d.each do |e|
$sp.printf("%02x", e)
i += 1
if i % 60 == 0
# we should now wait for incomming dot
wait_for_dot()
print('.') if $progress_dots
end
end
end
def hexdump(a)
i = 0
a.each do |e|
printf("\n\t") if i % 16 == 0
printf('%02x ', e)
i += 1
end
puts('') if i % 16 != 1
end
def str_hexdump(a)
i = 0
s = ''
a.each do |e|
s += "\n\t" if i % 16 == 0
s += sprintf('%02x ', e)
i += 1
end
s += "\n" if i % 16 != 1
return s
end
def load_key(k)
$sp.print("load-key\r")
sleep 0.1
v = ['n', 'e', 'p', 'q', 'dP', 'dQ', 'qInv']
v.each do |e|
load_bigint(k[e])
$logfile.printf("DBG: loaded %s\n", e) if $debug
end
while l = read_line_from_device()
break if />/.match(l)
end
end
def strip_leading_zeros(a)
loop do
return [] if a.length == 0
return a if a[0] != 0
a.delete_at(0)
end
end
def check_tv(tv)
sleep 0.1
$sp.print("sha1-test\r")
sleep 0.1
load_bigint(tv['msg'])
$logfile.printf("DBG: loaded %s\n", 'msg') if $debug
sleep 0.1
while l = read_line_from_device()
break if /signature:/.match(l)
end
test_sign = ''
loop do
l = read_line_from_device()
t = l.split
v = false
t.each { |e| v = true if e.length != 2 }
x = t.collect { |e| e.to_i(16) }
break if v
test_sign += l if l
end
test_sign_a = Array.new
test_sign = test_sign.split(/[\W\r\n]+/)
test_sign.each do |e|
v = e.sub(/[^0-9A-Fa-f]/, '')
test_sign_a << v if v.length == 2
end
test_sign_a.collect!{ |e| e.to_i(16) }
strip_leading_zeros(test_sign_a)
strip_leading_zeros(tv['sign'])
sign_ok = (test_sign_a == tv['sign'])
if !sign_ok
$logfile.printf("DBG: ref = %s test = %s\n", str_hexdump(tv['sign']) , str_hexdump(test_sign_a))
end
m = nil
loop do
l = read_line_from_device()
m = /(>>OK<<|ERROR)/.match(l)
break if m
end
return true if sign_ok && (m[1] == '>>OK<<')
return false
end
########################################
# MAIN
########################################
help_text = <<EOF
Usage of 'rsassa_pkcs1v15_check':
>ruby rsassa_pkcs1v15_check -f <file> [-c <file>] [-s <a>.<b>] [-n <name> | -l <file>]
-d enable debugging (logging all received text, not only responses)
-c <file> use <file> as configuration file
-f <file> read testvectors from <file>
-s <a>.<b> start with testvector <a>.<b>
-n <name> log to a file which name is based on <name>
EOF
opts = Getopt::Std.getopts('dc:f:l:s:n:')
if !opts['f']
print help_text
exit 0
end
conf = Hash.new
conf = readconfigfile("/etc/testport.conf", conf)
conf = readconfigfile("~/.testport.conf", conf)
conf = readconfigfile("testport.conf", conf)
conf = readconfigfile(opts["c"], conf) if opts["c"]
#puts conf.inspect
puts("serial port interface version: " + SerialPort::VERSION);
$linewidth = 64
params = { "baud" => conf["PORT"]["baud"].to_i,
"data_bits" => conf["PORT"]["databits"].to_i,
"stop_bits" => conf["PORT"]["stopbits"].to_i,
"parity" => SerialPort::NONE }
params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd"
params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even"
params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark"
params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
puts("\nPort: "+conf["PORT"]["port"]+"@" +
params["baud"].to_s +
" " +
params["data_bits"].to_s +
conf["PORT"]["paraty"][0,1].upcase +
params["stop_bits"].to_s +
"\n")
$sp = SerialPort.new(conf["PORT"]["port"], params)
$sp.read_timeout=1000; # 5 minutes
$sp.flow_control = SerialPort::SOFT
$debug = true if opts['d']
if opts['l'] && ! opts['n']
$logfile = File.open(opts['l'], 'w')
end
base_name = 'rsassa_pkcs1v15'
if opts['n']
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
if File.exists?(logfilename)
i=1
begin
logfilename = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i, '.txt')
i+=1
end while(File.exists?(logfilename))
while(i>2) do
n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-2, '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', i-1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
i-=1
end
n1 = sprintf('%s%s', conf['PORT']['testlogbase'], base_name + '_' + opts['n'] + '.txt')
n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '_', 1, '.txt')
File.rename(n1, n2)
printf("%s -> %s\n", n1, n2)
logfilename = conf['PORT']['testlogbase'] + base_name + '_' + opts['n'] + '.txt'
end
printf("logging to %s", logfilename)
$logfile = File.open(logfilename, 'w')
end
$logfile = STDOUT if ! $logfile
$logfile.sync = true
reset_system()
if opts['s'] && ( m = opts['s'].match(/([\d]+)\.([\d]+)/) )
sk = m[1].to_i
sv = m[2].to_i
else
sk = 1
sv = 1
end
f = File.open(opts['f'], "r")
exit if !f
ok,fail = process_file(f,sk,sv)
printf("\nOK: %d FAIL: %d :-%s\n",ok,fail, fail==0 ? ')':'(')

24
host/shavs_test2.rb

@ -241,12 +241,13 @@ end
# -f <file> also read config from <file>
# -i <n> skip until test nr. <n>
# -j <n> start with testfile <n>
# -o use just one testfile
# -h ???
# -d enable debug mode
# -c ???
# -a ???
opts = Getopt::Std.getopts("s:f:i:j:hdca")
opts = Getopt::Std.getopts("s:f:i:j:hdcao")
conf = Hash.new
conf = readconfigfile("/etc/testport.conf", conf)
@ -306,16 +307,16 @@ algo_tasks.each do |algoa|
puts("No test-set defined for #{algo} \r\n")
next
else
i=0
i = opts["j"].to_i if opts["j"]
logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a")
while conf[algo]["file_#{i}"] != nil
puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
reset_system()
init_system(algoa[1])
skip=0
skip=opts["i"].to_i if opts["i"]
nerrors=run_test(conf[algo]["file_#{i}"], skip)
i=0
i = opts["j"].to_i if opts["j"]
logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a")
while conf[algo]["file_#{i}"] != nil
puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
reset_system()
init_system(algoa[1])
skip=0
skip=opts["i"].to_i if opts["i"]
nerrors=run_test(conf[algo]["file_#{i}"], skip)
if nerrors == 0
puts("\n[ok]")
logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
@ -324,6 +325,7 @@ algo_tasks.each do |algoa|
logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
end
i = i+1
break if opts["o"]
end
logfile.close()
end

6
jh/jh_simple_speed_core.c

@ -33,15 +33,15 @@
static
void jh_round(uint8_t* a, uint8_t roundno){
uint8_t b[128];
uint8_t i,r,u,v,x,y;
uint8_t i,r=0,u,v,x,y;
const uint8_t *pr;
pr = jh_round_const + 32*roundno;
for(i=0; i<128; ++i){
if(i%4==0){
r = *pr++;
}
b[i]=jh_lutbox[((r&0xC0)<<2)|a[i]];
r<<=2;
b[i] = jh_lutbox[((r&0xC0)<<2)|a[i]];
r <<= 2;
}
for(i=0;i<128;++i){
u = jh_permutation_table[2*i];

23
md5/md5.c

@ -81,7 +81,7 @@ void md5_core(uint32_t* a, void* block, uint8_t as, uint8_t s, uint8_t i, uint8_
cli_hexdump(&i, 1); cli_putc(']');
#endif
t = a[as] + funcs[fi](a[(as+1)&3], a[(as+2)&3], a[(as+3)&3])
+ *((uint32_t*)block) + pgm_read_dword(md5_T+i) ;
+ *((uint32_t*)block) + md5_T[i] ;
a[as]=a[(as+1)&3] + ROTL32(t, s);
}
@ -139,32 +139,35 @@ void md5_nextBlock(md5_ctx_t *state, const void* block){
void md5_lastBlock(md5_ctx_t *state, const void* block, uint16_t length_b){
uint16_t l;
uint8_t b[64];
union {
uint8_t v8[64];
uint64_t v64[ 8];
} buffer;
while (length_b >= 512){
md5_nextBlock(state, block);
length_b -= 512;
block = ((uint8_t*)block) + 512/8;
}
memset(b, 0, 64);
memcpy(b, block, length_b/8);
memset(buffer.v8, 0, 64);
memcpy(buffer.v8, block, length_b/8);
/* insert padding one */
l=length_b/8;
if(length_b%8){
uint8_t t;
t = ((uint8_t*)block)[l];
t |= (0x80>>(length_b%8));
b[l]=t;
buffer.v8[l]=t;
}else{
b[l]=0x80;
buffer.v8[l]=0x80;
}
/* insert length value */
if(l+sizeof(uint64_t) >= 512/8){
md5_nextBlock(state, b);
md5_nextBlock(state, buffer.v8);
state->counter--;
memset(b, 0, 64-8);
memset(buffer.v8, 0, 64-8);
}
*((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length_b;
md5_nextBlock(state, b);
buffer.v64[7] = (state->counter * 512) + length_b;
md5_nextBlock(state, buffer.v8);
}
void md5_ctx2hash(md5_hash_t* dest, const md5_ctx_t* state){

36
md5/md5_sbox.c

@ -0,0 +1,36 @@
/* md5_sbox.c */
/*
This file is part of the ARM-Crypto-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 <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
const uint32_t md5_T[] = {
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf,
0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af,
0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e,
0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6,
0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8,
0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122,
0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039,
0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97,
0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d,
0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 };

16