diff options
author | gnn <gnn@FreeBSD.org> | 2007-05-09 19:37:02 +0000 |
---|---|---|
committer | gnn <gnn@FreeBSD.org> | 2007-05-09 19:37:02 +0000 |
commit | 38b76f06232a188e2b053370458b6901b745948b (patch) | |
tree | ab6a97da261f87bb2e97c008d467da3311010b9e /sys/opencrypto | |
parent | 4941ee4a2accc1d1a5d38148ec1378487b9e1cf0 (diff) | |
download | FreeBSD-src-38b76f06232a188e2b053370458b6901b745948b.zip FreeBSD-src-38b76f06232a188e2b053370458b6901b745948b.tar.gz |
Integrate the Camellia Block Cipher. For more information see RFC 4132
and its bibliography.
Submitted by: Tomoyuki Okazaki <okazaki at kick dot gr dot jp>
MFC after: 1 month
Diffstat (limited to 'sys/opencrypto')
-rw-r--r-- | sys/opencrypto/cryptodev.c | 3 | ||||
-rw-r--r-- | sys/opencrypto/cryptodev.h | 4 | ||||
-rw-r--r-- | sys/opencrypto/cryptosoft.c | 6 | ||||
-rw-r--r-- | sys/opencrypto/xform.c | 53 | ||||
-rw-r--r-- | sys/opencrypto/xform.h | 1 |
5 files changed, 66 insertions, 1 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c index 15a207b..03071e0 100644 --- a/sys/opencrypto/cryptodev.c +++ b/sys/opencrypto/cryptodev.c @@ -198,6 +198,9 @@ cryptof_ioctl( case CRYPTO_ARC4: txform = &enc_xform_arc4; break; + case CRYPTO_CAMELLIA_CBC: + txform = &enc_xform_camellia; + break; default: return (EINVAL); } diff --git a/sys/opencrypto/cryptodev.h b/sys/opencrypto/cryptodev.h index 39fbf37..afd79c8 100644 --- a/sys/opencrypto/cryptodev.h +++ b/sys/opencrypto/cryptodev.h @@ -97,6 +97,7 @@ #define CAST128_BLOCK_LEN 8 #define RIJNDAEL128_BLOCK_LEN 16 #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN +#define CAMELLIA_BLOCK_LEN 16 #define EALG_MAX_BLOCK_LEN AES_BLOCK_LEN /* Keep this updated */ #define CRYPTO_ALGORITHM_MIN 1 @@ -121,7 +122,8 @@ #define CRYPTO_SHA2_256_HMAC 18 #define CRYPTO_SHA2_384_HMAC 19 #define CRYPTO_SHA2_512_HMAC 20 -#define CRYPTO_ALGORITHM_MAX 20 /* Keep updated - see below */ +#define CRYPTO_CAMELLIA_CBC 21 +#define CRYPTO_ALGORITHM_MAX 21 /* Keep updated - see below */ /* Algorithm flags */ #define CRYPTO_ALG_FLAG_SUPPORTED 0x01 /* Algorithm is supported */ diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index 9de2350..ba83718 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -661,6 +661,9 @@ swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri) case CRYPTO_RIJNDAEL128_CBC: txf = &enc_xform_rijndael128; goto enccommon; + case CRYPTO_CAMELLIA_CBC: + txf = &enc_xform_camellia; + goto enccommon; case CRYPTO_NULL_CBC: txf = &enc_xform_null; goto enccommon; @@ -816,6 +819,7 @@ swcr_freesession(device_t dev, u_int64_t tid) case CRYPTO_CAST_CBC: case CRYPTO_SKIPJACK_CBC: case CRYPTO_RIJNDAEL128_CBC: + case CRYPTO_CAMELLIA_CBC: case CRYPTO_NULL_CBC: txf = swd->sw_exf; @@ -928,6 +932,7 @@ swcr_process(device_t dev, struct cryptop *crp, int hint) case CRYPTO_CAST_CBC: case CRYPTO_SKIPJACK_CBC: case CRYPTO_RIJNDAEL128_CBC: + case CRYPTO_CAMELLIA_CBC: if ((crp->crp_etype = swcr_encdec(crd, sw, crp->crp_buf, crp->crp_flags)) != 0) goto done; @@ -1019,6 +1024,7 @@ swcr_attach(device_t dev) REGISTER(CRYPTO_MD5); REGISTER(CRYPTO_SHA1); REGISTER(CRYPTO_RIJNDAEL128_CBC); + REGISTER(CRYPTO_CAMELLIA_CBC); REGISTER(CRYPTO_DEFLATE_COMP); #undef REGISTER diff --git a/sys/opencrypto/xform.c b/sys/opencrypto/xform.c index 86d56c3..464429f 100644 --- a/sys/opencrypto/xform.c +++ b/sys/opencrypto/xform.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <crypto/blowfish/blowfish.h> #include <crypto/des/des.h> #include <crypto/rijndael/rijndael.h> +#include <crypto/camellia/camellia.h> #include <crypto/sha1.h> #include <opencrypto/cast.h> @@ -74,24 +75,28 @@ static int blf_setkey(u_int8_t **, u_int8_t *, int); static int cast5_setkey(u_int8_t **, u_int8_t *, int); static int skipjack_setkey(u_int8_t **, u_int8_t *, int); static int rijndael128_setkey(u_int8_t **, u_int8_t *, int); +static int cml_setkey(u_int8_t **, u_int8_t *, int); static void des1_encrypt(caddr_t, u_int8_t *); static void des3_encrypt(caddr_t, u_int8_t *); static void blf_encrypt(caddr_t, u_int8_t *); static void cast5_encrypt(caddr_t, u_int8_t *); static void skipjack_encrypt(caddr_t, u_int8_t *); static void rijndael128_encrypt(caddr_t, u_int8_t *); +static void cml_encrypt(caddr_t, u_int8_t *); static void des1_decrypt(caddr_t, u_int8_t *); static void des3_decrypt(caddr_t, u_int8_t *); static void blf_decrypt(caddr_t, u_int8_t *); static void cast5_decrypt(caddr_t, u_int8_t *); static void skipjack_decrypt(caddr_t, u_int8_t *); static void rijndael128_decrypt(caddr_t, u_int8_t *); +static void cml_decrypt(caddr_t, u_int8_t *); static void des1_zerokey(u_int8_t **); static void des3_zerokey(u_int8_t **); static void blf_zerokey(u_int8_t **); static void cast5_zerokey(u_int8_t **); static void skipjack_zerokey(u_int8_t **); static void rijndael128_zerokey(u_int8_t **); +static void cml_zerokey(u_int8_t **); static void null_init(void *); static int null_update(void *, u_int8_t *, u_int16_t); @@ -184,6 +189,15 @@ struct enc_xform enc_xform_arc4 = { NULL, }; +struct enc_xform enc_xform_camellia = { + CRYPTO_CAMELLIA_CBC, "Camellia", + CAMELLIA_BLOCK_LEN, 8, 32, + cml_encrypt, + cml_decrypt, + cml_setkey, + cml_zerokey, +}; + /* Authentication instances */ struct auth_hash auth_hash_null = { CRYPTO_NULL_HMAC, "NULL-HMAC", @@ -533,6 +547,45 @@ rijndael128_zerokey(u_int8_t **sched) *sched = NULL; } +static void +cml_encrypt(caddr_t key, u_int8_t *blk) +{ + camellia_encrypt((camellia_ctx *) key, (u_char *) blk, (u_char *) blk); +} + +static void +cml_decrypt(caddr_t key, u_int8_t *blk) +{ + camellia_decrypt(((camellia_ctx *) key), (u_char *) blk, + (u_char *) blk); +} + +static int +cml_setkey(u_int8_t **sched, u_int8_t *key, int len) +{ + int err; + + if (len != 16 && len != 24 && len != 32) + return (EINVAL); + MALLOC(*sched, u_int8_t *, sizeof(camellia_ctx), M_CRYPTO_DATA, + M_NOWAIT|M_ZERO); + if (*sched != NULL) { + camellia_set_key((camellia_ctx *) *sched, (u_char *) key, + len * 8); + err = 0; + } else + err = ENOMEM; + return err; +} + +static void +cml_zerokey(u_int8_t **sched) +{ + bzero(*sched, sizeof(camellia_ctx)); + FREE(*sched, M_CRYPTO_DATA); + *sched = NULL; +} + /* * And now for auth. */ diff --git a/sys/opencrypto/xform.h b/sys/opencrypto/xform.h index bdf16ac..de7528b 100644 --- a/sys/opencrypto/xform.h +++ b/sys/opencrypto/xform.h @@ -81,6 +81,7 @@ extern struct enc_xform enc_xform_cast5; extern struct enc_xform enc_xform_skipjack; extern struct enc_xform enc_xform_rijndael128; extern struct enc_xform enc_xform_arc4; +extern struct enc_xform enc_xform_camellia; extern struct auth_hash auth_hash_null; extern struct auth_hash auth_hash_key_md5; |