You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/12/13 18:34:06 UTC
[nuttx] 03/05: crypto:convert code style form openbsd to nuttx
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 82956a2894bf3c058e68208023db1d92d835052d
Author: anjiahao <an...@xiaomi.com>
AuthorDate: Wed Jul 27 19:51:53 2022 +0800
crypto:convert code style form openbsd to nuttx
Signed-off-by: anjiahao <an...@xiaomi.com>
---
crypto/aes.c | 1608 +++++++++++++++------------
crypto/blf.c | 1173 ++++++++++----------
crypto/cast.c | 570 +++++-----
crypto/castsb.h | 1064 +++++++++---------
crypto/chacha_private.h | 396 ++++---
crypto/chachapoly.c | 440 ++++----
crypto/cmac.c | 211 ++--
crypto/crypto.c | 1229 ++++++++++++---------
crypto/cryptodev.c | 1421 +++++++++++++-----------
crypto/cryptosoft.c | 2553 ++++++++++++++++++++++++-------------------
crypto/des_locl.h | 252 +++--
crypto/ecb3_enc.c | 79 +-
crypto/ecb_enc.c | 143 ++-
crypto/gmac.c | 268 +++--
crypto/hmac.c | 292 ++---
crypto/idgen.c | 212 ++--
crypto/key_wrap.c | 201 ++--
crypto/md5.c | 410 +++----
crypto/podd.h | 74 +-
crypto/poly1305.c | 614 ++++++-----
crypto/rijndael.c | 2396 ++++++++++++++++++++++------------------
crypto/rmd160.c | 700 ++++++------
crypto/set_key.c | 359 +++---
crypto/sha1.c | 359 ++++--
crypto/sha2.c | 1541 +++++++++++++++-----------
crypto/siphash.c | 234 ++--
crypto/sk.h | 339 +++---
crypto/spr.h | 334 +++---
crypto/xform.c | 805 +++++++-------
include/crypto/aes.h | 41 +-
include/crypto/blf.h | 72 +-
include/crypto/cast.h | 40 +-
include/crypto/chachapoly.h | 122 ++-
include/crypto/cmac.h | 39 +-
include/crypto/cryptodev.h | 486 ++++----
include/crypto/cryptosoft.h | 106 +-
include/crypto/gmac.h | 71 +-
include/crypto/hmac.h | 75 +-
include/crypto/idgen.h | 38 +-
include/crypto/key_wrap.h | 39 +-
include/crypto/md5.h | 44 +-
include/crypto/poly1305.h | 36 +-
include/crypto/rijndael.h | 60 +-
include/crypto/rmd160.h | 44 +-
include/crypto/sha1.h | 41 +-
include/crypto/sha2.h | 87 +-
include/crypto/siphash.h | 85 +-
include/crypto/xform.h | 110 +-
48 files changed, 12170 insertions(+), 9743 deletions(-)
diff --git a/crypto/aes.c b/crypto/aes.c
index adc03449a5..2f4f049a5b 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -1,5 +1,7 @@
-/* $OpenBSD: aes.c,v 1.2 2020/07/22 13:54:30 tobhe Exp $ */
-/*
+/****************************************************************************
+ * crypto/aes.c
+ * $OpenBSD: aes.c,v 1.2 2020/07/22 13:54:30 tobhe Exp $
+ *
* Copyright (c) 2016 Thomas Pornin <po...@bolet.org>
*
* Modified for OpenBSD by Thomas Pornin and Mike Belopuhov.
@@ -23,37 +25,42 @@
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
- */
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/stdint.h>
#include <crypto/aes.h>
-static inline void
-enc32le(void *dst, uint32_t x)
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+static inline void enc32le(FAR void *dst, uint32_t x)
{
- unsigned char *buf = dst;
+ FAR unsigned char *buf = dst;
- buf[0] = (unsigned char)x;
- buf[1] = (unsigned char)(x >> 8);
- buf[2] = (unsigned char)(x >> 16);
- buf[3] = (unsigned char)(x >> 24);
+ buf[0] = (unsigned char)x;
+ buf[1] = (unsigned char)(x >> 8);
+ buf[2] = (unsigned char)(x >> 16);
+ buf[3] = (unsigned char)(x >> 24);
}
-static inline uint32_t
-dec32le(const void *src)
+static inline uint32_t dec32le(FAR const void *src)
{
- const unsigned char *buf = src;
+ FAR const unsigned char *buf = src;
- return (uint32_t)buf[0]
- | ((uint32_t)buf[1] << 8)
- | ((uint32_t)buf[2] << 16)
- | ((uint32_t)buf[3] << 24);
+ return (uint32_t)buf[0]
+ | ((uint32_t)buf[1] << 8)
+ | ((uint32_t)buf[2] << 16)
+ | ((uint32_t)buf[3] << 24);
}
-/*
- * This constant-time implementation is "bitsliced": the 128-bit state is
+/* This constant-time implementation is "bitsliced": the 128-bit state is
* split over eight 32-bit words q* in the following way:
*
* -- Input block consists in 16 bytes:
@@ -84,794 +91,995 @@ dec32le(const void *src)
* that aes_ct_ortho() is its own inverse.
*/
-/*
- * The AES S-box, as a bitsliced constant-time version. The input array
+/* The AES S-box, as a bitsliced constant-time version. The input array
* consists in eight 32-bit words; 32 S-box instances are computed in
* parallel. Bits 0 to 7 of each S-box input (bit 0 is least significant)
* are spread over the words 0 to 7, at the same rank.
*/
-static void
-aes_ct_bitslice_Sbox(uint32_t *q)
+
+static void aes_ct_bitslice_sbox(FAR uint32_t *q)
{
- /*
- * This S-box implementation is a straightforward translation of
- * the circuit described by Boyar and Peralta in "A new
- * combinational logic minimization technique with applications
- * to cryptology" (https://eprint.iacr.org/2009/191.pdf).
- *
- * Note that variables x* (input) and s* (output) are numbered
- * in "reverse" order (x0 is the high bit, x7 is the low bit).
- */
-
- uint32_t x0, x1, x2, x3, x4, x5, x6, x7;
- uint32_t y1, y2, y3, y4, y5, y6, y7, y8, y9;
- uint32_t y10, y11, y12, y13, y14, y15, y16, y17, y18, y19;
- uint32_t y20, y21;
- uint32_t z0, z1, z2, z3, z4, z5, z6, z7, z8, z9;
- uint32_t z10, z11, z12, z13, z14, z15, z16, z17;
- uint32_t t0, t1, t2, t3, t4, t5, t6, t7, t8, t9;
- uint32_t t10, t11, t12, t13, t14, t15, t16, t17, t18, t19;
- uint32_t t20, t21, t22, t23, t24, t25, t26, t27, t28, t29;
- uint32_t t30, t31, t32, t33, t34, t35, t36, t37, t38, t39;
- uint32_t t40, t41, t42, t43, t44, t45, t46, t47, t48, t49;
- uint32_t t50, t51, t52, t53, t54, t55, t56, t57, t58, t59;
- uint32_t t60, t61, t62, t63, t64, t65, t66, t67;
- uint32_t s0, s1, s2, s3, s4, s5, s6, s7;
-
- x0 = q[7];
- x1 = q[6];
- x2 = q[5];
- x3 = q[4];
- x4 = q[3];
- x5 = q[2];
- x6 = q[1];
- x7 = q[0];
-
- /*
- * Top linear transformation.
- */
- y14 = x3 ^ x5;
- y13 = x0 ^ x6;
- y9 = x0 ^ x3;
- y8 = x0 ^ x5;
- t0 = x1 ^ x2;
- y1 = t0 ^ x7;
- y4 = y1 ^ x3;
- y12 = y13 ^ y14;
- y2 = y1 ^ x0;
- y5 = y1 ^ x6;
- y3 = y5 ^ y8;
- t1 = x4 ^ y12;
- y15 = t1 ^ x5;
- y20 = t1 ^ x1;
- y6 = y15 ^ x7;
- y10 = y15 ^ t0;
- y11 = y20 ^ y9;
- y7 = x7 ^ y11;
- y17 = y10 ^ y11;
- y19 = y10 ^ y8;
- y16 = t0 ^ y11;
- y21 = y13 ^ y16;
- y18 = x0 ^ y16;
-
- /*
- * Non-linear section.
- */
- t2 = y12 & y15;
- t3 = y3 & y6;
- t4 = t3 ^ t2;
- t5 = y4 & x7;
- t6 = t5 ^ t2;
- t7 = y13 & y16;
- t8 = y5 & y1;
- t9 = t8 ^ t7;
- t10 = y2 & y7;
- t11 = t10 ^ t7;
- t12 = y9 & y11;
- t13 = y14 & y17;
- t14 = t13 ^ t12;
- t15 = y8 & y10;
- t16 = t15 ^ t12;
- t17 = t4 ^ t14;
- t18 = t6 ^ t16;
- t19 = t9 ^ t14;
- t20 = t11 ^ t16;
- t21 = t17 ^ y20;
- t22 = t18 ^ y19;
- t23 = t19 ^ y21;
- t24 = t20 ^ y18;
-
- t25 = t21 ^ t22;
- t26 = t21 & t23;
- t27 = t24 ^ t26;
- t28 = t25 & t27;
- t29 = t28 ^ t22;
- t30 = t23 ^ t24;
- t31 = t22 ^ t26;
- t32 = t31 & t30;
- t33 = t32 ^ t24;
- t34 = t23 ^ t33;
- t35 = t27 ^ t33;
- t36 = t24 & t35;
- t37 = t36 ^ t34;
- t38 = t27 ^ t36;
- t39 = t29 & t38;
- t40 = t25 ^ t39;
-
- t41 = t40 ^ t37;
- t42 = t29 ^ t33;
- t43 = t29 ^ t40;
- t44 = t33 ^ t37;
- t45 = t42 ^ t41;
- z0 = t44 & y15;
- z1 = t37 & y6;
- z2 = t33 & x7;
- z3 = t43 & y16;
- z4 = t40 & y1;
- z5 = t29 & y7;
- z6 = t42 & y11;
- z7 = t45 & y17;
- z8 = t41 & y10;
- z9 = t44 & y12;
- z10 = t37 & y3;
- z11 = t33 & y4;
- z12 = t43 & y13;
- z13 = t40 & y5;
- z14 = t29 & y2;
- z15 = t42 & y9;
- z16 = t45 & y14;
- z17 = t41 & y8;
-
- /*
- * Bottom linear transformation.
- */
- t46 = z15 ^ z16;
- t47 = z10 ^ z11;
- t48 = z5 ^ z13;
- t49 = z9 ^ z10;
- t50 = z2 ^ z12;
- t51 = z2 ^ z5;
- t52 = z7 ^ z8;
- t53 = z0 ^ z3;
- t54 = z6 ^ z7;
- t55 = z16 ^ z17;
- t56 = z12 ^ t48;
- t57 = t50 ^ t53;
- t58 = z4 ^ t46;
- t59 = z3 ^ t54;
- t60 = t46 ^ t57;
- t61 = z14 ^ t57;
- t62 = t52 ^ t58;
- t63 = t49 ^ t58;
- t64 = z4 ^ t59;
- t65 = t61 ^ t62;
- t66 = z1 ^ t63;
- s0 = t59 ^ t63;
- s6 = t56 ^ ~t62;
- s7 = t48 ^ ~t60;
- t67 = t64 ^ t65;
- s3 = t53 ^ t66;
- s4 = t51 ^ t66;
- s5 = t47 ^ t65;
- s1 = t64 ^ ~s3;
- s2 = t55 ^ ~t67;
-
- q[7] = s0;
- q[6] = s1;
- q[5] = s2;
- q[4] = s3;
- q[3] = s4;
- q[2] = s5;
- q[1] = s6;
- q[0] = s7;
+ /* This S-box implementation is a straightforward translation of
+ * the circuit described by Boyar and Peralta in "A new
+ * combinational logic minimization technique with applications
+ * to cryptology" (https://eprint.iacr.org/2009/191.pdf).
+ *
+ * Note that variables x* (input) and s* (output) are numbered
+ * in "reverse" order (x0 is the high bit, x7 is the low bit).
+ */
+
+ uint32_t x0;
+ uint32_t x1;
+ uint32_t x2;
+ uint32_t x3;
+ uint32_t x4;
+ uint32_t x5;
+ uint32_t x6;
+ uint32_t x7;
+ uint32_t y1;
+ uint32_t y2;
+ uint32_t y3;
+ uint32_t y4;
+ uint32_t y5;
+ uint32_t y6;
+ uint32_t y7;
+ uint32_t y8;
+ uint32_t y9;
+ uint32_t y10;
+ uint32_t y11;
+ uint32_t y12;
+ uint32_t y13;
+ uint32_t y14;
+ uint32_t y15;
+ uint32_t y16;
+ uint32_t y17;
+ uint32_t y18;
+ uint32_t y19;
+ uint32_t y20;
+ uint32_t y21;
+ uint32_t z0;
+ uint32_t z1;
+ uint32_t z2;
+ uint32_t z3;
+ uint32_t z4;
+ uint32_t z5;
+ uint32_t z6;
+ uint32_t z7;
+ uint32_t z8;
+ uint32_t z9;
+ uint32_t z10;
+ uint32_t z11;
+ uint32_t z12;
+ uint32_t z13;
+ uint32_t z14;
+ uint32_t z15;
+ uint32_t z16;
+ uint32_t z17;
+ uint32_t t0;
+ uint32_t t1;
+ uint32_t t2;
+ uint32_t t3;
+ uint32_t t4;
+ uint32_t t5;
+ uint32_t t6;
+ uint32_t t7;
+ uint32_t t8;
+ uint32_t t9;
+ uint32_t t10;
+ uint32_t t11;
+ uint32_t t12;
+ uint32_t t13;
+ uint32_t t14;
+ uint32_t t15;
+ uint32_t t16;
+ uint32_t t17;
+ uint32_t t18;
+ uint32_t t19;
+ uint32_t t20;
+ uint32_t t21;
+ uint32_t t22;
+ uint32_t t23;
+ uint32_t t24;
+ uint32_t t25;
+ uint32_t t26;
+ uint32_t t27;
+ uint32_t t28;
+ uint32_t t29;
+ uint32_t t30;
+ uint32_t t31;
+ uint32_t t32;
+ uint32_t t33;
+ uint32_t t34;
+ uint32_t t35;
+ uint32_t t36;
+ uint32_t t37;
+ uint32_t t38;
+ uint32_t t39;
+ uint32_t t40;
+ uint32_t t41;
+ uint32_t t42;
+ uint32_t t43;
+ uint32_t t44;
+ uint32_t t45;
+ uint32_t t46;
+ uint32_t t47;
+ uint32_t t48;
+ uint32_t t49;
+ uint32_t t50;
+ uint32_t t51;
+ uint32_t t52;
+ uint32_t t53;
+ uint32_t t54;
+ uint32_t t55;
+ uint32_t t56;
+ uint32_t t57;
+ uint32_t t58;
+ uint32_t t59;
+ uint32_t t60;
+ uint32_t t61;
+ uint32_t t62;
+ uint32_t t63;
+ uint32_t t64;
+ uint32_t t65;
+ uint32_t t66;
+ uint32_t t67;
+ uint32_t s0;
+ uint32_t s1;
+ uint32_t s2;
+ uint32_t s3;
+ uint32_t s4;
+ uint32_t s5;
+ uint32_t s6;
+ uint32_t s7;
+
+ x0 = q[7];
+ x1 = q[6];
+ x2 = q[5];
+ x3 = q[4];
+ x4 = q[3];
+ x5 = q[2];
+ x6 = q[1];
+ x7 = q[0];
+
+ /* Top linear transformation. */
+
+ y14 = x3 ^ x5;
+ y13 = x0 ^ x6;
+ y9 = x0 ^ x3;
+ y8 = x0 ^ x5;
+ t0 = x1 ^ x2;
+ y1 = t0 ^ x7;
+ y4 = y1 ^ x3;
+ y12 = y13 ^ y14;
+ y2 = y1 ^ x0;
+ y5 = y1 ^ x6;
+ y3 = y5 ^ y8;
+ t1 = x4 ^ y12;
+ y15 = t1 ^ x5;
+ y20 = t1 ^ x1;
+ y6 = y15 ^ x7;
+ y10 = y15 ^ t0;
+ y11 = y20 ^ y9;
+ y7 = x7 ^ y11;
+ y17 = y10 ^ y11;
+ y19 = y10 ^ y8;
+ y16 = t0 ^ y11;
+ y21 = y13 ^ y16;
+ y18 = x0 ^ y16;
+
+ /* Non-linear section. */
+
+ t2 = y12 & y15;
+ t3 = y3 & y6;
+ t4 = t3 ^ t2;
+ t5 = y4 & x7;
+ t6 = t5 ^ t2;
+ t7 = y13 & y16;
+ t8 = y5 & y1;
+ t9 = t8 ^ t7;
+ t10 = y2 & y7;
+ t11 = t10 ^ t7;
+ t12 = y9 & y11;
+ t13 = y14 & y17;
+ t14 = t13 ^ t12;
+ t15 = y8 & y10;
+ t16 = t15 ^ t12;
+ t17 = t4 ^ t14;
+ t18 = t6 ^ t16;
+ t19 = t9 ^ t14;
+ t20 = t11 ^ t16;
+ t21 = t17 ^ y20;
+ t22 = t18 ^ y19;
+ t23 = t19 ^ y21;
+ t24 = t20 ^ y18;
+
+ t25 = t21 ^ t22;
+ t26 = t21 & t23;
+ t27 = t24 ^ t26;
+ t28 = t25 & t27;
+ t29 = t28 ^ t22;
+ t30 = t23 ^ t24;
+ t31 = t22 ^ t26;
+ t32 = t31 & t30;
+ t33 = t32 ^ t24;
+ t34 = t23 ^ t33;
+ t35 = t27 ^ t33;
+ t36 = t24 & t35;
+ t37 = t36 ^ t34;
+ t38 = t27 ^ t36;
+ t39 = t29 & t38;
+ t40 = t25 ^ t39;
+
+ t41 = t40 ^ t37;
+ t42 = t29 ^ t33;
+ t43 = t29 ^ t40;
+ t44 = t33 ^ t37;
+ t45 = t42 ^ t41;
+ z0 = t44 & y15;
+ z1 = t37 & y6;
+ z2 = t33 & x7;
+ z3 = t43 & y16;
+ z4 = t40 & y1;
+ z5 = t29 & y7;
+ z6 = t42 & y11;
+ z7 = t45 & y17;
+ z8 = t41 & y10;
+ z9 = t44 & y12;
+ z10 = t37 & y3;
+ z11 = t33 & y4;
+ z12 = t43 & y13;
+ z13 = t40 & y5;
+ z14 = t29 & y2;
+ z15 = t42 & y9;
+ z16 = t45 & y14;
+ z17 = t41 & y8;
+
+ /* Bottom linear transformation. */
+
+ t46 = z15 ^ z16;
+ t47 = z10 ^ z11;
+ t48 = z5 ^ z13;
+ t49 = z9 ^ z10;
+ t50 = z2 ^ z12;
+ t51 = z2 ^ z5;
+ t52 = z7 ^ z8;
+ t53 = z0 ^ z3;
+ t54 = z6 ^ z7;
+ t55 = z16 ^ z17;
+ t56 = z12 ^ t48;
+ t57 = t50 ^ t53;
+ t58 = z4 ^ t46;
+ t59 = z3 ^ t54;
+ t60 = t46 ^ t57;
+ t61 = z14 ^ t57;
+ t62 = t52 ^ t58;
+ t63 = t49 ^ t58;
+ t64 = z4 ^ t59;
+ t65 = t61 ^ t62;
+ t66 = z1 ^ t63;
+ s0 = t59 ^ t63;
+ s6 = t56 ^ ~t62;
+ s7 = t48 ^ ~t60;
+ t67 = t64 ^ t65;
+ s3 = t53 ^ t66;
+ s4 = t51 ^ t66;
+ s5 = t47 ^ t65;
+ s1 = t64 ^ ~s3;
+ s2 = t55 ^ ~t67;
+
+ q[7] = s0;
+ q[6] = s1;
+ q[5] = s2;
+ q[4] = s3;
+ q[3] = s4;
+ q[2] = s5;
+ q[1] = s6;
+ q[0] = s7;
}
-/*
- * Perform bytewise orthogonalization of eight 32-bit words. Bytes
+/* Perform bytewise orthogonalization of eight 32-bit words. Bytes
* of q0..q7 are spread over all words: for a byte x that occurs
* at rank i in q[j] (byte x uses bits 8*i to 8*i+7 in q[j]), the bit
* of rank k in x (0 <= k <= 7) goes to q[k] at rank 8*i+j.
*
* This operation is an involution.
*/
-static void
-aes_ct_ortho(uint32_t *q)
+
+static void aes_ct_ortho(FAR uint32_t *q)
{
#define SWAPN(cl, ch, s, x, y) do { \
- uint32_t a, b; \
- a = (x); \
- b = (y); \
- (x) = (a & (uint32_t)cl) | ((b & (uint32_t)cl) << (s)); \
- (y) = ((a & (uint32_t)ch) >> (s)) | (b & (uint32_t)ch); \
- } while (0)
-
-#define SWAP2(x, y) SWAPN(0x55555555, 0xAAAAAAAA, 1, x, y)
-#define SWAP4(x, y) SWAPN(0x33333333, 0xCCCCCCCC, 2, x, y)
-#define SWAP8(x, y) SWAPN(0x0F0F0F0F, 0xF0F0F0F0, 4, x, y)
-
- SWAP2(q[0], q[1]);
- SWAP2(q[2], q[3]);
- SWAP2(q[4], q[5]);
- SWAP2(q[6], q[7]);
-
- SWAP4(q[0], q[2]);
- SWAP4(q[1], q[3]);
- SWAP4(q[4], q[6]);
- SWAP4(q[5], q[7]);
-
- SWAP8(q[0], q[4]);
- SWAP8(q[1], q[5]);
- SWAP8(q[2], q[6]);
- SWAP8(q[3], q[7]);
+ uint32_t a, b; \
+ a = (x); \
+ b = (y); \
+ (x) = (a & (uint32_t)cl) | ((b & (uint32_t)cl) << (s)); \
+ (y) = ((a & (uint32_t)ch) >> (s)) | (b & (uint32_t)ch); \
+ } while (0)
+
+#define SWAP2(x, y) SWAPN(0x55555555, 0xaaaaaaaa, 1, x, y)
+#define SWAP4(x, y) SWAPN(0x33333333, 0xcccccccc, 2, x, y)
+#define SWAP8(x, y) SWAPN(0x0f0f0f0f, 0xf0f0f0f0, 4, x, y)
+
+ SWAP2(q[0], q[1]);
+ SWAP2(q[2], q[3]);
+ SWAP2(q[4], q[5]);
+ SWAP2(q[6], q[7]);
+
+ SWAP4(q[0], q[2]);
+ SWAP4(q[1], q[3]);
+ SWAP4(q[4], q[6]);
+ SWAP4(q[5], q[7]);
+
+ SWAP8(q[0], q[4]);
+ SWAP8(q[1], q[5]);
+ SWAP8(q[2], q[6]);
+ SWAP8(q[3], q[7]);
}
-static inline uint32_t
-sub_word(uint32_t x)
+static inline uint32_t sub_word(uint32_t x)
{
- uint32_t q[8];
- int i;
-
- for (i = 0; i < 8; i ++) {
- q[i] = x;
- }
- aes_ct_ortho(q);
- aes_ct_bitslice_Sbox(q);
- aes_ct_ortho(q);
- return q[0];
+ uint32_t q[8];
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ q[i] = x;
+ }
+
+ aes_ct_ortho(q);
+ aes_ct_bitslice_sbox(q);
+ aes_ct_ortho(q);
+ return q[0];
}
-static const unsigned char Rcon[] = {
- 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36
+static const unsigned char rcon[] =
+{
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};
-/*
- * Base key schedule code. The function sub_word() must be defined
+/* Base key schedule code. The function sub_word() must be defined
* below. Subkeys are produced in little-endian convention (but not
* bitsliced). Key length is expressed in bytes.
*/
-static unsigned
-aes_keysched_base(uint32_t *skey, const void *key, size_t key_len)
+
+static unsigned aes_keysched_base(FAR uint32_t *skey,
+ FAR const void *key, size_t key_len)
{
- unsigned num_rounds;
- int i, j, k, nk, nkf;
- uint32_t tmp;
-
- switch (key_len) {
- case 16:
- num_rounds = 10;
- break;
- case 24:
- num_rounds = 12;
- break;
- case 32:
- num_rounds = 14;
- break;
- default:
- return 0;
- }
- nk = (int)(key_len >> 2);
- nkf = (int)((num_rounds + 1) << 2);
- for (i = 0; i < nk; i ++) {
- tmp = dec32le((const unsigned char *)key + (i << 2));
- skey[i] = tmp;
- }
- tmp = skey[(key_len >> 2) - 1];
- for (i = nk, j = 0, k = 0; i < nkf; i ++) {
- if (j == 0) {
- tmp = (tmp << 24) | (tmp >> 8);
- tmp = sub_word(tmp) ^ Rcon[k];
- } else if (nk > 6 && j == 4) {
- tmp = sub_word(tmp);
- }
- tmp ^= skey[i - nk];
- skey[i] = tmp;
- if (++ j == nk) {
- j = 0;
- k ++;
- }
- }
- return num_rounds;
+ unsigned num_rounds;
+ int i;
+ int j;
+ int k;
+ int nk;
+ int nkf;
+ uint32_t tmp;
+
+ switch (key_len)
+ {
+ case 16:
+ num_rounds = 10;
+ break;
+ case 24:
+ num_rounds = 12;
+ break;
+ case 32:
+ num_rounds = 14;
+ break;
+ default:
+ return 0;
+ }
+
+ nk = (int)(key_len >> 2);
+ nkf = (int)((num_rounds + 1) << 2);
+ for (i = 0; i < nk; i++)
+ {
+ tmp = dec32le((FAR const unsigned char *)key + (i << 2));
+ skey[i] = tmp;
+ }
+
+ tmp = skey[(key_len >> 2) - 1];
+ for (i = nk, j = 0, k = 0; i < nkf; i++)
+ {
+ if (j == 0)
+ {
+ tmp = (tmp << 24) | (tmp >> 8);
+ tmp = sub_word(tmp) ^ rcon[k];
+ }
+ else if (nk > 6 && j == 4)
+ {
+ tmp = sub_word(tmp);
+ }
+
+ tmp ^= skey[i - nk];
+ skey[i] = tmp;
+ if (++j == nk)
+ {
+ j = 0;
+ k++;
+ }
+ }
+
+ return num_rounds;
}
-/*
- * AES key schedule, constant-time version. skey[] is filled with n+1
+/* AES key schedule, constant-time version. skey[] is filled with n+1
* 128-bit subkeys, where n is the number of rounds (10 to 14, depending
* on key size). The number of rounds is returned. If the key size is
* invalid (not 16, 24 or 32), then 0 is returned.
*/
-unsigned
-aes_ct_keysched(uint32_t *comp_skey, const void *key, size_t key_len)
+
+unsigned aes_ct_keysched(FAR uint32_t *comp_skey,
+ FAR const void *key,
+ size_t key_len)
{
- uint32_t skey[60];
- unsigned u, num_rounds;
-
- num_rounds = aes_keysched_base(skey, key, key_len);
- for (u = 0; u <= num_rounds; u ++) {
- uint32_t q[8];
-
- q[0] = q[1] = skey[(u << 2) + 0];
- q[2] = q[3] = skey[(u << 2) + 1];
- q[4] = q[5] = skey[(u << 2) + 2];
- q[6] = q[7] = skey[(u << 2) + 3];
- aes_ct_ortho(q);
- comp_skey[(u << 2) + 0] =
- (q[0] & 0x55555555) | (q[1] & 0xAAAAAAAA);
- comp_skey[(u << 2) + 1] =
- (q[2] & 0x55555555) | (q[3] & 0xAAAAAAAA);
- comp_skey[(u << 2) + 2] =
- (q[4] & 0x55555555) | (q[5] & 0xAAAAAAAA);
- comp_skey[(u << 2) + 3] =
- (q[6] & 0x55555555) | (q[7] & 0xAAAAAAAA);
- }
- return num_rounds;
+ uint32_t skey[60];
+ unsigned u;
+ unsigned num_rounds;
+
+ num_rounds = aes_keysched_base(skey, key, key_len);
+ for (u = 0; u <= num_rounds; u++)
+ {
+ uint32_t q[8];
+
+ q[0] = q[1] = skey[(u << 2) + 0];
+ q[2] = q[3] = skey[(u << 2) + 1];
+ q[4] = q[5] = skey[(u << 2) + 2];
+ q[6] = q[7] = skey[(u << 2) + 3];
+ aes_ct_ortho(q);
+ comp_skey[(u << 2) + 0] =
+ (q[0] & 0x55555555) | (q[1] & 0xaaaaaaaa);
+ comp_skey[(u << 2) + 1] =
+ (q[2] & 0x55555555) | (q[3] & 0xaaaaaaaa);
+ comp_skey[(u << 2) + 2] =
+ (q[4] & 0x55555555) | (q[5] & 0xaaaaaaaa);
+ comp_skey[(u << 2) + 3] =
+ (q[6] & 0x55555555) | (q[7] & 0xaaaaaaaa);
+ }
+
+ return num_rounds;
}
-/*
- * Expand AES subkeys as produced by aes_ct_keysched(), into
+/* Expand AES subkeys as produced by aes_ct_keysched(), into
* a larger array suitable for aes_ct_bitslice_encrypt() and
* aes_ct_bitslice_decrypt().
*/
-void
-aes_ct_skey_expand(uint32_t *skey,
- unsigned num_rounds, const uint32_t *comp_skey)
+
+void aes_ct_skey_expand(FAR uint32_t *skey,
+ unsigned num_rounds,
+ FAR const uint32_t *comp_skey)
{
- unsigned u, v, n;
-
- n = (num_rounds + 1) << 2;
- for (u = 0, v = 0; u < n; u ++, v += 2) {
- uint32_t x, y;
-
- x = y = comp_skey[u];
- x &= 0x55555555;
- skey[v + 0] = x | (x << 1);
- y &= 0xAAAAAAAA;
- skey[v + 1] = y | (y >> 1);
- }
+ unsigned u;
+ unsigned v;
+ unsigned n;
+
+ n = (num_rounds + 1) << 2;
+ for (u = 0, v = 0; u < n; u ++, v += 2)
+ {
+ uint32_t x;
+ uint32_t y;
+
+ x = y = comp_skey[u];
+ x &= 0x55555555;
+ skey[v + 0] = x | (x << 1);
+ y &= 0xaaaaaaaa;
+ skey[v + 1] = y | (y >> 1);
+ }
}
-static inline void
-add_round_key(uint32_t *q, const uint32_t *sk)
+static inline void add_round_key(FAR uint32_t *q, FAR const uint32_t *sk)
{
- q[0] ^= sk[0];
- q[1] ^= sk[1];
- q[2] ^= sk[2];
- q[3] ^= sk[3];
- q[4] ^= sk[4];
- q[5] ^= sk[5];
- q[6] ^= sk[6];
- q[7] ^= sk[7];
+ q[0] ^= sk[0];
+ q[1] ^= sk[1];
+ q[2] ^= sk[2];
+ q[3] ^= sk[3];
+ q[4] ^= sk[4];
+ q[5] ^= sk[5];
+ q[6] ^= sk[6];
+ q[7] ^= sk[7];
}
-static inline void
-shift_rows(uint32_t *q)
+static inline void shift_rows(FAR uint32_t *q)
{
- int i;
-
- for (i = 0; i < 8; i ++) {
- uint32_t x;
-
- x = q[i];
- q[i] = (x & 0x000000FF)
- | ((x & 0x0000FC00) >> 2) | ((x & 0x00000300) << 6)
- | ((x & 0x00F00000) >> 4) | ((x & 0x000F0000) << 4)
- | ((x & 0xC0000000) >> 6) | ((x & 0x3F000000) << 2);
- }
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ uint32_t x;
+
+ x = q[i];
+ q[i] = (x & 0x000000ff)
+ | ((x & 0x0000fc00) >> 2) | ((x & 0x00000300) << 6)
+ | ((x & 0x00f00000) >> 4) | ((x & 0x000f0000) << 4)
+ | ((x & 0xc0000000) >> 6) | ((x & 0x3f000000) << 2);
+ }
}
-static inline uint32_t
-rotr16(uint32_t x)
+static inline uint32_t rotr16(uint32_t x)
{
- return (x << 16) | (x >> 16);
+ return (x << 16) | (x >> 16);
}
-static inline void
-mix_columns(uint32_t *q)
+static inline void mix_columns(FAR uint32_t *q)
{
- uint32_t q0, q1, q2, q3, q4, q5, q6, q7;
- uint32_t r0, r1, r2, r3, r4, r5, r6, r7;
-
- q0 = q[0];
- q1 = q[1];
- q2 = q[2];
- q3 = q[3];
- q4 = q[4];
- q5 = q[5];
- q6 = q[6];
- q7 = q[7];
- r0 = (q0 >> 8) | (q0 << 24);
- r1 = (q1 >> 8) | (q1 << 24);
- r2 = (q2 >> 8) | (q2 << 24);
- r3 = (q3 >> 8) | (q3 << 24);
- r4 = (q4 >> 8) | (q4 << 24);
- r5 = (q5 >> 8) | (q5 << 24);
- r6 = (q6 >> 8) | (q6 << 24);
- r7 = (q7 >> 8) | (q7 << 24);
-
- q[0] = q7 ^ r7 ^ r0 ^ rotr16(q0 ^ r0);
- q[1] = q0 ^ r0 ^ q7 ^ r7 ^ r1 ^ rotr16(q1 ^ r1);
- q[2] = q1 ^ r1 ^ r2 ^ rotr16(q2 ^ r2);
- q[3] = q2 ^ r2 ^ q7 ^ r7 ^ r3 ^ rotr16(q3 ^ r3);
- q[4] = q3 ^ r3 ^ q7 ^ r7 ^ r4 ^ rotr16(q4 ^ r4);
- q[5] = q4 ^ r4 ^ r5 ^ rotr16(q5 ^ r5);
- q[6] = q5 ^ r5 ^ r6 ^ rotr16(q6 ^ r6);
- q[7] = q6 ^ r6 ^ r7 ^ rotr16(q7 ^ r7);
+ uint32_t q0;
+ uint32_t q1;
+ uint32_t q2;
+ uint32_t q3;
+ uint32_t q4;
+ uint32_t q5;
+ uint32_t q6;
+ uint32_t q7;
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+
+ q0 = q[0];
+ q1 = q[1];
+ q2 = q[2];
+ q3 = q[3];
+ q4 = q[4];
+ q5 = q[5];
+ q6 = q[6];
+ q7 = q[7];
+ r0 = (q0 >> 8) | (q0 << 24);
+ r1 = (q1 >> 8) | (q1 << 24);
+ r2 = (q2 >> 8) | (q2 << 24);
+ r3 = (q3 >> 8) | (q3 << 24);
+ r4 = (q4 >> 8) | (q4 << 24);
+ r5 = (q5 >> 8) | (q5 << 24);
+ r6 = (q6 >> 8) | (q6 << 24);
+ r7 = (q7 >> 8) | (q7 << 24);
+
+ q[0] = q7 ^ r7 ^ r0 ^ rotr16(q0 ^ r0);
+ q[1] = q0 ^ r0 ^ q7 ^ r7 ^ r1 ^ rotr16(q1 ^ r1);
+ q[2] = q1 ^ r1 ^ r2 ^ rotr16(q2 ^ r2);
+ q[3] = q2 ^ r2 ^ q7 ^ r7 ^ r3 ^ rotr16(q3 ^ r3);
+ q[4] = q3 ^ r3 ^ q7 ^ r7 ^ r4 ^ rotr16(q4 ^ r4);
+ q[5] = q4 ^ r4 ^ r5 ^ rotr16(q5 ^ r5);
+ q[6] = q5 ^ r5 ^ r6 ^ rotr16(q6 ^ r6);
+ q[7] = q6 ^ r6 ^ r7 ^ rotr16(q7 ^ r7);
}
-/*
- * Compute AES encryption on bitsliced data. Since input is stored on
+/* Compute AES encryption on bitsliced data. Since input is stored on
* eight 32-bit words, two block encryptions are actually performed
* in parallel.
*/
-void
-aes_ct_bitslice_encrypt(unsigned num_rounds,
- const uint32_t *skey, uint32_t *q)
+
+void aes_ct_bitslice_encrypt(unsigned num_rounds,
+ FAR const uint32_t *skey,
+ FAR uint32_t *q)
{
- unsigned u;
-
- add_round_key(q, skey);
- for (u = 1; u < num_rounds; u ++) {
- aes_ct_bitslice_Sbox(q);
- shift_rows(q);
- mix_columns(q);
- add_round_key(q, skey + (u << 3));
- }
- aes_ct_bitslice_Sbox(q);
- shift_rows(q);
- add_round_key(q, skey + (num_rounds << 3));
+ unsigned u;
+
+ add_round_key(q, skey);
+ for (u = 1; u < num_rounds; u++)
+ {
+ aes_ct_bitslice_sbox(q);
+ shift_rows(q);
+ mix_columns(q);
+ add_round_key(q, skey + (u << 3));
+ }
+
+ aes_ct_bitslice_sbox(q);
+ shift_rows(q);
+ add_round_key(q, skey + (num_rounds << 3));
}
-/*
- * Like aes_ct_bitslice_Sbox(), but for the inverse S-box.
- */
-void
-aes_ct_bitslice_invSbox(uint32_t *q)
+/* Like aes_ct_bitslice_sbox(), but for the inverse S-box. */
+
+void aes_ct_bitslice_invsbox(FAR uint32_t *q)
{
- /*
- * AES S-box is:
- * S(x) = A(I(x)) ^ 0x63
- * where I() is inversion in GF(256), and A() is a linear
- * transform (0 is formally defined to be its own inverse).
- * Since inversion is an involution, the inverse S-box can be
- * computed from the S-box as:
- * iS(x) = B(S(B(x ^ 0x63)) ^ 0x63)
- * where B() is the inverse of A(). Indeed, for any y in GF(256):
- * iS(S(y)) = B(A(I(B(A(I(y)) ^ 0x63 ^ 0x63))) ^ 0x63 ^ 0x63) = y
- *
- * Note: we reuse the implementation of the forward S-box,
- * instead of duplicating it here, so that total code size is
- * lower. By merging the B() transforms into the S-box circuit
- * we could make faster CBC decryption, but CBC decryption is
- * already quite faster than CBC encryption because we can
- * process two blocks in parallel.
- */
- uint32_t q0, q1, q2, q3, q4, q5, q6, q7;
-
- q0 = ~q[0];
- q1 = ~q[1];
- q2 = q[2];
- q3 = q[3];
- q4 = q[4];
- q5 = ~q[5];
- q6 = ~q[6];
- q7 = q[7];
- q[7] = q1 ^ q4 ^ q6;
- q[6] = q0 ^ q3 ^ q5;
- q[5] = q7 ^ q2 ^ q4;
- q[4] = q6 ^ q1 ^ q3;
- q[3] = q5 ^ q0 ^ q2;
- q[2] = q4 ^ q7 ^ q1;
- q[1] = q3 ^ q6 ^ q0;
- q[0] = q2 ^ q5 ^ q7;
-
- aes_ct_bitslice_Sbox(q);
-
- q0 = ~q[0];
- q1 = ~q[1];
- q2 = q[2];
- q3 = q[3];
- q4 = q[4];
- q5 = ~q[5];
- q6 = ~q[6];
- q7 = q[7];
- q[7] = q1 ^ q4 ^ q6;
- q[6] = q0 ^ q3 ^ q5;
- q[5] = q7 ^ q2 ^ q4;
- q[4] = q6 ^ q1 ^ q3;
- q[3] = q5 ^ q0 ^ q2;
- q[2] = q4 ^ q7 ^ q1;
- q[1] = q3 ^ q6 ^ q0;
- q[0] = q2 ^ q5 ^ q7;
+ /* AES S-box is:
+ * S(x) = A(I(x)) ^ 0x63
+ * where I() is inversion in GF(256), and A() is a linear
+ * transform (0 is formally defined to be its own inverse).
+ * Since inversion is an involution, the inverse S-box can be
+ * computed from the S-box as:
+ * iS(x) = B(S(B(x ^ 0x63)) ^ 0x63)
+ * where B() is the inverse of A(). Indeed, for any y in GF(256):
+ * iS(S(y)) = B(A(I(B(A(I(y)) ^ 0x63 ^ 0x63))) ^ 0x63 ^ 0x63) = y
+ *
+ * Note: we reuse the implementation of the forward S-box,
+ * instead of duplicating it here, so that total code size is
+ * lower. By merging the B() transforms into the S-box circuit
+ * we could make faster CBC decryption, but CBC decryption is
+ * already quite faster than CBC encryption because we can
+ * process two blocks in parallel.
+ */
+
+ uint32_t q0;
+ uint32_t q1;
+ uint32_t q2;
+ uint32_t q3;
+ uint32_t q4;
+ uint32_t q5;
+ uint32_t q6;
+ uint32_t q7;
+
+ q0 = ~q[0];
+ q1 = ~q[1];
+ q2 = q[2];
+ q3 = q[3];
+ q4 = q[4];
+ q5 = ~q[5];
+ q6 = ~q[6];
+ q7 = q[7];
+ q[7] = q1 ^ q4 ^ q6;
+ q[6] = q0 ^ q3 ^ q5;
+ q[5] = q7 ^ q2 ^ q4;
+ q[4] = q6 ^ q1 ^ q3;
+ q[3] = q5 ^ q0 ^ q2;
+ q[2] = q4 ^ q7 ^ q1;
+ q[1] = q3 ^ q6 ^ q0;
+ q[0] = q2 ^ q5 ^ q7;
+
+ aes_ct_bitslice_sbox(q);
+
+ q0 = ~q[0];
+ q1 = ~q[1];
+ q2 = q[2];
+ q3 = q[3];
+ q4 = q[4];
+ q5 = ~q[5];
+ q6 = ~q[6];
+ q7 = q[7];
+ q[7] = q1 ^ q4 ^ q6;
+ q[6] = q0 ^ q3 ^ q5;
+ q[5] = q7 ^ q2 ^ q4;
+ q[4] = q6 ^ q1 ^ q3;
+ q[3] = q5 ^ q0 ^ q2;
+ q[2] = q4 ^ q7 ^ q1;
+ q[1] = q3 ^ q6 ^ q0;
+ q[0] = q2 ^ q5 ^ q7;
}
-static inline void
-inv_shift_rows(uint32_t *q)
+static inline void inv_shift_rows(FAR uint32_t *q)
{
- int i;
-
- for (i = 0; i < 8; i ++) {
- uint32_t x;
-
- x = q[i];
- q[i] = (x & 0x000000FF)
- | ((x & 0x00003F00) << 2) | ((x & 0x0000C000) >> 6)
- | ((x & 0x000F0000) << 4) | ((x & 0x00F00000) >> 4)
- | ((x & 0x03000000) << 6) | ((x & 0xFC000000) >> 2);
- }
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ uint32_t x;
+
+ x = q[i];
+ q[i] = (x & 0x000000ff)
+ | ((x & 0x00003f00) << 2) | ((x & 0x0000c000) >> 6)
+ | ((x & 0x000f0000) << 4) | ((x & 0x00f00000) >> 4)
+ | ((x & 0x03000000) << 6) | ((x & 0xfc000000) >> 2);
+ }
}
-static void
-inv_mix_columns(uint32_t *q)
+static void inv_mix_columns(FAR uint32_t *q)
{
- uint32_t q0, q1, q2, q3, q4, q5, q6, q7;
- uint32_t r0, r1, r2, r3, r4, r5, r6, r7;
-
- q0 = q[0];
- q1 = q[1];
- q2 = q[2];
- q3 = q[3];
- q4 = q[4];
- q5 = q[5];
- q6 = q[6];
- q7 = q[7];
- r0 = (q0 >> 8) | (q0 << 24);
- r1 = (q1 >> 8) | (q1 << 24);
- r2 = (q2 >> 8) | (q2 << 24);
- r3 = (q3 >> 8) | (q3 << 24);
- r4 = (q4 >> 8) | (q4 << 24);
- r5 = (q5 >> 8) | (q5 << 24);
- r6 = (q6 >> 8) | (q6 << 24);
- r7 = (q7 >> 8) | (q7 << 24);
-
- q[0] = q5 ^ q6 ^ q7 ^ r0 ^ r5 ^ r7 ^ rotr16(q0 ^ q5 ^ q6 ^ r0 ^ r5);
- q[1] = q0 ^ q5 ^ r0 ^ r1 ^ r5 ^ r6 ^ r7 ^ rotr16(q1 ^ q5 ^ q7 ^ r1 ^ r5 ^ r6);
- q[2] = q0 ^ q1 ^ q6 ^ r1 ^ r2 ^ r6 ^ r7 ^ rotr16(q0 ^ q2 ^ q6 ^ r2 ^ r6 ^ r7);
- q[3] = q0 ^ q1 ^ q2 ^ q5 ^ q6 ^ r0 ^ r2 ^ r3 ^ r5 ^ rotr16(q0 ^ q1 ^ q3 ^ q5 ^ q6 ^ q7 ^ r0 ^ r3 ^ r5 ^ r7);
- q[4] = q1 ^ q2 ^ q3 ^ q5 ^ r1 ^ r3 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr16(q1 ^ q2 ^ q4 ^ q5 ^ q7 ^ r1 ^ r4 ^ r5 ^ r6);
- q[5] = q2 ^ q3 ^ q4 ^ q6 ^ r2 ^ r4 ^ r5 ^ r6 ^ r7 ^ rotr16(q2 ^ q3 ^ q5 ^ q6 ^ r2 ^ r5 ^ r6 ^ r7);
- q[6] = q3 ^ q4 ^ q5 ^ q7 ^ r3 ^ r5 ^ r6 ^ r7 ^ rotr16(q3 ^ q4 ^ q6 ^ q7 ^ r3 ^ r6 ^ r7);
- q[7] = q4 ^ q5 ^ q6 ^ r4 ^ r6 ^ r7 ^ rotr16(q4 ^ q5 ^ q7 ^ r4 ^ r7);
+ uint32_t q0;
+ uint32_t q1;
+ uint32_t q2;
+ uint32_t q3;
+ uint32_t q4;
+ uint32_t q5;
+ uint32_t q6;
+ uint32_t q7;
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+
+ q0 = q[0];
+ q1 = q[1];
+ q2 = q[2];
+ q3 = q[3];
+ q4 = q[4];
+ q5 = q[5];
+ q6 = q[6];
+ q7 = q[7];
+ r0 = (q0 >> 8) | (q0 << 24);
+ r1 = (q1 >> 8) | (q1 << 24);
+ r2 = (q2 >> 8) | (q2 << 24);
+ r3 = (q3 >> 8) | (q3 << 24);
+ r4 = (q4 >> 8) | (q4 << 24);
+ r5 = (q5 >> 8) | (q5 << 24);
+ r6 = (q6 >> 8) | (q6 << 24);
+ r7 = (q7 >> 8) | (q7 << 24);
+
+ q[0] = q5 ^ q6 ^ q7 ^ r0 ^ r5 ^
+ r7 ^ rotr16(q0 ^ q5 ^ q6 ^ r0 ^ r5);
+
+ q[1] = q0 ^ q5 ^ r0 ^ r1 ^ r5 ^
+ r6 ^ r7 ^ rotr16(q1 ^ q5 ^ q7 ^ r1 ^ r5 ^ r6);
+
+ q[2] = q0 ^ q1 ^ q6 ^ r1 ^ r2 ^
+ r6 ^ r7 ^ rotr16(q0 ^ q2 ^ q6 ^ r2 ^ r6 ^ r7);
+
+ q[3] = q0 ^ q1 ^ q2 ^ q5 ^ q6 ^
+ r0 ^ r2 ^ r3 ^ r5 ^
+ rotr16(q0 ^ q1 ^ q3 ^ q5 ^ q6 ^ q7 ^ r0 ^ r3 ^ r5 ^ r7);
+
+ q[4] = q1 ^ q2 ^ q3 ^ q5 ^ r1 ^
+ r3 ^ r4 ^ r5 ^ r6 ^ r7 ^
+ rotr16(q1 ^ q2 ^ q4 ^ q5 ^ q7 ^ r1 ^ r4 ^ r5 ^ r6);
+
+ q[5] = q2 ^ q3 ^ q4 ^ q6 ^ r2 ^
+ r4 ^ r5 ^ r6 ^ r7 ^
+ rotr16(q2 ^ q3 ^ q5 ^ q6 ^ r2 ^ r5 ^ r6 ^ r7);
+
+ q[6] = q3 ^ q4 ^ q5 ^ q7 ^ r3 ^
+ r5 ^ r6 ^ r7 ^
+ rotr16(q3 ^ q4 ^ q6 ^ q7 ^ r3 ^ r6 ^ r7);
+
+ q[7] = q4 ^ q5 ^ q6 ^ r4 ^ r6 ^
+ r7 ^ rotr16(q4 ^ q5 ^ q7 ^ r4 ^ r7);
}
-/*
- * Compute AES decryption on bitsliced data. Since input is stored on
- * eight 32-bit words, two block decryptions are actually performed
- * in parallel.
+/* Compute AES decryption on bitsliced data.
+ * Since input is stored on
+ * eight 32-bit words, two block decryptions
+ * are actually performed in parallel.
*/
-void
-aes_ct_bitslice_decrypt(unsigned num_rounds,
- const uint32_t *skey, uint32_t *q)
+
+void aes_ct_bitslice_decrypt(unsigned num_rounds,
+ FAR const uint32_t *skey,
+ FAR uint32_t *q)
{
- unsigned u;
-
- add_round_key(q, skey + (num_rounds << 3));
- for (u = num_rounds - 1; u > 0; u --) {
- inv_shift_rows(q);
- aes_ct_bitslice_invSbox(q);
- add_round_key(q, skey + (u << 3));
- inv_mix_columns(q);
- }
- inv_shift_rows(q);
- aes_ct_bitslice_invSbox(q);
- add_round_key(q, skey);
+ unsigned u;
+
+ add_round_key(q, skey + (num_rounds << 3));
+ for (u = num_rounds - 1; u > 0; u--)
+ {
+ inv_shift_rows(q);
+ aes_ct_bitslice_invsbox(q);
+ add_round_key(q, skey + (u << 3));
+ inv_mix_columns(q);
+ }
+
+ inv_shift_rows(q);
+ aes_ct_bitslice_invsbox(q);
+ add_round_key(q, skey);
}
-
-int
-AES_Setkey(AES_CTX *ctx, const uint8_t *key, int len)
+int aes_setkey(FAR AES_CTX *ctx, FAR const uint8_t *key, int len)
{
- ctx->num_rounds = aes_ct_keysched(ctx->sk, key, len);
- if (ctx->num_rounds == 0)
- return -1;
- aes_ct_skey_expand(ctx->sk_exp, ctx->num_rounds, ctx->sk);
- return 0;
+ ctx->num_rounds = aes_ct_keysched(ctx->sk, key, len);
+ if (ctx->num_rounds == 0)
+ {
+ return -1;
+ }
+
+ aes_ct_skey_expand(ctx->sk_exp, ctx->num_rounds, ctx->sk);
+ return 0;
}
-void
-AES_Encrypt_ECB(AES_CTX *ctx, const uint8_t *src,
- uint8_t *dst, size_t num_blocks)
+void aes_encrypt_ecb(FAR AES_CTX *ctx, FAR const uint8_t *src,
+ FAR uint8_t *dst, size_t num_blocks)
{
- while (num_blocks > 0) {
- uint32_t q[8];
-
- q[0] = dec32le(src);
- q[2] = dec32le(src + 4);
- q[4] = dec32le(src + 8);
- q[6] = dec32le(src + 12);
- if (num_blocks > 1) {
- q[1] = dec32le(src + 16);
- q[3] = dec32le(src + 20);
- q[5] = dec32le(src + 24);
- q[7] = dec32le(src + 28);
- } else {
- q[1] = 0;
- q[3] = 0;
- q[5] = 0;
- q[7] = 0;
- }
- aes_ct_ortho(q);
- aes_ct_bitslice_encrypt(ctx->num_rounds, ctx->sk_exp, q);
- aes_ct_ortho(q);
- enc32le(dst, q[0]);
- enc32le(dst + 4, q[2]);
- enc32le(dst + 8, q[4]);
- enc32le(dst + 12, q[6]);
- if (num_blocks > 1) {
- enc32le(dst + 16, q[1]);
- enc32le(dst + 20, q[3]);
- enc32le(dst + 24, q[5]);
- enc32le(dst + 28, q[7]);
- src += 32;
- dst += 32;
- num_blocks -= 2;
- } else {
- break;
- }
- }
+ while (num_blocks > 0)
+ {
+ uint32_t q[8];
+
+ q[0] = dec32le(src);
+ q[2] = dec32le(src + 4);
+ q[4] = dec32le(src + 8);
+ q[6] = dec32le(src + 12);
+ if (num_blocks > 1)
+ {
+ q[1] = dec32le(src + 16);
+ q[3] = dec32le(src + 20);
+ q[5] = dec32le(src + 24);
+ q[7] = dec32le(src + 28);
+ }
+ else
+ {
+ q[1] = 0;
+ q[3] = 0;
+ q[5] = 0;
+ q[7] = 0;
+ }
+
+ aes_ct_ortho(q);
+ aes_ct_bitslice_encrypt(ctx->num_rounds, ctx->sk_exp, q);
+ aes_ct_ortho(q);
+ enc32le(dst, q[0]);
+ enc32le(dst + 4, q[2]);
+ enc32le(dst + 8, q[4]);
+ enc32le(dst + 12, q[6]);
+ if (num_blocks > 1)
+ {
+ enc32le(dst + 16, q[1]);
+ enc32le(dst + 20, q[3]);
+ enc32le(dst + 24, q[5]);
+ enc32le(dst + 28, q[7]);
+ src += 32;
+ dst += 32;
+ num_blocks -= 2;
+ }
+ else
+ {
+ break;
+ }
+ }
}
-void
-AES_Decrypt_ECB(AES_CTX *ctx, const uint8_t *src,
- uint8_t *dst, size_t num_blocks)
+void aes_decrypt_ecb(FAR AES_CTX *ctx, FAR const uint8_t *src,
+ FAR uint8_t *dst, size_t num_blocks)
{
- while (num_blocks > 0) {
- uint32_t q[8];
-
- q[0] = dec32le(src);
- q[2] = dec32le(src + 4);
- q[4] = dec32le(src + 8);
- q[6] = dec32le(src + 12);
- if (num_blocks > 1) {
- q[1] = dec32le(src + 16);
- q[3] = dec32le(src + 20);
- q[5] = dec32le(src + 24);
- q[7] = dec32le(src + 28);
- } else {
- q[1] = 0;
- q[3] = 0;
- q[5] = 0;
- q[7] = 0;
- }
- aes_ct_ortho(q);
- aes_ct_bitslice_decrypt(ctx->num_rounds, ctx->sk_exp, q);
- aes_ct_ortho(q);
- enc32le(dst, q[0]);
- enc32le(dst + 4, q[2]);
- enc32le(dst + 8, q[4]);
- enc32le(dst + 12, q[6]);
- if (num_blocks > 1) {
- enc32le(dst + 16, q[1]);
- enc32le(dst + 20, q[3]);
- enc32le(dst + 24, q[5]);
- enc32le(dst + 28, q[7]);
- src += 32;
- dst += 32;
- num_blocks -= 2;
- } else {
- break;
- }
- }
+ while (num_blocks > 0)
+ {
+ uint32_t q[8];
+
+ q[0] = dec32le(src);
+ q[2] = dec32le(src + 4);
+ q[4] = dec32le(src + 8);
+ q[6] = dec32le(src + 12);
+ if (num_blocks > 1)
+ {
+ q[1] = dec32le(src + 16);
+ q[3] = dec32le(src + 20);
+ q[5] = dec32le(src + 24);
+ q[7] = dec32le(src + 28);
+ }
+ else
+ {
+ q[1] = 0;
+ q[3] = 0;
+ q[5] = 0;
+ q[7] = 0;
+ }
+
+ aes_ct_ortho(q);
+ aes_ct_bitslice_decrypt(ctx->num_rounds, ctx->sk_exp, q);
+ aes_ct_ortho(q);
+ enc32le(dst, q[0]);
+ enc32le(dst + 4, q[2]);
+ enc32le(dst + 8, q[4]);
+ enc32le(dst + 12, q[6]);
+ if (num_blocks > 1)
+ {
+ enc32le(dst + 16, q[1]);
+ enc32le(dst + 20, q[3]);
+ enc32le(dst + 24, q[5]);
+ enc32le(dst + 28, q[7]);
+ src += 32;
+ dst += 32;
+ num_blocks -= 2;
+ }
+ else
+ {
+ break;
+ }
+ }
}
-void
-AES_Encrypt(AES_CTX *ctx, const uint8_t *src, uint8_t *dst)
+void aes_encrypt(FAR AES_CTX *ctx, FAR const uint8_t *src, FAR uint8_t *dst)
{
- AES_Encrypt_ECB(ctx, src, dst, 1);
+ aes_encrypt_ecb(ctx, src, dst, 1);
}
-void
-AES_Decrypt(AES_CTX *ctx, const uint8_t *src, uint8_t *dst)
+void aes_decrypt(FAR AES_CTX *ctx, FAR const uint8_t *src, FAR uint8_t *dst)
{
- AES_Decrypt_ECB(ctx, src, dst, 1);
+ aes_decrypt_ecb(ctx, src, dst, 1);
}
-int
-AES_KeySetup_Encrypt(uint32_t *skey, const uint8_t *key, int len)
+int aes_keysetup_encrypt(FAR uint32_t *skey, FAR const uint8_t *key, int len)
{
- unsigned r, u;
- uint32_t tkey[60];
-
- r = aes_keysched_base(tkey, key, len);
- if (r == 0) {
- return 0;
- }
- for (u = 0; u < ((r + 1) << 2); u ++) {
- uint32_t w;
-
- w = tkey[u];
- skey[u] = (w << 24)
- | ((w & 0x0000FF00) << 8)
- | ((w & 0x00FF0000) >> 8)
- | (w >> 24);
- }
- return r;
+ unsigned r;
+ unsigned u;
+ uint32_t tkey[60];
+
+ r = aes_keysched_base(tkey, key, len);
+ if (r == 0)
+ {
+ return 0;
+ }
+
+ for (u = 0; u < ((r + 1) << 2); u++)
+ {
+ uint32_t w;
+
+ w = tkey[u];
+ skey[u] = (w << 24)
+ | ((w & 0x0000ff00) << 8)
+ | ((w & 0x00ff0000) >> 8)
+ | (w >> 24);
+ }
+
+ return r;
}
-/*
- * Reduce value x modulo polynomial x^8+x^4+x^3+x+1. This works as
+/* Reduce value x modulo polynomial x^8+x^4+x^3+x+1. This works as
* long as x fits on 12 bits at most.
*/
-static inline uint32_t
-redgf256(uint32_t x)
+
+static inline uint32_t redgf256(uint32_t x)
{
- uint32_t h;
+ uint32_t h;
- h = x >> 8;
- return (x ^ h ^ (h << 1) ^ (h << 3) ^ (h << 4)) & 0xFF;
+ h = x >> 8;
+ return (x ^ h ^ (h << 1) ^ (h << 3) ^ (h << 4)) & 0xff;
}
-/*
- * Multiplication by 0x09 in GF(256).
- */
-static inline uint32_t
-mul9(uint32_t x)
+/* Multiplication by 0x09 in GF(256). */
+
+static inline uint32_t mul9(uint32_t x)
{
- return redgf256(x ^ (x << 3));
+ return redgf256(x ^ (x << 3));
}
-/*
- * Multiplication by 0x0B in GF(256).
- */
-static inline uint32_t
-mulb(uint32_t x)
+/* Multiplication by 0x0B in GF(256). */
+
+static inline uint32_t mulb(uint32_t x)
{
- return redgf256(x ^ (x << 1) ^ (x << 3));
+ return redgf256(x ^ (x << 1) ^ (x << 3));
}
-/*
- * Multiplication by 0x0D in GF(256).
- */
-static inline uint32_t
-muld(uint32_t x)
+/* Multiplication by 0x0D in GF(256). */
+
+static inline uint32_t muld(uint32_t x)
{
- return redgf256(x ^ (x << 2) ^ (x << 3));
+ return redgf256(x ^ (x << 2) ^ (x << 3));
}
-/*
- * Multiplication by 0x0E in GF(256).
- */
-static inline uint32_t
-mule(uint32_t x)
+/* Multiplication by 0x0E in GF(256). */
+
+static inline uint32_t mule(uint32_t x)
{
- return redgf256((x << 1) ^ (x << 2) ^ (x << 3));
+ return redgf256((x << 1) ^ (x << 2) ^ (x << 3));
}
-int
-AES_KeySetup_Decrypt(uint32_t *skey, const uint8_t *key, int len)
+int aes_keysetup_decrypt(FAR uint32_t *skey,
+ FAR const uint8_t *key,
+ int len)
{
- unsigned r, u;
- uint32_t tkey[60];
-
- /*
- * Compute encryption subkeys. We get them in big-endian
- * notation.
- */
- r = AES_KeySetup_Encrypt(tkey, key, len);
- if (r == 0) {
- return 0;
- }
-
- /*
- * Copy the subkeys in reverse order. Also, apply InvMixColumns()
- * on the subkeys (except first and last).
- */
- memcpy(skey + (r << 2), tkey, 4 * sizeof(uint32_t));
- memcpy(skey, tkey + (r << 2), 4 * sizeof(uint32_t));
- for (u = 4; u < (r << 2); u ++) {
- uint32_t sk, sk0, sk1, sk2, sk3;
- uint32_t tk, tk0, tk1, tk2, tk3;
-
- sk = tkey[u];
- sk0 = sk >> 24;
- sk1 = (sk >> 16) & 0xFF;
- sk2 = (sk >> 8) & 0xFF;
- sk3 = sk & 0xFF;
- tk0 = mule(sk0) ^ mulb(sk1) ^ muld(sk2) ^ mul9(sk3);
- tk1 = mul9(sk0) ^ mule(sk1) ^ mulb(sk2) ^ muld(sk3);
- tk2 = muld(sk0) ^ mul9(sk1) ^ mule(sk2) ^ mulb(sk3);
- tk3 = mulb(sk0) ^ muld(sk1) ^ mul9(sk2) ^ mule(sk3);
- tk = (tk0 << 24) ^ (tk1 << 16) ^ (tk2 << 8) ^ tk3;
- skey[((r - (u >> 2)) << 2) + (u & 3)] = tk;
- }
-
- return r;
+ unsigned r;
+ unsigned u;
+ uint32_t tkey[60];
+
+ /* Compute encryption subkeys. We get them in big-endian
+ * notation.
+ */
+
+ r = aes_keysetup_encrypt(tkey, key, len);
+ if (r == 0)
+ {
+ return 0;
+ }
+
+ /* Copy the subkeys in reverse order. Also, apply InvMixColumns()
+ * on the subkeys (except first and last).
+ */
+
+ memcpy(skey + (r << 2), tkey, 4 * sizeof(uint32_t));
+ memcpy(skey, tkey + (r << 2), 4 * sizeof(uint32_t));
+ for (u = 4; u < (r << 2); u++)
+ {
+ uint32_t sk;
+ uint32_t sk0;
+ uint32_t sk1;
+ uint32_t sk2;
+ uint32_t sk3;
+ uint32_t tk;
+ uint32_t tk0;
+ uint32_t tk1;
+ uint32_t tk2;
+ uint32_t tk3;
+
+ sk = tkey[u];
+ sk0 = sk >> 24;
+ sk1 = (sk >> 16) & 0xff;
+ sk2 = (sk >> 8) & 0xff;
+ sk3 = sk & 0xff;
+ tk0 = mule(sk0) ^ mulb(sk1) ^ muld(sk2) ^ mul9(sk3);
+ tk1 = mul9(sk0) ^ mule(sk1) ^ mulb(sk2) ^ muld(sk3);
+ tk2 = muld(sk0) ^ mul9(sk1) ^ mule(sk2) ^ mulb(sk3);
+ tk3 = mulb(sk0) ^ muld(sk1) ^ mul9(sk2) ^ mule(sk3);
+ tk = (tk0 << 24) ^ (tk1 << 16) ^ (tk2 << 8) ^ tk3;
+ skey[((r - (u >> 2)) << 2) + (u & 3)] = tk;
+ }
+
+ return r;
}
diff --git a/crypto/blf.c b/crypto/blf.c
index 957d83da7b..6d49b32b4d 100644
--- a/crypto/blf.c
+++ b/crypto/blf.c
@@ -1,6 +1,7 @@
-/* $OpenBSD: blf.c,v 1.8 2021/11/29 01:04:45 djm Exp $ */
-
-/*
+/****************************************************************************
+ * crypto/blf.c
+ * $OpenBSD: blf.c,v 1.8 2021/11/29 01:04:45 djm Exp $ *
+ *
* Blowfish block cipher for OpenBSD
* Copyright 1997 Niels Provos <pr...@physnet.uni-hamburg.de>
* All rights reserved.
@@ -28,15 +29,18 @@
* 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.
- */
+ ****************************************************************************/
-/*
- * This code is derived from section 14.3 and the given source
+/* This code is derived from section 14.3 and the given source
* in section V of Applied Cryptography, second edition.
* Blowfish is an unpatented fast block cipher designed by
* Bruce Schneier.
*/
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
#include <sys/param.h>
#include <sys/systm.h>
@@ -45,611 +49,648 @@
#undef inline
#ifdef __GNUC__
#define inline __inline
-#else /* !__GNUC__ */
+#else
#define inline
-#endif /* !__GNUC__ */
+#endif
/* Function for Feistel Networks */
-#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \
- + (s)[0x100 + (((x)>>16)&0xFF)]) \
- ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \
- + (s)[0x300 + ( (x) &0xFF)])
+#define F(s, x) ((((s)[(((x) >> 24) & 0xff)] \
+ + (s)[0x100 + (((x) >> 16) & 0xff)]) \
+ ^ (s)[0x200 + (((x) >> 8) & 0xff)]) \
+ + (s)[0x300 + ((x) & 0xff)])
+
+#define BLFRND(s, p, i, j, n) (i ^= F(s, j) ^ (p)[n])
-#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
-void
-Blowfish_encipher(blf_ctx *c, u_int32_t *x)
+void blowfish_encipher(FAR blf_ctx *c, FAR uint32_t *x)
{
- u_int32_t Xl;
- u_int32_t Xr;
- u_int32_t *s = c->S[0];
- u_int32_t *p = c->P;
-
- Xl = x[0];
- Xr = x[1];
-
- Xl ^= p[0];
- BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2);
- BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4);
- BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6);
- BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8);
- BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10);
- BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12);
- BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14);
- BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16);
-
- x[0] = Xr ^ p[17];
- x[1] = Xl;
+ uint32_t xl;
+ uint32_t xr;
+ FAR uint32_t *s = c->S[0];
+ FAR uint32_t *p = c->P;
+
+ xl = x[0];
+ xr = x[1];
+
+ xl ^= p[0];
+ BLFRND(s, p, xr, xl, 1); BLFRND(s, p, xl, xr, 2);
+ BLFRND(s, p, xr, xl, 3); BLFRND(s, p, xl, xr, 4);
+ BLFRND(s, p, xr, xl, 5); BLFRND(s, p, xl, xr, 6);
+ BLFRND(s, p, xr, xl, 7); BLFRND(s, p, xl, xr, 8);
+ BLFRND(s, p, xr, xl, 9); BLFRND(s, p, xl, xr, 10);
+ BLFRND(s, p, xr, xl, 11); BLFRND(s, p, xl, xr, 12);
+ BLFRND(s, p, xr, xl, 13); BLFRND(s, p, xl, xr, 14);
+ BLFRND(s, p, xr, xl, 15); BLFRND(s, p, xl, xr, 16);
+
+ x[0] = xr ^ p[17];
+ x[1] = xl;
}
-void
-Blowfish_decipher(blf_ctx *c, u_int32_t *x)
+void blowfish_decipher(FAR blf_ctx *c, FAR uint32_t *x)
{
- u_int32_t Xl;
- u_int32_t Xr;
- u_int32_t *s = c->S[0];
- u_int32_t *p = c->P;
-
- Xl = x[0];
- Xr = x[1];
-
- Xl ^= p[17];
- BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15);
- BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13);
- BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11);
- BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9);
- BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7);
- BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5);
- BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3);
- BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1);
-
- x[0] = Xr ^ p[0];
- x[1] = Xl;
+ uint32_t xl;
+ uint32_t xr;
+ FAR uint32_t *s = c->S[0];
+ FAR uint32_t *p = c->P;
+
+ xl = x[0];
+ xr = x[1];
+
+ xl ^= p[17];
+ BLFRND(s, p, xr, xl, 16); BLFRND(s, p, xl, xr, 15);
+ BLFRND(s, p, xr, xl, 14); BLFRND(s, p, xl, xr, 13);
+ BLFRND(s, p, xr, xl, 12); BLFRND(s, p, xl, xr, 11);
+ BLFRND(s, p, xr, xl, 10); BLFRND(s, p, xl, xr, 9);
+ BLFRND(s, p, xr, xl, 8); BLFRND(s, p, xl, xr, 7);
+ BLFRND(s, p, xr, xl, 6); BLFRND(s, p, xl, xr, 5);
+ BLFRND(s, p, xr, xl, 4); BLFRND(s, p, xl, xr, 3);
+ BLFRND(s, p, xr, xl, 2); BLFRND(s, p, xl, xr, 1);
+
+ x[0] = xr ^ p[0];
+ x[1] = xl;
}
-void
-Blowfish_initstate(blf_ctx *c)
+void blowfish_initstate(FAR blf_ctx *c)
{
- /* P-box and S-box tables initialized with digits of Pi */
-
- static const blf_ctx initstate =
-
- { {
- {
- 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
- 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
- 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
- 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
- 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
- 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
- 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
- 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
- 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
- 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
- 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
- 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
- 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
- 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
- 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
- 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
- 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
- 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
- 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
- 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
- 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
- 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
- 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
- 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
- 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
- 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
- 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
- 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
- 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
- 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
- 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
- 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
- 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
- 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
- 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
- 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
- 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
- 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
- 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
- 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
- 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
- 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
- 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
- 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
- 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
- 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
- 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
- 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
- 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
- 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
- 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
- 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
- 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
- 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
- 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
- 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
- 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
- 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
- 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
- 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
- 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
- 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
- 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
- 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
- {
- 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
- 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
- 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
- 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
- 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
- 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
- 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
- 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
- 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
- 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
- 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
- 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
- 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
- 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
- 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
- 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
- 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
- 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
- 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
- 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
- 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
- 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
- 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
- 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
- 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
- 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
- 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
- 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
- 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
- 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
- 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
- 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
- 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
- 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
- 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
- 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
- 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
- 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
- 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
- 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
- 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
- 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
- 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
- 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
- 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
- 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
- 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
- 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
- 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
- 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
- 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
- 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
- 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
- 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
- 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
- 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
- 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
- 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
- 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
- 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
- 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
- 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
- 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
- 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
- {
- 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
- 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
- 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
- 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
- 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
- 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
- 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
- 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
- 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
- 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
- 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
- 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
- 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
- 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
- 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
- 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
- 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
- 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
- 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
- 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
- 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
- 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
- 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
- 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
- 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
- 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
- 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
- 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
- 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
- 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
- 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
- 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
- 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
- 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
- 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
- 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
- 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
- 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
- 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
- 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
- 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
- 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
- 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
- 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
- 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
- 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
- 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
- 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
- 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
- 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
- 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
- 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
- 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
- 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
- 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
- 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
- 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
- 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
- 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
- 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
- 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
- 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
- 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
- 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
- {
- 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
- 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
- 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
- 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
- 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
- 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
- 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
- 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
- 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
- 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
- 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
- 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
- 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
- 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
- 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
- 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
- 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
- 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
- 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
- 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
- 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
- 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
- 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
- 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
- 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
- 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
- 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
- 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
- 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
- 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
- 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
- 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
- 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
- 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
- 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
- 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
- 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
- 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
- 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
- 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
- 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
- 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
- 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
- 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
- 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
- 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
- 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
- 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
- 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
- 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
- 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
- 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
- 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
- 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
- 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
- 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
- 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
- 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
- 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
- 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
- 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
- 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
- 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
- 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}
- },
- {
- 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
- 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
- 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
- 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
- 0x9216d5d9, 0x8979fb1b
- } };
-
- *c = initstate;
+ /* P-box and S-box tables initialized with digits of Pi */
+
+ static const blf_ctx initstate =
+ {
+ {
+ {
+ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+ 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+ 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+ 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+ 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+ 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+ 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+ 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+ 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+ 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+ 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+ 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+ 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+ 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+ 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+ 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+ 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+ 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+ 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+ 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+ 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+ 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+ 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+ 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+ 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+ 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+ 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+ 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+ 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+ 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+ 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+ 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+ 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+ 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+ 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+ 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+ 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+ 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+ 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+ 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+ 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+ 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+ 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+ 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+ 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+ 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+ 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+ 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+ 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+ 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+ 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+ 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+ 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+ 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+ 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+ 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+ 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+ 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+ 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+ 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+ 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+ 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+ 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
+ },
+ {
+ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+ 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+ 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+ 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+ 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+ 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+ 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+ 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+ 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+ 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+ 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+ 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+ 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+ 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+ 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+ 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+ 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+ 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+ 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+ 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+ 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+ 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+ 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+ 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+ 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+ 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+ 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+ 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+ 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+ 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+ 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+ 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+ 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+ 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+ 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+ 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+ 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+ 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+ 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+ 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+ 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+ 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+ 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+ 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+ 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+ 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+ 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+ 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+ 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+ 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+ 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+ 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+ 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+ 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+ 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+ 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+ 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+ 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+ 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+ 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+ 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+ 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+ 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
+ },
+ {
+ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+ 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+ 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+ 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+ 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+ 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+ 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+ 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+ 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+ 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+ 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+ 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+ 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+ 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+ 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+ 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+ 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+ 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+ 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+ 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+ 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+ 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+ 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+ 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+ 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+ 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+ 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+ 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+ 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+ 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+ 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+ 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+ 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+ 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+ 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+ 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+ 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+ 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+ 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+ 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+ 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+ 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+ 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+ 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+ 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+ 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+ 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+ 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+ 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+ 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+ 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+ 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+ 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+ 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+ 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+ 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+ 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+ 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+ 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+ 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+ 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+ 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+ 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
+ },
+ {
+ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+ 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+ 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+ 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+ 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+ 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+ 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+ 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+ 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+ 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+ 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+ 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+ 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+ 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+ 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+ 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+ 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+ 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+ 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+ 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+ 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+ 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+ 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+ 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+ 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+ 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+ 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+ 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+ 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+ 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+ 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+ 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+ 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+ 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+ 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+ 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+ 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+ 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+ 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+ 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+ 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+ 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+ 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+ 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+ 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+ 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+ 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+ 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+ 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+ 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+ 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+ 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+ 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+ 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+ 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+ 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+ 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+ 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+ 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+ 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+ 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+ 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+ 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
+ }
+ },
+ {
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+ 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+ 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
+ 0x9216d5d9, 0x8979fb1b
+ }
+ };
+
+ *c = initstate;
}
-u_int32_t
-Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
- u_int16_t *current)
+uint32_t blowfish_stream2word(FAR const uint8_t *data, uint16_t databytes,
+ FAR uint16_t *current)
{
- u_int8_t i;
- u_int16_t j;
- u_int32_t temp;
+ uint8_t i;
+ uint16_t j;
+ uint32_t temp;
- temp = 0x00000000;
- j = *current;
+ temp = 0x00000000;
+ j = *current;
- for (i = 0; i < 4; i++, j++) {
- if (j >= databytes)
- j = 0;
- temp = (temp << 8) | data[j];
- }
+ for (i = 0; i < 4; i++, j++)
+ {
+ if (j >= databytes)
+ {
+ j = 0;
+ }
- *current = j;
- return temp;
+ temp = (temp << 8) | data[j];
+ }
+
+ *current = j;
+ return temp;
}
-void
-Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
+void blowfish_expand0state(FAR blf_ctx *c,
+ FAR const uint8_t *key,
+ uint16_t keybytes)
{
- u_int16_t i;
- u_int16_t j;
- u_int16_t k;
- u_int32_t temp;
- u_int32_t data[2];
-
- j = 0;
- for (i = 0; i < BLF_N + 2; i++) {
- /* Extract 4 int8 to 1 int32 from keystream */
- temp = Blowfish_stream2word(key, keybytes, &j);
- c->P[i] = c->P[i] ^ temp;
- }
-
- j = 0;
- data[0] = 0x00000000;
- data[1] = 0x00000000;
- for (i = 0; i < BLF_N + 2; i += 2) {
- Blowfish_encipher(c, data);
-
- c->P[i] = data[0];
- c->P[i + 1] = data[1];
- }
-
- for (i = 0; i < 4; i++) {
- for (k = 0; k < 256; k += 2) {
- Blowfish_encipher(c, data);
-
- c->S[i][k] = data[0];
- c->S[i][k + 1] = data[1];
- }
- }
+ uint16_t i;
+ uint16_t j;
+ uint16_t k;
+ uint32_t temp;
+ uint32_t data[2];
+
+ j = 0;
+ for (i = 0; i < BLF_N + 2; i++)
+ {
+ /* Extract 4 int8 to 1 int32 from keystream */
+
+ temp = blowfish_stream2word(key, keybytes, &j);
+ c->P[i] = c->P[i] ^ temp;
+ }
+
+ j = 0;
+ data[0] = 0x00000000;
+ data[1] = 0x00000000;
+ for (i = 0; i < BLF_N + 2; i += 2)
+ {
+ blowfish_encipher(c, data);
+
+ c->P[i] = data[0];
+ c->P[i + 1] = data[1];
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ for (k = 0; k < 256; k += 2)
+ {
+ blowfish_encipher(c, data);
+
+ c->S[i][k] = data[0];
+ c->S[i][k + 1] = data[1];
+ }
+ }
}
-
-void
-Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
- const u_int8_t *key, u_int16_t keybytes)
+void blowfish_expandstate(FAR blf_ctx *c, FAR const uint8_t *data,
+ uint16_t databytes,
+ FAR const uint8_t *key, uint16_t keybytes)
{
- u_int16_t i;
- u_int16_t j;
- u_int16_t k;
- u_int32_t temp;
- u_int32_t d[2];
-
- j = 0;
- for (i = 0; i < BLF_N + 2; i++) {
- /* Extract 4 int8 to 1 int32 from keystream */
- temp = Blowfish_stream2word(key, keybytes, &j);
- c->P[i] = c->P[i] ^ temp;
- }
-
- j = 0;
- d[0] = 0x00000000;
- d[1] = 0x00000000;
- for (i = 0; i < BLF_N + 2; i += 2) {
- d[0] ^= Blowfish_stream2word(data, databytes, &j);
- d[1] ^= Blowfish_stream2word(data, databytes, &j);
- Blowfish_encipher(c, d);
-
- c->P[i] = d[0];
- c->P[i + 1] = d[1];
- }
-
- for (i = 0; i < 4; i++) {
- for (k = 0; k < 256; k += 2) {
- d[0]^= Blowfish_stream2word(data, databytes, &j);
- d[1] ^= Blowfish_stream2word(data, databytes, &j);
- Blowfish_encipher(c, d);
-
- c->S[i][k] = d[0];
- c->S[i][k + 1] = d[1];
- }
- }
-
+ uint16_t i;
+ uint16_t j;
+ uint16_t k;
+ uint32_t temp;
+ uint32_t d[2];
+
+ j = 0;
+ for (i = 0; i < BLF_N + 2; i++)
+ {
+ /* Extract 4 int8 to 1 int32 from keystream */
+
+ temp = blowfish_stream2word(key, keybytes, &j);
+ c->P[i] = c->P[i] ^ temp;
+ }
+
+ j = 0;
+ d[0] = 0x00000000;
+ d[1] = 0x00000000;
+ for (i = 0; i < BLF_N + 2; i += 2)
+ {
+ d[0] ^= blowfish_stream2word(data, databytes, &j);
+ d[1] ^= blowfish_stream2word(data, databytes, &j);
+ blowfish_encipher(c, d);
+
+ c->P[i] = d[0];
+ c->P[i + 1] = d[1];
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ for (k = 0; k < 256; k += 2)
+ {
+ d[0] ^= blowfish_stream2word(data, databytes, &j);
+ d[1] ^= blowfish_stream2word(data, databytes, &j);
+ blowfish_encipher(c, d);
+
+ c->S[i][k] = d[0];
+ c->S[i][k + 1] = d[1];
+ }
+ }
}
-void
-blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
+void blf_key(FAR blf_ctx *c, FAR const uint8_t *k, uint16_t len)
{
- /* Initialize S-boxes and subkeys with Pi */
- Blowfish_initstate(c);
+ /* Initialize S-boxes and subkeys with Pi */
+
+ blowfish_initstate(c);
+
+ /* Transform S-boxes and subkeys with key */
- /* Transform S-boxes and subkeys with key */
- Blowfish_expand0state(c, k, len);
+ blowfish_expand0state(c, k, len);
}
-void
-blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
+void blf_enc(FAR blf_ctx *c, FAR uint32_t *data, uint16_t blocks)
{
- u_int32_t *d;
- u_int16_t i;
-
- d = data;
- for (i = 0; i < blocks; i++) {
- Blowfish_encipher(c, d);
- d += 2;
- }
+ FAR uint32_t *d;
+ uint16_t i;
+
+ d = data;
+ for (i = 0; i < blocks; i++)
+ {
+ blowfish_encipher(c, d);
+ d += 2;
+ }
}
-void
-blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
+void blf_dec(FAR blf_ctx *c, FAR uint32_t *data, uint16_t blocks)
{
- u_int32_t *d;
- u_int16_t i;
-
- d = data;
- for (i = 0; i < blocks; i++) {
- Blowfish_decipher(c, d);
- d += 2;
- }
+ FAR uint32_t *d;
+ uint16_t i;
+
+ d = data;
+ for (i = 0; i < blocks; i++)
+ {
+ blowfish_decipher(c, d);
+ d += 2;
+ }
}
-void
-blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
+void blf_ecb_encrypt(FAR blf_ctx *c, FAR uint8_t *data, uint32_t len)
{
- u_int32_t l, r, d[2];
- u_int32_t i;
-
- for (i = 0; i < len; i += 8) {
- l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
- r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
- d[0] = l;
- d[1] = r;
- Blowfish_encipher(c, d);
- l = d[0];
- r = d[1];
- data[0] = l >> 24 & 0xff;
- data[1] = l >> 16 & 0xff;
- data[2] = l >> 8 & 0xff;
- data[3] = l & 0xff;
- data[4] = r >> 24 & 0xff;
- data[5] = r >> 16 & 0xff;
- data[6] = r >> 8 & 0xff;
- data[7] = r & 0xff;
- data += 8;
- }
+ uint32_t l;
+ uint32_t r;
+ uint32_t d[2];
+ uint32_t i;
+
+ for (i = 0; i < len; i += 8)
+ {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ d[0] = l;
+ d[1] = r;
+ blowfish_encipher(c, d);
+ l = d[0];
+ r = d[1];
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ data += 8;
+ }
}
-void
-blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
+void blf_ecb_decrypt(FAR blf_ctx *c, FAR uint8_t *data, uint32_t len)
{
- u_int32_t l, r, d[2];
- u_int32_t i;
-
- for (i = 0; i < len; i += 8) {
- l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
- r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
- d[0] = l;
- d[1] = r;
- Blowfish_decipher(c, d);
- l = d[0];
- r = d[1];
- data[0] = l >> 24 & 0xff;
- data[1] = l >> 16 & 0xff;
- data[2] = l >> 8 & 0xff;
- data[3] = l & 0xff;
- data[4] = r >> 24 & 0xff;
- data[5] = r >> 16 & 0xff;
- data[6] = r >> 8 & 0xff;
- data[7] = r & 0xff;
- data += 8;
- }
+ uint32_t l;
+ uint32_t r;
+ uint32_t d[2];
+ uint32_t i;
+
+ for (i = 0; i < len; i += 8)
+ {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ d[0] = l;
+ d[1] = r;
+ blowfish_decipher(c, d);
+ l = d[0];
+ r = d[1];
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ data += 8;
+ }
}
-void
-blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
+void blf_cbc_encrypt(FAR blf_ctx *c, FAR uint8_t *iv,
+ FAR uint8_t *data, uint32_t len)
{
- u_int32_t l, r, d[2];
- u_int32_t i, j;
-
- for (i = 0; i < len; i += 8) {
- for (j = 0; j < 8; j++)
- data[j] ^= iv[j];
- l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
- r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
- d[0] = l;
- d[1] = r;
- Blowfish_encipher(c, d);
- l = d[0];
- r = d[1];
- data[0] = l >> 24 & 0xff;
- data[1] = l >> 16 & 0xff;
- data[2] = l >> 8 & 0xff;
- data[3] = l & 0xff;
- data[4] = r >> 24 & 0xff;
- data[5] = r >> 16 & 0xff;
- data[6] = r >> 8 & 0xff;
- data[7] = r & 0xff;
- iv = data;
- data += 8;
- }
+ uint32_t l;
+ uint32_t r;
+ uint32_t d[2];
+ uint32_t i;
+ uint32_t j;
+
+ for (i = 0; i < len; i += 8)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ data[j] ^= iv[j];
+ }
+
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ d[0] = l;
+ d[1] = r;
+ blowfish_encipher(c, d);
+ l = d[0];
+ r = d[1];
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ iv = data;
+ data += 8;
+ }
}
-void
-blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
+void blf_cbc_decrypt(FAR blf_ctx *c, FAR uint8_t *iva,
+ FAR uint8_t *data, uint32_t len)
{
- u_int32_t l, r, d[2];
- u_int8_t *iv;
- u_int32_t i, j;
-
- iv = data + len - 16;
- data = data + len - 8;
- for (i = len - 8; i >= 8; i -= 8) {
- l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
- r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
- d[0] = l;
- d[1] = r;
- Blowfish_decipher(c, d);
- l = d[0];
- r = d[1];
- data[0] = l >> 24 & 0xff;
- data[1] = l >> 16 & 0xff;
- data[2] = l >> 8 & 0xff;
- data[3] = l & 0xff;
- data[4] = r >> 24 & 0xff;
- data[5] = r >> 16 & 0xff;
- data[6] = r >> 8 & 0xff;
- data[7] = r & 0xff;
- for (j = 0; j < 8; j++)
- data[j] ^= iv[j];
- iv -= 8;
- data -= 8;
- }
- l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
- r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
- d[0] = l;
- d[1] = r;
- Blowfish_decipher(c, d);
- l = d[0];
- r = d[1];
- data[0] = l >> 24 & 0xff;
- data[1] = l >> 16 & 0xff;
- data[2] = l >> 8 & 0xff;
- data[3] = l & 0xff;
- data[4] = r >> 24 & 0xff;
- data[5] = r >> 16 & 0xff;
- data[6] = r >> 8 & 0xff;
- data[7] = r & 0xff;
- for (j = 0; j < 8; j++)
- data[j] ^= iva[j];
+ uint32_t l;
+ uint32_t r;
+ uint32_t d[2];
+ FAR uint8_t *iv;
+ uint32_t i;
+ uint32_t j;
+
+ iv = data + len - 16;
+ data = data + len - 8;
+ for (i = len - 8; i >= 8; i -= 8)
+ {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ d[0] = l;
+ d[1] = r;
+ blowfish_decipher(c, d);
+ l = d[0];
+ r = d[1];
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ for (j = 0; j < 8; j++)
+ data[j] ^= iv[j];
+ iv -= 8;
+ data -= 8;
+ }
+
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ d[0] = l;
+ d[1] = r;
+ blowfish_decipher(c, d);
+ l = d[0];
+ r = d[1];
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ for (j = 0; j < 8; j++)
+ {
+ data[j] ^= iva[j];
+ }
}
diff --git a/crypto/cast.c b/crypto/cast.c
index cf3e908ac4..836d5db661 100644
--- a/crypto/cast.c
+++ b/crypto/cast.c
@@ -1,11 +1,16 @@
-/* $OpenBSD: cast.c,v 1.4 2012/04/25 04:12:27 matthew Exp $ */
+/****************************************************************************
+ * crypto/cast.c
+ * $OpenBSD: cast.c,v 1.4 2012/04/25 04:12:27 matthew Exp $
+ *
+ * CAST-128 in C
+ * Written by Steve Reid <sr...@sea-to-sky.net>
+ * 100% Public Domain - no warranty
+ * Released 1997.10.11
+ ****************************************************************************/
-/*
- * CAST-128 in C
- * Written by Steve Reid <sr...@sea-to-sky.net>
- * 100% Public Domain - no warranty
- * Released 1997.10.11
- */
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/types.h>
#include <sys/systm.h>
@@ -13,265 +18,338 @@
#include "castsb.h"
/* Macros to access 8-bit bytes out of a 32-bit word */
-#define U_INT8_Ta(x) ( (u_int8_t) (x>>24) )
-#define U_INT8_Tb(x) ( (u_int8_t) ((x>>16)&255) )
-#define U_INT8_Tc(x) ( (u_int8_t) ((x>>8)&255) )
-#define U_INT8_Td(x) ( (u_int8_t) ((x)&255) )
+
+#define UINT8_TA(x) ( (uint8_t) (x>>24) )
+#define UINT8_TB(x) ( (uint8_t) ((x>>16)&255) )
+#define UINT8_TC(x) ( (uint8_t) ((x>>8)&255) )
+#define UINT8_TD(x) ( (uint8_t) ((x)&255) )
/* Circular left shift */
+
#define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) )
/* CAST-128 uses three different round functions */
+
#define F1(l, r, i) \
- t = ROL(key->xkey[i] + r, key->xkey[i+16]); \
- l ^= ((cast_sbox1[U_INT8_Ta(t)] ^ cast_sbox2[U_INT8_Tb(t)]) - \
- cast_sbox3[U_INT8_Tc(t)]) + cast_sbox4[U_INT8_Td(t)];
+ t = ROL(key->xkey[i] + r, key->xkey[i+16]); \
+ l ^= ((cast_sbox1[UINT8_TA(t)] ^ cast_sbox2[UINT8_TB(t)]) - \
+ cast_sbox3[UINT8_TC(t)]) + cast_sbox4[UINT8_TD(t)];
+
#define F2(l, r, i) \
- t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \
- l ^= ((cast_sbox1[U_INT8_Ta(t)] - cast_sbox2[U_INT8_Tb(t)]) + \
- cast_sbox3[U_INT8_Tc(t)]) ^ cast_sbox4[U_INT8_Td(t)];
+ t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \
+ l ^= ((cast_sbox1[UINT8_TA(t)] - cast_sbox2[UINT8_TB(t)]) + \
+ cast_sbox3[UINT8_TC(t)]) ^ cast_sbox4[UINT8_TD(t)];
+
#define F3(l, r, i) \
- t = ROL(key->xkey[i] - r, key->xkey[i+16]); \
- l ^= ((cast_sbox1[U_INT8_Ta(t)] + cast_sbox2[U_INT8_Tb(t)]) ^ \
- cast_sbox3[U_INT8_Tc(t)]) - cast_sbox4[U_INT8_Td(t)];
+ t = ROL(key->xkey[i] - r, key->xkey[i+16]); \
+ l ^= ((cast_sbox1[UINT8_TA(t)] + cast_sbox2[UINT8_TB(t)]) ^ \
+ cast_sbox3[UINT8_TC(t)]) - cast_sbox4[UINT8_TD(t)];
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
-/***** Encryption Function *****/
+/* Encryption Function */
-void
-cast_encrypt(cast_key *key, u_int8_t *inblock, u_int8_t *outblock)
+void cast_encrypt(FAR cast_key *key,
+ FAR uint8_t *inblock,
+ FAR uint8_t *outblock)
{
- u_int32_t t, l, r;
-
- /* Get inblock into l,r */
- l = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) |
- ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3];
- r = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) |
- ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7];
- /* Do the work */
- F1(l, r, 0);
- F2(r, l, 1);
- F3(l, r, 2);
- F1(r, l, 3);
- F2(l, r, 4);
- F3(r, l, 5);
- F1(l, r, 6);
- F2(r, l, 7);
- F3(l, r, 8);
- F1(r, l, 9);
- F2(l, r, 10);
- F3(r, l, 11);
- /* Only do full 16 rounds if key length > 80 bits */
- if (key->rounds > 12) {
- F1(l, r, 12);
- F2(r, l, 13);
- F3(l, r, 14);
- F1(r, l, 15);
- }
- /* Put l,r into outblock */
- outblock[0] = U_INT8_Ta(r);
- outblock[1] = U_INT8_Tb(r);
- outblock[2] = U_INT8_Tc(r);
- outblock[3] = U_INT8_Td(r);
- outblock[4] = U_INT8_Ta(l);
- outblock[5] = U_INT8_Tb(l);
- outblock[6] = U_INT8_Tc(l);
- outblock[7] = U_INT8_Td(l);
- /* Wipe clean */
- t = l = r = 0;
-}
+ uint32_t t;
+ uint32_t l;
+ uint32_t r;
+ /* Get inblock into l,r */
-/***** Decryption Function *****/
+ l = ((uint32_t)inblock[0] << 24) |
+ ((uint32_t)inblock[1] << 16) |
+ ((uint32_t)inblock[2] << 8) |
+ (uint32_t)inblock[3];
-void
-cast_decrypt(cast_key *key, u_int8_t *inblock, u_int8_t *outblock)
-{
- u_int32_t t, l, r;
-
- /* Get inblock into l,r */
- r = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) |
- ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3];
- l = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) |
- ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7];
- /* Do the work */
- /* Only do full 16 rounds if key length > 80 bits */
- if (key->rounds > 12) {
- F1(r, l, 15);
- F3(l, r, 14);
- F2(r, l, 13);
- F1(l, r, 12);
- }
- F3(r, l, 11);
- F2(l, r, 10);
- F1(r, l, 9);
- F3(l, r, 8);
- F2(r, l, 7);
- F1(l, r, 6);
- F3(r, l, 5);
- F2(l, r, 4);
- F1(r, l, 3);
- F3(l, r, 2);
- F2(r, l, 1);
- F1(l, r, 0);
- /* Put l,r into outblock */
- outblock[0] = U_INT8_Ta(l);
- outblock[1] = U_INT8_Tb(l);
- outblock[2] = U_INT8_Tc(l);
- outblock[3] = U_INT8_Td(l);
- outblock[4] = U_INT8_Ta(r);
- outblock[5] = U_INT8_Tb(r);
- outblock[6] = U_INT8_Tc(r);
- outblock[7] = U_INT8_Td(r);
- /* Wipe clean */
- t = l = r = 0;
+ r = ((uint32_t)inblock[4] << 24) |
+ ((uint32_t)inblock[5] << 16) |
+ ((uint32_t)inblock[6] << 8) |
+ (uint32_t)inblock[7];
+
+ /* Do the work */
+
+ F1(l, r, 0);
+ F2(r, l, 1);
+ F3(l, r, 2);
+ F1(r, l, 3);
+ F2(l, r, 4);
+ F3(r, l, 5);
+ F1(l, r, 6);
+ F2(r, l, 7);
+ F3(l, r, 8);
+ F1(r, l, 9);
+ F2(l, r, 10);
+ F3(r, l, 11);
+
+ /* Only do full 16 rounds if key length > 80 bits */
+
+ if (key->rounds > 12)
+ {
+ F1(l, r, 12);
+ F2(r, l, 13);
+ F3(l, r, 14);
+ F1(r, l, 15);
+ }
+
+ /* Put l,r into outblock */
+
+ outblock[0] = UINT8_TA(r);
+ outblock[1] = UINT8_TB(r);
+ outblock[2] = UINT8_TC(r);
+ outblock[3] = UINT8_TD(r);
+ outblock[4] = UINT8_TA(l);
+ outblock[5] = UINT8_TB(l);
+ outblock[6] = UINT8_TC(l);
+ outblock[7] = UINT8_TD(l);
+
+ /* Wipe clean */
+
+ t = l = r = 0;
}
+/* Decryption Function */
+
+void cast_decrypt(FAR cast_key *key,
+ FAR uint8_t *inblock,
+ FAR uint8_t *outblock)
+{
+ uint32_t t;
+ uint32_t l;
+ uint32_t r;
+
+ /* Get inblock into l,r */
+
+ r = ((uint32_t)inblock[0] << 24) |
+ ((uint32_t)inblock[1] << 16) |
+ ((uint32_t)inblock[2] << 8) |
+ (uint32_t)inblock[3];
+
+ l = ((uint32_t)inblock[4] << 24) |
+ ((uint32_t)inblock[5] << 16) |
+ ((uint32_t)inblock[6] << 8) |
+ (uint32_t)inblock[7];
+
+ /* Do the work */
+
+ /* Only do full 16 rounds if key length > 80 bits */
-/***** Key Schedule *****/
+ if (key->rounds > 12)
+ {
+ F1(r, l, 15);
+ F3(l, r, 14);
+ F2(r, l, 13);
+ F1(l, r, 12);
+ }
-void
-cast_setkey(cast_key *key, u_int8_t *rawkey, int keybytes)
+ F3(r, l, 11);
+ F2(l, r, 10);
+ F1(r, l, 9);
+ F3(l, r, 8);
+ F2(r, l, 7);
+ F1(l, r, 6);
+ F3(r, l, 5);
+ F2(l, r, 4);
+ F1(r, l, 3);
+ F3(l, r, 2);
+ F2(r, l, 1);
+ F1(l, r, 0);
+
+ /* Put l,r into outblock */
+
+ outblock[0] = UINT8_TA(l);
+ outblock[1] = UINT8_TB(l);
+ outblock[2] = UINT8_TC(l);
+ outblock[3] = UINT8_TD(l);
+ outblock[4] = UINT8_TA(r);
+ outblock[5] = UINT8_TB(r);
+ outblock[6] = UINT8_TC(r);
+ outblock[7] = UINT8_TD(r);
+
+ /* Wipe clean */
+
+ t = l = r = 0;
+}
+
+/* Key Schedule */
+
+void cast_setkey(FAR cast_key *key, FAR uint8_t *rawkey, int keybytes)
{
- u_int32_t t[4], z[4], x[4];
- int i;
-
- /* Set number of rounds to 12 or 16, depending on key length */
- key->rounds = (keybytes <= 10 ? 12 : 16);
-
- /* Copy key to workspace x */
- for (i = 0; i < 4; i++) {
- x[i] = 0;
- if ((i*4+0) < keybytes) x[i] = (u_int32_t)rawkey[i*4+0] << 24;
- if ((i*4+1) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+1] << 16;
- if ((i*4+2) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+2] << 8;
- if ((i*4+3) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+3];
- }
- /* Generate 32 subkeys, four at a time */
- for (i = 0; i < 32; i+=4) {
- switch (i & 4) {
- case 0:
- t[0] = z[0] = x[0] ^ cast_sbox5[U_INT8_Tb(x[3])] ^
- cast_sbox6[U_INT8_Td(x[3])] ^
- cast_sbox7[U_INT8_Ta(x[3])] ^
- cast_sbox8[U_INT8_Tc(x[3])] ^
- cast_sbox7[U_INT8_Ta(x[2])];
- t[1] = z[1] = x[2] ^ cast_sbox5[U_INT8_Ta(z[0])] ^
- cast_sbox6[U_INT8_Tc(z[0])] ^
- cast_sbox7[U_INT8_Tb(z[0])] ^
- cast_sbox8[U_INT8_Td(z[0])] ^
- cast_sbox8[U_INT8_Tc(x[2])];
- t[2] = z[2] = x[3] ^ cast_sbox5[U_INT8_Td(z[1])] ^
- cast_sbox6[U_INT8_Tc(z[1])] ^
- cast_sbox7[U_INT8_Tb(z[1])] ^
- cast_sbox8[U_INT8_Ta(z[1])] ^
- cast_sbox5[U_INT8_Tb(x[2])];
- t[3] = z[3] = x[1] ^ cast_sbox5[U_INT8_Tc(z[2])] ^
- cast_sbox6[U_INT8_Tb(z[2])] ^
- cast_sbox7[U_INT8_Td(z[2])] ^
- cast_sbox8[U_INT8_Ta(z[2])] ^
- cast_sbox6[U_INT8_Td(x[2])];
- break;
- case 4:
- t[0] = x[0] = z[2] ^ cast_sbox5[U_INT8_Tb(z[1])] ^
- cast_sbox6[U_INT8_Td(z[1])] ^
- cast_sbox7[U_INT8_Ta(z[1])] ^
- cast_sbox8[U_INT8_Tc(z[1])] ^
- cast_sbox7[U_INT8_Ta(z[0])];
- t[1] = x[1] = z[0] ^ cast_sbox5[U_INT8_Ta(x[0])] ^
- cast_sbox6[U_INT8_Tc(x[0])] ^
- cast_sbox7[U_INT8_Tb(x[0])] ^
- cast_sbox8[U_INT8_Td(x[0])] ^
- cast_sbox8[U_INT8_Tc(z[0])];
- t[2] = x[2] = z[1] ^ cast_sbox5[U_INT8_Td(x[1])] ^
- cast_sbox6[U_INT8_Tc(x[1])] ^
- cast_sbox7[U_INT8_Tb(x[1])] ^
- cast_sbox8[U_INT8_Ta(x[1])] ^
- cast_sbox5[U_INT8_Tb(z[0])];
- t[3] = x[3] = z[3] ^ cast_sbox5[U_INT8_Tc(x[2])] ^
- cast_sbox6[U_INT8_Tb(x[2])] ^
- cast_sbox7[U_INT8_Td(x[2])] ^
- cast_sbox8[U_INT8_Ta(x[2])] ^
- cast_sbox6[U_INT8_Td(z[0])];
- break;
- }
- switch (i & 12) {
- case 0:
- case 12:
- key->xkey[i+0] = cast_sbox5[U_INT8_Ta(t[2])] ^
- cast_sbox6[U_INT8_Tb(t[2])] ^
- cast_sbox7[U_INT8_Td(t[1])] ^
- cast_sbox8[U_INT8_Tc(t[1])];
- key->xkey[i+1] = cast_sbox5[U_INT8_Tc(t[2])] ^
- cast_sbox6[U_INT8_Td(t[2])] ^
- cast_sbox7[U_INT8_Tb(t[1])] ^
- cast_sbox8[U_INT8_Ta(t[1])];
- key->xkey[i+2] = cast_sbox5[U_INT8_Ta(t[3])] ^
- cast_sbox6[U_INT8_Tb(t[3])] ^
- cast_sbox7[U_INT8_Td(t[0])] ^
- cast_sbox8[U_INT8_Tc(t[0])];
- key->xkey[i+3] = cast_sbox5[U_INT8_Tc(t[3])] ^
- cast_sbox6[U_INT8_Td(t[3])] ^
- cast_sbox7[U_INT8_Tb(t[0])] ^
- cast_sbox8[U_INT8_Ta(t[0])];
- break;
- case 4:
- case 8:
- key->xkey[i+0] = cast_sbox5[U_INT8_Td(t[0])] ^
- cast_sbox6[U_INT8_Tc(t[0])] ^
- cast_sbox7[U_INT8_Ta(t[3])] ^
- cast_sbox8[U_INT8_Tb(t[3])];
- key->xkey[i+1] = cast_sbox5[U_INT8_Tb(t[0])] ^
- cast_sbox6[U_INT8_Ta(t[0])] ^
- cast_sbox7[U_INT8_Tc(t[3])] ^
- cast_sbox8[U_INT8_Td(t[3])];
- key->xkey[i+2] = cast_sbox5[U_INT8_Td(t[1])] ^
- cast_sbox6[U_INT8_Tc(t[1])] ^
- cast_sbox7[U_INT8_Ta(t[2])] ^
- cast_sbox8[U_INT8_Tb(t[2])];
- key->xkey[i+3] = cast_sbox5[U_INT8_Tb(t[1])] ^
- cast_sbox6[U_INT8_Ta(t[1])] ^
- cast_sbox7[U_INT8_Tc(t[2])] ^
- cast_sbox8[U_INT8_Td(t[2])];
- break;
- }
- switch (i & 12) {
- case 0:
- key->xkey[i+0] ^= cast_sbox5[U_INT8_Tc(z[0])];
- key->xkey[i+1] ^= cast_sbox6[U_INT8_Tc(z[1])];
- key->xkey[i+2] ^= cast_sbox7[U_INT8_Tb(z[2])];
- key->xkey[i+3] ^= cast_sbox8[U_INT8_Ta(z[3])];
- break;
- case 4:
- key->xkey[i+0] ^= cast_sbox5[U_INT8_Ta(x[2])];
- key->xkey[i+1] ^= cast_sbox6[U_INT8_Tb(x[3])];
- key->xkey[i+2] ^= cast_sbox7[U_INT8_Td(x[0])];
- key->xkey[i+3] ^= cast_sbox8[U_INT8_Td(x[1])];
- break;
- case 8:
- key->xkey[i+0] ^= cast_sbox5[U_INT8_Tb(z[2])];
- key->xkey[i+1] ^= cast_sbox6[U_INT8_Ta(z[3])];
- key->xkey[i+2] ^= cast_sbox7[U_INT8_Tc(z[0])];
- key->xkey[i+3] ^= cast_sbox8[U_INT8_Tc(z[1])];
- break;
- case 12:
- key->xkey[i+0] ^= cast_sbox5[U_INT8_Td(x[0])];
- key->xkey[i+1] ^= cast_sbox6[U_INT8_Td(x[1])];
- key->xkey[i+2] ^= cast_sbox7[U_INT8_Ta(x[2])];
- key->xkey[i+3] ^= cast_sbox8[U_INT8_Tb(x[3])];
- break;
- }
- if (i >= 16) {
- key->xkey[i+0] &= 31;
- key->xkey[i+1] &= 31;
- key->xkey[i+2] &= 31;
- key->xkey[i+3] &= 31;
- }
- }
- /* Wipe clean */
- explicit_bzero(t, sizeof(t));
- explicit_bzero(x, sizeof(x));
- explicit_bzero(z, sizeof(z));
+ uint32_t t[4];
+ uint32_t z[4];
+ uint32_t x[4];
+ int i;
+
+ /* Set number of rounds to 12 or 16, depending on key length */
+
+ key->rounds = (keybytes <= 10 ? 12 : 16);
+
+ /* Copy key to workspace x */
+
+ for (i = 0; i < 4; i++)
+ {
+ x[i] = 0;
+ if ((i * 4 + 0) < keybytes)
+ {
+ x[i] = (uint32_t)rawkey[i * 4 + 0] << 24;
+ }
+
+ if ((i * 4 + 1) < keybytes)
+ {
+ x[i] |= (uint32_t)rawkey[i * 4 + 1] << 16;
+ }
+
+ if ((i * 4 + 2) < keybytes)
+ {
+ x[i] |= (uint32_t)rawkey[i * 4 + 2] << 8;
+ }
+
+ if ((i * 4 + 3) < keybytes)
+ {
+ x[i] |= (uint32_t)rawkey[i * 4 + 3];
+ }
+ }
+
+ /* Generate 32 subkeys, four at a time */
+
+ for (i = 0; i < 32; i += 4)
+ {
+ switch (i & 4)
+ {
+ case 0:
+ t[0] = z[0] = x[0] ^ cast_sbox5[UINT8_TB(x[3])] ^
+ cast_sbox6[UINT8_TD(x[3])] ^
+ cast_sbox7[UINT8_TA(x[3])] ^
+ cast_sbox8[UINT8_TC(x[3])] ^
+ cast_sbox7[UINT8_TA(x[2])];
+ t[1] = z[1] = x[2] ^ cast_sbox5[UINT8_TA(z[0])] ^
+ cast_sbox6[UINT8_TC(z[0])] ^
+ cast_sbox7[UINT8_TB(z[0])] ^
+ cast_sbox8[UINT8_TD(z[0])] ^
+ cast_sbox8[UINT8_TC(x[2])];
+ t[2] = z[2] = x[3] ^ cast_sbox5[UINT8_TD(z[1])] ^
+ cast_sbox6[UINT8_TC(z[1])] ^
+ cast_sbox7[UINT8_TB(z[1])] ^
+ cast_sbox8[UINT8_TA(z[1])] ^
+ cast_sbox5[UINT8_TB(x[2])];
+ t[3] = z[3] = x[1] ^ cast_sbox5[UINT8_TC(z[2])] ^
+ cast_sbox6[UINT8_TB(z[2])] ^
+ cast_sbox7[UINT8_TD(z[2])] ^
+ cast_sbox8[UINT8_TA(z[2])] ^
+ cast_sbox6[UINT8_TD(x[2])];
+ break;
+ case 4:
+ t[0] = x[0] = z[2] ^ cast_sbox5[UINT8_TB(z[1])] ^
+ cast_sbox6[UINT8_TD(z[1])] ^
+ cast_sbox7[UINT8_TA(z[1])] ^
+ cast_sbox8[UINT8_TC(z[1])] ^
+ cast_sbox7[UINT8_TA(z[0])];
+ t[1] = x[1] = z[0] ^ cast_sbox5[UINT8_TA(x[0])] ^
+ cast_sbox6[UINT8_TC(x[0])] ^
+ cast_sbox7[UINT8_TB(x[0])] ^
+ cast_sbox8[UINT8_TD(x[0])] ^
+ cast_sbox8[UINT8_TC(z[0])];
+ t[2] = x[2] = z[1] ^ cast_sbox5[UINT8_TD(x[1])] ^
+ cast_sbox6[UINT8_TC(x[1])] ^
+ cast_sbox7[UINT8_TB(x[1])] ^
+ cast_sbox8[UINT8_TA(x[1])] ^
+ cast_sbox5[UINT8_TB(z[0])];
+ t[3] = x[3] = z[3] ^ cast_sbox5[UINT8_TC(x[2])] ^
+ cast_sbox6[UINT8_TB(x[2])] ^
+ cast_sbox7[UINT8_TD(x[2])] ^
+ cast_sbox8[UINT8_TA(x[2])] ^
+ cast_sbox6[UINT8_TD(z[0])];
+ break;
+ }
+
+ switch (i & 12)
+ {
+ case 0:
+ case 12:
+ key->xkey[i + 0] = cast_sbox5[UINT8_TA(t[2])] ^
+ cast_sbox6[UINT8_TB(t[2])] ^
+ cast_sbox7[UINT8_TD(t[1])] ^
+ cast_sbox8[UINT8_TC(t[1])];
+ key->xkey[i + 1] = cast_sbox5[UINT8_TC(t[2])] ^
+ cast_sbox6[UINT8_TD(t[2])] ^
+ cast_sbox7[UINT8_TB(t[1])] ^
+ cast_sbox8[UINT8_TA(t[1])];
+ key->xkey[i + 2] = cast_sbox5[UINT8_TA(t[3])] ^
+ cast_sbox6[UINT8_TB(t[3])] ^
+ cast_sbox7[UINT8_TD(t[0])] ^
+ cast_sbox8[UINT8_TC(t[0])];
+ key->xkey[i + 3] = cast_sbox5[UINT8_TC(t[3])] ^
+ cast_sbox6[UINT8_TD(t[3])] ^
+ cast_sbox7[UINT8_TB(t[0])] ^
+ cast_sbox8[UINT8_TA(t[0])];
+ break;
+ case 4:
+ case 8:
+ key->xkey[i + 0] = cast_sbox5[UINT8_TD(t[0])] ^
+ cast_sbox6[UINT8_TC(t[0])] ^
+ cast_sbox7[UINT8_TA(t[3])] ^
+ cast_sbox8[UINT8_TB(t[3])];
+ key->xkey[i + 1] = cast_sbox5[UINT8_TB(t[0])] ^
+ cast_sbox6[UINT8_TA(t[0])] ^
+ cast_sbox7[UINT8_TC(t[3])] ^
+ cast_sbox8[UINT8_TD(t[3])];
+ key->xkey[i + 2] = cast_sbox5[UINT8_TD(t[1])] ^
+ cast_sbox6[UINT8_TC(t[1])] ^
+ cast_sbox7[UINT8_TA(t[2])] ^
+ cast_sbox8[UINT8_TB(t[2])];
+ key->xkey[i + 3] = cast_sbox5[UINT8_TB(t[1])] ^
+ cast_sbox6[UINT8_TA(t[1])] ^
+ cast_sbox7[UINT8_TC(t[2])] ^
+ cast_sbox8[UINT8_TD(t[2])];
+ break;
+ }
+
+ switch (i & 12)
+ {
+ case 0:
+ key->xkey[i + 0] ^= cast_sbox5[UINT8_TC(z[0])];
+ key->xkey[i + 1] ^= cast_sbox6[UINT8_TC(z[1])];
+ key->xkey[i + 2] ^= cast_sbox7[UINT8_TB(z[2])];
+ key->xkey[i + 3] ^= cast_sbox8[UINT8_TA(z[3])];
+ break;
+ case 4:
+ key->xkey[i + 0] ^= cast_sbox5[UINT8_TA(x[2])];
+ key->xkey[i + 1] ^= cast_sbox6[UINT8_TB(x[3])];
+ key->xkey[i + 2] ^= cast_sbox7[UINT8_TD(x[0])];
+ key->xkey[i + 3] ^= cast_sbox8[UINT8_TD(x[1])];
+ break;
+ case 8:
+ key->xkey[i + 0] ^= cast_sbox5[UINT8_TB(z[2])];
+ key->xkey[i + 1] ^= cast_sbox6[UINT8_TA(z[3])];
+ key->xkey[i + 2] ^= cast_sbox7[UINT8_TC(z[0])];
+ key->xkey[i + 3] ^= cast_sbox8[UINT8_TC(z[1])];
+ break;
+ case 12:
+ key->xkey[i + 0] ^= cast_sbox5[UINT8_TD(x[0])];
+ key->xkey[i + 1] ^= cast_sbox6[UINT8_TD(x[1])];
+ key->xkey[i + 2] ^= cast_sbox7[UINT8_TA(x[2])];
+ key->xkey[i + 3] ^= cast_sbox8[UINT8_TB(x[3])];
+ break;
+ }
+
+ if (i >= 16)
+ {
+ key->xkey[i + 0] &= 31;
+ key->xkey[i + 1] &= 31;
+ key->xkey[i + 2] &= 31;
+ key->xkey[i + 3] &= 31;
+ }
+ }
+
+ /* Wipe clean */
+
+ explicit_bzero(t, sizeof(t));
+ explicit_bzero(x, sizeof(x));
+ explicit_bzero(z, sizeof(z));
}
/* Made in Canada */
diff --git a/crypto/castsb.h b/crypto/castsb.h
index 0e1fb79623..de3a015521 100644
--- a/crypto/castsb.h
+++ b/crypto/castsb.h
@@ -1,544 +1,554 @@
-/* $OpenBSD: castsb.h,v 1.1 2000/02/28 23:13:04 deraadt Exp $ */
-/*
- * CAST-128 in C
- * Written by Steve Reid <sr...@sea-to-sky.net>
- * 100% Public Domain - no warranty
- * Released 1997.10.11
- */
+/****************************************************************************
+ * crypto/castsb.h
+ * $OpenBSD: castsb.h,v 1.1 2000/02/28 23:13:04 deraadt Exp $
+ *
+ * CAST-128 in C
+ * Written by Steve Reid <sr...@sea-to-sky.net>
+ * 100% Public Domain - no warranty
+ * Released 1997.10.11
+ ****************************************************************************/
-static const u_int32_t cast_sbox1[256] = {
- 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A,
- 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949,
- 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675,
- 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E,
- 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2,
- 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D,
- 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F,
- 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0,
- 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE,
- 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7,
- 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F,
- 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935,
- 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D,
- 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D,
- 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165,
- 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50,
- 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272,
- 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE,
- 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D,
- 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3,
- 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A,
- 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167,
- 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F,
- 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291,
- 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9,
- 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779,
- 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6,
- 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2,
- 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9,
- 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511,
- 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E,
- 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D,
- 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E,
- 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5,
- 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82,
- 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324,
- 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC,
- 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C,
- 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F,
- 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC,
- 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491,
- 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D,
- 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE,
- 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96,
- 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A,
- 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A,
- 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79,
- 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D,
- 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779,
- 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD,
- 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755,
- 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6,
- 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB,
- 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9,
- 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0,
- 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872,
- 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79,
- 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C,
- 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298,
- 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E,
- 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571,
- 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9,
- 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D,
- 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF
+static const uint32_t cast_sbox1[256] =
+{
+ 0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a,
+ 0x1e213f2f, 0x9c004dd3, 0x6003e540, 0xcf9fc949,
+ 0xbfd4af27, 0x88bbbdb5, 0xe2034090, 0x98d09675,
+ 0x6e63a0e0, 0x15c361d2, 0xc2e7661d, 0x22d4ff8e,
+ 0x28683b6f, 0xc07fd059, 0xff2379c8, 0x775f50e2,
+ 0x43c340d3, 0xdf2f8656, 0x887ca41a, 0xa2d2bd2d,
+ 0xa1c9e0d6, 0x346c4819, 0x61b76d87, 0x22540f2f,
+ 0x2abe32e1, 0xaa54166b, 0x22568e3a, 0xa2d341d0,
+ 0x66db40c8, 0xa784392f, 0x004dff2f, 0x2db9d2de,
+ 0x97943fac, 0x4a97c1d8, 0x527644b7, 0xb5f437a7,
+ 0xb82cbaef, 0xd751d159, 0x6ff7f0ed, 0x5a097a1f,
+ 0x827b68d0, 0x90ecf52e, 0x22b0c054, 0xbc8e5935,
+ 0x4b6d2f7f, 0x50bb64a2, 0xd2664910, 0xbee5812d,
+ 0xb7332290, 0xe93b159f, 0xb48ee411, 0x4bff345d,
+ 0xfd45c240, 0xad31973f, 0xc4f6d02e, 0x55fc8165,
+ 0xd5b1caad, 0xa1ac2dae, 0xa2d4b76d, 0xc19b0c50,
+ 0x882240f2, 0x0c6e4f38, 0xa4e4bfd7, 0x4f5ba272,
+ 0x564c1d2f, 0xc59c5319, 0xb949e354, 0xb04669fe,
+ 0xb1b6ab8a, 0xc71358dd, 0x6385c545, 0x110f935d,
+ 0x57538ad5, 0x6a390493, 0xe63d37e0, 0x2a54f6b3,
+ 0x3a787d5f, 0x6276a0b5, 0x19a6fcdf, 0x7a42206a,
+ 0x29f9d4d5, 0xf61b1891, 0xbb72275e, 0xaa508167,
+ 0x38901091, 0xc6b505eb, 0x84c7cb8c, 0x2ad75a0f,
+ 0x874a1427, 0xa2d1936b, 0x2ad286af, 0xaa56d291,
+ 0xd7894360, 0x425c750d, 0x93b39e26, 0x187184c9,
+ 0x6c00b32d, 0x73e2bb14, 0xa0bebc3c, 0x54623779,
+ 0x64459eab, 0x3f328b82, 0x7718cf82, 0x59a2cea6,
+ 0x04ee002e, 0x89fe78e6, 0x3fab0950, 0x325ff6c2,
+ 0x81383f05, 0x6963c5c8, 0x76cb5ad6, 0xd49974c9,
+ 0xca180dcf, 0x380782d5, 0xc7fa5cf6, 0x8ac31511,
+ 0x35e79e13, 0x47da91d0, 0xf40f9086, 0xa7e2419e,
+ 0x31366241, 0x051ef495, 0xaa573b04, 0x4a805d8d,
+ 0x548300d0, 0x00322a3c, 0xbf64cddf, 0xba57a68e,
+ 0x75c6372b, 0x50afd341, 0xa7c13275, 0x915a0bf5,
+ 0x6b54bfab, 0x2b0b1426, 0xab4cc9d7, 0x449ccd82,
+ 0xf7fbf265, 0xab85c5f3, 0x1b55db94, 0xaad4e324,
+ 0xcfa4bd3f, 0x2deaa3e2, 0x9e204d02, 0xc8bd25ac,
+ 0xeadf55b3, 0xd5bd9e98, 0xe31231b2, 0x2ad5ad6c,
+ 0x954329de, 0xadbe4528, 0xd8710f69, 0xaa51c90f,
+ 0xaa786bf6, 0x22513f1e, 0xaa51a79b, 0x2ad344cc,
+ 0x7b5a41f0, 0xd37cfbad, 0x1b069505, 0x41ece491,
+ 0xb4c332e6, 0x032268d4, 0xc9600acc, 0xce387e6d,
+ 0xbf6bb16c, 0x6a70fb78, 0x0d03d9c9, 0xd4df39de,
+ 0xe01063da, 0x4736f464, 0x5ad328d8, 0xb347cc96,
+ 0x75bb0fc3, 0x98511bfb, 0x4ffbcc35, 0xb58bcf6a,
+ 0xe11f0abc, 0xbfc5fe4a, 0xa70aec10, 0xac39570a,
+ 0x3f04442f, 0x6188b153, 0xe0397a2e, 0x5727cb79,
+ 0x9ceb418f, 0x1cacd68d, 0x2ad37c96, 0x0175cb9d,
+ 0xc69dff09, 0xc75b65f0, 0xd9db40d8, 0xec0e7779,
+ 0x4744ead4, 0xb11c3274, 0xdd24cb9e, 0x7e1c54bd,
+ 0xf01144f9, 0xd2240eb1, 0x9675b3fd, 0xa3ac3755,
+ 0xd47c27af, 0x51c85f4d, 0x56907596, 0xa5bb15e6,
+ 0x580304f0, 0xca042cf1, 0x011a37ea, 0x8dbfaadb,
+ 0x35ba3e4a, 0x3526ffa0, 0xc37b4d09, 0xbc306ed9,
+ 0x98a52666, 0x5648f725, 0xff5e569d, 0x0ced63d0,
+ 0x7c63b2cf, 0x700b45e1, 0xd5ea50f1, 0x85a92872,
+ 0xaf1fbda7, 0xd4234870, 0xa7870bf3, 0x2d3b4d79,
+ 0x42e04198, 0x0cd0ede7, 0x26470db8, 0xf881814c,
+ 0x474d6ad7, 0x7c0c5e5c, 0xd1231959, 0x381b7298,
+ 0xf5d2f4db, 0xab838653, 0x6e2f1e23, 0x83719c9e,
+ 0xbd91e046, 0x9a56456e, 0xdc39200c, 0x20c8c571,
+ 0x962bda1c, 0xe1e696ff, 0xb141ab08, 0x7cca89b9,
+ 0x1a69e783, 0x02cc4843, 0xa2f7c579, 0x429ef47d,
+ 0x427b169c, 0x5ac9f049, 0xdd8f0f00, 0x5c8165bf
};
-static const u_int32_t cast_sbox2[256] = {
- 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380,
- 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651,
- 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA,
- 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3,
- 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909,
- 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB,
- 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B,
- 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806,
- 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4,
- 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B,
- 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F,
- 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359,
- 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21,
- 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B,
- 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D,
- 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C,
- 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F,
- 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34,
- 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D,
- 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB,
- 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4,
- 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD,
- 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801,
- 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860,
- 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755,
- 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B,
- 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709,
- 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304,
- 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B,
- 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B,
- 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C,
- 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF,
- 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9,
- 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C,
- 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3,
- 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13,
- 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9,
- 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F,
- 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB,
- 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6,
- 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4,
- 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6,
- 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43,
- 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58,
- 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8,
- 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906,
- 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171,
- 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D,
- 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89,
- 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6,
- 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B,
- 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4,
- 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB,
- 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6,
- 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E,
- 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F,
- 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA,
- 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249,
- 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA,
- 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA,
- 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD,
- 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9,
- 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF,
- 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1
+static const uint32_t cast_sbox2[256] =
+{
+ 0x1f201094, 0xef0ba75b, 0x69e3cf7e, 0x393f4380,
+ 0xfe61cf7a, 0xeec5207a, 0x55889c94, 0x72fc0651,
+ 0xada7ef79, 0x4e1d7235, 0xd55a63ce, 0xde0436ba,
+ 0x99c430ef, 0x5f0c0794, 0x18dcdb7d, 0xa1d6eff3,
+ 0xa0b52f7b, 0x59e83605, 0xee15b094, 0xe9ffd909,
+ 0xdc440086, 0xef944459, 0xba83ccb3, 0xe0c3cdfb,
+ 0xd1da4181, 0x3b092ab1, 0xf997f1c1, 0xa5e6cf7b,
+ 0x01420ddb, 0xe4e7ef5b, 0x25a1ff41, 0xe180f806,
+ 0x1fc41080, 0x179bee7a, 0xd37ac6a9, 0xfe5830a4,
+ 0x98de8b7f, 0x77e83f4e, 0x79929269, 0x24fa9f7b,
+ 0xe113c85b, 0xacc40083, 0xd7503525, 0xf7ea615f,
+ 0x62143154, 0x0d554b63, 0x5d681121, 0xc866c359,
+ 0x3d63cf73, 0xcee234c0, 0xd4d87e87, 0x5c672b21,
+ 0x071f6181, 0x39f7627f, 0x361e3084, 0xe4eb573b,
+ 0x602f64a4, 0xd63acd9c, 0x1bbc4635, 0x9e81032d,
+ 0x2701f50c, 0x99847ab4, 0xa0e3df79, 0xba6cf38c,
+ 0x10843094, 0x2537a95e, 0xf46f6ffe, 0xa1ff3b1f,
+ 0x208cfb6a, 0x8f458c74, 0xd9e0a227, 0x4ec73a34,
+ 0xfc884f69, 0x3e4de8df, 0xef0e0088, 0x3559648d,
+ 0x8a45388c, 0x1d804366, 0x721d9bfd, 0xa58684bb,
+ 0xe8256333, 0x844e8212, 0x128d8098, 0xfed33fb4,
+ 0xce280ae1, 0x27e19ba5, 0xd5a6c252, 0xe49754bd,
+ 0xc5d655dd, 0xeb667064, 0x77840b4d, 0xa1b6a801,
+ 0x84db26a9, 0xe0b56714, 0x21f043b7, 0xe5d05860,
+ 0x54f03084, 0x066ff472, 0xa31aa153, 0xdadc4755,
+ 0xb5625dbf, 0x68561be6, 0x83ca6b94, 0x2d6ed23b,
+ 0xeccf01db, 0xa6d3d0ba, 0xb6803d5c, 0xaf77a709,
+ 0x33b4a34c, 0x397bc8d6, 0x5ee22b95, 0x5f0e5304,
+ 0x81ed6f61, 0x20e74364, 0xb45e1378, 0xde18639b,
+ 0x881ca122, 0xb96726d1, 0x8049a7e8, 0x22b7da7b,
+ 0x5e552d25, 0x5272d237, 0x79d2951c, 0xc60d894c,
+ 0x488cb402, 0x1ba4fe5b, 0xa4b09f6b, 0x1ca815cf,
+ 0xa20c3005, 0x8871df63, 0xb9de2fcb, 0x0cc6c9e9,
+ 0x0beeff53, 0xe3214517, 0xb4542835, 0x9f63293c,
+ 0xee41e729, 0x6e1d2d7c, 0x50045286, 0x1e6685f3,
+ 0xf33401c6, 0x30a22c95, 0x31a70850, 0x60930f13,
+ 0x73f98417, 0xa1269859, 0xec645c44, 0x52c877a9,
+ 0xcdff33a6, 0xa02b1741, 0x7cbad9a2, 0x2180036f,
+ 0x50d99c08, 0xcb3f4861, 0xc26bd765, 0x64a3f6ab,
+ 0x80342676, 0x25a75e7b, 0xe4e6d1fc, 0x20c710e6,
+ 0xcdf0b680, 0x17844d3b, 0x31eef84d, 0x7e0824e4,
+ 0x2ccb49eb, 0x846a3bae, 0x8ff77888, 0xee5d60f6,
+ 0x7af75673, 0x2fdd5cdb, 0xa11631c1, 0x30f66f43,
+ 0xb3faec54, 0x157fd7fa, 0xef8579cc, 0xd152de58,
+ 0xdb2ffd5e, 0x8f32ce19, 0x306af97a, 0x02f03ef8,
+ 0x99319ad5, 0xc242fa0f, 0xa7e3ebb0, 0xc68e4906,
+ 0xb8da230c, 0x80823028, 0xdcdef3c8, 0xd35fb171,
+ 0x088a1bc8, 0xbec0c560, 0x61a3c9e8, 0xbca8f54d,
+ 0xc72feffa, 0x22822e99, 0x82c570b4, 0xd8d94e89,
+ 0x8b1c34bc, 0x301e16e6, 0x273be979, 0xb0ffeaa6,
+ 0x61d9b8c6, 0x00b24869, 0xb7ffce3f, 0x08dc283b,
+ 0x43daf65a, 0xf7e19798, 0x7619b72f, 0x8f1c9ba4,
+ 0xdc8637a0, 0x16a7d3b1, 0x9fc393b7, 0xa7136eeb,
+ 0xc6bcc63e, 0x1a513742, 0xef6828bc, 0x520365d6,
+ 0x2d6a77ab, 0x3527ed4b, 0x821fd216, 0x095c6e2e,
+ 0xdb92f2fb, 0x5eea29cb, 0x145892f5, 0x91584f7f,
+ 0x5483697b, 0x2667a8cc, 0x85196048, 0x8c4bacea,
+ 0x833860d4, 0x0d23e0f9, 0x6c387e8a, 0x0ae6d249,
+ 0xb284600c, 0xd835731d, 0xdcb1c647, 0xac4c56ea,
+ 0x3ebd81b3, 0x230eabb0, 0x6438bc87, 0xf0b5b1fa,
+ 0x8f5ea2b3, 0xfc184642, 0x0a036b7a, 0x4fb089bd,
+ 0x649da589, 0xa345415e, 0x5c038323, 0x3e5d3bb9,
+ 0x43d79572, 0x7e6dd07c, 0x06dfdf1e, 0x6c6cc4ef,
+ 0x7160a539, 0x73bfbe70, 0x83877605, 0x4523ecf1
};
-static const u_int32_t cast_sbox3[256] = {
- 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907,
- 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90,
- 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE,
- 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5,
- 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E,
- 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E,
- 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC,
- 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240,
- 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E,
- 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5,
- 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F,
- 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B,
- 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99,
- 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71,
- 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F,
- 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04,
- 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380,
- 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82,
- 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8,
- 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15,
- 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504,
- 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2,
- 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6,
- 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176,
- 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E,
- 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148,
- 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D,
- 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC,
- 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1,
- 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341,
- 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C,
- 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E,
- 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15,
- 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51,
- 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4,
- 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F,
- 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B,
- 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A,
- 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392,
- 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B,
- 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231,
- 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B,
- 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889,
- 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5,
- 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67,
- 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45,
- 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49,
- 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536,
- 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D,
- 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC,
- 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D,
- 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0,
- 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E,
- 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69,
- 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767,
- 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2,
- 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE,
- 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49,
- 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24,
- 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D,
- 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0,
- 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A,
- 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5,
- 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783
+static const uint32_t cast_sbox3[256] =
+{
+ 0x8defc240, 0x25fa5d9f, 0xeb903dbf, 0xe810c907,
+ 0x47607fff, 0x369fe44b, 0x8c1fc644, 0xaececa90,
+ 0xbeb1f9bf, 0xeefbcaea, 0xe8cf1950, 0x51df07ae,
+ 0x920e8806, 0xf0ad0548, 0xe13c8d83, 0x927010d5,
+ 0x11107d9f, 0x07647db9, 0xb2e3e4d4, 0x3d4f285e,
+ 0xb9afa820, 0xfade82e0, 0xa067268b, 0x8272792e,
+ 0x553fb2c0, 0x489ae22b, 0xd4ef9794, 0x125e3fbc,
+ 0x21fffcee, 0x825b1bfd, 0x9255c5ed, 0x1257a240,
+ 0x4e1a8302, 0xbae07fff, 0x528246e7, 0x8e57140e,
+ 0x3373f7bf, 0x8c9f8188, 0xa6fc4ee8, 0xc982b5a5,
+ 0xa8c01db7, 0x579fc264, 0x67094f31, 0xf2bd3f5f,
+ 0x40fff7c1, 0x1fb78dfc, 0x8e6bd2c1, 0x437be59b,
+ 0x99b03dbf, 0xb5dbc64b, 0x638dc0e6, 0x55819d99,
+ 0xa197c81c, 0x4a012d6e, 0xc5884a28, 0xccc36f71,
+ 0xb843c213, 0x6c0743f1, 0x8309893c, 0x0feddd5f,
+ 0x2f7fe850, 0xd7c07f7e, 0x02507fbf, 0x5afb9a04,
+ 0xa747d2d0, 0x1651192e, 0xaf70bf3e, 0x58c31380,
+ 0x5f98302e, 0x727cc3c4, 0x0a0fb402, 0x0f7fef82,
+ 0x8c96fdad, 0x5d2c2aae, 0x8ee99a49, 0x50da88b8,
+ 0x8427f4a0, 0x1eac5790, 0x796fb449, 0x8252dc15,
+ 0xefbd7d9b, 0xa672597d, 0xada840d8, 0x45f54504,
+ 0xfa5d7403, 0xe83ec305, 0x4f91751a, 0x925669c2,
+ 0x23efe941, 0xa903f12e, 0x60270df2, 0x0276e4b6,
+ 0x94fd6574, 0x927985b2, 0x8276dbcb, 0x02778176,
+ 0xf8af918d, 0x4e48f79e, 0x8f616ddf, 0xe29d840e,
+ 0x842f7d83, 0x340ce5c8, 0x96bbb682, 0x93b4b148,
+ 0xef303cab, 0x984faf28, 0x779faf9b, 0x92dc560d,
+ 0x224d1e20, 0x8437aa88, 0x7d29dc96, 0x2756d3dc,
+ 0x8b907cee, 0xb51fd240, 0xe7c07ce3, 0xe566b4a1,
+ 0xc3e9615e, 0x3cf8209d, 0x6094d1e3, 0xcd9ca341,
+ 0x5c76460e, 0x00ea983b, 0xd4d67881, 0xfd47572c,
+ 0xf76cedd9, 0xbda8229c, 0x127dadaa, 0x438a074e,
+ 0x1f97c090, 0x081bdb8a, 0x93a07ebe, 0xb938ca15,
+ 0x97b03cff, 0x3dc2c0f8, 0x8d1ab2ec, 0x64380e51,
+ 0x68cc7bfb, 0xd90f2788, 0x12490181, 0x5de5ffd4,
+ 0xdd7ef86a, 0x76a2e214, 0xb9a40368, 0x925d958f,
+ 0x4b39fffa, 0xba39aee9, 0xa4ffd30b, 0xfaf7933b,
+ 0x6d498623, 0x193cbcfa, 0x27627545, 0x825cf47a,
+ 0x61bd8ba0, 0xd11e42d1, 0xcead04f4, 0x127ea392,
+ 0x10428db7, 0x8272a972, 0x9270c4a8, 0x127de50b,
+ 0x285ba1c8, 0x3c62f44f, 0x35c0eaa5, 0xe805d231,
+ 0x428929fb, 0xb4fcdf82, 0x4fb66a53, 0x0e7dc15b,
+ 0x1f081fab, 0x108618ae, 0xfcfd086d, 0xf9ff2889,
+ 0x694bcc11, 0x236a5cae, 0x12deca4d, 0x2c3f8cc5,
+ 0xd2d02dfe, 0xf8ef5896, 0xe4cf52da, 0x95155b67,
+ 0x494a488c, 0xb9b6a80c, 0x5c8f82bc, 0x89d36b45,
+ 0x3a609437, 0xec00c9a9, 0x44715253, 0x0a874b49,
+ 0xd773bc40, 0x7c34671c, 0x02717ef6, 0x4feb5536,
+ 0xa2d02fff, 0xd2bf60c4, 0xd43f03c0, 0x50b4ef6d,
+ 0x07478cd1, 0x006e1888, 0xa2e53f55, 0xb9e6d4bc,
+ 0xa2048016, 0x97573833, 0xd7207d67, 0xde0f8f3d,
+ 0x72f87b33, 0xabcc4f33, 0x7688c55d, 0x7b00a6b0,
+ 0x947b0001, 0x570075d2, 0xf9bb88f8, 0x8942019e,
+ 0x4264a5ff, 0x856302e0, 0x72dbd92b, 0xee971b69,
+ 0x6ea22fde, 0x5f08ae2b, 0xaf7a616d, 0xe5c98767,
+ 0xcf1febd2, 0x61efc8c2, 0xf1ac2571, 0xcc8239c2,
+ 0x67214cb8, 0xb1e583d1, 0xb7dc3e62, 0x7f10bdce,
+ 0xf90a5c38, 0x0ff0443d, 0x606e6dc6, 0x60543a49,
+ 0x5727c148, 0x2be98a1d, 0x8ab41738, 0x20e1be24,
+ 0xaf96da0f, 0x68458425, 0x99833be5, 0x600d457d,
+ 0x282f9350, 0x8334b362, 0xd91d1120, 0x2b6d8da0,
+ 0x642b1e31, 0x9c305a00, 0x52bce688, 0x1b03588a,
+ 0xf7baefd5, 0x4142ed9c, 0xa4315c11, 0x83323ec5,
+ 0xdfef4636, 0xa133c501, 0xe9d3531c, 0xee353783
};
-static const u_int32_t cast_sbox4[256] = {
- 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298,
- 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1,
- 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120,
- 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF,
- 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220,
- 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15,
- 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE,
- 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121,
- 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701,
- 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25,
- 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B,
- 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5,
- 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93,
- 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB,
- 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746,
- 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5,
- 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9,
- 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D,
- 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB,
- 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6,
- 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C,
- 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23,
- 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7,
- 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003,
- 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340,
- 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6,
- 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327,
- 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119,
- 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC,
- 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24,
- 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205,
- 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A,
- 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031,
- 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79,
- 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5,
- 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF,
- 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C,
- 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26,
- 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69,
- 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB,
- 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9,
- 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7,
- 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF,
- 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417,
- 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3,
- 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2,
- 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2,
- 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2,
- 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF,
- 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A,
- 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091,
- 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919,
- 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF,
- 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF,
- 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF,
- 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876,
- 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367,
- 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB,
- 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C,
- 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04,
- 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43,
- 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282,
- 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E,
- 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2
+static const uint32_t cast_sbox4[256] =
+{
+ 0x9db30420, 0x1fb6e9de, 0xa7be7bef, 0xd273a298,
+ 0x4a4f7bdb, 0x64ad8c57, 0x85510443, 0xfa020ed1,
+ 0x7e287aff, 0xe60fb663, 0x095f35a1, 0x79ebf120,
+ 0xfd059d43, 0x6497b7b1, 0xf3641f63, 0x241e4adf,
+ 0x28147f5f, 0x4fa2b8cd, 0xc9430040, 0x0cc32220,
+ 0xfdd30b30, 0xc0a5374f, 0x1d2d00d9, 0x24147b15,
+ 0xee4d111a, 0x0fca5167, 0x71ff904c, 0x2d195ffe,
+ 0x1a05645f, 0x0c13fefe, 0x081b08ca, 0x05170121,
+ 0x80530100, 0xe83e5efe, 0xac9af4f8, 0x7fe72701,
+ 0xd2b8ee5f, 0x06df4261, 0xbb9e9b8a, 0x7293ea25,
+ 0xce84ffdf, 0xf5718801, 0x3dd64b04, 0xa26f263b,
+ 0x7ed48400, 0x547eebe6, 0x446d4ca0, 0x6cf3d6f5,
+ 0x2649abdf, 0xaea0c7f5, 0x36338cc1, 0x503f7e93,
+ 0xd3772061, 0x11b638e1, 0x72500e03, 0xf80eb2bb,
+ 0xabe0502e, 0xec8d77de, 0x57971e81, 0xe14f6746,
+ 0xc9335400, 0x6920318f, 0x081dbb99, 0xffc304a5,
+ 0x4d351805, 0x7f3d5ce3, 0xa6c866c6, 0x5d5bcca9,
+ 0xdaec6fea, 0x9f926f91, 0x9f46222f, 0x3991467d,
+ 0xa5bf6d8e, 0x1143c44f, 0x43958302, 0xd0214eeb,
+ 0x022083b8, 0x3fb6180c, 0x18f8931e, 0x281658e6,
+ 0x26486e3e, 0x8bd78a70, 0x7477e4c1, 0xb506e07c,
+ 0xf32d0a25, 0x79098b02, 0xe4eabb81, 0x28123b23,
+ 0x69dead38, 0x1574ca16, 0xdf871b62, 0x211c40b7,
+ 0xa51a9ef9, 0x0014377b, 0x041e8ac8, 0x09114003,
+ 0xbd59e4d2, 0xe3d156d5, 0x4fe876d5, 0x2f91a340,
+ 0x557be8de, 0x00eae4a7, 0x0ce5c2ec, 0x4db4bba6,
+ 0xe756bdff, 0xdd3369ac, 0xec17b035, 0x06572327,
+ 0x99afc8b0, 0x56c8c391, 0x6b65811c, 0x5e146119,
+ 0x6e85cb75, 0xbe07c002, 0xc2325577, 0x893ff4ec,
+ 0x5bbfc92d, 0xd0ec3b25, 0xb7801ab7, 0x8d6d3b24,
+ 0x20c763ef, 0xc366a5fc, 0x9c382880, 0x0ace3205,
+ 0xaac9548a, 0xeca1d7c7, 0x041afa32, 0x1d16625a,
+ 0x6701902c, 0x9b757a54, 0x31d477f7, 0x9126b031,
+ 0x36cc6fdb, 0xc70b8b46, 0xd9e66a48, 0x56e55a79,
+ 0x026a4ceb, 0x52437eff, 0x2f8f76b4, 0x0df980a5,
+ 0x8674cde3, 0xedda04eb, 0x17a9be04, 0x2c18f4df,
+ 0xb7747f9d, 0xab2af7b4, 0xefc34d20, 0x2e096b7c,
+ 0x1741a254, 0xe5b6a035, 0x213d42f6, 0x2c1c7c26,
+ 0x61c2f50f, 0x6552daf9, 0xd2c231f8, 0x25130f69,
+ 0xd8167fa2, 0x0418f2c8, 0x001a96a6, 0x0d1526ab,
+ 0x63315c21, 0x5e0a72ec, 0x49bafefd, 0x187908d9,
+ 0x8d0dbd86, 0x311170a7, 0x3e9b640c, 0xcc3e10d7,
+ 0xd5cad3b6, 0x0caec388, 0xf73001e1, 0x6c728aff,
+ 0x71eae2a1, 0x1f9af36e, 0xcfcbd12f, 0xc1de8417,
+ 0xac07be6b, 0xcb44a1d8, 0x8b9b0f56, 0x013988c3,
+ 0xb1c52fca, 0xb4be31cd, 0xd8782806, 0x12a3a4e2,
+ 0x6f7de532, 0x58fd7eb6, 0xd01ee900, 0x24adffc2,
+ 0xf4990fc5, 0x9711aac5, 0x001d7b95, 0x82e5e7d2,
+ 0x109873f6, 0x00613096, 0xc32d9521, 0xada121ff,
+ 0x29908415, 0x7fbb977f, 0xaf9eb3db, 0x29c9ed2a,
+ 0x5ce2a465, 0xa730f32c, 0xd0aa3fe8, 0x8a5cc091,
+ 0xd49e2ce7, 0x0ce454a9, 0xd60acd86, 0x015f1919,
+ 0x77079103, 0xdea03af6, 0x78a8565e, 0xdee356df,
+ 0x21f05cbe, 0x8b75e387, 0xb3c50651, 0xb8a5c3ef,
+ 0xd8eeb6d2, 0xe523be77, 0xc2154529, 0x2f69efdf,
+ 0xafe67afb, 0xf470c4b2, 0xf3e0eb5b, 0xd6cc9876,
+ 0x39e4460c, 0x1fda8538, 0x1987832f, 0xca007367,
+ 0xa99144f8, 0x296b299e, 0x492fc295, 0x9266beab,
+ 0xb5676e69, 0x9bd3ddda, 0xdf7e052f, 0xdb25701c,
+ 0x1b5e51ee, 0xf65324e6, 0x6afce36c, 0x0316cc04,
+ 0x8644213e, 0xb7dc59d0, 0x7965291f, 0xccd6fd43,
+ 0x41823979, 0x932bcdf6, 0xb657c34d, 0x4edfd282,
+ 0x7ae5290c, 0x3cb9536b, 0x851e20fe, 0x9833557e,
+ 0x13ecf0b0, 0xd3ffb372, 0x3f85c5c1, 0x0aef7ed2
};
-static const u_int32_t cast_sbox5[256] = {
- 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911,
- 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F,
- 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00,
- 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A,
- 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180,
- 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF,
- 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2,
- 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02,
- 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725,
- 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A,
- 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B,
- 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7,
- 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571,
- 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9,
- 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC,
- 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981,
- 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA,
- 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774,
- 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263,
- 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655,
- 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468,
- 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2,
- 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B,
- 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910,
- 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284,
- 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1,
- 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4,
- 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA,
- 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7,
- 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049,
- 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE,
- 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F,
- 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6,
- 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA,
- 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4,
- 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE,
- 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561,
- 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3,
- 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6,
- 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840,
- 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406,
- 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4,
- 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472,
- 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2,
- 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487,
- 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7,
- 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288,
- 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5,
- 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2,
- 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E,
- 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78,
- 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E,
- 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76,
- 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801,
- 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0,
- 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD,
- 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58,
- 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0,
- 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2,
- 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20,
- 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE,
- 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8,
- 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55,
- 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4
+static const uint32_t cast_sbox5[256] =
+{
+ 0x7ec90c04, 0x2c6e74b9, 0x9b0e66df, 0xa6337911,
+ 0xb86a7fff, 0x1dd358f5, 0x44dd9d44, 0x1731167f,
+ 0x08fbf1fa, 0xe7f511cc, 0xd2051b00, 0x735aba00,
+ 0x2ab722d8, 0x386381cb, 0xacf6243a, 0x69befd7a,
+ 0xe6a2e77f, 0xf0c720cd, 0xc4494816, 0xccf5c180,
+ 0x38851640, 0x15b0a848, 0xe68b18cb, 0x4caadeff,
+ 0x5f480a01, 0x0412b2aa, 0x259814fc, 0x41d0efe2,
+ 0x4e40b48d, 0x248eb6fb, 0x8dba1cfe, 0x41a99b02,
+ 0x1a550a04, 0xba8f65cb, 0x7251f4e7, 0x95a51725,
+ 0xc106ecd7, 0x97a5980a, 0xc539b9aa, 0x4d79fe6a,
+ 0xf2f3f763, 0x68af8040, 0xed0c9e56, 0x11b4958b,
+ 0xe1eb5a88, 0x8709e6b0, 0xd7e07156, 0x4e29fea7,
+ 0x6366e52d, 0x02d1c000, 0xc4ac8e05, 0x9377f571,
+ 0x0c05372a, 0x578535f2, 0x2261be02, 0xd642a0c9,
+ 0xdf13a280, 0x74b55bd2, 0x682199c0, 0xd421e5ec,
+ 0x53fb3ce8, 0xc8adedb3, 0x28a87fc9, 0x3d959981,
+ 0x5c1ff900, 0xfe38d399, 0x0c4eff0b, 0x062407ea,
+ 0xaa2f4fb1, 0x4fb96976, 0x90c79505, 0xb0a8a774,
+ 0xef55a1ff, 0xe59ca2c2, 0xa6b62d27, 0xe66a4263,
+ 0xdf65001f, 0x0ec50966, 0xdfdd55bc, 0x29de0655,
+ 0x911e739a, 0x17af8975, 0x32c7911c, 0x89f89468,
+ 0x0d01e980, 0x524755f4, 0x03b63cc9, 0x0cc844b2,
+ 0xbcf3f0aa, 0x87ac36e9, 0xe53a7426, 0x01b3d82b,
+ 0x1a9e7449, 0x64ee2d7e, 0xcddbb1da, 0x01c94910,
+ 0xb868bf80, 0x0d26f3fd, 0x9342ede7, 0x04a5c284,
+ 0x636737b6, 0x50f5b616, 0xf24766e3, 0x8eca36c1,
+ 0x136e05db, 0xfef18391, 0xfb887a37, 0xd6e7f7d4,
+ 0xc7fb7dc9, 0x3063fcdf, 0xb6f589de, 0xec2941da,
+ 0x26e46695, 0xb7566419, 0xf654efc5, 0xd08d58b7,
+ 0x48925401, 0xc1bacb7f, 0xe5ff550f, 0xb6083049,
+ 0x5bb5d0e8, 0x87d72e5a, 0xab6a6ee1, 0x223a66ce,
+ 0xc62bf3cd, 0x9e0885f9, 0x68cb3e47, 0x086c010f,
+ 0xa21de820, 0xd18b69de, 0xf3f65777, 0xfa02c3f6,
+ 0x407edac3, 0xcbb3d550, 0x1793084d, 0xb0d70eba,
+ 0x0ab378d5, 0xd951fb0c, 0xded7da56, 0x4124bbe4,
+ 0x94ca0b56, 0x0f5755d1, 0xe0e1e56e, 0x6184b5be,
+ 0x580a249f, 0x94f74bc0, 0xe327888e, 0x9f7b5561,
+ 0xc3dc0280, 0x05687715, 0x646c6bd7, 0x44904db3,
+ 0x66b4f0a3, 0xc0f1648a, 0x697ed5af, 0x49e92ff6,
+ 0x309e374f, 0x2cb6356a, 0x85808573, 0x4991f840,
+ 0x76f0ae02, 0x083be84d, 0x28421c9a, 0x44489406,
+ 0x736e4cb8, 0xc1092910, 0x8bc95fc6, 0x7d869cf4,
+ 0x134f616f, 0x2e77118d, 0xb31b2be1, 0xaa90b472,
+ 0x3ca5d717, 0x7d161bba, 0x9cad9010, 0xaf462ba2,
+ 0x9fe459d2, 0x45d34559, 0xd9f2da13, 0xdbc65487,
+ 0xf3e4f94e, 0x176d486f, 0x097c13ea, 0x631da5c7,
+ 0x445f7382, 0x175683f4, 0xcdc66a97, 0x70be0288,
+ 0xb3cdcf72, 0x6e5dd2f3, 0x20936079, 0x459b80a5,
+ 0xbe60e2db, 0xa9c23101, 0xeba5315c, 0x224e42f2,
+ 0x1c5c1572, 0xf6721b2c, 0x1ad2fff3, 0x8c25404e,
+ 0x324ed72f, 0x4067b7fd, 0x0523138e, 0x5ca3bc78,
+ 0xdc0fd66e, 0x75922283, 0x784d6b17, 0x58ebb16e,
+ 0x44094f85, 0x3f481d87, 0xfcfeae7b, 0x77b5ff76,
+ 0x8c2302bf, 0xaaf47556, 0x5f46b02a, 0x2b092801,
+ 0x3d38f5f7, 0x0ca81f36, 0x52af4a8a, 0x66d5e7c0,
+ 0xdf3b0874, 0x95055110, 0x1b5ad7a8, 0xf61ed5ad,
+ 0x6cf6e479, 0x20758184, 0xd0cefa65, 0x88f7be58,
+ 0x4a046826, 0x0ff6f8f3, 0xa09c7f70, 0x5346aba0,
+ 0x5ce96c28, 0xe176eda3, 0x6bac307f, 0x376829d2,
+ 0x85360fa9, 0x17e3fe2a, 0x24b79767, 0xf5a96b20,
+ 0xd6cd2595, 0x68ff1ebf, 0x7555442c, 0xf19f06be,
+ 0xf9e0659a, 0xeeb9491d, 0x34010718, 0xbb30cab8,
+ 0xe822fe15, 0x88570983, 0x750e6249, 0xda627e55,
+ 0x5e76ffa8, 0xb1534546, 0x6d47de08, 0xefe9e7d4
};
-static const u_int32_t cast_sbox6[256] = {
- 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C,
- 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC,
- 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9,
- 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138,
- 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E,
- 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367,
- 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866,
- 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98,
- 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C,
- 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072,
- 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD,
- 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3,
- 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53,
- 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD,
- 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D,
- 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8,
- 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF,
- 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9,
- 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807,
- 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54,
- 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A,
- 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387,
- 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563,
- 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC,
- 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0,
- 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF,
- 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE,
- 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF,
- 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0,
- 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F,
- 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2,
- 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289,
- 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853,
- 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950,
- 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA,
- 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F,
- 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9,
- 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B,
- 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751,
- 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE,
- 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358,
- 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13,
- 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397,
- 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976,
- 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459,
- 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0,
- 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4,
- 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891,
- 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F,
- 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA,
- 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB,
- 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC,
- 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2,
- 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084,
- 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB,
- 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25,
- 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B,
- 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121,
- 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B,
- 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5,
- 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855,
- 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD,
- 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454,
- 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F
+static const uint32_t cast_sbox6[256] =
+{
+ 0xf6fa8f9d, 0x2cac6ce1, 0x4ca34867, 0xe2337f7c,
+ 0x95db08e7, 0x016843b4, 0xeced5cbc, 0x325553ac,
+ 0xbf9f0960, 0xdfa1e2ed, 0x83f0579d, 0x63ed86b9,
+ 0x1ab6a6b8, 0xde5ebe39, 0xf38ff732, 0x8989b138,
+ 0x33f14961, 0xc01937bd, 0xf506c6da, 0xe4625e7e,
+ 0xa308ea99, 0x4e23e33c, 0x79cbd7cc, 0x48a14367,
+ 0xa3149619, 0xfec94bd5, 0xa114174a, 0xeaa01866,
+ 0xa084db2d, 0x09a8486f, 0xa888614a, 0x2900af98,
+ 0x01665991, 0xe1992863, 0xc8f30c60, 0x2e78ef3c,
+ 0xd0d51932, 0xcf0fec14, 0xf7ca07d2, 0xd0a82072,
+ 0xfd41197e, 0x9305a6b0, 0xe86be3da, 0x74bed3cd,
+ 0x372da53c, 0x4c7f4448, 0xdab5d440, 0x6dba0ec3,
+ 0x083919a7, 0x9fbaeed9, 0x49dbcfb0, 0x4e670c53,
+ 0x5c3d9c01, 0x64bdb941, 0x2c0e636a, 0xba7dd9cd,
+ 0xea6f7388, 0xe70bc762, 0x35f29adb, 0x5c4cdd8d,
+ 0xf0d48d8c, 0xb88153e2, 0x08a19866, 0x1ae2eac8,
+ 0x284caf89, 0xaa928223, 0x9334be53, 0x3b3a21bf,
+ 0x16434be3, 0x9aea3906, 0xefe8c36e, 0xf890cdd9,
+ 0x80226dae, 0xc340a4a3, 0xdf7e9c09, 0xa694a807,
+ 0x5b7c5ecc, 0x221db3a6, 0x9a69a02f, 0x68818a54,
+ 0xceb2296f, 0x53c0843a, 0xfe893655, 0x25bfe68a,
+ 0xb4628abc, 0xcf222ebf, 0x25ac6f48, 0xa9a99387,
+ 0x53bddb65, 0xe76ffbe7, 0xe967fd78, 0x0ba93563,
+ 0x8e342bc1, 0xe8a11be9, 0x4980740d, 0xc8087dfc,
+ 0x8de4bf99, 0xa11101a0, 0x7fd37975, 0xda5a26c0,
+ 0xe81f994f, 0x9528cd89, 0xfd339fed, 0xb87834bf,
+ 0x5f04456d, 0x22258698, 0xc9c4c83b, 0x2dc156be,
+ 0x4f628daa, 0x57f55ec5, 0xe2220abe, 0xd2916ebf,
+ 0x4ec75b95, 0x24f2c3c0, 0x42d15d99, 0xcd0d7fa0,
+ 0x7b6e27ff, 0xa8dc8af0, 0x7345c106, 0xf41e232f,
+ 0x35162386, 0xe6ea8926, 0x3333b094, 0x157ec6f2,
+ 0x372b74af, 0x692573e4, 0xe9a9d848, 0xf3160289,
+ 0x3a62ef1d, 0xa787e238, 0xf3a5f676, 0x74364853,
+ 0x20951063, 0x4576698d, 0xb6fad407, 0x592af950,
+ 0x36f73523, 0x4cfb6e87, 0x7da4cec0, 0x6c152daa,
+ 0xcb0396a8, 0xc50dfe5d, 0xfcd707ab, 0x0921c42f,
+ 0x89dff0bb, 0x5fe2be78, 0x448f4f33, 0x754613c9,
+ 0x2b05d08d, 0x48b9d585, 0xdc049441, 0xc8098f9b,
+ 0x7dede786, 0xc39a3373, 0x42410005, 0x6a091751,
+ 0x0ef3c8a6, 0x890072d6, 0x28207682, 0xa9a9f7be,
+ 0xbf32679d, 0xd45b5b75, 0xb353fd00, 0xcbb0e358,
+ 0x830f220a, 0x1f8fb214, 0xd372cf08, 0xcc3c4a13,
+ 0x8cf63166, 0x061c87be, 0x88c98f88, 0x6062e397,
+ 0x47cf8e7a, 0xb6c85283, 0x3cc2acfb, 0x3fc06976,
+ 0x4e8f0252, 0x64d8314d, 0xda3870e3, 0x1e665459,
+ 0xc10908f0, 0x513021a5, 0x6c5b68b7, 0x822f8aa0,
+ 0x3007cd3e, 0x74719eef, 0xdc872681, 0x073340d4,
+ 0x7e432fd9, 0x0c5ec241, 0x8809286c, 0xf592d891,
+ 0x08a930f6, 0x957ef305, 0xb7fbffbd, 0xc266e96f,
+ 0x6fe4ac98, 0xb173ecc0, 0xbc60b42a, 0x953498da,
+ 0xfba1ae12, 0x2d4bd736, 0x0f25faab, 0xa4f3fceb,
+ 0xe2969123, 0x257f0c3d, 0x9348af49, 0x361400bc,
+ 0xe8816f4a, 0x3814f200, 0xa3f94043, 0x9c7a54c2,
+ 0xbc704f57, 0xda41e7f9, 0xc25ad33a, 0x54f4a084,
+ 0xb17f5505, 0x59357cbe, 0xedbd15c8, 0x7f97c5ab,
+ 0xba5ac7b5, 0xb6f6deaf, 0x3a479c3a, 0x5302da25,
+ 0x653d7e6a, 0x54268d49, 0x51a477ea, 0x5017d55b,
+ 0xd7d25d88, 0x44136c76, 0x0404a8c8, 0xb8e5a121,
+ 0xb81a928a, 0x60ed5869, 0x97c55b96, 0xeaec991b,
+ 0x29935913, 0x01fdb7f1, 0x088e8dfa, 0x9ab6f6f5,
+ 0x3b4cbf9f, 0x4a5de3ab, 0xe6051d35, 0xa0e1d855,
+ 0xd36b4cf1, 0xf544edeb, 0xb0e93524, 0xbebb8fbd,
+ 0xa2d762cf, 0x49c92f54, 0x38b5f331, 0x7128a454,
+ 0x48392905, 0xa65b1db8, 0x851c97bd, 0xd675cf2f
};
-static const u_int32_t cast_sbox7[256] = {
- 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693,
- 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F,
- 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82,
- 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE,
- 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD,
- 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43,
- 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F,
- 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19,
- 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9,
- 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2,
- 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E,
- 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516,
- 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83,
- 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88,
- 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E,
- 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816,
- 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A,
- 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756,
- 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F,
- 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A,
- 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B,
- 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264,
- 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78,
- 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688,
- 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D,
- 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28,
- 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802,
- 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3,
- 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9,
- 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7,
- 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302,
- 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06,
- 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858,
- 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033,
- 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A,
- 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A,
- 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4,
- 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566,
- 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF,
- 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509,
- 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9,
- 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962,
- 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C,
- 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E,
- 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07,
- 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C,
- 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939,
- 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C,
- 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E,
- 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285,
- 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378,
- 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301,
- 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD,
- 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE,
- 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567,
- 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767,
- 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2,
- 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647,
- 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF,
- 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914,
- 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2,
- 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C,
- 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA,
- 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3
+static const uint32_t cast_sbox7[256] =
+{
+ 0x85e04019, 0x332bf567, 0x662dbfff, 0xcfc65693,
+ 0x2a8d7f6f, 0xab9bc912, 0xde6008a1, 0x2028da1f,
+ 0x0227bce7, 0x4d642916, 0x18fac300, 0x50f18b82,
+ 0x2cb2cb11, 0xb232e75c, 0x4b3695f2, 0xb28707de,
+ 0xa05fbcf6, 0xcd4181e9, 0xe150210c, 0xe24ef1bd,
+ 0xb168c381, 0xfde4e789, 0x5c79b0d8, 0x1e8bfd43,
+ 0x4d495001, 0x38be4341, 0x913cee1d, 0x92a79c3f,
+ 0x089766be, 0xbaeeadf4, 0x1286becf, 0xb6eacb19,
+ 0x2660c200, 0x7565bde4, 0x64241f7a, 0x8248dca9,
+ 0xc3b3ad66, 0x28136086, 0x0bd8dfa8, 0x356d1cf2,
+ 0x107789be, 0xb3b2e9ce, 0x0502aa8f, 0x0bc0351e,
+ 0x166bf52a, 0xeb12ff82, 0xe3486911, 0xd34d7516,
+ 0x4e7b3aff, 0x5f43671b, 0x9cf6e037, 0x4981ac83,
+ 0x334266ce, 0x8c9341b7, 0xd0d854c0, 0xcb3a6c88,
+ 0x47bc2829, 0x4725ba37, 0xa66ad22b, 0x7ad61f1e,
+ 0x0c5cbafa, 0x4437f107, 0xb6e79962, 0x42d2d816,
+ 0x0a961288, 0xe1a5c06e, 0x13749e67, 0x72fc081a,
+ 0xb1d139f7, 0xf9583745, 0xcf19df58, 0xbec3f756,
+ 0xc06eba30, 0x07211b24, 0x45c28829, 0xc95e317f,
+ 0xbc8ec511, 0x38bc46e9, 0xc6e6fa14, 0xbae8584a,
+ 0xad4ebc46, 0x468f508b, 0x7829435f, 0xf124183b,
+ 0x821dba9f, 0xaff60ff4, 0xea2c4e6d, 0x16e39264,
+ 0x92544a8b, 0x009b4fc3, 0xaba68ced, 0x9ac96f78,
+ 0x06a5b79a, 0xb2856e6e, 0x1aec3ca9, 0xbe838688,
+ 0x0e0804e9, 0x55f1be56, 0xe7e5363b, 0xb3a1f25d,
+ 0xf7debb85, 0x61fe033c, 0x16746233, 0x3c034c28,
+ 0xda6d0c74, 0x79aac56c, 0x3ce4e1ad, 0x51f0c802,
+ 0x98f8f35a, 0x1626a49f, 0xeed82b29, 0x1d382fe3,
+ 0x0c4fb99a, 0xbb325778, 0x3ec6d97b, 0x6e77a6a9,
+ 0xcb658b5c, 0xd45230c7, 0x2bd1408b, 0x60c03eb7,
+ 0xb9068d78, 0xa33754f4, 0xf430c87d, 0xc8a71302,
+ 0xb96d8c32, 0xebd4e7be, 0xbe8b9d2d, 0x7979fb06,
+ 0xe7225308, 0x8b75cf77, 0x11ef8da4, 0xe083c858,
+ 0x8d6b786f, 0x5a6317a6, 0xfa5cf7a0, 0x5dda0033,
+ 0xf28ebfb0, 0xf5b9c310, 0xa0eac280, 0x08b9767a,
+ 0xa3d9d2b0, 0x79d34217, 0x021a718d, 0x9ac6336a,
+ 0x2711fd60, 0x438050e3, 0x069908a8, 0x3d7fedc4,
+ 0x826d2bef, 0x4eeb8476, 0x488dcf25, 0x36c9d566,
+ 0x28e74e41, 0xc2610aca, 0x3d49a9cf, 0xbae3b9df,
+ 0xb65f8de6, 0x92aeaf64, 0x3ac7d5e6, 0x9ea80509,
+ 0xf22b017d, 0xa4173f70, 0xdd1e16c3, 0x15e0d7f9,
+ 0x50b1b887, 0x2b9f4fd5, 0x625aba82, 0x6a017962,
+ 0x2ec01b9c, 0x15488aa9, 0xd716e740, 0x40055a2c,
+ 0x93d29a22, 0xe32dbf9a, 0x058745b9, 0x3453dc1e,
+ 0xd699296e, 0x496cff6f, 0x1c9f4986, 0xdfe2ed07,
+ 0xb87242d1, 0x19de7eae, 0x053e561a, 0x15ad6f8c,
+ 0x66626c1c, 0x7154c24c, 0xea082b2a, 0x93eb2939,
+ 0x17dcb0f0, 0x58d4f2ae, 0x9ea294fb, 0x52cf564c,
+ 0x9883fe66, 0x2ec40581, 0x763953c3, 0x01d6692e,
+ 0xd3a0c108, 0xa1e7160e, 0xe4f2dfa6, 0x693ed285,
+ 0x74904698, 0x4c2b0edd, 0x4f757656, 0x5d393378,
+ 0xa132234f, 0x3d321c5d, 0xc3f5e194, 0x4b269301,
+ 0xc79f022f, 0x3c997e7e, 0x5e4f9504, 0x3ffafbbd,
+ 0x76f7ad0e, 0x296693f4, 0x3d1fce6f, 0xc61e45be,
+ 0xd3b5ab34, 0xf72bf9b7, 0x1b0434c0, 0x4e72b567,
+ 0x5592a33d, 0xb5229301, 0xcfd2a87f, 0x60aeb767,
+ 0x1814386b, 0x30bcc33d, 0x38a0c07d, 0xfd1606f2,
+ 0xc363519b, 0x589dd390, 0x5479f8e6, 0x1cb8d647,
+ 0x97fd61a9, 0xea7759f4, 0x2d57539d, 0x569a58cf,
+ 0xe84e63ad, 0x462e1b78, 0x6580f87e, 0xf3817914,
+ 0x91da55f4, 0x40a230f3, 0xd1988f35, 0xb6e318d2,
+ 0x3ffa50bc, 0x3d40f021, 0xc3c0bdae, 0x4958c24c,
+ 0x518f36b2, 0x84b1d370, 0x0fedce83, 0x878ddada,
+ 0xf2a279c7, 0x94e01be8, 0x90716f4b, 0x954b8aa3
};
-static const u_int32_t cast_sbox8[256] = {
- 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095,
- 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5,
- 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174,
- 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC,
- 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940,
- 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD,
- 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42,
- 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D,
- 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164,
- 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2,
- 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4,
- 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862,
- 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0,
- 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC,
- 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6,
- 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C,
- 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491,
- 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E,
- 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B,
- 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039,
- 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8,
- 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8,
- 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006,
- 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42,
- 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564,
- 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5,
- 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB,
- 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472,
- 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC,
- 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225,
- 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8,
- 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C,
- 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441,
- 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB,
- 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F,
- 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054,
- 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504,
- 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70,
- 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C,
- 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC,
- 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6,
- 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C,
- 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD,
- 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3,
- 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4,
- 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4,
- 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC,
- 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101,
- 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA,
- 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F,
- 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF,
- 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E,
- 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603,
- 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A,
- 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37,
- 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C,
- 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819,
- 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384,
- 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D,
- 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C,
- 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347,
- 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82,
- 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D,
- 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E
+static const uint32_t cast_sbox8[256] =
+{
+ 0xe216300d, 0xbbddfffc, 0xa7ebdabd, 0x35648095,
+ 0x7789f8b7, 0xe6c1121b, 0x0e241600, 0x052ce8b5,
+ 0x11a9cfb0, 0xe5952f11, 0xece7990a, 0x9386d174,
+ 0x2a42931c, 0x76e38111, 0xb12def3a, 0x37ddddfc,
+ 0xde9adeb1, 0x0a0cc32c, 0xbe197029, 0x84a00940,
+ 0xbb243a0f, 0xb4d137cf, 0xb44e79f0, 0x049eedfd,
+ 0x0b15a15d, 0x480d3168, 0x8bbbde5a, 0x669ded42,
+ 0xc7ece831, 0x3f8f95e7, 0x72df191b, 0x7580330d,
+ 0x94074251, 0x5c7dcdfa, 0xabbe6d63, 0xaa402164,
+ 0xb301d40a, 0x02e7d1ca, 0x53571dae, 0x7a3182a2,
+ 0x12a8ddec, 0xfdaa335d, 0x176f43e8, 0x71fb46d4,
+ 0x38129022, 0xce949ad4, 0xb84769ad, 0x965bd862,
+ 0x82f3d055, 0x66fb9767, 0x15b80b4e, 0x1d5b47a0,
+ 0x4cfde06f, 0xc28ec4b8, 0x57e8726e, 0x647a78fc,
+ 0x99865d44, 0x608bd593, 0x6c200e03, 0x39dc5ff6,
+ 0x5d0b00a3, 0xae63aff2, 0x7e8bd632, 0x70108c0c,
+ 0xbbd35049, 0x2998df04, 0x980cf42a, 0x9b6df491,
+ 0x9e7edd53, 0x06918548, 0x58cb7e07, 0x3b74ef2e,
+ 0x522fffb1, 0xd24708cc, 0x1c7e27cd, 0xa4eb215b,
+ 0x3cf1d2e2, 0x19b47a38, 0x424f7618, 0x35856039,
+ 0x9d17dee7, 0x27eb35e6, 0xc9aff67b, 0x36baf5b8,
+ 0x09c467cd, 0xc18910b1, 0xe11dbf7b, 0x06cd1af8,
+ 0x7170c608, 0x2d5e3354, 0xd4de495a, 0x64c6d006,
+ 0xbcc0c62c, 0x3dd00db3, 0x708f8f34, 0x77d51b42,
+ 0x264f620f, 0x24b8d2bf, 0x15c1b79e, 0x46a52564,
+ 0xf8d7e54e, 0x3e378160, 0x7895cda5, 0x859c15a5,
+ 0xe6459788, 0xc37bc75f, 0xdb07ba0c, 0x0676a3ab,
+ 0x7f229b1e, 0x31842e7b, 0x24259fd7, 0xf8bef472,
+ 0x835ffcb8, 0x6df4c1f2, 0x96f5b195, 0xfd0af0fc,
+ 0xb0fe134c, 0xe2506d3d, 0x4f9b12ea, 0xf215f225,
+ 0xa223736f, 0x9fb4c428, 0x25d04979, 0x34c713f8,
+ 0xc4618187, 0xea7a6e98, 0x7cd16efc, 0x1436876c,
+ 0xf1544107, 0xbedeee14, 0x56e9af27, 0xa04aa441,
+ 0x3cf7c899, 0x92ecbae6, 0xdd67016d, 0x151682eb,
+ 0xa842eedf, 0xfdba60b4, 0xf1907b75, 0x20e3030f,
+ 0x24d8c29e, 0xe139673b, 0xefa63fb8, 0x71873054,
+ 0xb6f2cf3b, 0x9f326442, 0xcb15a4cc, 0xb01a4504,
+ 0xf1e47d8d, 0x844a1be5, 0xbae7dfdc, 0x42cbda70,
+ 0xcd7dae0a, 0x57e85b7a, 0xd53f5af6, 0x20cf4d8c,
+ 0xcea4d428, 0x79d130a4, 0x3486ebfb, 0x33d3cddc,
+ 0x77853b53, 0x37effcb5, 0xc5068778, 0xe580b3e6,
+ 0x4e68b8f4, 0xc5c8b37e, 0x0d809ea2, 0x398feb7c,
+ 0x132a4f94, 0x43b7950e, 0x2fee7d1c, 0x223613bd,
+ 0xdd06caa2, 0x37df932b, 0xc4248289, 0xacf3ebc3,
+ 0x5715f6b7, 0xef3478dd, 0xf267616f, 0xc148cbe4,
+ 0x9052815e, 0x5e410fab, 0xb48a2465, 0x2eda7fa4,
+ 0xe87b40e4, 0xe98ea084, 0x5889e9e1, 0xefd390fc,
+ 0xdd07d35b, 0xdb485694, 0x38d7e5b2, 0x57720101,
+ 0x730edebc, 0x5b643113, 0x94917e4f, 0x503c2fba,
+ 0x646f1282, 0x7523d24a, 0xe0779695, 0xf9c17a8f,
+ 0x7a5b2121, 0xd187b896, 0x29263a4d, 0xba510cdf,
+ 0x81f47c9f, 0xad1163ed, 0xea7b5965, 0x1a00726e,
+ 0x11403092, 0x00da6d77, 0x4a0cdd61, 0xad1f4603,
+ 0x605bdfb0, 0x9eedc364, 0x22ebe6a8, 0xcee7d28a,
+ 0xa0e736a0, 0x5564a6b9, 0x10853209, 0xc7eb8f37,
+ 0x2de705ca, 0x8951570f, 0xdf09822b, 0xbd691a6c,
+ 0xaa12e4f2, 0x87451c0f, 0xe0f6a27a, 0x3ada4819,
+ 0x4cf1764f, 0x0d771c2b, 0x67cdb156, 0x350d8384,
+ 0x5938fa0f, 0x42399ef3, 0x36997b07, 0x0e84093d,
+ 0x4aa93e61, 0x8360d87b, 0x1fa98b0c, 0x1149382c,
+ 0xe97625a5, 0x0614d1b7, 0x0e25244b, 0x0c768347,
+ 0x589e8d82, 0x0d2059d1, 0xa466bb1e, 0xf8da0a82,
+ 0x04f19130, 0xba6e4ec0, 0x99265164, 0x1ee7230d,
+ 0x50b2ad80, 0xeaee6801, 0x8db2a283, 0xea8bf59e
};
diff --git a/crypto/chacha_private.h b/crypto/chacha_private.h
index 8c926ea4b0..48b4031bda 100644
--- a/crypto/chacha_private.h
+++ b/crypto/chacha_private.h
@@ -1,62 +1,72 @@
-/* $OpenBSD: chacha_private.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $ */
-/*
-chacha-merged.c version 20080118
-D. J. Bernstein
-Public domain.
-*/
+/****************************************************************************
+ * crypto/chacha_private.h
+ * $OpenBSD: chacha_private.h,v 1.4 2020/07/22 13:54:30 tobhe Exp $
+ *
+ * chacha-merged.c version 20080118
+ * D. J. Bernstein
+ * Public domain.
+ ****************************************************************************/
-#include <sys/systm.h>
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
-typedef unsigned char u8;
-typedef unsigned int u32;
+#include <sys/systm.h>
typedef struct
{
- u32 input[16]; /* could be compressed */
-} chacha_ctx;
+ uint32_t input[16]; /* could be compressed */
+}
+chacha_ctx;
#define U8C(v) (v##U)
#define U32C(v) (v##U)
-#define U8V(v) ((u8)(v) & U8C(0xFF))
-#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
+#define U8V(v) ((uint8_t)(v) & U8C(0xFF))
+#define U32V(v) ((uint32_t)(v) & U32C(0xFFFFFFFF))
#define ROTL32(v, n) \
(U32V((v) << (n)) | ((v) >> (32 - (n))))
#define U8TO32_LITTLE(p) \
- (((u32)((p)[0]) ) | \
- ((u32)((p)[1]) << 8) | \
- ((u32)((p)[2]) << 16) | \
- ((u32)((p)[3]) << 24))
+ (((uint32_t)((p)[0])) | \
+ ((uint32_t)((p)[1]) << 8) | \
+ ((uint32_t)((p)[2]) << 16) | \
+ ((uint32_t)((p)[3]) << 24)) \
#define U32TO8_LITTLE(p, v) \
do { \
- (p)[0] = U8V((v) ); \
- (p)[1] = U8V((v) >> 8); \
+ (p)[0] = U8V((v)); \
+ (p)[1] = U8V((v) >> 8); \
(p)[2] = U8V((v) >> 16); \
(p)[3] = U8V((v) >> 24); \
} while (0)
-#define ROTATE(v,c) (ROTL32(v,c))
-#define XOR(v,w) ((v) ^ (w))
-#define PLUS(v,w) (U32V((v) + (w)))
-#define PLUSONE(v) (PLUS((v),1))
+#define ROTATE(v, c) (ROTL32(v, c))
+#define XOR(v, w) ((v) ^ (w))
+#define PLUS(v, w) (U32V((v) + (w)))
+#define PLUSONE(v) (PLUS((v), 1))
-#define QUARTERROUND(a,b,c,d) \
- a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
- c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
- a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
- c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
+#define QUARTERROUND(a, b, c, d) \
+ do \
+ { \
+ a = PLUS(a, b); d = ROTATE(XOR(d, a), 16); \
+ c = PLUS(c, d); b = ROTATE(XOR(b, c), 12); \
+ a = PLUS(a, b); d = ROTATE(XOR(d, a), 8); \
+ c = PLUS(c, d); b = ROTATE(XOR(b, c), 7); \
+ } \
+ while (0)
static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";
-static inline void
-hchacha20(u32 derived_key[8], const u8 nonce[16], const u8 key[32])
+static inline void hchacha20(FAR uint32_t *derived_key,
+ FAR const uint8_t *nonce,
+ FAR const uint8_t *key)
{
int i;
- uint32_t x[] = {
+ uint32_t x[] =
+ {
U8TO32_LITTLE(sigma + 0),
U8TO32_LITTLE(sigma + 4),
U8TO32_LITTLE(sigma + 8),
@@ -75,36 +85,46 @@ hchacha20(u32 derived_key[8], const u8 nonce[16], const u8 key[32])
U8TO32_LITTLE(nonce + 12)
};
- for (i = 20;i > 0;i -= 2) {
- QUARTERROUND( x[0], x[4], x[8],x[12])
- QUARTERROUND( x[1], x[5], x[9],x[13])
- QUARTERROUND( x[2], x[6],x[10],x[14])
- QUARTERROUND( x[3], x[7],x[11],x[15])
- QUARTERROUND( x[0], x[5],x[10],x[15])
- QUARTERROUND( x[1], x[6],x[11],x[12])
- QUARTERROUND( x[2], x[7], x[8],x[13])
- QUARTERROUND( x[3], x[4], x[9],x[14])
- }
-
- memcpy(derived_key + 0, x + 0, sizeof(u32) * 4);
- memcpy(derived_key + 4, x + 12, sizeof(u32) * 4);
+ for (i = 20; i > 0; i -= 2)
+ {
+ QUARTERROUND(x[0], x[4], x[8], x[12]);
+ QUARTERROUND(x[1], x[5], x[9], x[13]);
+ QUARTERROUND(x[2], x[6], x[10], x[14]);
+ QUARTERROUND(x[3], x[7], x[11], x[15]);
+ QUARTERROUND(x[0], x[5], x[10], x[15]);
+ QUARTERROUND(x[1], x[6], x[11], x[12]);
+ QUARTERROUND(x[2], x[7], x[8], x[13]);
+ QUARTERROUND(x[3], x[4], x[9], x[14]);
+ }
+
+ memcpy(derived_key + 0, x + 0, sizeof(uint32_t) * 4);
+ memcpy(derived_key + 4, x + 12, sizeof(uint32_t) * 4);
}
-static void
-chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
+static void chacha_keysetup(FAR chacha_ctx *x,
+ FAR const uint8_t *k,
+ FAR uint32_t kbits)
{
- const char *constants;
+ FAR const char *constants;
x->input[4] = U8TO32_LITTLE(k + 0);
x->input[5] = U8TO32_LITTLE(k + 4);
x->input[6] = U8TO32_LITTLE(k + 8);
x->input[7] = U8TO32_LITTLE(k + 12);
- if (kbits == 256) { /* recommended */
- k += 16;
- constants = sigma;
- } else { /* kbits == 128 */
- constants = tau;
- }
+ if (kbits == 256)
+ {
+ /* recommended */
+
+ k += 16;
+ constants = sigma;
+ }
+ else
+ {
+ /* kbits == 128 */
+
+ constants = tau;
+ }
+
x->input[8] = U8TO32_LITTLE(k + 0);
x->input[9] = U8TO32_LITTLE(k + 4);
x->input[10] = U8TO32_LITTLE(k + 8);
@@ -115,8 +135,9 @@ chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
x->input[3] = U8TO32_LITTLE(constants + 12);
}
-static void
-chacha_ivsetup(chacha_ctx *x, const u8 *iv, const u8 *counter)
+static void chacha_ivsetup(FAR chacha_ctx *x,
+ FAR const uint8_t *iv,
+ FAR const uint8_t *counter)
{
x->input[12] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 0);
x->input[13] = counter == NULL ? 0 : U8TO32_LITTLE(counter + 4);
@@ -124,16 +145,51 @@ chacha_ivsetup(chacha_ctx *x, const u8 *iv, const u8 *counter)
x->input[15] = U8TO32_LITTLE(iv + 4);
}
-static void
-chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
+static void chacha_encrypt_bytes(FAR chacha_ctx *x,
+ FAR const uint8_t *m,
+ FAR uint8_t *c,
+ uint32_t bytes)
{
- u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
- u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
- u8 *ctarget = NULL;
- u8 tmp[64];
+ uint32_t x0;
+ uint32_t x1;
+ uint32_t x2;
+ uint32_t x3;
+ uint32_t x4;
+ uint32_t x5;
+ uint32_t x6;
+ uint32_t x7;
+ uint32_t x8;
+ uint32_t x9;
+ uint32_t x10;
+ uint32_t x11;
+ uint32_t x12;
+ uint32_t x13;
+ uint32_t x14;
+ uint32_t x15;
+ uint32_t j0;
+ uint32_t j1;
+ uint32_t j2;
+ uint32_t j3;
+ uint32_t j4;
+ uint32_t j5;
+ uint32_t j6;
+ uint32_t j7;
+ uint32_t j8;
+ uint32_t j9;
+ uint32_t j10;
+ uint32_t j11;
+ uint32_t j12;
+ uint32_t j13;
+ uint32_t j14;
+ uint32_t j15;
+ FAR uint8_t *ctarget = NULL;
+ uint8_t tmp[64];
u_int i;
- if (!bytes) return;
+ if (!bytes)
+ {
+ return;
+ }
j0 = x->input[0];
j1 = x->input[1];
@@ -152,110 +208,128 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
j14 = x->input[14];
j15 = x->input[15];
- for (;;) {
- if (bytes < 64) {
- for (i = 0;i < bytes;++i) tmp[i] = m[i];
- m = tmp;
- ctarget = c;
- c = tmp;
- }
- x0 = j0;
- x1 = j1;
- x2 = j2;
- x3 = j3;
- x4 = j4;
- x5 = j5;
- x6 = j6;
- x7 = j7;
- x8 = j8;
- x9 = j9;
- x10 = j10;
- x11 = j11;
- x12 = j12;
- x13 = j13;
- x14 = j14;
- x15 = j15;
- for (i = 20;i > 0;i -= 2) {
- QUARTERROUND( x0, x4, x8,x12)
- QUARTERROUND( x1, x5, x9,x13)
- QUARTERROUND( x2, x6,x10,x14)
- QUARTERROUND( x3, x7,x11,x15)
- QUARTERROUND( x0, x5,x10,x15)
- QUARTERROUND( x1, x6,x11,x12)
- QUARTERROUND( x2, x7, x8,x13)
- QUARTERROUND( x3, x4, x9,x14)
- }
- x0 = PLUS(x0,j0);
- x1 = PLUS(x1,j1);
- x2 = PLUS(x2,j2);
- x3 = PLUS(x3,j3);
- x4 = PLUS(x4,j4);
- x5 = PLUS(x5,j5);
- x6 = PLUS(x6,j6);
- x7 = PLUS(x7,j7);
- x8 = PLUS(x8,j8);
- x9 = PLUS(x9,j9);
- x10 = PLUS(x10,j10);
- x11 = PLUS(x11,j11);
- x12 = PLUS(x12,j12);
- x13 = PLUS(x13,j13);
- x14 = PLUS(x14,j14);
- x15 = PLUS(x15,j15);
+ for (; ; )
+ {
+ if (bytes < 64)
+ {
+ for (i = 0; i < bytes; ++i)
+ {
+ tmp[i] = m[i];
+ }
+
+ m = tmp;
+ ctarget = c;
+ c = tmp;
+ }
+
+ x0 = j0;
+ x1 = j1;
+ x2 = j2;
+ x3 = j3;
+ x4 = j4;
+ x5 = j5;
+ x6 = j6;
+ x7 = j7;
+ x8 = j8;
+ x9 = j9;
+ x10 = j10;
+ x11 = j11;
+ x12 = j12;
+ x13 = j13;
+ x14 = j14;
+ x15 = j15;
+ for (i = 20; i > 0; i -= 2)
+ {
+ QUARTERROUND(x0, x4, x8, x12);
+ QUARTERROUND(x1, x5, x9, x13);
+ QUARTERROUND(x2, x6, x10, x14);
+ QUARTERROUND(x3, x7, x11, x15);
+ QUARTERROUND(x0, x5, x10, x15);
+ QUARTERROUND(x1, x6, x11, x12);
+ QUARTERROUND(x2, x7, x8, x13);
+ QUARTERROUND(x3, x4, x9, x14);
+ }
+
+ x0 = PLUS(x0, j0);
+ x1 = PLUS(x1, j1);
+ x2 = PLUS(x2, j2);
+ x3 = PLUS(x3, j3);
+ x4 = PLUS(x4, j4);
+ x5 = PLUS(x5, j5);
+ x6 = PLUS(x6, j6);
+ x7 = PLUS(x7, j7);
+ x8 = PLUS(x8, j8);
+ x9 = PLUS(x9, j9);
+ x10 = PLUS(x10, j10);
+ x11 = PLUS(x11, j11);
+ x12 = PLUS(x12, j12);
+ x13 = PLUS(x13, j13);
+ x14 = PLUS(x14, j14);
+ x15 = PLUS(x15, j15);
#ifndef KEYSTREAM_ONLY
- x0 = XOR(x0,U8TO32_LITTLE(m + 0));
- x1 = XOR(x1,U8TO32_LITTLE(m + 4));
- x2 = XOR(x2,U8TO32_LITTLE(m + 8));
- x3 = XOR(x3,U8TO32_LITTLE(m + 12));
- x4 = XOR(x4,U8TO32_LITTLE(m + 16));
- x5 = XOR(x5,U8TO32_LITTLE(m + 20));
- x6 = XOR(x6,U8TO32_LITTLE(m + 24));
- x7 = XOR(x7,U8TO32_LITTLE(m + 28));
- x8 = XOR(x8,U8TO32_LITTLE(m + 32));
- x9 = XOR(x9,U8TO32_LITTLE(m + 36));
- x10 = XOR(x10,U8TO32_LITTLE(m + 40));
- x11 = XOR(x11,U8TO32_LITTLE(m + 44));
- x12 = XOR(x12,U8TO32_LITTLE(m + 48));
- x13 = XOR(x13,U8TO32_LITTLE(m + 52));
- x14 = XOR(x14,U8TO32_LITTLE(m + 56));
- x15 = XOR(x15,U8TO32_LITTLE(m + 60));
+ x0 = XOR(x0, U8TO32_LITTLE(m + 0));
+ x1 = XOR(x1, U8TO32_LITTLE(m + 4));
+ x2 = XOR(x2, U8TO32_LITTLE(m + 8));
+ x3 = XOR(x3, U8TO32_LITTLE(m + 12));
+ x4 = XOR(x4, U8TO32_LITTLE(m + 16));
+ x5 = XOR(x5, U8TO32_LITTLE(m + 20));
+ x6 = XOR(x6, U8TO32_LITTLE(m + 24));
+ x7 = XOR(x7, U8TO32_LITTLE(m + 28));
+ x8 = XOR(x8, U8TO32_LITTLE(m + 32));
+ x9 = XOR(x9, U8TO32_LITTLE(m + 36));
+ x10 = XOR(x10, U8TO32_LITTLE(m + 40));
+ x11 = XOR(x11, U8TO32_LITTLE(m + 44));
+ x12 = XOR(x12, U8TO32_LITTLE(m + 48));
+ x13 = XOR(x13, U8TO32_LITTLE(m + 52));
+ x14 = XOR(x14, U8TO32_LITTLE(m + 56));
+ x15 = XOR(x15, U8TO32_LITTLE(m + 60));
#endif
- j12 = PLUSONE(j12);
- if (!j12) {
- j13 = PLUSONE(j13);
- /* stopping at 2^70 bytes per nonce is user's responsibility */
- }
+ j12 = PLUSONE(j12);
+ if (!j12)
+ {
+ j13 = PLUSONE(j13);
- U32TO8_LITTLE(c + 0,x0);
- U32TO8_LITTLE(c + 4,x1);
- U32TO8_LITTLE(c + 8,x2);
- U32TO8_LITTLE(c + 12,x3);
- U32TO8_LITTLE(c + 16,x4);
- U32TO8_LITTLE(c + 20,x5);
- U32TO8_LITTLE(c + 24,x6);
- U32TO8_LITTLE(c + 28,x7);
- U32TO8_LITTLE(c + 32,x8);
- U32TO8_LITTLE(c + 36,x9);
- U32TO8_LITTLE(c + 40,x10);
- U32TO8_LITTLE(c + 44,x11);
- U32TO8_LITTLE(c + 48,x12);
- U32TO8_LITTLE(c + 52,x13);
- U32TO8_LITTLE(c + 56,x14);
- U32TO8_LITTLE(c + 60,x15);
-
- if (bytes <= 64) {
- if (bytes < 64) {
- for (i = 0;i < bytes;++i) ctarget[i] = c[i];
- }
- x->input[12] = j12;
- x->input[13] = j13;
- return;
- }
- bytes -= 64;
- c += 64;
+ /* stopping at 2^70 bytes per nonce is user's responsibility */
+ }
+
+ U32TO8_LITTLE(c + 0, x0);
+ U32TO8_LITTLE(c + 4, x1);
+ U32TO8_LITTLE(c + 8, x2);
+ U32TO8_LITTLE(c + 12, x3);
+ U32TO8_LITTLE(c + 16, x4);
+ U32TO8_LITTLE(c + 20, x5);
+ U32TO8_LITTLE(c + 24, x6);
+ U32TO8_LITTLE(c + 28, x7);
+ U32TO8_LITTLE(c + 32, x8);
+ U32TO8_LITTLE(c + 36, x9);
+ U32TO8_LITTLE(c + 40, x10);
+ U32TO8_LITTLE(c + 44, x11);
+ U32TO8_LITTLE(c + 48, x12);
+ U32TO8_LITTLE(c + 52, x13);
+ U32TO8_LITTLE(c + 56, x14);
+ U32TO8_LITTLE(c + 60, x15);
+
+ if (bytes <= 64)
+ {
+ if (bytes < 64)
+ {
+ for (i = 0; i < bytes; ++i)
+ {
+ ctarget[i] = c[i];
+ }
+ }
+
+ x->input[12] = j12;
+ x->input[13] = j13;
+ return;
+ }
+
+ bytes -= 64;
+ c += 64;
#ifndef KEYSTREAM_ONLY
- m += 64;
+ m += 64;
#endif
- }
+ }
}
diff --git a/crypto/chachapoly.c b/crypto/chachapoly.c
index 348435b1e5..8e5e6b913b 100644
--- a/crypto/chachapoly.c
+++ b/crypto/chachapoly.c
@@ -1,5 +1,7 @@
-/* $OpenBSD: chachapoly.c,v 1.6 2020/07/22 13:54:30 tobhe Exp $ */
-/*
+/****************************************************************************
+ * crypto/chachapoly.c
+ * $OpenBSD: chachapoly.c,v 1.6 2020/07/22 13:54:30 tobhe Exp $
+ *
* Copyright (c) 2015 Mike Belopuhov
*
* Permission to use, copy, modify, and distribute this software for any
@@ -13,7 +15,11 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
@@ -22,240 +28,272 @@
#include <crypto/poly1305.h>
#include <crypto/chachapoly.h>
-int
-chacha20_setkey(void *sched, u_int8_t *key, int len)
+#include "chacha_private.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const uint8_t pad0[16];
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int chacha20_setkey(FAR void *sched, FAR uint8_t *key, int len)
{
- struct chacha20_ctx *ctx = (struct chacha20_ctx *)sched;
+ FAR struct chacha20_ctx *ctx = (FAR struct chacha20_ctx *)sched;
+
+ if (len != CHACHA20_KEYSIZE + CHACHA20_SALT)
+ {
+ return -1;
+ }
- if (len != CHACHA20_KEYSIZE + CHACHA20_SALT)
- return (-1);
+ /* initial counter is 1 */
- /* initial counter is 1 */
- ctx->nonce[0] = 1;
- memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE,
- CHACHA20_SALT);
- chacha_keysetup((chacha_ctx *)&ctx->block, key, CHACHA20_KEYSIZE * 8);
- return (0);
+ ctx->nonce[0] = 1;
+ memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE,
+ CHACHA20_SALT);
+ chacha_keysetup((FAR chacha_ctx *)&ctx->block, key, CHACHA20_KEYSIZE * 8);
+ return 0;
}
-void
-chacha20_reinit(caddr_t key, u_int8_t *iv)
+void chacha20_reinit(caddr_t key, FAR uint8_t *iv)
{
- struct chacha20_ctx *ctx = (struct chacha20_ctx *)key;
+ FAR struct chacha20_ctx *ctx = (FAR struct chacha20_ctx *)key;
- chacha_ivsetup((chacha_ctx *)ctx->block, iv, ctx->nonce);
+ chacha_ivsetup((FAR chacha_ctx *)ctx->block, iv, ctx->nonce);
}
-void
-chacha20_crypt(caddr_t key, u_int8_t *data)
+void chacha20_crypt(caddr_t key, FAR uint8_t *data)
{
- struct chacha20_ctx *ctx = (struct chacha20_ctx *)key;
+ FAR struct chacha20_ctx *ctx = (FAR struct chacha20_ctx *)key;
- chacha_encrypt_bytes((chacha_ctx *)ctx->block, data, data,
- CHACHA20_BLOCK_LEN);
+ chacha_encrypt_bytes((FAR chacha_ctx *)ctx->block, data, data,
+ CHACHA20_BLOCK_LEN);
}
-void
-Chacha20_Poly1305_Init(void *xctx)
+void chacha20_poly1305_init(FAR void *xctx)
{
- CHACHA20_POLY1305_CTX *ctx = xctx;
+ FAR CHACHA20_POLY1305_CTX *ctx = xctx;
- memset(ctx, 0, sizeof(*ctx));
+ memset(ctx, 0, sizeof(*ctx));
}
-void
-Chacha20_Poly1305_Setkey(void *xctx, const uint8_t *key, uint16_t klen)
+void chacha20_poly1305_setkey(FAR void *xctx, FAR const uint8_t *key,
+ uint16_t klen)
{
- CHACHA20_POLY1305_CTX *ctx = xctx;
+ FAR CHACHA20_POLY1305_CTX *ctx = xctx;
- /* salt is provided with the key material */
- memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE,
- CHACHA20_SALT);
- chacha_keysetup((chacha_ctx *)&ctx->chacha, key, CHACHA20_KEYSIZE * 8);
+ /* salt is provided with the key material */
+
+ memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE,
+ CHACHA20_SALT);
+ chacha_keysetup((FAR chacha_ctx *)&ctx->chacha, key, CHACHA20_KEYSIZE * 8);
}
-void
-Chacha20_Poly1305_Reinit(void *xctx, const uint8_t *iv, uint16_t ivlen)
+void chacha20_poly1305_reinit(FAR void *xctx, FAR const uint8_t *iv,
+ uint16_t ivlen)
{
- CHACHA20_POLY1305_CTX *ctx = xctx;
+ FAR CHACHA20_POLY1305_CTX *ctx = xctx;
+
+ /* initial counter is 0 */
- /* initial counter is 0 */
- chacha_ivsetup((chacha_ctx *)&ctx->chacha, iv, ctx->nonce);
- chacha_encrypt_bytes((chacha_ctx *)&ctx->chacha, ctx->key, ctx->key,
- POLY1305_KEYLEN);
- poly1305_init((poly1305_state *)&ctx->poly, ctx->key);
+ chacha_ivsetup((FAR chacha_ctx *)&ctx->chacha, iv, ctx->nonce);
+ chacha_encrypt_bytes((FAR chacha_ctx *)&ctx->chacha, ctx->key, ctx->key,
+ POLY1305_KEYLEN);
+ poly1305_init((FAR poly1305_state *)&ctx->poly, ctx->key);
}
-int
-Chacha20_Poly1305_Update(void *xctx, const uint8_t *data, uint16_t len)
+int chacha20_poly1305_update(FAR void *xctx, FAR const uint8_t *data,
+ uint16_t len)
{
- static const unsigned char zeroes[POLY1305_BLOCK_LEN];
- CHACHA20_POLY1305_CTX *ctx = xctx;
- size_t rem;
-
- poly1305_update((poly1305_state *)&ctx->poly, data, len);
-
- /* number of bytes in the last 16 byte block */
- rem = (len + POLY1305_BLOCK_LEN) & (POLY1305_BLOCK_LEN - 1);
- if (rem > 0)
- poly1305_update((poly1305_state *)&ctx->poly, zeroes,
- POLY1305_BLOCK_LEN - rem);
- return (0);
+ static const unsigned char zeroes[POLY1305_BLOCK_LEN];
+ FAR CHACHA20_POLY1305_CTX *ctx = xctx;
+ size_t rem;
+
+ poly1305_update((FAR poly1305_state *)&ctx->poly, data, len);
+
+ /* number of bytes in the last 16 byte block */
+
+ rem = (len + POLY1305_BLOCK_LEN) & (POLY1305_BLOCK_LEN - 1);
+ if (rem > 0)
+ {
+ poly1305_update((FAR poly1305_state *)&ctx->poly, zeroes,
+ POLY1305_BLOCK_LEN - rem);
+ }
+
+ return 0;
}
-void
-Chacha20_Poly1305_Final(uint8_t tag[POLY1305_TAGLEN], void *xctx)
+void chacha20_poly1305_final(FAR uint8_t *tag, FAR void *xctx)
{
- CHACHA20_POLY1305_CTX *ctx = xctx;
+ FAR CHACHA20_POLY1305_CTX *ctx = xctx;
- poly1305_finish((poly1305_state *)&ctx->poly, tag);
- explicit_bzero(ctx, sizeof(*ctx));
+ poly1305_finish((FAR poly1305_state *)&ctx->poly, tag);
+ explicit_bzero(ctx, sizeof(*ctx));
}
-static const uint8_t pad0[16] = { 0 };
-
-void
-chacha20poly1305_encrypt(
- uint8_t *dst,
- const uint8_t *src,
- const size_t src_len,
- const uint8_t *ad,
- const size_t ad_len,
- const uint64_t nonce,
- const uint8_t key[CHACHA20POLY1305_KEY_SIZE]
-) {
- poly1305_state poly1305_ctx;
- chacha_ctx ctx;
- union {
- uint8_t b0[CHACHA20POLY1305_KEY_SIZE];
- uint64_t lens[2];
- } b = { { 0 } };
- uint64_t le_nonce = htole64(nonce);
-
- chacha_keysetup(&ctx, key, CHACHA20POLY1305_KEY_SIZE * 8);
- chacha_ivsetup(&ctx, (uint8_t *) &le_nonce, NULL);
- chacha_encrypt_bytes(&ctx, b.b0, b.b0, sizeof(b.b0));
- poly1305_init(&poly1305_ctx, b.b0);
-
- poly1305_update(&poly1305_ctx, ad, ad_len);
- poly1305_update(&poly1305_ctx, pad0, (0x10 - ad_len) & 0xf);
-
- chacha_encrypt_bytes(&ctx, (uint8_t *) src, dst, src_len);
-
- poly1305_update(&poly1305_ctx, dst, src_len);
- poly1305_update(&poly1305_ctx, pad0, (0x10 - src_len) & 0xf);
-
- b.lens[0] = htole64(ad_len);
- b.lens[1] = htole64(src_len);
- poly1305_update(&poly1305_ctx, (uint8_t *)b.lens, sizeof(b.lens));
-
- poly1305_finish(&poly1305_ctx, dst + src_len);
-
- explicit_bzero(&ctx, sizeof(chacha_ctx));
- explicit_bzero(&b, sizeof(b));
+void chacha20poly1305_encrypt(
+ FAR uint8_t *dst,
+ FAR const uint8_t *src,
+ const size_t src_len,
+ FAR const uint8_t *ad,
+ const size_t ad_len,
+ const uint64_t nonce,
+ FAR const uint8_t *key)
+{
+ poly1305_state poly1305_ctx;
+ chacha_ctx ctx;
+ union
+ {
+ uint8_t b0[CHACHA20POLY1305_KEY_SIZE];
+ uint64_t lens[2];
+ } b =
+ {
+ {
+ 0
+ }
+ };
+
+ uint64_t le_nonce = htole64(nonce);
+
+ chacha_keysetup(&ctx, key, CHACHA20POLY1305_KEY_SIZE * 8);
+ chacha_ivsetup(&ctx, (FAR uint8_t *) &le_nonce, NULL);
+ chacha_encrypt_bytes(&ctx, b.b0, b.b0, sizeof(b.b0));
+ poly1305_init(&poly1305_ctx, b.b0);
+
+ poly1305_update(&poly1305_ctx, ad, ad_len);
+ poly1305_update(&poly1305_ctx, pad0, (0x10 - ad_len) & 0xf);
+
+ chacha_encrypt_bytes(&ctx, (FAR uint8_t *)src, dst, src_len);
+
+ poly1305_update(&poly1305_ctx, dst, src_len);
+ poly1305_update(&poly1305_ctx, pad0, (0x10 - src_len) & 0xf);
+
+ b.lens[0] = htole64(ad_len);
+ b.lens[1] = htole64(src_len);
+ poly1305_update(&poly1305_ctx, (FAR uint8_t *)b.lens, sizeof(b.lens));
+
+ poly1305_finish(&poly1305_ctx, dst + src_len);
+
+ explicit_bzero(&ctx, sizeof(chacha_ctx));
+ explicit_bzero(&b, sizeof(b));
}
-int
-chacha20poly1305_decrypt(
- uint8_t *dst,
- const uint8_t *src,
- const size_t src_len,
- const uint8_t *ad,
- const size_t ad_len,
- const uint64_t nonce,
- const uint8_t key[CHACHA20POLY1305_KEY_SIZE]
-) {
- poly1305_state poly1305_ctx;
- chacha_ctx ctx;
- int ret;
- size_t dst_len;
- union {
- uint8_t b0[CHACHA20POLY1305_KEY_SIZE];
- uint8_t mac[CHACHA20POLY1305_AUTHTAG_SIZE];
- uint64_t lens[2];
- } b = { { 0 } };
- uint64_t le_nonce = htole64(nonce);
-
- if (src_len < CHACHA20POLY1305_AUTHTAG_SIZE)
- return 0;
-
- chacha_keysetup(&ctx, key, CHACHA20POLY1305_KEY_SIZE * 8);
- chacha_ivsetup(&ctx, (uint8_t *) &le_nonce, NULL);
- chacha_encrypt_bytes(&ctx, b.b0, b.b0, sizeof(b.b0));
- poly1305_init(&poly1305_ctx, b.b0);
-
- poly1305_update(&poly1305_ctx, ad, ad_len);
- poly1305_update(&poly1305_ctx, pad0, (0x10 - ad_len) & 0xf);
-
- dst_len = src_len - CHACHA20POLY1305_AUTHTAG_SIZE;
- poly1305_update(&poly1305_ctx, src, dst_len);
- poly1305_update(&poly1305_ctx, pad0, (0x10 - dst_len) & 0xf);
-
- b.lens[0] = htole64(ad_len);
- b.lens[1] = htole64(dst_len);
- poly1305_update(&poly1305_ctx, (uint8_t *)b.lens, sizeof(b.lens));
-
- poly1305_finish(&poly1305_ctx, b.mac);
-
- ret = timingsafe_bcmp(b.mac, src + dst_len, CHACHA20POLY1305_AUTHTAG_SIZE);
- if (!ret)
- chacha_encrypt_bytes(&ctx, (uint8_t *) src, dst, dst_len);
-
- explicit_bzero(&ctx, sizeof(ctx));
- explicit_bzero(&b, sizeof(b));
-
- return !ret;
+int chacha20poly1305_decrypt(
+ FAR uint8_t *dst,
+ FAR const uint8_t *src,
+ const size_t src_len,
+ FAR const uint8_t *ad,
+ const size_t ad_len,
+ const uint64_t nonce,
+ FAR const uint8_t *key)
+{
+ poly1305_state poly1305_ctx;
+ chacha_ctx ctx;
+ int ret;
+ size_t dst_len;
+ union {
+ uint8_t b0[CHACHA20POLY1305_KEY_SIZE];
+ uint8_t mac[CHACHA20POLY1305_AUTHTAG_SIZE];
+ uint64_t lens[2];
+ } b =
+ {
+ {
+ 0
+ }
+ };
+
+ uint64_t le_nonce = htole64(nonce);
+
+ if (src_len < CHACHA20POLY1305_AUTHTAG_SIZE)
+ {
+ return 0;
+ }
+
+ chacha_keysetup(&ctx, key, CHACHA20POLY1305_KEY_SIZE * 8);
+ chacha_ivsetup(&ctx, (FAR uint8_t *) &le_nonce, NULL);
+ chacha_encrypt_bytes(&ctx, b.b0, b.b0, sizeof(b.b0));
+ poly1305_init(&poly1305_ctx, b.b0);
+
+ poly1305_update(&poly1305_ctx, ad, ad_len);
+ poly1305_update(&poly1305_ctx, pad0, (0x10 - ad_len) & 0xf);
+
+ dst_len = src_len - CHACHA20POLY1305_AUTHTAG_SIZE;
+ poly1305_update(&poly1305_ctx, src, dst_len);
+ poly1305_update(&poly1305_ctx, pad0, (0x10 - dst_len) & 0xf);
+
+ b.lens[0] = htole64(ad_len);
+ b.lens[1] = htole64(dst_len);
+ poly1305_update(&poly1305_ctx, (FAR uint8_t *)b.lens, sizeof(b.lens));
+
+ poly1305_finish(&poly1305_ctx, b.mac);
+
+ ret = timingsafe_bcmp(b.mac, src + dst_len, CHACHA20POLY1305_AUTHTAG_SIZE);
+ if (!ret)
+ {
+ chacha_encrypt_bytes(&ctx, (FAR uint8_t *) src, dst, dst_len);
+ }
+
+ explicit_bzero(&ctx, sizeof(chacha_ctx));
+ explicit_bzero(&b, sizeof(b));
+
+ return !ret;
}
-void
-xchacha20poly1305_encrypt(
- uint8_t *dst,
- const uint8_t *src,
- const size_t src_len,
- const uint8_t *ad,
- const size_t ad_len,
- const uint8_t nonce[XCHACHA20POLY1305_NONCE_SIZE],
- const uint8_t key[CHACHA20POLY1305_KEY_SIZE]
-) {
- int i;
- uint32_t derived_key[CHACHA20POLY1305_KEY_SIZE / sizeof(uint32_t)];
- uint64_t h_nonce;
-
- memcpy(&h_nonce, nonce + 16, sizeof(h_nonce));
- h_nonce = le64toh(h_nonce);
- hchacha20(derived_key, nonce, key);
-
- for(i = 0; i < (sizeof(derived_key)/sizeof(derived_key[0])); i++)
- (derived_key[i]) = htole32((derived_key[i]));
-
- chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len,
- h_nonce, (uint8_t *)derived_key);
- explicit_bzero(derived_key, CHACHA20POLY1305_KEY_SIZE);
+void xchacha20poly1305_encrypt(
+ FAR uint8_t *dst,
+ FAR const uint8_t *src,
+ const size_t src_len,
+ FAR const uint8_t *ad,
+ const size_t ad_len,
+ FAR const uint8_t *nonce,
+ FAR const uint8_t *key)
+{
+ int i;
+ uint32_t derived_key[CHACHA20POLY1305_KEY_SIZE / sizeof(uint32_t)];
+ uint64_t h_nonce;
+
+ memcpy(&h_nonce, nonce + 16, sizeof(h_nonce));
+ h_nonce = le64toh(h_nonce);
+ hchacha20(derived_key, nonce, key);
+
+ for (i = 0; i < (sizeof(derived_key) / sizeof(derived_key[0])); i++)
+ {
+ derived_key[i] = htole32(derived_key[i]);
+ }
+
+ chacha20poly1305_encrypt(dst, src, src_len, ad, ad_len,
+ h_nonce, (FAR uint8_t *)derived_key);
+ explicit_bzero(derived_key, CHACHA20POLY1305_KEY_SIZE);
}
-int
-xchacha20poly1305_decrypt(
- uint8_t *dst,
- const uint8_t *src,
- const size_t src_len,
- const uint8_t *ad,
- const size_t ad_len,
- const uint8_t nonce[XCHACHA20POLY1305_NONCE_SIZE],
- const uint8_t key[CHACHA20POLY1305_KEY_SIZE]
-) {
- int ret, i;
- uint32_t derived_key[CHACHA20POLY1305_KEY_SIZE / sizeof(uint32_t)];
- uint64_t h_nonce;
-
- memcpy(&h_nonce, nonce + 16, sizeof(h_nonce));
- h_nonce = le64toh(h_nonce);
- hchacha20(derived_key, nonce, key);
- for(i = 0; i < (sizeof(derived_key)/sizeof(derived_key[0])); i++)
- (derived_key[i]) = htole32((derived_key[i]));
-
- ret = chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len,
- h_nonce, (uint8_t *)derived_key);
- explicit_bzero(derived_key, CHACHA20POLY1305_KEY_SIZE);
-
- return ret;
+int xchacha20poly1305_decrypt(
+ FAR uint8_t *dst,
+ FAR const uint8_t *src,
+ const size_t src_len,
+ FAR const uint8_t *ad,
+ const size_t ad_len,
+ FAR const uint8_t *nonce,
+ FAR const uint8_t *key)
+{
+ int ret;
+ int i;
+ uint32_t derived_key[CHACHA20POLY1305_KEY_SIZE / sizeof(uint32_t)];
+ uint64_t h_nonce;
+
+ memcpy(&h_nonce, nonce + 16, sizeof(h_nonce));
+ h_nonce = le64toh(h_nonce);
+ hchacha20(derived_key, nonce, key);
+ for (i = 0; i < (sizeof(derived_key) / sizeof(derived_key[0])); i++)
+ {
+ derived_key[i] = htole32(derived_key[i]);
+ }
+
+ ret = chacha20poly1305_decrypt(dst, src, src_len, ad, ad_len,
+ h_nonce, (FAR uint8_t *)derived_key);
+ explicit_bzero(derived_key, CHACHA20POLY1305_KEY_SIZE);
+
+ return ret;
}
diff --git a/crypto/cmac.c b/crypto/cmac.c
index 97ad3fc22c..04e038809a 100644
--- a/crypto/cmac.c
+++ b/crypto/cmac.c
@@ -1,6 +1,7 @@
-/* $OpenBSD: cmac.c,v 1.3 2017/05/02 17:07:06 mikeb Exp $ */
-
-/*-
+/****************************************************************************
+ * crypto/cmac.c
+ * $OpenBSD: cmac.c,v 1.3 2017/05/02 17:07:06 mikeb Exp $
+ *
* Copyright (c) 2008 Damien Bergamini <da...@free.fr>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -14,107 +15,145 @@
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
+ *
+ ****************************************************************************/
-/*
- * This code implements the CMAC (Cipher-based Message Authentication)
+/* This code implements the CMAC (Cipher-based Message Authentication)
* algorithm described in FIPS SP800-38B using the AES-128 cipher.
*/
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
#include <sys/param.h>
#include <sys/systm.h>
#include <crypto/aes.h>
#include <crypto/cmac.h>
-#define LSHIFT(v, r) do { \
- int i; \
- for (i = 0; i < 15; i++) \
- (r)[i] = (v)[i] << 1 | (v)[i + 1] >> 7; \
- (r)[15] = (v)[15] << 1; \
-} while (0)
-
-#define XOR(v, r) do { \
- int i; \
- for (i = 0; i < 16; i++) \
- (r)[i] ^= (v)[i]; \
-} while (0)
-
-void
-AES_CMAC_Init(AES_CMAC_CTX *ctx)
+#define LSHIFT(v, r) do \
+ { \
+ int i; \
+ for (i = 0; i < 15; i++) \
+ (r)[i] = (v)[i] << 1 | (v)[i + 1] >> 7; \
+ (r)[15] = (v)[15] << 1; \
+ } while (0)
+
+#define XOR(v, r) do \
+ { \
+ int i; \
+ for (i = 0; i < 16; i++) \
+ (r)[i] ^= (v)[i]; \
+ } while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void aes_cmac_init(FAR AES_CMAC_CTX *ctx)
{
- memset(ctx->X, 0, sizeof ctx->X);
- ctx->M_n = 0;
+ memset(ctx->X, 0, sizeof ctx->X);
+ ctx->m_n = 0;
}
-void
-AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const u_int8_t key[AES_CMAC_KEY_LENGTH])
+void aes_cmac_setkey(FAR AES_CMAC_CTX *ctx,
+ FAR const uint8_t *key)
{
- AES_Setkey(&ctx->aesctx, key, 16);
+ aes_setkey(&ctx->aesctx, key, 16);
}
-void
-AES_CMAC_Update(AES_CMAC_CTX *ctx, const u_int8_t *data, u_int len)
+void aes_cmac_update(FAR AES_CMAC_CTX *ctx,
+ FAR const uint8_t *data,
+ u_int len)
{
- u_int mlen;
-
- if (ctx->M_n > 0) {
- mlen = MIN(16 - ctx->M_n, len);
- memcpy(ctx->M_last + ctx->M_n, data, mlen);
- ctx->M_n += mlen;
- if (ctx->M_n < 16 || len == mlen)
- return;
- XOR(ctx->M_last, ctx->X);
- AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X);
- data += mlen;
- len -= mlen;
- }
- while (len > 16) { /* not last block */
- XOR(data, ctx->X);
- AES_Encrypt(&ctx->aesctx, ctx->X, ctx->X);
- data += 16;
- len -= 16;
- }
- /* potential last block, save it */
- memcpy(ctx->M_last, data, len);
- ctx->M_n = len;
+ u_int mlen;
+
+ if (ctx->m_n > 0)
+ {
+ mlen = MIN(16 - ctx->m_n, len);
+ memcpy(ctx->m_last + ctx->m_n, data, mlen);
+ ctx->m_n += mlen;
+ if (ctx->m_n < 16 || len == mlen)
+ {
+ return;
+ }
+
+ XOR(ctx->m_last, ctx->X);
+ aes_encrypt(&ctx->aesctx, ctx->X, ctx->X);
+ data += mlen;
+ len -= mlen;
+ }
+
+ while (len > 16)
+ {
+ /* not last block */
+
+ XOR(data, ctx->X);
+ aes_encrypt(&ctx->aesctx, ctx->X, ctx->X);
+ data += 16;
+ len -= 16;
+ }
+
+ /* potential last block, save it */
+
+ memcpy(ctx->m_last, data, len);
+ ctx->m_n = len;
}
-void
-AES_CMAC_Final(u_int8_t digest[AES_CMAC_DIGEST_LENGTH], AES_CMAC_CTX *ctx)
+void aes_cmac_final(FAR uint8_t *digest,
+ FAR AES_CMAC_CTX *ctx)
{
- u_int8_t K[16];
-
- /* generate subkey K1 */
- memset(K, 0, sizeof K);
- AES_Encrypt(&ctx->aesctx, K, K);
-
- if (K[0] & 0x80) {
- LSHIFT(K, K);
- K[15] ^= 0x87;
- } else
- LSHIFT(K, K);
-
- if (ctx->M_n == 16) {
- /* last block was a complete block */
- XOR(K, ctx->M_last);
- } else {
- /* generate subkey K2 */
- if (K[0] & 0x80) {
- LSHIFT(K, K);
- K[15] ^= 0x87;
- } else
- LSHIFT(K, K);
-
- /* padding(M_last) */
- ctx->M_last[ctx->M_n] = 0x80;
- while (++ctx->M_n < 16)
- ctx->M_last[ctx->M_n] = 0;
-
- XOR(K, ctx->M_last);
- }
- XOR(ctx->M_last, ctx->X);
- AES_Encrypt(&ctx->aesctx, ctx->X, digest);
-
- explicit_bzero(K, sizeof K);
+ uint8_t K[16];
+
+ /* generate subkey K1 */
+
+ memset(K, 0, sizeof K);
+ aes_encrypt(&ctx->aesctx, K, K);
+
+ if (K[0] & 0x80)
+ {
+ LSHIFT(K, K);
+ K[15] ^= 0x87;
+ }
+ else
+ {
+ LSHIFT(K, K);
+ }
+
+ if (ctx->m_n == 16)
+ {
+ /* last block was a complete block */
+
+ XOR(K, ctx->m_last);
+ }
+ else
+ {
+ /* generate subkey K2 */
+
+ if (K[0] & 0x80)
+ {
+ LSHIFT(K, K);
+ K[15] ^= 0x87;
+ }
+ else
+ {
+ LSHIFT(K, K);
+ }
+
+ /* padding(m_last) */
+
+ ctx->m_last[ctx->m_n] = 0x80;
+ while (++ctx->m_n < 16)
+ {
+ ctx->m_last[ctx->m_n] = 0;
+ }
+
+ XOR(K, ctx->m_last);
+ }
+
+ XOR(ctx->m_last, ctx->X);
+ aes_encrypt(&ctx->aesctx, ctx->X, digest);
+
+ explicit_bzero(K, sizeof K);
}
diff --git a/crypto/crypto.c b/crypto/crypto.c
index f62752d278..5037f6718c 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -1,5 +1,7 @@
-/* $OpenBSD: crypto.c,v 1.65 2014/07/13 23:24:47 deraadt Exp $ */
-/*
+/****************************************************************************
+ * crypto/crypto.c
+ * $OpenBSD: crypto.c,v 1.65 2014/07/13 23:24:47 deraadt Exp $
+ *
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
*
* This code was written by Angelos D. Keromytis in Athens, Greece, in
@@ -18,7 +20,11 @@
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
* PURPOSE.
- */
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
@@ -28,636 +34,769 @@
#include <crypto/cryptodev.h>
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
void crypto_init(void);
-struct cryptocap *crypto_drivers = NULL;
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+FAR static struct cryptocap *crypto_drivers = NULL;
int crypto_drivers_num = 0;
struct pool cryptop_pool;
struct pool cryptodesc_pool;
-struct taskq *crypto_taskq;
+FAR struct taskq *crypto_taskq;
-/*
- * Create a new session.
- */
-int
-crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard)
+/* Create a new session. */
+
+int crypto_newsession(FAR uint64_t *sid,
+ FAR struct cryptoini *cri,
+ int hard)
{
- u_int32_t hid, lid, hid2 = -1;
- struct cryptocap *cpc;
- struct cryptoini *cr;
- int err, s, turn = 0;
-
- if (crypto_drivers == NULL)
- return EINVAL;
-
- s = splvm();
-
- /*
- * The algorithm we use here is pretty stupid; just use the
- * first driver that supports all the algorithms we need. Do
- * a double-pass over all the drivers, ignoring software ones
- * at first, to deal with cases of drivers that register after
- * the software one(s) --- e.g., PCMCIA crypto cards.
- *
- * XXX We need more smarts here (in real life too, but that's
- * XXX another story altogether).
- */
- do {
- for (hid = 0; hid < crypto_drivers_num; hid++) {
- cpc = &crypto_drivers[hid];
-
- /*
- * If it's not initialized or has remaining sessions
- * referencing it, skip.
- */
- if (cpc->cc_newsession == NULL ||
- (cpc->cc_flags & CRYPTOCAP_F_CLEANUP))
- continue;
-
- if (cpc->cc_flags & CRYPTOCAP_F_SOFTWARE) {
- /*
- * First round of search, ignore
- * software drivers.
- */
- if (turn == 0)
- continue;
- } else { /* !CRYPTOCAP_F_SOFTWARE */
- /* Second round of search, only software. */
- if (turn == 1)
- continue;
- }
-
- /* See if all the algorithms are supported. */
- for (cr = cri; cr; cr = cr->cri_next) {
- if (cpc->cc_alg[cr->cri_alg] == 0)
- break;
- }
-
- /*
- * If even one algorithm is not supported,
- * keep searching.
- */
- if (cr != NULL)
- continue;
-
- /*
- * If we had a previous match, see how it compares
- * to this one. Keep "remembering" whichever is
- * the best of the two.
- */
- if (hid2 != -1) {
- /*
- * Compare session numbers, pick the one
- * with the lowest.
- * XXX Need better metrics, this will
- * XXX just do un-weighted round-robin.
- */
- if (crypto_drivers[hid].cc_sessions <=
- crypto_drivers[hid2].cc_sessions)
- hid2 = hid;
- } else {
- /*
- * Remember this one, for future
- * comparisons.
- */
- hid2 = hid;
- }
- }
-
- /*
- * If we found something worth remembering, leave. The
- * side-effect is that we will always prefer a hardware
- * driver over the software one.
- */
- if (hid2 != -1)
- break;
-
- turn++;
-
- /* If we only want hardware drivers, don't do second pass. */
- } while (turn <= 2 && hard == 0);
-
- hid = hid2;
-
- /*
- * Can't do everything in one session.
- *
- * XXX Fix this. We need to inject a "virtual" session
- * XXX layer right about here.
- */
-
- if (hid == -1) {
- splx(s);
- return EINVAL;
- }
-
- /* Call the driver initialization routine. */
- lid = hid; /* Pass the driver ID. */
- err = crypto_drivers[hid].cc_newsession(&lid, cri);
- if (err == 0) {
- (*sid) = hid;
- (*sid) <<= 32;
- (*sid) |= (lid & 0xffffffff);
- crypto_drivers[hid].cc_sessions++;
- }
-
- splx(s);
- return err;
+ uint32_t hid;
+ uint32_t lid;
+ uint32_t hid2 = -1;
+ FAR struct cryptocap *cpc;
+ FAR struct cryptoini *cr;
+ int turn = 0;
+ int err;
+ int s;
+
+ if (crypto_drivers == NULL)
+ {
+ return EINVAL;
+ }
+
+ s = splvm();
+
+ /* The algorithm we use here is pretty stupid; just use the
+ * first driver that supports all the algorithms we need. Do
+ * a double-pass over all the drivers, ignoring software ones
+ * at first, to deal with cases of drivers that register after
+ * the software one(s) --- e.g., PCMCIA crypto cards.
+ *
+ * XXX We need more smarts here (in real life too, but that's
+ * XXX another story altogether).
+ */
+
+ do
+ {
+ for (hid = 0; hid < crypto_drivers_num; hid++)
+ {
+ cpc = &crypto_drivers[hid];
+
+ /* If it's not initialized or has remaining sessions
+ * referencing it, skip.
+ */
+
+ if (cpc->cc_newsession == NULL ||
+ (cpc->cc_flags & CRYPTOCAP_F_CLEANUP))
+ {
+ continue;
+ }
+
+ if (cpc->cc_flags & CRYPTOCAP_F_SOFTWARE)
+ {
+ /* First round of search, ignore
+ * software drivers.
+ */
+
+ if (turn == 0)
+ {
+ continue;
+ }
+ }
+ else
+ {
+ /* !CRYPTOCAP_F_SOFTWARE
+ * Second round of search, only software.
+ */
+
+ if (turn == 1)
+ {
+ continue;
+ }
+ }
+
+ /* See if all the algorithms are supported. */
+
+ for (cr = cri; cr; cr = cr->cri_next)
+ {
+ if (cpc->cc_alg[cr->cri_alg] == 0)
+ {
+ break;
+ }
+ }
+
+ /* If even one algorithm is not supported,
+ * keep searching.
+ */
+
+ if (cr != NULL)
+ {
+ continue;
+ }
+
+ /* If we had a previous match, see how it compares
+ * to this one. Keep "remembering" whichever is
+ * the best of the two.
+ */
+
+ if (hid2 != -1)
+ {
+ /* Compare session numbers, pick the one
+ * with the lowest.
+ * XXX Need better metrics, this will
+ * XXX just do un-weighted round-robin.
+ */
+
+ if (crypto_drivers[hid].cc_sessions <=
+ crypto_drivers[hid2].cc_sessions)
+ {
+ hid2 = hid;
+ }
+ }
+ else
+ {
+ /* Remember this one, for future
+ * comparisons.
+ */
+
+ hid2 = hid;
+ }
+ }
+
+ /* If we found something worth remembering, leave. The
+ * side-effect is that we will always prefer a hardware
+ * driver over the software one.
+ */
+
+ if (hid2 != -1)
+ {
+ break;
+ }
+
+ turn++;
+
+ /* If we only want hardware drivers, don't do second pass. */
+ }
+ while (turn <= 2 && hard == 0);
+
+ hid = hid2;
+
+ /* Can't do everything in one session.
+ * XXX Fix this. We need to inject a "virtual" session
+ * XXX layer right about here.
+ */
+
+ if (hid == -1)
+ {
+ splx(s);
+ return EINVAL;
+ }
+
+ /* Call the driver initialization routine. */
+
+ lid = hid; /* Pass the driver ID. */
+ err = crypto_drivers[hid].cc_newsession(&lid, cri);
+ if (err == 0)
+ {
+ *sid = hid;
+ *sid <<= 32;
+ *sid |= (lid & 0xffffffff);
+ crypto_drivers[hid].cc_sessions++;
+ }
+
+ splx(s);
+ return err;
}
-/*
- * Delete an existing session (or a reserved session on an unregistered
+/* Delete an existing session (or a reserved session on an unregistered
* driver).
*/
-int
-crypto_freesession(u_int64_t sid)
+
+int crypto_freesession(uint64_t sid)
{
- int err = 0, s;
- u_int32_t hid;
+ int err = 0;
+ int s;
+ uint32_t hid;
- if (crypto_drivers == NULL)
- return EINVAL;
+ if (crypto_drivers == NULL)
+ {
+ return EINVAL;
+ }
- /* Determine two IDs. */
- hid = (sid >> 32) & 0xffffffff;
+ /* Determine two IDs. */
- if (hid >= crypto_drivers_num)
- return ENOENT;
+ hid = (sid >> 32) & 0xffffffff;
- s = splvm();
+ if (hid >= crypto_drivers_num)
+ {
+ return ENOENT;
+ }
- if (crypto_drivers[hid].cc_sessions)
- crypto_drivers[hid].cc_sessions--;
+ s = splvm();
- /* Call the driver cleanup routine, if available. */
- if (crypto_drivers[hid].cc_freesession)
- err = crypto_drivers[hid].cc_freesession(sid);
+ if (crypto_drivers[hid].cc_sessions)
+ {
+ crypto_drivers[hid].cc_sessions--;
+ }
- /*
- * If this was the last session of a driver marked as invalid,
- * make the entry available for reuse.
- */
- if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) &&
- crypto_drivers[hid].cc_sessions == 0)
- explicit_bzero(&crypto_drivers[hid], sizeof(struct cryptocap));
+ /* Call the driver cleanup routine, if available. */
- splx(s);
- return err;
+ if (crypto_drivers[hid].cc_freesession)
+ {
+ err = crypto_drivers[hid].cc_freesession(sid);
+ }
+
+ /* If this was the last session of a driver marked as invalid,
+ * make the entry available for reuse.
+ */
+
+ if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) &&
+ crypto_drivers[hid].cc_sessions == 0)
+ {
+ explicit_bzero(&crypto_drivers[hid], sizeof(struct cryptocap));
+ }
+
+ splx(s);
+ return err;
}
-/*
- * Find an empty slot.
- */
-int32_t
-crypto_get_driverid(u_int8_t flags)
+/* Find an empty slot. */
+
+int crypto_get_driverid(uint8_t flags)
{
- struct cryptocap *newdrv;
- int i, s;
-
- s = splvm();
-
- if (crypto_drivers_num == 0) {
- crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
- crypto_drivers = mallocarray(crypto_drivers_num,
- sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT);
- if (crypto_drivers == NULL) {
- crypto_drivers_num = 0;
- splx(s);
- return -1;
- }
-
- bzero(crypto_drivers, crypto_drivers_num *
- sizeof(struct cryptocap));
- }
-
- for (i = 0; i < crypto_drivers_num; i++) {
- if (crypto_drivers[i].cc_process == NULL &&
- !(crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) &&
- crypto_drivers[i].cc_sessions == 0) {
- crypto_drivers[i].cc_sessions = 1; /* Mark */
- crypto_drivers[i].cc_flags = flags;
- splx(s);
- return i;
- }
- }
-
- /* Out of entries, allocate some more. */
- if (i == crypto_drivers_num) {
- if (crypto_drivers_num >= CRYPTO_DRIVERS_MAX) {
- splx(s);
- return -1;
- }
-
- newdrv = mallocarray(crypto_drivers_num,
- 2 * sizeof(struct cryptocap), M_CRYPTO_DATA, M_NOWAIT);
- if (newdrv == NULL) {
- splx(s);
- return -1;
- }
-
- bcopy(crypto_drivers, newdrv,
- crypto_drivers_num * sizeof(struct cryptocap));
- bzero(&newdrv[crypto_drivers_num],
- crypto_drivers_num * sizeof(struct cryptocap));
-
- newdrv[i].cc_sessions = 1; /* Mark */
- newdrv[i].cc_flags = flags;
- crypto_drivers_num *= 2;
-
- free(crypto_drivers, M_CRYPTO_DATA, 0);
- crypto_drivers = newdrv;
- splx(s);
- return i;
- }
-
- /* Shouldn't really get here... */
- splx(s);
- return -1;
+ FAR struct cryptocap *newdrv;
+ int i;
+ int s;
+
+ s = splvm();
+
+ if (crypto_drivers_num == 0)
+ {
+ crypto_drivers_num = CRYPTO_DRIVERS_INITIAL;
+ crypto_drivers = mallocarray(crypto_drivers_num,
+ sizeof(struct cryptocap),
+ M_CRYPTO_DATA, M_NOWAIT);
+ if (crypto_drivers == NULL)
+ {
+ crypto_drivers_num = 0;
+ splx(s);
+ return -1;
+ }
+
+ bzero(crypto_drivers, crypto_drivers_num *
+ sizeof(struct cryptocap));
+ }
+
+ for (i = 0; i < crypto_drivers_num; i++)
+ {
+ if (crypto_drivers[i].cc_process == NULL &&
+ !(crypto_drivers[i].cc_flags & CRYPTOCAP_F_CLEANUP) &&
+ crypto_drivers[i].cc_sessions == 0)
+ {
+ crypto_drivers[i].cc_sessions = 1; /* Mark */
+ crypto_drivers[i].cc_flags = flags;
+ splx(s);
+ return i;
+ }
+ }
+
+ /* Out of entries, allocate some more. */
+
+ if (i == crypto_drivers_num)
+ {
+ if (crypto_drivers_num >= CRYPTO_DRIVERS_MAX)
+ {
+ splx(s);
+ return -1;
+ }
+
+ newdrv = mallocarray(crypto_drivers_num,
+ 2 * sizeof(struct cryptocap),
+ M_CRYPTO_DATA, M_NOWAIT);
+ if (newdrv == NULL)
+ {
+ splx(s);
+ return -1;
+ }
+
+ bcopy(crypto_drivers, newdrv,
+ crypto_drivers_num * sizeof(struct cryptocap));
+ bzero(&newdrv[crypto_drivers_num],
+ crypto_drivers_num * sizeof(struct cryptocap));
+
+ newdrv[i].cc_sessions = 1; /* Mark */
+ newdrv[i].cc_flags = flags;
+ crypto_drivers_num *= 2;
+
+ free(crypto_drivers, M_CRYPTO_DATA, 0);
+ crypto_drivers = newdrv;
+ splx(s);
+ return i;
+ }
+
+ /* Shouldn't really get here... */
+
+ splx(s);
+ return -1;
}
-/*
- * Register a crypto driver. It should be called once for each algorithm
+/* Register a crypto driver. It should be called once for each algorithm
* supported by the driver.
*/
-int
-crypto_kregister(u_int32_t driverid, int *kalg,
- int (*kprocess)(struct cryptkop *))
+
+int crypto_kregister(uint32_t driverid, FAR int *kalg,
+ CODE int (*kprocess)(FAR struct cryptkop *))
{
- int s, i;
+ int s;
+ int i;
- if (driverid >= crypto_drivers_num || kalg == NULL ||
- crypto_drivers == NULL)
- return EINVAL;
+ if (driverid >= crypto_drivers_num || kalg == NULL ||
+ crypto_drivers == NULL)
+ {
+ return EINVAL;
+ }
- s = splvm();
+ s = splvm();
- for (i = 0; i <= CRK_ALGORITHM_MAX; i++) {
- /*
- * XXX Do some performance testing to determine
- * placing. We probably need an auxiliary data
- * structure that describes relative performances.
- */
+ for (i = 0; i <= CRK_ALGORITHM_MAX; i++)
+ {
+ /* XXX Do some performance testing to determine
+ * placing. We probably need an auxiliary data
+ * structure that describes relative performances.
+ */
- crypto_drivers[driverid].cc_kalg[i] = kalg[i];
- }
+ crypto_drivers[driverid].cc_kalg[i] = kalg[i];
+ }
- crypto_drivers[driverid].cc_kprocess = kprocess;
+ crypto_drivers[driverid].cc_kprocess = kprocess;
- splx(s);
- return 0;
+ splx(s);
+ return 0;
}
/* Register a crypto driver. */
-int
-crypto_register(u_int32_t driverid, int *alg,
- int (*newses)(u_int32_t *, struct cryptoini *),
- int (*freeses)(u_int64_t), int (*process)(struct cryptop *))
-{
- int s, i;
+int crypto_register(uint32_t driverid, FAR int *alg,
+ CODE int (*newses)(FAR uint32_t *,
+ FAR struct cryptoini *),
+ CODE int (*freeses)(uint64_t),
+ CODE int (*process)(FAR struct cryptop *))
+{
+ int s;
+ int i;
- if (driverid >= crypto_drivers_num || alg == NULL ||
- crypto_drivers == NULL)
- return EINVAL;
-
- s = splvm();
+ if (driverid >= crypto_drivers_num || alg == NULL ||
+ crypto_drivers == NULL)
+ {
+ return EINVAL;
+ }
- for (i = 0; i <= CRYPTO_ALGORITHM_MAX; i++) {
- /*
- * XXX Do some performance testing to determine
- * placing. We probably need an auxiliary data
- * structure that describes relative performances.
- */
+ s = splvm();
- crypto_drivers[driverid].cc_alg[i] = alg[i];
- }
+ for (i = 0; i <= CRYPTO_ALGORITHM_MAX; i++)
+ {
+ /* XXX Do some performance testing to determine
+ * placing. We probably need an auxiliary data
+ * structure that describes relative performances.
+ */
+ crypto_drivers[driverid].cc_alg[i] = alg[i];
+ }
- crypto_drivers[driverid].cc_newsession = newses;
- crypto_drivers[driverid].cc_process = process;
- crypto_drivers[driverid].cc_freesession = freeses;
- crypto_drivers[driverid].cc_sessions = 0; /* Unmark */
+ crypto_drivers[driverid].cc_newsession = newses;
+ crypto_drivers[driverid].cc_process = process;
+ crypto_drivers[driverid].cc_freesession = freeses;
+ crypto_drivers[driverid].cc_sessions = 0; /* Unmark */
- splx(s);
+ splx(s);
- return 0;
+ return 0;
}
-/*
- * Unregister a crypto driver. If there are pending sessions using it,
+/* Unregister a crypto driver. If there are pending sessions using it,
* leave enough information around so that subsequent calls using those
* sessions will correctly detect the driver being unregistered and reroute
* the request.
*/
-int
-crypto_unregister(u_int32_t driverid, int alg)
+
+int crypto_unregister(uint32_t driverid, int alg)
{
- int i = CRYPTO_ALGORITHM_MAX + 1, s;
- u_int32_t ses;
-
- s = splvm();
-
- /* Sanity checks. */
- if (driverid >= crypto_drivers_num || crypto_drivers == NULL ||
- ((alg <= 0 || alg > CRYPTO_ALGORITHM_MAX) &&
- alg != CRYPTO_ALGORITHM_MAX + 1) ||
- crypto_drivers[driverid].cc_alg[alg] == 0) {
- splx(s);
- return EINVAL;
- }
-
- if (alg != CRYPTO_ALGORITHM_MAX + 1) {
- crypto_drivers[driverid].cc_alg[alg] = 0;
-
- /* Was this the last algorithm ? */
- for (i = 1; i <= CRYPTO_ALGORITHM_MAX; i++)
- if (crypto_drivers[driverid].cc_alg[i] != 0)
- break;
- }
-
- /*
- * If a driver unregistered its last algorithm or all of them
- * (alg == CRYPTO_ALGORITHM_MAX + 1), cleanup its entry.
- */
- if (i == CRYPTO_ALGORITHM_MAX + 1 || alg == CRYPTO_ALGORITHM_MAX + 1) {
- ses = crypto_drivers[driverid].cc_sessions;
- bzero(&crypto_drivers[driverid], sizeof(struct cryptocap));
- if (ses != 0) {
- /*
- * If there are pending sessions, just mark as invalid.
- */
- crypto_drivers[driverid].cc_flags |= CRYPTOCAP_F_CLEANUP;
- crypto_drivers[driverid].cc_sessions = ses;
- }
- }
- splx(s);
- return 0;
+ int i = CRYPTO_ALGORITHM_MAX + 1;
+ int s;
+ uint32_t ses;
+
+ s = splvm();
+
+ /* Sanity checks. */
+
+ if (driverid >= crypto_drivers_num || crypto_drivers == NULL ||
+ ((alg <= 0 || alg > CRYPTO_ALGORITHM_MAX) &&
+ alg != CRYPTO_ALGORITHM_MAX + 1) ||
+ crypto_drivers[driverid].cc_alg[alg] == 0)
+ {
+ splx(s);
+ return EINVAL;
+ }
+
+ if (alg != CRYPTO_ALGORITHM_MAX + 1)
+ {
+ crypto_drivers[driverid].cc_alg[alg] = 0;
+
+ /* Was this the last algorithm ? */
+
+ for (i = 1; i <= CRYPTO_ALGORITHM_MAX; i++)
+ {
+ if (crypto_drivers[driverid].cc_alg[i] != 0)
+ {
+ break;
+ }
+ }
+ }
+
+ /* If a driver unregistered its last algorithm or all of them
+ * (alg == CRYPTO_ALGORITHM_MAX + 1), cleanup its entry.
+ */
+
+ if (i == CRYPTO_ALGORITHM_MAX + 1 || alg == CRYPTO_ALGORITHM_MAX + 1)
+ {
+ ses = crypto_drivers[driverid].cc_sessions;
+ bzero(&crypto_drivers[driverid], sizeof(struct cryptocap));
+ if (ses != 0)
+ {
+ /* If there are pending sessions, just mark as invalid. */
+
+ crypto_drivers[driverid].cc_flags |= CRYPTOCAP_F_CLEANUP;
+ crypto_drivers[driverid].cc_sessions = ses;
+ }
+ }
+
+ splx(s);
+ return 0;
}
-/*
- * Add crypto request to a queue, to be processed by a kernel thread.
- */
-int
-crypto_dispatch(struct cryptop *crp)
+/* Add crypto request to a queue, to be processed by a kernel thread. */
+
+int crypto_dispatch(FAR struct cryptop *crp)
{
- if (crypto_taskq && !(crp->crp_flags & CRYPTO_F_NOQUEUE)) {
- task_set(&crp->crp_task, (void (*))crypto_invoke, crp, NULL);
- task_add(crypto_taskq, &crp->crp_task);
- } else {
- crypto_invoke(crp);
- }
-
- return 0;
+ if (crypto_taskq && !(crp->crp_flags & CRYPTO_F_NOQUEUE))
+ {
+ task_set(&crp->crp_task, (void (*))crypto_invoke, crp, NULL);
+ task_add(crypto_taskq, &crp->crp_task);
+ }
+ else
+ {
+ crypto_invoke(crp);
+ }
+
+ return 0;
}
-int
-crypto_kdispatch(struct cryptkop *krp)
+int crypto_kdispatch(FAR struct cryptkop *krp)
{
- if (crypto_taskq) {
- task_set(&krp->krp_task, (void (*))crypto_kinvoke, krp, NULL);
- task_add(crypto_taskq, &krp->krp_task);
- } else {
- crypto_kinvoke(krp);
- }
-
- return 0;
+ if (crypto_taskq)
+ {
+ task_set(&krp->krp_task, (void (*))crypto_kinvoke, krp, NULL);
+ task_add(crypto_taskq, &krp->krp_task);
+ }
+ else
+ {
+ crypto_kinvoke(krp);
+ }
+
+ return 0;
}
-/*
- * Dispatch an asymmetric crypto request to the appropriate crypto devices.
- */
-int
-crypto_kinvoke(struct cryptkop *krp)
+/* Dispatch an asymmetric crypto request to the appropriate crypto devices. */
+
+int crypto_kinvoke(FAR struct cryptkop *krp)
{
- extern int cryptodevallowsoft;
- u_int32_t hid;
- int error;
- int s;
-
- /* Sanity checks. */
- if (krp == NULL || krp->krp_callback == NULL)
- return (EINVAL);
-
- s = splvm();
- for (hid = 0; hid < crypto_drivers_num; hid++) {
- if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
- cryptodevallowsoft == 0)
- continue;
- if (crypto_drivers[hid].cc_kprocess == NULL)
- continue;
- if ((crypto_drivers[hid].cc_kalg[krp->krp_op] &
- CRYPTO_ALG_FLAG_SUPPORTED) == 0)
- continue;
- break;
- }
-
- if (hid == crypto_drivers_num) {
- krp->krp_status = ENODEV;
- crypto_kdone(krp);
- splx(s);
- return (0);
- }
-
- krp->krp_hid = hid;
-
- crypto_drivers[hid].cc_koperations++;
-
- error = crypto_drivers[hid].cc_kprocess(krp);
- if (error) {
- krp->krp_status = error;
- crypto_kdone(krp);
- }
- splx(s);
- return (0);
+ extern int cryptodevallowsoft;
+ uint32_t hid;
+ int error;
+ int s;
+
+ /* Sanity checks. */
+
+ if (krp == NULL || krp->krp_callback == NULL)
+ {
+ return EINVAL;
+ }
+
+ s = splvm();
+ for (hid = 0; hid < crypto_drivers_num; hid++)
+ {
+ if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
+ cryptodevallowsoft == 0)
+ {
+ continue;
+ }
+
+ if (crypto_drivers[hid].cc_kprocess == NULL)
+ {
+ continue;
+ }
+
+ if ((crypto_drivers[hid].cc_kalg[krp->krp_op] &
+ CRYPTO_ALG_FLAG_SUPPORTED) == 0)
+ {
+ continue;
+ }
+
+ break;
+ }
+
+ if (hid == crypto_drivers_num)
+ {
+ krp->krp_status = ENODEV;
+ crypto_kdone(krp);
+ splx(s);
+ return 0;
+ }
+
+ krp->krp_hid = hid;
+
+ crypto_drivers[hid].cc_koperations++;
+
+ error = crypto_drivers[hid].cc_kprocess(krp);
+ if (error)
+ {
+ krp->krp_status = error;
+ crypto_kdone(krp);
+ }
+
+ splx(s);
+ return 0;
}
-/*
- * Dispatch a crypto request to the appropriate crypto devices.
- */
-int
-crypto_invoke(struct cryptop *crp)
+/* Dispatch a crypto request to the appropriate crypto devices. */
+
+int crypto_invoke(FAR struct cryptop *crp)
{
- struct cryptodesc *crd;
- u_int64_t nid;
- u_int32_t hid;
- int error;
- int s;
-
- /* Sanity checks. */
- if (crp == NULL || crp->crp_callback == NULL)
- return EINVAL;
-
- s = splvm();
- if (crp->crp_desc == NULL || crypto_drivers == NULL) {
- crp->crp_etype = EINVAL;
- crypto_done(crp);
- splx(s);
- return 0;
- }
-
- hid = (crp->crp_sid >> 32) & 0xffffffff;
- if (hid >= crypto_drivers_num)
- goto migrate;
-
- if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP) {
- crypto_freesession(crp->crp_sid);
- goto migrate;
- }
-
- if (crypto_drivers[hid].cc_process == NULL)
- goto migrate;
-
- crypto_drivers[hid].cc_operations++;
- crypto_drivers[hid].cc_bytes += crp->crp_ilen;
-
- error = crypto_drivers[hid].cc_process(crp);
- if (error) {
- if (error == ERESTART) {
- /* Unregister driver and migrate session. */
- crypto_unregister(hid, CRYPTO_ALGORITHM_MAX + 1);
- goto migrate;
- } else {
- crp->crp_etype = error;
- }
- }
-
- splx(s);
- return 0;
-
- migrate:
- /* Migrate session. */
- for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
- crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
-
- if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI), 0) == 0)
- crp->crp_sid = nid;
-
- crp->crp_etype = EAGAIN;
- crypto_done(crp);
- splx(s);
- return 0;
+ FAR struct cryptodesc *crd;
+ uint64_t nid;
+ uint32_t hid;
+ int error;
+ int s;
+
+ /* Sanity checks. */
+
+ if (crp == NULL || crp->crp_callback == NULL)
+ {
+ return EINVAL;
+ }
+
+ s = splvm();
+ if (crp->crp_desc == NULL || crypto_drivers == NULL)
+ {
+ crp->crp_etype = EINVAL;
+ crypto_done(crp);
+ splx(s);
+ return 0;
+ }
+
+ hid = (crp->crp_sid >> 32) & 0xffffffff;
+ if (hid >= crypto_drivers_num)
+ {
+ goto migrate;
+ }
+
+ if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_CLEANUP)
+ {
+ crypto_freesession(crp->crp_sid);
+ goto migrate;
+ }
+
+ if (crypto_drivers[hid].cc_process == NULL)
+ {
+ goto migrate;
+ }
+
+ crypto_drivers[hid].cc_operations++;
+ crypto_drivers[hid].cc_bytes += crp->crp_ilen;
+
+ error = crypto_drivers[hid].cc_process(crp);
+ if (error)
+ {
+ if (error == ERESTART)
+ {
+ /* Unregister driver and migrate session. */
+
+ crypto_unregister(hid, CRYPTO_ALGORITHM_MAX + 1);
+ goto migrate;
+ }
+ else
+ {
+ crp->crp_etype = error;
+ }
+ }
+
+ splx(s);
+ return 0;
+
+migrate:
+
+ /* Migrate session. */
+
+ for (crd = crp->crp_desc; crd->crd_next; crd = crd->crd_next)
+ {
+ crd->CRD_INI.cri_next = &(crd->crd_next->CRD_INI);
+ }
+
+ if (crypto_newsession(&nid, &(crp->crp_desc->CRD_INI), 0) == 0)
+ {
+ crp->crp_sid = nid;
+ }
+
+ crp->crp_etype = EAGAIN;
+ crypto_done(crp);
+ splx(s);
+ return 0;
}
-/*
- * Release a set of crypto descriptors.
- */
-void
-crypto_freereq(struct cryptop *crp)
+/* Release a set of crypto descriptors. */
+
+void crypto_freereq(FAR struct cryptop *crp)
{
- struct cryptodesc *crd;
- int s;
+ FAR struct cryptodesc *crd;
+ int s;
- if (crp == NULL)
- return;
+ if (crp == NULL)
+ {
+ return;
+ }
- s = splvm();
+ s = splvm();
- while ((crd = crp->crp_desc) != NULL) {
- crp->crp_desc = crd->crd_next;
- pool_put(&cryptodesc_pool, crd);
- }
+ while ((crd = crp->crp_desc) != NULL)
+ {
+ crp->crp_desc = crd->crd_next;
+ pool_put(&cryptodesc_pool, crd);
+ }
- pool_put(&cryptop_pool, crp);
- splx(s);
+ pool_put(&cryptop_pool, crp);
+ splx(s);
}
-/*
- * Acquire a set of crypto descriptors.
- */
-struct cryptop *
-crypto_getreq(int num)
+/* Acquire a set of crypto descriptors. */
+
+FAR struct cryptop *crypto_getreq(int num)
{
- struct cryptodesc *crd;
- struct cryptop *crp;
- int s;
-
- s = splvm();
-
- crp = pool_get(&cryptop_pool, PR_NOWAIT);
- if (crp == NULL) {
- splx(s);
- return NULL;
- }
- bzero(crp, sizeof(struct cryptop));
-
- while (num--) {
- crd = pool_get(&cryptodesc_pool, PR_NOWAIT);
- if (crd == NULL) {
- splx(s);
- crypto_freereq(crp);
- return NULL;
- }
-
- bzero(crd, sizeof(struct cryptodesc));
- crd->crd_next = crp->crp_desc;
- crp->crp_desc = crd;
- }
-
- splx(s);
- return crp;
+ FAR struct cryptodesc *crd;
+ FAR struct cryptop *crp;
+ int s;
+
+ s = splvm();
+
+ crp = pool_get(&cryptop_pool, PR_NOWAIT);
+ if (crp == NULL)
+ {
+ splx(s);
+ return NULL;
+ }
+
+ bzero(crp, sizeof(struct cryptop));
+
+ while (num--)
+ {
+ crd = pool_get(&cryptodesc_pool, PR_NOWAIT);
+ if (crd == NULL)
+ {
+ splx(s);
+ crypto_freereq(crp);
+ return NULL;
+ }
+
+ bzero(crd, sizeof(struct cryptodesc));
+ crd->crd_next = crp->crp_desc;
+ crp->crp_desc = crd;
+ }
+
+ splx(s);
+ return crp;
}
-void
-crypto_init(void)
+void crypto_init(void)
{
- crypto_taskq = taskq_create("crypto", 1, IPL_HIGH);
+ crypto_taskq = taskq_create("crypto", 1, IPL_HIGH);
- pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0,
- 0, "cryptop", NULL);
- pool_init(&cryptodesc_pool, sizeof(struct cryptodesc), 0, 0,
- 0, "cryptodesc", NULL);
+ pool_init(&cryptop_pool, sizeof(struct cryptop), 0, 0,
+ 0, "cryptop", NULL);
+ pool_init(&cryptodesc_pool, sizeof(struct cryptodesc), 0, 0,
+ 0, "cryptodesc", NULL);
}
-/*
- * Invoke the callback on behalf of the driver.
- */
-void
-crypto_done(struct cryptop *crp)
+/* Invoke the callback on behalf of the driver. */
+
+void crypto_done(FAR struct cryptop *crp)
{
- crp->crp_flags |= CRYPTO_F_DONE;
- if (crp->crp_flags & CRYPTO_F_NOQUEUE) {
- /* not from the crypto queue, wakeup the userland process */
- crp->crp_callback(crp);
- } else {
- task_set(&crp->crp_task, (void (*))crp->crp_callback,
- crp, NULL);
- task_add(crypto_taskq, &crp->crp_task);
- }
+ crp->crp_flags |= CRYPTO_F_DONE;
+ if (crp->crp_flags & CRYPTO_F_NOQUEUE)
+ {
+ /* not from the crypto queue, wakeup the userland process */
+
+ crp->crp_callback(crp);
+ }
+ else
+ {
+ task_set(&crp->crp_task, (void (*))crp->crp_callback,
+ crp, NULL);
+ task_add(crypto_taskq, &crp->crp_task);
+ }
}
-/*
- * Invoke the callback on behalf of the driver.
- */
-void
-crypto_kdone(struct cryptkop *krp)
+/* Invoke the callback on behalf of the driver. */
+
+void crypto_kdone(FAR struct cryptkop *krp)
{
- task_set(&krp->krp_task, (void (*))krp->krp_callback, krp, NULL);
- task_add(crypto_taskq, &krp->krp_task);
+ task_set(&krp->krp_task, (void (*))krp->krp_callback, krp, NULL);
+ task_add(crypto_taskq, &krp->krp_task);
}
-int
-crypto_getfeat(int *featp)
+int crypto_getfeat(FAR int *featp)
{
- extern int cryptodevallowsoft, userasymcrypto;
- int hid, kalg, feat = 0;
-
- if (userasymcrypto == 0)
- goto out;
- for (hid = 0; hid < crypto_drivers_num; hid++) {
- if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
- cryptodevallowsoft == 0) {
- continue;
- }
- if (crypto_drivers[hid].cc_kprocess == NULL)
- continue;
- for (kalg = 0; kalg <= CRK_ALGORITHM_MAX; kalg++)
- if ((crypto_drivers[hid].cc_kalg[kalg] &
- CRYPTO_ALG_FLAG_SUPPORTED) != 0)
- feat |= 1 << kalg;
- }
+ extern int cryptodevallowsoft;
+ extern int userasymcrypto;
+ int hid;
+ int kalg;
+ int feat = 0;
+
+ if (userasymcrypto == 0)
+ {
+ goto out;
+ }
+
+ for (hid = 0; hid < crypto_drivers_num; hid++)
+ {
+ if ((crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE) &&
+ cryptodevallowsoft == 0)
+ {
+ continue;
+ }
+
+ if (crypto_drivers[hid].cc_kprocess == NULL)
+ {
+ continue;
+ }
+
+ for (kalg = 0; kalg <= CRK_ALGORITHM_MAX; kalg++)
+ {
+ if ((crypto_drivers[hid].cc_kalg[kalg] &
+ CRYPTO_ALG_FLAG_SUPPORTED) != 0)
+ {
+ feat |= 1 << kalg;
+ }
+ }
+ }
+
out:
- *featp = feat;
- return (0);
+ *featp = feat;
+ return 0;
}
diff --git a/crypto/cryptodev.c b/crypto/cryptodev.c
index 7b9f27c7bb..db55eeac0a 100644
--- a/crypto/cryptodev.c
+++ b/crypto/cryptodev.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: cryptodev.c,v 1.82 2014/08/18 05:11:03 dlg Exp $ */
-
-/*
+/****************************************************************************
+ * crypto/cryptodev.c
+ * $OpenBSD: cryptodev.c,v 1.82 2014/08/18 05:11:03 dlg Exp $
* Copyright (c) 2001 Theo de Raadt
*
* Redistribution and use in source and binary forms, with or without
@@ -27,8 +27,11 @@
* Effort sponsored in part by the Defense Advanced Research Projects
* Agency (DARPA) and Air Force Research Laboratory, Air Force
* Materiel Command, USAF, under agreement number F30602-01-2-0537.
- *
- */
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
@@ -50,711 +53,885 @@
#include <crypto/cryptodev.h>
#include <crypto/xform.h>
-extern struct cryptocap *crypto_drivers;
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern FAR struct cryptocap *crypto_drivers;
extern int crypto_drivers_num;
+int usercrypto = 0; /* userland may do crypto requests */
+int userasymcrypto = 0; /* userland may do asymmetric crypto reqs */
+int cryptodevallowsoft = 0; /* only use hardware crypto */
-struct csession {
- TAILQ_ENTRY(csession) next;
- u_int64_t sid;
- u_int32_t ses;
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct csession
+{
+ TAILQ_ENTRY(csession) next;
+ uint64_t sid;
+ uint32_t ses;
+
+ uint32_t cipher;
+ FAR const struct enc_xform *txform;
+ uint32_t mac;
+ FAR const struct auth_hash *thash;
+
+ caddr_t key;
+ int keylen;
+ u_char tmp_iv[EALG_MAX_BLOCK_LEN];
+
+ caddr_t mackey;
+ int mackeylen;
+ struct iovec iovec[IOV_MAX];
+ struct uio uio;
+ int error;
+};
- u_int32_t cipher;
- const struct enc_xform *txform;
- u_int32_t mac;
- const struct auth_hash *thash;
+struct fcrypt
+{
+ TAILQ_HEAD(csessionlist, csession) csessions;
+ int sesn;
+};
- caddr_t key;
- int keylen;
- u_char tmp_iv[EALG_MAX_BLOCK_LEN];
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
- caddr_t mackey;
- int mackeylen;
- u_char tmp_mac[CRYPTO_MAX_MAC_LEN];
+void cryptoattach(int);
- struct iovec iovec[IOV_MAX];
- struct uio uio;
- int error;
-};
+int cryptof_read(FAR struct file *, FAR off_t *,
+ FAR struct uio *, FAR struct ucred *);
+int cryptof_write(FAR struct file *, FAR off_t *,
+ FAR struct uio *, FAR struct ucred *);
+int cryptof_ioctl(FAR struct file *, u_long, caddr_t, FAR struct proc *p);
+int cryptof_poll(FAR struct file *, int, FAR struct proc *);
+int cryptof_kqfilter(FAR struct file *, FAR struct knote *);
+int cryptof_stat(FAR struct file *, FAR struct stat *, FAR struct proc *);
+int cryptof_close(FAR struct file *, FAR struct proc *);
-struct fcrypt {
- TAILQ_HEAD(csessionlist, csession) csessions;
- int sesn;
-};
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
-void cryptoattach(int);
-
-int cryptof_read(struct file *, off_t *, struct uio *, struct ucred *);
-int cryptof_write(struct file *, off_t *, struct uio *, struct ucred *);
-int cryptof_ioctl(struct file *, u_long, caddr_t, struct proc *p);
-int cryptof_poll(struct file *, int, struct proc *);
-int cryptof_kqfilter(struct file *, struct knote *);
-int cryptof_stat(struct file *, struct stat *, struct proc *);
-int cryptof_close(struct file *, struct proc *);
-
-static struct fileops cryptofops = {
- cryptof_read,
- cryptof_write,
- cryptof_ioctl,
- cryptof_poll,
- cryptof_kqfilter,
- cryptof_stat,
- cryptof_close
+static struct fileops g_cryptofops =
+{
+ cryptof_read,
+ cryptof_write,
+ cryptof_ioctl,
+ cryptof_poll,
+ cryptof_kqfilter,
+ cryptof_stat,
+ cryptof_close
};
-struct csession *csefind(struct fcrypt *, u_int);
-int csedelete(struct fcrypt *, struct csession *);
-struct csession *cseadd(struct fcrypt *, struct csession *);
-struct csession *csecreate(struct fcrypt *, u_int64_t, caddr_t, u_int64_t,
- caddr_t, u_int64_t, u_int32_t, u_int32_t, const struct enc_xform *,
- const struct auth_hash *);
-int csefree(struct csession *);
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
-int cryptodev_op(struct csession *, struct crypt_op *, struct proc *);
-int cryptodev_key(struct crypt_kop *);
-int cryptodev_dokey(struct crypt_kop *kop, struct crparam kvp[]);
+FAR struct csession *csefind(FAR struct fcrypt *, u_int);
+int csedelete(FAR struct fcrypt *, FAR struct csession *);
+FAR struct csession *cseadd(FAR struct fcrypt *, FAR struct csession *);
+FAR struct csession *csecreate(FAR struct fcrypt *, uint64_t,
+ caddr_t, uint64_t,
+ caddr_t, uint64_t, uint32_t,
+ uint32_t, FAR const struct enc_xform *,
+ FAR const struct auth_hash *);
+int csefree(FAR struct csession *);
-int cryptodev_cb(struct cryptop *);
-int cryptodevkey_cb(struct cryptkop *);
+int cryptodev_op(FAR struct csession *,
+ FAR struct crypt_op *, FAR struct proc *);
+int cryptodev_key(FAR struct crypt_kop *);
+int cryptodev_dokey(FAR struct crypt_kop *kop, FAR struct crparam *kvp);
-int usercrypto = 0; /* userland may do crypto requests */
-int userasymcrypto = 0; /* userland may do asymmetric crypto reqs */
-int cryptodevallowsoft = 0; /* only use hardware crypto */
+int cryptodev_cb(FAR struct cryptop *);
+int cryptodevkey_cb(FAR struct cryptkop *);
/* ARGSUSED */
-int
-cryptof_read(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred)
+
+int cryptof_read(FAR struct file *fp, FAR off_t *poff,
+ FAR struct uio *uio, FAR struct ucred *cred)
{
- return (EIO);
+ return EIO;
}
/* ARGSUSED */
-int
-cryptof_write(struct file *fp, off_t *poff, struct uio *uio, struct ucred *cred)
+
+int cryptof_write(FAR struct file *fp, FAR off_t *poff,
+ FAR struct uio *uio, FAR struct ucred *cred)
{
- return (EIO);
+ return EIO;
}
/* ARGSUSED */
-int
-cryptof_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
+
+int cryptof_ioctl(FAR struct file *fp, u_long cmd,
+ caddr_t data, FAR struct proc *p)
{
- struct cryptoini cria, crie;
- struct fcrypt *fcr = fp->f_data;
- struct csession *cse;
- struct session_op *sop;
- struct crypt_op *cop;
- const struct enc_xform *txform = NULL;
- const struct auth_hash *thash = NULL;
- u_int64_t sid;
- u_int32_t ses;
- int error = 0;
-
- switch (cmd) {
- case CIOCGSESSION:
- sop = (struct session_op *)data;
- switch (sop->cipher) {
- case 0:
- break;
- case CRYPTO_3DES_CBC:
- txform = &enc_xform_3des;
- break;
- case CRYPTO_BLF_CBC:
- txform = &enc_xform_blf;
- break;
- case CRYPTO_CAST_CBC:
- txform = &enc_xform_cast5;
- break;
- case CRYPTO_AES_CBC:
- txform = &enc_xform_aes;
- break;
- case CRYPTO_AES_CTR:
- txform = &enc_xform_aes_ctr;
- break;
- case CRYPTO_AES_XTS:
- txform = &enc_xform_aes_xts;
- break;
- case CRYPTO_NULL:
- txform = &enc_xform_null;
- break;
- default:
- return (EINVAL);
- }
-
- switch (sop->mac) {
- case 0:
- break;
- case CRYPTO_MD5_HMAC:
- thash = &auth_hash_hmac_md5_96;
- break;
- case CRYPTO_SHA1_HMAC:
- thash = &auth_hash_hmac_sha1_96;
- break;
- case CRYPTO_RIPEMD160_HMAC:
- thash = &auth_hash_hmac_ripemd_160_96;
- break;
- case CRYPTO_SHA2_256_HMAC:
- thash = &auth_hash_hmac_sha2_256_128;
- break;
- case CRYPTO_SHA2_384_HMAC:
- thash = &auth_hash_hmac_sha2_384_192;
- break;
- case CRYPTO_SHA2_512_HMAC:
- thash = &auth_hash_hmac_sha2_512_256;
- break;
- case CRYPTO_AES_128_GMAC:
- thash = &auth_hash_gmac_aes_128;
- break;
- default:
- return (EINVAL);
- }
-
- bzero(&crie, sizeof(crie));
- bzero(&cria, sizeof(cria));
-
- if (txform) {
- crie.cri_alg = txform->type;
- crie.cri_klen = sop->keylen * 8;
- if (sop->keylen > txform->maxkey ||
- sop->keylen < txform->minkey) {
- error = EINVAL;
- goto bail;
- }
-
- crie.cri_key = malloc(crie.cri_klen / 8, M_XDATA,
- M_WAITOK);
- if ((error = copyin(sop->key, crie.cri_key,
- crie.cri_klen / 8)))
- goto bail;
- if (thash)
- crie.cri_next = &cria;
- }
-
- if (thash) {
- cria.cri_alg = thash->type;
- cria.cri_klen = sop->mackeylen * 8;
- if (sop->mackeylen > thash->keysize) {
- error = EINVAL;
- goto bail;
- }
-
- if (cria.cri_klen) {
- cria.cri_key = malloc(cria.cri_klen / 8,
- M_XDATA, M_WAITOK);
- if ((error = copyin(sop->mackey, cria.cri_key,
- cria.cri_klen / 8)))
- goto bail;
- }
- }
-
- error = crypto_newsession(&sid, (txform ? &crie : &cria),
- !cryptodevallowsoft);
-
- if (error)
- goto bail;
-
- cse = csecreate(fcr, sid, crie.cri_key, crie.cri_klen,
- cria.cri_key, cria.cri_klen, sop->cipher, sop->mac, txform,
- thash);
-
- if (cse == NULL) {
- crypto_freesession(sid);
- error = EINVAL;
- goto bail;
- }
- sop->ses = cse->ses;
+ struct cryptoini cria;
+ struct cryptoini crie;
+ FAR struct fcrypt *fcr = fp->f_data;
+ FAR struct csession *cse;
+ FAR struct session_op *sop;
+ FAR struct crypt_op *cop;
+ FAR const struct enc_xform *txform = NULL;
+ FAR const struct auth_hash *thash = NULL;
+ uint64_t sid;
+ uint32_t ses;
+ int error = 0;
+
+ switch (cmd)
+ {
+ case CIOCGSESSION:
+ sop = (FAR struct session_op *)data;
+ switch (sop->cipher)
+ {
+ case 0:
+ break;
+ case CRYPTO_3DES_CBC:
+ txform = &enc_xform_3des;
+ break;
+ case CRYPTO_BLF_CBC:
+ txform = &enc_xform_blf;
+ break;
+ case CRYPTO_CAST_CBC:
+ txform = &enc_xform_cast5;
+ break;
+ case CRYPTO_AES_CBC:
+ txform = &enc_xform_aes;
+ break;
+ case CRYPTO_AES_CTR:
+ txform = &enc_xform_aes_ctr;
+ break;
+ case CRYPTO_AES_XTS:
+ txform = &enc_xform_aes_xts;
+ break;
+ case CRYPTO_NULL:
+ txform = &enc_xform_null;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ switch (sop->mac)
+ {
+ case 0:
+ break;
+ case CRYPTO_MD5_HMAC:
+ thash = &auth_hash_hmac_md5_96;
+ break;
+ case CRYPTO_SHA1_HMAC:
+ thash = &auth_hash_hmac_sha1_96;
+ break;
+ case CRYPTO_RIPEMD160_HMAC:
+ thash = &auth_hash_hmac_ripemd_160_96;
+ break;
+ case CRYPTO_SHA2_256_HMAC:
+ thash = &auth_hash_hmac_sha2_256_128;
+ break;
+ case CRYPTO_SHA2_384_HMAC:
+ thash = &auth_hash_hmac_sha2_384_192;
+ break;
+ case CRYPTO_SHA2_512_HMAC:
+ thash = &auth_hash_hmac_sha2_512_256;
+ break;
+ case CRYPTO_AES_128_GMAC:
+ thash = &auth_hash_gmac_aes_128;
+ break;
+ default:
+ return EINVAL;
+ }
+
+ bzero(&crie, sizeof(crie));
+ bzero(&cria, sizeof(cria));
+
+ if (txform)
+ {
+ crie.cri_alg = txform->type;
+ crie.cri_klen = sop->keylen * 8;
+ if (sop->keylen > txform->maxkey ||
+ sop->keylen < txform->minkey)
+ {
+ error = EINVAL;
+ goto bail;
+ }
+
+ crie.cri_key = malloc(crie.cri_klen / 8, M_XDATA,
+ M_WAITOK);
+ if ((error = copyin(sop->key, crie.cri_key,
+ crie.cri_klen / 8)))
+ {
+ goto bail;
+ }
+
+ if (thash)
+ {
+ crie.cri_next = &cria;
+ }
+ }
+
+ if (thash)
+ {
+ cria.cri_alg = thash->type;
+ cria.cri_klen = sop->mackeylen * 8;
+ if (sop->mackeylen > thash->keysize)
+ {
+ error = EINVAL;
+ goto bail;
+ }
+
+ if (cria.cri_klen)
+ {
+ cria.cri_key = malloc(cria.cri_klen / 8,
+ M_XDATA, M_WAITOK);
+ if ((error = copyin(sop->mackey, cria.cri_key,
+ cria.cri_klen / 8)))
+ {
+ goto bail;
+ }
+ }
+ }
+
+ error = crypto_newsession(&sid, txform ? &crie : &cria,
+ !cryptodevallowsoft);
+
+ if (error)
+ {
+ goto bail;
+ }
+
+ cse = csecreate(fcr, sid, crie.cri_key, crie.cri_klen,
+ cria.cri_key, cria.cri_klen, sop->cipher, sop->mac, txform,
+ thash);
+
+ if (cse == NULL)
+ {
+ crypto_freesession(sid);
+ error = EINVAL;
+ goto bail;
+ }
+
+ sop->ses = cse->ses;
bail:
- if (error) {
- if (crie.cri_key) {
- explicit_bzero(crie.cri_key, crie.cri_klen / 8);
- free(crie.cri_key, M_XDATA, 0);
- }
- if (cria.cri_key) {
- explicit_bzero(cria.cri_key, cria.cri_klen / 8);
- free(cria.cri_key, M_XDATA, 0);
- }
- }
- break;
- case CIOCFSESSION:
- ses = *(u_int32_t *)data;
- cse = csefind(fcr, ses);
- if (cse == NULL)
- return (EINVAL);
- csedelete(fcr, cse);
- error = csefree(cse);
- break;
- case CIOCCRYPT:
- cop = (struct crypt_op *)data;
- cse = csefind(fcr, cop->ses);
- if (cse == NULL)
- return (EINVAL);
- error = cryptodev_op(cse, cop, p);
- break;
- case CIOCKEY:
- error = cryptodev_key((struct crypt_kop *)data);
- break;
- case CIOCASYMFEAT:
- error = crypto_getfeat((int *)data);
- break;
- default:
- error = EINVAL;
- }
- return (error);
+ if (error)
+ {
+ if (crie.cri_key)
+ {
+ explicit_bzero(crie.cri_key, crie.cri_klen / 8);
+ free(crie.cri_key, M_XDATA, 0);
+ }
+
+ if (cria.cri_key)
+ {
+ explicit_bzero(cria.cri_key, cria.cri_klen / 8);
+ free(cria.cri_key, M_XDATA, 0);
+ }
+ }
+
+ break;
+ case CIOCFSESSION:
+ ses = *(FAR uint32_t *)data;
+ cse = csefind(fcr, ses);
+ if (cse == NULL)
+ {
+ return EINVAL;
+ }
+
+ csedelete(fcr, cse);
+ error = csefree(cse);
+ break;
+ case CIOCCRYPT:
+ cop = (FAR struct crypt_op *)data;
+ cse = csefind(fcr, cop->ses);
+ if (cse == NULL)
+ {
+ return EINVAL;
+ }
+
+ error = cryptodev_op(cse, cop, p);
+ break;
+ case CIOCKEY:
+ error = cryptodev_key((FAR struct crypt_kop *)data);
+ break;
+ case CIOCASYMFEAT:
+ error = crypto_getfeat((FAR int *)data);
+ break;
+ default:
+ error = EINVAL;
+ }
+
+ return error;
}
-int
-cryptodev_op(struct csession *cse, struct crypt_op *cop, struct proc *p)
+int cryptodev_op(FAR struct csession *cse,
+ FAR struct crypt_op *cop,
+ FAR struct proc *p)
{
- struct cryptop *crp = NULL;
- struct cryptodesc *crde = NULL, *crda = NULL;
- int s, error;
- u_int32_t hid;
-
- if (cop->len > 64*1024-4)
- return (E2BIG);
-
- if (cse->txform) {
- if (cop->len == 0 || (cop->len % cse->txform->blocksize) != 0)
- return (EINVAL);
- }
-
- bzero(&cse->uio, sizeof(cse->uio));
- cse->uio.uio_iovcnt = 1;
- cse->uio.uio_segflg = UIO_SYSSPACE;
- cse->uio.uio_rw = UIO_WRITE;
- cse->uio.uio_procp = p;
- cse->uio.uio_iov = cse->iovec;
- bzero(&cse->iovec, sizeof(cse->iovec));
- cse->uio.uio_iov[0].iov_len = cop->len;
- cse->uio.uio_iov[0].iov_base = dma_alloc(cop->len, M_WAITOK);
- cse->uio.uio_resid = cse->uio.uio_iov[0].iov_len;
-
- /* number of requests, not logical and */
- crp = crypto_getreq((cse->txform != NULL) + (cse->thash != NULL));
- if (crp == NULL) {
- error = ENOMEM;
- goto bail;
- }
-
- if (cse->thash) {
- crda = crp->crp_desc;
- if (cse->txform)
- crde = crda->crd_next;
- } else {
- if (cse->txform)
- crde = crp->crp_desc;
- else {
- error = EINVAL;
- goto bail;
- }
- }
-
- if ((error = copyin(cop->src, cse->uio.uio_iov[0].iov_base, cop->len)))
- goto bail;
-
- if (crda) {
- crda->crd_skip = 0;
- crda->crd_len = cop->len;
- crda->crd_inject = 0; /* ??? */
-
- crda->crd_alg = cse->mac;
- crda->crd_key = cse->mackey;
- crda->crd_klen = cse->mackeylen * 8;
- }
-
- if (crde) {
- if (cop->op == COP_ENCRYPT)
- crde->crd_flags |= CRD_F_ENCRYPT;
- else
- crde->crd_flags &= ~CRD_F_ENCRYPT;
- crde->crd_len = cop->len;
- crde->crd_inject = 0;
-
- crde->crd_alg = cse->cipher;
- crde->crd_key = cse->key;
- crde->crd_klen = cse->keylen * 8;
- }
-
- crp->crp_ilen = cop->len;
- crp->crp_buf = (caddr_t)&cse->uio;
- crp->crp_callback = cryptodev_cb;
- crp->crp_sid = cse->sid;
- crp->crp_opaque = cse;
-
- if (cop->iv) {
- if (crde == NULL) {
- error = EINVAL;
- goto bail;
- }
- if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
- error = EINVAL;
- goto bail;
- }
- if ((error = copyin(cop->iv, cse->tmp_iv, cse->txform->blocksize)))
- goto bail;
- bcopy(cse->tmp_iv, crde->crd_iv, cse->txform->blocksize);
- crde->crd_flags |= CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT;
- crde->crd_skip = 0;
- } else if (cse->cipher == CRYPTO_ARC4) { /* XXX use flag? */
- crde->crd_skip = 0;
- } else if (crde) {
- crde->crd_flags |= CRD_F_IV_PRESENT;
- crde->crd_skip = cse->txform->blocksize;
- crde->crd_len -= cse->txform->blocksize;
- }
-
- if (cop->mac) {
- if (crda == NULL) {
- error = EINVAL;
- goto bail;
- }
- crp->crp_mac = cse->tmp_mac;
- }
-
- /* try the fast path first */
- crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_NOQUEUE;
- hid = (crp->crp_sid >> 32) & 0xffffffff;
- if (hid >= crypto_drivers_num)
- goto dispatch;
- if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE)
- goto dispatch;
- if (crypto_drivers[hid].cc_process == NULL)
- goto dispatch;
- error = crypto_drivers[hid].cc_process(crp);
- if (error) {
- /* clear error */
- crp->crp_etype = 0;
- goto dispatch;
- }
- goto processed;
- dispatch:
- crp->crp_flags = CRYPTO_F_IOV;
- crypto_dispatch(crp);
- processed:
- s = splnet();
- while (!(crp->crp_flags & CRYPTO_F_DONE)) {
- error = tsleep(cse, PSOCK, "crydev", 0);
- }
- splx(s);
- if (error) {
- /* XXX can this happen? if so, how do we recover? */
- goto bail;
- }
-
- if (cse->error) {
- error = cse->error;
- goto bail;
- }
- if (crp->crp_etype != 0) {
- error = crp->crp_etype;
- goto bail;
- }
-
-
- if (cop->dst &&
- (error = copyout(cse->uio.uio_iov[0].iov_base, cop->dst, cop->len)))
- goto bail;
-
- if (cop->mac &&
- (error = copyout(crp->crp_mac, cop->mac, cse->thash->authsize)))
- goto bail;
+ FAR struct cryptop *crp = NULL;
+ FAR struct cryptodesc *crde = NULL;
+ FAR struct cryptodesc *crda = NULL;
+ int s;
+ int error;
+ uint32_t hid;
+
+ if (cop->len > 64 * 1024 - 4)
+ {
+ return E2BIG;
+ }
+
+ if (cse->txform)
+ {
+ if (cop->len == 0 || (cop->len % cse->txform->blocksize) != 0)
+ {
+ return EINVAL;
+ }
+ }
+
+ bzero(&cse->uio, sizeof(cse->uio));
+ cse->uio.uio_iovcnt = 1;
+ cse->uio.uio_segflg = UIO_SYSSPACE;
+ cse->uio.uio_rw = UIO_WRITE;
+ cse->uio.uio_procp = p;
+ cse->uio.uio_iov = cse->iovec;
+ bzero(&cse->iovec, sizeof(cse->iovec));
+ cse->uio.uio_iov[0].iov_len = cop->len;
+ cse->uio.uio_iov[0].iov_base = dma_alloc(cop->len, M_WAITOK);
+ cse->uio.uio_resid = cse->uio.uio_iov[0].iov_len;
+
+ /* number of requests, not logical and */
+
+ crp = crypto_getreq((cse->txform != NULL) + (cse->thash != NULL));
+ if (crp == NULL)
+ {
+ error = ENOMEM;
+ goto bail;
+ }
+
+ if (cse->thash)
+ {
+ crda = crp->crp_desc;
+ if (cse->txform)
+ crde = crda->crd_next;
+ }
+ else
+ {
+ if (cse->txform)
+ {
+ crde = crp->crp_desc;
+ }
+ else
+ {
+ error = EINVAL;
+ goto bail;
+ }
+ }
+
+ if ((error = copyin(cop->src, cse->uio.uio_iov[0].iov_base, cop->len)))
+ {
+ goto bail;
+ }
+
+ if (crda)
+ {
+ crda->crd_skip = 0;
+ crda->crd_len = cop->len;
+ crda->crd_inject = 0;
+
+ crda->crd_alg = cse->mac;
+ crda->crd_key = cse->mackey;
+ crda->crd_klen = cse->mackeylen * 8;
+ }
+
+ if (crde)
+ {
+ if (cop->op == COP_ENCRYPT)
+ {
+ crde->crd_flags |= CRD_F_ENCRYPT;
+ }
+ else
+ {
+ crde->crd_flags &= ~CRD_F_ENCRYPT;
+ }
+
+ crde->crd_len = cop->len;
+ crde->crd_inject = 0;
+ crde->crd_alg = cse->cipher;
+ crde->crd_key = cse->key;
+ crde->crd_klen = cse->keylen * 8;
+ }
+
+ crp->crp_ilen = cop->len;
+ crp->crp_buf = (caddr_t)&cse->uio;
+ crp->crp_callback = cryptodev_cb;
+ crp->crp_sid = cse->sid;
+ crp->crp_opaque = cse;
+
+ if (cop->iv)
+ {
+ if (crde == NULL)
+ {
+ error = EINVAL;
+ goto bail;
+ }
+
+ if ((error = copyin(cop->iv, cse->tmp_iv, cse->txform->blocksize)))
+ {
+ goto bail;
+ }
+
+ bcopy(cse->tmp_iv, crde->crd_iv, cse->txform->blocksize);
+ crde->crd_flags |= CRD_F_IV_EXPLICIT | CRD_F_IV_PRESENT;
+ crde->crd_skip = 0;
+ }
+ else if (crde)
+ {
+ crde->crd_flags |= CRD_F_IV_PRESENT;
+ crde->crd_skip = cse->txform->blocksize;
+ crde->crd_len -= cse->txform->blocksize;
+ }
+
+ if (cop->mac)
+ {
+ if (crda == NULL)
+ {
+ error = EINVAL;
+ goto bail;
+ }
+
+ crp->crp_mac = cop->mac;
+ }
+
+ /* try the fast path first */
+
+ crp->crp_flags = CRYPTO_F_IOV | CRYPTO_F_NOQUEUE;
+ hid = (crp->crp_sid >> 32) & 0xffffffff;
+ if (hid >= crypto_drivers_num)
+ {
+ goto dispatch;
+ }
+
+ if (crypto_drivers[hid].cc_flags & CRYPTOCAP_F_SOFTWARE)
+ {
+ goto dispatch;
+ }
+
+ if (crypto_drivers[hid].cc_process == NULL)
+ {
+ goto dispatch;
+ }
+
+ error = crypto_drivers[hid].cc_process(crp);
+ if (error)
+ {
+ /* clear error */
+
+ crp->crp_etype = 0;
+ goto dispatch;
+ }
+
+ goto processed;
+dispatch:
+ crp->crp_flags = CRYPTO_F_IOV;
+ crypto_dispatch(crp);
+processed:
+ s = splnet();
+ while (!(crp->crp_flags & CRYPTO_F_DONE))
+ {
+ error = tsleep(cse, PSOCK, "crydev", 0);
+ }
+
+ splx(s);
+ if (error)
+ {
+ /* XXX can this happen? if so, how do we recover? */
+
+ goto bail;
+ }
+
+ if (cse->error)
+ {
+ error = cse->error;
+ goto bail;
+ }
+
+ if (crp->crp_etype != 0)
+ {
+ error = crp->crp_etype;
+ goto bail;
+ }
+
+ if (cop->dst &&
+ (error = copyout(cse->uio.uio_iov[0].iov_base, cop->dst, cop->len)))
+ {
+ goto bail;
+ }
+
+ if (cop->mac &&
+ (error = copyout(crp->crp_mac, cop->mac, cse->thash->hashsize)))
+ {
+ goto bail;
+ }
bail:
- if (crp)
- crypto_freereq(crp);
- if (cse->uio.uio_iov[0].iov_base)
- dma_free(cse->uio.uio_iov[0].iov_base, cop->len);
+ if (crp)
+ {
+ crypto_freereq(crp);
+ }
+
+ if (cse->uio.uio_iov[0].iov_base)
+ {
+ dma_free(cse->uio.uio_iov[0].iov_base, cop->len);
+ }
- return (error);
+ return error;
}
-int
-cryptodev_cb(struct cryptop *crp)
+int cryptodev_cb(FAR struct cryptop *crp)
{
- struct csession *cse = crp->crp_opaque;
-
- cse->error = crp->crp_etype;
- if (crp->crp_etype == EAGAIN) {
- crp->crp_flags = CRYPTO_F_IOV;
- return crypto_dispatch(crp);
- }
- wakeup(cse);
- return (0);
+ FAR struct csession *cse = crp->crp_opaque;
+
+ cse->error = crp->crp_etype;
+ if (crp->crp_etype == EAGAIN)
+ {
+ crp->crp_flags = CRYPTO_F_IOV;
+ return crypto_dispatch(crp);
+ }
+
+ wakeup(cse);
+ return (0);
}
-int
-cryptodevkey_cb(struct cryptkop *krp)
+int cryptodevkey_cb(FAR struct cryptkop *krp)
{
-
- wakeup(krp);
- return (0);
+ wakeup(krp);
+ return (0);
}
-int
-cryptodev_key(struct crypt_kop *kop)
+int cryptodev_key(FAR struct crypt_kop *kop)
{
- struct cryptkop *krp = NULL;
- int error = EINVAL;
- int in, out, size, i;
-
- if (kop->crk_iparams + kop->crk_oparams > CRK_MAXPARAM) {
- return (EFBIG);
- }
-
- in = kop->crk_iparams;
- out = kop->crk_oparams;
- switch (kop->crk_op) {
- case CRK_MOD_EXP:
- if (in == 3 && out == 1)
- break;
- return (EINVAL);
- case CRK_MOD_EXP_CRT:
- if (in == 6 && out == 1)
- break;
- return (EINVAL);
- case CRK_DSA_SIGN:
- if (in == 5 && out == 2)
- break;
- return (EINVAL);
- case CRK_DSA_VERIFY:
- if (in == 7 && out == 0)
- break;
- return (EINVAL);
- case CRK_DH_COMPUTE_KEY:
- if (in == 3 && out == 1)
- break;
- return (EINVAL);
- default:
- return (EINVAL);
- }
-
- krp = malloc(sizeof *krp, M_XDATA, M_WAITOK | M_ZERO);
- krp->krp_op = kop->crk_op;
- krp->krp_status = kop->crk_status;
- krp->krp_iparams = kop->crk_iparams;
- krp->krp_oparams = kop->crk_oparams;
- krp->krp_status = 0;
- krp->krp_callback = cryptodevkey_cb;
-
- for (i = 0; i < CRK_MAXPARAM; i++) {
- krp->krp_param[i].crp_nbits = kop->crk_param[i].crp_nbits;
- if (kop->crk_param[i].crp_nbits > 65536) {
- /* XXX how big do we need to support? */
- goto fail;
- }
- }
- for (i = 0; i < krp->krp_iparams + krp->krp_oparams; i++) {
- size = (krp->krp_param[i].crp_nbits + 7) / 8;
- if (size == 0)
- continue;
- krp->krp_param[i].crp_p = malloc(size, M_XDATA, M_WAITOK);
- if (i >= krp->krp_iparams)
- continue;
- error = copyin(kop->crk_param[i].crp_p, krp->krp_param[i].crp_p, size);
- if (error)
- goto fail;
- }
-
- error = crypto_kdispatch(krp);
- if (error)
- goto fail;
- error = tsleep(krp, PSOCK, "crydev", 0);
- if (error) {
- /* XXX can this happen? if so, how do we recover? */
- goto fail;
- }
-
- if (krp->krp_status != 0) {
- error = krp->krp_status;
- goto fail;
- }
-
- for (i = krp->krp_iparams; i < krp->krp_iparams + krp->krp_oparams; i++) {
- size = (krp->krp_param[i].crp_nbits + 7) / 8;
- if (size == 0)
- continue;
- error = copyout(krp->krp_param[i].crp_p, kop->crk_param[i].crp_p, size);
- if (error)
- goto fail;
- }
+ FAR struct cryptkop *krp = NULL;
+ int error = EINVAL;
+ int in;
+ int out;
+ int size;
+ int i;
+
+ if (kop->crk_iparams + kop->crk_oparams > CRK_MAXPARAM)
+ {
+ return EFBIG;
+ }
+
+ in = kop->crk_iparams;
+ out = kop->crk_oparams;
+ switch (kop->crk_op)
+ {
+ case CRK_MOD_EXP:
+ if (in == 3 && out == 1)
+ break;
+ return EINVAL;
+ case CRK_MOD_EXP_CRT:
+ if (in == 6 && out == 1)
+ break;
+ return EINVAL;
+ case CRK_DSA_SIGN:
+ if (in == 5 && out == 2)
+ break;
+ return EINVAL;
+ case CRK_DSA_VERIFY:
+ if (in == 7 && out == 0)
+ break;
+ return EINVAL;
+ case CRK_DH_COMPUTE_KEY:
+ if (in == 3 && out == 1)
+ break;
+ return EINVAL;
+ default:
+ return EINVAL;
+ }
+
+ krp = malloc(sizeof *krp, M_XDATA, M_WAITOK | M_ZERO);
+ krp->krp_op = kop->crk_op;
+ krp->krp_status = kop->crk_status;
+ krp->krp_iparams = kop->crk_iparams;
+ krp->krp_oparams = kop->crk_oparams;
+ krp->krp_status = 0;
+ krp->krp_callback = cryptodevkey_cb;
+
+ for (i = 0; i < CRK_MAXPARAM; i++)
+ {
+ krp->krp_param[i].crp_nbits = kop->crk_param[i].crp_nbits;
+ if (kop->crk_param[i].crp_nbits > 65536)
+ {
+ /* XXX how big do we need to support? */
+
+ goto fail;
+ }
+ }
+
+ for (i = 0; i < krp->krp_iparams + krp->krp_oparams; i++)
+ {
+ size = (krp->krp_param[i].crp_nbits + 7) / 8;
+ if (size == 0)
+ {
+ continue;
+ }
+
+ krp->krp_param[i].crp_p = malloc(size, M_XDATA, M_WAITOK);
+ if (i >= krp->krp_iparams)
+ {
+ continue;
+ }
+
+ error = copyin(kop->crk_param[i].crp_p,
+ krp->krp_param[i].crp_p, size);
+ if (error)
+ {
+ goto fail;
+ }
+ }
+
+ error = crypto_kdispatch(krp);
+ if (error)
+ {
+ goto fail;
+ }
+
+ error = tsleep(krp, PSOCK, "crydev", 0);
+ if (error)
+ {
+ /* XXX can this happen? if so, how do we recover? */
+
+ goto fail;
+ }
+
+ if (krp->krp_status != 0)
+ {
+ error = krp->krp_status;
+ goto fail;
+ }
+
+ for (i = krp->krp_iparams; i < krp->krp_iparams + krp->krp_oparams; i++)
+ {
+ size = (krp->krp_param[i].crp_nbits + 7) / 8;
+ if (size == 0)
+ {
+ continue;
+ }
+
+ error = copyout(krp->krp_param[i].crp_p,
+ kop->crk_param[i].crp_p, size);
+ if (error)
+ {
+ goto fail;
+ }
+ }
fail:
- if (krp) {
- kop->crk_status = krp->krp_status;
- for (i = 0; i < CRK_MAXPARAM; i++) {
- if (krp->krp_param[i].crp_p) {
- explicit_bzero(krp->krp_param[i].crp_p,
- (krp->krp_param[i].crp_nbits + 7) / 8);
- free(krp->krp_param[i].crp_p, M_XDATA, 0);
- }
- }
- free(krp, M_XDATA, 0);
- }
- return (error);
+ if (krp)
+ {
+ kop->crk_status = krp->krp_status;
+ for (i = 0; i < CRK_MAXPARAM; i++)
+ {
+ if (krp->krp_param[i].crp_p)
+ {
+ explicit_bzero(krp->krp_param[i].crp_p,
+ (krp->krp_param[i].crp_nbits + 7) / 8);
+ free(krp->krp_param[i].crp_p, M_XDATA, 0);
+ }
+ }
+
+ free(krp, M_XDATA, 0);
+ }
+
+ return error;
}
/* ARGSUSED */
-int
-cryptof_poll(struct file *fp, int events, struct proc *p)
+
+int cryptof_poll(FAR struct file *fp, int events, FAR struct proc *p)
{
- return (0);
+ return 0;
}
/* ARGSUSED */
-int
-cryptof_kqfilter(struct file *fp, struct knote *kn)
+
+int cryptof_kqfilter(FAR struct file *fp, FAR struct knote *kn)
{
- return (0);
+ return 0;
}
/* ARGSUSED */
-int
-cryptof_stat(struct file *fp, struct stat *sb, struct proc *p)
+
+int cryptof_stat(FAR struct file *fp,
+ FAR struct stat *sb,
+ FAR struct proc *p)
{
- return (EOPNOTSUPP);
+ return EOPNOTSUPP;
}
/* ARGSUSED */
-int
-cryptof_close(struct file *fp, struct proc *p)
+
+int cryptof_close(FAR struct file *fp, FAR struct proc *p)
{
- struct fcrypt *fcr = fp->f_data;
- struct csession *cse;
-
- while ((cse = TAILQ_FIRST(&fcr->csessions))) {
- TAILQ_REMOVE(&fcr->csessions, cse, next);
- (void)csefree(cse);
- }
- free(fcr, M_XDATA, 0);
- fp->f_data = NULL;
- return 0;
+ FAR struct fcrypt *fcr = fp->f_data;
+ FAR struct csession *cse;
+
+ while ((cse = TAILQ_FIRST(&fcr->csessions)))
+ {
+ TAILQ_REMOVE(&fcr->csessions, cse, next);
+ (void)csefree(cse);
+ }
+
+ free(fcr, M_XDATA, 0);
+ fp->f_data = NULL;
+ return 0;
}
-void
-cryptoattach(int n)
+void cryptoattach(int n)
{
}
-int
-cryptoopen(dev_t dev, int flag, int mode, struct proc *p)
+int cryptoopen(dev_t dev, int flag, int mode, FAR struct proc *p)
{
- if (usercrypto == 0)
- return (ENXIO);
+ if (usercrypto == 0)
+ {
+ return ENXIO;
+ }
+
#ifdef CRYPTO
- return (0);
+ return 0;
#else
- return (ENXIO);
+ return ENXIO;
#endif
}
-int
-cryptoclose(dev_t dev, int flag, int mode, struct proc *p)
+int cryptoclose(dev_t dev, int flag, int mode, FAR struct proc *p)
{
- return (0);
+ return (0);
}
-int
-cryptoioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+int cryptoioctl(dev_t dev, u_long cmd,
+ caddr_t data, int flag, FAR struct proc *p)
{
- struct file *f;
- struct fcrypt *fcr;
- int fd;
- int error = 0;
-
- switch (cmd) {
- case CRIOGET:
- fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK);
- TAILQ_INIT(&fcr->csessions);
- fcr->sesn = 0;
-
- fdplock(p->p_fd);
- error = falloc(p, &f, &fd);
- fdpunlock(p->p_fd);
- if (error) {
- free(fcr, M_XDATA, 0);
- return (error);
- }
- f->f_flag = FREAD | FWRITE;
- f->f_type = DTYPE_CRYPTO;
- f->f_ops = &cryptofops;
- f->f_data = fcr;
- *(u_int32_t *)data = fd;
- FILE_SET_MATURE(f, p);
- break;
- default:
- error = EINVAL;
- break;
- }
- return (error);
+ FAR struct file *f;
+ FAR struct fcrypt *fcr;
+ int fd;
+ int error = 0;
+
+ switch (cmd)
+ {
+ case CRIOGET:
+ fcr = malloc(sizeof(struct fcrypt), M_XDATA, M_WAITOK);
+ TAILQ_INIT(&fcr->csessions);
+ fcr->sesn = 0;
+
+ fdplock(p->p_fd);
+ error = falloc(p, &f, &fd);
+ fdpunlock(p->p_fd);
+ if (error)
+ {
+ free(fcr, M_XDATA, 0);
+ return error;
+ }
+
+ f->f_flag = FREAD | FWRITE;
+ f->f_type = DTYPE_CRYPTO;
+ f->f_ops = &cryptofops;
+ f->f_data = fcr;
+ *(FAR uint32_t *)data = fd;
+ FILE_SET_MATURE(f, p);
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return error;
}
-struct csession *
-csefind(struct fcrypt *fcr, u_int ses)
+FAR struct csession *csefind(FAR struct fcrypt *fcr, u_int ses)
{
- struct csession *cse;
+ FAR struct csession *cse;
+
+ TAILQ_FOREACH(cse, &fcr->csessions, next)
+ if (cse->ses == ses)
+ {
+ return cse;
+ }
- TAILQ_FOREACH(cse, &fcr->csessions, next)
- if (cse->ses == ses)
- return (cse);
- return (NULL);
+ return NULL;
}
-int
-csedelete(struct fcrypt *fcr, struct csession *cse_del)
+int csedelete(FAR struct fcrypt *fcr, FAR struct csession *cse_del)
{
- struct csession *cse;
-
- TAILQ_FOREACH(cse, &fcr->csessions, next) {
- if (cse == cse_del) {
- TAILQ_REMOVE(&fcr->csessions, cse, next);
- return (1);
- }
- }
- return (0);
+ FAR struct csession *cse;
+
+ TAILQ_FOREACH(cse, &fcr->csessions, next)
+ {
+ if (cse == cse_del)
+ {
+ TAILQ_REMOVE(&fcr->csessions, cse, next);
+ return 1;
+ }
+ }
+
+ return 0;
}
-struct csession *
-cseadd(struct fcrypt *fcr, struct csession *cse)
+FAR struct csession *cseadd(FAR struct fcrypt *fcr,
+ FAR struct csession *cse)
{
- TAILQ_INSERT_TAIL(&fcr->csessions, cse, next);
- cse->ses = fcr->sesn++;
- return (cse);
+ TAILQ_INSERT_TAIL(&fcr->csessions, cse, next);
+ cse->ses = fcr->sesn++;
+ return cse;
}
-struct csession *
-csecreate(struct fcrypt *fcr, u_int64_t sid, caddr_t key, u_int64_t keylen,
- caddr_t mackey, u_int64_t mackeylen, u_int32_t cipher, u_int32_t mac,
- const struct enc_xform *txform, const struct auth_hash *thash)
+FAR struct csession *csecreate(FAR struct fcrypt *fcr, uint64_t sid,
+ caddr_t key, uint64_t keylen,
+ caddr_t mackey, uint64_t mackeylen,
+ uint32_t cipher, uint32_t mac,
+ FAR const struct enc_xform *txform,
+ FAR const struct auth_hash *thash)
{
- struct csession *cse;
-
- cse = malloc(sizeof(struct csession), M_XDATA, M_NOWAIT);
- if (cse == NULL)
- return NULL;
- cse->key = key;
- cse->keylen = keylen/8;
- cse->mackey = mackey;
- cse->mackeylen = mackeylen/8;
- cse->sid = sid;
- cse->cipher = cipher;
- cse->mac = mac;
- cse->txform = txform;
- cse->thash = thash;
- cse->error = 0;
- cseadd(fcr, cse);
- return (cse);
+ FAR struct csession *cse;
+
+ cse = malloc(sizeof(struct csession), M_XDATA, M_NOWAIT);
+ if (cse == NULL)
+ {
+ return NULL;
+ }
+
+ cse->key = key;
+ cse->keylen = keylen / 8;
+ cse->mackey = mackey;
+ cse->mackeylen = mackeylen / 8;
+ cse->sid = sid;
+ cse->cipher = cipher;
+ cse->mac = mac;
+ cse->txform = txform;
+ cse->thash = thash;
+ cse->error = 0;
+ cseadd(fcr, cse);
+ return cse;
}
-int
-csefree(struct csession *cse)
+int csefree(FAR struct csession *cse)
{
- int error;
-
- error = crypto_freesession(cse->sid);
- if (cse->key)
- free(cse->key, M_XDATA, 0);
- if (cse->mackey)
- free(cse->mackey, M_XDATA, 0);
- free(cse, M_XDATA, 0);
- return (error);
+ int error;
+
+ error = crypto_freesession(cse->sid);
+ if (cse->key)
+ {
+ free(cse->key, M_XDATA, 0);
+ }
+
+ if (cse->mackey)
+ {
+ free(cse->mackey, M_XDATA, 0);
+ }
+
+ free(cse, M_XDATA, 0);
+ return error;
}
diff --git a/crypto/cryptosoft.c b/crypto/cryptosoft.c
index 912f67d914..7beb81a31b 100644
--- a/crypto/cryptosoft.c
+++ b/crypto/cryptosoft.c
@@ -1,6 +1,6 @@
-/* $OpenBSD: cryptosoft.c,v 1.71 2014/07/13 23:24:47 deraadt Exp $ */
-
-/*
+/****************************************************************************
+ * crypto/cryptosoft.c
+ * $OpenBSD: cryptosoft.c,v 1.71 2014/07/13 23:24:47 deraadt Exp $
* The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
*
* This code was written by Angelos D. Keromytis in Athens, Greece, in
@@ -19,7 +19,11 @@
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
* PURPOSE.
- */
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
#include <sys/param.h>
#include <sys/systm.h>
@@ -36,1136 +40,1475 @@
#include <crypto/cryptosoft.h>
#include <crypto/xform.h>
-const u_int8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN] = {
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
- 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
-};
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
-const u_int8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN] = {
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C,
- 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C, 0x5C
+const uint8_t hmac_ipad_buffer[HMAC_MAX_BLOCK_LEN] =
+{
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
+ 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36
};
+const uint8_t hmac_opad_buffer[HMAC_MAX_BLOCK_LEN] =
+{
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c,
+ 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c, 0x5c
+};
-struct swcr_data **swcr_sessions = NULL;
-u_int32_t swcr_sesnum = 0;
-int32_t swcr_id = -1;
+FAR struct swcr_data **swcr_sessions = NULL;
+uint32_t swcr_sesnum = 0;
+int swcr_id = -1;
#define COPYBACK(x, a, b, c, d) \
- do { \
- if ((x) == CRYPTO_BUF_MBUF) \
- m_copyback((struct mbuf *)a,b,c,d,M_NOWAIT); \
- else \
- cuio_copyback((struct uio *)a,b,c,d); \
- } while (0)
+ do { \
+ if ((x) == CRYPTO_BUF_MBUF) \
+ m_copyback((FAR struct mbuf *)a,b,c,d,M_NOWAIT); \
+ else \
+ cuio_copyback((FAR struct uio *)a,b,c,d); \
+ } while (0)
#define COPYDATA(x, a, b, c, d) \
- do { \
- if ((x) == CRYPTO_BUF_MBUF) \
- m_copydata((struct mbuf *)a,b,c,d); \
- else \
- cuio_copydata((struct uio *)a,b,c,d); \
- } while (0)
-
-/*
- * Apply a symmetric encryption/decryption algorithm.
- */
-int
-swcr_encdec(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
- int outtype)
+ do { \
+ if ((x) == CRYPTO_BUF_MBUF) \
+ m_copydata((FAR struct mbuf *)a,b,c,d); \
+ else \
+ cuio_copydata((FAR struct uio *)a,b,c,d); \
+ } while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/* Apply a symmetric encryption/decryption algorithm. */
+
+int swcr_encdec(FAR struct cryptodesc *crd, FAR struct swcr_data *sw,
+ caddr_t buf, int outtype)
{
- unsigned char iv[EALG_MAX_BLOCK_LEN], blk[EALG_MAX_BLOCK_LEN], *idat;
- unsigned char *ivp, *nivp, iv2[EALG_MAX_BLOCK_LEN];
- const struct enc_xform *exf;
- int i, k, j, blks, ind, count, ivlen;
- struct mbuf *m = NULL;
- struct uio *uio = NULL;
-
- exf = sw->sw_exf;
- blks = exf->blocksize;
- ivlen = exf->ivsize;
-
- /* Check for non-padded data */
- if (crd->crd_len % blks)
- return EINVAL;
-
- if (outtype == CRYPTO_BUF_MBUF)
- m = (struct mbuf *) buf;
- else
- uio = (struct uio *) buf;
-
- /* Initialize the IV */
- if (crd->crd_flags & CRD_F_ENCRYPT) {
- /* IV explicitly provided ? */
- if (crd->crd_flags & CRD_F_IV_EXPLICIT)
- bcopy(crd->crd_iv, iv, ivlen);
- else
- arc4random_buf(iv, ivlen);
-
- /* Do we need to write the IV */
- if (!(crd->crd_flags & CRD_F_IV_PRESENT))
- COPYBACK(outtype, buf, crd->crd_inject, ivlen, iv);
-
- } else { /* Decryption */
- /* IV explicitly provided ? */
- if (crd->crd_flags & CRD_F_IV_EXPLICIT)
- bcopy(crd->crd_iv, iv, ivlen);
- else {
- /* Get IV off buf */
- COPYDATA(outtype, buf, crd->crd_inject, ivlen, iv);
- }
- }
-
- ivp = iv;
-
- /*
- * xforms that provide a reinit method perform all IV
- * handling themselves.
- */
- if (exf->reinit)
- exf->reinit((caddr_t)sw->sw_kschedule, iv);
-
- if (outtype == CRYPTO_BUF_MBUF) {
- /* Find beginning of data */
- m = m_getptr(m, crd->crd_skip, &k);
- if (m == NULL)
- return EINVAL;
-
- i = crd->crd_len;
-
- while (i > 0) {
- /*
- * If there's insufficient data at the end of
- * an mbuf, we have to do some copying.
- */
- if (m->m_len < k + blks && m->m_len != k) {
- m_copydata(m, k, blks, blk);
-
- /* Actual encryption/decryption */
- if (exf->reinit) {
- if (crd->crd_flags & CRD_F_ENCRYPT) {
- exf->encrypt((caddr_t)sw->sw_kschedule,
- blk);
- } else {
- exf->decrypt((caddr_t)sw->sw_kschedule,
- blk);
- }
- } else if (crd->crd_flags & CRD_F_ENCRYPT) {
- /* XOR with previous block */
- for (j = 0; j < blks; j++)
- blk[j] ^= ivp[j];
-
- exf->encrypt((caddr_t)sw->sw_kschedule, blk);
-
- /*
- * Keep encrypted block for XOR'ing
- * with next block
- */
- bcopy(blk, iv, blks);
- ivp = iv;
- } else { /* decrypt */
- /*
- * Keep encrypted block for XOR'ing
- * with next block
- */
- nivp = (ivp == iv) ? iv2 : iv;
- bcopy(blk, nivp, blks);
-
- exf->decrypt((caddr_t)sw->sw_kschedule, blk);
-
- /* XOR with previous block */
- for (j = 0; j < blks; j++)
- blk[j] ^= ivp[j];
- ivp = nivp;
- }
-
- /* Copy back decrypted block */
- m_copyback(m, k, blks, blk, M_NOWAIT);
-
- /* Advance pointer */
- m = m_getptr(m, k + blks, &k);
- if (m == NULL)
- return EINVAL;
-
- i -= blks;
-
- /* Could be done... */
- if (i == 0)
- break;
- }
-
- /* Skip possibly empty mbufs */
- if (k == m->m_len) {
- for (m = m->m_next; m && m->m_len == 0;
- m = m->m_next)
- ;
- k = 0;
- }
-
- /* Sanity check */
- if (m == NULL)
- return EINVAL;
-
- /*
- * Warning: idat may point to garbage here, but
- * we only use it in the while() loop, only if
- * there are indeed enough data.
- */
- idat = mtod(m, unsigned char *) + k;
-
- while (m->m_len >= k + blks && i > 0) {
- if (exf->reinit) {
- if (crd->crd_flags & CRD_F_ENCRYPT) {
- exf->encrypt(sw->sw_kschedule,
- idat);
- } else {
- exf->decrypt(sw->sw_kschedule,
- idat);
- }
- } else if (crd->crd_flags & CRD_F_ENCRYPT) {
- /* XOR with previous block/IV */
- for (j = 0; j < blks; j++)
- idat[j] ^= ivp[j];
-
- exf->encrypt(sw->sw_kschedule, idat);
- ivp = idat;
- } else { /* decrypt */
- /*
- * Keep encrypted block to be used
- * in next block's processing.
- */
- nivp = (ivp == iv) ? iv2 : iv;
- bcopy(idat, nivp, blks);
-
- exf->decrypt(sw->sw_kschedule, idat);
-
- /* XOR with previous block/IV */
- for (j = 0; j < blks; j++)
- idat[j] ^= ivp[j];
- ivp = nivp;
- }
-
- idat += blks;
- k += blks;
- i -= blks;
- }
- }
- } else {
- /* Find beginning of data */
- count = crd->crd_skip;
- ind = cuio_getptr(uio, count, &k);
- if (ind == -1)
- return EINVAL;
-
- i = crd->crd_len;
-
- while (i > 0) {
- /*
- * If there's insufficient data at the end,
- * we have to do some copying.
- */
- if (uio->uio_iov[ind].iov_len < k + blks &&
- uio->uio_iov[ind].iov_len != k) {
- cuio_copydata(uio, count, blks, blk);
-
- /* Actual encryption/decryption */
- if (exf->reinit) {
- if (crd->crd_flags & CRD_F_ENCRYPT) {
- exf->encrypt(sw->sw_kschedule,
- blk);
- } else {
- exf->decrypt(sw->sw_kschedule,
- blk);
- }
- } else if (crd->crd_flags & CRD_F_ENCRYPT) {
- /* XOR with previous block */
- for (j = 0; j < blks; j++)
- blk[j] ^= ivp[j];
-
- exf->encrypt(sw->sw_kschedule, blk);
-
- /*
- * Keep encrypted block for XOR'ing
- * with next block
- */
- bcopy(blk, iv, blks);
- ivp = iv;
- } else { /* decrypt */
- /*
- * Keep encrypted block for XOR'ing
- * with next block
- */
- nivp = (ivp == iv) ? iv2 : iv;
- bcopy(blk, nivp, blks);
-
- exf->decrypt(sw->sw_kschedule, blk);
-
- /* XOR with previous block */
- for (j = 0; j < blks; j++)
- blk[j] ^= ivp[j];
- ivp = nivp;
- }
-
- /* Copy back decrypted block */
- cuio_copyback(uio, count, blks, blk);
-
- count += blks;
-
- /* Advance pointer */
- ind = cuio_getptr(uio, count, &k);
- if (ind == -1)
- return (EINVAL);
-
- i -= blks;
-
- /* Could be done... */
- if (i == 0)
- break;
- }
-
- /*
- * Warning: idat may point to garbage here, but
- * we only use it in the while() loop, only if
- * there are indeed enough data.
- */
- idat = (char *)uio->uio_iov[ind].iov_base + k;
-
- while (uio->uio_iov[ind].iov_len >= k + blks &&
- i > 0) {
- if (exf->reinit) {
- if (crd->crd_flags & CRD_F_ENCRYPT) {
- exf->encrypt(sw->sw_kschedule,
- idat);
- } else {
- exf->decrypt(sw->sw_kschedule,
- idat);
- }
- } else if (crd->crd_flags & CRD_F_ENCRYPT) {
- /* XOR with previous block/IV */
- for (j = 0; j < blks; j++)
- idat[j] ^= ivp[j];
-
- exf->encrypt(sw->sw_kschedule, idat);
- ivp = idat;
- } else { /* decrypt */
- /*
- * Keep encrypted block to be used
- * in next block's processing.
- */
- nivp = (ivp == iv) ? iv2 : iv;
- bcopy(idat, nivp, blks);
-
- exf->decrypt(sw->sw_kschedule, idat);
-
- /* XOR with previous block/IV */
- for (j = 0; j < blks; j++)
- idat[j] ^= ivp[j];
- ivp = nivp;
- }
-
- idat += blks;
- count += blks;
- k += blks;
- i -= blks;
- }
-
- /*
- * Advance to the next iov if the end of the current iov
- * is aligned with the end of a cipher block.
- * Note that the code is equivalent to calling:
- * ind = cuio_getptr(uio, count, &k);
- */
- if (i > 0 && k == uio->uio_iov[ind].iov_len) {
- k = 0;
- ind++;
- if (ind >= uio->uio_iovcnt)
- return (EINVAL);
- }
- }
- }
-
- return 0; /* Done with encryption/decryption */
+ unsigned char iv[EALG_MAX_BLOCK_LEN];
+ unsigned char blk[EALG_MAX_BLOCK_LEN];
+ FAR unsigned char *idat;
+ FAR unsigned char *ivp;
+ FAR unsigned char *nivp;
+ unsigned char iv2[EALG_MAX_BLOCK_LEN];
+ FAR const struct enc_xform *exf;
+ int i;
+ int k;
+ int j;
+ int blks;
+ int ind;
+ int count;
+ int ivlen;
+ FAR struct mbuf *m = NULL;
+ FAR struct uio *uio = NULL;
+
+ exf = sw->sw_exf;
+ blks = exf->blocksize;
+ ivlen = exf->ivsize;
+
+ /* Check for non-padded data */
+
+ if (crd->crd_len % blks)
+ {
+ return EINVAL;
+ }
+
+ if (outtype == CRYPTO_BUF_MBUF)
+ {
+ m = (FAR struct mbuf *) buf;
+ }
+ else
+ {
+ uio = (FAR struct uio *) buf;
+ }
+
+ /* Initialize the IV */
+
+ if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ /* IV explicitly provided ? */
+
+ if (crd->crd_flags & CRD_F_IV_EXPLICIT)
+ {
+ bcopy(crd->crd_iv, iv, ivlen);
+ }
+ else
+ {
+ arc4random_buf(iv, ivlen);
+ }
+
+ /* Do we need to write the IV */
+
+ if (!(crd->crd_flags & CRD_F_IV_PRESENT))
+ {
+ COPYBACK(outtype, buf, crd->crd_inject, ivlen, iv);
+ }
+ }
+ else
+ {
+ /* Decryption */
+
+ /* IV explicitly provided ? */
+
+ if (crd->crd_flags & CRD_F_IV_EXPLICIT)
+ {
+ bcopy(crd->crd_iv, iv, ivlen);
+ }
+ else
+ {
+ /* Get IV off buf */
+
+ COPYDATA(outtype, buf, crd->crd_inject, ivlen, iv);
+ }
+ }
+
+ ivp = iv;
+
+ /* xforms that provide a reinit method perform all IV
+ * handling themselves.
+ */
+
+ if (exf->reinit)
+ {
+ exf->reinit((caddr_t)sw->sw_kschedule, iv);
+ }
+
+ if (outtype == CRYPTO_BUF_MBUF)
+ {
+ /* Find beginning of data */
+
+ m = m_getptr(m, crd->crd_skip, &k);
+ if (m == NULL)
+ {
+ return EINVAL;
+ }
+
+ i = crd->crd_len;
+
+ while (i > 0)
+ {
+ /* If there's insufficient data at the end of
+ * an mbuf, we have to do some copying.
+ */
+
+ if (m->m_len < k + blks && m->m_len != k)
+ {
+ m_copydata(m, k, blks, blk);
+
+ /* Actual encryption/decryption */
+
+ if (exf->reinit)
+ {
+ if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ exf->encrypt((caddr_t)sw->sw_kschedule,
+ blk);
+ }
+ else
+ {
+ exf->decrypt((caddr_t)sw->sw_kschedule,
+ blk);
+ }
+ }
+ else if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ /* XOR with previous block */
+
+ for (j = 0; j < blks; j++)
+ {
+ blk[j] ^= ivp[j];
+ }
+
+ exf->encrypt((caddr_t)sw->sw_kschedule, blk);
+
+ /* Keep encrypted block for XOR'ing
+ * with next block
+ */
+
+ bcopy(blk, iv, blks);
+ ivp = iv;
+ }
+ else
+ {
+ /* decrypt */
+
+ /* Keep encrypted block for XOR'ing
+ * with next block
+ */
+
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(blk, nivp, blks);
+
+ exf->decrypt(sw->sw_kschedule, blk);
+
+ /* XOR with previous block */
+
+ for (j = 0; j < blks; j++)
+ {
+ blk[j] ^= ivp[j];
+ }
+
+ ivp = nivp;
+ }
+
+ /* Copy back decrypted block */
+
+ m_copyback(m, k, blks, blk, M_NOWAIT);
+
+ /* Advance pointer */
+
+ m = m_getptr(m, k + blks, &k);
+ if (m == NULL)
+ {
+ return EINVAL;
+ }
+
+ i -= blks;
+
+ /* Could be done... */
+
+ if (i == 0)
+ {
+ break;
+ }
+ }
+
+ /* Skip possibly empty mbufs */
+
+ if (k == m->m_len)
+ {
+ for (m = m->m_next; m && m->m_len == 0;
+ m = m->m_next)
+ ;
+ k = 0;
+ }
+
+ /* Sanity check */
+
+ if (m == NULL)
+ {
+ return EINVAL;
+ }
+
+ /* Warning: idat may point to garbage here, but
+ * we only use it in the while() loop, only if
+ * there are indeed enough data.
+ */
+
+ idat = mtod(m, FAR unsigned char *) + k;
+
+ while (m->m_len >= k + blks && i > 0)
+ {
+ if (exf->reinit)
+ {
+ if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ exf->encrypt(sw->sw_kschedule,
+ idat);
+ }
+ else
+ {
+ exf->decrypt(sw->sw_kschedule,
+ idat);
+ }
+ }
+ else if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ /* XOR with previous block/IV */
+
+ for (j = 0; j < blks; j++)
+ {
+ idat[j] ^= ivp[j];
+ }
+
+ exf->encrypt(sw->sw_kschedule, idat);
+ ivp = idat;
+ }
+ else
+ {
+ /* decrypt */
+
+ /* Keep encrypted block to be used
+ * in next block's processing.
+ */
+
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(idat, nivp, blks);
+
+ exf->decrypt(sw->sw_kschedule, idat);
+
+ /* XOR with previous block/IV */
+
+ for (j = 0; j < blks; j++)
+ {
+ idat[j] ^= ivp[j];
+ }
+
+ ivp = nivp;
+ }
+
+ idat += blks;
+ k += blks;
+ i -= blks;
+ }
+ }
+ }
+ else
+ {
+ /* Find beginning of data */
+
+ count = crd->crd_skip;
+ ind = cuio_getptr(uio, count, &k);
+ if (ind == -1)
+ {
+ return EINVAL;
+ }
+
+ i = crd->crd_len;
+
+ while (i > 0)
+ {
+ /* If there's insufficient data at the end,
+ * we have to do some copying.
+ */
+
+ if (uio->uio_iov[ind].iov_len < k + blks &&
+ uio->uio_iov[ind].iov_len != k)
+ {
+ cuio_copydata(uio, count, blks, blk);
+
+ /* Actual encryption/decryption */
+
+ if (exf->reinit)
+ {
+ if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ exf->encrypt(sw->sw_kschedule,
+ blk);
+ }
+ else
+ {
+ exf->decrypt(sw->sw_kschedule,
+ blk);
+ }
+ }
+ else if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ /* XOR with previous block */
+
+ for (j = 0; j < blks; j++)
+ {
+ blk[j] ^= ivp[j];
+ }
+
+ exf->encrypt(sw->sw_kschedule, blk);
+
+ /* Keep encrypted block for XOR'ing
+ * with next block
+ */
+
+ bcopy(blk, iv, blks);
+ ivp = iv;
+ }
+ else
+ {
+ /* decrypt */
+
+ /* Keep encrypted block for XOR'ing
+ * with next block
+ */
+
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(blk, nivp, blks);
+
+ exf->decrypt(sw->sw_kschedule, blk);
+
+ /* XOR with previous block */
+
+ for (j = 0; j < blks; j++)
+ {
+ blk[j] ^= ivp[j];
+ }
+
+ ivp = nivp;
+ }
+
+ /* Copy back decrypted block */
+
+ cuio_copyback(uio, count, blks, blk);
+
+ count += blks;
+
+ /* Advance pointer */
+
+ ind = cuio_getptr(uio, count, &k);
+ if (ind == -1)
+ {
+ return EINVAL;
+ }
+
+ i -= blks;
+
+ /* Could be done... */
+
+ if (i == 0)
+ {
+ break;
+ }
+ }
+
+ /* Warning: idat may point to garbage here, but
+ * we only use it in the while() loop, only if
+ * there are indeed enough data.
+ */
+
+ idat = (FAR char *)uio->uio_iov[ind].iov_base + k;
+
+ while (uio->uio_iov[ind].iov_len >= k + blks &&
+ i > 0)
+ {
+ if (exf->reinit)
+ {
+ if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ exf->encrypt(sw->sw_kschedule,
+ idat);
+ }
+ else
+ {
+ exf->decrypt(sw->sw_kschedule,
+ idat);
+ }
+ }
+ else if (crd->crd_flags & CRD_F_ENCRYPT)
+ {
+ /* XOR with previous block/IV */
+
+ for (j = 0; j < blks; j++)
+ {
+ idat[j] ^= ivp[j];
+ }
+
+ exf->encrypt(sw->sw_kschedule, idat);
+ ivp = idat;
+ }
+ else
+ {
+ /* decrypt */
+
+ /* Keep encrypted block to be used
+ * in next block's processing.
+ */
+
+ nivp = (ivp == iv) ? iv2 : iv;
+ bcopy(idat, nivp, blks);
+
+ exf->decrypt(sw->sw_kschedule, idat);
+
+ /* XOR with previous block/IV */
+
+ for (j = 0; j < blks; j++)
+ {
+ idat[j] ^= ivp[j];
+ }
+
+ ivp = nivp;
+ }
+
+ idat += blks;
+ count += blks;
+ k += blks;
+ i -= blks;
+ }
+
+ /* Advance to the next iov if the end of the current iov
+ * is aligned with the end of a cipher block.
+ * Note that the code is equivalent to calling:
+ * ind = cuio_getptr(uio, count, &k);
+ */
+
+ if (i > 0 && k == uio->uio_iov[ind].iov_len)
+ {
+ k = 0;
+ ind++;
+ if (ind >= uio->uio_iovcnt)
+ {
+ return EINVAL;
+ }
+ }
+ }
+ }
+
+ return 0; /* Done with encryption/decryption */
}
-/*
- * Compute keyed-hash authenticator.
- */
-int
-swcr_authcompute(struct cryptop *crp, struct cryptodesc *crd,
- struct swcr_data *sw, caddr_t buf, int outtype)
+/* Compute keyed-hash authenticator. */
+
+int swcr_authcompute(FAR struct cryptop *crp,
+ FAR struct cryptodesc *crd,
+ FAR struct swcr_data *sw,
+ caddr_t buf, int outtype)
{
- unsigned char aalg[AALG_MAX_RESULT_LEN];
- const struct auth_hash *axf;
- union authctx ctx;
- int err;
-
- if (sw->sw_ictx == 0)
- return EINVAL;
-
- axf = sw->sw_axf;
-
- bcopy(sw->sw_ictx, &ctx, axf->ctxsize);
-
- if (outtype == CRYPTO_BUF_MBUF)
- err = m_apply((struct mbuf *) buf, crd->crd_skip, crd->crd_len,
- (int (*)(caddr_t, caddr_t, unsigned int)) axf->Update,
- (caddr_t) &ctx);
- else
- err = cuio_apply((struct uio *) buf, crd->crd_skip,
- crd->crd_len,
- (int (*)(caddr_t, caddr_t, unsigned int)) axf->Update,
- (caddr_t) &ctx);
-
- if (err)
- return err;
-
- if (crd->crd_flags & CRD_F_ESN)
- axf->Update(&ctx, crd->crd_esn, 4);
-
- switch (sw->sw_alg) {
- case CRYPTO_MD5_HMAC:
- case CRYPTO_SHA1_HMAC:
- case CRYPTO_RIPEMD160_HMAC:
- case CRYPTO_SHA2_256_HMAC:
- case CRYPTO_SHA2_384_HMAC:
- case CRYPTO_SHA2_512_HMAC:
- if (sw->sw_octx == NULL)
- return EINVAL;
-
- axf->Final(aalg, &ctx);
- bcopy(sw->sw_octx, &ctx, axf->ctxsize);
- axf->Update(&ctx, aalg, axf->hashsize);
- axf->Final(aalg, &ctx);
- break;
- }
-
- /* Inject the authentication data */
- if (outtype == CRYPTO_BUF_MBUF)
- COPYBACK(outtype, buf, crd->crd_inject, axf->hashsize, aalg);
- else
- bcopy(aalg, crp->crp_mac, axf->hashsize);
-
- return 0;
+ unsigned char aalg[AALG_MAX_RESULT_LEN];
+ FAR const struct auth_hash *axf;
+ union authctx ctx;
+ int err;
+
+ if (sw->sw_ictx == 0)
+ {
+ return EINVAL;
+ }
+
+ axf = sw->sw_axf;
+
+ bcopy(sw->sw_ictx, &ctx, axf->ctxsize);
+
+ if (outtype == CRYPTO_BUF_MBUF)
+ {
+ err = m_apply((FAR struct mbuf *) buf, crd->crd_skip, crd->crd_len,
+ (int (*)(caddr_t, caddr_t, unsigned int)) axf->update,
+ (caddr_t) &ctx);
+ }
+ else
+ {
+ err = cuio_apply((FAR struct uio *) buf, crd->crd_skip,
+ crd->crd_len,
+ (int (*)(caddr_t, caddr_t, unsigned int)) axf->update,
+ (caddr_t) &ctx);
+ }
+
+ if (err)
+ {
+ return err;
+ }
+
+ if (crd->crd_flags & CRD_F_ESN)
+ {
+ axf->update(&ctx, crd->crd_esn, 4);
+ }
+
+ switch (sw->sw_alg)
+ {
+ case CRYPTO_MD5_HMAC:
+ case CRYPTO_SHA1_HMAC:
+ case CRYPTO_RIPEMD160_HMAC:
+ case CRYPTO_SHA2_256_HMAC:
+ case CRYPTO_SHA2_384_HMAC:
+ case CRYPTO_SHA2_512_HMAC:
+ if (sw->sw_octx == NULL)
+ {
+ return EINVAL;
+ }
+
+ axf->final(aalg, &ctx);
+ bcopy(sw->sw_octx, &ctx, axf->ctxsize);
+ axf->update(&ctx, aalg, axf->hashsize);
+ axf->final(aalg, &ctx);
+ break;
+ }
+
+ if (outtype == CRYPTO_BUF_MBUF)
+ {
+ COPYBACK(outtype, buf, crd->crd_inject, axf->hashsize, aalg);
+ }
+ else
+ {
+ bcopy(aalg, crp->crp_mac, axf->hashsize);
+ }
+
+ return 0;
}
-/*
- * Apply a combined encryption-authentication transformation
- */
-int
-swcr_authenc(struct cryptop *crp)
+/* Apply a combined encryption-authentication transformation */
+
+int swcr_authenc(FAR struct cryptop *crp)
{
- uint32_t blkbuf[howmany(EALG_MAX_BLOCK_LEN, sizeof(uint32_t))];
- u_char *blk = (u_char *)blkbuf;
- u_char aalg[AALG_MAX_RESULT_LEN];
- u_char iv[EALG_MAX_BLOCK_LEN];
- union authctx ctx;
- struct cryptodesc *crd, *crda = NULL, *crde = NULL;
- struct swcr_data *sw, *swa, *swe = NULL;
- const struct auth_hash *axf = NULL;
- const struct enc_xform *exf = NULL;
- struct mbuf *m = NULL;
- struct uio *uio = NULL;
- caddr_t buf = (caddr_t)crp->crp_buf;
- uint32_t *blkp;
- int aadlen, blksz, i, ivlen, outtype, len, iskip, oskip;
-
- ivlen = blksz = iskip = oskip = 0;
-
- for (crd = crp->crp_desc; crd; crd = crd->crd_next) {
- for (sw = swcr_sessions[crp->crp_sid & 0xffffffff];
- sw && sw->sw_alg != crd->crd_alg;
- sw = sw->sw_next)
- ;
- if (sw == NULL)
- return (EINVAL);
-
- switch (sw->sw_alg) {
- case CRYPTO_AES_GCM_16:
- case CRYPTO_AES_GMAC:
- case CRYPTO_CHACHA20_POLY1305:
- swe = sw;
- crde = crd;
- exf = swe->sw_exf;
- ivlen = exf->ivsize;
- break;
- case CRYPTO_AES_128_GMAC:
- case CRYPTO_AES_192_GMAC:
- case CRYPTO_AES_256_GMAC:
- case CRYPTO_CHACHA20_POLY1305_MAC:
- swa = sw;
- crda = crd;
- axf = swa->sw_axf;
- if (swa->sw_ictx == 0)
- return (EINVAL);
- bcopy(swa->sw_ictx, &ctx, axf->ctxsize);
- blksz = axf->blocksize;
- break;
- default:
- return (EINVAL);
- }
- }
- if (crde == NULL || crda == NULL)
- return (EINVAL);
-
- if (crp->crp_flags & CRYPTO_F_IMBUF) {
- outtype = CRYPTO_BUF_MBUF;
- m = (struct mbuf *)buf;
- } else {
- outtype = CRYPTO_BUF_IOV;
- uio = (struct uio *)buf;
- }
-
- /* Initialize the IV */
- if (crde->crd_flags & CRD_F_ENCRYPT) {
- /* IV explicitly provided ? */
- if (crde->crd_flags & CRD_F_IV_EXPLICIT)
- bcopy(crde->crd_iv, iv, ivlen);
- else
- arc4random_buf(iv, ivlen);
-
- /* Do we need to write the IV */
- if (!(crde->crd_flags & CRD_F_IV_PRESENT))
- COPYBACK(outtype, buf, crde->crd_inject, ivlen, iv);
-
- } else { /* Decryption */
- /* IV explicitly provided ? */
- if (crde->crd_flags & CRD_F_IV_EXPLICIT)
- bcopy(crde->crd_iv, iv, ivlen);
- else {
- /* Get IV off buf */
- COPYDATA(outtype, buf, crde->crd_inject, ivlen, iv);
- }
- }
-
- /* Supply MAC with IV */
- if (axf->Reinit)
- axf->Reinit(&ctx, iv, ivlen);
-
- /* Supply MAC with AAD */
- aadlen = crda->crd_len;
- /*
- * Section 5 of RFC 4106 specifies that AAD construction consists of
- * {SPI, ESN, SN} whereas the real packet contains only {SPI, SN}.
- * Unfortunately it doesn't follow a good example set in the Section
... 14341 lines suppressed ...