make SWAP_KEY_GET symmetrical with SWAP_KEY_PUT by having it call
authordlg <dlg@openbsd.org>
Wed, 6 May 2015 04:00:10 +0000 (04:00 +0000)
committerdlg <dlg@openbsd.org>
Wed, 6 May 2015 04:00:10 +0000 (04:00 +0000)
a function in uvm_swap_encrypt.c instead of doing stuff inline.

lets me remove an extern from the header too.

ok kettenis@

sys/uvm/uvm_swap_encrypt.c
sys/uvm/uvm_swap_encrypt.h

index ae76454..71406f1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_swap_encrypt.c,v 1.21 2015/05/04 10:21:15 dlg Exp $       */
+/*     $OpenBSD: uvm_swap_encrypt.c,v 1.22 2015/05/06 04:00:10 dlg Exp $       */
 
 /*
  * Copyright 1999 Niels Provos <provos@citi.umich.edu>
@@ -87,6 +87,13 @@ swap_encrypt_ctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
        /* NOTREACHED */
 }
 
+void
+swap_key_create(struct swap_key *key)
+{
+       arc4random_buf(key->key, sizeof(key->key));
+       uvm_swpkeyscreated++;
+}
+
 void
 swap_key_delete(struct swap_key *key)
 {
index 3545ae0..e883f6b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_swap_encrypt.h,v 1.9 2009/03/23 22:10:04 oga Exp $        */
+/*     $OpenBSD: uvm_swap_encrypt.h,v 1.10 2015/05/06 04:00:10 dlg Exp $       */
 
 /*
  * Copyright 1999 Niels Provos <provos@citi.umich.edu>
@@ -61,13 +61,9 @@ 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);
 
-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++;   \
+                                               swap_key_create(x);     \
                                        }                               \
                                        (x)->refcount++;                \
                                } while(0);
@@ -79,6 +75,7 @@ extern u_int uvm_swpkeyscreated;
                                        }                               \
                                } while(0);
 
+void swap_key_create(struct swap_key *);
 void swap_key_delete(struct swap_key *);
 
 extern int uvm_doswapencrypt;          /* swapencrypt enabled/disabled */