00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "mem.h"
00022 #include "whirlpool.h"
00023
00024 void whirlpool_finalize(whirlpool_t * const context,
00025 unsigned char * const result)
00026 {
00027 int i;
00028 uint8_t *buf = context->buf;
00029 uint8_t *len = context->len;
00030 int bits = context->bits;
00031 int pos = context->pos;
00032 uint8_t *digest = result;
00033
00034
00035 buf[pos] |= 0x80U >> (bits & 7);
00036 pos++;
00037
00038
00039 if (pos > WBLOCKBYTES - LENGTHBYTES) {
00040 if (pos < WBLOCKBYTES)
00041 mem_set(&buf[pos], 0, WBLOCKBYTES - pos);
00042
00043
00044 whirlpool_transform(context);
00045
00046
00047 pos = 0;
00048 }
00049
00050 if (pos < WBLOCKBYTES - LENGTHBYTES)
00051 mem_set(&buf[pos], 0, (WBLOCKBYTES - LENGTHBYTES) - pos);
00052
00053 pos = WBLOCKBYTES - LENGTHBYTES;
00054
00055
00056 mem_cpy(&buf[WBLOCKBYTES - LENGTHBYTES], len, LENGTHBYTES);
00057
00058
00059 whirlpool_transform(context);
00060
00061
00062 for (i = 0; i < DIGESTBYTES/8; i++) {
00063 digest[0] = (uint8_t)(context->hash[i] >> 56);
00064 digest[1] = (uint8_t)(context->hash[i] >> 48);
00065 digest[2] = (uint8_t)(context->hash[i] >> 40);
00066 digest[3] = (uint8_t)(context->hash[i] >> 32);
00067 digest[4] = (uint8_t)(context->hash[i] >> 24);
00068 digest[5] = (uint8_t)(context->hash[i] >> 16);
00069 digest[6] = (uint8_t)(context->hash[i] >> 8);
00070 digest[7] = (uint8_t)(context->hash[i] );
00071 digest += 8;
00072 }
00073
00074 context->bits = bits;
00075 context->pos = pos;
00076 }