- (djm) [ed25519.c ssh-ed25519.c openbsd-compat/Makefile.in]

[openbsd-compat/bcrypt_pbkdf.c] Make ed25519/new key format compile on
       Linux
This commit is contained in:
Damien Miller 2013-12-07 12:37:53 +11:00
parent 1ff130dac9
commit f104da263d
5 changed files with 31 additions and 33 deletions

View File

@ -33,14 +33,17 @@
- djm@cvs.openbsd.org 2013/12/07 00:19:15 - djm@cvs.openbsd.org 2013/12/07 00:19:15
[key.c] [key.c]
set k->cert = NULL after freeing it set k->cert = NULL after freeing it
- [blocks.c ed25519.c fe25519.c fe25519.h ge25519.c ge25519.h] - (djm) [blocks.c ed25519.c fe25519.c fe25519.h ge25519.c ge25519.h]
[ge25519_base.data hash.c sc25519.c sc25519.h verify.c] Fix RCS idents [ge25519_base.data hash.c sc25519.c sc25519.h verify.c] Fix RCS idents
- [Makefile.in] Add ed25519 sources - (djm) [Makefile.in] Add ed25519 sources
- [authfile.c] Conditionalise inclusion of util.h - (djm) [authfile.c] Conditionalise inclusion of util.h
- [configure.ac openbsd-compat/Makefile.in openbsd-compat/bcrypt_pbkdf.c] - (djm) [configure.ac openbsd-compat/Makefile.in openbsd-compat/bcrypt_pbkdf.c]
[openbsd-compat/blf.h openbsd-compat/blowfish.c] [openbsd-compat/blf.h openbsd-compat/blowfish.c]
[openbsd-compat/openbsd-compat.h] Start at supporting bcrypt_pbkdf in [openbsd-compat/openbsd-compat.h] Start at supporting bcrypt_pbkdf in
portable. portable.
- (djm) [ed25519.c ssh-ed25519.c openbsd-compat/Makefile.in]
[openbsd-compat/bcrypt_pbkdf.c] Make ed25519/new key format compile on
Linux
20131205 20131205
- (djm) OpenBSD CVS Sync - (djm) OpenBSD CVS Sync

View File

@ -2,6 +2,7 @@
/* Public Domain, from supercop-20130419/crypto_sign/ed25519/ref/ed25519.c */ /* Public Domain, from supercop-20130419/crypto_sign/ed25519/ref/ed25519.c */
#include "includes.h"
#include "crypto_api.h" #include "crypto_api.h"
#include "ge25519.h" #include "ge25519.h"

View File

@ -1,4 +1,4 @@
# $Id: Makefile.in,v 1.53 2013/12/07 00:51:54 djm Exp $ # $Id: Makefile.in,v 1.54 2013/12/07 01:37:54 djm Exp $
sysconfdir=@sysconfdir@ sysconfdir=@sysconfdir@
piddir=@piddir@ piddir=@piddir@
@ -16,7 +16,7 @@ RANLIB=@RANLIB@
INSTALL=@INSTALL@ INSTALL=@INSTALL@
LDFLAGS=-L. @LDFLAGS@ LDFLAGS=-L. @LDFLAGS@
OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sha2.o sigact.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o
COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xmmap.o xcrypt.o

View File

@ -24,18 +24,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <util.h>
#ifdef HAVE_BLF_H #ifdef HAVE_BLF_H
# include <blf.h> # include <blf.h>
#endif #endif
#ifdef HAVE_SHA256_UPDATE
# ifdef HAVE_SHA2_H #include "crypto_api.h"
# include <sha2.h> #define SHA512_DIGEST_LENGTH crypto_hash_sha512_BYTES
# elif defined(HAVE_CRYPTO_SHA2_H)
# include <crypto/sha2.h>
# endif
#endif
/* /*
* pkcs #5 pbkdf2 implementation using the "bcrypt" hash * pkcs #5 pbkdf2 implementation using the "bcrypt" hash
@ -109,12 +104,11 @@ int
bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t saltlen, bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t saltlen,
u_int8_t *key, size_t keylen, unsigned int rounds) u_int8_t *key, size_t keylen, unsigned int rounds)
{ {
SHA2_CTX ctx;
u_int8_t sha2pass[SHA512_DIGEST_LENGTH]; u_int8_t sha2pass[SHA512_DIGEST_LENGTH];
u_int8_t sha2salt[SHA512_DIGEST_LENGTH]; u_int8_t sha2salt[SHA512_DIGEST_LENGTH];
u_int8_t out[BCRYPT_HASHSIZE]; u_int8_t out[BCRYPT_HASHSIZE];
u_int8_t tmpout[BCRYPT_HASHSIZE]; u_int8_t tmpout[BCRYPT_HASHSIZE];
u_int8_t countsalt[4]; u_int8_t *countsalt;
size_t i, j, amt, stride; size_t i, j, amt, stride;
uint32_t count; uint32_t count;
@ -122,37 +116,34 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t salt
if (rounds < 1) if (rounds < 1)
return -1; return -1;
if (passlen == 0 || saltlen == 0 || keylen == 0 || if (passlen == 0 || saltlen == 0 || keylen == 0 ||
keylen > sizeof(out) * sizeof(out)) keylen > sizeof(out) * sizeof(out) || saltlen > 1<<20)
return -1;
if ((countsalt = calloc(1, saltlen + 4)) == NULL)
return -1; return -1;
stride = (keylen + sizeof(out) - 1) / sizeof(out); stride = (keylen + sizeof(out) - 1) / sizeof(out);
amt = (keylen + stride - 1) / stride; amt = (keylen + stride - 1) / stride;
/* collapse password */ memcpy(countsalt, salt, saltlen);
SHA512Init(&ctx);
SHA512Update(&ctx, pass, passlen);
SHA512Final(sha2pass, &ctx);
/* collapse password */
crypto_hash_sha512(sha2pass, pass, passlen);
/* generate key, sizeof(out) at a time */ /* generate key, sizeof(out) at a time */
for (count = 1; keylen > 0; count++) { for (count = 1; keylen > 0; count++) {
countsalt[0] = (count >> 24) & 0xff; countsalt[saltlen + 0] = (count >> 24) & 0xff;
countsalt[1] = (count >> 16) & 0xff; countsalt[saltlen + 1] = (count >> 16) & 0xff;
countsalt[2] = (count >> 8) & 0xff; countsalt[saltlen + 2] = (count >> 8) & 0xff;
countsalt[3] = count & 0xff; countsalt[saltlen + 3] = count & 0xff;
/* first round, salt is salt */ /* first round, salt is salt */
SHA512Init(&ctx); crypto_hash_sha512(sha2salt, countsalt, saltlen + 4);
SHA512Update(&ctx, salt, saltlen);
SHA512Update(&ctx, countsalt, sizeof(countsalt));
SHA512Final(sha2salt, &ctx);
bcrypt_hash(sha2pass, sha2salt, tmpout); bcrypt_hash(sha2pass, sha2salt, tmpout);
memcpy(out, tmpout, sizeof(out)); memcpy(out, tmpout, sizeof(out));
for (i = 1; i < rounds; i++) { for (i = 1; i < rounds; i++) {
/* subsequent rounds, salt is previous output */ /* subsequent rounds, salt is previous output */
SHA512Init(&ctx); crypto_hash_sha512(sha2salt, tmpout, sizeof(tmpout));
SHA512Update(&ctx, tmpout, sizeof(tmpout));
SHA512Final(sha2salt, &ctx);
bcrypt_hash(sha2pass, sha2salt, tmpout); bcrypt_hash(sha2pass, sha2salt, tmpout);
for (j = 0; j < sizeof(out); j++) for (j = 0; j < sizeof(out); j++)
out[j] ^= tmpout[j]; out[j] ^= tmpout[j];
@ -168,8 +159,9 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t salt
} }
/* zap */ /* zap */
memset(&ctx, 0, sizeof(ctx));
memset(out, 0, sizeof(out)); memset(out, 0, sizeof(out));
memset(countsalt, 0, saltlen + 4);
free(countsalt);
return 0; return 0;
} }

View File

@ -15,6 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "includes.h"
#include <sys/types.h> #include <sys/types.h>
#include "crypto_api.h" #include "crypto_api.h"