summaryrefslogtreecommitdiff
path: root/db/hmac
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/hmac
parentb754fe19fd387ca5fe8e7c00ddaa25c898fa192f (diff)
downloadrpm-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.gz
rpm-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.tar.bz2
rpm-2cfd3012bfcb5c5c61bbaf662ef084e0ab789d79.zip
Update internal BDB to version 4.5.20
Diffstat (limited to 'db/hmac')
-rw-r--r--db/hmac/hmac.c74
-rw-r--r--db/hmac/sha1.c26
2 files changed, 63 insertions, 37 deletions
diff --git a/db/hmac/hmac.c b/db/hmac/hmac.c
index bb2da5eb4..8edadd640 100644
--- a/db/hmac/hmac.c
+++ b/db/hmac/hmac.c
@@ -1,26 +1,23 @@
/*-
* 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: hmac.c,v 1.27 2004/01/28 03:36:11 bostic Exp $
+ * $Id: hmac.c,v 12.9 2006/09/09 14:28:23 bostic Exp $
*/
#include "db_config.h"
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
#include "db_int.h"
#include "dbinc/crypto.h"
#include "dbinc/db_page.h" /* for hash.h only */
#include "dbinc/hash.h"
#include "dbinc/hmac.h"
+#include "dbinc/log.h"
#define HMAC_OUTPUT_SIZE 20
#define HMAC_BLOCK_SIZE 64
@@ -79,10 +76,12 @@ __db_hmac(k, data, data_len, mac)
* __db_chksum --
* Create a MAC/SHA1 checksum.
*
- * PUBLIC: void __db_chksum __P((u_int8_t *, size_t, u_int8_t *, u_int8_t *));
+ * PUBLIC: void __db_chksum __P((void *,
+ * PUBLIC: u_int8_t *, size_t, u_int8_t *, u_int8_t *));
*/
void
-__db_chksum(data, data_len, mac_key, store)
+__db_chksum(hdr, data, data_len, mac_key, store)
+ void *hdr;
u_int8_t *data;
size_t data_len;
u_int8_t *mac_key;
@@ -90,27 +89,37 @@ __db_chksum(data, data_len, mac_key, store)
{
int sumlen;
u_int32_t hash4;
- u_int8_t tmp[DB_MAC_KEY];
/*
* Since the checksum might be on a page of data we are checksumming
* we might be overwriting after checksumming, we zero-out the
* checksum value so that we can have a known value there when
* we verify the checksum.
+ * If we are passed a log header XOR in prev and len so we have
+ * some redundancy on these fields. Mostly we need to be sure that
+ * we detect a race when doing hot backups and reading a live log
+ * file.
*/
if (mac_key == NULL)
sumlen = sizeof(u_int32_t);
else
sumlen = DB_MAC_KEY;
- memset(store, 0, sumlen);
+ if (hdr == NULL)
+ memset(store, 0, sumlen);
+ else
+ store = ((HDR*)hdr)->chksum;
if (mac_key == NULL) {
/* Just a hash, no MAC */
hash4 = __ham_func4(NULL, data, (u_int32_t)data_len);
+ if (hdr != NULL)
+ hash4 ^= ((HDR *)hdr)->prev ^ ((HDR *)hdr)->len;
memcpy(store, &hash4, sumlen);
} else {
- memset(tmp, 0, DB_MAC_KEY);
- __db_hmac(mac_key, data, data_len, tmp);
- memcpy(store, tmp, sumlen);
+ __db_hmac(mac_key, data, data_len, store);
+ if (hdr != 0) {
+ ((int *)store)[0] ^= ((HDR *)hdr)->prev;
+ ((int *)store)[1] ^= ((HDR *)hdr)->len;
+ }
}
return;
}
@@ -145,11 +154,12 @@ __db_derive_mac(passwd, plen, mac_key)
* Return 0 on success, >0 (errno) on error, -1 on checksum mismatch.
*
* PUBLIC: int __db_check_chksum __P((DB_ENV *,
- * PUBLIC: DB_CIPHER *, u_int8_t *, void *, size_t, int));
+ * PUBLIC: void *, DB_CIPHER *, u_int8_t *, void *, size_t, int));
*/
int
-__db_check_chksum(dbenv, db_cipher, chksum, data, data_len, is_hmac)
+__db_check_chksum(dbenv, hdr, db_cipher, chksum, data, data_len, is_hmac)
DB_ENV *dbenv;
+ void *hdr;
DB_CIPHER *db_cipher;
u_int8_t *chksum;
void *data;
@@ -168,7 +178,7 @@ __db_check_chksum(dbenv, db_cipher, chksum, data, data_len, is_hmac)
*/
if (is_hmac == 0) {
if (db_cipher != NULL) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Unencrypted checksum with a supplied encryption key");
return (EINVAL);
}
@@ -176,7 +186,7 @@ __db_check_chksum(dbenv, db_cipher, chksum, data, data_len, is_hmac)
mac_key = NULL;
} else {
if (db_cipher == NULL) {
- __db_err(dbenv,
+ __db_errx(dbenv,
"Encrypted checksum: no encryption key specified");
return (EINVAL);
}
@@ -189,16 +199,36 @@ __db_check_chksum(dbenv, db_cipher, chksum, data, data_len, is_hmac)
* Since the checksum might be on the page, we need to have known data
* there so that we can generate the same original checksum. We zero
* it out, just like we do in __db_chksum above.
+ * If there is a log header, XOR the prev and len fields.
*/
- memcpy(old, chksum, sum_len);
- memset(chksum, 0, sum_len);
+retry:
+ if (hdr == NULL) {
+ memcpy(old, chksum, sum_len);
+ memset(chksum, 0, sum_len);
+ chksum = old;
+ }
+
if (mac_key == NULL) {
/* Just a hash, no MAC */
hash4 = __ham_func4(NULL, data, (u_int32_t)data_len);
- ret = memcmp((u_int32_t *)old, &hash4, sum_len) ? -1 : 0;
+ if (hdr != NULL)
+ LOG_HDR_SUM(0, hdr, &hash4);
+ ret = memcmp((u_int32_t *)chksum, &hash4, sum_len) ? -1 : 0;
} else {
__db_hmac(mac_key, data, data_len, new);
- ret = memcmp(old, new, sum_len) ? -1 : 0;
+ if (hdr != NULL)
+ LOG_HDR_SUM(1, hdr, new);
+ ret = memcmp(chksum, new, sum_len) ? -1 : 0;
+ }
+ /*
+ * !!!
+ * We might be looking at an old log even with the new
+ * code. So, if we have a hdr, and the checksum doesn't
+ * match, try again without a hdr.
+ */
+ if (hdr != NULL && ret != 0) {
+ hdr = NULL;
+ goto retry;
}
return (ret);
diff --git a/db/hmac/sha1.c b/db/hmac/sha1.c
index 8824796f0..b3fdf7eb0 100644
--- a/db/hmac/sha1.c
+++ b/db/hmac/sha1.c
@@ -1,16 +1,19 @@
/*
- * $Id: sha1.c,v 1.14 2004/01/28 03:36:11 bostic Exp $
+ * $Id: sha1.c,v 12.2 2006/09/08 20:32:10 bostic Exp $
*/
#include "db_config.h"
+#include "db_int.h"
+#include "dbinc/hmac.h"
+
/*
SHA-1 in C
By Steve Reid <sreid@sea-to-sky.net>
100% Public Domain
-----------------
-Modified 7/98
+Modified 7/98
By James H. Brown <jbrown@burgoyne.com>
Still 100% Public Domain
@@ -32,7 +35,7 @@ Since the file IO in main() reads 16K at a time, any file 8K or larger would
be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
"a"s).
-I also changed the declaration of variables i & j in SHA1Update to
+I also changed the declaration of variables i & j in SHA1Update to
unsigned long from unsigned int for the same reason.
These changes should make no difference to any 32 bit implementations since
@@ -59,7 +62,7 @@ Still 100% public domain
Modified 4/01
By Saul Kravitz <Saul.Kravitz@celera.com>
Still 100% PD
-Modified to run on Compaq Alpha hardware.
+Modified to run on Compaq Alpha hardware.
*/
@@ -76,13 +79,6 @@ A million repetitions of "a"
#define SHA1HANDSOFF
-#ifndef NO_SYSTEM_INCLUDES
-#include <string.h>
-#endif
-
-#include "db_int.h"
-#include "dbinc/hmac.h"
-
/* #include <process.h> */ /* prototype for exit() - JHB */
/* Using return() instead of exit() - SWR */
@@ -113,7 +109,7 @@ __db_SHAPrintContext(context, msg)
{
printf("%s (%d,%d) %x %x %x %x %x\n",
msg,
- context->count[0], context->count[1],
+ context->count[0], context->count[1],
context->state[0],
context->state[1],
context->state[2],
@@ -126,7 +122,7 @@ __db_SHAPrintContext(context, msg)
/*
* __db_SHA1Transform --
- *
+ *
* PUBLIC: void __db_SHA1Transform __P((u_int32_t *, unsigned char *));
*/
void
@@ -191,7 +187,7 @@ static int is_bigendian = -1;
/* SHA1Init - Initialize new context */
-/*
+/*
* __db_SHA1Init --
* Initialize new context
*
@@ -290,6 +286,6 @@ unsigned char finalcount[8];
__db_SHA1Transform(context->state, context->buffer);
#endif
}
-
+
/*************************************************************/