Feat: add detailed benchmar to reference impl

This commit is contained in:
Dorian Zedler 2022-07-20 22:26:43 +02:00
parent 48dd446638
commit d54e10fbe3
Signed by: dorian
GPG key ID: 989DE36109AFA354
2 changed files with 9 additions and 0 deletions

View file

@ -49,6 +49,8 @@ void MD2Final PROTO_LIST((unsigned char[16], MD2_CTX *));
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include "../md2_common.h"
void md2_hash_ref(size_t len, const uint8_t buf[len], uint8_t out[16]); void md2_hash_ref(size_t len, const uint8_t buf[len], uint8_t out[16]);
#endif // MD2_REF_H #endif // MD2_REF_H

View file

@ -83,6 +83,7 @@ void md2_hash_ref(size_t len, const uint8_t buf[len], uint8_t out[16]) {
MD2Init(&context); MD2Init(&context);
MD2Update(&context, buf, len); MD2Update(&context, buf, len);
MD2Final(out, &context); MD2Final(out, &context);
END_MARK
} }
/* MD2 initialization. Begins an MD2 operation, writing a new context. /* MD2 initialization. Begins an MD2 operation, writing a new context.
@ -169,23 +170,29 @@ unsigned char block[16];
*/ */
MD2_memcpy((POINTER)x, (POINTER)state, 16); MD2_memcpy((POINTER)x, (POINTER)state, 16);
MD2_memcpy((POINTER)x + 16, (POINTER)block, 16); MD2_memcpy((POINTER)x + 16, (POINTER)block, 16);
FIRST_LOOP_START_MARK
for (i = 0; i < 16; i++) x[i + 32] = state[i] ^ block[i]; for (i = 0; i < 16; i++) x[i + 32] = state[i] ^ block[i];
FIRST_LOOP_END_MARK
/* Encrypt block (18 rounds). /* Encrypt block (18 rounds).
*/ */
t = 0; t = 0;
SECOND_LOOP_START_MARK
for (i = 0; i < 18; i++) { for (i = 0; i < 18; i++) {
for (j = 0; j < 48; j++) t = x[j] ^= PI_SUBST[t]; for (j = 0; j < 48; j++) t = x[j] ^= PI_SUBST[t];
t = (t + i) & 0xff; t = (t + i) & 0xff;
} }
SECOND_LOOP_END_MARK
/* Save new state */ /* Save new state */
MD2_memcpy((POINTER)state, (POINTER)x, 16); MD2_memcpy((POINTER)state, (POINTER)x, 16);
/* Update checksum. /* Update checksum.
*/ */
CHECKSUM_START_MARK
t = checksum[15]; t = checksum[15];
for (i = 0; i < 16; i++) t = checksum[i] ^= PI_SUBST[block[i] ^ t]; for (i = 0; i < 16; i++) t = checksum[i] ^= PI_SUBST[block[i] ^ t];
CHECKSUM_END_MARK
/* Zeroize sensitive information. /* Zeroize sensitive information.
*/ */