diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-03-23 22:07:42 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2009-03-23 22:07:42 +0000 |
commit | 4fe12823a6c86e647cfd8ad32feedf50ad6f06bf (patch) | |
tree | 4a5e6cc6a464341731cfd3807f344d6e783cf349 | |
parent | bfec2c4397630d66d4a7037c0f0e4ddbe16352b3 (diff) |
turn a for (i = 0; i < size; i++) arc4random(); loop into arc4random_buf().
Since that function is now so small (2 lines), inline it into it's only user.
Shaves some bytes (104 on amd64).
ok deraadt@, blambert@. djm@ liked an earlier diff.
-rw-r--r-- | sys/uvm/uvm_swap.c | 3 | ||||
-rw-r--r-- | sys/uvm/uvm_swap_encrypt.c | 15 | ||||
-rw-r--r-- | sys/uvm/uvm_swap_encrypt.h | 29 |
3 files changed, 21 insertions, 26 deletions
diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index c32844a1425..38de9a4ec46 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.86 2009/03/20 15:19:04 oga Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.87 2009/03/23 22:07:41 oga Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -52,6 +52,7 @@ #include <uvm/uvm.h> #ifdef UVM_SWAP_ENCRYPT +#include <dev/rndvar.h> #include <sys/syslog.h> #endif diff --git a/sys/uvm/uvm_swap_encrypt.c b/sys/uvm/uvm_swap_encrypt.c index b3b22385680..66acf3880ae 100644 --- a/sys/uvm/uvm_swap_encrypt.c +++ b/sys/uvm/uvm_swap_encrypt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap_encrypt.c,v 1.14 2005/03/26 16:06:46 deraadt Exp $ */ +/* $OpenBSD: uvm_swap_encrypt.c,v 1.15 2009/03/23 22:07:41 oga Exp $ */ /* * Copyright 1999 Niels Provos <provos@citi.umich.edu> @@ -89,19 +89,6 @@ swap_encrypt_ctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, } void -swap_key_create(struct swap_key *key) -{ - int i; - u_int32_t *p = key->key; - - key->refcount = 0; - for (i = 0; i < sizeof(key->key) / sizeof(u_int32_t); i++) - *p++ = arc4random(); - - uvm_swpkeyscreated++; -} - -void swap_key_delete(struct swap_key *key) { /* Make sure that this key gets removed if we just used it */ diff --git a/sys/uvm/uvm_swap_encrypt.h b/sys/uvm/uvm_swap_encrypt.h index 63d237062e2..101420527a9 100644 --- a/sys/uvm/uvm_swap_encrypt.h +++ b/sys/uvm/uvm_swap_encrypt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap_encrypt.h,v 1.7 2002/07/02 19:38:55 nate Exp $ */ +/* $OpenBSD: uvm_swap_encrypt.h,v 1.8 2009/03/23 22:07:41 oga Exp $ */ /* * Copyright 1999 Niels Provos <provos@citi.umich.edu> @@ -61,17 +61,24 @@ void swap_decrypt(struct swap_key *,caddr_t, caddr_t, u_int64_t, size_t); void swap_key_cleanup(struct swap_key *); void swap_key_prepare(struct swap_key *, int); -#define SWAP_KEY_GET(s,x) do { if ((x)->refcount == 0) {\ - swap_key_create(x); \ - } \ - (x)->refcount++; } while(0); -#define SWAP_KEY_PUT(s,x) do { (x)->refcount--; \ - if ((x)->refcount == 0) { \ - swap_key_delete(x); \ - } \ - } while(0); +extern u_int uvm_swpkeyscreated; + +#define SWAP_KEY_GET(s,x) do { \ + if ((x)->refcount == 0) { \ + arc4random_buf((x)->key,\ + sizeof((x)->key)); \ + uvm_swpkeyscreated++; \ + } \ + (x)->refcount++; \ + } while(0); + +#define SWAP_KEY_PUT(s,x) do { \ + (x)->refcount--; \ + if ((x)->refcount == 0) { \ + swap_key_delete(x); \ + } \ + } while(0); -void swap_key_create(struct swap_key *); void swap_key_delete(struct swap_key *); extern int uvm_doswapencrypt; /* swapencrypt enabled/disabled */ |