summaryrefslogtreecommitdiff
path: root/db/crypto
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2007-07-16 16:48:14 +0300
committerPanu Matilainen <pmatilai@redhat.com>2007-07-16 16:48:14 +0300
commit2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79 (patch)
treee12ee52087506ac8c7a5eee83b17497d98df2d40 /db/crypto
parentb754fe19fd387ca5fe8e7c00ddaa25c898fa192f (diff)
downloadlibrpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.gz
librpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.bz2
librpm-tizen-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.zip
Update internal BDB to version 4.5.20
Diffstat (limited to 'db/crypto')
-rw-r--r--db/crypto/aes_method.c12
-rw-r--r--db/crypto/crypto.c171
-rw-r--r--db/crypto/crypto.html13
-rw-r--r--db/crypto/mersenne/mt19937db.c41
-rw-r--r--db/crypto/rijndael/rijndael-alg-fst.c2
-rw-r--r--db/crypto/rijndael/rijndael-alg-fst.h6
-rw-r--r--db/crypto/rijndael/rijndael-api-fst.c37
-rw-r--r--db/crypto/rijndael/rijndael-api-fst.h2
8 files changed, 139 insertions, 145 deletions
diff --git a/db/crypto/aes_method.c b/db/crypto/aes_method.c
index 567e67456..cd4370b3a 100644
--- a/db/crypto/aes_method.c
+++ b/db/crypto/aes_method.c
@@ -1,21 +1,17 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2001-2004
- * Sleepycat Software. All rights reserved.
+ * Copyright (c) 2001-2006
+ * Oracle Corporation. All rights reserved.
*
* Some parts of this code originally written by Adam Stubblefield,
* -- astubble@rice.edu.
*
- * $Id: aes_method.c,v 1.20 2004/09/17 22:00:25 mjc Exp $
+ * $Id: aes_method.c,v 12.5 2006/08/24 14:45:12 bostic Exp $
*/
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/crypto.h"
#include "dbinc/hmac.h"
@@ -268,6 +264,6 @@ __aes_err(dbenv, err)
errstr = "AES error unrecognized";
break;
}
- __db_err(dbenv, errstr);
+ __db_errx(dbenv, errstr);
return;
}
diff --git a/db/crypto/crypto.c b/db/crypto/crypto.c
index f753ec3f0..72a8444e0 100644
--- a/db/crypto/crypto.c
+++ b/db/crypto/crypto.c
@@ -1,21 +1,17 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2004
- * Sleepycat Software. All rights reserved.
+ * Copyright (c) 1996-2006
+ * Oracle Corporation. All rights reserved.
*
* Some parts of this code originally written by Adam Stubblefield
* -- astubble@rice.edu
*
- * $Id: crypto.c,v 1.31 2004/10/15 16:59:38 bostic Exp $
+ * $Id: crypto.c,v 12.10 2006/08/24 14:45:12 bostic Exp $
*/
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/crypto.h"
@@ -40,35 +36,31 @@ __crypto_region_init(dbenv)
ret = 0;
infop = dbenv->reginfo;
renv = infop->primary;
- MUTEX_LOCK(dbenv, &renv->mutex);
if (renv->cipher_off == INVALID_ROFF) {
if (!CRYPTO_ON(dbenv))
- goto err;
+ return (0);
if (!F_ISSET(infop, REGION_CREATE)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Joining non-encrypted environment with encryption key");
- ret = EINVAL;
- goto err;
+ return (EINVAL);
}
if (F_ISSET(db_cipher, CIPHER_ANY)) {
- __db_err(dbenv, "Encryption algorithm not supplied");
- ret = EINVAL;
- goto err;
+ __db_errx(dbenv, "Encryption algorithm not supplied");
+ return (EINVAL);
}
/*
- * Must create the shared information. We need:
- * Shared cipher information that contains the passwd.
- * After we copy the passwd, we smash and free the one in the
- * dbenv.
+ * Must create the shared information. We need: Shared cipher
+ * information that contains the passwd. After we copy the
+ * passwd, we smash and free the one in the dbenv.
*/
- if ((ret = __db_shalloc(
- infop, sizeof(CIPHER), MUTEX_ALIGN, &cipher)) != 0)
- goto err;
+ if ((ret =
+ __db_shalloc(infop, sizeof(CIPHER), 0, &cipher)) != 0)
+ return (ret);
memset(cipher, 0, sizeof(*cipher));
if ((ret = __db_shalloc(
infop, dbenv->passwd_len, 0, &sh_passwd)) != 0) {
__db_shalloc_free(infop, cipher);
- goto err;
+ return (ret);
}
memset(sh_passwd, 0, dbenv->passwd_len);
cipher->passwd = R_OFFSET(infop, sh_passwd);
@@ -78,52 +70,45 @@ __crypto_region_init(dbenv)
renv->cipher_off = R_OFFSET(infop, cipher);
} else {
if (!CRYPTO_ON(dbenv)) {
- __db_err(dbenv,
- "Encrypted environment: no encryption key supplied");
- ret = EINVAL;
- goto err;
+ __db_errx(dbenv,
+ "Encrypted environment: no encryption key supplied");
+ return (EINVAL);
}
cipher = R_ADDR(infop, renv->cipher_off);
sh_passwd = R_ADDR(infop, cipher->passwd);
if ((cipher->passwd_len != dbenv->passwd_len) ||
memcmp(dbenv->passwd, sh_passwd, cipher->passwd_len) != 0) {
- __db_err(dbenv, "Invalid password");
- ret = EPERM;
- goto err;
+ __db_errx(dbenv, "Invalid password");
+ return (EPERM);
}
if (!F_ISSET(db_cipher, CIPHER_ANY) &&
db_cipher->alg != cipher->flags) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Environment encrypted using a different algorithm");
- ret = EINVAL;
- goto err;
+ return (EINVAL);
}
if (F_ISSET(db_cipher, CIPHER_ANY))
/*
- * We have CIPHER_ANY and we are joining the
- * existing env. Setup our cipher structure
- * for whatever algorithm this env has.
+ * We have CIPHER_ANY and we are joining the existing
+ * env. Setup our cipher structure for whatever
+ * algorithm this env has.
*/
if ((ret = __crypto_algsetup(dbenv, db_cipher,
cipher->flags, 0)) != 0)
- goto err;
+ return (ret);
}
- MUTEX_UNLOCK(dbenv, &renv->mutex);
ret = db_cipher->init(dbenv, db_cipher);
/*
- * On success, no matter if we allocated it or are using the
- * already existing one, we are done with the passwd in the dbenv.
- * We smash N-1 bytes so that we don't overwrite the nul.
+ * On success, no matter if we allocated it or are using the already
+ * existing one, we are done with the passwd in the dbenv. We smash
+ * N-1 bytes so that we don't overwrite the nul.
*/
memset(dbenv->passwd, 0xff, dbenv->passwd_len-1);
__os_free(dbenv, dbenv->passwd);
dbenv->passwd = NULL;
dbenv->passwd_len = 0;
- if (0) {
-err: MUTEX_UNLOCK(dbenv, &renv->mutex);
- }
return (ret);
}
@@ -197,7 +182,7 @@ __crypto_algsetup(dbenv, db_cipher, alg, do_init)
ret = 0;
if (!CRYPTO_ON(dbenv)) {
- __db_err(dbenv, "No cipher structure given");
+ __db_errx(dbenv, "No cipher structure given");
return (EINVAL);
}
F_CLR(db_cipher, CIPHER_ANY);
@@ -236,47 +221,67 @@ __crypto_decrypt_meta(dbenv, dbp, mbuf, do_metachk)
u_int8_t *iv;
/*
- * If we weren't given a dbp, we just want to decrypt the page
- * on behalf of some internal subsystem, not on behalf of a user
- * with a dbp. Therefore, set up a dummy dbp so that the call
- * to P_OVERHEAD below works.
+ * If we weren't given a dbp, we just want to decrypt the page on
+ * behalf of some internal subsystem, not on behalf of a user with
+ * a dbp. Therefore, set up a dummy dbp so that the call to
+ * P_OVERHEAD below works.
*/
if (dbp == NULL) {
memset(&dummydb, 0, sizeof(DB));
dbp = &dummydb;
}
+
+ ret = 0;
+ meta = (DBMETA *)mbuf;
+
/*
- * Meta-pages may be encrypted for DBMETASIZE bytes. If
- * we have a non-zero IV (that is written after encryption)
- * then we decrypt (or error if the user isn't set up for
- * security). We guarantee that the IV space on non-encrypted
- * pages will be zero and a zero-IV is illegal for encryption.
- * Therefore any non-zero IV means an encrypted database.
- * This basically checks the passwd on the file
- * if we cannot find a good magic number.
- * We walk through all the algorithms we know about attempting
- * to decrypt (and possibly byteswap).
+ * !!!
+ * We used an "unused" field in the meta-data page to flag whether or
+ * not the database is encrypted. Unfortunately, that unused field
+ * was used in Berkeley DB releases before 3.0 (for example, 2.7.7).
+ * It would have been OK, except encryption doesn't follow the usual
+ * rules of "upgrade before doing anything else", we check encryption
+ * before checking for old versions of the database.
+ *
+ * We don't have to check Btree databases -- before 3.0, the field of
+ * interest was the bt_maxkey field (which was never supported and has
+ * since been removed).
+ *
+ * Ugly check to jump out if this format is older than what we support.
+ * It assumes no encrypted page will have an unencrypted magic number,
+ * but that seems relatively safe. [#10920]
+ */
+ if (meta->magic == DB_HASHMAGIC && meta->version <= 5)
+ return (0);
+
+ /*
+ * Meta-pages may be encrypted for DBMETASIZE bytes. If we have a
+ * non-zero IV (that is written after encryption) then we decrypt (or
+ * error if the user isn't set up for security). We guarantee that
+ * the IV space on non-encrypted pages will be zero and a zero-IV is
+ * illegal for encryption. Therefore any non-zero IV means an
+ * encrypted database. This basically checks the passwd on the file
+ * if we cannot find a good magic number. We walk through all the
+ * algorithms we know about attempting to decrypt (and possibly
+ * byteswap).
*
* !!!
- * All method meta pages have the IV and checksum at the
- * exact same location, but not in DBMETA, use BTMETA.
+ * All method meta pages have the IV and checksum at the exact same
+ * location, but not in DBMETA, use BTMETA.
*/
- ret = 0;
- meta = (DBMETA *)mbuf;
if (meta->encrypt_alg != 0) {
db_cipher = (DB_CIPHER *)dbenv->crypto_handle;
if (!F_ISSET(dbp, DB_AM_ENCRYPT)) {
if (!CRYPTO_ON(dbenv)) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Encrypted database: no encryption flag specified");
return (EINVAL);
}
/*
- * User has a correct, secure env, but has
- * encountered a database in that env that is
- * secure, but user didn't dbp->set_flags. Since
- * it is existing, use encryption if it is that
- * way already.
+ * User has a correct, secure env, but has encountered
+ * a database in that env that is secure, but user
+ * didn't dbp->set_flags. Since it is existing, use
+ * encryption if it is that way already.
*/
F_SET(dbp, DB_AM_ENCRYPT|DB_AM_CHKSUM);
}
@@ -284,19 +289,19 @@ __crypto_decrypt_meta(dbenv, dbp, mbuf, do_metachk)
* This was checked in set_flags when DB_AM_ENCRYPT was set.
* So it better still be true here.
*/
- DB_ASSERT(CRYPTO_ON(dbenv));
+ DB_ASSERT(dbenv, CRYPTO_ON(dbenv));
if (!F_ISSET(db_cipher, CIPHER_ANY) &&
meta->encrypt_alg != db_cipher->alg) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Database encrypted using a different algorithm");
return (EINVAL);
}
- DB_ASSERT(F_ISSET(dbp, DB_AM_CHKSUM));
+ DB_ASSERT(dbenv, F_ISSET(dbp, DB_AM_CHKSUM));
iv = ((BTMETA *)mbuf)->iv;
/*
- * For ALL pages, we do not encrypt the beginning
- * of the page that contains overhead information.
- * This is true of meta and all other pages.
+ * For ALL pages, we do not encrypt the beginning of the page
+ * that contains overhead information. This is true of meta
+ * and all other pages.
*/
pg_off = P_OVERHEAD(dbp);
alg_retry:
@@ -311,7 +316,7 @@ alg_retry:
return (ret);
if (((BTMETA *)meta)->crypto_magic !=
meta->magic) {
- __db_err(dbenv, "Invalid password");
+ __db_errx(dbenv, "Invalid password");
return (EINVAL);
}
/*
@@ -330,10 +335,10 @@ alg_retry:
goto alg_retry;
} else if (F_ISSET(dbp, DB_AM_ENCRYPT)) {
/*
- * They gave us a passwd, but the database is not
- * encrypted. This is an error. We do NOT want to
- * silently allow them to write data in the clear when
- * the user set up and expects encrypted data.
+ * They gave us a passwd, but the database is not encrypted.
+ * This is an error. We do NOT want to silently allow them
+ * to write data in the clear when the user set up and expects
+ * encrypted data.
*
* This covers at least the following scenario.
* 1. User creates and sets up an encrypted database.
@@ -349,7 +354,7 @@ alg_retry:
* Therefore, asking for encryption with a database that
* was not encrypted is an error.
*/
- __db_err(dbenv,
+ __db_errx(dbenv,
"Unencrypted database with a supplied encryption key");
return (EINVAL);
}
@@ -377,9 +382,9 @@ __crypto_set_passwd(dbenv_src, dbenv_dest)
infop = dbenv_src->reginfo;
renv = infop->primary;
- DB_ASSERT(CRYPTO_ON(dbenv_src));
+ DB_ASSERT(dbenv_src, CRYPTO_ON(dbenv_src));
cipher = R_ADDR(infop, renv->cipher_off);
sh_passwd = R_ADDR(infop, cipher->passwd);
- return (__dbenv_set_encrypt(dbenv_dest, sh_passwd, DB_ENCRYPT_AES));
+ return (__env_set_encrypt(dbenv_dest, sh_passwd, DB_ENCRYPT_AES));
}
diff --git a/db/crypto/crypto.html b/db/crypto/crypto.html
index 9475beb2a..129a7f4f3 100644
--- a/db/crypto/crypto.html
+++ b/db/crypto/crypto.html
@@ -11,7 +11,6 @@
&nbsp;Security Interface for Berkeley DB</h1></center>
<center><i>Susan LoVerso</i>
-<br><i>sue@sleepycat.com</i>
<br><i>Rev 1.6</i>
<br><i>2002 Feb 26</i></center>
@@ -108,7 +107,7 @@ The setup of the security subsystem will be similar to replication initializatio
since it is a sort of subsystem, but it does not have its own region.&nbsp;
When the environment handle is created via <i>db_env_create</i>, we initialize
our <i>set_encrypt</i> method to be the RPC or local version.&nbsp; Therefore
-the <i>__dbenv</i> structure needs a new pointer:
+the <i>DB_ENV</i> structure needs a new pointer:
<pre>&nbsp;&nbsp;&nbsp; void&nbsp;&nbsp;&nbsp; *crypto_handle;&nbsp;&nbsp; /* Security handle */</pre>
The crypto handle will really point to a new <i>__db_cipher</i> structure
that will contain a set of functions and a pointer to the in-memory information
@@ -134,21 +133,21 @@ this is set up, it is read-only forever.
<p>During <a href="../docs/api_c/env_set_encrypt.html">dbenv->set_encrypt</a>,
we set the encryption, decryption and checksumming methods to the appropriate
functions based on the flags.&nbsp; This function will allocate us a crypto
-handle that we store in the <i>__dbenv</i> structure just like all the
+handle that we store in the <i>DB_ENV</i> structure just like all the
other subsystems.&nbsp; For now, only AES ciphering functions and SHA1
checksumming functions are supported.&nbsp; Also we will copy the password
-into the <i>__dbenv</i> structure.&nbsp; We ultimately need to keep the
+into the <i>DB_ENV</i> structure.&nbsp; We ultimately need to keep the
password in the environment's shared memory region or compare this one
against the one that is there, if we are joining an existing environment,
but we do not have it yet because open has not yet been called.&nbsp; We
will allocate a structure that will be used in initialization and set up
the function pointers to point to the algorithm-specific functions.
-<p>In the&nbsp; <i>__dbenv_open</i> path, in <i>__db_e_attach</i>, if we
+<p>In the&nbsp; <i>__env_open</i> path, in <i>__db_e_attach</i>, if we
are creating the region and the <i>dbenv->passwd</i> field is set, we need
to use the length of the password in the initial computation of the environment's
size.&nbsp; This guarantees sufficient space for storing the password in
shared memory.&nbsp; Then we will call a new function to initialize the
-security region, <i>__crypto_region_init</i> in <i>__dbenv_open</i>.&nbsp;
+security region, <i>__crypto_region_init</i> in <i>__env_open</i>.&nbsp;
If we are the creator, we will allocate space in the shared region to store
the password and copy the password into that space.&nbsp; Or, if we are
not the creator we will compare the password stored in the dbenv with the
@@ -304,7 +303,7 @@ We will have per-process state vectors that are set up when a process begins.&nb
That way we minimize the contention and only multi-threaded processes need
acquire locks for the IV.&nbsp; We will have the state vector in the environment
handle in heap memory, as well as the index and there will be a mutex protecting
-it for threaded access.&nbsp; This will be added to the <i>__dbenv</i>
+it for threaded access.&nbsp; This will be added to the <i>DB_ENV</i>
structure:
<pre>&nbsp;&nbsp;&nbsp; DB_MUTEX&nbsp;&nbsp;&nbsp; *mt_mutexp;&nbsp;&nbsp; /* Mersenne Twister mutex */
&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *mti;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* MT index */
diff --git a/db/crypto/mersenne/mt19937db.c b/db/crypto/mersenne/mt19937db.c
index 1c1699db5..6cd259932 100644
--- a/db/crypto/mersenne/mt19937db.c
+++ b/db/crypto/mersenne/mt19937db.c
@@ -1,5 +1,5 @@
/*
- * $Id: mt19937db.c,v 1.12 2004/06/14 16:54:27 mjc Exp $
+ * $Id: mt19937db.c,v 12.4 2006/09/08 20:32:02 bostic Exp $
*/
#include "db_config.h"
@@ -33,14 +33,14 @@
/* ACM Transactions on Modeling and Computer Simulation, */
/* Vol. 8, No. 1, January 1998, pp 3--30. */
-/* Period parameters */
+/* Period parameters */
#define N 624
#define M 397
#define MATRIX_A 0x9908b0df /* constant vector a */
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
#define LOWER_MASK 0x7fffffff /* least significant r bits */
-/* Tempering parameters */
+/* Tempering parameters */
#define TEMPERING_MASK_B 0x9d2c5680
#define TEMPERING_MASK_C 0xefc60000
#define TEMPERING_SHIFT_U(y) (y >> 11)
@@ -69,7 +69,7 @@ __db_generate_iv(dbenv, iv)
ret = 0;
n = DB_IV_BYTES / sizeof(u_int32_t);
- MUTEX_THREAD_LOCK(dbenv, dbenv->mt_mutexp);
+ MUTEX_LOCK(dbenv, dbenv->mtx_mt);
if (dbenv->mt == NULL) {
if ((ret = __os_calloc(dbenv, 1, N*sizeof(unsigned long),
&dbenv->mt)) != 0)
@@ -77,30 +77,29 @@ __db_generate_iv(dbenv, iv)
/* mti==N+1 means mt[N] is not initialized */
dbenv->mti = N + 1;
}
- for (i = 0; i < n; i++)
-{
+ for (i = 0; i < n; i++) {
/*
* We do not allow 0. If we get one just try again.
*/
do {
iv[i] = (u_int32_t)__db_genrand(dbenv);
} while (iv[i] == 0);
-}
+ }
- MUTEX_THREAD_UNLOCK(dbenv, dbenv->mt_mutexp);
+ MUTEX_UNLOCK(dbenv, dbenv->mtx_mt);
return (0);
}
/* Initializing the array with a seed */
static void
__db_sgenrand(seed, mt, mtip)
- unsigned long seed;
+ unsigned long seed;
unsigned long mt[];
int *mtip;
{
int i;
- DB_ASSERT(seed != 0);
+ DB_ASSERT(NULL, seed != 0);
for (i=0;i<N;i++) {
mt[i] = seed & 0xffff0000;
seed = 69069 * seed + 1;
@@ -116,28 +115,28 @@ __db_sgenrand(seed, mt, mtip)
/* This function allows to choose any of 2^19937-1 ones. */
/* Essential bits in "seed_array[]" is following 19937 bits: */
/* (seed_array[0]&UPPER_MASK), seed_array[1], ..., seed_array[N-1]. */
-/* (seed_array[0]&LOWER_MASK) is discarded. */
+/* (seed_array[0]&LOWER_MASK) is discarded. */
/* Theoretically, */
/* (seed_array[0]&UPPER_MASK), seed_array[1], ..., seed_array[N-1] */
/* can take any values except all zeros. */
static void
__db_lsgenrand(seed_array, mt, mtip)
- unsigned long seed_array[];
- unsigned long mt[];
+ unsigned long seed_array[];
+ unsigned long mt[];
int *mtip;
/* the length of seed_array[] must be at least N */
{
int i;
- for (i=0;i<N;i++)
+ for (i=0;i<N;i++)
mt[i] = seed_array[i];
*mtip=N;
}
#endif
-static unsigned long
+static unsigned long
__db_genrand(dbenv)
- DB_ENV *dbenv;
+ DB_ENV *dbenv;
{
unsigned long y;
static unsigned long mag01[2]={0x0, MATRIX_A};
@@ -145,7 +144,7 @@ __db_genrand(dbenv)
u_int32_t secs, seed, usecs;
/*
- * We are called with the mt_mutexp locked
+ * We are called with DB_ENV->mtx_mt locked.
*/
if (dbenv->mti >= N) { /* generate N words at one time */
int kk;
@@ -157,10 +156,10 @@ __db_genrand(dbenv)
*/
do {
__os_clock(dbenv, &secs, &usecs);
- __db_chksum((u_int8_t *)&secs, sizeof(secs), NULL,
+ __db_chksum(NULL, (u_int8_t *)&secs, sizeof(secs), NULL,
(u_int8_t *)&seed);
} while (seed == 0);
- __db_sgenrand((long)seed, dbenv->mt, &dbenv->mti);
+ __db_sgenrand((long)seed, dbenv->mt, &dbenv->mti);
}
for (kk=0;kk<N-M;kk++) {
@@ -176,12 +175,12 @@ __db_genrand(dbenv)
dbenv->mti = 0;
}
-
+
y = dbenv->mt[dbenv->mti++];
y ^= TEMPERING_SHIFT_U(y);
y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
y ^= TEMPERING_SHIFT_L(y);
- return y;
+ return y;
}
diff --git a/db/crypto/rijndael/rijndael-alg-fst.c b/db/crypto/rijndael/rijndael-alg-fst.c
index 4a251606d..f37b953ac 100644
--- a/db/crypto/rijndael/rijndael-alg-fst.c
+++ b/db/crypto/rijndael/rijndael-alg-fst.c
@@ -1350,7 +1350,7 @@ __db_rijndaelEncryptRound(rk, Nr, pt, ct)
(Te4[(s1 >> 8) & 0xff] & 0x0000ff00) ^
(Te4[(s2 ) & 0xff] & 0x000000ff) ^
rk[3];
-
+
s0 = t0;
s1 = t1;
s2 = t2;
diff --git a/db/crypto/rijndael/rijndael-alg-fst.h b/db/crypto/rijndael/rijndael-alg-fst.h
index fe9ce3814..2b9d6a03c 100644
--- a/db/crypto/rijndael/rijndael-alg-fst.h
+++ b/db/crypto/rijndael/rijndael-alg-fst.h
@@ -1,5 +1,5 @@
/*
- * $Id: rijndael-alg-fst.h,v 1.2 2002/01/08 18:53:37 sue Exp $
+ * $Id: rijndael-alg-fst.h,v 12.1 2006/09/08 20:32:03 bostic Exp $
*/
/**
* rijndael-alg-fst.h
@@ -33,8 +33,8 @@
#define MAXKB (256/8)
#define MAXNR 14
-typedef u_int8_t u8;
-typedef u_int16_t u16;
+typedef u_int8_t u8;
+typedef u_int16_t u16;
typedef u_int32_t u32;
#endif /* __RIJNDAEL_ALG_FST_H */
diff --git a/db/crypto/rijndael/rijndael-api-fst.c b/db/crypto/rijndael/rijndael-api-fst.c
index 09475370f..e570de810 100644
--- a/db/crypto/rijndael/rijndael-api-fst.c
+++ b/db/crypto/rijndael/rijndael-api-fst.c
@@ -34,13 +34,8 @@
* Markus Friedl <markus.friedl@informatik.uni-erlangen.de>
* John Skodon <skodonj@webquill.com>
*/
-
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/crypto.h"
@@ -60,7 +55,7 @@ __db_makeKey(key, direction, keyLen, keyMaterial)
char *keyMaterial;
{
u8 cipherKey[MAXKB];
-
+
if (key == NULL) {
return BAD_KEY_INSTANCE;
}
@@ -140,7 +135,7 @@ __db_blockEncrypt(cipher, key, input, inputLen, outBuffer)
}
numBlocks = (int)(inputLen/128);
-
+
switch (cipher->mode) {
case MODE_ECB:
for (i = numBlocks; i > 0; i--) {
@@ -149,7 +144,7 @@ __db_blockEncrypt(cipher, key, input, inputLen, outBuffer)
outBuffer += 16;
}
break;
-
+
case MODE_CBC:
iv = cipher->IV;
for (i = numBlocks; i > 0; i--) {
@@ -185,7 +180,7 @@ __db_blockEncrypt(cipher, key, input, inputLen, outBuffer)
default:
return BAD_CIPHER_STATE;
}
-
+
return 128*numBlocks;
}
@@ -235,7 +230,7 @@ __db_padEncrypt(cipher, key, input, inputOctets, outBuffer)
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16*numBlocks);
- DB_ASSERT(padLen > 0 && padLen <= 16);
+ DB_ASSERT(NULL, padLen > 0 && padLen <= 16);
memcpy(block, input, 16 - padLen);
memset(block + 16 - padLen, padLen, padLen);
__db_rijndaelEncrypt(key->rk, key->Nr, block, outBuffer);
@@ -255,7 +250,7 @@ __db_padEncrypt(cipher, key, input, inputOctets, outBuffer)
outBuffer += 16;
}
padLen = 16 - (inputOctets - 16*numBlocks);
- DB_ASSERT(padLen > 0 && padLen <= 16);
+ DB_ASSERT(NULL, padLen > 0 && padLen <= 16);
for (i = 0; i < 16 - padLen; i++) {
block[i] = input[i] ^ iv[i];
}
@@ -309,7 +304,7 @@ __db_blockDecrypt(cipher, key, input, inputLen, outBuffer)
outBuffer += 16;
}
break;
-
+
case MODE_CBC:
memcpy(tmpiv, cipher->IV, MAX_IV_SIZE);
for (i = numBlocks; i > 0; i--) {
@@ -345,7 +340,7 @@ __db_blockDecrypt(cipher, key, input, inputLen, outBuffer)
default:
return BAD_CIPHER_STATE;
}
-
+
return 128*numBlocks;
}
@@ -402,7 +397,7 @@ __db_padDecrypt(cipher, key, input, inputOctets, outBuffer)
}
memcpy(outBuffer, block, 16 - padLen);
break;
-
+
case MODE_CBC:
/* all blocks but last */
memcpy(tmpiv, cipher->IV, MAX_IV_SIZE);
@@ -434,11 +429,11 @@ __db_padDecrypt(cipher, key, input, inputOctets, outBuffer)
}
memcpy(outBuffer, block, 16 - padLen);
break;
-
+
default:
return BAD_CIPHER_STATE;
}
-
+
return 16*numBlocks - padLen;
}
@@ -447,7 +442,7 @@ __db_padDecrypt(cipher, key, input, inputOctets, outBuffer)
* cipherUpdateRounds:
*
* Encrypts/Decrypts exactly one full block a specified number of rounds.
- * Only used in the Intermediate Value Known Answer Test.
+ * Only used in the Intermediate Value Known Answer Test.
*
* Returns:
* TRUE - on success
@@ -480,17 +475,17 @@ __db_cipherUpdateRounds(cipher, key, input, inputLen, outBuffer, rounds)
case DIR_ENCRYPT:
__db_rijndaelEncryptRound(key->rk, key->Nr, block, rounds);
break;
-
+
case DIR_DECRYPT:
__db_rijndaelDecryptRound(key->rk, key->Nr, block, rounds);
break;
-
+
default:
return BAD_KEY_DIR;
- }
+ }
memcpy(outBuffer, block, 16);
-
+
return TRUE;
}
#endif /* INTERMEDIATE_VALUE_KAT */
diff --git a/db/crypto/rijndael/rijndael-api-fst.h b/db/crypto/rijndael/rijndael-api-fst.h
index 4137aa25e..caf0abc4a 100644
--- a/db/crypto/rijndael/rijndael-api-fst.h
+++ b/db/crypto/rijndael/rijndael-api-fst.h
@@ -1,5 +1,5 @@
/*
- * $Id: rijndael-api-fst.h,v 1.5 2003/03/17 19:42:18 bostic Exp $
+ * $Id: rijndael-api-fst.h,v 12.0 2004/11/17 03:43:17 bostic Exp $
*/
/**
* rijndael-api-fst.h