arg error checking and CHACHA_AEAD_TEST update

This commit is contained in:
JacobBarthelmeh
2014-07-11 16:06:29 -06:00
parent e62fbdd49f
commit 4250955003
4 changed files with 74 additions and 29 deletions

View File

@@ -80,13 +80,16 @@ int Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter)
word32 temp[3]; /* used for alignment of memory */
XMEMSET(temp, 0, 12);
if (ctx == NULL)
return BAD_FUNC_ARG;
#ifdef CHACHA_AEAD_TEST
int k;
word32 i;
printf("NONCE : ");
for (k = 0; k < 12; k++) {
printf("%02x", nonce[k]);
for (i = 0; i < 12; i++) {
printf("%02x", inIv[i]);
}
printf("\n");
printf("\n\n");
#endif
XMEMCPY(temp, inIv, 12);
@@ -130,12 +133,14 @@ int Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz)
#endif /* XSTREAM_ALIGN */
#ifdef CHACHA_AEAD_TEST
int k;
printf("ChaCha key used : ");
for (k = 0; k < keySz; k++) {
printf("%02x", key[k]);
word32 i;
printf("ChaCha key used :\n");
for (i = 0; i < keySz; i++) {
printf("%02x", key[i]);
if ((i + 1) % 8 == 0)
printf("\n");
}
printf("\n");
printf("\n\n");
#endif
ctx->X[4] = U8TO32_LITTLE(k + 0);

View File

@@ -37,18 +37,15 @@
#else
#include <ctaocrypt/src/misc.c>
#endif
#ifdef CHACHA_AEAD_TEST
#include <stdio.h>
#endif
#ifdef _MSC_VER
/* 4127 warning constant while(1) */
#pragma warning(disable: 4127)
#endif
#ifdef BIG_ENDIAN_ORDER
#define LITTLE32(x) ByteReverseWord32(x)
#else
#define LITTLE32(x) (x)
#endif
#if defined(POLY130564)
#if defined(_MSC_VER)
@@ -254,14 +251,17 @@ static void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) {
if (keySz != 32)
return 1;
if (keySz != 32 || ctx == NULL)
return BAD_FUNC_ARG;
#ifdef CHACHA_AEAD_TEST
int k;
printf("Poly key used: ");
for (k = 0; k < keySz; k++)
word32 k;
printf("Poly key used:\n");
for (k = 0; k < keySz; k++) {
printf("%02x", key[k]);
if ((k+1) % 8 == 0)
printf("\n");
}
printf("\n");
#endif
@@ -319,6 +319,9 @@ int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) {
int Poly1305Final(Poly1305* ctx, byte* mac) {
if (ctx == NULL)
return BAD_FUNC_ARG;
#if defined(POLY130564)
word64 h0,h1,h2,c;
@@ -484,11 +487,17 @@ int Poly1305Final(Poly1305* ctx, byte* mac) {
int Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes) {
if (ctx == NULL)
return BAD_FUNC_ARG;
#ifdef CHACHA_AEAD_TEST
int k;
printf("Raw input to poly: ");
for (k = 0; k < bytes; k++)
word32 k;
printf("Raw input to poly:\n");
for (k = 0; k < bytes; k++) {
printf("%02x", m[k]);
if ((k+1) % 16 == 0)
printf("\n");
}
printf("\n");
#endif
size_t i;