Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/opencrypto support camellia-cbc by swcrypt



details:   https://anonhg.NetBSD.org/src/rev/8811021565b5
branches:  trunk
changeset: 764813:8811021565b5
user:      drochner <drochner%NetBSD.org@localhost>
date:      Thu May 05 17:44:39 2011 +0000

description:
support camellia-cbc by swcrypt

diffstat:

 sys/opencrypto/cryptosoft.c       |  10 +++++-
 sys/opencrypto/cryptosoft_xform.c |  57 +++++++++++++++++++++++++++++++++++++-
 sys/opencrypto/files.opencrypto   |   4 +-
 3 files changed, 65 insertions(+), 6 deletions(-)

diffs (186 lines):

diff -r 4b1c275f0e5a -r 8811021565b5 sys/opencrypto/cryptosoft.c
--- a/sys/opencrypto/cryptosoft.c       Thu May 05 17:42:17 2011 +0000
+++ b/sys/opencrypto/cryptosoft.c       Thu May 05 17:44:39 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cryptosoft.c,v 1.29 2011/02/25 20:13:10 drochner Exp $ */
+/*     $NetBSD: cryptosoft.c,v 1.30 2011/05/05 17:44:39 drochner Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/cryptosoft.c,v 1.2.2.1 2002/11/21 23:34:23 sam Exp $       */
 /*     $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */
 
@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.29 2011/02/25 20:13:10 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cryptosoft.c,v 1.30 2011/05/05 17:44:39 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -653,6 +653,9 @@
                case CRYPTO_RIJNDAEL128_CBC:
                        txf = &swcr_enc_xform_rijndael128;
                        goto enccommon;
+               case CRYPTO_CAMELLIA_CBC:
+                       txf = &swcr_enc_xform_camellia;
+                       goto enccommon;
                case CRYPTO_NULL_CBC:
                        txf = &swcr_enc_xform_null;
                        goto enccommon;
@@ -839,6 +842,7 @@
                case CRYPTO_CAST_CBC:
                case CRYPTO_SKIPJACK_CBC:
                case CRYPTO_RIJNDAEL128_CBC:
+               case CRYPTO_CAMELLIA_CBC:
                case CRYPTO_NULL_CBC:
                        txf = swd->sw_exf;
 
@@ -966,6 +970,7 @@
                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, type)) != 0)
                                goto done;
@@ -1032,6 +1037,7 @@
        REGISTER(CRYPTO_BLF_CBC);
        REGISTER(CRYPTO_CAST_CBC);
        REGISTER(CRYPTO_SKIPJACK_CBC);
+       REGISTER(CRYPTO_CAMELLIA_CBC);
        REGISTER(CRYPTO_NULL_CBC);
        REGISTER(CRYPTO_MD5_HMAC);
        REGISTER(CRYPTO_MD5_HMAC_96);
diff -r 4b1c275f0e5a -r 8811021565b5 sys/opencrypto/cryptosoft_xform.c
--- a/sys/opencrypto/cryptosoft_xform.c Thu May 05 17:42:17 2011 +0000
+++ b/sys/opencrypto/cryptosoft_xform.c Thu May 05 17:44:39 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cryptosoft_xform.c,v 1.14 2011/02/24 20:03:41 drochner Exp $ */
+/*     $NetBSD: cryptosoft_xform.c,v 1.15 2011/05/05 17:44:39 drochner Exp $ */
 /*     $FreeBSD: src/sys/opencrypto/xform.c,v 1.1.2.1 2002/11/21 23:34:23 sam Exp $    */
 /*     $OpenBSD: xform.c,v 1.19 2002/08/16 22:47:25 dhartmei Exp $     */
 
@@ -40,13 +40,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.14 2011/02/24 20:03:41 drochner Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cryptosoft_xform.c,v 1.15 2011/05/05 17:44:39 drochner Exp $");
 
 #include <crypto/blowfish/blowfish.h>
 #include <crypto/cast128/cast128.h>
 #include <crypto/des/des.h>
 #include <crypto/rijndael/rijndael.h>
 #include <crypto/skipjack/skipjack.h>
+#include <crypto/camellia/camellia.h>
 
 #include <opencrypto/deflate.h>
 
@@ -86,24 +87,28 @@
 static int cast5_setkey(u_int8_t **, const u_int8_t *, int);
 static  int skipjack_setkey(u_int8_t **, const u_int8_t *, int);
 static  int rijndael128_setkey(u_int8_t **, const u_int8_t *, int);
+static  int cml_setkey(u_int8_t **, const u_int8_t *, int);
 static void des1_encrypt(void *, u_int8_t *);
 static void des3_encrypt(void *, u_int8_t *);
 static void blf_encrypt(void *, u_int8_t *);
 static void cast5_encrypt(void *, u_int8_t *);
 static void skipjack_encrypt(void *, u_int8_t *);
 static void rijndael128_encrypt(void *, u_int8_t *);
+static  void cml_encrypt(void *, u_int8_t *);
 static void des1_decrypt(void *, u_int8_t *);
 static void des3_decrypt(void *, u_int8_t *);
 static void blf_decrypt(void *, u_int8_t *);
 static void cast5_decrypt(void *, u_int8_t *);
 static void skipjack_decrypt(void *, u_int8_t *);
 static void rijndael128_decrypt(void *, u_int8_t *);
+static  void cml_decrypt(void *, 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 *, const u_int8_t *, u_int16_t);
@@ -193,6 +198,14 @@
        NULL,
 };
 
+static const struct swcr_enc_xform swcr_enc_xform_camellia = {
+       &enc_xform_camellia,
+       cml_encrypt,
+       cml_decrypt,
+       cml_setkey,
+       cml_zerokey
+};
+
 /* Authentication instances */
 static const struct swcr_auth_hash swcr_auth_hash_null = {
        &auth_hash_null,
@@ -560,6 +573,46 @@
        *sched = NULL;
 }
 
+static void
+cml_encrypt(void *key, u_int8_t *blk)
+{
+
+       camellia_encrypt(key, blk, blk);
+}
+
+static void
+cml_decrypt(void *key, u_int8_t *blk)
+{
+
+       camellia_decrypt(key, blk, blk);
+}
+
+static int
+cml_setkey(u_int8_t **sched, const u_int8_t *key, int len)
+{
+       int err;
+
+       if (len != 16 && len != 24 && len != 32)
+               return (EINVAL);
+       *sched = malloc(sizeof(camellia_ctx), M_CRYPTO_DATA,
+                       M_NOWAIT|M_ZERO);
+       if (*sched != NULL) {
+               camellia_set_key((camellia_ctx *) *sched, key, len * 8);
+               err = 0;
+       } else
+               err = ENOMEM;
+       return err;
+}
+
+static void
+cml_zerokey(u_int8_t **sched)
+{
+
+       memset(*sched, 0, sizeof(camellia_ctx));
+       free(*sched, M_CRYPTO_DATA);
+       *sched = NULL;
+}
+
 /*
  * And now for auth.
  */
diff -r 4b1c275f0e5a -r 8811021565b5 sys/opencrypto/files.opencrypto
--- a/sys/opencrypto/files.opencrypto   Thu May 05 17:42:17 2011 +0000
+++ b/sys/opencrypto/files.opencrypto   Thu May 05 17:44:39 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.opencrypto,v 1.21 2011/02/19 16:26:34 drochner Exp $
+#      $NetBSD: files.opencrypto,v 1.22 2011/05/05 17:44:39 drochner Exp $
 #
 #
 
@@ -15,7 +15,7 @@
 # Pseudo-device that provides software implementations of various cryptographic
 # algorithms.
 defpseudo swcrypto: opencrypto,
-               blowfish, des, cast128, rijndael, skipjack
+               blowfish, des, cast128, rijndael, skipjack, camellia
 file   opencrypto/cryptosoft.c         swcrypto
 file   opencrypto/deflate.c            swcrypto        # wrapper around zlib
 



Home | Main Index | Thread Index | Old Index