mirror of https://github.com/wolfSSL/wolfssl.git
added the cammelia cipher, updated the test cases
parent
b8b968d77f
commit
2e2de4cf4d
|
@ -249,7 +249,7 @@ void bench_camellia(void)
|
||||||
double start, total, persec;
|
double start, total, persec;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
CamelliaSetKey(&cam, key, 16, iv, CAMELLIA_ENCRYPTION);
|
CamelliaSetKey(&cam, key, 16, iv);
|
||||||
start = current_time();
|
start = current_time();
|
||||||
|
|
||||||
for(i = 0; i < megs; i++)
|
for(i = 0; i < megs; i++)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1691,7 +1691,7 @@ int aesccm_test(void)
|
||||||
#ifdef HAVE_CAMELLIA
|
#ifdef HAVE_CAMELLIA
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CAM_ECB, CAM_CBC
|
CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1701,8 +1701,7 @@ typedef struct {
|
||||||
const byte* ciphertext;
|
const byte* ciphertext;
|
||||||
const byte* key;
|
const byte* key;
|
||||||
word32 keySz;
|
word32 keySz;
|
||||||
int cipherErrorCode;
|
int errorCode;
|
||||||
int plainErrorCode;
|
|
||||||
} test_vector_t;
|
} test_vector_t;
|
||||||
|
|
||||||
int camellia_test(void)
|
int camellia_test(void)
|
||||||
|
@ -1809,19 +1808,23 @@ int camellia_test(void)
|
||||||
0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
|
0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
|
||||||
};
|
};
|
||||||
|
|
||||||
byte c[CAMELLIA_BLOCK_SIZE];
|
byte out[CAMELLIA_BLOCK_SIZE];
|
||||||
byte p[CAMELLIA_BLOCK_SIZE];
|
Camellia cam;
|
||||||
Camellia enc;
|
|
||||||
Camellia dec;
|
|
||||||
int i, testsSz;
|
int i, testsSz;
|
||||||
const test_vector_t testVectors[] =
|
const test_vector_t testVectors[] =
|
||||||
{
|
{
|
||||||
{CAM_ECB, pte, ive, c1, k1, sizeof(k1), -114, -115},
|
{CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
|
||||||
{CAM_ECB, pte, ive, c2, k2, sizeof(k2), -116, -117},
|
{CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
|
||||||
{CAM_ECB, pte, ive, c3, k3, sizeof(k3), -118, -119},
|
{CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
|
||||||
{CAM_CBC, ptc, ivc, c4, k4, sizeof(k4), -120, -121},
|
{CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
|
||||||
{CAM_CBC, ptc, ivc, c5, k5, sizeof(k5), -121, -122},
|
{CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
|
||||||
{CAM_CBC, ptc, ivc, c6, k6, sizeof(k6), -122, -123}
|
{CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
|
||||||
|
{CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
|
||||||
|
{CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
|
||||||
|
{CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
|
||||||
|
{CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
|
||||||
|
{CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
|
||||||
|
{CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((sizeof(pte) != CAMELLIA_BLOCK_SIZE) ||
|
if ((sizeof(pte) != CAMELLIA_BLOCK_SIZE) ||
|
||||||
|
@ -1830,38 +1833,45 @@ int camellia_test(void)
|
||||||
|
|
||||||
testsSz = sizeof(testVectors)/sizeof(test_vector_t);
|
testsSz = sizeof(testVectors)/sizeof(test_vector_t);
|
||||||
for (i = 0; i < testsSz; i++) {
|
for (i = 0; i < testsSz; i++) {
|
||||||
XMEMSET(c, 0, CAMELLIA_BLOCK_SIZE);
|
CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
|
||||||
XMEMSET(p, 0, CAMELLIA_BLOCK_SIZE);
|
testVectors[i].iv);
|
||||||
CamelliaSetKey(&enc, testVectors[i].key, testVectors[i].keySz,
|
|
||||||
testVectors[i].iv, CAMELLIA_ENCRYPTION);
|
|
||||||
CamelliaSetKey(&dec, testVectors[i].key, testVectors[i].keySz,
|
|
||||||
testVectors[i].iv, CAMELLIA_DECRYPTION);
|
|
||||||
|
|
||||||
if (testVectors[i].type == CAM_ECB) {
|
switch (testVectors[i].type) {
|
||||||
CamelliaEncryptDirect(&enc, c, testVectors[i].plaintext);
|
case CAM_ECB_ENC:
|
||||||
CamelliaDecryptDirect(&dec, p, testVectors[i].ciphertext);
|
CamelliaEncryptDirect(&cam, out, testVectors[i].plaintext);
|
||||||
}
|
if (memcmp(out, testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE))
|
||||||
else {
|
return testVectors[i].errorCode;
|
||||||
CamelliaCbcEncrypt(&enc, c, testVectors[i].plaintext,
|
break;
|
||||||
|
case CAM_ECB_DEC:
|
||||||
|
CamelliaDecryptDirect(&cam, out, testVectors[i].ciphertext);
|
||||||
|
if (memcmp(out, testVectors[i].plaintext, CAMELLIA_BLOCK_SIZE))
|
||||||
|
return testVectors[i].errorCode;
|
||||||
|
break;
|
||||||
|
case CAM_CBC_ENC:
|
||||||
|
CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
|
||||||
CAMELLIA_BLOCK_SIZE);
|
CAMELLIA_BLOCK_SIZE);
|
||||||
CamelliaCbcDecrypt(&dec, p, testVectors[i].ciphertext,
|
if (memcmp(out, testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE))
|
||||||
|
return testVectors[i].errorCode;
|
||||||
|
break;
|
||||||
|
case CAM_CBC_DEC:
|
||||||
|
CamelliaCbcDecrypt(&cam, out, testVectors[i].ciphertext,
|
||||||
CAMELLIA_BLOCK_SIZE);
|
CAMELLIA_BLOCK_SIZE);
|
||||||
|
if (memcmp(out, testVectors[i].plaintext, CAMELLIA_BLOCK_SIZE))
|
||||||
|
return testVectors[i].errorCode;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(c, testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE))
|
|
||||||
return testVectors[i].cipherErrorCode;
|
|
||||||
if (memcmp(p, testVectors[i].plaintext, CAMELLIA_BLOCK_SIZE))
|
|
||||||
return testVectors[i].plainErrorCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setting the IV and checking it was actually set. */
|
/* Setting the IV and checking it was actually set. */
|
||||||
CamelliaSetIV(&enc, ivc);
|
CamelliaSetIV(&cam, ivc);
|
||||||
if (XMEMCMP(enc.reg, ivc, CAMELLIA_BLOCK_SIZE))
|
if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Setting the IV to NULL should leave the IV unchanged */
|
/* Setting the IV to NULL should leave the IV unchanged */
|
||||||
if (CamelliaSetIV(&enc, NULL) != 0 ||
|
if (CamelliaSetIV(&cam, NULL) != 0 ||
|
||||||
XMEMCMP(enc.reg, ivc, CAMELLIA_BLOCK_SIZE))
|
XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* First parameter should never be null */
|
/* First parameter should never be null */
|
||||||
|
@ -1869,11 +1879,11 @@ int camellia_test(void)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* First parameter should never be null, check it fails */
|
/* First parameter should never be null, check it fails */
|
||||||
if (CamelliaSetKey(NULL, k1, sizeof(k1), NULL, CAMELLIA_ENCRYPTION) == 0)
|
if (CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Key should have a size of 16, 24, or 32 */
|
/* Key should have a size of 16, 24, or 32 */
|
||||||
if (CamelliaSetKey(&enc, k1, 0, NULL, CAMELLIA_ENCRYPTION) == 0)
|
if (CamelliaSetKey(&cam, k1, 0, NULL) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,3 +1,30 @@
|
||||||
|
/* camellia.h ver 1.2.0
|
||||||
|
*
|
||||||
|
* Copyright (c) 2006,2007
|
||||||
|
* NTT (Nippon Telegraph and Telephone Corporation) . All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer as
|
||||||
|
* the first lines of this file unmodified.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY NTT ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL NTT BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
/* camellia.h
|
/* camellia.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Sawtooth Consulting Ltd.
|
* Copyright (C) 2006-2013 Sawtooth Consulting Ltd.
|
||||||
|
@ -33,24 +60,24 @@
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CAMELLIA_ENCRYPTION = 0,
|
CAMELLIA_BLOCK_SIZE = 16
|
||||||
CAMELLIA_DECRYPTION = 1,
|
|
||||||
CAMELLIA_BLOCK_SIZE = 16,
|
|
||||||
CAMELLIA_KEY_128_BITS = 16,
|
|
||||||
CAMELLIA_KEY_192_BITS = 24,
|
|
||||||
CAMELLIA_KEY_256_BITS = 32
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define CAMELLIA_TABLE_BYTE_LEN 272
|
||||||
|
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / sizeof(word32))
|
||||||
|
|
||||||
|
typedef word32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
|
||||||
|
|
||||||
typedef struct Camellia {
|
typedef struct Camellia {
|
||||||
word32 keySz;
|
word32 keySz;
|
||||||
|
KEY_TABLE_TYPE key;
|
||||||
word32 reg[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
word32 reg[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
word32 tmp[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
word32 tmp[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
} Camellia;
|
} Camellia;
|
||||||
|
|
||||||
|
|
||||||
CYASSL_API int CamelliaSetKey(Camellia* cam,
|
CYASSL_API int CamelliaSetKey(Camellia* cam,
|
||||||
const byte* key, word32 len, const byte* iv, int dir);
|
const byte* key, word32 len, const byte* iv);
|
||||||
CYASSL_API int CamelliaSetIV(Camellia* cam, const byte* iv);
|
CYASSL_API int CamelliaSetIV(Camellia* cam, const byte* iv);
|
||||||
CYASSL_API void CamelliaEncryptDirect(Camellia* cam, byte* out, const byte* in);
|
CYASSL_API void CamelliaEncryptDirect(Camellia* cam, byte* out, const byte* in);
|
||||||
CYASSL_API void CamelliaDecryptDirect(Camellia* cam, byte* out, const byte* in);
|
CYASSL_API void CamelliaDecryptDirect(Camellia* cam, byte* out, const byte* in);
|
||||||
|
|
Loading…
Reference in New Issue