Page MenuHomeFreeBSD

D19411.diff
No OneTemporary

D19411.diff

Index: head/sys/dev/random/fortuna.c
===================================================================
--- head/sys/dev/random/fortuna.c
+++ head/sys/dev/random/fortuna.c
@@ -308,20 +308,16 @@
static __inline void
random_fortuna_genblocks(uint8_t *buf, u_int blockcount)
{
- u_int i;
RANDOM_RESEED_ASSERT_LOCK_OWNED();
KASSERT(!uint128_is_zero(fortuna_state.fs_counter), ("FS&K: C != 0"));
- for (i = 0; i < blockcount; i++) {
- /*-
- * FS&K - r = r|E(K,C)
- * - C = C + 1
- */
- randomdev_encrypt(&fortuna_state.fs_key, &fortuna_state.fs_counter, buf, RANDOM_BLOCKSIZE);
- buf += RANDOM_BLOCKSIZE;
- uint128_increment(&fortuna_state.fs_counter);
- }
+ /*
+ * Fills buf with RANDOM_BLOCKSIZE * blockcount bytes of keystream.
+ * Increments fs_counter as it goes.
+ */
+ randomdev_keystream(&fortuna_state.fs_key, &fortuna_state.fs_counter,
+ buf, blockcount);
}
/*-
Index: head/sys/dev/random/hash.h
===================================================================
--- head/sys/dev/random/hash.h
+++ head/sys/dev/random/hash.h
@@ -29,6 +29,8 @@
#ifndef SYS_DEV_RANDOM_HASH_H_INCLUDED
#define SYS_DEV_RANDOM_HASH_H_INCLUDED
+#include <dev/random/uint128.h>
+
/* Keys are formed from cipher blocks */
#define RANDOM_KEYSIZE 32 /* (in bytes) == 256 bits */
#define RANDOM_KEYSIZE_WORDS (RANDOM_KEYSIZE/sizeof(uint32_t))
@@ -52,6 +54,6 @@
void randomdev_hash_iterate(struct randomdev_hash *, const void *, size_t);
void randomdev_hash_finish(struct randomdev_hash *, void *);
void randomdev_encrypt_init(struct randomdev_key *, const void *);
-void randomdev_encrypt(struct randomdev_key *context, const void *, void *, u_int);
+void randomdev_keystream(struct randomdev_key *context, uint128_t *, void *, u_int);
#endif /* SYS_DEV_RANDOM_HASH_H_INCLUDED */
Index: head/sys/dev/random/hash.c
===================================================================
--- head/sys/dev/random/hash.c
+++ head/sys/dev/random/hash.c
@@ -88,13 +88,26 @@
rijndael_makeKey(&context->key, DIR_ENCRYPT, RANDOM_KEYSIZE*8, data);
}
-/* Encrypt the supplied data using the key schedule preset in the context.
- * <length> bytes are encrypted from <*d_in> to <*d_out>. <length> must be
- * a multiple of RANDOM_BLOCKSIZE.
+/*
+ * Create a psuedorandom output stream of 'blockcount' blocks using a CTR-mode
+ * cipher or similar. The 128-bit counter is supplied in the in-out parmeter
+ * 'ctr.' The output stream goes to 'd_out.' 'blockcount' RANDOM_BLOCKSIZE
+ * bytes are generated.
*/
void
-randomdev_encrypt(struct randomdev_key *context, const void *d_in, void *d_out, u_int length)
+randomdev_keystream(struct randomdev_key *context, uint128_t *ctr,
+ void *d_out, u_int blockcount)
{
+ u_int i;
- rijndael_blockEncrypt(&context->cipher, &context->key, d_in, length*8, d_out);
+ for (i = 0; i < blockcount; i++) {
+ /*-
+ * FS&K - r = r|E(K,C)
+ * - C = C + 1
+ */
+ rijndael_blockEncrypt(&context->cipher, &context->key,
+ (void *)ctr, RANDOM_BLOCKSIZE * 8, d_out);
+ d_out = (char *)d_out + RANDOM_BLOCKSIZE;
+ uint128_increment(ctr);
+ }
}

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 28, 7:46 PM (3 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17833041
Default Alt Text
D19411.diff (3 KB)

Event Timeline