From: Simon Wilkinson Date: Sat, 11 Sep 2010 12:02:49 +0000 (+0100) Subject: Unix CM: Add osi_crypto crypto interface X-Git-Tag: openafs-devel-1_7_1~935 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=b4350fab31ab91373caac4601d26cd0451da0aa4 Unix CM: Add osi_crypto crypto interface Add a new osi file to the cache manager. This file includes functions which interface hcrypto with the kernel's own cryptography library. At the moment, the only such function is osi_readRandom which returns a block of random data from the kernel's PRNG. Change-Id: Ib728f5bb638ef634efe4822da24bb7cca723983f Reviewed-on: http://gerrit.openafs.org/3944 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/afs/DARWIN/osi_crypto.c b/src/afs/DARWIN/osi_crypto.c new file mode 100644 index 0000000..0e52d91 --- /dev/null +++ b/src/afs/DARWIN/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + read_random(data, len); + return 0; +} diff --git a/src/afs/FBSD/osi_crypto.c b/src/afs/FBSD/osi_crypto.c new file mode 100644 index 0000000..0e52d91 --- /dev/null +++ b/src/afs/FBSD/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + read_random(data, len); + return 0; +} diff --git a/src/afs/LINUX/osi_crypto.c b/src/afs/LINUX/osi_crypto.c new file mode 100644 index 0000000..ead1916 --- /dev/null +++ b/src/afs/LINUX/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + get_random_bytes(data, len); + return 0; +} diff --git a/src/afs/LINUX24/osi_crypto.c b/src/afs/LINUX24/osi_crypto.c new file mode 100644 index 0000000..ead1916 --- /dev/null +++ b/src/afs/LINUX24/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + get_random_bytes(data, len); + return 0; +} diff --git a/src/afs/NBSD/osi_crypto.c b/src/afs/NBSD/osi_crypto.c new file mode 100644 index 0000000..134d458 --- /dev/null +++ b/src/afs/NBSD/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + rnd_extract_data(data, len, RND_EXTRACT_ANY); + return 0; +} diff --git a/src/afs/OBSD/osi_crypto.c b/src/afs/OBSD/osi_crypto.c new file mode 100644 index 0000000..f992061 --- /dev/null +++ b/src/afs/OBSD/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + arc4random_buf(data, len); + return 0; +} diff --git a/src/afs/SOLARIS/osi_crypto.c b/src/afs/SOLARIS/osi_crypto.c new file mode 100644 index 0000000..0b09445 --- /dev/null +++ b/src/afs/SOLARIS/osi_crypto.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Your Filesystem Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "afs/param.h" + +#include + +int +osi_readRandom(void *data, afs_size_t len) { + random_get_pseudo_bytes(data, len); + return 0; +} diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index acf1d32..24a7d50 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -618,6 +618,9 @@ extern int afs_linux_storeproc(struct vcache *, struct storeOps *, void *, struct dcache *, int *, afs_size_t *); #endif +/* ARCH/osi_crypto.c */ +extern int osi_readRandom(void *, afs_size_t); + /* ARCH/osi_misc.c */ extern void afs_osi_SetTime(osi_timeval_t * atv); diff --git a/src/libafs/Makefile.common.in b/src/libafs/Makefile.common.in index e0d5eb6..55419f5 100644 --- a/src/libafs/Makefile.common.in +++ b/src/libafs/Makefile.common.in @@ -553,6 +553,8 @@ osi_fetchstore.o: $(TOP_SRCDIR)/afs/$(MKAFS_OSTYPE)/osi_fetchstore.c $(CRULE_NOOPT) osi_vcache.o: $(TOP_SRCDIR)/afs/$(MKAFS_OSTYPE)/osi_vcache.c $(CRULE_NOOPT) +osi_crypto.o: $(TOP_SRCDIR)/afs/$(MKAFS_OSTYPE)/osi_crypto.c + $(CRULE_OPT) clean: -$(RM) -rf STATIC* MODLOAD* $(AFS_OS_CLEAN) diff --git a/src/libafs/MakefileProto.DARWIN.in b/src/libafs/MakefileProto.DARWIN.in index bc2cd5d..3141931 100644 --- a/src/libafs/MakefileProto.DARWIN.in +++ b/src/libafs/MakefileProto.DARWIN.in @@ -18,6 +18,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ # OS specific object files: AFS_OS_OBJS = \ + osi_crypto.o \ osi_misc.o \ osi_file.o \ osi_inode.o \ diff --git a/src/libafs/MakefileProto.FBSD.in b/src/libafs/MakefileProto.FBSD.in index 0e682af..3bb4a62 100644 --- a/src/libafs/MakefileProto.FBSD.in +++ b/src/libafs/MakefileProto.FBSD.in @@ -15,6 +15,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ # OS specific object files: AFS_OS_OBJS = \ + osi_crypto.o \ osi_gcpags.o \ osi_groups.o \ osi_file.o \ diff --git a/src/libafs/MakefileProto.LINUX.in b/src/libafs/MakefileProto.LINUX.in index 655c0ce..e4f0d67 100644 --- a/src/libafs/MakefileProto.LINUX.in +++ b/src/libafs/MakefileProto.LINUX.in @@ -23,6 +23,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ AFS_OS_OBJS = \ osi_alloc.o \ osi_cred.o \ + osi_crypto.o \ osi_gcpags.o \ osi_groups.o \ osi_inode.o \ diff --git a/src/libafs/MakefileProto.NBSD.in b/src/libafs/MakefileProto.NBSD.in index 3375c15..892dea2 100644 --- a/src/libafs/MakefileProto.NBSD.in +++ b/src/libafs/MakefileProto.NBSD.in @@ -15,6 +15,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ # OS specific object files: AFS_OS_OBJS = \ + osi_crypto.o \ osi_gcpags.o \ osi_groups.o \ osi_file.o \ diff --git a/src/libafs/MakefileProto.OBSD.in b/src/libafs/MakefileProto.OBSD.in index 47daf33..3e3beaa 100644 --- a/src/libafs/MakefileProto.OBSD.in +++ b/src/libafs/MakefileProto.OBSD.in @@ -36,6 +36,7 @@ KOBJ = MODLOAD # OS specific object files: AFS_OS_OBJS = \ + osi_crypto.o \ osi_gcpags.o \ osi_groups.o \ osi_file.o \ diff --git a/src/libafs/MakefileProto.SOLARIS.in b/src/libafs/MakefileProto.SOLARIS.in index 4d96272..ff10d5b 100644 --- a/src/libafs/MakefileProto.SOLARIS.in +++ b/src/libafs/MakefileProto.SOLARIS.in @@ -15,6 +15,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ # OS specific object files: AFS_OS_OBJS = \ + osi_crypto.o \ osi_gcpags.o \ osi_groups.o \ osi_inode.o \