summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2003-11-11 18:58:54 +0000
committerume <ume@FreeBSD.org>2003-11-11 18:58:54 +0000
commit7755ea7d71cf23ea52cd572d71b9f8ae828c37ee (patch)
tree1f326f8814db081c0373acbcd861163d91ae8f2e
parentc53afacbe5fe9502539b8d16d260b60c8e5bee36 (diff)
downloadFreeBSD-src-7755ea7d71cf23ea52cd572d71b9f8ae828c37ee.zip
FreeBSD-src-7755ea7d71cf23ea52cd572d71b9f8ae828c37ee.tar.gz
cleanup rijndael API.
since there are naming conflicts with opencrypto, #define was added to rename functions intend to avoid conflicts. Obtained from: KAME
-rw-r--r--sys/conf/files2
-rw-r--r--sys/crypto/rijndael/rijndael.c57
-rw-r--r--sys/crypto/rijndael/rijndael.h51
-rw-r--r--sys/netinet6/esp_rijndael.c44
4 files changed, 120 insertions, 34 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 89cf739..162220e 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -207,7 +207,7 @@ crypto/cast128/cast128.c optional ipsec ipsec_esp
crypto/des/des_ecb.c optional ipsec ipsec_esp
crypto/des/des_setkey.c optional ipsec ipsec_esp
crypto/rijndael/rijndael-alg-fst.c optional ipsec
-crypto/rijndael/rijndael-api-fst.c optional ipsec
+crypto/rijndael/rijndael.c optional ipsec
opencrypto/rmd160.c optional ipsec
crypto/sha1.c optional ipsec
crypto/sha2/sha2.c optional ipsec
diff --git a/sys/crypto/rijndael/rijndael.c b/sys/crypto/rijndael/rijndael.c
new file mode 100644
index 0000000..9a7fda3
--- /dev/null
+++ b/sys/crypto/rijndael/rijndael.c
@@ -0,0 +1,57 @@
+/* $KAME: rijndael.c,v 1.3 2003/08/28 14:20:22 itojun Exp $ */
+
+/*
+ * rijndael-alg-fst.c
+ *
+ * @version 3.0 (December 2000)
+ *
+ * Optimised ANSI C code for the Rijndael cipher (now AES)
+ *
+ * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
+ * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
+ * @author Paulo Barreto <paulo.barreto@terra.com.br>
+ *
+ * This code is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''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 THE AUTHORS OR CONTRIBUTORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include <crypto/rijndael/rijndael.h>
+
+void
+rijndael_set_key(rijndael_ctx *ctx, const u_char *key, int bits)
+{
+
+ ctx->Nr = rijndaelKeySetupEnc(ctx->ek, key, bits);
+ rijndaelKeySetupDec(ctx->dk, key, bits);
+}
+
+void
+rijndael_decrypt(const rijndael_ctx *ctx, const u_char *src, u_char *dst)
+{
+
+ rijndaelDecrypt(ctx->dk, ctx->Nr, src, dst);
+}
+
+void
+rijndael_encrypt(const rijndael_ctx *ctx, const u_char *src, u_char *dst)
+{
+
+ rijndaelEncrypt(ctx->ek, ctx->Nr, src, dst);
+}
diff --git a/sys/crypto/rijndael/rijndael.h b/sys/crypto/rijndael/rijndael.h
index 8f2cc89..41ecf48 100644
--- a/sys/crypto/rijndael/rijndael.h
+++ b/sys/crypto/rijndael/rijndael.h
@@ -1,3 +1,52 @@
-/* $KAME: rijndael.h,v 1.2 2000/10/02 17:14:27 itojun Exp $ */
+/* $KAME: rijndael.h,v 1.6 2003/08/28 08:36:32 itojun Exp $ */
+/* $FreeBSD$ */
+/**
+ * rijndael-alg-fst.h
+ *
+ * @version 3.0 (December 2000)
+ *
+ * Optimised ANSI C code for the Rijndael cipher (now AES)
+ *
+ * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
+ * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
+ * @author Paulo Barreto <paulo.barreto@terra.com.br>
+ *
+ * This code is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''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 THE AUTHORS OR CONTRIBUTORS 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.
+ */
+
+#ifndef __RIJNDAEL_H
+#define __RIJNDAEL_H
+
+#include <crypto/rijndael/rijndael-alg-fst.h>
#include <crypto/rijndael/rijndael-api-fst.h>
+
+/* XXX: avoid conflicts with opencrypto */
+#define rijndael_set_key _rijndael_set_key
+#define rijndael_decrypt _rijndael_decrypt
+#define rijndael_encrypt _rijndael_encrypt
+
+typedef struct {
+ int decrypt;
+ int Nr; /* key-length-dependent number of rounds */
+ uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)]; /* encrypt key schedule */
+ uint32_t dk[4 * (RIJNDAEL_MAXNR + 1)]; /* decrypt key schedule */
+} rijndael_ctx;
+
+void rijndael_set_key(rijndael_ctx *, const u_char *, int);
+void rijndael_decrypt(const rijndael_ctx *, const u_char *, u_char *);
+void rijndael_encrypt(const rijndael_ctx *, const u_char *, u_char *);
+
+#endif /* __RIJNDAEL_H */
diff --git a/sys/netinet6/esp_rijndael.c b/sys/netinet6/esp_rijndael.c
index e8c6995..cbb9705 100644
--- a/sys/netinet6/esp_rijndael.c
+++ b/sys/netinet6/esp_rijndael.c
@@ -1,5 +1,5 @@
/* $FreeBSD$ */
-/* $KAME: esp_rijndael.c,v 1.4 2001/03/02 05:53:05 itojun Exp $ */
+/* $KAME: esp_rijndael.c,v 1.14 2003/08/28 08:23:20 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -30,9 +30,6 @@
* SUCH DAMAGE.
*/
-#include "opt_inet.h"
-#include "opt_inet6.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
@@ -50,13 +47,12 @@
#include <net/net_osdep.h>
-/* as rijndael uses assymetric scheduled keys, we need to do it twice. */
size_t
esp_rijndael_schedlen(algo)
const struct esp_algorithm *algo;
{
- return sizeof(keyInstance) * 2;
+ return sizeof(rijndael_ctx);
}
int
@@ -64,15 +60,11 @@ esp_rijndael_schedule(algo, sav)
const struct esp_algorithm *algo;
struct secasvar *sav;
{
- keyInstance *k;
+ rijndael_ctx *ctx;
- k = (keyInstance *)sav->sched;
- if (rijndael_makeKey(&k[0], DIR_DECRYPT, _KEYLEN(sav->key_enc) * 8,
- _KEYBUF(sav->key_enc)) < 0)
- return -1;
- if (rijndael_makeKey(&k[1], DIR_ENCRYPT, _KEYLEN(sav->key_enc) * 8,
- _KEYBUF(sav->key_enc)) < 0)
- return -1;
+ ctx = (rijndael_ctx *)sav->sched;
+ rijndael_set_key(ctx,
+ (u_char *)_KEYBUF(sav->key_enc), _KEYLEN(sav->key_enc) * 8);
return 0;
}
@@ -83,16 +75,10 @@ esp_rijndael_blockdecrypt(algo, sav, s, d)
u_int8_t *s;
u_int8_t *d;
{
- cipherInstance c;
- keyInstance *p;
+ rijndael_ctx *ctx;
- /* does not take advantage of CBC mode support */
- bzero(&c, sizeof(c));
- if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0)
- return -1;
- p = (keyInstance *)sav->sched;
- if (rijndael_blockDecrypt(&c, &p[0], s, algo->padbound * 8, d) < 0)
- return -1;
+ ctx = (rijndael_ctx *)sav->sched;
+ rijndael_decrypt(ctx, s, d);
return 0;
}
@@ -103,15 +89,9 @@ esp_rijndael_blockencrypt(algo, sav, s, d)
u_int8_t *s;
u_int8_t *d;
{
- cipherInstance c;
- keyInstance *p;
+ rijndael_ctx *ctx;
- /* does not take advantage of CBC mode support */
- bzero(&c, sizeof(c));
- if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0)
- return -1;
- p = (keyInstance *)sav->sched;
- if (rijndael_blockEncrypt(&c, &p[1], s, algo->padbound * 8, d) < 0)
- return -1;
+ ctx = (rijndael_ctx *)sav->sched;
+ rijndael_encrypt(ctx, s, d);
return 0;
}
OpenPOWER on IntegriCloud