diff options
| author | Greg Hudson <ghudson@mit.edu> | 2011-02-25 17:23:54 +0000 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2011-02-25 17:23:54 +0000 |
| commit | ef7fa87854b1bb71e05884356e4129e200a58529 (patch) | |
| tree | 60d74ade3bd4b3b67616980298e6ddfc2c9c1555 /src/lib/crypto/nss | |
| parent | 920ffa13c22ef8c6ac835a293f5d63f944a82859 (diff) | |
| download | krb5-ef7fa87854b1bb71e05884356e4129e200a58529.tar.gz krb5-ef7fa87854b1bb71e05884356e4129e200a58529.tar.xz krb5-ef7fa87854b1bb71e05884356e4129e200a58529.zip | |
Now that all PRNG modules fit nicely into a single source file,
simplify the PRNG abstraction, flattening the implementations into
crypto/krb and removing the indirection through function pointers.
Move the guts of the NSS PRNG implementation into the nss subdir so
that crypto/krb doesn't need to be built with CRYPTO_IMPL_CFLAGS.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24661 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/nss')
| -rw-r--r-- | src/lib/crypto/nss/Makefile.in | 3 | ||||
| -rw-r--r-- | src/lib/crypto/nss/nss_prng.h | 36 | ||||
| -rw-r--r-- | src/lib/crypto/nss/prng.c | 57 |
3 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/crypto/nss/Makefile.in b/src/lib/crypto/nss/Makefile.in index a1d587887..c2a2e4e9c 100644 --- a/src/lib/crypto/nss/Makefile.in +++ b/src/lib/crypto/nss/Makefile.in @@ -21,16 +21,19 @@ DEFS= STLIBOBJS=\ hmac.o \ pbkdf2.o \ + prng.o \ stubs.o OBJS=\ $(OUTPRE)hmac.$(OBJEXT) \ $(OUTPRE)pbkdf2.$(OBJEXT) \ + $(OUTPRE)prng.$(OBJEXT) \ $(OUTPRE)stubs.$(OBJEXT) SRCS=\ $(srcdir)/hmac.c \ $(srcdir)/pbkdf2.c \ + $(srcdir)/prng.c \ $(srcdir)/stubs.c STOBJLISTS= des/OBJS.ST md4/OBJS.ST \ diff --git a/src/lib/crypto/nss/nss_prng.h b/src/lib/crypto/nss/nss_prng.h new file mode 100644 index 000000000..11bf9edc1 --- /dev/null +++ b/src/lib/crypto/nss/nss_prng.h @@ -0,0 +1,36 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* lib/crypto/nss/nss_prng.h - Declarations for NSS PRNG wrappers */ +/* + * Copyright (C) 2011 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#ifndef NSS_PRNG_H +#define NSS_PRNG_H + +krb5_error_code +k5_nss_prng_add_entropy(krb5_context context, const krb5_data *indata); + +krb5_error_code +k5_nss_prng_make_octets(krb5_context context, krb5_data *outdata); + +#endif /* NSS_PRNG_H */ diff --git a/src/lib/crypto/nss/prng.c b/src/lib/crypto/nss/prng.c new file mode 100644 index 000000000..61039171b --- /dev/null +++ b/src/lib/crypto/nss/prng.c @@ -0,0 +1,57 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* lib/crypto/nss/prng.c - NSS prng functions */ +/* + * Copyright (C) 2011 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "k5-int.h" +#include "nss_gen.h" +#include "nss_prng.h" +#include <pk11pub.h> + +krb5_error_code +k5_nss_prng_add_entropy(krb5_context context, const krb5_data *indata) +{ + krb5_error_code ret; + + ret = k5_nss_init(); + if (ret) + return ret; + if (PK11_RandomUpdate(indata->data, indata->length) != SECSuccess) + return k5_nss_map_last_error(); + return 0; +} + +krb5_error_code +k5_nss_prng_make_octets(krb5_context context, krb5_data *outdata) +{ + krb5_error_code ret; + + ret = k5_nss_init(); + if (ret) + return ret; + if (PK11_GenerateRandom((unsigned char *)outdata->data, + outdata->length) != SECSuccess) + return k5_nss_map_last_error(); + return 0; +} |
