Initial Windows port

This commit is contained in:
Asanka Herath
2009-07-22 15:55:45 -04:00
committed by Love Hornquist Astrand
parent 25a2ac726b
commit b1063ea8fc
361 changed files with 11994 additions and 1334 deletions

242
lib/hcrypto/NTMakefile Normal file
View File

@@ -0,0 +1,242 @@
########################################################################
#
# Copyright (c) 2009, Secure Endpoints 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:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
# "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
# COPYRIGHT HOLDER OR CONTRIBUTORS 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.
#
RELDIR=lib\hcrypto
AUXCFLAGS=$(AUXCFLAGS) -DKRB5 -I$(INCDIR)\hcrypto
!include ../../windows/NTMakefile.w32
# Include files
HCRYPTOINCLUDEDIR=$(INCDIR)\hcrypto
INCFILES= \
$(HCRYPTOINCLUDEDIR)\aes.h \
$(HCRYPTOINCLUDEDIR)\bn.h \
$(HCRYPTOINCLUDEDIR)\des.h \
$(HCRYPTOINCLUDEDIR)\dh.h \
$(HCRYPTOINCLUDEDIR)\dsa.h \
$(HCRYPTOINCLUDEDIR)\engine.h \
$(HCRYPTOINCLUDEDIR)\evp.h \
$(HCRYPTOINCLUDEDIR)\hmac.h \
$(HCRYPTOINCLUDEDIR)\md2.h \
$(HCRYPTOINCLUDEDIR)\md4.h \
$(HCRYPTOINCLUDEDIR)\md5.h \
$(HCRYPTOINCLUDEDIR)\pkcs12.h \
$(HCRYPTOINCLUDEDIR)\rand.h \
$(HCRYPTOINCLUDEDIR)\randi.h \
$(HCRYPTOINCLUDEDIR)\rc2.h \
$(HCRYPTOINCLUDEDIR)\rc4.h \
$(HCRYPTOINCLUDEDIR)\rsa.h \
$(HCRYPTOINCLUDEDIR)\sha.h \
$(HCRYPTOINCLUDEDIR)\ui.h
mkincdir:
!if !exist($(HCRYPTOINCLUDEDIR))
$(MKDIR) $(HCRYPTOINCLUDEDIR)
!endif
{}.h{$(HCRYPTOINCLUDEDIR)}.h:
$(CP) $** $@
all:: mkincdir
all:: $(INCFILES)
# libhcrypto
libhcrypt_OBJs = \
$(OBJ)\imath.obj \
$(OBJ)\iprime.obj \
$(OBJ)\aes.obj \
$(OBJ)\bn.obj \
$(OBJ)\camellia.obj \
$(OBJ)\camellia-ntt.obj \
$(OBJ)\des.obj \
$(OBJ)\dh.obj \
$(OBJ)\dh-imath.obj \
$(OBJ)\dsa.obj \
$(OBJ)\evp.obj \
$(OBJ)\engine.obj \
$(OBJ)\hmac.obj \
$(OBJ)\md2.obj \
$(OBJ)\md4.obj \
$(OBJ)\md5.obj \
$(OBJ)\pkcs5.obj \
$(OBJ)\pkcs12.obj \
$(OBJ)\rand-fortuna.obj \
$(OBJ)\rand-timer.obj \
$(OBJ)\rand.obj \
$(OBJ)\rc2.obj \
$(OBJ)\rc4.obj \
$(OBJ)\rijndael-alg-fst.obj \
$(OBJ)\rnd_keys.obj \
$(OBJ)\rsa.obj \
$(OBJ)\rsa-gmp.obj \
$(OBJ)\rsa-imath.obj \
$(OBJ)\sha.obj \
$(OBJ)\sha256.obj \
$(OBJ)\ui.obj
$(LIBHCRYPTO): $(libhcrypt_OBJs)
$(LIBCON)
{imath/}.c{$(OBJ)}.obj:
$(C2OBJ)
all:: $(LIBHCRYPTO)
clean::
-$(RM) $(LIBHCRYPTO)
# Tests
TESTLIB=$(OBJ)\libhctest.lib
$(TESTLIB): \
$(OBJ)\imath.obj \
$(OBJ)\des.obj \
$(OBJ)\ui.obj
$(LIBCON)
test-binaries: \
$(OBJ)\destest.exe \
$(OBJ)\mdtest.exe \
$(OBJ)\rc2test.exe \
$(OBJ)\rctest.exe \
$(OBJ)\test_bn.exe \
$(OBJ)\test_cipher.exe \
$(OBJ)\test_engine_dso.exe \
$(OBJ)\test_hmac.exe \
$(OBJ)\test_imath.exe \
$(OBJ)\test_pkcs5.exe \
$(OBJ)\test_pkcs12.exe \
$(OBJ)\test_rsa.exe \
$(OBJ)\test_dh.exe \
$(OBJ)\test_rand.exe \
$(OBJ)\test_crypto.sh
$(OBJ)\destest.exe: $(OBJ)\destest.obj $(TESTLIB) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\mdtest.exe: $(OBJ)\mdtest.obj $(LIBHCRYPTO) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\rc2test.exe: $(OBJ)\rc2test.obj $(LIBHCRYPTO) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\rctest.exe: $(OBJ)\rctest.obj $(LIBHCRYPTO) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_bn.exe: $(OBJ)\test_bn.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBASN1)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_cipher.exe: $(OBJ)\test_cipher.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBVERS)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_engine_dso.exe: $(OBJ)\test_engine_dso.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBASN1) $(LIBVERS)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_hmac.exe: $(OBJ)\test_hmac.obj $(LIBHCRYPTO)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_imath.exe: $(OBJ)\test_imath.obj $(TESTLIB) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_pkcs5.exe: $(OBJ)\test_pkcs5.obj $(LIBHCRYPTO) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_pkcs12.exe: $(OBJ)\test_pkcs12.obj $(LIBHCRYPTO) $(LIBASN1) $(LIBROKEN)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_rsa.exe: $(OBJ)\test_rsa.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBASN1) $(LIBVERS)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_dh.exe: $(OBJ)\test_dh.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBASN1) $(LIBVERS)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_rand.exe: $(OBJ)\test_rand.obj $(LIBHCRYPTO) $(LIBROKEN) $(LIBASN1) $(LIBVERS)
$(EXECONLINK)
$(_VC_MANIFEST_EMBED_EXE)
$(_VC_MANIFEST_CLEAN)
$(OBJ)\test_crypto.sh: test_crypto.in NTMakefile
$(SED) -e "s,[@]srcdir[@],$(SRCDIR),g" -e "s,[@]exeext[@],.exe,g" < test_crypto.in > $@
test-run:
cd $(OBJ)
destest.exe
mdtest.exe
rc2test.exe
rctest.exe
test_bn.exe
test_cipher.exe
test_engine_dso.exe
test_hmac.exe
test_imath.exe
test_pkcs5.exe
test_pkcs12.exe
# test_rsa.exe
# test_dh.exe
!ifdef SH
$(SH) test_crypto.sh
!endif
cd $(SRCDIR)
test:: $(TESTLIB) test-binaries test-run

View File

@@ -69,7 +69,7 @@ void AES_encrypt(const unsigned char *, unsigned char *, const AES_KEY *);
void AES_decrypt(const unsigned char *, unsigned char *, const AES_KEY *);
void AES_cbc_encrypt(const unsigned char *, unsigned char *,
const unsigned long, const AES_KEY *,
unsigned long, const AES_KEY *,
unsigned char *, int);
#ifdef __cplusplus

View File

@@ -40,6 +40,7 @@
#include <limits.h>
#include <krb5-types.h>
#include <roken.h>
#include <rfc2459_asn1.h> /* XXX */
#include <der.h>

View File

@@ -49,6 +49,7 @@
#include <evp-cc.h>
#include <krb5-types.h>
#include <roken.h>
#ifndef HCRYPTO_DEF_PROVIDER
#define HCRYPTO_DEF_PROVIDER hcrypto

View File

@@ -43,6 +43,7 @@
#ifdef KRB5
#include <krb5-types.h>
#endif
#include <roken.h>
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))

View File

@@ -35,6 +35,9 @@
#include <stdlib.h>
#include <rand.h>
#ifdef KRB5
#include <krb5-types.h>
#endif
#include <roken.h>
#include "randi.h"
@@ -451,6 +454,7 @@ fortuna_reseed(void)
if (!init_done)
abort();
#ifndef NO_RAND_UNIX_METHOD
{
unsigned char buf[INIT_BYTES];
if ((*hc_rand_unix_method.bytes)(buf, sizeof(buf)) == 1) {
@@ -459,6 +463,7 @@ fortuna_reseed(void)
memset(buf, 0, sizeof(buf));
}
}
#endif
#ifdef HAVE_ARC4RANDOM
{
uint32_t buf[INIT_BYTES / sizeof(uint32_t)];
@@ -470,6 +475,7 @@ fortuna_reseed(void)
entropy_p = 1;
}
#endif
#ifndef NO_RAND_EGD_METHOD
/*
* Only to get egd entropy if /dev/random or arc4rand failed since
* it can be horribly slow to generate new bits.
@@ -482,6 +488,7 @@ fortuna_reseed(void)
memset(buf, 0, sizeof(buf));
}
}
#endif
/*
* Fall back to gattering data from timer and secret files, this
* is really the last resort.
@@ -521,10 +528,12 @@ fortuna_reseed(void)
gettimeofday(&tv, NULL);
add_entropy(&main_state, (void *)&tv, sizeof(tv));
}
#ifdef HAVE_GETUID
{
uid_t u = getuid();
add_entropy(&main_state, (void *)&u, sizeof(u));
}
#endif
return entropy_p;
}

View File

@@ -31,11 +31,12 @@
#include "config.h"
#include <stdlib.h>
#ifdef KRB5
#include <krb5-types.h>
#endif
#include <rijndael-alg-fst.h>
#include "rijndael-alg-fst.h"
/* the file should not be used from outside */
typedef uint8_t u8;

View File

@@ -39,11 +39,11 @@
#ifdef KRB5
#include <krb5-types.h>
#endif
#include <stdlib.h>
#include <des.h>
#include <rand.h>
#include <stdlib.h>
#undef __attribute__
#define __attribute__(X)

View File

@@ -36,9 +36,9 @@
srcdir="@srcdir@"
rsa="${TESTS_ENVIRONMENT} ./test_rsa"
engine="${TESTS_ENVIRONMENT} ./test_engine_dso"
rand="${TESTS_ENVIRONMENT} ./test_rand"
rsa="${TESTS_ENVIRONMENT} ./test_rsa@exeext@"
engine="${TESTS_ENVIRONMENT} ./test_engine_dso@exeext@"
rand="${TESTS_ENVIRONMENT} ./test_rand@exeext@"
${engine} --test-random > /dev/null || { echo "missing random"; exit 77; }

View File

@@ -113,10 +113,14 @@ main(int argc, char **argv)
if (rand_method) {
if (strcasecmp(rand_method, "fortuna") == 0)
RAND_set_rand_method(RAND_fortuna_method());
#ifndef NO_RAND_UNIX_METHOD
else if (strcasecmp(rand_method, "unix") == 0)
RAND_set_rand_method(RAND_unix_method());
#endif
#ifndef NO_RAND_EGD_METHOD
else if (strcasecmp(rand_method, "egd") == 0)
RAND_set_rand_method(RAND_egd_method());
#endif
else
errx(1, "unknown method %s", rand_method);
}

View File

@@ -37,10 +37,15 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#include <roken.h>
#include <ui.h>
#ifdef HAVE_CONIO_H
#include <conio.h>
#endif
static sig_atomic_t intr_flag;
@@ -50,6 +55,8 @@ intr(int sig)
intr_flag++;
}
#ifndef HAVE_CONIO_H
#ifndef NSIG
#define NSIG 47
#endif
@@ -135,6 +142,51 @@ read_string(const char *preprompt, const char *prompt,
return 0;
}
#else /* CONIO_H */
static int
read_string_conio(const char *preprompt, const char *prompt,
char *buf, size_t len, int echo)
{
int of = 0;
int c;
char *p;
void (*oldsigintr)(int);
_cprintf("%s%s", preprompt, prompt);
oldsigintr = signal(SIGINT, intr);
p = buf;
while(intr_flag == 0){
c = ((echo)? _getche(): _getch());
if(c == '\n')
break;
if(of == 0)
*p++ = c;
of = (p == buf + len);
}
if(of)
p--;
*p = 0;
if(echo == 0){
printf("\n");
}
signal(SIGINT, oldsigintr);
if(intr_flag)
return -2;
if(of)
return -1;
return 0;
}
#define read_string read_string_conio
#endif
int
UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
{