diff --git a/ctaocrypt/src/camellia.c b/ctaocrypt/src/camellia.c index 9d35fa2e5..efdbbba8f 100644 --- a/ctaocrypt/src/camellia.c +++ b/ctaocrypt/src/camellia.c @@ -42,6 +42,20 @@ int CamelliaSetKey(Camellia* cam, (void)cam; (void)key; (void)dir; + + if (cam == NULL) return BAD_FUNC_ARG; + + switch (len) { + case CAMELLIA_KEY_128_BITS: + break; + case CAMELLIA_KEY_192_BITS: + break; + case CAMELLIA_KEY_256_BITS: + break; + default: + return BAD_FUNC_ARG; + } + cam->keySz = len; return CamelliaSetIV(cam, iv); } diff --git a/ctaocrypt/test/test.c b/ctaocrypt/test/test.c index 47bb6b431..b5fdea3e1 100644 --- a/ctaocrypt/test/test.c +++ b/ctaocrypt/test/test.c @@ -1854,6 +1854,28 @@ int camellia_test(void) return testVectors[i].plainErrorCode; } + /* Setting the IV and checking it was actually set. */ + CamelliaSetIV(&enc, ivc); + if (XMEMCMP(enc.reg, ivc, CAMELLIA_BLOCK_SIZE)) + return -1; + + /* Setting the IV to NULL should leave the IV unchanged */ + if (CamelliaSetIV(&enc, NULL) != 0 || + XMEMCMP(enc.reg, ivc, CAMELLIA_BLOCK_SIZE)) + return -1; + + /* First parameter should never be null */ + if (CamelliaSetIV(NULL, NULL) == 0) + return -1; + + /* First parameter should never be null, check it fails */ + if (CamelliaSetKey(NULL, k1, sizeof(k1), NULL, CAMELLIA_ENCRYPTION) == 0) + return -1; + + /* Key should have a size of 16, 24, or 32 */ + if (CamelliaSetKey(&enc, k1, 0, NULL, CAMELLIA_ENCRYPTION) == 0) + return -1; + return 0; } #endif /* HAVE_CAMELLIA */ diff --git a/cyassl/ctaocrypt/camellia.h b/cyassl/ctaocrypt/camellia.h index f8ba2bf99..47146a400 100644 --- a/cyassl/ctaocrypt/camellia.h +++ b/cyassl/ctaocrypt/camellia.h @@ -35,7 +35,10 @@ enum { CAMELLIA_ENCRYPTION = 0, CAMELLIA_DECRYPTION = 1, - CAMELLIA_BLOCK_SIZE = 16 + CAMELLIA_BLOCK_SIZE = 16, + CAMELLIA_KEY_128_BITS = 16, + CAMELLIA_KEY_192_BITS = 24, + CAMELLIA_KEY_256_BITS = 32 };