Add Camellia
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21687 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -89,6 +89,10 @@ libhcrypto_la_SOURCES = \
|
|||||||
aes.h \
|
aes.h \
|
||||||
bn.c \
|
bn.c \
|
||||||
bn.h \
|
bn.h \
|
||||||
|
camellia.h \
|
||||||
|
camellia.c \
|
||||||
|
camellia-ntt.c \
|
||||||
|
camellia-ntt.h \
|
||||||
des-tables.h \
|
des-tables.h \
|
||||||
des.c \
|
des.c \
|
||||||
des.h \
|
des.h \
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <krb5-types.h>
|
#include <krb5-types.h>
|
||||||
|
|
||||||
#include <aes.h>
|
#include <aes.h>
|
||||||
|
#include "camellia.h"
|
||||||
#include <des.h>
|
#include <des.h>
|
||||||
#include <sha.h>
|
#include <sha.h>
|
||||||
#include <rc2.h>
|
#include <rc2.h>
|
||||||
@@ -768,6 +769,99 @@ EVP_aes_256_cbc(void)
|
|||||||
return &aes_256_cbc;
|
return &aes_256_cbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
camellia_init(EVP_CIPHER_CTX *ctx,
|
||||||
|
const unsigned char * key,
|
||||||
|
const unsigned char * iv,
|
||||||
|
int encp)
|
||||||
|
{
|
||||||
|
CAMELLIA_KEY *k = ctx->cipher_data;
|
||||||
|
k->bits = ctx->cipher->key_len * 8;
|
||||||
|
CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
camellia_do_cipher(EVP_CIPHER_CTX *ctx,
|
||||||
|
unsigned char *out,
|
||||||
|
const unsigned char *in,
|
||||||
|
unsigned int size)
|
||||||
|
{
|
||||||
|
CAMELLIA_KEY *k = ctx->cipher_data;
|
||||||
|
CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
camellia_cleanup(EVP_CIPHER_CTX *ctx)
|
||||||
|
{
|
||||||
|
memset(ctx->cipher_data, 0, sizeof(CAMELLIA_KEY));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EVP_CIPHER *
|
||||||
|
EVP_camellia_128_cbc(void)
|
||||||
|
{
|
||||||
|
static const EVP_CIPHER cipher = {
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
EVP_CIPH_CBC_MODE,
|
||||||
|
camellia_init,
|
||||||
|
camellia_do_cipher,
|
||||||
|
camellia_cleanup,
|
||||||
|
sizeof(CAMELLIA_KEY),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
return &cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EVP_CIPHER *
|
||||||
|
EVP_camellia_192_cbc(void)
|
||||||
|
{
|
||||||
|
static const EVP_CIPHER cipher = {
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
24,
|
||||||
|
16,
|
||||||
|
EVP_CIPH_CBC_MODE,
|
||||||
|
camellia_init,
|
||||||
|
camellia_do_cipher,
|
||||||
|
camellia_cleanup,
|
||||||
|
sizeof(CAMELLIA_KEY),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
return &cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EVP_CIPHER *
|
||||||
|
EVP_camellia_256_cbc(void)
|
||||||
|
{
|
||||||
|
static const EVP_CIPHER cipher = {
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
32,
|
||||||
|
16,
|
||||||
|
EVP_CIPH_CBC_MODE,
|
||||||
|
camellia_init,
|
||||||
|
camellia_do_cipher,
|
||||||
|
camellia_cleanup,
|
||||||
|
sizeof(CAMELLIA_KEY),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
return &cipher;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -779,7 +873,10 @@ static const struct cipher_name {
|
|||||||
{ "des-ede3-cbc", EVP_des_ede3_cbc },
|
{ "des-ede3-cbc", EVP_des_ede3_cbc },
|
||||||
{ "aes-128-cbc", EVP_aes_128_cbc },
|
{ "aes-128-cbc", EVP_aes_128_cbc },
|
||||||
{ "aes-192-cbc", EVP_aes_192_cbc },
|
{ "aes-192-cbc", EVP_aes_192_cbc },
|
||||||
{ "aes-256-cbc", EVP_aes_256_cbc }
|
{ "aes-256-cbc", EVP_aes_256_cbc },
|
||||||
|
{ "camellia-128-cbc", EVP_camellia_128_cbc },
|
||||||
|
{ "camellia-192-cbc", EVP_camellia_192_cbc },
|
||||||
|
{ "camellia-256-cbc", EVP_camellia_256_cbc }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -83,6 +83,9 @@
|
|||||||
#define EVP_rc2_cbc hc_EVP_rc2_cbc
|
#define EVP_rc2_cbc hc_EVP_rc2_cbc
|
||||||
#define EVP_rc4 hc_EVP_rc4
|
#define EVP_rc4 hc_EVP_rc4
|
||||||
#define EVP_rc4_40 hc_EVP_rc4_40
|
#define EVP_rc4_40 hc_EVP_rc4_40
|
||||||
|
#define EVP_camellia_128_cbc hc_EVP_camellia_128_cbc
|
||||||
|
#define EVP_camellia_192_cbc hc_EVP_camellia_192_cbc
|
||||||
|
#define EVP_camellia_256_cbc hc_EVP_camellia_256_cbc
|
||||||
#define EVP_sha hc_EVP_sha
|
#define EVP_sha hc_EVP_sha
|
||||||
#define EVP_sha1 hc_EVP_sha1
|
#define EVP_sha1 hc_EVP_sha1
|
||||||
#define EVP_sha256 hc_EVP_sha256
|
#define EVP_sha256 hc_EVP_sha256
|
||||||
@@ -180,6 +183,9 @@ const EVP_CIPHER * EVP_rc2_64_cbc(void);
|
|||||||
const EVP_CIPHER * EVP_rc2_cbc(void);
|
const EVP_CIPHER * EVP_rc2_cbc(void);
|
||||||
const EVP_CIPHER * EVP_rc4(void);
|
const EVP_CIPHER * EVP_rc4(void);
|
||||||
const EVP_CIPHER * EVP_rc4_40(void);
|
const EVP_CIPHER * EVP_rc4_40(void);
|
||||||
|
const EVP_CIPHER * EVP_camellia_128_cbc(void);
|
||||||
|
const EVP_CIPHER * EVP_camellia_192_cbc(void);
|
||||||
|
const EVP_CIPHER * EVP_camellia_256_cbc(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@@ -46,6 +46,8 @@ RCSID("$Id$");
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <evp.h>
|
#include <evp.h>
|
||||||
|
#include <hex.h>
|
||||||
|
#include <err.h>
|
||||||
|
|
||||||
struct tests {
|
struct tests {
|
||||||
void *key;
|
void *key;
|
||||||
@@ -78,7 +80,7 @@ struct tests rc2_40_tests[] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tests des_ede3_cbc_tests[] = {
|
struct tests des_ede3_tests[] = {
|
||||||
{ "1917ffe6bb772efc297643bc63567e9a002e4d431d5ffd58",
|
{ "1917ffe6bb772efc297643bc63567e9a002e4d431d5ffd58",
|
||||||
24,
|
24,
|
||||||
"\xbf\x9a\x12\xb7\x26\x69\xfd\x05",
|
"\xbf\x9a\x12\xb7\x26\x69\xfd\x05",
|
||||||
@@ -88,6 +90,16 @@ struct tests des_ede3_cbc_tests[] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct tests camellia128_tests[] = {
|
||||||
|
{ "\x19\x17\xff\xe6\xbb\x77\x2e\xfc\x29\x76\x43\xbc\x63\x56\x7e\x9a",
|
||||||
|
16,
|
||||||
|
"\x12\x13\xff\xe3\xbb\x7e\x21\xfc\xe9\x76\x44\xbc\x63\x56\x7e\xff",
|
||||||
|
16,
|
||||||
|
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||||
|
"\xf6\x1b\xa9\xa6\xed\xb2\xd3\x4e\x59\x70\xbc\x50\x4e\x89\xd7\xf5"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_cipher(const EVP_CIPHER *c, struct tests *t)
|
test_cipher(const EVP_CIPHER *c, struct tests *t)
|
||||||
@@ -110,16 +122,18 @@ test_cipher(const EVP_CIPHER *c, struct tests *t)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (memcmp(d, t->outdata, t->datasize) != 0) {
|
if (memcmp(d, t->outdata, t->datasize) != 0) {
|
||||||
printf("encrypt not the same\n");
|
char *s;
|
||||||
return 1;
|
hex_encode(d, t->datasize, &s);
|
||||||
|
errx(1, "decrypt not the same: %s\n", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EVP_Cipher(&dctx, d, d, t->datasize))
|
if (!EVP_Cipher(&dctx, d, d, t->datasize))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (memcmp(d, t->indata, t->datasize) != 0) {
|
if (memcmp(d, t->indata, t->datasize) != 0) {
|
||||||
printf("decrypt not the same\n");
|
char *s;
|
||||||
return 1;
|
hex_encode(d, t->datasize, &s);
|
||||||
|
errx(1, "decrypt not the same: %s\n", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
EVP_CIPHER_CTX_cleanup(&ectx);
|
EVP_CIPHER_CTX_cleanup(&ectx);
|
||||||
@@ -139,8 +153,10 @@ main(int argc, char **argv)
|
|||||||
ret += test_cipher(EVP_aes_256_cbc(), &aes_tests[i]);
|
ret += test_cipher(EVP_aes_256_cbc(), &aes_tests[i]);
|
||||||
for (i = 0; i < sizeof(rc2_40_tests)/sizeof(rc2_40_tests[0]); i++)
|
for (i = 0; i < sizeof(rc2_40_tests)/sizeof(rc2_40_tests[0]); i++)
|
||||||
ret += test_cipher(EVP_rc2_40_cbc(), &rc2_40_tests[i]);
|
ret += test_cipher(EVP_rc2_40_cbc(), &rc2_40_tests[i]);
|
||||||
for (i = 0; i < sizeof(rc2_40_tests)/sizeof(rc2_40_tests[0]); i++)
|
for (i = 0; i < sizeof(des_ede3_tests)/sizeof(des_ede3_tests[0]); i++)
|
||||||
ret += test_cipher(EVP_des_ede3_cbc(), &des_ede3_cbc_tests[i]);
|
ret += test_cipher(EVP_des_ede3_cbc(), &des_ede3_tests[i]);
|
||||||
|
for (i = 0; i < sizeof(camellia128_tests)/sizeof(camellia128_tests[0]); i++)
|
||||||
|
ret += test_cipher(EVP_des_ede3_cbc(), &camellia128_tests[i]);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user