hcrypto, otp: Remove hcrypto and otp!

We must switch to OpenSSL 3.x, and getting lib/hcrypto to provide
OpenSSL 3.x APIs is too large an undertaking.  Plus the hcrypto backend
is not safe, not secure (probably has timing leaks galore), and no one
has the resources to make it a world-class crypto library, so it just
has to go.
This commit is contained in:
Nicolas Williams
2025-10-09 19:00:39 -05:00
parent 199d6b7f8f
commit 7439820618
456 changed files with 62 additions and 82478 deletions

View File

@@ -34,7 +34,6 @@ ktutil-commands.c ktutil-commands.h: ktutil-commands.in
LDADD = \
$(top_builddir)/lib/kadm5/libkadm5clnt.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(top_builddir)/lib/sl/libsl.la \
$(LIB_heimbase) \

View File

@@ -2,9 +2,6 @@
include $(top_srcdir)/Makefile.am.common
if OTP
dir_otp = otp
endif
if DCE
dir_dce = dceutils
endif
@@ -14,7 +11,6 @@ endif
SUBDIRS = \
$(dir_afsutil) \
dbutils \
$(dir_otp) \
gssmask \
test \
kf \

View File

@@ -13,7 +13,6 @@ man_MANS = afslog.1 pagsh.1
LDADD = $(LIB_kafs) \
$(top_builddir)/lib/krb5/libkrb5.la \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_hcrypto) \
$(LIB_roken)
EXTRA_DIST = NTMakefile $(man_MANS)

View File

@@ -13,7 +13,6 @@ kf_SOURCES = kf.c kf_locl.h
kfd_SOURCES = kfd.c kf_locl.h
LDADD = $(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken)

View File

@@ -1,58 +0,0 @@
2006-10-07 Love Hörnquist Åstrand <lha@it.su.se>
* Makefile.am: Add man_MANS to EXTRA_DIST
2005-05-29 Love Hörquist Åstrand <lha@it.su.se>
* Makefile.am: add LIB_roken as a explit dependency
2003-09-03 Love Hörquist Åstrand <lha@it.su.se>
* otpprint.c: s/des_read_pw_string/UI_UTIL_read_pw_string/
* otp.c: s/des_read_pw_string/UI_UTIL_read_pw_string/
2003-02-25 Love Hörquist Åstrand <lha@it.su.se>
* otp.c: remove \n from errx, from NetBSD
2000-11-29 Johan Danielsson <joda@pdc.kth.se>
* otpprint.1: sort parameters and close a list
* otp.1: sort parameters and close a list
1999-09-14 Assar Westerlund <assar@sics.se>
* otp.c (verify_user_otp): check return value from
des_read_pw_string
Thu Apr 1 16:51:07 1999 Johan Danielsson <joda@hella.pdc.kth.se>
* otpprint.c: use getarg
* otp.c: use getarg
Thu Mar 18 12:08:58 1999 Johan Danielsson <joda@hella.pdc.kth.se>
* Makefile.am: include Makefile.am.common
Thu Mar 4 19:45:40 1999 Johan Danielsson <joda@hella.pdc.kth.se>
* Makefile.am: DESTDIR
Sat Feb 27 19:44:25 1999 Johan Danielsson <joda@hella.pdc.kth.se>
* Makefile.am: add
Sun Nov 22 10:32:50 1998 Assar Westerlund <assar@sics.se>
* otpprint.c: more braces
* Makefile.in (WFLAGS): set
Sun Dec 21 09:31:30 1997 Assar Westerlund <assar@sics.se>
* otp.c (renew): don't set the OTP if the reading of the string
fails.

View File

@@ -1,15 +0,0 @@
# $Id$
include $(top_srcdir)/Makefile.am.common
bin_PROGRAMS = otp otpprint
bin_SUIDS = otp
otp_SOURCES = otp.c otp_locl.h
otp_LDADD = $(LIB_hcrypto) $(LIB_roken) $(top_builddir)/lib/otp/libotp.la
otpprint_SOURCES = otpprint.c otp_locl.h
otpprint_LDADD = $(LIB_hcrypto) $(LIB_roken) $(top_builddir)/lib/otp/libotp.la
man_MANS = otp.1 otpprint.1
EXTRA_DIST = NTMakefile $(man_MANS)

View File

@@ -1,35 +0,0 @@
########################################################################
#
# 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=appl\otp
!include ../../windows/NTMakefile.w32

View File

@@ -1,90 +0,0 @@
.\" Copyright (c) 1996, 2000 Kungliga Tekniska Högskolan
.\" (Royal Institute of Technology, Stockholm, Sweden).
.\" 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.
.\"
.\" 3. Neither the name of the Institute nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
.\"
.\" $Id$
.\"
.Dd November 17, 1996
.Dt OTP 1
.Os KTH-KRB
.Sh NAME
.Nm otp
.Nd manages one-time passwords
.Sh SYNOPSIS
.Nm otp
.Op Fl dhlor
.Op Fl f Ar algorithm
.Op Fl u Ar user
.Ar sequence-number
.Ar seed
.Sh DESCRIPTION
The
.Nm
program initializes and updates your current series of one-time
passwords (OTPs).
.Pp
Use this to set a new series of one-time passwords. Only perform this
on the console or over an encrypted link as you will have to supply
your pass-phrase. The other two parameters are
.Ar sequence-number
and
.Ar seed .
.Pp
Options are:
.Bl -tag -width Ds
.It Fl d
To delete a one-time password.
.It Fl f
Choose a different
.Ar algorithm
from the default md5. Pick any of: md4, md5, and sha.
.It Fl h
For getting a help message.
.It Fl l
List the current table of one-time passwords.
.It Fl o
To open (unlock) the otp-entry for a user.
.It Fl r
To renew a one-time password series. This operation can be performed
over an potentially eavesdropped link because you do not supply the
pass-phrase. First you need to supply the current one-time password
and then the new one corresponding to the supplied
.Ar sequence-number
and
.Ar seed .
.It Fl u
To choose a different
.Ar user
to set one-time passwords for. This only works when running
.Nm
as root.
.El
.Sh SEE ALSO
.Xr otpprint 1

View File

@@ -1,371 +0,0 @@
/*
* Copyright (c) 1995-1997, 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include "otp_locl.h"
#include <getarg.h>
RCSID("$Id$");
static int listp;
static int deletep;
static int openp;
static int renewp;
static char* alg_string;
static char *user;
static int version_flag;
static int help_flag;
struct getargs args[] = {
{ "list", 'l', arg_flag, &listp, "list OTP status", NULL },
{ "delete", 'd', arg_flag, &deletep, "delete OTP", NULL },
{ "open", 'o', arg_flag, &openp, "open a locked OTP", NULL },
{ "renew", 'r', arg_flag, &renewp, "securely renew OTP", NULL },
{ "hash", 'f', arg_string, &alg_string,
"hash algorithm (md4, md5, or sha)", "algorithm"},
{ "user", 'u', arg_string, &user,
"user other than current user (root only)", "user" },
{ "version", 0, arg_flag, &version_flag, NULL, NULL },
{ "help", 'h', arg_flag, &help_flag, NULL, NULL }
};
int num_args = sizeof(args) / sizeof(args[0]);
static void
usage(int code)
{
arg_printusage(args, num_args, NULL, "[num seed]");
exit(code);
}
/*
* Renew the OTP for a user.
* The pass-phrase is not required (RFC 1938/8.0)
*/
static int
renew (int argc, char **argv, OtpAlgorithm *alg, char *inuser)
{
OtpContext newctx, *ctx;
char prompt[128];
char pw[64];
void *dbm;
int ret;
newctx.alg = alg;
newctx.user = inuser;
newctx.n = atoi (argv[0]);
strlcpy (newctx.seed, argv[1], sizeof(newctx.seed));
strlwr(newctx.seed);
snprintf (prompt, sizeof(prompt),
"[ otp-%s %u %s ]",
newctx.alg->name,
newctx.n,
newctx.seed);
if (UI_UTIL_read_pw_string (pw, sizeof(pw), prompt, 0) == 0 &&
otp_parse (newctx.key, pw, alg) == 0) {
ctx = &newctx;
ret = 0;
} else
return 1;
dbm = otp_db_open ();
if (dbm == NULL) {
warnx ("otp_db_open failed");
return 1;
}
otp_put (dbm, ctx);
otp_db_close (dbm);
return ret;
}
/*
* Return 0 if the user could enter the next OTP.
* I would rather have returned !=0 but it's shell-like here around.
*/
static int
verify_user_otp(char *username)
{
OtpContext ctx;
char passwd[OTP_MAX_PASSPHRASE + 1];
char ss[256];
char *prompt = NULL;
if (otp_challenge (&ctx, username, ss, sizeof(ss)) != 0) {
warnx("no otp challenge found for %s", username);
return 1;
}
if (asprintf(&prompt, "%s's %s Password: ", username, ss) == -1 ||
prompt == NULL)
err(1, "out of memory");
if (UI_UTIL_read_pw_string(passwd, sizeof(passwd)-1, prompt, 0)) {
free(prompt);
return 1;
}
free(prompt);
return otp_verify_user (&ctx, passwd);
}
/*
* Set the OTP for a user
*/
static int
set (int argc, char **argv, OtpAlgorithm *alg, char *inuser)
{
void *db;
OtpContext ctx;
char pw[OTP_MAX_PASSPHRASE + 1];
int ret;
int i;
ctx.alg = alg;
ctx.user = strdup (inuser);
if (ctx.user == NULL)
err (1, "out of memory");
ctx.n = atoi (argv[0]);
strlcpy (ctx.seed, argv[1], sizeof(ctx.seed));
strlwr(ctx.seed);
do {
if (UI_UTIL_read_pw_string (pw, sizeof(pw), "Pass-phrase: ",
UI_UTIL_FLAG_VERIFY))
return 1;
if (strlen (pw) < OTP_MIN_PASSPHRASE)
printf ("Too short pass-phrase. Use at least %d characters\n",
OTP_MIN_PASSPHRASE);
} while(strlen(pw) < OTP_MIN_PASSPHRASE);
ctx.alg->init (ctx.key, pw, ctx.seed);
for (i = 0; i < ctx.n; ++i)
ctx.alg->next (ctx.key);
db = otp_db_open ();
if(db == NULL) {
free (ctx.user);
err (1, "otp_db_open failed");
}
ret = otp_put (db, &ctx);
otp_db_close (db);
free (ctx.user);
return ret;
}
/*
* Delete otp of user from the database
*/
static int
delete_otp (int argc, char **argv, char *inuser)
{
void *db;
OtpContext ctx;
int ret;
db = otp_db_open ();
if(db == NULL)
errx (1, "otp_db_open failed");
ctx.user = inuser;
ret = otp_delete(db, &ctx);
otp_db_close (db);
return ret;
}
/*
* Tell whether the user has an otp
*/
static int
has_an_otp(char *inuser)
{
void *db;
OtpContext ctx;
int ret;
db = otp_db_open ();
if(db == NULL) {
warnx ("otp_db_open failed");
return 0; /* if no db no otp! */
}
ctx.user = inuser;
ret = otp_simple_get(db, &ctx);
otp_db_close (db);
return !ret;
}
/*
* Get and print out the otp entry for some user
*/
static void
print_otp_entry_for_name (void *db, char *inuser)
{
OtpContext ctx;
ctx.user = inuser;
if (!otp_simple_get(db, &ctx)) {
fprintf(stdout,
"%s\totp-%s %d %s",
ctx.user, ctx.alg->name, ctx.n, ctx.seed);
if (ctx.lock_time)
fprintf(stdout,
"\tlocked since %s",
ctime(&ctx.lock_time));
else
fprintf(stdout, "\n");
}
}
static int
open_otp (int argc, char **argv, char *inuser)
{
void *db;
OtpContext ctx;
int ret;
db = otp_db_open ();
if (db == NULL)
errx (1, "otp_db_open failed");
ctx.user = inuser;
ret = otp_simple_get (db, &ctx);
if (ret == 0)
ret = otp_put (db, &ctx);
otp_db_close (db);
return ret;
}
/*
* Print otp entries for one or all users
*/
static int
list_otps (int argc, char **argv, char *inuser)
{
void *db;
struct passwd *pw;
db = otp_db_open ();
if(db == NULL)
errx (1, "otp_db_open failed");
if (inuser)
print_otp_entry_for_name(db, inuser);
else
/* scans all users... so as to get a deterministic order */
while ((pw = getpwent()))
print_otp_entry_for_name(db, pw->pw_name);
otp_db_close (db);
return 0;
}
int
main (int argc, char **argv)
{
int defaultp = 0;
int uid = getuid();
OtpAlgorithm *alg = otp_find_alg (OTP_ALG_DEFAULT);
int optidx = 0;
char userbuf[128];
setprogname (argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
if(deletep && uid != 0)
errx (1, "Only root can delete OTPs");
if(alg_string) {
alg = otp_find_alg (alg_string);
if (alg == NULL)
errx (1, "Unknown algorithm: %s", alg_string);
}
if (user && uid != 0)
errx (1, "Only root can use `-u'");
argc -= optidx;
argv += optidx;
if (!(listp || deletep || renewp || openp))
defaultp = 1;
if ( listp + deletep + renewp + defaultp + openp != 1)
usage(1); /* one of -d or -l or -r or none */
if(deletep || openp || listp) {
if(argc != 0)
errx(1, "delete, open, and list requires no arguments");
} else {
if(argc != 2)
errx(1, "setup, and renew requires `num', and `seed'");
}
if (listp)
return list_otps (argc, argv, user);
if (user == NULL) {
user = roken_get_username(userbuf, sizeof(userbuf));
if (user == NULL)
err (1, "You don't exist");
}
/*
* users other that root must provide the next OTP to update the sequence.
* it avoids someone to use a pending session to change an OTP sequence.
* see RFC 1938/8.0.
*/
if (uid != 0 && (defaultp || renewp)) {
if (!has_an_otp(user)) {
errx (1, "Only root can set an initial OTP");
} else { /* Check the next OTP (RFC 1938/8.0: SHOULD) */
if (verify_user_otp(user) != 0) {
errx (1, "User authentication failed");
}
}
}
if (deletep)
return delete_otp (argc, argv, user);
else if (renewp)
return renew (argc, argv, alg, user);
else if (openp)
return open_otp (argc, argv, user);
else
return set (argc, argv, alg, user);
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <roken.h>
#include <err.h>
#include "crypto-headers.h" /* for des_read_pw_string */
#include <otp.h>

View File

@@ -1,82 +0,0 @@
.\" Copyright (c) 1996, 2000 - 2001 Kungliga Tekniska Högskolan
.\" (Royal Institute of Technology, Stockholm, Sweden).
.\" 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.
.\"
.\" 3. Neither the name of the Institute nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
.\"
.\" $Id$
.\"
.Dd November 17, 1996
.Dt OTP 1
.Os KTH-KRB
.Sh NAME
.Nm otpprint
.Nd print lists of one-time passwords
.Sh SYNOPSIS
.Nm otp
.Op Fl n Ar count
.Op Fl e
.Op Fl h
.Op Fl f Ar algorithm
.Ar sequence-number
.Ar seed
.Sh DESCRIPTION
The
.Nm
program prints lists of OTPs.
.Pp
Use this to print out a series of one-time passwords. You will have
to supply the
.Ar sequence number
and the
.Ar seed
as arguments and then the program will prompt you for your pass-phrase.
.Pp
There are several different print formats. The default is to print
each password with six short english words.
.Pp
Options are:
.Bl -tag -width Ds
.It Fl e
Print the passwords in ``extended'' format. In this format a prefix
that says ``hex:'' or ``word:'' is included.
.It Fl f
To choose a different
.Ar algorithm
from the default md5. Pick any of: md4, md5, and sha.
.It Fl h
Print the passwords in hex.
.It Fl n
Print
.Ar count
one-time passwords, starting at
.Ar sequence-number
and going backwards. The default is 10.
.El
.Sh SEE ALSO
.Xr otp 1

View File

@@ -1,136 +0,0 @@
/*
* Copyright (c) 1995-1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include "otp_locl.h"
#include <getarg.h>
RCSID("$Id$");
static int extendedp;
static int count = 10;
static int hexp;
static char* alg_string;
static int version_flag;
static int help_flag;
struct getargs args[] = {
{ "extended", 'e', arg_flag, &extendedp, "print keys in extended format",
NULL },
{ "count", 'n', arg_integer, &count, "number of keys to print", NULL },
{ "hexadecimal", 'h', arg_flag, &hexp, "output in hexadecimal", NULL },
{ "hash", 'f', arg_string, &alg_string,
"hash algorithm (md4, md5, or sha)", "algorithm"},
{ "version", 0, arg_flag, &version_flag, NULL, NULL },
{ "help", 0, arg_flag, &help_flag, NULL, NULL }
};
int num_args = sizeof(args) / sizeof(args[0]);
static void
usage(int code)
{
arg_printusage(args, num_args, NULL, "num seed");
exit(code);
}
static int
print (int argc,
char **argv,
int incount,
OtpAlgorithm *alg,
void (*print_fn)(OtpKey, char *, size_t))
{
char pw[64];
OtpKey key;
int n;
int i;
char *seed;
if (argc != 2)
usage (1);
n = atoi(argv[0]);
seed = argv[1];
if (UI_UTIL_read_pw_string (pw, sizeof(pw), "Pass-phrase: ", 0))
return 1;
alg->init (key, pw, seed);
for (i = 0; i < n; ++i) {
char s[64];
alg->next (key);
if (i >= n - incount) {
(*print_fn)(key, s, sizeof(s));
printf ("%d: %s\n", i + 1, s);
}
}
return 0;
}
int
main (int argc, char **argv)
{
int optidx = 0;
void (*fn)(OtpKey, char *, size_t);
OtpAlgorithm *alg = otp_find_alg (OTP_ALG_DEFAULT);
setprogname (argv[0]);
if(getarg(args, num_args, argc, argv, &optidx))
usage(1);
if(help_flag)
usage(0);
if(version_flag) {
print_version(NULL);
exit(0);
}
if(alg_string) {
alg = otp_find_alg (alg_string);
if (alg == NULL)
errx(1, "Unknown algorithm: %s", alg_string);
}
argc -= optidx;
argv += optidx;
if (hexp) {
if (extendedp)
fn = otp_print_hex_extended;
else
fn = otp_print_hex;
} else {
if (extendedp)
fn = otp_print_stddict_extended;
else
fn = otp_print_stddict;
}
return print (argc, argv, count, alg, fn);
}

View File

@@ -55,13 +55,11 @@ kinit_auditdns_LDADD = \
$(top_builddir)/lib/gssapi/libgssapi.la \
$(top_builddir)/lib/gss_preauth/libgss_preauth.la \
$(top_builddir)/lib/ntlm/libheimntlm.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_libintl) \
$(LIB_roken)
LDADD = $(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken)

View File

@@ -6,7 +6,6 @@ dnl - own-built libhcrypto
m4_define([test_headers], [
#undef KRB5 /* makes md4.h et al unhappy */
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -27,18 +26,6 @@ m4_define([test_headers], [
#include <openssl/rand.h>
#include <openssl/hmac.h>
#include <openssl/pkcs12.h>
#else
#include <hcrypto/evp.h>
#include <hcrypto/md4.h>
#include <hcrypto/md5.h>
#include <hcrypto/sha.h>
#include <hcrypto/des.h>
#include <hcrypto/rc4.h>
#include <hcrypto/aes.h>
#include <hcrypto/engine.h>
#include <hcrypto/hmac.h>
#include <hcrypto/pkcs12.h>
#endif
])
m4_define([test_body], [
void *schedule = 0;
@@ -54,9 +41,7 @@ m4_define([test_body], [
EVP_CIPHER_iv_length(((EVP_CIPHER*)0));
UI_UTIL_read_pw_string(0,0,0,0);
RAND_status();
#ifdef HAVE_HCRYPTO_W_OPENSSL
EC_KEY_new();
#endif
OpenSSL_add_all_algorithms();
AES_encrypt(0,0,0);
@@ -65,25 +50,19 @@ m4_define([test_body], [
AC_DEFUN([KRB_CRYPTO],[
AC_ARG_WITH([hcrypto-default-backend],
AS_HELP_STRING([--with-hcrypto-default-backend=cc|pkcs11_hcrypto|ossl|w32crypto|hcrypto],
AS_HELP_STRING([--with-hcrypto-default-backend=ossl],
[specify the default hcrypto backend]),
[
CFLAGS="${CFLAGS} -DHCRYPTO_DEF_PROVIDER=${withval}"
case "$withval" in
cc) AC_DEFINE(HCRYPTO_DEF_PROVIDER, [cc], [Define to one of cc, pkcs11, ossl, w32crypto, or hcrypto to set a default hcrypto provider]);;
pkcs11_hcrypto) AC_DEFINE(HCRYPTO_DEF_PROVIDER, [pkcs11_hcrypto], [Define to one of cc, pkcs11, ossl, w32crypto, or hcrypto to set a default hcrypto provider]);;
ossl) AC_DEFINE(HCRYPTO_DEF_PROVIDER, [ossl], [Define to one of cc, pkcs11, ossl, w32crypto, or hcrypto to set a default hcrypto provider]);;
w32crypto) AC_DEFINE(HCRYPTO_DEF_PROVIDER, [w32crypto], [Define to one of cc, pkcs11, ossl, w32crypto, or hcrypto to set a default hcrypto provider]);;
hcrypto) AC_DEFINE(HCRYPTO_DEF_PROVIDER, [hcrypto], [Define to one of cc, pkcs11, ossl, w32crypto, or hcrypto to set a default hcrypto provider]);;
*) echo "Invalid hcrypto provider name ($withval)"; exit 5;;
esac
],
[])
if test "$with_val" != ossl -a "$withval" != ""; then
AC_MSG_ERROR([hcrypto has been removed 0])
fi
]
)
AC_ARG_WITH([hcrypto-fallback],
AS_HELP_STRING([--without-hcrypto-fallback],
[disable fallback on hcrypto for unavailable algorithms]),
[AC_DEFINE([HCRYPTO_FALLBACK],0,[Set to 1 to allow fallback to hcrypto for unavailable algorithms])],
[AC_DEFINE([HCRYPTO_FALLBACK],1,[Set to 1 to allow fallback to hcrypto for unavailable algorithms])])
[AC_MSG_ERROR([hcrypto has been removed 2])]
)
AC_WITH_ALL([openssl])
AC_MSG_CHECKING([for crypto library])
@@ -108,7 +87,7 @@ if test "$with_openssl" != "no"; then
elif test "${with_openssl}" != "/usr" -a -d "${with_openssl}/lib"; then
LIB_openssl_crypto="-L${with_openssl}/lib"
fi
CFLAGS="-DHAVE_HCRYPTO_W_OPENSSL ${INCLUDE_openssl_crypto} ${CFLAGS}"
CFLAGS="${INCLUDE_openssl_crypto} ${CFLAGS}"
LDFLAGS="${LIB_openssl_crypto} ${LDFLAGS}"
AC_CHECK_LIB([crypto], [OPENSSL_init],
[LIB_openssl_crypto="${LIB_openssl_crypto} -lcrypto"; openssl=yes], [openssl=no], [])
@@ -150,13 +129,6 @@ if test "$with_openssl" != "no"; then
LDFLAGS="${saved_LDFLAGS}"
fi
LIB_hcrypto='$(top_builddir)/lib/hcrypto/libhcrypto.la'
LIB_hcrypto_a='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.a'
LIB_hcrypto_so='$(top_builddir)/lib/hcrypto/.libs/libhcrypto.so'
LIB_hcrypto_appl="-lhcrypto"
AC_MSG_RESULT([included libhcrypto])
AC_ARG_WITH(pkcs11-module,
AS_HELP_STRING([--with-pkcs11-module=path],
[use PKCS11 module in path]),
@@ -168,15 +140,10 @@ if test "$pkcs11_module" != ""; then
openssl=no
fi
if test "$openssl" = "yes"; then
AC_DEFINE([HAVE_HCRYPTO_W_OPENSSL], 1, [define to use openssl's libcrypto as the default backend for libhcrypto])
if test "$openssl" != "yes"; then
AC_MSG_ERROR([OpenSSL is required])
fi
AM_CONDITIONAL(HAVE_HCRYPTO_W_OPENSSL, test "$openssl" = yes)dnl
AC_SUBST(INCLUDE_openssl_crypto)
AC_SUBST(LIB_openssl_crypto)
AC_SUBST(LIB_hcrypto)
AC_SUBST(LIB_hcrypto_a)
AC_SUBST(LIB_hcrypto_so)
AC_SUBST(LIB_hcrypto_appl)
])

View File

@@ -3,25 +3,8 @@ dnl
dnl check requirements for OTP library
dnl
AC_DEFUN([rk_OTP],[
AC_REQUIRE([rk_DB])dnl
AC_ARG_ENABLE(otp,
AS_HELP_STRING([--disable-otp],[if you don't want OTP support]))
if test "$enable_otp" = yes -a "$db_type" = unknown; then
AC_MSG_ERROR([OTP requires a NDBM/DB compatible library])
fi
if test "$enable_otp" != no; then
if test "$db_type" != unknown; then
enable_otp=yes
else
enable_otp=no
fi
fi
if test "$enable_otp" = yes; then
AC_DEFINE(OTP, 1, [Define if you want OTP support in applications.])
LIB_otp='$(top_builddir)/lib/otp/libotp.la'
AC_SUBST(LIB_otp)
fi
AC_MSG_CHECKING([whether to enable OTP library])
AC_MSG_RESULT($enable_otp)
AM_CONDITIONAL(OTP, test "$enable_otp" = yes)dnl
AC_MSG_ERROR([OTP has been removed],
AC_MSG_ERROR([OTP has been removed])
])

View File

@@ -359,8 +359,6 @@ LIBADD_roken="$LIB_roken"
AC_SUBST(LIBADD_roken)dnl
LIB_roken="\$(top_builddir)/lib/vers/libvers.la $LIB_roken"
rk_OTP
rk_LIBDISPATCH
AC_CHECK_OSFC2
@@ -734,23 +732,19 @@ AC_CONFIG_FILES(Makefile \
etc/Makefile \
include/Makefile \
include/gssapi/Makefile \
include/hcrypto/Makefile \
include/kadm5/Makefile \
lib/Makefile \
lib/base/Makefile \
lib/base/Makefile \
lib/asn1/Makefile \
lib/com_err/Makefile \
lib/hcrypto/Makefile \
lib/hx509/Makefile \
lib/gssapi/Makefile \
lib/ntlm/Makefile \
lib/hdb/Makefile \
lib/ipc/Makefile \
lib/kadm5/Makefile \
lib/kafs/Makefile \
lib/kdfs/Makefile \
lib/krb5/Makefile \
lib/otp/Makefile \
lib/roken/Makefile \
lib/sl/Makefile \
lib/sqlite/Makefile \
@@ -768,7 +762,6 @@ AC_CONFIG_FILES(Makefile \
appl/afsutil/Makefile \
appl/dbutils/Makefile \
appl/gssmask/Makefile \
appl/otp/Makefile \
appl/test/Makefile \
appl/kf/Makefile \
appl/dceutils/Makefile \

View File

@@ -18,11 +18,6 @@ dxy_subst = sed -e 's,[@]srcdir[@],$(srcdir),g' \
-e 's,[@]objdir[@],.,g' \
-e 's,[@]PACKAGE_VERSION[@],$(PACKAGE_VERSION),g'
hcrypto.dxy: hcrypto.din Makefile
$(dxy_subst) < $(srcdir)/hcrypto.din > hcrypto.dxy.tmp
chmod +x hcrypto.dxy.tmp
mv hcrypto.dxy.tmp hcrypto.dxy
hdb.dxy: hdb.din Makefile
$(dxy_subst) < $(srcdir)/hdb.din > hdb.dxy.tmp
chmod +x hdb.dxy.tmp
@@ -69,9 +64,7 @@ vars.texi: vars.tin Makefile
PROJECTS = base hdb hx509 gssapi krb5 ntlm wind
PROJECTS += hcrypto
doxyout doxygen: base.dxy hdb.dxy hx509.dxy hcrypto.dxy gssapi.dxy krb5.dxy ntlm.dxy wind.dxy
doxyout doxygen: base.dxy hdb.dxy hx509.dxy gssapi.dxy krb5.dxy ntlm.dxy wind.dxy
@test -d $(srcdir)/doxyout && \
find $(srcdir)/doxyout -type d ! -perm -200 -exec chmod u+w {} ';' ; \
rm -rf $(srcdir)/doxyout ; \
@@ -137,7 +130,6 @@ EXTRA_DIST = \
footer.html \
gssapi.din \
hdb.din \
hcrypto.din \
header.html \
heimdal.css \
base.din \
@@ -155,7 +147,6 @@ EXTRA_DIST = \
vars.tin
CLEANFILES = \
hcrypto.dxy* \
base.dxy* \
hx509.dxy* \
hdb.dxy* \

View File

@@ -2,17 +2,6 @@
@comment node-name, next, previous, up
@appendix Acknowledgments
Eric Young wrote ``libdes''. Heimdal used to use libdes, without it
kth-krb would never have existed. Since there are no longer any Eric
Young code left in the library, we renamed it to libhcrypto.
All functions in libhcrypto have been re-implemented or used available
public domain code. The core AES function where written by Vincent
Rijmen, Antoon Bosselaers and Paulo Barreto. The core DES SBOX
transformation was written by Richard Outerbridge. @code{imath} that
is used for public key crypto support is written by Michael
J. Fromberger.
The University of California at Berkeley initially wrote @code{telnet},
and @code{telnetd}. The authentication and encryption code of
@code{telnet} and @code{telnetd} was added by David Borman (then of Cray

View File

@@ -159,41 +159,6 @@ SUCH DAMAGE.
@end verbatim
@copynext
@heading TomsFastMath / LibTomMath
Tom's fast math (bignum support) and LibTomMath
@verbatim
The LibTom license
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
@end verbatim
@copynext
@heading Doug Rabson
@@ -275,70 +240,6 @@ SUCH DAMAGE.
@end verbatim
@copynext
@heading Marko Kreen
Fortuna in libhcrypto
@verbatim
Copyright (c) 2005 Marko Kreen
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 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 AUTHOR 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.
@end verbatim
@copynext
@heading NTT (Nippon Telegraph and Telephone Corporation)
Camellia in libhcrypto
@verbatim
Copyright (c) 2006,2007
NTT (Nippon Telegraph and Telephone Corporation) . 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 as
the first lines of this file unmodified.
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 NTT ``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 NTT 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.
@end verbatim
@copynext
@heading The NetBSD Foundation, Inc.
@@ -374,37 +275,6 @@ POSSIBILITY OF SUCH DAMAGE.
@end verbatim
@copynext
@heading Vincent Rijmen, Antoon Bosselaers, Paulo Barreto
AES in libhcrypto
@verbatim
rijndael-alg-fst.c
@version 3.0 (December 2000)
Optimised ANSI C code for the Rijndael cipher (now AES)
@author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
@author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
@author Paulo Barreto <paulo.barreto@terra.com.br>
This code is hereby placed in the public domain.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''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 AUTHORS 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.
@end verbatim
@copynext
@heading Apple, Inc
@@ -435,30 +305,6 @@ THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
@end verbatim
@copynext
@heading Richard Outerbridge
DES core in libhcrypto
@verbatim
D3DES (V5.09) -
A portable, public domain, version of the Data Encryption Standard.
Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge.
Thanks to: Dan Hoey for his excellent Initial and Inverse permutation
code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis
Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau,
for humouring me on.
Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge.
(GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992.
@end verbatim
@copynext
@@ -501,44 +347,4 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
@copynext
@heading Novell, Inc
lib/hcrypto/test_dh.c
@verbatim
Copyright (c) 2007, Novell, Inc.
Author: Matthias Koenig <mkoenig@suse.de>
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.
* Neither the name of the Novell nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
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 OWNER 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.
@end verbatim
@copyrightend

View File

@@ -1,16 +0,0 @@
# Doxyfile 1.5.3
PROJECT_NAME = "Heimdal crypto library"
PROJECT_NUMBER = @PACKAGE_VERSION@
OUTPUT_DIRECTORY = @srcdir@/doxyout/hcrypto
INPUT = @srcdir@/../lib/hcrypto
EXAMPLE_PATH = @srcdir@/../lib/hcrypto
WARN_IF_UNDOCUMENTED = YES
PERL_PATH = /usr/bin/perl
HTML_HEADER = "@srcdir@/header.html"
HTML_FOOTER = "@srcdir@/footer.html"
@INCLUDE = "@srcdir@/doxytmpl.dxy"

View File

@@ -2,7 +2,7 @@
include $(top_srcdir)/Makefile.am.common
SUBDIRS = kadm5 hcrypto gssapi
SUBDIRS = kadm5 gssapi
noinst_PROGRAMS = bits
CHECK_LOCAL = no-check-local
@@ -101,7 +101,6 @@ CLEANFILES = \
ntlm_err.h \
ocsp_asn1.h \
ocsp_template_asn1.h \
otp.h \
parse_bytes.h \
parse_time.h \
parse_units.h \

View File

@@ -31,7 +31,7 @@
RELDIR=include
SUBDIRS=kadm5 hcrypto gssapi
SUBDIRS=kadm5 gssapi
!include ../windows/NTMakefile.w32
!include ../windows/NTMakefile.version
@@ -62,12 +62,10 @@ while(<>) {
if ("$(KRB5)") { print "#define KRB5 1\n"; }
if ("$(KRB4)") { print "#define KRB4 1\n"; }
if ("$(WEAK_CRYPTO)") { print "#define HEIM_WEAK_CRYPTO 1\n"; }
if ("$(HCRYPTO_FALLBACK)") { print "#define HCRYPTO_FALLBACK 1\n"; } else { print "#define HCRYPTO_FALLBACK 0\n"; }
if ("$(PKINIT)") { print "#define PKINIT 1\n"; }
if ("$(NO_AFS)") { print "#define NO_AFS 1\n"; }
if ("$(OPENLDAP)") { print "#define OPENLDAP 1\n"; }
if ("$(OPENLDAP_MODULE)") { print "#define OPENLDAP_MODULE 1\n"; }
if ("$(OTP)") { print "#define OTP 1 \n"; }
if ("$(AUTHENTICATION)") { print "#define AUTHENTICATION 1\n"; }
if ("$(DIAGNOSTICS)") { print "#define DIAGNOSTICS 1\n"; }
if ("$(ENCRYPTION)") { print "#define ENCRYPTION 1\n"; }

View File

@@ -693,9 +693,6 @@ static const char *const rcsid[] = { (const char *)rcsid, "@(#)" msg }
/* Define to 1 if you have the `openpty' function. */
/* #define HAVE_OPENPTY 1 */
/* define to 1 to use openssl's libcrypto as a (default) backend for libhcrypto */
/* #undef HAVE_HCRYPTO_W_OPENSSL */
/* Define to enable basic OSF C2 support. */
/* #undef HAVE_OSFC2 */

View File

@@ -9,17 +9,17 @@
#include <krb5-types.h>
#endif
#include <hcrypto/evp.h>
#include <hcrypto/des.h>
#include <hcrypto/md4.h>
#include <hcrypto/md5.h>
#include <hcrypto/sha.h>
#include <hcrypto/rc4.h>
#include <hcrypto/rc2.h>
#include <hcrypto/ui.h>
#include <hcrypto/rand.h>
#include <hcrypto/engine.h>
#include <hcrypto/pkcs12.h>
#include <hcrypto/hmac.h>
#include <openssl/evp.h>
#include <openssl/des.h>
#include <openssl/md4.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <openssl/rc4.h>
#include <openssl/rc2.h>
#include <openssl/ui.h>
#include <openssl/rand.h>
#include <openssl/engine.h>
#include <openssl/pkcs12.h>
#include <openssl/hmac.h>
#endif /* __crypto_header__ */

View File

@@ -1,30 +0,0 @@
# $Id$
include $(top_srcdir)/Makefile.am.common
CLEANFILES = \
aes.h \
bn.h \
des.h \
dh.h \
dsa.h \
ec.h \
ecdsa.h \
ecdh.h \
engine.h \
evp.h \
evp-hcrypto.h \
evp-cc.h \
hmac.h \
md4.h \
md5.h \
pkcs12.h \
rand.h \
rc2.h \
rc4.h \
rsa.h \
sha.h \
ui.h \
undef.h
EXTRA_DIST = NTMakefile

View File

@@ -1,34 +0,0 @@
########################################################################
#
# 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=include\hcrypto
!include ../../windows/NTMakefile.w32

View File

@@ -63,7 +63,6 @@ check_PROGRAMS = $(TESTS)
LDADD_common = \
$(top_builddir)/lib/hdb/libhdb.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken) \
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)

View File

@@ -34,7 +34,6 @@ man_MANS = kcm.8
LDADD = $(top_builddir)/lib/hdb/libhdb.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(top_builddir)/lib/ntlm/libheimntlm.la \
$(top_builddir)/lib/ipc/libheim-ipcs.la \

View File

@@ -45,7 +45,6 @@ bx509d_LDADD = -ldl \
$(MICROHTTPD_LIBS) \
$(LIB_roken) \
$(LIB_heimbase) \
$(LIB_hcrypto) \
$(top_builddir)/lib/sl/libsl.la \
$(top_builddir)/lib/asn1/libasn1.la \
$(top_builddir)/lib/krb5/libkrb5.la \
@@ -63,7 +62,6 @@ httpkadmind_LDADD = -ldl \
$(MICROHTTPD_LIBS) \
$(LIB_roken) \
$(LIB_heimbase) \
$(LIB_hcrypto) \
$(top_builddir)/lib/sl/libsl.la \
$(top_builddir)/lib/asn1/libasn1.la \
$(top_builddir)/lib/krb5/libkrb5.la \
@@ -181,7 +179,6 @@ hprop_LDADD = \
$(top_builddir)/lib/hdb/libhdb.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_kdb) \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken) \
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)
@@ -190,7 +187,6 @@ hpropd_LDADD = \
$(top_builddir)/lib/hdb/libhdb.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_kdb) \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken) \
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)
@@ -207,7 +203,6 @@ libkdc_la_LIBADD = \
$(top_builddir)/lib/gss_preauth/libgss_preauth.la \
$(LIB_kdb) \
$(top_builddir)/lib/ntlm/libheimntlm.la \
$(LIB_hcrypto) \
$(LIB_openssl_crypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken) \
@@ -215,7 +210,6 @@ libkdc_la_LIBADD = \
LDADD = $(top_builddir)/lib/hdb/libhdb.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken) \
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)

View File

@@ -33,8 +33,6 @@
* SUCH DAMAGE.
*/
#define HC_DEPRECATED_CRYPTO
#include "headers.h"
#include <digest_asn1.h>
#include <heimntlm.h>

View File

@@ -100,9 +100,6 @@
#include <der.h>
#include <gssapi/gssapi.h>
#ifndef NO_NTLM
#include <heimntlm.h>
#endif
#include <kdc.h>
#include <kdc-plugin.h>
#include <kdc-audit.h>

View File

@@ -147,9 +147,6 @@ specified as:
And there are some configuration options which do not have
command-line equivalents:
.Bl -tag -width "xxx" -offset indent
.It Li enable-digest = Va boolean
turn on support for digest processing in the KDC.
The default is FALSE.
.It Li check-ticket-addresses = Va boolean
Check the addresses in the ticket when processing TGS requests.
The default is TRUE.

View File

@@ -41,7 +41,9 @@
/*
* As with the other *-ec.c files in Heimdal, this is a bit of a hack.
*
* The idea is to use OpenSSL for EC because hcrypto doesn't have the
* XXX This is no longer relevant now that we've removed hcrypto.
*
* The idea _was_ to use OpenSSL for EC because hcrypto doesn't have the
* required functionality at this time. To do this we segregate
* EC-using code into separate source files and then we arrange for them
* to get the OpenSSL headers and not the conflicting hcrypto ones.
@@ -51,7 +53,6 @@
* strange header include order here.
*/
#ifdef HAVE_HCRYPTO_W_OPENSSL
#include <openssl/evp.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
@@ -63,12 +64,8 @@
#include <openssl/core_names.h>
#endif
#define HEIM_NO_CRYPTO_HDRS
#endif /* HAVE_HCRYPTO_W_OPENSSL */
#define NO_HCRYPTO_POLLUTION
#include "kdc_locl.h"
#include <hcrypto/des.h>
#include <heim_asn1.h>
#include <rfc2459_asn1.h>
#include <cms_asn1.h>
@@ -83,7 +80,6 @@ _kdc_pk_free_client_ec_param(krb5_context context,
void *k0,
void *k1)
{
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
EVP_PKEY_free(k0);
EVP_PKEY_free(k1);
@@ -91,10 +87,8 @@ _kdc_pk_free_client_ec_param(krb5_context context,
EC_KEY_free(k0);
EC_KEY_free(k1);
#endif
#endif
}
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
static krb5_error_code
generate_ecdh_keyblock_ossl30(krb5_context context,
@@ -236,7 +230,6 @@ generate_ecdh_keyblock_ossl11(krb5_context context,
return 0;
}
#endif
#endif /* HAVE_HCRYPTO_W_OPENSSL */
krb5_error_code
_kdc_generate_ecdh_keyblock(krb5_context context,
@@ -245,7 +238,6 @@ _kdc_generate_ecdh_keyblock(krb5_context context,
unsigned char **dh_gen_key, /* shared secret */
size_t *dh_gen_keylen)
{
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
return generate_ecdh_keyblock_ossl30(context, ec_key_pk,
(EVP_PKEY **)ec_key_key,
@@ -255,12 +247,8 @@ _kdc_generate_ecdh_keyblock(krb5_context context,
(EC_KEY **)ec_key_key,
dh_gen_key, dh_gen_keylen);
#endif
#else
return ENOTSUP;
#endif /* HAVE_HCRYPTO_W_OPENSSL */
}
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
static krb5_error_code
get_ecdh_param_ossl30(krb5_context context,
@@ -425,7 +413,6 @@ get_ecdh_param_ossl11(krb5_context context,
return ret;
}
#endif
#endif /* HAVE_HCRYPTO_W_OPENSSL */
krb5_error_code
_kdc_get_ecdh_param(krb5_context context,
@@ -433,15 +420,11 @@ _kdc_get_ecdh_param(krb5_context context,
SubjectPublicKeyInfo *dh_key_info,
void **out)
{
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
return get_ecdh_param_ossl30(context, config, dh_key_info, (EVP_PKEY **)out);
#else
return get_ecdh_param_ossl11(context, config, dh_key_info, (EC_KEY **)out);
#endif
#else
return ENOTSUP;
#endif /* HAVE_HCRYPTO_W_OPENSSL */
}
@@ -449,7 +432,6 @@ _kdc_get_ecdh_param(krb5_context context,
*
*/
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
static krb5_error_code
serialize_ecdh_key_ossl30(krb5_context context,
@@ -526,7 +508,6 @@ serialize_ecdh_key_ossl11(krb5_context context,
return 0;
}
#endif
#endif
krb5_error_code
_kdc_serialize_ecdh_key(krb5_context context,
@@ -534,15 +515,11 @@ _kdc_serialize_ecdh_key(krb5_context context,
unsigned char **out,
size_t *out_len)
{
#ifdef HAVE_HCRYPTO_W_OPENSSL
#ifdef HAVE_OPENSSL_30
return serialize_ecdh_key_ossl30(context, key, out, out_len);
#else
return serialize_ecdh_key_ossl11(context, key, out, out_len);
#endif
#else
return ENOTSUP;
#endif
}
#endif

View File

@@ -23,7 +23,6 @@ kpasswdd_LDADD = \
$(DB3LIB) $(DB1LIB) $(LMDBLIB) $(NDBMLIB)
LDADD = $(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken)

View File

@@ -33,7 +33,6 @@ kinit_LDADD = \
$(top_builddir)/lib/gssapi/libgssapi.la \
$(top_builddir)/lib/gss_preauth/libgss_preauth.la \
$(top_builddir)/lib/ntlm/libheimntlm.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_libintl) \
$(LIB_roken)
@@ -62,7 +61,6 @@ nodist_kdigest_SOURCES = kdigest-commands.c
kdigest_LDADD = \
$(top_builddir)/lib/ntlm/libheimntlm.la \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(top_builddir)/lib/sl/libsl.la \
$(LIB_roken)
@@ -81,7 +79,6 @@ heimtools-commands.c heimtools-commands.h: heimtools-commands.in
LDADD = \
$(top_builddir)/lib/krb5/libkrb5.la \
$(LIB_hcrypto) \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_roken)

View File

@@ -31,8 +31,6 @@
* SUCH DAMAGE.
*/
#define HC_DEPRECATED_CRYPTO
#include "kuser_locl.h"
#include <kdigest-commands.h>

View File

@@ -34,7 +34,6 @@
*/
#include "kuser_locl.h"
#undef HC_DEPRECATED_CRYPTO
#include <krb5_locl.h>
#ifdef HAVE_FRAMEWORK_SECURITY

View File

@@ -36,7 +36,6 @@
#include "kuser_locl.h"
#include "parse_units.h"
#include "heimtools-commands.h"
#undef HC_DEPRECATED_CRYPTO
static const char *
printable_time_internal(time_t t, int x)

View File

@@ -34,7 +34,6 @@
#include "kuser_locl.h"
#include "heimtools-commands.h"
#include <kx509_asn1.h>
#undef HC_DEPRECATED_CRYPTO
#include "../lib/hx509/hx_locl.h"
#include "../lib/krb5/krb5_locl.h"
#include "hx509-private.h"

View File

@@ -5,9 +5,6 @@ include $(top_srcdir)/Makefile.am.common
if LIBEDIT
dir_editline = libedit
endif
if OTP
dir_otp = otp
endif
if DCE
dir_dce = kdfs
endif
@@ -34,7 +31,6 @@ SUBDIRS = \
wind \
asn1 \
$(dir_sqlite) \
hcrypto \
ipc \
hx509 \
krb5 \
@@ -44,7 +40,6 @@ SUBDIRS = \
gss_preauth \
hdb \
kadm5 \
$(dir_otp) \
$(dir_dce)
EXTRA_DIST = NTMakefile heimdal

View File

@@ -30,9 +30,6 @@
#
!ifdef OTP
dir_otp = otp
!endif
!ifdef DCE
dir_dce = kdfs
!endif
@@ -51,8 +48,8 @@ assembly=..\packages\windows\assembly
!endif
SUBDIRS = roken vers com_err base sl wind asn1 sqlite \
hcrypto hx509 krb5 heimdal ntlm kafs gssapi gss_preauth \
hdb kadm5 $(dir_otp) $(dir_dce) $(plugin) $(assembly)
hx509 krb5 heimdal ntlm kafs gssapi gss_preauth \
hdb kadm5 $(dir_dce) $(plugin) $(assembly)
!include ../windows/NTMakefile.w32

View File

@@ -32,7 +32,6 @@
#include <krb5_locl.h>
#include <mech_locl.h>
#include <heimntlm.h>
#include "gss-preauth-protos.h"
#include "gss-preauth-private.h"

View File

@@ -279,7 +279,6 @@ libgssapi_la_LIBADD = \
$(top_builddir)/lib/krb5/libkrb5.la \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_com_err) \
$(LIB_hcrypto) \
$(LIBADD_roken)
man_MANS = gssapi.3 gss_acquire_cred.3 mech/mech.5 gss-token.1

View File

@@ -53,7 +53,6 @@
#include <roken.h>
#include <heim_threads.h>
#define HC_DEPRECATED_CRYPTO
#include "crypto-headers.h"
/*

View File

@@ -58,7 +58,6 @@
#include <heimntlm.h>
#define HC_DEPRECATED_CRYPTO
#include "crypto-headers.h"
typedef OM_uint32

View File

@@ -36,6 +36,7 @@
#include <krb5_locl.h> /* for _krb5_SP800_108_HMAC_KDF() */
/* XXX Use OpenSSL 3.x */
#include <hcrypto/x25519_ref10.h>
#include <gssapi.h>

File diff suppressed because it is too large Load Diff

View File

@@ -1,108 +0,0 @@
The hunt for getting a DES with plain BSD license w/o advertisement clause
==========================================================================
$Id$
This all feels very silly given that DES is about 30 years old and now
is deprecated.
Helpful documents on the way:
Schider's crypto wasn't that useful since it only told how to do DES,
not how to do des fast or how to not use DES. I find this to be a
common thread in the book, it explain each tool in great detail, but
not its limitations.
Dag Arne Osvik: Efficient Implementation of the Data Encryption Standard
Some threads on sci.crypto was also useful.
PC1 transformations
===================
Getting the PC1 bit mangling working was hard, I never got it to work.
Printning out the bit usage made me realize a lookup table could be
used since only 12 bits are used from the first half and 16 from the
second.
01110000 01110000 01110000 01110000 01111000 01111000 01111000 01111000
00001111 00001111 00001111 00001111 00000111 00000111 00000111 00000111
The pattern is getting more obvious if it's printed out where the bits
are coming from.
8 16 24 - - - - -
7 15 23 - - - - -
6 14 22 - - - - -
5 13 21 - - - - -
4 12 20 28 - - - -
3 11 19 27 - - - -
2 10 18 26 - - - -
1 9 17 25 - - - -
- - - 60 56 48 40 -
- - - 59 55 47 39 -
- - - 58 54 46 38 -
- - - 57 53 45 37 -
- - - - 52 44 36 -
- - - - 51 43 35 -
- - - - 50 42 34 -
- - - - 49 41 33 -
Only 3 bits-table is needed for the first half and 4 bits for the
second half because they are on diffrent shift offsets.
So to get the bitpattern bit-pattern
gen_pattern("pc1_c_3", 7, [ 5, 13, 21 ], 0, 0x1000000);
gen_pattern("pc1_c_4", 15, [ 1, 9, 17, 25 ], 0, 0x1000000);
gen_pattern("pc1_d_3", 7, [ 49, 41, 33 ], 32, 0x1000000);
gen_pattern("pc1_d_4", 15, [ 57, 53, 45, 37 ], 32, 0x1000000);
PC2 transformations
===================
PC2 is also a table lookup, since it's a 24 bit field, I use 4 6-bit
lookup tables. Printing the reverse of the PC2 table reveal that some
of the bits are not used, namely (9, 18, 22, 25) from c and (7, 10,
15, 26) from d.
pc2 from c
----------
5 24 7 16 6 10 20
18 - 12 3 15 23 1
9 19 2 - 14 22 11
- 13 4 - 17 21 8
pc2 from d
----------
51 35 31 52 39 45 -
50 32 - 43 36 29 48
- 41 38 47 33 40 42
49 37 30 46 - 34 44
So we generate tables for that too.
gen_pattern("pc2_c_1", 63, [ 5, 24, 7, 16, 6, 10 ], 0, 0x800000);
gen_pattern("pc2_c_2", 63, [ 20, 18, 12, 3, 15, 23 ], 0, 0x800000);
gen_pattern("pc2_c_3", 63, [ 1, 9, 19, 2, 14, 22 ], 0, 0x800000);
gen_pattern("pc2_c_4", 63, [ 11, 13, 4, 17, 21, 8 ], 0, 0x800000);
gen_pattern("pc2_d_1", 63, [ 51, 35, 31, 52, 39, 45 ], 28, 0x800000);
gen_pattern("pc2_d_2", 63, [ 50, 32, 43, 36, 29, 48 ], 28, 0x800000);
gen_pattern("pc2_d_3", 63, [ 41, 38, 47, 33, 40, 42 ], 28, 0x800000);
gen_pattern("pc2_d_4", 63, [ 49, 37, 30, 46, 34, 44 ], 28, 0x800000);
SBOX transformations
====================
The SBOX transformations are 6 bit to 4 bit transformations.
Here I grew tired and used Richard Outerbridge SBOXes. Thank you
Richard.

View File

@@ -1,424 +0,0 @@
# $Id$
include $(top_srcdir)/Makefile.am.common
AUTOMAKE_OPTIONS = subdir-objects
if HAVE_HCRYPTO_W_OPENSSL
AM_CPPFLAGS += $(INCLUDE_openssl_crypto)
endif
AM_CPPFLAGS += -I$(top_srcdir)/lib/hx509 \
-I$(srcdir)/libtommath -DUSE_HCRYPTO_LTM=1 \
-I$(srcdir)/x25519 \
-I$(srcdir)/..
WFLAGS += $(WFLAGS_LITE) -Wno-error=unused-function
# XXX: Make these not necessary:
WFLAGS += -Wno-error=unused-result -Wno-error=deprecated-declarations
WFLAGS += $(WFLAGS_UNUSED_BUT_SET_VAR)
lib_LTLIBRARIES = libhcrypto.la
check_LTLIBRARIES = libhctest.la
libhcrypto_la_LDFLAGS = -version-info 5:0:0
libhcrypto_la_LIBADD = \
$(top_builddir)/lib/asn1/libasn1.la \
$(LIB_dlopen) \
$(LIB_heimbase) \
$(LIBADD_roken)
if HAVE_HCRYPTO_W_OPENSSL
libhcrypto_la_LIBADD += $(LIB_openssl_crypto)
endif
hcryptoincludedir = $(includedir)/hcrypto
buildhcryptoinclude = $(buildinclude)/hcrypto
hcryptoinclude_HEADERS = \
aes.h \
bn.h \
des.h \
dh.h \
dsa.h \
ec.h \
ecdh.h \
ecdsa.h \
engine.h \
evp.h \
evp-hcrypto.h \
evp-cc.h \
evp-openssl.h \
evp-pkcs11.h \
hmac.h \
md4.h \
md5.h \
pkcs12.h \
rand.h \
rc2.h \
rc4.h \
rsa.h \
sha.h \
ui.h \
undef.h
install-build-headers:: $(hcryptoinclude_HEADERS) $(x25519include_HEADERS)
@foo='$(hcryptoinclude_HEADERS)'; \
for f in $$foo; do \
f=`basename $$f`; \
if test -f "$(srcdir)/$$f"; then file="$(srcdir)/$$f"; \
else file="$$f"; fi; \
if cmp -s $$file $(buildhcryptoinclude)/$$f 2> /dev/null ; then \
: ; else \
echo "cp $$file $(buildhcryptoinclude)/$$f";\
cp $$file $(buildhcryptoinclude)/$$f; \
fi ; \
done
PROGRAM_TESTS = \
destest \
mdtest \
rc2test \
rctest \
test_bn \
test_bulk \
test_cipher \
test_engine_dso \
test_hmac \
test_pkcs12 \
test_pkcs5
libhctest_la_SOURCES = \
des-tables.h \
des.c \
des.h \
ui.c \
ui.h
destest_LDADD = libhctest.la $(LIB_roken)
SCRIPT_TESTS = \
test_crypto
noinst_PROGRAMS = test_rand
noinst_HEADERS = \
x25519/ed25519_ref10_fe_51.h \
x25519/ed25519_ref10_fe_25_5.h \
x25519/ed25519_ref10.h \
x25519/fe_25_5/base.h \
x25519/fe_25_5/base2.h \
x25519/fe_25_5/constants.h \
x25519/fe_25_5/fe.h \
x25519/fe_51/base.h \
x25519/fe_51/base2.h \
x25519/fe_51/constants.h \
x25519/fe_51/fe.h \
x25519/align.h \
x25519_ref10.h
check_PROGRAMS = $(PROGRAM_TESTS) test_rsa test_dh example_evp_cipher
check_SCRIPTS = $(SCRIPT_TESTS)
TESTS = $(PROGRAM_TESTS) $(SCRIPT_TESTS)
LDADD = $(lib_LTLIBRARIES) $(LIB_roken) $(LIB_openssl_crypto)
test_rand_LDADD = $(LDADD) -lm
libhcrypto_la_SOURCES = \
$(ltmsources) \
$(x25519sources)\
aes.c \
aes.h \
bn.c \
bn.h \
common.c \
common.h \
camellia.h \
camellia.c \
camellia-ntt.c \
camellia-ntt.h \
des-tables.h \
des.c \
des.h \
dh.c \
dh.h \
dh-ltm.c \
dsa.c \
dsa.h \
doxygen.c \
evp.c \
evp.h \
evp-hcrypto.c \
evp-cc.c \
evp-openssl.c \
evp-pkcs11.c \
engine.c \
engine.h \
hash.h \
hmac.c \
hmac.h \
md4.c \
md4.h \
md5.c \
md5.h \
pkcs5.c \
pkcs12.c \
rand-fortuna.c \
rand-timer.c \
rand-unix.c \
rand.c \
rand.h \
randi.h \
rc2.c \
rc2.h \
rc4.c \
rc4.h \
rijndael-alg-fst.c \
rijndael-alg-fst.h \
rnd_keys.c \
rsa.c \
rsa-gmp.c \
rsa-ltm.c \
rsa.h \
sha.c \
sha.h \
sha256.c \
sha512.c \
validate.c \
ui.c \
ui.h \
undef.h
ltmsources = \
libtommath/bn_cutoffs.c \
libtommath/bn_deprecated.c \
libtommath/bn_mp_2expt.c \
libtommath/bn_mp_abs.c \
libtommath/bn_mp_add.c \
libtommath/bn_mp_add_d.c \
libtommath/bn_mp_addmod.c \
libtommath/bn_mp_and.c \
libtommath/bn_mp_clamp.c \
libtommath/bn_mp_clear.c \
libtommath/bn_mp_clear_multi.c \
libtommath/bn_mp_cmp.c \
libtommath/bn_mp_cmp_d.c \
libtommath/bn_mp_cmp_mag.c \
libtommath/bn_mp_cnt_lsb.c \
libtommath/bn_mp_complement.c \
libtommath/bn_mp_copy.c \
libtommath/bn_mp_count_bits.c \
libtommath/bn_mp_decr.c \
libtommath/bn_mp_div.c \
libtommath/bn_mp_div_2.c \
libtommath/bn_mp_div_2d.c \
libtommath/bn_mp_div_3.c \
libtommath/bn_mp_div_d.c \
libtommath/bn_mp_dr_is_modulus.c \
libtommath/bn_mp_dr_reduce.c \
libtommath/bn_mp_dr_setup.c \
libtommath/bn_mp_error_to_string.c \
libtommath/bn_mp_exch.c \
libtommath/bn_mp_expt_u32.c \
libtommath/bn_mp_exptmod.c \
libtommath/bn_mp_exteuclid.c \
libtommath/bn_mp_fread.c \
libtommath/bn_mp_from_sbin.c \
libtommath/bn_mp_from_ubin.c \
libtommath/bn_mp_fwrite.c \
libtommath/bn_mp_gcd.c \
libtommath/bn_mp_get_double.c \
libtommath/bn_mp_get_i32.c \
libtommath/bn_mp_get_i64.c \
libtommath/bn_mp_get_l.c \
libtommath/bn_mp_get_ll.c \
libtommath/bn_mp_get_mag_u32.c \
libtommath/bn_mp_get_mag_u64.c \
libtommath/bn_mp_get_mag_ul.c \
libtommath/bn_mp_get_mag_ull.c \
libtommath/bn_mp_grow.c \
libtommath/bn_mp_incr.c \
libtommath/bn_mp_init.c \
libtommath/bn_mp_init_copy.c \
libtommath/bn_mp_init_i32.c \
libtommath/bn_mp_init_i64.c \
libtommath/bn_mp_init_l.c \
libtommath/bn_mp_init_ll.c \
libtommath/bn_mp_init_multi.c \
libtommath/bn_mp_init_set.c \
libtommath/bn_mp_init_size.c \
libtommath/bn_mp_init_u32.c \
libtommath/bn_mp_init_u64.c \
libtommath/bn_mp_init_ul.c \
libtommath/bn_mp_init_ull.c \
libtommath/bn_mp_invmod.c \
libtommath/bn_mp_is_square.c \
libtommath/bn_mp_iseven.c \
libtommath/bn_mp_isodd.c \
libtommath/bn_mp_kronecker.c \
libtommath/bn_mp_lcm.c \
libtommath/bn_mp_log_u32.c \
libtommath/bn_mp_lshd.c \
libtommath/bn_mp_mod.c \
libtommath/bn_mp_mod_2d.c \
libtommath/bn_mp_mod_d.c \
libtommath/bn_mp_montgomery_calc_normalization.c \
libtommath/bn_mp_montgomery_reduce.c \
libtommath/bn_mp_montgomery_setup.c \
libtommath/bn_mp_mul.c \
libtommath/bn_mp_mul_2.c \
libtommath/bn_mp_mul_2d.c \
libtommath/bn_mp_mul_d.c \
libtommath/bn_mp_mulmod.c \
libtommath/bn_mp_neg.c \
libtommath/bn_mp_or.c \
libtommath/bn_mp_pack.c \
libtommath/bn_mp_pack_count.c \
libtommath/bn_mp_prime_fermat.c \
libtommath/bn_mp_prime_frobenius_underwood.c \
libtommath/bn_mp_prime_is_prime.c \
libtommath/bn_mp_prime_miller_rabin.c \
libtommath/bn_mp_prime_next_prime.c \
libtommath/bn_mp_prime_rabin_miller_trials.c \
libtommath/bn_mp_prime_rand.c \
libtommath/bn_mp_prime_strong_lucas_selfridge.c \
libtommath/bn_mp_radix_size.c \
libtommath/bn_mp_radix_smap.c \
libtommath/bn_mp_rand.c \
libtommath/bn_mp_read_radix.c \
libtommath/bn_mp_reduce.c \
libtommath/bn_mp_reduce_2k.c \
libtommath/bn_mp_reduce_2k_l.c \
libtommath/bn_mp_reduce_2k_setup.c \
libtommath/bn_mp_reduce_2k_setup_l.c \
libtommath/bn_mp_reduce_is_2k.c \
libtommath/bn_mp_reduce_is_2k_l.c \
libtommath/bn_mp_reduce_setup.c \
libtommath/bn_mp_root_u32.c \
libtommath/bn_mp_rshd.c \
libtommath/bn_mp_sbin_size.c \
libtommath/bn_mp_set.c \
libtommath/bn_mp_set_double.c \
libtommath/bn_mp_set_i32.c \
libtommath/bn_mp_set_i64.c \
libtommath/bn_mp_set_l.c \
libtommath/bn_mp_set_ll.c \
libtommath/bn_mp_set_u32.c \
libtommath/bn_mp_set_u64.c \
libtommath/bn_mp_set_ul.c \
libtommath/bn_mp_set_ull.c \
libtommath/bn_mp_shrink.c \
libtommath/bn_mp_signed_rsh.c \
libtommath/bn_mp_sqr.c \
libtommath/bn_mp_sqrmod.c \
libtommath/bn_mp_sqrt.c \
libtommath/bn_mp_sqrtmod_prime.c \
libtommath/bn_mp_sub.c \
libtommath/bn_mp_sub_d.c \
libtommath/bn_mp_submod.c \
libtommath/bn_mp_to_radix.c \
libtommath/bn_mp_to_sbin.c \
libtommath/bn_mp_to_ubin.c \
libtommath/bn_mp_ubin_size.c \
libtommath/bn_mp_unpack.c \
libtommath/bn_mp_xor.c \
libtommath/bn_mp_zero.c \
libtommath/bn_prime_tab.c \
libtommath/bn_s_mp_add.c \
libtommath/bn_s_mp_balance_mul.c \
libtommath/bn_s_mp_exptmod.c \
libtommath/bn_s_mp_exptmod_fast.c \
libtommath/bn_s_mp_get_bit.c \
libtommath/bn_s_mp_invmod_fast.c \
libtommath/bn_s_mp_invmod_slow.c \
libtommath/bn_s_mp_karatsuba_mul.c \
libtommath/bn_s_mp_karatsuba_sqr.c \
libtommath/bn_s_mp_montgomery_reduce_fast.c \
libtommath/bn_s_mp_mul_digs.c \
libtommath/bn_s_mp_mul_digs_fast.c \
libtommath/bn_s_mp_mul_high_digs.c \
libtommath/bn_s_mp_mul_high_digs_fast.c \
libtommath/bn_s_mp_prime_is_divisible.c \
libtommath/bn_s_mp_rand_jenkins.c \
libtommath/bn_s_mp_rand_platform.c \
libtommath/bn_s_mp_reverse.c \
libtommath/bn_s_mp_sqr.c \
libtommath/bn_s_mp_sqr_fast.c \
libtommath/bn_s_mp_sub.c \
libtommath/bn_s_mp_toom_mul.c \
libtommath/bn_s_mp_toom_sqr.c \
libtommath/tommath_private.h \
libtommath/tommath_cutoffs.h \
libtommath/tommath_superclass.h \
libtommath/tommath_class.h \
libtommath/tommath.h
x25519sources = \
x25519/ed25519_ref10.c \
x25519/x25519_ref10.c
$(libhcrypto_la_OBJECTS) $(test_rand_OBJECTS): hcrypto-link
libhcrypto_la_CPPFLAGS = -DBUILD_HCRYPTO_LIB $(AM_CPPFLAGS)
if versionscript
libhcrypto_la_LDFLAGS += $(LDFLAGS_VERSION_SCRIPT)$(srcdir)/version-script.map
endif
$(libhcrypto_la_OBJECTS): $(srcdir)/version-script.map
hcrypto-link:
$(LN_S) $(srcdir)/../hcrypto hcrypto
touch hcrypto-link
do_subst = sed -e 's,[@]srcdir[@],$(srcdir),g' -e 's,[@]exeext[@],$(exeext),g'
test_crypto: test_crypto.in Makefile
$(do_subst) < $(srcdir)/test_crypto.in > test_crypto.tmp
chmod +x test_crypto.tmp
mv test_crypto.tmp test_crypto
CLEANFILES = \
crypto-test \
crypto-test2 \
error \
hcrypto \
hcrypto-link \
test.file \
test_crypto \
test-out* \
test_crypto.tmp \
test_crypto.tmp
EXTRA_DIST = \
NTMakefile \
DESperate.txt \
passwd_dialog.rc \
libhcrypto-exports.def \
dh-tfm.c \
ec.h \
ecdh.h \
ecdsa.h \
evp-crypt.c \
evp-w32.c \
evp-w32.h \
evp-wincng.c \
evp-wincng.h \
gen-des.pl \
md5crypt_test.c \
passwd_dialog.aps \
passwd_dialog.clw \
passwd_dialog.rc \
passwd_dialog.res \
passwd_dlg.c \
passwd_dlg.h \
rand-w32.c \
resource.h \
rsa-tfm.c \
rsakey.der \
rsakey2048.der \
rsakey4096.der \
test_crypto.in \
version-script.map

View File

@@ -1,272 +0,0 @@
########################################################################
#
# Copyright (c) 2009-2016, 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.
#
SUBDIRS=libtommath x25519
RELDIR=lib\hcrypto
!include ../../windows/NTMakefile.w32
HCRYPTOINCLUDEDIR = $(INCDIR)\hcrypto
HEIMBASEDIR = $(SRC)\lib\base
HX509DIR = $(SRC)\lib\hx509
!ifdef INCLUDE_openssl_crypto
openssl_inc=-I$(INCLUDE_openssl_crypto)
!endif
intcflags=-DKRB5 -DASN1_LIB -I$(HCRYPTOINCLUDEDIR) -DUSE_HCRYPTO_LTM=1 \
-I$(HX509DIR) $(openssl_inc)
# Do dependencies first
all:: subdirs
clean:: clean-subdirs
test:: test-subdirs
# Include files
INCFILES= \
$(HCRYPTOINCLUDEDIR)\aes.h \
$(HCRYPTOINCLUDEDIR)\bn.h \
$(HCRYPTOINCLUDEDIR)\des.h \
$(HCRYPTOINCLUDEDIR)\dh.h \
$(HCRYPTOINCLUDEDIR)\dsa.h \
$(HCRYPTOINCLUDEDIR)\ec.h \
$(HCRYPTOINCLUDEDIR)\ecdh.h \
$(HCRYPTOINCLUDEDIR)\ecdsa.h \
$(HCRYPTOINCLUDEDIR)\engine.h \
$(HCRYPTOINCLUDEDIR)\evp.h \
$(HCRYPTOINCLUDEDIR)\evp-hcrypto.h \
$(HCRYPTOINCLUDEDIR)\evp-cc.h \
$(HCRYPTOINCLUDEDIR)\evp-openssl.h \
$(HCRYPTOINCLUDEDIR)\evp-pkcs11.h \
$(HCRYPTOINCLUDEDIR)\evp-wincng.h \
$(HCRYPTOINCLUDEDIR)\evp-w32.h \
$(HCRYPTOINCLUDEDIR)\hmac.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 \
$(HCRYPTOINCLUDEDIR)\undef.h \
$(HCRYPTOINCLUDEDIR)\x25519_ref10.h \
mkincdir:
!if !exist($(HCRYPTOINCLUDEDIR))
$(MKDIR) $(HCRYPTOINCLUDEDIR)
!endif
{}.h{$(HCRYPTOINCLUDEDIR)}.h:
$(CP) $** $@
all:: mkincdir
all:: $(INCFILES)
# libhcrypto
libhcrypto_OBJs = \
$(OBJ)\aes.obj \
$(OBJ)\bn.obj \
$(OBJ)\camellia.obj \
$(OBJ)\camellia-ntt.obj \
$(OBJ)\common.obj \
$(OBJ)\des.obj \
$(OBJ)\dh.obj \
$(OBJ)\dh-ltm.obj \
$(OBJ)\dh-tfm.obj \
$(OBJ)\dsa.obj \
$(OBJ)\evp.obj \
$(OBJ)\evp-hcrypto.obj \
$(OBJ)\evp-cc.obj \
$(OBJ)\evp-openssl.obj \
$(OBJ)\evp-pkcs11.obj \
$(OBJ)\evp-wincng.obj \
$(OBJ)\evp-w32.obj \
$(OBJ)\engine.obj \
$(OBJ)\hmac.obj \
$(OBJ)\md4.obj \
$(OBJ)\md5.obj \
$(OBJ)\pkcs5.obj \
$(OBJ)\pkcs12.obj \
$(OBJ)\rand-w32.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-ltm.obj \
$(OBJ)\rsa-tfm.obj \
$(OBJ)\sha.obj \
$(OBJ)\sha256.obj \
$(OBJ)\sha512.obj \
$(OBJ)\ui.obj \
$(OBJ)\validate.obj
$(LIBHCRYPTO): $(libhcrypto_OBJs)
$(LIBCON)
all:: $(LIBHCRYPTO)
clean::
-$(RM) $(LIBHCRYPTO)
# Tests
TESTLIB=$(OBJ)\libhctest.lib
$(TESTLIB): \
$(OBJ)\des.obj \
$(OBJ)\ui.obj
$(LIBCON)
test-binaries: \
$(OBJ)\destest.exe \
$(OBJ)\example_evp_cipher.exe \
$(OBJ)\mdtest.exe \
$(OBJ)\rc2test.exe \
$(OBJ)\rctest.exe \
$(OBJ)\test_bn.exe \
$(OBJ)\test_bulk.exe \
$(OBJ)\test_cipher.exe \
$(OBJ)\test_engine_dso.exe \
$(OBJ)\test_hmac.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) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\example_evp_cipher.exe: $(OBJ)\example_evp_cipher.obj $(TESTLIB) $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\mdtest.exe: $(OBJ)\mdtest.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(OBJ)\sha512.obj
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\rc2test.exe: $(OBJ)\rc2test.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\rctest.exe: $(OBJ)\rctest.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_bn.exe: $(OBJ)\test_bn.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_bulk.exe: $(OBJ)\test_bulk.obj $(TESTLIB) $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_cipher.exe: $(OBJ)\test_cipher.obj $(TESTLIB) $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_engine_dso.exe: $(OBJ)\test_engine_dso.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_hmac.exe: $(OBJ)\test_hmac.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_pkcs5.exe: $(OBJ)\test_pkcs5.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_pkcs12.exe: $(OBJ)\test_pkcs12.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_rsa.exe: $(OBJ)\test_rsa.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_dh.exe: $(OBJ)\test_dh.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
$(OBJ)\test_rand.exe: $(OBJ)\test_rand.obj $(LIBHEIMDAL) $(LIBROKEN) $(LIBHEIMBASE) $(LIBVERS)
$(EXECONLINK)
$(EXEPREP_NODIST)
SRCDIR2=$(SRCDIR:\=\\\\)
$(OBJ)\test_crypto.sh: test_crypto.in NTMakefile
$(SED) -e "s,[@]srcdir[@],$(SRCDIR2),g" -e "s,[@]exeext[@],.exe,g" -e "s,\r,," < test_crypto.in > $@ || $(RM) $@
test-run:
cd $(OBJ)
!ifdef SH
-$(SH) test_crypto.sh
!endif
-destest.exe
-mdtest.exe
-rc2test.exe
-rctest.exe
-test_bn.exe
-test_bulk.exe --provider=hcrypto
-test_bulk.exe --provider=w32crypto
-test_cipher.exe
-test_engine_dso.exe
-test_hmac.exe
-test_pkcs5.exe
-test_pkcs12.exe
-test_rsa.exe
-test_dh.exe
cd $(SRCDIR)
test:: $(TESTLIB) test-binaries test-run
test-exports:
$(PERL) ..\..\cf\w32-check-exported-symbols.pl --vs version-script.map --def libhcrypto-exports.def
test:: test-exports

View File

@@ -1,142 +0,0 @@
/*
* Copyright (c) 2003 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#ifdef KRB5
#include <krb5-types.h>
#endif
#include "rijndael-alg-fst.h"
#include "aes.h"
int
AES_set_encrypt_key(const unsigned char *userkey, const int bits, AES_KEY *key)
{
key->rounds = rijndaelKeySetupEnc(key->key, userkey, bits);
if (key->rounds == 0)
return -1;
return 0;
}
int
AES_set_decrypt_key(const unsigned char *userkey, const int bits, AES_KEY *key)
{
key->rounds = rijndaelKeySetupDec(key->key, userkey, bits);
if (key->rounds == 0)
return -1;
return 0;
}
void
AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
{
rijndaelEncrypt(key->key, key->rounds, in, out);
}
void
AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key)
{
rijndaelDecrypt(key->key, key->rounds, in, out);
}
void
AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
unsigned long size, const AES_KEY *key,
unsigned char *iv, int forward_encrypt)
{
unsigned char tmp[AES_BLOCK_SIZE];
int i;
if (forward_encrypt) {
while (size >= AES_BLOCK_SIZE) {
for (i = 0; i < AES_BLOCK_SIZE; i++)
tmp[i] = in[i] ^ iv[i];
AES_encrypt(tmp, out, key);
memcpy(iv, out, AES_BLOCK_SIZE);
size -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}
if (size) {
for (i = 0; i < size; i++)
tmp[i] = in[i] ^ iv[i];
for (i = size; i < AES_BLOCK_SIZE; i++)
tmp[i] = iv[i];
AES_encrypt(tmp, out, key);
memcpy(iv, out, AES_BLOCK_SIZE);
}
} else {
while (size >= AES_BLOCK_SIZE) {
memcpy(tmp, in, AES_BLOCK_SIZE);
AES_decrypt(tmp, out, key);
for (i = 0; i < AES_BLOCK_SIZE; i++)
out[i] ^= iv[i];
memcpy(iv, tmp, AES_BLOCK_SIZE);
size -= AES_BLOCK_SIZE;
in += AES_BLOCK_SIZE;
out += AES_BLOCK_SIZE;
}
if (size) {
memcpy(tmp, in, AES_BLOCK_SIZE);
AES_decrypt(tmp, out, key);
for (i = 0; i < size; i++)
out[i] ^= iv[i];
memcpy(iv, tmp, AES_BLOCK_SIZE);
}
}
}
void
AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
unsigned long size, const AES_KEY *key,
unsigned char *iv, int forward_encrypt)
{
int i;
for (i = 0; i < size; i++) {
unsigned char tmp[AES_BLOCK_SIZE + 1];
memcpy(tmp, iv, AES_BLOCK_SIZE);
AES_encrypt(iv, iv, key);
if (!forward_encrypt) {
tmp[AES_BLOCK_SIZE] = in[i];
}
out[i] = in[i] ^ iv[0];
if (forward_encrypt) {
tmp[AES_BLOCK_SIZE] = out[i];
}
memcpy(iv, &tmp[1], AES_BLOCK_SIZE);
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright (c) 2003-2004 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_AES_H
#define HEIM_AES_H 1
/* symbol renaming */
#define AES_set_encrypt_key hc_AES_set_encrypt_key
#define AES_set_decrypt_key hc_AES_decrypt_key
#define AES_encrypt hc_AES_encrypt
#define AES_decrypt hc_AES_decrypt
#define AES_cbc_encrypt hc_AES_cbc_encrypt
#define AES_cfb8_encrypt hc_AES_cfb8_encrypt
/*
*
*/
#define AES_BLOCK_SIZE 16
#define AES_MAXNR 14
#define AES_ENCRYPT 1
#define AES_DECRYPT 0
typedef struct aes_key {
uint32_t key[(AES_MAXNR+1)*4];
int rounds;
} AES_KEY;
#ifdef __cplusplus
extern "C" {
#endif
int AES_set_encrypt_key(const unsigned char *, const int, AES_KEY *);
int AES_set_decrypt_key(const unsigned char *, const int, AES_KEY *);
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 *,
unsigned long, const AES_KEY *,
unsigned char *, int);
void AES_cfb8_encrypt(const unsigned char *, unsigned char *,
unsigned long, const AES_KEY *,
unsigned char *, int);
#ifdef __cplusplus
}
#endif
#endif /* HEIM_AES_H */

View File

@@ -1,529 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <krb5-types.h>
#include <rfc2459_asn1.h> /* XXX */
#include <der.h>
#include <bn.h>
#include <rand.h>
#include <hex.h>
BIGNUM *
BN_new(void)
{
heim_integer *hi;
hi = calloc(1, sizeof(*hi));
return (BIGNUM *)hi;
}
void
BN_free(BIGNUM *bn)
{
BN_clear(bn);
free(bn);
}
void
BN_clear(BIGNUM *bn)
{
heim_integer *hi = (heim_integer *)bn;
if (hi->data) {
memset(hi->data, 0, hi->length);
free(hi->data);
}
memset(hi, 0, sizeof(*hi));
}
void
BN_clear_free(BIGNUM *bn)
{
BN_free(bn);
}
BIGNUM *
BN_dup(const BIGNUM *bn)
{
BIGNUM *b = BN_new();
if (der_copy_heim_integer((const heim_integer *)bn, (heim_integer *)b)) {
BN_free(b);
return NULL;
}
return b;
}
/*
* If the caller really want to know the number of bits used, subtract
* one from the length, multiply by 8, and then lookup in the table
* how many bits the hightest byte uses.
*/
int
BN_num_bits(const BIGNUM *bn)
{
static unsigned char num2bits[256] = {
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
};
const heim_integer *i = (const void *)bn;
if (i->length == 0)
return 0;
return (i->length - 1) * 8 + num2bits[((unsigned char *)i->data)[0]];
}
int
BN_num_bytes(const BIGNUM *bn)
{
return ((const heim_integer *)bn)->length;
}
/*
* Ignore negative flag.
*/
BIGNUM *
BN_bin2bn(const void *s, int len, BIGNUM *bn)
{
heim_integer *hi = (void *)bn;
if (len < 0)
return NULL;
if (hi == NULL) {
hi = (heim_integer *)BN_new();
if (hi == NULL)
return NULL;
}
if (hi->data)
BN_clear((BIGNUM *)hi);
hi->negative = 0;
hi->data = malloc(len);
if (hi->data == NULL && len != 0) {
if (bn == NULL)
BN_free((BIGNUM *)hi);
return NULL;
}
hi->length = len;
if (len)
memcpy(hi->data, s, len);
return (BIGNUM *)hi;
}
int
BN_bn2bin(const BIGNUM *bn, void *to)
{
const heim_integer *hi = (const void *)bn;
memcpy(to, hi->data, hi->length);
return hi->length;
}
int
BN_hex2bn(BIGNUM **bnp, const char *in)
{
int negative;
ssize_t ret;
size_t len;
void *data;
len = strlen(in);
data = malloc(len);
if (data == NULL)
return 0;
if (*in == '-') {
negative = 1;
in++;
} else
negative = 0;
ret = hex_decode(in, data, len);
if (ret < 0) {
free(data);
return 0;
}
*bnp = BN_bin2bn(data, ret, NULL);
free(data);
if (*bnp == NULL)
return 0;
BN_set_negative(*bnp, negative);
return 1;
}
char *
BN_bn2hex(const BIGNUM *bn)
{
ssize_t ret;
size_t len;
void *data;
char *str;
len = BN_num_bytes(bn);
data = malloc(len);
if (data == NULL)
return 0;
len = BN_bn2bin(bn, data);
ret = hex_encode(data, len, &str);
free(data);
if (ret < 0)
return 0;
return str;
}
int
BN_cmp(const BIGNUM *bn1, const BIGNUM *bn2)
{
return der_heim_integer_cmp((const heim_integer *)bn1,
(const heim_integer *)bn2);
}
void
BN_set_negative(BIGNUM *bn, int flag)
{
((heim_integer *)bn)->negative = (flag ? 1 : 0);
}
int
BN_is_negative(const BIGNUM *bn)
{
return ((const heim_integer *)bn)->negative ? 1 : 0;
}
static const unsigned char is_set[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
int
BN_is_bit_set(const BIGNUM *bn, int bit)
{
const heim_integer *hi = (const heim_integer *)bn;
unsigned char *p = hi->data;
if ((bit / 8) >= hi->length || hi->length == 0)
return 0;
return p[hi->length - 1 - (bit / 8)] & is_set[bit % 8];
}
int
BN_set_bit(BIGNUM *bn, int bit)
{
heim_integer *hi = (heim_integer *)bn;
unsigned char *p;
if ((bit / 8) > hi->length || hi->length == 0) {
size_t len = bit == 0 ? 1 : (bit + 7) / 8;
void *d = realloc(hi->data, len);
if (d == NULL)
return 0;
hi->data = d;
p = hi->data;
memset(&p[hi->length], 0, len);
hi->length = len;
} else
p = hi->data;
p[hi->length - 1 - (bit / 8)] |= is_set[bit % 8];
return 1;
}
int
BN_clear_bit(BIGNUM *bn, int bit)
{
heim_integer *hi = (heim_integer *)bn;
unsigned char *p = hi->data;
if ((bit / 8) > hi->length || hi->length == 0)
return 0;
p[hi->length - 1 - (bit / 8)] &= (unsigned char)(~(is_set[bit % 8]));
return 1;
}
int
BN_set_word(BIGNUM *bn, unsigned long num)
{
unsigned char p[sizeof(num)];
unsigned long num2;
int i, len;
if (bn == NULL)
return 0;
for (num2 = num, i = 0; num2 > 0; i++)
num2 = num2 >> 8;
len = i;
for (; i > 0; i--) {
p[i - 1] = (num & 0xff);
num = num >> 8;
}
bn = BN_bin2bn(p, len, bn);
return bn != NULL;
}
unsigned long
BN_get_word(const BIGNUM *bn)
{
const heim_integer *hi = (const heim_integer *)bn;
unsigned long num = 0;
int i;
if (hi->negative || hi->length > sizeof(num))
return ULONG_MAX;
for (i = 0; i < hi->length; i++)
num = ((unsigned char *)hi->data)[i] | (num << 8);
return num;
}
int
BN_rand(BIGNUM *bn, int bits, int top, int bottom)
{
size_t len = (bits + 7) / 8;
heim_integer *i = (heim_integer *)bn;
BN_clear(bn);
i->negative = 0;
i->data = malloc(len);
if (i->data == NULL && len != 0)
return 0;
i->length = len;
if (RAND_bytes(i->data, i->length) != 1) {
free(i->data);
i->data = NULL;
return 0;
}
{
size_t j = len * 8;
while(j > bits) {
BN_clear_bit(bn, j - 1);
j--;
}
}
if (top == -1) {
;
} else if (top == 0 && bits > 0) {
BN_set_bit(bn, bits - 1);
} else if (top == 1 && bits > 1) {
BN_set_bit(bn, bits - 1);
BN_set_bit(bn, bits - 2);
} else {
BN_clear(bn);
return 0;
}
if (bottom && bits > 0)
BN_set_bit(bn, 0);
return 1;
}
/*
*
*/
int
BN_uadd(BIGNUM *res, const BIGNUM *a, const BIGNUM *b)
{
const heim_integer *ai = (const heim_integer *)a;
const heim_integer *bi = (const heim_integer *)b;
const unsigned char *ap, *bp;
unsigned char *cp;
heim_integer ci;
int carry = 0;
ssize_t len;
if (ai->negative && bi->negative)
return 0;
if (ai->length < bi->length) {
const heim_integer *si = bi;
bi = ai; ai = si;
}
ci.negative = 0;
ci.length = ai->length + 1;
ci.data = malloc(ci.length);
if (ci.data == NULL)
return 0;
ap = &((const unsigned char *)ai->data)[ai->length - 1];
bp = &((const unsigned char *)bi->data)[bi->length - 1];
cp = &((unsigned char *)ci.data)[ci.length - 1];
for (len = bi->length; len > 0; len--) {
carry = *ap + *bp + carry;
*cp = carry & 0xff;
carry = (carry & ~0xff) ? 1 : 0;
ap--; bp--; cp--;
}
for (len = ai->length - bi->length; len > 0; len--) {
carry = *ap + carry;
*cp = carry & 0xff;
carry = (carry & ~0xff) ? 1 : 0;
ap--; cp--;
}
if (!carry)
memmove(cp, cp + 1, --ci.length);
else
*cp = carry;
BN_clear(res);
*((heim_integer *)res) = ci;
return 1;
}
/*
* Callback when doing slow generation of numbers, like primes.
*/
void
BN_GENCB_set(BN_GENCB *gencb, int (*cb_2)(int, int, BN_GENCB *), void *ctx)
{
gencb->ver = 2;
gencb->cb.cb_2 = cb_2;
gencb->arg = ctx;
}
int
BN_GENCB_call(BN_GENCB *cb, int a, int b)
{
if (cb == NULL || cb->cb.cb_2 == NULL)
return 1;
return cb->cb.cb_2(a, b, cb);
}
/*
*
*/
struct BN_CTX {
struct {
BIGNUM **val;
size_t used;
size_t len;
} bn;
struct {
size_t *val;
size_t used;
size_t len;
} stack;
};
BN_CTX *
BN_CTX_new(void)
{
struct BN_CTX *c;
c = calloc(1, sizeof(*c));
return c;
}
void
BN_CTX_free(BN_CTX *c)
{
size_t i;
for (i = 0; i < c->bn.len; i++)
BN_free(c->bn.val[i]);
free(c->bn.val);
free(c->stack.val);
}
BIGNUM *
BN_CTX_get(BN_CTX *c)
{
if (c->bn.used == c->bn.len) {
void *ptr;
size_t i;
c->bn.len += 16;
ptr = realloc(c->bn.val, c->bn.len * sizeof(c->bn.val[0]));
if (ptr == NULL)
return NULL;
c->bn.val = ptr;
for (i = c->bn.used; i < c->bn.len; i++) {
c->bn.val[i] = BN_new();
if (c->bn.val[i] == NULL) {
c->bn.len = i;
return NULL;
}
}
}
return c->bn.val[c->bn.used++];
}
void
BN_CTX_start(BN_CTX *c)
{
if (c->stack.used == c->stack.len) {
void *ptr;
c->stack.len += 16;
ptr = realloc(c->stack.val, c->stack.len * sizeof(c->stack.val[0]));
if (ptr == NULL)
abort();
c->stack.val = ptr;
}
c->stack.val[c->stack.used++] = c->bn.used;
}
void
BN_CTX_end(BN_CTX *c)
{
const size_t prev = c->stack.val[c->stack.used - 1];
size_t i;
if (c->stack.used == 0)
abort();
for (i = prev; i < c->bn.used; i++)
BN_clear(c->bn.val[i]);
c->stack.used--;
c->bn.used = prev;
}

View File

@@ -1,139 +0,0 @@
/*
* Copyright (c) 2006-2016 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/*
* $Id$
*/
#ifndef _HEIM_BN_H
#define _HEIM_BN_H 1
/* symbol renaming */
#define BN_GENCB_call hc_BN_GENCB_call
#define BN_GENCB_set hc_BN_GENCB_set
#define BN_bin2bn hc_BN_bin2bn
#define BN_bn2bin hc_BN_bn2bin
#define BN_bn2hex hc_BN_bn2hex
#define BN_clear hc_BN_clear
#define BN_clear_bit hc_BN_clear_bit
#define BN_clear_free hc_BN_clear_free
#define BN_cmp hc_BN_cmp
#define BN_dup hc_BN_dup
#define BN_free hc_BN_free
#define BN_is_negative hc_BN_is_negative
#define BN_get_word hc_BN_get_word
#define BN_hex2bn hc_BN_hex2bn
#define BN_is_bit_set hc_BN_is_bit_set
#define BN_new hc_BN_new
#define BN_num_bits hc_BN_num_bits
#define BN_num_bytes hc_BN_num_bytes
#define BN_rand hc_BN_rand
#define BN_set_bit hc_BN_set_bit
#define BN_set_negative hc_BN_set_negative
#define BN_set_word hc_BN_set_word
#define BN_uadd hc_BN_uadd
#define BN_CTX_new hc_BN_CTX_new
#define BN_CTX_free hc_BN_CTX_free
#define BN_CTX_get hc_BN_CTX_get
#define BN_CTX_start hc_BN_CTX_start
#define BN_CTX_end hc_BN_CTX_end
#define BIGNUM hc_BIGNUM
#define BN_GENCB hc_BN_GENCB
#define BN_CTX hc_BN_CTX
#define BN_BLINDING hc_BN_BLINDING
#define BN_MONT_CTX hc_BN_MONT_CTX
/*
*
*/
typedef struct BIGNUM BIGNUM;
typedef struct BN_GENCB BN_GENCB;
typedef struct BN_CTX BN_CTX;
typedef struct BN_MONT_CTX BN_MONT_CTX;
typedef struct BN_BLINDING BN_BLINDING;
struct BN_GENCB {
unsigned int ver;
void *arg;
union {
int (*cb_2)(int, int, BN_GENCB *);
} cb;
};
/*
*
*/
BIGNUM *BN_new(void);
void BN_free(BIGNUM *);
void BN_clear_free(BIGNUM *);
void BN_clear(BIGNUM *);
BIGNUM *BN_dup(const BIGNUM *);
int BN_num_bits(const BIGNUM *);
int BN_num_bytes(const BIGNUM *);
int BN_cmp(const BIGNUM *, const BIGNUM *);
void BN_set_negative(BIGNUM *, int);
int BN_is_negative(const BIGNUM *);
int BN_is_bit_set(const BIGNUM *, int);
int BN_set_bit(BIGNUM *, int);
int BN_clear_bit(BIGNUM *, int);
int BN_set_word(BIGNUM *, unsigned long);
unsigned long BN_get_word(const BIGNUM *);
BIGNUM *BN_bin2bn(const void *,int len,BIGNUM *);
int BN_bn2bin(const BIGNUM *, void *);
int BN_hex2bn(BIGNUM **, const char *);
char * BN_bn2hex(const BIGNUM *);
int BN_uadd(BIGNUM *, const BIGNUM *, const BIGNUM *);
int BN_rand(BIGNUM *, int, int, int);
void BN_GENCB_set(BN_GENCB *, int (*)(int, int, BN_GENCB *), void *);
int BN_GENCB_call(BN_GENCB *, int, int);
BN_CTX *BN_CTX_new(void);
void BN_CTX_free(BN_CTX *);
BIGNUM *BN_CTX_get(BN_CTX *);
void BN_CTX_start(BN_CTX *);
void BN_CTX_end(BN_CTX *);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +0,0 @@
/* camellia.h ver 1.2.0
*
* Copyright (c) 2006,2007
* NTT (Nippon Telegraph and Telephone Corporation) . 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 as
* the first lines of this file unmodified.
* 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 NTT ``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 NTT 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.
*/
#ifndef HEADER_CAMELLIA_H
#define HEADER_CAMELLIA_H
#ifdef __cplusplus
extern "C" {
#endif
/* symbol renaming */
#define Camellia_DecryptBlock hc_Camellia_DecryptBlock
#define Camellia_Ekeygen hc_Camellia_Ekeygen
#define Camellia_EncryptBlock hc_Camellia_EncryptBlock
#define CAMELLIA_BLOCK_SIZE 16
#define CAMELLIA_TABLE_BYTE_LEN 272
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
/* u32 must be 32bit word */
typedef uint32_t u32;
typedef unsigned char u8;
typedef u32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
void Camellia_Ekeygen(const int keyBitLength,
const unsigned char *rawKey,
KEY_TABLE_TYPE keyTable);
void Camellia_EncryptBlock(const int keyBitLength,
const unsigned char *plaintext,
const KEY_TABLE_TYPE keyTable,
unsigned char *cipherText);
void Camellia_DecryptBlock(const int keyBitLength,
const unsigned char *cipherText,
const KEY_TABLE_TYPE keyTable,
unsigned char *plaintext);
#ifdef __cplusplus
}
#endif
#endif /* HEADER_CAMELLIA_H */

View File

@@ -1,113 +0,0 @@
/*
* Copyright (c) 2007 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#ifdef KRB5
#include <krb5-types.h>
#endif
#include "camellia-ntt.h"
#include "camellia.h"
int
CAMELLIA_set_key(const unsigned char *userkey,
const int bits, CAMELLIA_KEY *key)
{
key->bits = bits;
Camellia_Ekeygen(bits, userkey, key->key);
return 1;
}
void
CAMELLIA_encrypt(const unsigned char *in, unsigned char *out,
const CAMELLIA_KEY *key)
{
Camellia_EncryptBlock(key->bits, in, key->key, out);
}
void
CAMELLIA_decrypt(const unsigned char *in, unsigned char *out,
const CAMELLIA_KEY *key)
{
Camellia_DecryptBlock(key->bits, in, key->key, out);
}
void
CAMELLIA_cbc_encrypt(const unsigned char *in, unsigned char *out,
unsigned long size, const CAMELLIA_KEY *key,
unsigned char *iv, int mode_encrypt)
{
unsigned char tmp[CAMELLIA_BLOCK_SIZE];
int i;
if (mode_encrypt) {
while (size >= CAMELLIA_BLOCK_SIZE) {
for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
tmp[i] = in[i] ^ iv[i];
CAMELLIA_encrypt(tmp, out, key);
memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
size -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
out += CAMELLIA_BLOCK_SIZE;
}
if (size) {
for (i = 0; i < size; i++)
tmp[i] = in[i] ^ iv[i];
for (i = size; i < CAMELLIA_BLOCK_SIZE; i++)
tmp[i] = iv[i];
CAMELLIA_encrypt(tmp, out, key);
memcpy(iv, out, CAMELLIA_BLOCK_SIZE);
}
} else {
while (size >= CAMELLIA_BLOCK_SIZE) {
memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
CAMELLIA_decrypt(tmp, out, key);
for (i = 0; i < CAMELLIA_BLOCK_SIZE; i++)
out[i] ^= iv[i];
memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
size -= CAMELLIA_BLOCK_SIZE;
in += CAMELLIA_BLOCK_SIZE;
out += CAMELLIA_BLOCK_SIZE;
}
if (size) {
memcpy(tmp, in, CAMELLIA_BLOCK_SIZE);
CAMELLIA_decrypt(tmp, out, key);
for (i = 0; i < size; i++)
out[i] ^= iv[i];
memcpy(iv, tmp, CAMELLIA_BLOCK_SIZE);
}
}
}

View File

@@ -1,72 +0,0 @@
/*
* Copyright (c) 2007 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_CAMELLIA_H
#define HEIM_CAMELLIA_H 1
/* symbol renaming */
#define CAMELLIA_set_key hc_CAMELLIA_set_encrypt_key
#define CAMELLIA_encrypt hc_CAMELLIA_encrypt
#define CAMELLIA_decrypt hc_CAMELLIA_decrypt
#define CAMELLIA_cbc_encrypt hc_CAMELLIA_cbc_encrypt
/*
*
*/
#define CAMELLIA_BLOCK_SIZE 16
#define CAMELLIA_TABLE_BYTE_LEN 272
#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
#define CAMELLIA_ENCRYPT 1
#define CAMELLIA_DECRYPT 0
typedef struct camellia_key {
unsigned int bits;
uint32_t key[CAMELLIA_TABLE_WORD_LEN];
} CAMELLIA_KEY;
int CAMELLIA_set_key(const unsigned char *, const int, CAMELLIA_KEY *);
void CAMELLIA_encrypt(const unsigned char *, unsigned char *,
const CAMELLIA_KEY *);
void CAMELLIA_decrypt(const unsigned char *, unsigned char *,
const CAMELLIA_KEY *);
void CAMELLIA_cbc_encrypt(const unsigned char *, unsigned char *,
unsigned long, const CAMELLIA_KEY *,
unsigned char *, int);
#endif /* HEIM_CAMELLIA_H */

View File

@@ -1,65 +0,0 @@
/*
* Copyright (c) 2010 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2010 Apple 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <krb5-types.h>
#include <rfc2459_asn1.h>
#include <hcrypto/bn.h>
#include "common.h"
int
_hc_BN_to_integer(BIGNUM *bn, heim_integer *integer)
{
integer->length = BN_num_bytes(bn);
integer->data = malloc(integer->length);
if (integer->data == NULL)
return ENOMEM;
BN_bn2bin(bn, integer->data);
integer->negative = BN_is_negative(bn);
return 0;
}
BIGNUM *
_hc_integer_to_BN(const heim_integer *i, BIGNUM *bn)
{
bn = BN_bin2bn(i->data, i->length, bn);
if (bn)
BN_set_negative(bn, i->negative);
return bn;
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright (c) 2010 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2010 Apple 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifndef HCRYPTO_COMMON_H
#define HCRYPTO_COMMON_H 1
int
_hc_BN_to_integer(BIGNUM *, heim_integer *);
BIGNUM *
_hc_integer_to_BN(const heim_integer *i, BIGNUM *bn);
#endif /* HCRYPTO_COMMON_H */

View File

@@ -1,196 +0,0 @@
/* GENERATE FILE from gen-des.pl, do not edit */
/* pc1_c_3 bit pattern 5 13 21 */
static int pc1_c_3[8] = {
0x00000000, 0x00000010, 0x00001000, 0x00001010,
0x00100000, 0x00100010, 0x00101000, 0x00101010
};
/* pc1_c_4 bit pattern 1 9 17 25 */
static int pc1_c_4[16] = {
0x00000000, 0x00000001, 0x00000100, 0x00000101,
0x00010000, 0x00010001, 0x00010100, 0x00010101,
0x01000000, 0x01000001, 0x01000100, 0x01000101,
0x01010000, 0x01010001, 0x01010100, 0x01010101
};
/* pc1_d_3 bit pattern 49 41 33 */
static int pc1_d_3[8] = {
0x00000000, 0x01000000, 0x00010000, 0x01010000,
0x00000100, 0x01000100, 0x00010100, 0x01010100
};
/* pc1_d_4 bit pattern 57 53 45 37 */
static int pc1_d_4[16] = {
0x00000000, 0x00100000, 0x00001000, 0x00101000,
0x00000010, 0x00100010, 0x00001010, 0x00101010,
0x00000001, 0x00100001, 0x00001001, 0x00101001,
0x00000011, 0x00100011, 0x00001011, 0x00101011
};
/* pc2_c_1 bit pattern 5 24 7 16 6 10 */
static int pc2_c_1[64] = {
0x00000000, 0x00004000, 0x00040000, 0x00044000,
0x00000100, 0x00004100, 0x00040100, 0x00044100,
0x00020000, 0x00024000, 0x00060000, 0x00064000,
0x00020100, 0x00024100, 0x00060100, 0x00064100,
0x00000001, 0x00004001, 0x00040001, 0x00044001,
0x00000101, 0x00004101, 0x00040101, 0x00044101,
0x00020001, 0x00024001, 0x00060001, 0x00064001,
0x00020101, 0x00024101, 0x00060101, 0x00064101,
0x00080000, 0x00084000, 0x000c0000, 0x000c4000,
0x00080100, 0x00084100, 0x000c0100, 0x000c4100,
0x000a0000, 0x000a4000, 0x000e0000, 0x000e4000,
0x000a0100, 0x000a4100, 0x000e0100, 0x000e4100,
0x00080001, 0x00084001, 0x000c0001, 0x000c4001,
0x00080101, 0x00084101, 0x000c0101, 0x000c4101,
0x000a0001, 0x000a4001, 0x000e0001, 0x000e4001,
0x000a0101, 0x000a4101, 0x000e0101, 0x000e4101
};
/* pc2_c_2 bit pattern 20 18 12 3 15 23 */
static int pc2_c_2[64] = {
0x00000000, 0x00000002, 0x00000200, 0x00000202,
0x00200000, 0x00200002, 0x00200200, 0x00200202,
0x00001000, 0x00001002, 0x00001200, 0x00001202,
0x00201000, 0x00201002, 0x00201200, 0x00201202,
0x00000040, 0x00000042, 0x00000240, 0x00000242,
0x00200040, 0x00200042, 0x00200240, 0x00200242,
0x00001040, 0x00001042, 0x00001240, 0x00001242,
0x00201040, 0x00201042, 0x00201240, 0x00201242,
0x00000010, 0x00000012, 0x00000210, 0x00000212,
0x00200010, 0x00200012, 0x00200210, 0x00200212,
0x00001010, 0x00001012, 0x00001210, 0x00001212,
0x00201010, 0x00201012, 0x00201210, 0x00201212,
0x00000050, 0x00000052, 0x00000250, 0x00000252,
0x00200050, 0x00200052, 0x00200250, 0x00200252,
0x00001050, 0x00001052, 0x00001250, 0x00001252,
0x00201050, 0x00201052, 0x00201250, 0x00201252
};
/* pc2_c_3 bit pattern 1 9 19 2 14 22 */
static int pc2_c_3[64] = {
0x00000000, 0x00000004, 0x00000400, 0x00000404,
0x00400000, 0x00400004, 0x00400400, 0x00400404,
0x00000020, 0x00000024, 0x00000420, 0x00000424,
0x00400020, 0x00400024, 0x00400420, 0x00400424,
0x00008000, 0x00008004, 0x00008400, 0x00008404,
0x00408000, 0x00408004, 0x00408400, 0x00408404,
0x00008020, 0x00008024, 0x00008420, 0x00008424,
0x00408020, 0x00408024, 0x00408420, 0x00408424,
0x00800000, 0x00800004, 0x00800400, 0x00800404,
0x00c00000, 0x00c00004, 0x00c00400, 0x00c00404,
0x00800020, 0x00800024, 0x00800420, 0x00800424,
0x00c00020, 0x00c00024, 0x00c00420, 0x00c00424,
0x00808000, 0x00808004, 0x00808400, 0x00808404,
0x00c08000, 0x00c08004, 0x00c08400, 0x00c08404,
0x00808020, 0x00808024, 0x00808420, 0x00808424,
0x00c08020, 0x00c08024, 0x00c08420, 0x00c08424
};
/* pc2_c_4 bit pattern 11 13 4 17 21 8 */
static int pc2_c_4[64] = {
0x00000000, 0x00010000, 0x00000008, 0x00010008,
0x00000080, 0x00010080, 0x00000088, 0x00010088,
0x00100000, 0x00110000, 0x00100008, 0x00110008,
0x00100080, 0x00110080, 0x00100088, 0x00110088,
0x00000800, 0x00010800, 0x00000808, 0x00010808,
0x00000880, 0x00010880, 0x00000888, 0x00010888,
0x00100800, 0x00110800, 0x00100808, 0x00110808,
0x00100880, 0x00110880, 0x00100888, 0x00110888,
0x00002000, 0x00012000, 0x00002008, 0x00012008,
0x00002080, 0x00012080, 0x00002088, 0x00012088,
0x00102000, 0x00112000, 0x00102008, 0x00112008,
0x00102080, 0x00112080, 0x00102088, 0x00112088,
0x00002800, 0x00012800, 0x00002808, 0x00012808,
0x00002880, 0x00012880, 0x00002888, 0x00012888,
0x00102800, 0x00112800, 0x00102808, 0x00112808,
0x00102880, 0x00112880, 0x00102888, 0x00112888
};
/* pc2_d_1 bit pattern 51 35 31 52 39 45 */
static int pc2_d_1[64] = {
0x00000000, 0x00000080, 0x00002000, 0x00002080,
0x00000001, 0x00000081, 0x00002001, 0x00002081,
0x00200000, 0x00200080, 0x00202000, 0x00202080,
0x00200001, 0x00200081, 0x00202001, 0x00202081,
0x00020000, 0x00020080, 0x00022000, 0x00022080,
0x00020001, 0x00020081, 0x00022001, 0x00022081,
0x00220000, 0x00220080, 0x00222000, 0x00222080,
0x00220001, 0x00220081, 0x00222001, 0x00222081,
0x00000002, 0x00000082, 0x00002002, 0x00002082,
0x00000003, 0x00000083, 0x00002003, 0x00002083,
0x00200002, 0x00200082, 0x00202002, 0x00202082,
0x00200003, 0x00200083, 0x00202003, 0x00202083,
0x00020002, 0x00020082, 0x00022002, 0x00022082,
0x00020003, 0x00020083, 0x00022003, 0x00022083,
0x00220002, 0x00220082, 0x00222002, 0x00222082,
0x00220003, 0x00220083, 0x00222003, 0x00222083
};
/* pc2_d_2 bit pattern 50 32 43 36 29 48 */
static int pc2_d_2[64] = {
0x00000000, 0x00000010, 0x00800000, 0x00800010,
0x00010000, 0x00010010, 0x00810000, 0x00810010,
0x00000200, 0x00000210, 0x00800200, 0x00800210,
0x00010200, 0x00010210, 0x00810200, 0x00810210,
0x00100000, 0x00100010, 0x00900000, 0x00900010,
0x00110000, 0x00110010, 0x00910000, 0x00910010,
0x00100200, 0x00100210, 0x00900200, 0x00900210,
0x00110200, 0x00110210, 0x00910200, 0x00910210,
0x00000004, 0x00000014, 0x00800004, 0x00800014,
0x00010004, 0x00010014, 0x00810004, 0x00810014,
0x00000204, 0x00000214, 0x00800204, 0x00800214,
0x00010204, 0x00010214, 0x00810204, 0x00810214,
0x00100004, 0x00100014, 0x00900004, 0x00900014,
0x00110004, 0x00110014, 0x00910004, 0x00910014,
0x00100204, 0x00100214, 0x00900204, 0x00900214,
0x00110204, 0x00110214, 0x00910204, 0x00910214
};
/* pc2_d_3 bit pattern 41 38 47 33 40 42 */
static int pc2_d_3[64] = {
0x00000000, 0x00000400, 0x00001000, 0x00001400,
0x00080000, 0x00080400, 0x00081000, 0x00081400,
0x00000020, 0x00000420, 0x00001020, 0x00001420,
0x00080020, 0x00080420, 0x00081020, 0x00081420,
0x00004000, 0x00004400, 0x00005000, 0x00005400,
0x00084000, 0x00084400, 0x00085000, 0x00085400,
0x00004020, 0x00004420, 0x00005020, 0x00005420,
0x00084020, 0x00084420, 0x00085020, 0x00085420,
0x00000800, 0x00000c00, 0x00001800, 0x00001c00,
0x00080800, 0x00080c00, 0x00081800, 0x00081c00,
0x00000820, 0x00000c20, 0x00001820, 0x00001c20,
0x00080820, 0x00080c20, 0x00081820, 0x00081c20,
0x00004800, 0x00004c00, 0x00005800, 0x00005c00,
0x00084800, 0x00084c00, 0x00085800, 0x00085c00,
0x00004820, 0x00004c20, 0x00005820, 0x00005c20,
0x00084820, 0x00084c20, 0x00085820, 0x00085c20
};
/* pc2_d_4 bit pattern 49 37 30 46 34 44 */
static int pc2_d_4[64] = {
0x00000000, 0x00000100, 0x00040000, 0x00040100,
0x00000040, 0x00000140, 0x00040040, 0x00040140,
0x00400000, 0x00400100, 0x00440000, 0x00440100,
0x00400040, 0x00400140, 0x00440040, 0x00440140,
0x00008000, 0x00008100, 0x00048000, 0x00048100,
0x00008040, 0x00008140, 0x00048040, 0x00048140,
0x00408000, 0x00408100, 0x00448000, 0x00448100,
0x00408040, 0x00408140, 0x00448040, 0x00448140,
0x00000008, 0x00000108, 0x00040008, 0x00040108,
0x00000048, 0x00000148, 0x00040048, 0x00040148,
0x00400008, 0x00400108, 0x00440008, 0x00440108,
0x00400048, 0x00400148, 0x00440048, 0x00440148,
0x00008008, 0x00008108, 0x00048008, 0x00048108,
0x00008048, 0x00008148, 0x00048048, 0x00048148,
0x00408008, 0x00408108, 0x00448008, 0x00448108,
0x00408048, 0x00408148, 0x00448048, 0x00448148
};
static unsigned char odd_parity[256] = {
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14,
16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31,
32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47,
49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62,
64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79,
81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94,
97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110,
112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127,
128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143,
145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158,
161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174,
176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191,
193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206,
208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223,
224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239,
241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254,
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,146 +0,0 @@
/*
* Copyright (c) 2005 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef _DESperate_H
#define _DESperate_H 1
/* symbol renaming */
#define _DES_ipfp_test _hc_DES_ipfp_test
#define DES_cbc_cksum hc_DES_cbc_cksum
#define DES_cbc_encrypt hc_DES_cbc_encrypt
#define DES_cfb64_encrypt hc_DES_cfb64_encrypt
#define DES_check_key_parity hc_DES_check_key_parity
#define DES_ecb3_encrypt hc_DES_ecb3_encrypt
#define DES_ecb_encrypt hc_DES_ecb_encrypt
#define DES_ede3_cbc_encrypt hc_DES_ede3_cbc_encrypt
#define DES_encrypt hc_DES_encrypt
#define DES_generate_random_block hc_DES_generate_random_block
#define DES_init_random_number_generator hc_DES_init_random_number_generator
#define DES_is_weak_key hc_DES_is_weak_key
#define DES_key_sched hc_DES_key_sched
#define DES_new_random_key hc_DES_new_random_key
#define DES_pcbc_encrypt hc_DES_pcbc_encrypt
#define DES_rand_data hc_DES_rand_data
#define DES_random_key hc_DES_random_key
#define DES_read_password hc_DES_read_password
#define DES_set_key hc_DES_set_key
#define DES_set_key_checked hc_DES_set_key_checked
#define DES_set_key_unchecked hc_DES_set_key_unchecked
#define DES_set_key_sched hc_DES_set_key_sched
#define DES_set_odd_parity hc_DES_set_odd_parity
#define DES_set_random_generator_seed hc_DES_set_random_generator_seed
#define DES_set_sequence_number hc_DES_set_sequence_number
#define DES_string_to_key hc_DES_string_to_key
/*
*
*/
#define DES_CBLOCK_LEN 8
#define DES_KEY_SZ 8
#define DES_ENCRYPT 1
#define DES_DECRYPT 0
typedef unsigned char DES_cblock[DES_CBLOCK_LEN];
typedef struct DES_key_schedule
{
uint32_t ks[32];
} DES_key_schedule;
/*
*
*/
#ifndef HC_DEPRECATED
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
#define HC_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER) && (_MSC_VER>1200)
#define HC_DEPRECATED __declspec(deprecated)
#else
#define HC_DEPRECATED
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
void DES_set_odd_parity(DES_cblock *);
int DES_check_key_parity(DES_cblock *);
int DES_is_weak_key(DES_cblock *);
int HC_DEPRECATED DES_set_key(DES_cblock *, DES_key_schedule *);
int DES_set_key_checked(DES_cblock *, DES_key_schedule *);
int DES_set_key_unchecked(DES_cblock *, DES_key_schedule *);
int DES_key_sched(DES_cblock *, DES_key_schedule *);
void DES_string_to_key(const char *, DES_cblock *);
int DES_read_password(DES_cblock *, char *, int);
void HC_DEPRECATED DES_rand_data(void *, int);
void HC_DEPRECATED DES_set_random_generator_seed(DES_cblock *);
void HC_DEPRECATED DES_generate_random_block(DES_cblock *);
void HC_DEPRECATED DES_set_sequence_number(void *);
void HC_DEPRECATED DES_init_random_number_generator(DES_cblock *);
void HC_DEPRECATED DES_random_key(DES_cblock *);
int HC_DEPRECATED DES_new_random_key(DES_cblock *);
void DES_encrypt(uint32_t [2], DES_key_schedule *, int);
void DES_ecb_encrypt(DES_cblock *, DES_cblock *, DES_key_schedule *, int);
void DES_ecb3_encrypt(DES_cblock *,DES_cblock *, DES_key_schedule *,
DES_key_schedule *, DES_key_schedule *, int);
void DES_pcbc_encrypt(const void *, void *, long,
DES_key_schedule *, DES_cblock *, int);
void DES_cbc_encrypt(const void *, void *, long,
DES_key_schedule *, DES_cblock *, int);
void DES_ede3_cbc_encrypt(const void *, void *, long,
DES_key_schedule *, DES_key_schedule *,
DES_key_schedule *, DES_cblock *, int);
void DES_cfb64_encrypt(const void *, void *, long,
DES_key_schedule *, DES_cblock *, int *, int);
uint32_t DES_cbc_cksum(const void *, DES_cblock *,
long, DES_key_schedule *, DES_cblock *);
void _DES_ipfp_test(void);
#ifdef __cplusplus
}
#endif
#endif /* _DESperate_H */

View File

@@ -1,621 +0,0 @@
/*
* Copyright (c) 2005 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#ifdef KRB5
#include <krb5-types.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <err.h>
#include "des.h"
static void
ecb_test(char key[8], char in[8], char out[8])
{
unsigned char k[8], indata[8], outdata[8], outdata2[8], ansdata[8];
DES_key_schedule s;
memcpy(k, key, 8);
memcpy(indata, in, 8);
memcpy(ansdata, out, 8);
DES_set_odd_parity(&k);
DES_set_key_unchecked(&k, &s);
DES_ecb_encrypt(&indata, &outdata, &s, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "des: encrypt");
DES_ecb_encrypt(&outdata, &outdata2, &s, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "des: decrypt");
}
static void
ebc3_test(char key1[8], char key2[8], char key3[8], char in[8], char out[8])
{
unsigned char k1[8], k2[8], k3[8],
indata[8], outdata[8], outdata2[8], ansdata[8];
DES_key_schedule s1, s2, s3;
memcpy(k1, key1, 8);
memcpy(k2, key2, 8);
memcpy(k3, key3, 8);
memcpy(indata, in, 8);
memcpy(ansdata, out, 8);
DES_set_odd_parity(&k1);
DES_set_odd_parity(&k2);
DES_set_odd_parity(&k3);
DES_set_key_unchecked(&k1, &s1);
DES_set_key_unchecked(&k2, &s2);
DES_set_key_unchecked(&k3, &s3);
DES_ecb3_encrypt(&indata, &outdata, &s1, &s2, &s3, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "des3: encrypt");
DES_ecb3_encrypt(&outdata, &outdata2, &s1, &s2, &s3, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "des3: decrypt");
}
static void
cbc_test(char key1[8], char iv[8], char in[24], char out[24])
{
unsigned char k1[8],
indata[24], outdata[24], outdata2[24], ansdata[24];
DES_key_schedule s1;
DES_cblock ivdata;
memcpy(k1, key1, 8);
memcpy(ivdata, iv, 8);
memcpy(indata, in, 24);
memcpy(ansdata, out, 24);
DES_set_odd_parity(&k1);
DES_set_key_unchecked(&k1, &s1);
DES_cbc_encrypt(indata, outdata, 24, &s1, &ivdata, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "cbc: encrypt");
DES_cbc_encrypt(outdata, outdata2, 24, &s1, &ivdata, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "cbc: decrypt");
}
static void
cfb64_test(char key1[8], char iv[8], char in[23], char out[23])
{
unsigned char k1[8],
indata[23], outdata[23], outdata2[23], ansdata[23];
DES_key_schedule s1;
DES_cblock ivdata;
int num;
memcpy(k1, key1, 8);
memcpy(indata, in, 23);
memcpy(ansdata, out, 23);
DES_set_odd_parity(&k1);
DES_set_key_unchecked(&k1, &s1);
num = 0;
memcpy(ivdata, iv, 8);
DES_cfb64_encrypt(indata, outdata, 23, &s1, &ivdata, &num, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "cfb64: encrypt");
num = 0;
memcpy(ivdata, iv, 8);
DES_cfb64_encrypt(outdata, outdata2, 23, &s1, &ivdata, &num, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "cfb64: decrypt");
}
static void
cbc3_test(char key1[8], char key2[8], char key3[8],
char iv[8], char in[24], char out[24])
{
unsigned char k1[8], k2[8], k3[8],
indata[24], outdata[24], outdata2[24], ansdata[24];
DES_key_schedule s1, s2, s3;
DES_cblock ivdata, ivec_copy;
memcpy(k1, key1, 8);
memcpy(k2, key2, 8);
memcpy(k3, key3, 8);
memcpy(ivdata, iv, 8);
memcpy(indata, in, 24);
memcpy(ansdata, out, 24);
DES_set_odd_parity(&k1);
DES_set_odd_parity(&k2);
DES_set_odd_parity(&k3);
DES_set_key_unchecked(&k1, &s1);
DES_set_key_unchecked(&k2, &s2);
DES_set_key_unchecked(&k3, &s3);
memcpy(&ivec_copy, &ivdata, sizeof(ivec_copy));
DES_ede3_cbc_encrypt(indata, outdata, 24,
&s1, &s2, &s3, &ivec_copy, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "cbc3: encrypt");
memcpy(&ivec_copy, &ivdata, sizeof(ivec_copy));
DES_ede3_cbc_encrypt(outdata, outdata2, 24,
&s1, &s2, &s3, &ivec_copy, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "cbc3: decrypt");
}
static void
pcbc_test(char key1[8], char iv[8], char in[24], char out[24])
{
unsigned char k1[8],
indata[24], outdata[24], outdata2[24], ansdata[24];
DES_key_schedule s1;
DES_cblock ivdata;
memcpy(k1, key1, 8);
memcpy(ivdata, iv, 8);
memcpy(indata, in, 24);
memcpy(ansdata, out, 24);
DES_set_odd_parity(&k1);
DES_set_key_unchecked(&k1, &s1);
DES_pcbc_encrypt(indata, outdata, 24, &s1, &ivdata, 1);
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "pcbc: encrypt");
DES_pcbc_encrypt(outdata, outdata2, 24, &s1, &ivdata, 0);
if (memcmp(indata, outdata2, sizeof(outdata2)) != 0)
errx(1, "pcbc: decrypt");
}
static void
cbc_cksum(char key1[8], char iv[8], char *in, size_t len,
uint32_t ret, char out[8])
{
unsigned char k1[8], indata[24], ansdata[8];
DES_key_schedule s1;
DES_cblock ivdata, outdata;
uint32_t r;
memcpy(k1, key1, 8);
memcpy(ivdata, iv, 8);
memcpy(indata, in, len);
memcpy(ansdata, out, 8);
DES_set_odd_parity(&k1);
DES_set_key_unchecked(&k1, &s1);
r = DES_cbc_cksum(indata, &outdata, len, &s1, &ivdata);
if (ret != r)
errx(1, "cbc_cksum: cksum error");
if (memcmp(outdata, ansdata, sizeof(ansdata)) != 0)
errx(1, "cbc_cksum: checksum");
}
static void
s2k(char *password, const char *salt, char akey[8])
{
DES_cblock k;
size_t l = strlen(password) + strlen(salt);
char *pw = malloc(l + 1);
strcpy(pw, password);
strcat(pw, salt);
DES_string_to_key(pw, &k);
if (memcmp(akey, &k, 8) != 0)
errx(1, "key wrong for '%s'", pw);
free(pw);
}
static void
weak_test(int is_weak, const char akey[8])
{
DES_cblock key;
memcpy(&key, akey, sizeof(key));
if (DES_is_weak_key(&key) != is_weak)
errx(1, "weakness is wrong");
}
/*
*
*/
int
main(int argc, char **argv)
{
_DES_ipfp_test();
ecb_test("\x31\x16\xe3\x57\x97\xa8\x68\xe5",
"\xbb\xe4\x48\x6e\xdf\x9a\x05\x4f",
"\xa8\x82\xa0\x15\x76\xeb\xfd\xc7");
ecb_test("\xfe\x4a\x19\xa1\x45\xa7\xb9\xd0",
"\x2a\x67\x3c\x07\x59\x4d\xde\xb8",
"\x9d\x61\xd5\x1c\xd7\xd0\xd3\x8b");
ecb_test("\xbf\x13\x25\xec\xa4\xbc\x1a\x54",
"\x16\xa5\xd9\x30\x0f\x55\x20\x71",
"\x04\x44\x6c\xe0\x32\x32\x78\xd2");
ebc3_test("\x7c\x2f\x79\xd5\xb5\x37\x01\xcb",
"\xb9\xbc\x86\xea\x04\x45\xab\x2c",
"\x19\x1c\xcd\x83\x8a\x29\x97\x3e",
"\x87\x03\x59\xdd\xf4\xc6\xeb\xb7",
"\xcc\x72\x66\x85\xed\xa2\xee\x09");
ebc3_test("\x10\x34\x32\x4c\xc4\x9b\x57\x5b",
"\xb0\x6e\xb6\x26\xd6\x52\x2c\x15",
"\xa7\x64\xf8\x20\xc1\x89\x73\xc1",
"\x37\xa4\xad\x4d\x76\xee\x7c\x02",
"\xdf\xb9\x2b\x99\x59\x71\xc4\x89");
ebc3_test("\xf8\xa7\xfd\xe6\x6d\x73\x34\x26",
"\x4c\xbf\x40\x5d\x5d\xf4\x31\xef",
"\x04\xdf\xf2\x58\xd0\x5e\x54\x68",
"\x44\x2a\xa2\x19\xbd\x0a\x2b\x61",
"\x17\x26\x39\xd5\xd5\xd9\x40\x71");
ebc3_test("\x13\x5e\x23\x07\x2c\x16\x0d\x25",
"\x64\x6d\x2f\xe0\x68\xa8\x16\x75",
"\x7c\x7c\x19\x64\xbc\xae\xe0\x0e",
"\x7b\x8c\x76\x76\xb0\x95\x7f\xed",
"\xe2\x6e\x05\x1d\xdc\x74\xc1\xb7");
ebc3_test("\xbc\x92\x32\xb6\x68\x0d\x73\x19",
"\x70\xef\x98\x19\xe9\xec\x04\x1c",
"\x02\x4c\x75\x08\xce\xc4\x34\x16",
"\x73\xab\x28\x69\x6a\x20\x2f\x99",
"\x3b\xb1\x2d\xb6\x21\x0a\x44\xca");
ebc3_test("\x01\x98\x16\xea\x85\xd5\x3b\x8a",
"\x73\x23\xb5\x49\xd9\x10\x5b\xea",
"\xb6\xc4\xce\xc4\x89\x92\x0e\x15",
"\xd9\x35\xcf\x21\x47\x7b\xdf\xb5",
"\xa1\x71\x57\x1f\x1e\x84\x08\xac");
ebc3_test("\x58\x6d\xbc\x04\x70\x4f\xe6\x3e",
"\xcd\x76\x26\x01\xae\xce\x0b\xe5",
"\xf2\x4f\x64\x16\x8f\x0d\x4f\x6b",
"\xa7\x0d\xa0\x56\xa0\x8b\x2a\x77",
"\xe5\x12\x9b\x8a\x92\xc8\xdd\xe1");
ebc3_test("\x40\xd6\xad\x43\x52\x23\xa7\xcd",
"\x04\x19\xae\x94\xce\x46\x31\xd3",
"\x45\x6e\x3b\xb5\x4f\x37\x5e\x9d",
"\xbd\xb0\x60\x75\x91\x02\x48\xf4",
"\xb5\xa1\xe6\x4b\x4e\xa3\x8c\x4b");
ebc3_test("\x91\xab\x80\x9b\x97\xf4\x58\x5e",
"\xc2\x68\x46\x61\x9e\x04\xa1\x29",
"\xc7\xe5\x5b\x32\xcb\x43\xc8\xa4",
"\x31\x38\x90\x1c\xc8\x78\x12\x50",
"\xf8\x65\xae\xa1\xdf\x4e\xbf\xa8");
cbc_test("\x57\x98\x7a\x8a\x29\x7c\xc1\xad",
"\xe1\x28\x69\x58\xd6\x91\x9f\x4e",
"\xa0\x11\x1a\xdd\xeb\x62\xb8\x9e\x28\x08\x6e\x0b\x6d\x6d\x57\x31\x1b\x4c\x82\x4c\xc3\x19\xe0\x93",
"\x42\xa5\x2f\x26\xbb\x92\x3a\x6b\x64\xe0\x3b\x1a\x33\x5a\x9c\x2b\xc8\xd9\x41\x37\x8d\x3e\x58\xbf");
cbc_test("\x23\xd6\xec\x86\x86\x4f\x02\xcd",
"\xfe\x8e\xa4\x07\x35\x41\x14\x99",
"\xe3\xc2\x5d\x6e\x81\xae\xa0\xe8\xc8\xdd\xd2\x0d\xf4\x26\x90\x10\xca\x8c\x07\x58\xb2\x17\xcc\x1a",
"\x97\xb9\xbc\xa6\xd1\x98\xc1\x7f\x4b\xac\x61\x8a\x16\xec\x1f\xee\x28\x6f\xe8\x25\xf0\x41\xbc\xde");
cbc_test("\x07\xe5\xc8\x52\xba\x3d\xef\xcd",
"\xa9\x21\x3e\x84\x44\x7c\xce\x1a",
"\xfc\x03\x72\x30\xb0\xcb\xe8\x99\x21\x54\x4d\xfa\x86\xdd\x99\xe1\x96\xe7\x7c\xb5\xbd\x5b\x6f\xd0",
"\x27\x76\x66\x62\x1f\xcf\x48\xdb\x15\x11\x73\x8b\xe0\xc9\xbd\x2b\x40\xae\x0c\x35\xeb\x93\xa3\x1c");
cbc_test("\xef\x2f\x07\xd6\x2f\x70\x4f\x68",
"\x16\x1e\xaf\x87\x3a\x83\x9f\x33",
"\xb8\x4c\xb3\xbf\xfa\x5d\xa9\xc7\x1c\x15\x8d\x39\xf2\x29\xf5\x5a\x3d\x21\x0d\x61\x05\xaa\x48\x92",
"\x51\x85\x2f\xad\x67\xb6\x0a\x15\xb8\x73\x15\xf1\x79\x9d\xed\xf5\x6c\x11\x22\xe5\x48\x51\xab\xae");
cbc_test("\xd0\x2c\x68\xc1\xe6\xb0\x76\x98",
"\xc7\x4f\x31\xa9\x5d\xd5\x5b\xcc",
"\x9d\x4b\x2a\x54\x60\xf1\xb0\x10\x34\x87\xdc\x25\xa5\x80\x6c\x4d\x0c\x7f\x53\x37\x58\x42\xc7\x26",
"\x79\xc5\xf0\x21\x0d\x7a\x38\xc0\x66\x9a\x07\x2f\xa4\x9c\x1f\xbb\x66\x4d\x6c\x86\x5b\x47\x44\x60");
cbc_test("\xd6\xe3\x75\x92\xb0\x8f\x45\x70",
"\xdc\xc6\xab\x3e\xf2\x7e\x13\xd6",
"\x38\x57\x27\x0a\xef\x74\x94\x82\x92\xfa\x28\xed\xff\x24\x1e\x0e\x8f\xaa\x9e\x24\x2f\x41\x65\x78",
"\x1d\xcc\x07\x55\xe8\xea\xd1\x08\x55\x11\x72\xfe\xdb\xdf\xa0\xc9\xb6\x3a\x2e\xdf\xf0\x67\xd3\xf4");
cbc_test("\xb3\xbc\xb5\x61\x04\xda\x1a\x34",
"\x8e\x4e\xa5\x8a\xeb\x6a\xea\xbb",
"\x72\x73\x51\xe0\x58\xc5\x2e\xe1\x64\x10\x05\x59\x64\x70\x3f\xbe\x43\xa2\xed\x7a\x5d\x1b\x9c\xc7",
"\xa6\xb2\xf2\xea\x96\x62\xfb\x2f\x2a\x6a\xa1\x2f\x8e\xe1\x12\xd2\xe4\x82\x4c\xc1\x00\x74\x9c\x8f");
cbc_test("\x8f\xdf\x01\x89\xfe\x13\x9b\x2c",
"\x66\x18\xf8\x80\xa1\x3b\x1b\x91",
"\x32\xdb\xae\xa7\x3b\x77\xb2\x6e\xcc\xa5\xa1\x2e\x15\x19\x49\x83\x2f\xfb\x94\xcc\xd1\xa1\x4b\x02",
"\x47\x31\xca\x04\x4d\x1a\x24\x39\xda\x71\xc5\xb8\x7f\xea\x79\xf5\x43\xa6\x53\x15\x78\x84\x34\x75");
cbc_test("\xe5\x34\xb6\x75\x68\x07\x70\x85",
"\x73\x98\x29\xf7\x7a\xe7\xe7\xb7",
"\x9c\x9e\x4c\xa6\x62\x21\xc4\x15\x47\x43\xd5\xf2\x3a\xf3\xfd\xb5\x53\xa7\x16\x9e\xa6\x4f\x0d\xac",
"\x81\x2d\xa4\x99\x60\xbf\x9c\xf4\x46\x1d\xee\xc6\xb0\xe1\x4a\x29\xea\xfd\xce\x4b\xa1\x45\x93\x7b");
cbc3_test("\x61\xcb\x8c\xb0\x32\x2a\xc2\x5d",
"\x98\xe3\x49\xc1\x0d\xb5\x67\xce",
"\xf2\x43\x10\x61\x85\x6b\xa7\x15",
"\x65\xf5\x8f\x1a\x2b\x33\xf2\xb5",
"\x8c\x06\xe0\x60\x68\x25\x9c\x95\x81\x46\xda\x41\x9d\xa8\x9c\x49\x2f\xee\x33\x35\x95\x11\xbd\xa0",
"\x93\x27\xed\xc7\x35\xb9\xe5\x3c\x7b\x10\x3e\x39\x01\x41\x61\x04\xe7\xf2\xd9\x63\x96\xca\x57\xf1");
cbc3_test("\x15\x61\x6b\x76\xae\x0e\x98\x01",
"\x76\xce\x9d\x94\xa7\xe3\x73\xa4",
"\x19\xd9\x15\x98\x9b\xba\x83\x40",
"\x60\xef\xc2\xc6\xa2\x40\x01\xc7",
"\x8b\x4d\xf4\x37\xad\x1c\xc2\x4e\xcc\xc4\x4b\x17\x67\xf7\xfa\xec\xf8\x94\x6f\x7a\x84\x56\x81\x09",
"\x68\xdf\x82\xcb\xd9\xcd\x3d\xca\x12\x0e\x2e\x39\xba\xf7\x5a\x8c\x41\xbd\x6f\x9d\x85\xfe\x1b\x1d");
cbc3_test("\xd5\x2a\x4f\xa4\x13\x9e\x73\x15",
"\x6d\x75\xa8\x15\x07\xd3\x7c\x79",
"\xd5\xe0\xa7\x91\xf8\xf2\x9d\xcd",
"\x4c\xdb\x56\xb8\x6f\x0e\x2a\x59",
"\xbe\x64\x20\x24\x7d\x2b\x6b\xf4\xd9\xc0\xa0\x9b\x8d\x88\x6e\x50\x6f\xf8\xb6\x4a\x7e\x52\x52\x93",
"\x01\x83\x75\x7b\xd6\x03\xff\xd8\xe9\x6d\x6c\x92\x24\x25\x35\xfa\x43\x4c\x40\xff\xec\xb0\x8b\x50");
cbc3_test("\x02\xad\x13\x31\xd5\xd6\xef\x7c",
"\x86\x3e\x02\xce\x94\x97\x37\xba",
"\x01\x07\x20\x04\xf8\x92\xb6\xb3",
"\x26\x79\x1b\xef\x90\x54\xd6\xc1",
"\x55\xee\xea\x81\x42\x8b\xbf\xfb\x6c\x14\xec\xbd\xba\x55\x0d\xc4\xd2\xd6\xf0\xea\xd1\x03\xde\x5b",
"\x69\x49\xc5\x48\x4f\xda\x03\x90\x84\xef\x86\xd2\x98\xa7\xae\xfa\x17\x35\x7e\x06\xbd\xd3\x51\x0b");
cbc3_test("\x3d\x9b\xae\x5b\x7f\x91\x85\xe0",
"\xdf\x07\xb3\xdf\x97\x0b\x43\x80",
"\xe3\x46\x58\xd9\x68\x79\xb3\xae",
"\xd4\x27\xee\x5d\x73\xb1\x82\xf5",
"\x44\x86\x9a\xa6\x79\x2d\x9e\x94\x11\x6c\x7b\xc6\xe8\xef\x63\x95\x71\xc6\x62\x20\x43\x87\xaf\x65",
"\xc2\xf5\xbc\x91\xc5\x7c\x69\xb2\x05\xcc\x28\x92\xc1\x96\x5a\xc2\xcb\x0c\x71\xc7\x51\x7d\x0c\xcc");
cbc3_test("\x43\x8c\x23\x92\xd5\x92\x67\xfb",
"\x5b\x5e\xb0\x31\x1c\x9d\x5d\x10",
"\x8a\xa2\x16\x64\xd6\xa4\xc4\x5b",
"\x06\xc5\xdd\xa3\x4a\x2b\x37\xb7",
"\x99\xd5\x76\xee\x7c\x4d\xcc\x18\x39\x78\x16\x7c\xcc\x1a\x0a\x27\xdb\xf1\x5f\xe1\x87\x86\xb7\x2c",
"\x91\xbe\xaf\x79\xd0\x14\x7c\x05\x60\x1c\x7e\xd6\x22\x15\xac\xed\xf3\x78\xa5\xc7\x52\xa0\x60\x49");
cbc3_test("\x80\xc2\x86\x7a\x51\x45\x29\x1c",
"\xc7\xfd\xad\xd0\x7c\x4a\xd0\x3e",
"\xe6\x89\x98\xfe\x01\x67\x20\x89",
"\x5c\x23\xe4\x26\x82\x27\xad\xeb",
"\xa1\x38\x4e\xf1\x07\x1a\xdd\x25\x47\xe6\xda\x9d\xa9\xfe\x98\x55\x05\x95\x75\xc2\x59\x18\xcf\xf1",
"\x36\x58\xea\xc5\xf8\x41\xa7\x49\xe8\x22\x75\xfe\xb6\x8b\xdd\x0d\xf0\x66\x42\xe6\x84\x23\x29\xff");
cbc3_test("\xbc\x68\x54\x85\x2c\xc1\xe0\x07",
"\x7c\x6e\x34\x04\x6b\x91\xc4\x54",
"\x9d\xa4\xda\xa1\xda\x6d\xdc\xd3",
"\x1c\x3d\xa9\x41\xa2\xe5\xff\x8a",
"\x0a\x58\xff\x5a\xec\xc1\x7e\x94\x24\xf4\x4f\xdc\x5b\x29\xe2\x78\x62\x8a\xd2\xe2\xd7\x45\x54\x17",
"\x80\x68\xa6\xed\x87\x40\xd5\x32\xd2\xb8\x32\x61\x35\xae\xae\xf7\x14\x1f\x98\xdb\xba\x21\x4f\x9f");
cbc3_test("\xa1\x2a\x7a\x67\xfe\xea\xd3\xe3",
"\x70\xe5\xd5\x4c\xf1\xce\x4c\x26",
"\x75\x4c\x85\x16\xb5\xc8\x07\xe9",
"\x4c\xa4\xb5\xdd\x86\x86\x70\x5a",
"\x0d\x07\xfd\x23\xc1\x1d\x65\xd8\xb2\x79\xb8\xa3\xc5\x8e\x47\xbe\x0f\xed\x7b\x15\x43\xe9\x7c\x5e",
"\xde\x17\xfe\x05\x43\x80\x85\xd0\x9c\x60\xe0\xbe\x8d\xa2\x65\x0e\x63\x02\x72\xb6\xf3\x7d\xda\x90");
pcbc_test("\xe3\xf2\xb0\x26\x7c\x4a\x94\x80",
"\x40\x08\x4c\x44\xa3\xb5\xf7\x97",
"\xe7\xbd\x54\xa1\xbb\x48\x67\xcd\xe0\xee\xff\x8d\x3d\x25\x2b\xf0\x61\x48\xbe\xf2\x63\x5d\xce\x4a",
"\xf5\xe9\x48\xdc\xb8\x61\x39\xa9\x90\x27\xec\x09\x23\x50\xe0\xa9\x78\xb2\x1c\x29\x3c\xa7\x6c\x88");
pcbc_test("\xfd\x54\x2a\x5b\x97\xa4\x5b\x52",
"\x37\x36\x6e\x22\x7e\x66\x08\x8c",
"\xe4\x2d\x81\x88\x86\xb2\x44\x55\x80\x3d\x3c\xbd\x42\x9f\x5d\xdb\x4b\x63\x23\x1c\x31\x13\xa6\x0f",
"\x9c\x9f\x65\x05\x79\x91\x71\x96\x82\x2a\xc0\xe5\xa0\x6f\x71\xab\x68\x32\xd4\xd7\x5e\x38\x38\xf6");
pcbc_test("\x25\x91\x08\xe5\x57\x85\xb6\x20",
"\x47\x6e\xbe\x9f\xb9\x6b\x55\xe9",
"\x44\xfd\xdd\x42\x07\x99\xf0\x8f\xdb\xa5\x14\x1e\x76\x07\x90\x5b\x29\x10\x21\xb9\x7e\xac\xc7\x77",
"\x88\x4f\xdc\x6e\x37\x5e\x4e\xac\x8d\x3f\x9d\xd1\x82\x51\x65\xf5\xf9\x08\xa7\xac\x01\x61\x19\x85");
pcbc_test("\x6d\x43\xc7\x9d\x6b\x97\x64\x40",
"\x56\xfb\xcb\xb3\x97\xb5\x70\x13",
"\x54\x67\xa9\x42\x86\x85\x81\x8f\xb4\x72\xa2\x5f\x2d\x90\xbb\x5c\xb5\xb9\x9b\x71\x8f\x2b\xae\x05",
"\x2c\xd1\x63\x6f\x11\x1d\x5e\x40\x8c\x47\x49\x12\x31\x48\xb7\x12\x4c\xc1\x6a\xaf\x0e\x33\x11\xe1");
pcbc_test("\x3b\xa2\xbc\xd5\x5d\x9d\xdf\x73",
"\x43\xb7\x26\x71\xce\x6d\x97\xac",
"\x4e\xf6\x7d\xd7\xfc\x6b\x35\x54\xae\xc9\xfe\xf7\xb7\x1e\x47\xa5\x61\x44\x50\xb3\xe4\xe8\x7d\xdc",
"\x4d\xda\xbd\xad\xc4\xde\xdc\xf4\xfc\xbd\xfc\xa7\xbd\xe4\x7e\x73\x28\xc5\x5c\xd0\x9a\x35\x39\xa6");
pcbc_test("\x46\x9e\xda\xdf\x0d\x97\x8a\xd3",
"\x6c\x9f\xdf\xc0\x48\x3b\xa5\x17",
"\xb9\xd8\x99\x61\x67\xf3\xec\xa9\xc1\x29\xa3\x8b\x63\xe2\xc2\x28\xaf\x56\x2d\x39\x1d\xeb\x7c\xbc",
"\x70\x5d\xd4\x54\x90\xb9\x6c\x0c\x93\x96\x6a\x4a\x4e\xb8\x80\xce\xb3\xcd\x64\xa7\x6c\xb2\xe4\xc9");
pcbc_test("\x31\x89\x51\x38\x2f\x97\xfe\xef",
"\x17\xdc\xf8\xde\xcc\x8f\x40\x3e",
"\xef\xcf\xe9\x9e\x11\xd8\x35\xdf\x58\x11\xd0\x0a\x68\xce\xe1\x6b\xb5\xca\x68\x47\xb7\xb9\x9a\x34",
"\x3a\x93\x47\x3c\x1b\xa9\xeb\x88\x13\xfd\x1b\xd8\x76\xb5\xd3\xe2\xb8\x83\x10\x56\x68\xab\xe1\x28");
pcbc_test("\xba\x1c\x70\x94\x62\x10\x19\xda",
"\x7a\x8b\xc0\x9e\x00\xbb\x7e\xcb",
"\x30\x74\x6b\xa6\xd6\x07\xae\x44\xd6\x5c\xe6\x18\x97\x90\xaa\x08\xcb\xa8\xf4\x8b\xea\x8b\x4f\xe6",
"\x0a\x77\x24\x7c\xcd\xf8\x06\x01\x20\x02\x14\x33\xd6\xf4\x4e\x89\xc0\x38\x65\x44\x6b\x9c\x92\x16");
pcbc_test("\xfe\x97\xf2\x6d\x8f\x0d\x86\x94",
"\x30\x8a\x7d\x9b\xf4\x28\x6e\x84",
"\x82\xb0\x9b\x42\xf6\xdc\x38\x41\x41\x03\x60\x28\x7f\x90\x08\x8b\x6c\x55\xe7\x76\xcd\xa7\xae\xbc",
"\x35\x0b\xf1\xc0\x56\x64\x6f\x7b\x3e\x1f\xd1\x90\xbd\xda\x10\xb1\xd1\x49\xc6\x62\x5f\xf9\x6c\xf9");
cbc_cksum("\x58\x83\x67\xfb\xdf\x51\x7c\xfd",
"\x46\x0a\xa5\x94\x6b\xd6\xaa\x91",
"\x15\x0b\x16\x3a\x56\x79\x33\xdf\x6e\xa0\xd9\x54\x14\x7b\x37\xa9\xb1\x15\xe1\x28\xfe\x35\xe9\x34",
24,
0x16466788,
"\xa7\xbd\x2a\x1b\x16\x46\x67\x88");
cbc_cksum("\xf1\xe0\x91\x1c\xfe\x10\xe5\xb5",
"\x9c\xc6\x7d\xf3\x3e\x58\x40\x06",
"\x9c\x90\x88\xfe\x9c\x38\xc0\xd5\xaa\xc6\xf2\xc2\x7d\x00\xf6\x5f\xbd\x87\x25\xbe\x41\x64\x9f\xb7",
24,
0xd8a127cc,
"\x93\x5d\x75\x62\xd8\xa1\x27\xcc");
cbc_cksum("\x20\xbf\xdc\xd5\x5b\x9d\xc8\x79",
"\x68\xdc\xe2\xfa\x18\xb3\xa9\xe0",
"\xef\xba\xc4\x8b\x78\xc2\x02\xc2\x74\x71\x9f\xfa\x4b\xa2\x8a\xe5\xfb\x82\x3d\x48\xcf\x28\x08\x42",
24,
0x45236285,
"\xc0\xb9\x2c\x86\x45\x23\x62\x85");
cbc_cksum("\x31\x6d\xa8\xc2\x43\x16\x64\xea",
"\x7b\x5e\x9f\x7c\xb8\xa3\xbd\x89",
"\x8a\xd4\xe4\x77\xbb\x45\x17\x3d\xd2\xef\xe6\xb9\x65\x8b\xb3\xa9\x28\xef\xd7\x0c\xa8\x47\x5d\xb8",
24,
0x3f021cb2,
"\x10\x94\x4c\x2f\x3f\x02\x1c\xb2");
cbc_cksum("\xd5\x75\x51\x8f\xc8\x97\x1a\xc4",
"\xbc\x7a\x70\x58\xae\x29\x60\x3a",
"\x8d\x2c\x70\xdb\x53\xda\x0f\x50\xd9\xb5\x81\x18\x26\x66\x84\xda\xf6\x32\xa0\xe5\xf9\x09\xfd\x35",
24,
0x2f64dd4f,
"\x89\xe4\x70\x0d\x2f\x64\xdd\x4f");
cbc_cksum("\xda\x6e\x32\x80\x20\xbc\x67\x54",
"\xf4\x93\x86\x43\x29\x57\x6e\xec",
"\xfe\xd8\xfe\xad\x4e\x05\xd8\xb8\x9b\x9f\xaa\xa5\x90\x6d\xcb\xff\x40\xab\xc5\x25\x2b\xda\xa7\x09",
24,
0x6281ce23,
"\xa1\x88\xc2\x3d\x62\x81\xce\x23");
cbc_cksum("\xb6\xc7\x75\x8a\xfb\xd3\xf8\xad",
"\xf1\x4f\xd7\x39\x4b\xec\xa3\x99",
"\x31\xd0\x45\x9d\x62\xe3\x49\xbb\x58\xc2\x58\xbe\x13\x51\x1e\x3f\x54\xe5\x31\x7d\xd0\x94\x57\x7a",
24,
0x09c7ee4e,
"\x2f\x40\xb3\xd2\x09\xc7\xee\x4e");
cbc_cksum("\xa8\x4f\x16\xf4\x89\x3d\xf7\xec",
"\x04\x78\xbc\xd3\x4f\x32\xfd\x46",
"\xe5\x44\x30\x5e\x55\xa3\x08\xe9\xcd\xd1\xbe\x63\x66\x26\x27\x62\xc3\x4f\x2a\x50\x69\x21\x24\xde",
24,
0xdf3357c7,
"\xa8\x6e\x80\x3b\xdf\x33\x57\xc7");
cbc_cksum("\xd6\x4f\x40\xef\x8a\x2a\xf1\x20",
"\xd5\x40\xe7\x86\x36\x26\x79\xc9",
"\xcc\x74\x2b\x78\xca\x47\xb0\xd3\xe6\x72\x42\x76\xee\x80\xb0\xe5\x78\x12\x3b\x4e\x76\x91\xda\x1a",
24,
0x14a5029a,
"\x33\xd2\xb5\x8a\x14\xa5\x02\x9a");
cbc_cksum("\xfb\x89\xa1\x9d\xa7\xec\xc1\x5e",
"\x9c\x7f\x47\xd0\x79\x5d\x4b\x97",
"\xb6\x8b\x48\xe0\x01\x78\xec\x50\x7f\xf1\xfd\xd2\x87\x76\xba\x4b\x9c\x5c\xc7\x25",
20,
0xa1471604,
"\x39\x5b\x7d\xb1\xa1\x47\x16\x04");
cbc_cksum("\x70\xb3\xc4\x0b\x5b\x4f\x98\xe5",
"\x86\xc0\x05\x1a\xd5\x8f\x78\x2c",
"\xef\x01\x7b\xd8\xff\x68\x5d\x66\xb6\xbe\xd8\xf5\xb9\xed\x4e\xec\xe3\x3c\x12\xc5",
20,
0xc4b74f9a,
"\x2b\x07\xe3\x90\xc4\xb7\x4f\x9a");
cbc_cksum("\xfe\x04\xcb\xfe\xef\x34\xe9\x58",
"\xd9\x28\xae\xc0\x2c\xd3\xf6\xb0",
"\x24\x25\x9b\x67\xda\x76\xa6\x64\x6f\x31\x94\x18\x2e\x06\x71\x82\xaf\xbd\x86\x63",
20,
0xbd7c84e6,
"\x70\x3e\x91\xf5\xbd\x7c\x84\xe6");
cbc_cksum("\x10\xc2\x70\x94\x9b\x16\x20\x1c",
"\x62\xed\x5a\x48\x6c\xf3\x51\xa0",
"\x90\x3e\x06\xc1\x63\x6a\x1f\x1a\xfe\x9d\x74\xb6\x13\xde\x62\xd2\x6f\x19\x37\x25",
20,
0x26761f96,
"\x8b\x6a\x9c\x85\x26\x76\x1f\x96");
cbc_cksum("\x61\x32\x7c\x7f\x31\xc7\x98\xe6",
"\xd9\xba\x0d\x9d\x9e\xa3\xcc\x66",
"\x98\x8f\xc6\x5a\x54\x04\x63\xd9\x53\x86\x5d\x75\x53\x48\xcc\xa3\x00\x7a\x12\xe5",
20,
0xf0f6ad33,
"\x6a\xfb\xed\xd3\xf0\xf6\xad\x33");
cbc_cksum("\x85\xdf\x01\x2c\xab\x3b\xec\x13",
"\xc6\x44\x87\x5b\x78\x2a\x74\x92",
"\x8b\xf5\x0d\xff\x5c\xb3\xc1\xcd\x9e\xf7\xb8\x8e\x3b\xf8\x61\x4d\x26\x6a\x7b\xe8",
20,
0x7acfe214,
"\x52\xb7\x05\xe9\x7a\xcf\xe2\x14");
cbc_cksum("\x49\xdf\xb0\x16\x7f\xec\x10\x52",
"\x09\xa3\x36\x8f\xe9\xe0\x06\x19",
"\x3a\x0f\x66\xf7\x7a\x47\x34\xe4\xaa\x09\x36\x90\xe9\x90\x19\xff\x99\x94\x92\x04",
20,
0x9a3a59bb,
"\xd3\xe2\xce\xfc\x9a\x3a\x59\xbb");
cbc_cksum("\x5b\xbf\x4c\xc8\xce\xf4\x51\x1a",
"\x7c\xee\xc0\x5a\x20\x2b\x10\x22",
"\x05\x1d\xec\xdb\x30\x73\xf2\x21\xbf\x64\xe0\x5f\xdf\x02\x79\xe9\x47\xf2\x9c\x4e",
20,
0xaf9d3602,
"\xaa\xf3\xa2\x5a\xaf\x9d\x36\x02");
cbc_cksum("\xad\xda\xa2\x19\x6d\x37\xda\x67",
"\xb2\x10\x0f\xd5\xda\xdd\x17\xfc",
"\x44\x02\x6b\xd6\xd4\x8c\x42\x58\x8b\x59\x35\xce\xd7\x04\x6b\x35\xa6\x5f\x28\x97",
20,
0xd112a978,
"\xb2\x5f\x6a\x07\xd1\x12\xa9\x78");
s2k("potatoe", "WHITEHOUSE.GOVdanny",
"\xdf\x3d\x32\xa7\x4f\xd9\x2a\x01");
s2k("password", "ATHENA.MIT.EDUraeburn",
"\xCB\xC2\x2F\xAE\x23\x52\x98\xE3");
s2k("\xf0\x9d\x84\x9e", "EXAMPLE.COMpianist",
"\x4f\xfb\x26\xba\xb0\xcd\x94\x13");
s2k("NNNN6666", "FFFFAAAA",
"\xc4\xbf\x6b\x25\xad\xf7\xa4\xf8");
s2k("", "",
"\x01\x01\x01\x01\x01\x01\x01\xf1");
cfb64_test("\x45\xc2\x0b\x01\x40\x08\x13\x8a",
"\x9a\xef\xf4\x37\x41\x69\x0b\xd6",
"\x5d\x12\x5d\xf5\xae\x1d\xc6\x47\x21\xd3\x16\xba\x45\x0e\x9d\x4c\x00\xfd\xf8\x64\xca\x69\x67",
"\xff\x99\x06\xd8\xe9\xbc\xae\x7e\xde\x49\x7b\x34\x5d\xa0\x74\x61\x9b\x6f\x70\x38\x40\x40\xba");
cfb64_test("\xdc\xe9\x51\xc4\x0b\xad\x85\xa8",
"\xf5\x56\x6c\xef\x42\xed\x9f\xa8",
"\x7d\xe5\xeb\x04\x5c\xaf\x8c\x5b\xf4\x88\xba\x4a\x99\x6a\x3a\x79\xc0\x88\x01\x05\xac\x98\x3c",
"\x53\x87\x11\xc4\xa6\xf3\x1e\x67\x56\xfc\x8c\x63\xf0\x2e\xd9\x0e\x4a\x86\x8e\x5b\xa7\xde\xcf");
cfb64_test("\x25\xf7\xa7\x0e\x85\x4f\x5b\xb6",
"\x83\xae\x73\x03\xea\xeb\x82\x05",
"\x1b\x80\x23\xdc\x61\x23\xa7\xde\x80\xf6\xec\xb1\xc1\x6d\x3e\x59\x1f\x76\x6d\xdf\xfa\x42\xc7",
"\xe2\xf7\x8d\x2f\x86\xce\x1f\xfc\xdb\x82\xb9\xb5\x9c\xa9\xf4\x9c\x2b\x3f\x34\x6c\x83\xf7\x7e");
cfb64_test("\xab\xd5\xd3\x68\xf1\x2c\x0e\x0d",
"\x8a\xea\xe8\xc0\xad\xb9\x51\x83",
"\x3d\xcb\x7d\xcf\x57\xa6\xf6\x16\x4f\x34\xb6\x5f\xc2\xa9\xf0\xec\x90\xc5\x43\xa0\x19\xfc\x3f",
"\xe9\x2c\x22\x20\xd4\x27\x90\x89\x40\x08\x4a\x23\x4d\x41\x05\x67\xe1\xde\xf5\x0b\x8b\x96\xb1");
cfb64_test("\x92\x38\xd3\xfd\x61\x83\x92\x0e",
"\x25\xb6\x34\x51\x6d\x6a\x35\xa2",
"\x98\x55\xab\x2a\xa2\x9e\xcf\xf4\x92\xdf\xb4\xc6\xc1\x34\x55\xf6\x13\x85\x4c\x50\xdc\x82\x1e",
"\x87\x96\x47\xa6\xcd\xff\xda\xd2\xad\x88\xaa\x25\xbd\xcd\x72\x61\x37\x14\x42\x14\xc7\x4b\x7f");
cfb64_test("\xf4\xcb\x97\xad\xef\x7f\x80\xb0",
"\xfc\xa0\x7d\xb6\x75\xb8\x48\xea",
"\xc2\x1e\x16\x2b\xb7\xcf\xc6\xa0\x4b\x76\x75\x61\x49\x66\x0d\xce\xd2\x12\xf2\x98\x07\x2f\xac",
"\xe2\x20\xbf\x29\x5b\x34\x20\x2a\x2e\x99\xa5\x50\x97\x1b\x4b\x18\xb4\xd6\x87\x35\x7b\x5f\x43");
cfb64_test("\x3b\x1c\x15\xec\xb9\x5e\xe0\xda",
"\x7d\x94\x23\x76\x96\x72\x62\xf4",
"\x5d\x83\xdb\x76\x52\x46\xa7\x84\x0a\x71\x2c\x09\x40\xbd\x3d\x75\x73\x28\x0b\x22\x07\x6f\x8a",
"\xf1\x01\x8f\xe2\x32\x35\xe6\x06\xcf\xbb\xe4\x15\x9e\x4e\xf0\xe8\x2e\xcd\xac\xbf\xa6\xc2\xec");
cfb64_test("\xc2\xcd\x76\x79\x7f\x51\xce\x86",
"\x38\xcf\x55\x7d\x0c\xd5\x35\xfe",
"\xc7\xe5\xe8\x1d\x19\x09\x9f\xd5\xdb\x89\x26\xc1\xf1\xc1\x18\x50\xcf\x8b\xf2\xe1\x87\xeb\xe6",
"\xd4\x5d\xca\x30\xb9\x41\xfa\x36\x83\xfc\x40\x2d\xd2\xe8\x94\x38\x49\xc8\xa3\x35\xb7\x5d\x9c");
cfb64_test("\x67\xfd\xc4\x31\x45\x40\xf7\xea",
"\xb9\x29\xe6\x78\xdd\x1a\x13\x84",
"\x12\x9b\xe5\xb3\xdd\x42\x6f\x45\x86\x97\x25\x87\x05\xee\x7e\x57\x8f\x22\x79\xb3\x22\xa2\x95",
"\x38\xef\x49\xbc\xdd\xbb\x6b\x73\xc0\xd7\xa6\x70\xe0\x1b\xde\x8d\xe6\xb4\xc6\x69\xca\x5e\x1e");
weak_test(1, "\x01\x01\x01\x01\x01\x01\x01\x01"); /* weak keys */
weak_test(1, "\x01\x01\x01\x01\x01\x01\x01\x01");
weak_test(1, "\xFE\xFE\xFE\xFE\xFE\xFE\xFE\xFE");
weak_test(1, "\x1F\x1F\x1F\x1F\x0E\x0E\x0E\x0E");
weak_test(1, "\xE0\xE0\xE0\xE0\xF1\xF1\xF1\xF1");
weak_test(1, "\x01\xFE\x01\xFE\x01\xFE\x01\xFE"); /* semi-weak keys */
weak_test(1, "\xFE\x01\xFE\x01\xFE\x01\xFE\x01");
weak_test(1, "\x1F\xE0\x1F\xE0\x0E\xF1\x0E\xF1");
weak_test(1, "\xE0\x1F\xE0\x1F\xF1\x0E\xF1\x0E");
weak_test(1, "\x01\xE0\x01\xE0\x01\xF1\x01\xF1");
weak_test(1, "\xE0\x01\xE0\x01\xF1\x01\xF1\x01");
weak_test(1, "\x1F\xFE\x1F\xFE\x0E\xFE\x0E\xFE");
weak_test(1, "\xFE\x1F\xFE\x1F\xFE\x0E\xFE\x0E");
weak_test(1, "\x01\x1F\x01\x1F\x01\x0E\x01\x0E");
weak_test(1, "\x1F\x01\x1F\x01\x0E\x01\x0E\x01");
weak_test(1, "\xE0\xFE\xE0\xFE\xF1\xFE\xF1\xFE");
weak_test(1, "\xFE\xE0\xFE\xE0\xFE\xF1\xFE\xF1");
weak_test(0, "\x01\x01\x01\x01\x01\x01\x01\x02");
weak_test(0, "\xFF\xE0\xFE\xE0\xFE\xF1\xFE\xF1");
return 0;
}

View File

@@ -1,264 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <roken.h>
#include <dh.h>
#include "tommath.h"
static int
BN2mpz(mp_int *s, const BIGNUM *bn)
{
size_t len;
void *p;
len = BN_num_bytes(bn);
p = malloc(len);
BN_bn2bin(bn, p);
if (mp_from_ubin(s, p, len) != MP_OKAY) {
free(p);
return -1;
}
free(p);
return 0;
}
static BIGNUM *
mpz2BN(mp_int *s)
{
size_t size;
BIGNUM *bn;
void *p;
size = mp_ubin_size(s);
p = malloc(size);
if (p == NULL)
return NULL;
if (mp_to_ubin(s, p, SIZE_MAX, NULL) != MP_OKAY) {
free(p);
return NULL;
};
bn = BN_bin2bn(p, size, NULL);
free(p);
return bn;
}
/*
*
*/
#define DH_NUM_TRIES 10
static int
ltm_dh_generate_key(DH *dh)
{
mp_int pub, priv_key, g, p;
int have_private_key = (dh->priv_key != NULL);
int codes, times = 0;
int res;
if (dh->p == NULL || dh->g == NULL)
return 0;
while (times++ < DH_NUM_TRIES) {
if (!have_private_key) {
size_t bits = BN_num_bits(dh->p);
if (dh->priv_key)
BN_free(dh->priv_key);
dh->priv_key = BN_new();
if (dh->priv_key == NULL)
return 0;
if (!BN_rand(dh->priv_key, bits - 1, 0, 0)) {
BN_clear_free(dh->priv_key);
dh->priv_key = NULL;
return 0;
}
}
if (dh->pub_key) {
BN_free(dh->pub_key);
dh->pub_key = NULL;
}
if (mp_init_multi(&pub, &priv_key, &g, &p, NULL) != MP_OKAY)
continue;
if (BN2mpz(&priv_key, dh->priv_key) != 0)
continue;
if (BN2mpz(&g, dh->g) != 0)
continue;
if (BN2mpz(&p, dh->p) != 0)
continue;
res = mp_exptmod(&g, &priv_key, &p, &pub);
mp_clear_multi(&priv_key, &g, &p, NULL);
if (res != 0)
continue;
dh->pub_key = mpz2BN(&pub);
mp_clear(&pub);
if (dh->pub_key == NULL)
return 0;
if (DH_check_pubkey(dh, dh->pub_key, &codes) && codes == 0)
break;
if (have_private_key)
return 0;
}
if (times >= DH_NUM_TRIES) {
if (!have_private_key && dh->priv_key) {
BN_free(dh->priv_key);
dh->priv_key = NULL;
}
if (dh->pub_key) {
BN_free(dh->pub_key);
dh->pub_key = NULL;
}
return 0;
}
return 1;
}
static int
ltm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
{
mp_int s, priv_key, p, peer_pub;
int ret;
if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
return -1;
if (mp_init_multi(&s, &priv_key, &p, &peer_pub, NULL) != MP_OKAY)
return -1;
if (BN2mpz(&p, dh->p) != 0) {
ret = -1;
goto out;
}
if (BN2mpz(&peer_pub, pub) != 0) {
ret = 1;
goto out;
}
/* check if peers pubkey is reasonable */
if (mp_isneg(&peer_pub)
|| mp_cmp(&peer_pub, &p) >= 0
|| mp_cmp_d(&peer_pub, 1) <= 0)
{
ret = -1;
goto out;
}
if (BN2mpz(&priv_key, dh->priv_key) != 0) {
ret = -1;
goto out;
}
ret = mp_exptmod(&peer_pub, &priv_key, &p, &s);
if (ret != 0) {
ret = -1;
goto out;
}
ret = mp_ubin_size(&s);
if (mp_to_ubin(&s, shared, SIZE_MAX, NULL) != MP_OKAY)
ret = -1;
out:
mp_clear_multi(&s, &priv_key, &p, &peer_pub, NULL);
return ret;
}
static int
ltm_dh_generate_params(DH *dh, int a, int b, BN_GENCB *callback)
{
/* groups should already be known, we don't care about this */
return 0;
}
static int
ltm_dh_init(DH *dh)
{
return 1;
}
static int
ltm_dh_finish(DH *dh)
{
return 1;
}
/*
*
*/
const DH_METHOD _hc_dh_ltm_method = {
"hcrypto ltm DH",
ltm_dh_generate_key,
ltm_dh_compute_key,
NULL,
ltm_dh_init,
ltm_dh_finish,
0,
NULL,
ltm_dh_generate_params
};
/**
* DH implementation using libtommath.
*
* @return the DH_METHOD for the DH implementation using libtommath.
*
* @ingroup hcrypto_dh
*/
const DH_METHOD *
DH_ltm_method(void)
{
return &_hc_dh_ltm_method;
}

View File

@@ -1,248 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <dh.h>
#ifdef USE_HCRYPTO_TFM
#include "tfm.h"
static void
BN2mpz(fp_int *s, const BIGNUM *bn)
{
size_t len;
void *p;
len = BN_num_bytes(bn);
p = malloc(len);
BN_bn2bin(bn, p);
fp_read_unsigned_bin(s, p, len);
free(p);
}
static BIGNUM *
mpz2BN(fp_int *s)
{
size_t size;
BIGNUM *bn;
void *p;
size = fp_unsigned_bin_size(s);
p = malloc(size);
if (p == NULL && size != 0)
return NULL;
fp_to_unsigned_bin(s, p);
bn = BN_bin2bn(p, size, NULL);
free(p);
return bn;
}
/*
*
*/
#define DH_NUM_TRIES 10
static int
tfm_dh_generate_key(DH *dh)
{
fp_int pub, priv_key, g, p;
int have_private_key = (dh->priv_key != NULL);
int codes, times = 0;
int res;
if (dh->p == NULL || dh->g == NULL)
return 0;
while (times++ < DH_NUM_TRIES) {
if (!have_private_key) {
size_t bits = BN_num_bits(dh->p);
if (dh->priv_key)
BN_free(dh->priv_key);
dh->priv_key = BN_new();
if (dh->priv_key == NULL)
return 0;
if (!BN_rand(dh->priv_key, bits - 1, 0, 0)) {
BN_clear_free(dh->priv_key);
dh->priv_key = NULL;
return 0;
}
}
if (dh->pub_key)
BN_free(dh->pub_key);
fp_init_multi(&pub, &priv_key, &g, &p, NULL);
BN2mpz(&priv_key, dh->priv_key);
BN2mpz(&g, dh->g);
BN2mpz(&p, dh->p);
res = fp_exptmod(&g, &priv_key, &p, &pub);
fp_zero(&priv_key);
fp_zero(&g);
fp_zero(&p);
if (res != 0)
continue;
dh->pub_key = mpz2BN(&pub);
fp_zero(&pub);
if (dh->pub_key == NULL)
return 0;
if (DH_check_pubkey(dh, dh->pub_key, &codes) && codes == 0)
break;
if (have_private_key)
return 0;
}
if (times >= DH_NUM_TRIES) {
if (!have_private_key && dh->priv_key) {
BN_free(dh->priv_key);
dh->priv_key = NULL;
}
if (dh->pub_key) {
BN_free(dh->pub_key);
dh->pub_key = NULL;
}
return 0;
}
return 1;
}
static int
tfm_dh_compute_key(unsigned char *shared, const BIGNUM * pub, DH *dh)
{
fp_int s, priv_key, p, peer_pub;
size_t size = 0;
int ret;
if (dh->pub_key == NULL || dh->g == NULL || dh->priv_key == NULL)
return -1;
fp_init(&p);
BN2mpz(&p, dh->p);
fp_init(&peer_pub);
BN2mpz(&peer_pub, pub);
/* check if peers pubkey is reasonable */
if (fp_isneg(&peer_pub)
|| fp_cmp(&peer_pub, &p) >= 0
|| fp_cmp_d(&peer_pub, 1) <= 0)
{
fp_zero(&p);
fp_zero(&peer_pub);
return -1;
}
fp_init(&priv_key);
BN2mpz(&priv_key, dh->priv_key);
fp_init(&s);
ret = fp_exptmod(&peer_pub, &priv_key, &p, &s);
fp_zero(&p);
fp_zero(&peer_pub);
fp_zero(&priv_key);
if (ret != 0)
return -1;
size = fp_unsigned_bin_size(&s);
fp_to_unsigned_bin(&s, shared);
fp_zero(&s);
return size;
}
static int
tfm_dh_generate_params(DH *dh, int a, int b, BN_GENCB *callback)
{
/* groups should already be known, we don't care about this */
return 0;
}
static int
tfm_dh_init(DH *dh)
{
return 1;
}
static int
tfm_dh_finish(DH *dh)
{
return 1;
}
/*
*
*/
const DH_METHOD _hc_dh_tfm_method = {
"hcrypto tfm DH",
tfm_dh_generate_key,
tfm_dh_compute_key,
NULL,
tfm_dh_init,
tfm_dh_finish,
0,
NULL,
tfm_dh_generate_params
};
/**
* DH implementation using tfm.
*
* @return the DH_METHOD for the DH implementation using tfm.
*
* @ingroup hcrypto_dh
*/
const DH_METHOD *
DH_tfm_method(void)
{
return &_hc_dh_tfm_method;
}
#endif

View File

@@ -1,551 +0,0 @@
/*
* Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <roken.h>
#include <krb5-types.h>
#include <rfc2459_asn1.h>
#include <dh.h>
/**
* @page page_dh DH - Diffie-Hellman key exchange
*
* Diffie-Hellman key exchange is a protocol that allows two parties
* to establish a shared secret key.
*
* Include and example how to use DH_new() and friends here.
*
* See the library functions here: @ref hcrypto_dh
*/
/**
* Create a new DH object using DH_new_method(NULL), see DH_new_method().
*
* @return a newly allocated DH object.
*
* @ingroup hcrypto_dh
*/
DH *
DH_new(void)
{
return DH_new_method(NULL);
}
/**
* Create a new DH object from the given engine, if the NULL is used,
* the default engine is used. Free the DH object with DH_free().
*
* @param engine The engine to use to allocate the DH object.
*
* @return a newly allocated DH object.
*
* @ingroup hcrypto_dh
*/
DH *
DH_new_method(ENGINE *engine)
{
DH *dh;
dh = calloc(1, sizeof(*dh));
if (dh == NULL)
return NULL;
dh->references = 1;
if (engine) {
ENGINE_up_ref(engine);
dh->engine = engine;
} else {
dh->engine = ENGINE_get_default_DH();
}
if (dh->engine) {
dh->meth = ENGINE_get_DH(dh->engine);
if (dh->meth == NULL) {
ENGINE_finish(dh->engine);
free(dh);
return 0;
}
}
if (dh->meth == NULL)
dh->meth = DH_get_default_method();
(*dh->meth->init)(dh);
return dh;
}
/**
* Free a DH object and release related resources, like ENGINE, that
* the object was using.
*
* @param dh object to be freed.
*
* @ingroup hcrypto_dh
*/
void
DH_free(DH *dh)
{
if (dh->references <= 0)
abort();
if (--dh->references > 0)
return;
(*dh->meth->finish)(dh);
if (dh->engine)
ENGINE_finish(dh->engine);
#define free_if(f) if (f) { BN_free(f); }
free_if(dh->p);
free_if(dh->g);
free_if(dh->pub_key);
free_if(dh->priv_key);
free_if(dh->q);
free_if(dh->j);
free_if(dh->counter);
#undef free_if
memset_s(dh, sizeof(*dh), 0, sizeof(*dh));
free(dh);
}
/**
* Add a reference to the DH object. The object should be free with
* DH_free() to drop the reference.
*
* @param dh the object to increase the reference count too.
*
* @return the updated reference count, can't safely be used except
* for debug printing.
*
* @ingroup hcrypto_dh
*/
int
DH_up_ref(DH *dh)
{
return ++dh->references;
}
/**
* The maximum output size of the DH_compute_key() function.
*
* @param dh The DH object to get the size from.
*
* @return the maximum size in bytes of the out data.
*
* @ingroup hcrypto_dh
*/
int
DH_size(const DH *dh)
{
return BN_num_bytes(dh->p);
}
/**
* Set the data index idx in the DH object to data.
*
* @param dh DH object.
* @param idx index to set the data for.
* @param data data to store for the index idx.
*
* @return 1 on success.
*
* @ingroup hcrypto_dh
*/
int
DH_set_ex_data(DH *dh, int idx, void *data)
{
dh->ex_data.sk = data;
return 1;
}
/**
* Get the data for index idx in the DH object.
*
* @param dh DH object.
* @param idx index to get the data for.
*
* @return the object store in index idx
*
* @ingroup hcrypto_dh
*/
void *
DH_get_ex_data(DH *dh, int idx)
{
return dh->ex_data.sk;
}
/**
* Generate DH parameters for the DH object give parameters.
*
* @param dh The DH object to generate parameters for.
* @param prime_len length of the prime
* @param generator generator, g
* @param cb Callback parameters to show progress, can be NULL.
*
* @return the maximum size in bytes of the out data.
*
* @ingroup hcrypto_dh
*/
int
DH_generate_parameters_ex(DH *dh, int prime_len, int generator, BN_GENCB *cb)
{
if (dh->meth->generate_params)
return dh->meth->generate_params(dh, prime_len, generator, cb);
return 0;
}
/**
* Check that the public key is sane.
*
* @param dh the local peer DH parameters.
* @param pub_key the remote peer public key parameters.
* @param codes return that the failures of the pub_key are.
*
* @return 1 on success, 0 on failure and *codes is set the the
* combined fail check for the public key
*
* @ingroup hcrypto_dh
*/
int
DH_check_pubkey(const DH *dh, const BIGNUM *pub_key, int *codes)
{
BIGNUM *bn = NULL, *sum = NULL;
int ret = 0;
*codes = 0;
/**
* Checks that the function performs are:
* - pub_key is not negative
*/
if (BN_is_negative(pub_key))
goto out;
/**
* - pub_key > 1 and pub_key < p - 1,
* to avoid small subgroups attack.
*/
bn = BN_new();
if (bn == NULL)
goto out;
if (!BN_set_word(bn, 1))
goto out;
if (BN_cmp(bn, pub_key) >= 0)
*codes |= DH_CHECK_PUBKEY_TOO_SMALL;
sum = BN_new();
if (sum == NULL)
goto out;
BN_uadd(sum, pub_key, bn);
if (BN_cmp(sum, dh->p) >= 0)
*codes |= DH_CHECK_PUBKEY_TOO_LARGE;
/**
* - if g == 2, pub_key have more then one bit set,
* if bits set is 1, log_2(pub_key) is trival
*/
if (!BN_set_word(bn, 2))
goto out;
if (BN_cmp(bn, dh->g) == 0) {
unsigned i, n = BN_num_bits(pub_key);
unsigned bits = 0;
for (i = 0; i < n; i++)
if (BN_is_bit_set(pub_key, i))
bits++;
if (bits < 2) {
*codes |= DH_CHECK_PUBKEY_TOO_SMALL;
goto out;
}
}
ret = 1;
out:
if (bn)
BN_free(bn);
if (sum)
BN_free(sum);
return ret;
}
/**
* Generate a new DH private-public key pair. The dh parameter must be
* allocted first with DH_new(). dh->p and dp->g must be set.
*
* @param dh dh parameter.
*
* @return 1 on success.
*
* @ingroup hcrypto_dh
*/
int
DH_generate_key(DH *dh)
{
return dh->meth->generate_key(dh);
}
/**
* Complute the shared secret key.
*
* @param shared_key the resulting shared key, need to be at least
* DH_size() large.
* @param peer_pub_key the peer's public key.
* @param dh the dh key pair.
*
* @return 1 on success.
*
* @ingroup hcrypto_dh
*/
int
DH_compute_key(unsigned char *shared_key,
const BIGNUM *peer_pub_key, DH *dh)
{
int codes;
/**
* Checks that the pubkey passed in is valid using
* DH_check_pubkey().
*/
if (!DH_check_pubkey(dh, peer_pub_key, &codes) || codes != 0)
return -1;
return dh->meth->compute_key(shared_key, peer_pub_key, dh);
}
/**
* Set a new method for the DH keypair.
*
* @param dh dh parameter.
* @param method the new method for the DH parameter.
*
* @return 1 on success.
*
* @ingroup hcrypto_dh
*/
int
DH_set_method(DH *dh, const DH_METHOD *method)
{
(*dh->meth->finish)(dh);
if (dh->engine) {
ENGINE_finish(dh->engine);
dh->engine = NULL;
}
dh->meth = method;
(*dh->meth->init)(dh);
return 1;
}
/*
*
*/
static int
dh_null_generate_key(DH *dh)
{
return 0;
}
static int
dh_null_compute_key(unsigned char *shared,const BIGNUM *pub, DH *dh)
{
return 0;
}
static int
dh_null_init(DH *dh)
{
return 1;
}
static int
dh_null_finish(DH *dh)
{
return 1;
}
static int
dh_null_generate_params(DH *dh, int prime_num, int len, BN_GENCB *cb)
{
return 0;
}
static const DH_METHOD dh_null_method = {
"hcrypto null DH",
dh_null_generate_key,
dh_null_compute_key,
NULL,
dh_null_init,
dh_null_finish,
0,
NULL,
dh_null_generate_params
};
extern const DH_METHOD _hc_dh_ltm_method;
static const DH_METHOD *dh_default_method = &_hc_dh_ltm_method;
/**
* Return the dummy DH implementation.
*
* @return pointer to a DH_METHOD.
*
* @ingroup hcrypto_dh
*/
const DH_METHOD *
DH_null_method(void)
{
return &dh_null_method;
}
/**
* Set the default DH implementation.
*
* @param meth pointer to a DH_METHOD.
*
* @ingroup hcrypto_dh
*/
void
DH_set_default_method(const DH_METHOD *meth)
{
dh_default_method = meth;
}
/**
* Return the default DH implementation.
*
* @return pointer to a DH_METHOD.
*
* @ingroup hcrypto_dh
*/
const DH_METHOD *
DH_get_default_method(void)
{
return dh_default_method;
}
/*
*
*/
static int
bn2heim_int(BIGNUM *bn, heim_integer *integer)
{
integer->length = BN_num_bytes(bn);
integer->data = malloc(integer->length);
if (integer->data == NULL) {
integer->length = 0;
return ENOMEM;
}
BN_bn2bin(bn, integer->data);
integer->negative = BN_is_negative(bn);
return 0;
}
/**
*
*/
int
i2d_DHparams(DH *dh, unsigned char **pp)
{
DHParameter data;
size_t size;
int ret;
memset(&data, 0, sizeof(data));
if (bn2heim_int(dh->p, &data.prime) ||
bn2heim_int(dh->g, &data.base))
{
free_DHParameter(&data);
return -1;
}
if (pp == NULL) {
size = length_DHParameter(&data);
free_DHParameter(&data);
} else {
void *p;
size_t len;
ASN1_MALLOC_ENCODE(DHParameter, p, len, &data, &size, ret);
free_DHParameter(&data);
if (ret)
return -1;
if (len != size) {
abort();
return -1;
}
memcpy(*pp, p, size);
free(p);
*pp += size;
}
return size;
}

View File

@@ -1,148 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/*
* $Id$
*/
#ifndef _HEIM_DH_H
#define _HEIM_DH_H 1
/* symbol renaming */
#define DH hc_DH
#define DH_METHOD hc_DH_METHOD
#define DH_null_method hc_DH_null_method
#define DH_tfm_method hc_DH_tfm_method
#define DH_ltm_method hc_DH_ltm_method
#define DH_new hc_DH_new
#define DH_new_method hc_DH_new_method
#define DH_free hc_DH_free
#define DH_up_ref hc_DH_up_ref
#define DH_size hc_DH_size
#define DH_set_default_method hc_DH_set_default_method
#define DH_get_default_method hc_DH_get_default_method
#define DH_set_method hc_DH_set_method
#define DH_get_method hc_DH_get_method
#define DH_set_ex_data hc_DH_set_ex_data
#define DH_get_ex_data hc_DH_get_ex_data
#define DH_generate_parameters_ex hc_DH_generate_parameters_ex
#define DH_check_pubkey hc_DH_check_pubkey
#define DH_generate_key hc_DH_generate_key
#define DH_compute_key hc_DH_compute_key
#define i2d_DHparams hc_i2d_DHparams
/*
*
*/
typedef struct DH DH;
typedef struct DH_METHOD DH_METHOD;
#include <hcrypto/bn.h>
#include <hcrypto/engine.h>
struct DH_METHOD {
const char *name;
int (*generate_key)(DH *);
int (*compute_key)(unsigned char *,const BIGNUM *,DH *);
int (*bn_mod_exp)(const DH *, BIGNUM *, const BIGNUM *,
const BIGNUM *, const BIGNUM *, BN_CTX *,
BN_MONT_CTX *);
int (*init)(DH *);
int (*finish)(DH *);
int flags;
void *app_data;
int (*generate_params)(DH *, int, int, BN_GENCB *);
};
struct DH {
int pad;
int version;
BIGNUM *p;
BIGNUM *g;
long length;
BIGNUM *pub_key;
BIGNUM *priv_key;
int flags;
void *method_mont_p;
BIGNUM *q;
BIGNUM *j;
void *seed;
int seedlen;
BIGNUM *counter;
int references;
struct CRYPTO_EX_DATA {
void *sk;
int dummy;
} ex_data;
const DH_METHOD *meth;
ENGINE *engine;
};
/* DH_check_pubkey return codes in `codes' argument. */
#define DH_CHECK_PUBKEY_TOO_SMALL 1
#define DH_CHECK_PUBKEY_TOO_LARGE 2
/*
*
*/
const DH_METHOD *DH_null_method(void);
const DH_METHOD *DH_tfm_method(void);
const DH_METHOD *DH_ltm_method(void);
DH * DH_new(void);
DH * DH_new_method(ENGINE *);
void DH_free(DH *);
int DH_up_ref(DH *);
int DH_size(const DH *);
void DH_set_default_method(const DH_METHOD *);
const DH_METHOD *
DH_get_default_method(void);
int DH_set_method(DH *, const DH_METHOD *);
int DH_set_ex_data(DH *, int, void *);
void * DH_get_ex_data(DH *, int);
int DH_generate_parameters_ex(DH *, int, int, BN_GENCB *);
int DH_check_pubkey(const DH *, const BIGNUM *, int *);
int DH_generate_key(DH *);
int DH_compute_key(unsigned char *,const BIGNUM *,DH *);
int i2d_DHparams(DH *, unsigned char **);
#endif /* _HEIM_DH_H */

View File

@@ -1,102 +0,0 @@
/*
* Copyright (c) 2007 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/**
*
*/
/*! @mainpage Heimdal crypto library
*
* @section intro Introduction
*
* Heimdal libhcrypto library is a implementation many crypto
* algorithms, among others: AES, SHA, DES, RSA, Camellia and many
* help function.
*
* hcrypto provies a OpenSSL compatible interface libcrypto interface
* and is licensed under a 3 clause BSD license (GPL compatible).
*
* The project web page: http://www.h5l.org/
*
* Sections of this manual:
*
* - @subpage page_evp, @ref hcrypto_evp
* - @subpage page_rand, @ref hcrypto_rand
* - @subpage page_dh, @ref hcrypto_dh
* - @subpage page_rsa, @ref hcrypto_rsa
* - @ref hcrypto_misc
*
* Older interfaces that you should not use:
*
* - @subpage page_des, @ref hcrypto_des
*
* @subsection control_functions Control functions
*
* Functions controlling general behavior, like adding algorithms, are
* documented in this module: @ref hcrypto_core .
*
* @subsection return_values Return values
*
* Return values are diffrent in this module to be compatible with
* OpenSSL interface. The diffrence is that on success 1 is returned
* instead of the customary 0.
* @subsection History
*
* Eric Young implemented DES in the library libdes, that grew into
* libcrypto in the ssleay package. ssleay went into recession and
* then got picked up by the OpenSSL (htp://www.openssl.org/)
* project.
*
* libhcrypto is an independent implementation with no code decended
* from ssleay/openssl. Both includes some common imported code, for
* example the AES implementation.
*/
/** @defgroup hcrypto_dh Diffie-Hellman functions
* See the @ref page_dh for description and examples.
*/
/** @defgroup hcrypto_rsa RSA functions
* See the @ref page_rsa for description and examples.
*/
/** @defgroup hcrypto_evp EVP generic crypto functions
* See the @ref page_evp for description and examples.
*/
/** @defgroup hcrypto_rand RAND crypto functions
* See the @ref page_rand for description and examples.
*/
/** @defgroup hcrypto_des DES crypto functions
* See the @ref page_des for description and examples.
*/
/** @defgroup hcrypto_core hcrypto function controlling behavior */
/** @defgroup hcrypto_misc hcrypto miscellaneous functions */

View File

@@ -1,127 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <dsa.h>
/*
*
*/
DSA *
DSA_new(void)
{
DSA *dsa = calloc(1, sizeof(*dsa));
dsa->meth = rk_UNCONST(DSA_get_default_method());
dsa->references = 1;
return dsa;
}
void
DSA_free(DSA *dsa)
{
if (dsa->references <= 0)
abort();
if (--dsa->references > 0)
return;
(*dsa->meth->finish)(dsa);
#define free_if(f) if (f) { BN_free(f); }
free_if(dsa->p);
free_if(dsa->q);
free_if(dsa->g);
free_if(dsa->pub_key);
free_if(dsa->priv_key);
free_if(dsa->kinv);
free_if(dsa->r);
#undef free_if
memset_s(dsa, sizeof(*dsa), 0, sizeof(*dsa));
free(dsa);
}
int
DSA_up_ref(DSA *dsa)
{
return ++dsa->references;
}
/*
*
*/
static const DSA_METHOD dsa_null_method = {
"hcrypto null DSA",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
0,
NULL
};
const DSA_METHOD *
DSA_null_method(void)
{
return &dsa_null_method;
}
const DSA_METHOD *dsa_default_mech = &dsa_null_method;
void
DSA_set_default_method(const DSA_METHOD *mech)
{
dsa_default_mech = mech;
}
const DSA_METHOD *
DSA_get_default_method(void)
{
return dsa_default_mech;
}
int
DSA_verify(int type, const unsigned char * digest, int digest_len,
const unsigned char *sig, int sig_len, DSA *dsa)
{
return -1;
}

View File

@@ -1,142 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/*
* $Id$
*/
#ifndef _HEIM_DSA_H
#define _HEIM_DSA_H 1
#include <hcrypto/bn.h>
/* symbol renaming */
#define DSA hc_DSA
#define DSA_METHOD hc_DSA_METHOD
#define DSA_null_method hc_DSA_null_method
#define DSA_new hc_DSA_new
#define DSA_free hc_DSA_free
#define DSA_up_ref hc_DSA_up_ref
#define DSA_set_default_method hc_DSA_set_default_method
#define DSA_get_default_method hc_DSA_get_default_method
#define DSA_set_method hc_DSA_set_method
#define DSA_get_method hc_DSA_get_method
#define DSA_set_app_data hc_DSA_set_app_data
#define DSA_get_app_data hc_DSA_get_app_data
#define DSA_size hc_DSA_size
#define DSA_verify hc_DSA_verify
/*
*
*/
typedef struct DSA DSA;
typedef struct DSA_METHOD DSA_METHOD;
typedef struct DSA_SIG DSA_SIG;
struct DSA_SIG {
BIGNUM *r;
BIGNUM *s;
};
struct DSA_METHOD {
const char *name;
DSA_SIG * (*dsa_do_sign)(const unsigned char *, int, DSA *);
int (*dsa_sign_setup)(DSA *, BN_CTX *, BIGNUM **, BIGNUM **);
int (*dsa_do_verify)(const unsigned char *, int, DSA_SIG *, DSA *);
int (*dsa_mod_exp)(DSA *, BIGNUM *, BIGNUM *, BIGNUM *,
BIGNUM *, BIGNUM *, BIGNUM *, BN_CTX *,
BN_MONT_CTX *);
int (*bn_mod_exp)(DSA *, BIGNUM *, BIGNUM *, const BIGNUM *,
const BIGNUM *, BN_CTX *,
BN_MONT_CTX *);
int (*init)(DSA *);
int (*finish)(DSA *);
int flags;
void *app_data;
};
struct DSA {
int pad;
long version;
int write_params;
BIGNUM *p;
BIGNUM *q;
BIGNUM *g;
BIGNUM *pub_key;
BIGNUM *priv_key;
BIGNUM *kinv;
BIGNUM *r;
int flags;
void *method_mont_p;
int references;
struct dsa_CRYPTO_EX_DATA {
void *sk;
int dummy;
} ex_data;
const DSA_METHOD *meth;
void *engine;
};
/*
*
*/
const DSA_METHOD *DSA_null_method(void);
/*
*
*/
DSA * DSA_new(void);
void DSA_free(DSA *);
int DSA_up_ref(DSA *);
void DSA_set_default_method(const DSA_METHOD *);
const DSA_METHOD * DSA_get_default_method(void);
const DSA_METHOD * DSA_get_method(const DSA *);
int DSA_set_method(DSA *, const DSA_METHOD *);
void DSA_set_app_data(DSA *, void *arg);
void * DSA_get_app_data(DSA *);
int DSA_size(const DSA *);
int DSA_verify(int, const unsigned char *, int,
const unsigned char *, int, DSA *);
#endif /* _HEIM_DSA_H */

View File

@@ -1,178 +0,0 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include "ec.h"
struct EC_POINT {
int inf;
mp_int x;
mp_int y;
mp_int z;
};
struct EC_GROUP {
size_t size;
mp_int prime;
mp_int order;
mp_int Gx;
mp_int Gy;
};
struct EC_KEY {
int type;
EC_GROUP *group;
EC_POINT *pubkey;
mp_int privkey;
};
unsigned long
EC_GROUP_get_degree(EC_GROUP *)
{
}
EC_GROUP *
EC_KEY_get0_group(EC_KEY *)
{
}
int
EC_GROUP_get_order(EC_GROUP *, BIGNUM *, BN_CTX *)
{
}
EC_KEY *
o2i_ECPublicKey(EC_KEY **key, unsigned char **, size_t)
{
}
void
EC_KEY_free(EC_KEY *)
{
}
EC_GROUP *
EC_GROUP_new_by_curve_name(int nid)
{
}
EC_KEY *
EC_KEY_new_by_curve_name(EC_GROUP_ID nid)
{
EC_KEY *key;
key = calloc(1, sizeof(*key));
return key;
}
void
EC_POINT_free(EC_POINT *p)
{
mp_clear_multi(&p->x, p->y, p->z, NULL);
free(p);
}
static int
ec_point_mul(EC_POINT *res, const EC_GROUP *group, const mp_int *point)
{
}
EC_POINT *
EC_POINT_new(void)
{
EC_POINT *p;
p = calloc(1, sizeof(*p));
if (mp_init_multi(&p->x, &p->y, &p->z, NULL) != 0) {
EC_POINT_free(p);
return NULL;
}
return p;
}
int
EC_KEY_generate_key(EC_KEY *key)
{
int ret = 0;
if (key->group == NULL)
return 0;
do {
random(key->privkey, key->group->size);
} while(mp_cmp(key->privkey, key->group->order) >= 0);
if (key->pubkey == NULL)
key->pubkey = EC_POINT_new();
if (ec_point_mul(&key->pubkey, key->group, key->privkey) != 1)
goto error;
ret = 1;
error:
ECPOINT_free(&base);
return ret;
}
void
EC_KEY_set_group(EC_KEY *, EC_GROUP *)
{
}
void
EC_GROUP_free(EC_GROUP *)
{
}
int
EC_KEY_check_key(const EC_KEY *)
{
}
const BIGNUM *
EC_KEY_get0_private_key(const EC_KEY *key)
{
}
int
EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *bn)
{
}

View File

@@ -1,97 +0,0 @@
/*
* Copyright (c) 2009-2016 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifndef HEIM_EC_H
#define HEIM_EC_H 1
#define EC_KEY hc_EC_KEY
#define EC_GROUP hc_EC_GROUP
#define EC_GROUP_ID hc_EC_GROUP_ID
#define EC_GROUP_ID_s hc_EC_GROUP_ID_s
#define EC_GROUP_get_degree hc_EC_GROUP_get_degree
#define EC_KEY_get0_group hc_EC_KEY_get0_group
#define EC_GROUP_get_order hc_EC_GROUP_get_order
#define o2i_ECPublicKey hc_o2i_ECPublicKey
#define EC_KEY_free hc_EC_KEY_free
#define EC_GROUP_new_by_curve_name hc_EC_GROUP_new_by_curve_name
#define EC_KEY_set_group hc_EC_KEY_set_group
#define EC_GROUP_free hc_EC_GROUP_free
#define EC_KEY_check_key hc_EC_KEY_check_key
#define EC_KEY_get0_private_key hc_EC_KEY_get0_private_key
#define EC_KEY_set_private_key hc_EC_KEY_set_private_key
#include <hcrypto/bn.h>
#include <hcrypto/engine.h>
typedef struct EC_KEY EC_KEY;
typedef struct EC_GROUP EC_GROUP;
typedef struct EC_GROUP_ID_s *EC_GROUP_ID;
unsigned long
EC_GROUP_get_degree(EC_GROUP *);
EC_GROUP *
EC_KEY_get0_group(EC_KEY *);
int
EC_GROUP_get_order(EC_GROUP *, BIGNUM *, BN_CTX *);
EC_KEY *
o2i_ECPublicKey(EC_KEY **key, unsigned char **, size_t);
EC_KEY *
EC_KEY_new_by_curve_name(EC_GROUP_ID);
int
EC_KEY_generate_key(EC_KEY *);
void
EC_KEY_free(EC_KEY *);
EC_GROUP *
EC_GROUP_new_by_curve_name(int nid);
void
EC_KEY_set_group(EC_KEY *, EC_GROUP *);
void
EC_GROUP_free(EC_GROUP *);
int
EC_KEY_check_key(const EC_KEY *);
const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
#endif /* HEIM_EC_H */

View File

@@ -1,47 +0,0 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifndef HEIM_ECDH_H
#define HEIM_ECDH_H 1
#define ECDH_compute_key hc_ECDH_compute_key
#include <hcrypto/ec.h>
int
ECDH_compute_key(void *, size_t,
const EC_KEY *, const EC_KEY *,
void *(*KDF)(const void *, size_t, void *, size_t *));
#endif /* HEIM_ECDH_H */

View File

@@ -1,52 +0,0 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#ifndef HEIM_ECDSA_H
#define HEIM_ECDSA_H 1
#define ECDSA_verify hc_ECDSA_verify
#define ECDSA_sign hc_ECDSA_sign
#define ECDSA_size hc_ECDSA_size
#include <hcrypto/ec.h>
int ECDSA_verify(int, const unsigned char *, unsigned int,
unsigned char *, unsigned int, EC_KEY *);
int ECDSA_sign(int, const unsigned char *, unsigned int,
unsigned char *, unsigned int *, EC_KEY *);
int ECDSA_size(EC_KEY *);
#endif /* HEIM_ECDSA_H */

View File

@@ -1,396 +0,0 @@
/*
* Copyright (c) 2006 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <engine.h>
struct hc_engine {
int references;
char *name;
char *id;
void (*destroy)(ENGINE *);
const RSA_METHOD *rsa;
const DH_METHOD *dh;
const RAND_METHOD *rand;
void *dso_handle;
};
ENGINE *
ENGINE_new(void)
{
ENGINE *engine;
engine = calloc(1, sizeof(*engine));
if (engine == NULL)
return NULL;
engine->references = 1;
engine->destroy = 0;
engine->dh = 0;
engine->rand = 0;
engine->dso_handle = 0;
return engine;
}
int
ENGINE_free(ENGINE *engine)
{
return ENGINE_finish(engine);
}
int
ENGINE_finish(ENGINE *engine)
{
if (engine->references-- <= 0)
abort();
if (engine->references > 0)
return 1;
if (engine->name)
free(engine->name);
if (engine->id)
free(engine->id);
if(engine->destroy)
(*engine->destroy)(engine);
if (engine->dso_handle)
dlclose(engine->dso_handle);
memset_s(engine, sizeof(*engine), 0, sizeof(*engine));
engine->references = -1;
free(engine);
return 1;
}
int
ENGINE_up_ref(ENGINE *engine)
{
if (engine->references < 0)
abort();
engine->references++;
return 1;
}
int
ENGINE_set_id(ENGINE *engine, const char *id)
{
engine->id = strdup(id);
return (engine->id == NULL) ? 0 : 1;
}
int
ENGINE_set_name(ENGINE *engine, const char *name)
{
engine->name = strdup(name);
return (engine->name == NULL) ? 0 : 1;
}
int
ENGINE_set_RSA(ENGINE *engine, const RSA_METHOD *method)
{
engine->rsa = method;
return 1;
}
int
ENGINE_set_DH(ENGINE *engine, const DH_METHOD *method)
{
engine->dh = method;
return 1;
}
int
ENGINE_set_destroy_function(ENGINE *e, void (*destroy)(ENGINE *))
{
e->destroy = destroy;
return 1;
}
const char *
ENGINE_get_id(const ENGINE *engine)
{
return engine->id;
}
const char *
ENGINE_get_name(const ENGINE *engine)
{
return engine->name;
}
const RSA_METHOD *
ENGINE_get_RSA(const ENGINE *engine)
{
return engine->rsa;
}
const DH_METHOD *
ENGINE_get_DH(const ENGINE *engine)
{
return engine->dh;
}
const RAND_METHOD *
ENGINE_get_RAND(const ENGINE *engine)
{
return engine->rand;
}
/*
*
*/
#define SG_default_engine(type) \
static ENGINE *type##_engine; \
int \
ENGINE_set_default_##type(ENGINE *engine) \
{ \
if (type##_engine) \
ENGINE_finish(type##_engine); \
type##_engine = engine; \
if (type##_engine) \
ENGINE_up_ref(type##_engine); \
return 1; \
} \
ENGINE * \
ENGINE_get_default_##type(void) \
{ \
if (type##_engine) \
ENGINE_up_ref(type##_engine); \
return type##_engine; \
}
SG_default_engine(RSA)
SG_default_engine(DH)
#undef SG_default_engine
/*
*
*/
static ENGINE **engines;
static unsigned int num_engines;
static int
add_engine(ENGINE *engine)
{
ENGINE **d, *dup;
dup = ENGINE_by_id(engine->id);
if (dup)
return 0;
d = realloc(engines, (num_engines + 1) * sizeof(*engines));
if (d == NULL)
return 1;
engines = d;
engines[num_engines++] = engine;
return 1;
}
void
ENGINE_load_builtin_engines(void)
{
ENGINE *engine;
int ret;
engine = ENGINE_new();
if (engine == NULL)
return;
ENGINE_set_id(engine, "builtin");
ENGINE_set_name(engine,
"Heimdal crypto builtin (ltm) engine version " PACKAGE_VERSION);
ENGINE_set_RSA(engine, RSA_ltm_method());
ENGINE_set_DH(engine, DH_ltm_method());
ret = add_engine(engine);
if (ret != 1)
ENGINE_finish(engine);
#ifdef USE_HCRYPTO_TFM
/*
* TFM
*/
engine = ENGINE_new();
if (engine == NULL)
return;
ENGINE_set_id(engine, "tfm");
ENGINE_set_name(engine,
"Heimdal crypto tfm engine version " PACKAGE_VERSION);
ENGINE_set_RSA(engine, RSA_tfm_method());
ENGINE_set_DH(engine, DH_tfm_method());
ret = add_engine(engine);
if (ret != 1)
ENGINE_finish(engine);
#endif /* USE_HCRYPTO_TFM */
#ifdef USE_HCRYPTO_LTM
/*
* ltm
*/
engine = ENGINE_new();
if (engine == NULL)
return;
ENGINE_set_id(engine, "ltm");
ENGINE_set_name(engine,
"Heimdal crypto ltm engine version " PACKAGE_VERSION);
ENGINE_set_RSA(engine, RSA_ltm_method());
ENGINE_set_DH(engine, DH_ltm_method());
ret = add_engine(engine);
if (ret != 1)
ENGINE_finish(engine);
#endif
#ifdef HAVE_GMP
/*
* gmp
*/
engine = ENGINE_new();
if (engine == NULL)
return;
ENGINE_set_id(engine, "gmp");
ENGINE_set_name(engine,
"Heimdal crypto gmp engine version " PACKAGE_VERSION);
ENGINE_set_RSA(engine, RSA_gmp_method());
ret = add_engine(engine);
if (ret != 1)
ENGINE_finish(engine);
#endif
}
ENGINE *
ENGINE_by_dso(const char *path, const char *id)
{
#ifdef HAVE_DLOPEN
ENGINE *engine;
int ret;
engine = calloc(1, sizeof(*engine));
if (engine == NULL)
return NULL;
engine->references = 0; /* ref will be added below */
engine->destroy = 0;
engine->dh = 0;
engine->rand = 0;
engine->dso_handle = dlopen(path, RTLD_NOW | RTLD_LOCAL | RTLD_GROUP);
if (engine->dso_handle == NULL) {
/* printf("error: %s\n", dlerror()); */
free(engine);
return NULL;
}
{
unsigned long version;
openssl_v_check v_check;
v_check = (openssl_v_check)dlsym(engine->dso_handle, "v_check");
if (v_check == NULL) {
dlclose(engine->dso_handle);
free(engine);
return NULL;
}
version = (*v_check)(OPENSSL_DYNAMIC_VERSION);
if (version == 0) {
dlclose(engine->dso_handle);
free(engine);
return NULL;
}
}
{
openssl_bind_engine bind_engine;
bind_engine =
(openssl_bind_engine)dlsym(engine->dso_handle, "bind_engine");
if (bind_engine == NULL) {
dlclose(engine->dso_handle);
free(engine);
return NULL;
}
ret = (*bind_engine)(engine, id, NULL); /* XXX fix third arg */
if (ret != 1) {
dlclose(engine->dso_handle);
free(engine);
return NULL;
}
}
ENGINE_up_ref(engine);
ret = add_engine(engine);
if (ret != 1) {
ENGINE_finish(engine);
return NULL;
}
return engine;
#else
return NULL;
#endif
}
ENGINE *
ENGINE_by_id(const char *id)
{
int i;
for (i = 0; i < num_engines; i++) {
if (strcmp(id, engines[i]->id) == 0) {
ENGINE_up_ref(engines[i]);
return engines[i];
}
}
return NULL;
}
void
ENGINE_add_conf_module(void)
{
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright (c) 2006-2016 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/*
* $Id$
*/
#ifndef _HEIM_ENGINE_H
#define _HEIM_ENGINE_H 1
/* symbol renaming */
#define ENGINE_add_conf_module hc_ENGINE_add_conf_module
#define ENGINE_by_dso hc_ENGINE_by_dso
#define ENGINE_by_id hc_ENGINE_by_id
#define ENGINE_finish hc_ENGINE_finish
#define ENGINE_get_DH hc_ENGINE_get_DH
#define ENGINE_get_RSA hc_ENGINE_get_RSA
#define ENGINE_get_RAND hc_ENGINE_get_RAND
#define ENGINE_get_id hc_ENGINE_get_id
#define ENGINE_get_name hc_ENGINE_get_name
#define ENGINE_load_builtin_engines hc_ENGINE_load_builtin_engines
#define ENGINE_set_DH hc_ENGINE_set_DH
#define ENGINE_set_RSA hc_ENGINE_set_RSA
#define ENGINE_set_id hc_ENGINE_set_id
#define ENGINE_set_name hc_ENGINE_set_name
#define ENGINE_set_destroy_function hc_ENGINE_set_destroy_function
#define ENGINE_new hc_ENGINE_new
#define ENGINE_free hc_ENGINE_free
#define ENGINE_up_ref hc_ENGINE_up_ref
#define ENGINE_get_default_DH hc_ENGINE_get_default_DH
#define ENGINE_get_default_RSA hc_ENGINE_get_default_RSA
#define ENGINE_set_default_DH hc_ENGINE_set_default_DH
#define ENGINE_set_default_RSA hc_ENGINE_set_default_RSA
#define ENGINE hc_ENGINE
/*
*
*/
typedef struct hc_engine ENGINE;
/*#define NID_md2 0 */
#define NID_md4 1
#define NID_md5 2
#define NID_sha1 4
#define NID_sha256 5
/*
*
*/
#include <hcrypto/rsa.h>
#include <hcrypto/dsa.h>
#include <hcrypto/dh.h>
#include <hcrypto/rand.h>
#define OPENSSL_DYNAMIC_VERSION (unsigned long)0x00020000
typedef int (*openssl_bind_engine)(ENGINE *, const char *, const void *);
typedef unsigned long (*openssl_v_check)(unsigned long);
ENGINE *
ENGINE_new(void);
int ENGINE_free(ENGINE *);
void ENGINE_add_conf_module(void);
void ENGINE_load_builtin_engines(void);
ENGINE *ENGINE_by_id(const char *);
ENGINE *ENGINE_by_dso(const char *, const char *);
int ENGINE_finish(ENGINE *);
int ENGINE_up_ref(ENGINE *);
int ENGINE_set_id(ENGINE *, const char *);
int ENGINE_set_name(ENGINE *, const char *);
int ENGINE_set_RSA(ENGINE *, const RSA_METHOD *);
int ENGINE_set_DH(ENGINE *, const DH_METHOD *);
int ENGINE_set_destroy_function(ENGINE *, void (*)(ENGINE *));
const char * ENGINE_get_id(const ENGINE *);
const char * ENGINE_get_name(const ENGINE *);
const RSA_METHOD * ENGINE_get_RSA(const ENGINE *);
const DH_METHOD * ENGINE_get_DH(const ENGINE *);
const RAND_METHOD * ENGINE_get_RAND(const ENGINE *);
int ENGINE_set_default_RSA(ENGINE *);
ENGINE * ENGINE_get_default_RSA(void);
int ENGINE_set_default_DH(ENGINE *);
ENGINE * ENGINE_get_default_DH(void);
#endif /* _HEIM_ENGINE_H */

View File

@@ -1,917 +0,0 @@
/*
* Copyright (c) 2008 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Portions Copyright (c) 2009 Apple 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* CommonCrypto provider */
#ifdef __APPLE__
#include <config.h>
#include <roken.h>
#include <assert.h>
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
#include <CommonCrypto/CommonDigest.h>
#endif
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
#include <CommonCrypto/CommonCryptor.h>
#endif
#include <evp.h>
#include <evp-hcrypto.h>
#include <evp-cc.h>
/*
*
*/
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
struct cc_key {
CCCryptorRef href;
};
static int
cc_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct cc_key *cc = ctx->cipher_data;
CCCryptorStatus ret;
size_t moved;
memcpy(out, in, size);
ret = CCCryptorUpdate(cc->href, in, size, out, size, &moved);
if (ret)
return 0;
if (moved != size)
return 0;
return 1;
}
static int
cc_cleanup(EVP_CIPHER_CTX *ctx)
{
struct cc_key *cc = ctx->cipher_data;
if (cc->href)
CCCryptorRelease(cc->href);
return 1;
}
static int
init_cc_key(int encp, unsigned long flags,
CCAlgorithm alg, const void *key, size_t keylen,
const void *iv, CCCryptorRef *ref)
{
CCOperation op = encp ? kCCEncrypt : kCCDecrypt;
CCMode mode;
CCModeOptions options = 0;
CCCryptorStatus ret;
if (*ref) {
if (key == NULL && iv) {
CCCryptorReset(*ref, iv);
return 1;
}
CCCryptorRelease(*ref);
}
if (key) {
switch (flags & EVP_CIPH_MODE) {
case EVP_CIPH_STREAM_CIPHER:
mode = kCCModeRC4;
break;
case EVP_CIPH_CFB8_MODE:
mode = kCCModeCFB8;
break;
default:
mode = kCCModeCBC;
break;
}
ret = CCCryptorCreateWithMode(op, mode, alg, ccNoPadding,
iv, key, keylen, NULL, 0, 0,
options, ref);
if (ret)
return 0;
}
return 1;
}
static int
cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithm3DES,
key, kCCKeySize3DES, iv, &cc->href);
}
#endif /* HAVE_COMMONCRYPTO_COMMONCRYPTOR_H */
/**
* The triple DES cipher type (Apple CommonCrypto provider)
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_des_ede3_cbc(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER des_ede3_cbc = {
0,
8,
24,
8,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_des_ede3_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &des_ede3_cbc;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_des_ede3_cbc();
#else
return NULL;
#endif
}
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
/*
*
*/
static int
cc_des_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmDES,
key, kCCBlockSizeDES, iv, &cc->href);
}
#endif
/**
* The DES cipher type (Apple CommonCrypto provider)
*
* @return the DES-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_des_cbc(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER des_ede3_cbc = {
0,
kCCBlockSizeDES,
kCCBlockSizeDES,
kCCBlockSizeDES,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_des_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &des_ede3_cbc;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_des_cbc();
#else
return NULL;
#endif
}
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
/*
*
*/
static int
cc_aes_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmAES128,
key, ctx->cipher->key_len, iv, &cc->href);
}
#endif
/**
* The AES-128 cipher type (Apple CommonCrypto provider)
*
* @return the AES-128-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_128_cbc(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
kCCBlockSizeAES128,
kCCKeySizeAES128,
kCCBlockSizeAES128,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_128_cbc();
#else
return NULL;
#endif
}
/**
* The AES-192 cipher type (Apple CommonCrypto provider)
*
* @return the AES-192-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_192_cbc(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
kCCBlockSizeAES128,
kCCKeySizeAES192,
kCCBlockSizeAES128,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_192_cbc();
#else
return NULL;
#endif
}
/**
* The AES-256 cipher type (Apple CommonCrypto provider)
*
* @return the AES-256-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_256_cbc(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
kCCBlockSizeAES128,
kCCKeySizeAES256,
kCCBlockSizeAES128,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_256_cbc();
#else
return NULL;
#endif
}
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
/*
*
*/
static int
cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmAES128,
key, ctx->cipher->key_len, NULL, &cc->href);
}
#endif
/**
* The AES-128 CFB8 cipher type (Apple CommonCrypto provider)
*
* @return the AES-128-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_128_cfb8(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
1,
kCCKeySizeAES128,
kCCBlockSizeAES128,
EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cfb8_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_128_cfb8();
#else
return NULL;
#endif
}
/**
* The AES-192 CFB8 cipher type (Apple CommonCrypto provider)
*
* @return the AES-192-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_192_cfb8(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
1,
kCCKeySizeAES192,
kCCBlockSizeAES128,
EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cfb8_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_192_cfb8();
#else
return NULL;
#endif
}
/**
* The AES-256 CFB8 cipher type (Apple CommonCrypto provider)
*
* @return the AES-256-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_aes_256_cfb8(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER c = {
0,
kCCBlockSizeAES128,
kCCKeySizeAES256,
kCCBlockSizeAES128,
EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_aes_cfb8_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &c;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_aes_256_cfb8();
#else
return NULL;
#endif
}
/*
*
*/
#ifdef COMMONCRYPTO_SUPPORTS_RC2
static int
cc_rc2_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmRC2,
key, ctx->cipher->key_len, iv, &cc->href);
}
#endif
/**
* The RC2 cipher type - common crypto
*
* @return the RC2 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_rc2_cbc(void)
{
#ifdef COMMONCRYPTO_SUPPORTS_RC2
static const EVP_CIPHER rc2_cbc = {
0,
kCCBlockSizeRC2,
16,
kCCBlockSizeRC2,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_rc2_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &rc2_cbc;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_rc2_cbc();
#else
return NULL;
#endif
}
/**
* The RC2-40 cipher type - common crypto
*
* @return the RC2-40 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_rc2_40_cbc(void)
{
#ifdef COMMONCRYPTO_SUPPORTS_RC2
static const EVP_CIPHER rc2_40_cbc = {
0,
kCCBlockSizeRC2,
5,
kCCBlockSizeRC2,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_rc2_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &rc2_40_cbc;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_rc2_40_cbc();
#else
return NULL;
#endif
}
/**
* The RC2-64 cipher type - common crypto
*
* @return the RC2-64 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_rc2_64_cbc(void)
{
#ifdef COMMONCRYPTO_SUPPORTS_RC2
static const EVP_CIPHER rc2_64_cbc = {
0,
kCCBlockSizeRC2,
8,
kCCBlockSizeRC2,
EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
cc_rc2_cbc_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &rc2_64_cbc;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_rc2_64_cbc();
#else
return NULL;
#endif
}
/**
* The CommonCrypto md4 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_md4(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md md4 = {
CC_MD4_DIGEST_LENGTH,
CC_MD4_BLOCK_BYTES,
sizeof(CC_MD4_CTX),
(hc_evp_md_init)CC_MD4_Init,
(hc_evp_md_update)CC_MD4_Update,
(hc_evp_md_final)CC_MD4_Final,
(hc_evp_md_cleanup)NULL
};
return &md4;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_md4();
#else
return NULL;
#endif
}
/**
* The CommonCrypto md5 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_md5(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md md5 = {
CC_MD5_DIGEST_LENGTH,
CC_MD5_BLOCK_BYTES,
sizeof(CC_MD5_CTX),
(hc_evp_md_init)CC_MD5_Init,
(hc_evp_md_update)CC_MD5_Update,
(hc_evp_md_final)CC_MD5_Final,
(hc_evp_md_cleanup)NULL
};
return &md5;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_md5();
#else
return NULL;
#endif
}
/**
* The CommonCrypto sha1 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_sha1(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md sha1 = {
CC_SHA1_DIGEST_LENGTH,
CC_SHA1_BLOCK_BYTES,
sizeof(CC_SHA1_CTX),
(hc_evp_md_init)CC_SHA1_Init,
(hc_evp_md_update)CC_SHA1_Update,
(hc_evp_md_final)CC_SHA1_Final,
(hc_evp_md_cleanup)NULL
};
return &sha1;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_sha1();
#else
return NULL;
#endif
}
/**
* The CommonCrypto sha256 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_sha256(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md sha256 = {
CC_SHA256_DIGEST_LENGTH,
CC_SHA256_BLOCK_BYTES,
sizeof(CC_SHA256_CTX),
(hc_evp_md_init)CC_SHA256_Init,
(hc_evp_md_update)CC_SHA256_Update,
(hc_evp_md_final)CC_SHA256_Final,
(hc_evp_md_cleanup)NULL
};
return &sha256;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_sha256();
#else
return NULL;
#endif
}
/**
* The CommonCrypto sha384 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_sha384(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md sha384 = {
CC_SHA384_DIGEST_LENGTH,
CC_SHA384_BLOCK_BYTES,
sizeof(CC_SHA512_CTX),
(hc_evp_md_init)CC_SHA384_Init,
(hc_evp_md_update)CC_SHA384_Update,
(hc_evp_md_final)CC_SHA384_Final,
(hc_evp_md_cleanup)NULL
};
return &sha384;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_sha384();
#else
return NULL;
#endif
}
/**
* The CommonCrypto sha512 provider
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_cc_sha512(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
static const struct hc_evp_md sha512 = {
CC_SHA512_DIGEST_LENGTH,
CC_SHA512_BLOCK_BYTES,
sizeof(CC_SHA512_CTX),
(hc_evp_md_init)CC_SHA512_Init,
(hc_evp_md_update)CC_SHA512_Update,
(hc_evp_md_final)CC_SHA512_Final,
(hc_evp_md_cleanup)NULL
};
return &sha512;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_sha512();
#else
return NULL;
#endif
}
/**
* The Camellia-128 cipher type - CommonCrypto
*
* @return the Camellia-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_camellia_128_cbc(void)
{
#if HCRYPTO_FALLBACK
return EVP_hcrypto_camellia_128_cbc();
#else
return NULL;
#endif
}
/**
* The Camellia-198 cipher type - CommonCrypto
*
* @return the Camellia-198 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_camellia_192_cbc(void)
{
#if HCRYPTO_FALLBACK
return EVP_hcrypto_camellia_192_cbc();
#else
return NULL;
#endif
}
/**
* The Camellia-256 cipher type - CommonCrypto
*
* @return the Camellia-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_camellia_256_cbc(void)
{
#if HCRYPTO_FALLBACK
return EVP_hcrypto_camellia_256_cbc();
#else
return NULL;
#endif
}
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
/*
*
*/
static int
cc_rc4_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct cc_key *cc = ctx->cipher_data;
return init_cc_key(encp, ctx->cipher->flags, kCCAlgorithmRC4,
key, ctx->key_len, iv, &cc->href);
}
#endif
/**
* The RC4 cipher type (Apple CommonCrypto provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_rc4(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER rc4 = {
0,
1,
16,
0,
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
cc_rc4_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &rc4;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_rc4();
#else
return NULL;
#endif
}
/**
* The RC4-40 cipher type (Apple CommonCrypto provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_cc_rc4_40(void)
{
#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
static const EVP_CIPHER rc4_40 = {
0,
1,
5,
0,
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
cc_rc4_init,
cc_do_cipher,
cc_cleanup,
sizeof(struct cc_key),
NULL,
NULL,
NULL,
NULL
};
return &rc4_40;
#elif HCRYPTO_FALLBACK
return EVP_hcrypto_rc4_40();
#else
return NULL;
#endif
}
#endif /* __APPLE__ */

View File

@@ -1,100 +0,0 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_CC_H
#define HEIM_EVP_CC_H 1
/* symbol renaming */
#define EVP_cc_md4 hc_EVP_cc_md4
#define EVP_cc_md5 hc_EVP_cc_md5
#define EVP_cc_sha1 hc_EVP_cc_sha1
#define EVP_cc_sha256 hc_EVP_cc_sha256
#define EVP_cc_sha384 hc_EVP_cc_sha384
#define EVP_cc_sha512 hc_EVP_cc_sha512
#define EVP_cc_des_cbc hc_EVP_cc_des_cbc
#define EVP_cc_des_ede3_cbc hc_EVP_cc_des_ede3_cbc
#define EVP_cc_aes_128_cbc hc_EVP_cc_aes_128_cbc
#define EVP_cc_aes_192_cbc hc_EVP_cc_aes_192_cbc
#define EVP_cc_aes_256_cbc hc_EVP_cc_aes_256_cbc
#define EVP_cc_aes_128_cfb8 hc_EVP_cc_aes_128_cfb8
#define EVP_cc_aes_192_cfb8 hc_EVP_cc_aes_192_cfb8
#define EVP_cc_aes_256_cfb8 hc_EVP_cc_aes_256_cfb8
#define EVP_cc_rc4 hc_EVP_cc_rc4
#define EVP_cc_rc4_40 hc_EVP_cc_rc4_40
#define EVP_cc_rc2_40_cbc hc_EVP_cc_rc2_40_cbc
#define EVP_cc_rc2_64_cbc hc_EVP_cc_rc2_64_cbc
#define EVP_cc_rc2_cbc hc_EVP_cc_rc2_cbc
#define EVP_cc_camellia_128_cbc hc_EVP_cc_camellia_128_cbc
#define EVP_cc_camellia_192_cbc hc_EVP_cc_camellia_192_cbc
#define EVP_cc_camellia_256_cbc hc_EVP_cc_camellia_256_cbc
/*
*
*/
HC_CPP_BEGIN
const EVP_MD * EVP_cc_md4(void);
const EVP_MD * EVP_cc_md5(void);
const EVP_MD * EVP_cc_sha1(void);
const EVP_MD * EVP_cc_sha256(void);
const EVP_MD * EVP_cc_sha384(void);
const EVP_MD * EVP_cc_sha512(void);
const EVP_CIPHER * EVP_cc_rc2_cbc(void);
const EVP_CIPHER * EVP_cc_rc2_40_cbc(void);
const EVP_CIPHER * EVP_cc_rc2_64_cbc(void);
const EVP_CIPHER * EVP_cc_rc4(void);
const EVP_CIPHER * EVP_cc_rc4_40(void);
const EVP_CIPHER * EVP_cc_des_cbc(void);
const EVP_CIPHER * EVP_cc_des_ede3_cbc(void);
const EVP_CIPHER * EVP_cc_aes_128_cbc(void);
const EVP_CIPHER * EVP_cc_aes_192_cbc(void);
const EVP_CIPHER * EVP_cc_aes_256_cbc(void);
const EVP_CIPHER * EVP_cc_aes_128_cfb8(void);
const EVP_CIPHER * EVP_cc_aes_192_cfb8(void);
const EVP_CIPHER * EVP_cc_aes_256_cfb8(void);
const EVP_CIPHER * EVP_cc_camellia_128_cbc(void);
const EVP_CIPHER * EVP_cc_camellia_192_cbc(void);
const EVP_CIPHER * EVP_cc_camellia_256_cbc(void);
HC_CPP_END
#endif /* HEIM_EVP_CC_H */

View File

@@ -1,217 +0,0 @@
/*
* Copyright (c) 2008 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* Windows crypto provider plugin, sample */
#include <config.h>
#include <roken.h>
#define HC_DEPRECATED
#include <assert.h>
#include <evp.h>
#include <crypt.h>
static HCRYPTPROV hCryptProv = NULL;
/*
*
*/
struct generic_key {
HCRYPTKEY *hKey;
};
static int
generic_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct generic_key *gk = ctx->cipher_data;
BOOL bResult;
DWORD length = size;
bResult = CryptSetKeyParam(gk->hKey, KP_IV, ctx->iv, 0);
_ASSERT(bResult);
memcpy(out, in, size);
if (ctx->encrypt)
bResult = CryptEncrypt(gk->hKey, 0, TRUE, 0, out, &length, size);
else
bResult = CryptDecrypt(gk->hKey, 0, TRUE, 0, out, &length);
_ASSERT(bResult);
return 1;
}
static int
generic_cleanup(EVP_CIPHER_CTX *ctx)
{
struct generic_key *gk = ctx->cipher_data;
CryptDestroyKey(gk->hKey);
gk->hKey = NULL;
return 1;
}
static HCRYPTKEY
import_key(int alg, const unsigned char *key, size_t keylen)
{
struct {
BLOBHEADER hdr;
DWORD len;
BYTE key[1];
} *key_blob;
size_t bloblen = sizeof(*key_blob) - 1 + keylen;
key_blob = malloc(bloblen);
key_blob->hdr.bType = PLAINTEXTKEYBLOB;
key_blob->hdr.bVersion = CUR_BLOB_VERSION;
key_blob->hdr.reserved = 0;
key_blob->hdr.aiKeyAlg = alg;
key_blob->len = 24;
memcpy(key_blob->key, key, keylen);
bResult = CryptImportKey(hCryptProv,
(void *)key_blob, bloblen, 0, 0,
&gk->hKey);
free(key_blob);
_ASSERT(bResult);
return hKey;
}
static int
crypto_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct generic_key *gk = ctx->cipher_data;
DWORD paramData;
gk->hKey = import_key(CALG_3DES,
key->key->keyvalue.data,
key->key->keyvalue.len);
return 1;
}
/**
* The triple DES cipher type (Micrsoft crypt provider)
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_wincrypt_des_ede3_cbc(void)
{
static const EVP_CIPHER des_ede3_cbc = {
0,
8,
24,
8,
EVP_CIPH_CBC_MODE,
crypto_des_ede3_cbc_init,
generic_cbc_do_cipher,
generic_cleanup,
sizeof(struct generic_key),
NULL,
NULL,
NULL,
NULL
};
return &des_ede3_cbc;
}
/*
*
*/
struct generic_hash {
HCRYPTHASH hHash;
};
static void
crypto_md5_init(struct generic_hash *m);
{
BOOL bResult;
bResult = CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &m->hHash);
_ASSERT(bResult);
}
static void
generic_hash_update (struct generic_hash *m, const void *p, size_t len)
{
BOOL bResult;
bResult = CryptHashData(m->hHash, data, ( DWORD )len, 0 );
_ASSERT(bResult);
}
static void
generic_hash_final (void *res, struct generic_hash *m);
{
DWORD length;
BOOL bResult;
bResult = CryptGetHashParam(m->hHash, HP_HASHVAL, res, &length, 0)
_ASSERT(bResult);
}
static void
generic_hash_cleanup(struct generic_hash *m)
{
CryptDestroyHash(m->hHash);
m->hHash = NULL;
}
const EVP_MD *
EVP_wincrypt_md5(void)
{
static const struct hc_evp_md md5 = {
16,
64,
sizeof(struct generic_hash),
(hc_evp_md_init)crypto_md5_init,
(hc_evp_md_update)generic_hash_update,
(hc_evp_md_final)generic_hash_final,
(hc_evp_md_cleanup)generic_hash_cleanup
};
return &md5;
}

View File

@@ -1,831 +0,0 @@
/*
* Copyright (c) 2006 - 2008 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#define HC_DEPRECATED
#include <assert.h>
#include <evp.h>
#include <evp-hcrypto.h>
#include <krb5-types.h>
#include <des.h>
#include "camellia.h"
#include <aes.h>
#include <rc2.h>
#include <rc4.h>
#include <sha.h>
#include <md4.h>
#include <md5.h>
/*
*
*/
static int
aes_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
AES_KEY *k = ctx->cipher_data;
if (ctx->encrypt || EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB8_MODE)
AES_set_encrypt_key(key, ctx->cipher->key_len * 8, k);
else
AES_set_decrypt_key(key, ctx->cipher->key_len * 8, k);
return 1;
}
static int
aes_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
AES_KEY *k = ctx->cipher_data;
if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB8_MODE)
AES_cfb8_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
else
AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
return 1;
}
/**
* The AES-128 cipher type (hcrypto)
*
* @return the AES-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_128_cbc(void)
{
static const EVP_CIPHER aes_128_cbc = {
0,
16,
16,
16,
EVP_CIPH_CBC_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_128_cbc;
}
/**
* The AES-192 cipher type (hcrypto)
*
* @return the AES-192 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_192_cbc(void)
{
static const EVP_CIPHER aes_192_cbc = {
0,
16,
24,
16,
EVP_CIPH_CBC_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_192_cbc;
}
/**
* The AES-256 cipher type (hcrypto)
*
* @return the AES-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_256_cbc(void)
{
static const EVP_CIPHER aes_256_cbc = {
0,
16,
32,
16,
EVP_CIPH_CBC_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_256_cbc;
}
/**
* The AES-128 CFB8 cipher type (hcrypto)
*
* @return the AES-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_128_cfb8(void)
{
static const EVP_CIPHER aes_128_cfb8 = {
0,
1,
16,
16,
EVP_CIPH_CFB8_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_128_cfb8;
}
/**
* The AES-192 CFB8 cipher type (hcrypto)
*
* @return the AES-192 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_192_cfb8(void)
{
static const EVP_CIPHER aes_192_cfb8 = {
0,
1,
24,
16,
EVP_CIPH_CFB8_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_192_cfb8;
}
/**
* The AES-256 CFB8 cipher type (hcrypto)
*
* @return the AES-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_aes_256_cfb8(void)
{
static const EVP_CIPHER aes_256_cfb8 = {
0,
1,
32,
16,
EVP_CIPH_CFB8_MODE,
aes_init,
aes_do_cipher,
NULL,
sizeof(AES_KEY),
NULL,
NULL,
NULL,
NULL
};
return &aes_256_cfb8;
}
/**
* The message digest SHA256 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_sha256(void)
{
static const struct hc_evp_md sha256 = {
32,
64,
sizeof(SHA256_CTX),
(hc_evp_md_init)SHA256_Init,
(hc_evp_md_update)SHA256_Update,
(hc_evp_md_final)SHA256_Final,
NULL
};
return &sha256;
}
/**
* The message digest SHA384 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_sha384(void)
{
static const struct hc_evp_md sha384 = {
48,
128,
sizeof(SHA384_CTX),
(hc_evp_md_init)SHA384_Init,
(hc_evp_md_update)SHA384_Update,
(hc_evp_md_final)SHA384_Final,
NULL
};
return &sha384;
}
/**
* The message digest SHA512 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_sha512(void)
{
static const struct hc_evp_md sha512 = {
64,
128,
sizeof(SHA512_CTX),
(hc_evp_md_init)SHA512_Init,
(hc_evp_md_update)SHA512_Update,
(hc_evp_md_final)SHA512_Final,
NULL
};
return &sha512;
}
/**
* The message digest SHA1 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_sha1(void)
{
static const struct hc_evp_md sha1 = {
20,
64,
sizeof(SHA_CTX),
(hc_evp_md_init)SHA1_Init,
(hc_evp_md_update)SHA1_Update,
(hc_evp_md_final)SHA1_Final,
NULL
};
return &sha1;
}
/**
* The message digest MD5 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_md5(void)
{
static const struct hc_evp_md md5 = {
16,
64,
sizeof(MD5_CTX),
(hc_evp_md_init)MD5_Init,
(hc_evp_md_update)MD5_Update,
(hc_evp_md_final)MD5_Final,
NULL
};
return &md5;
}
/**
* The message digest MD4 - hcrypto
*
* @return the message digest type.
*
* @ingroup hcrypto_evp
*/
const EVP_MD *
EVP_hcrypto_md4(void)
{
static const struct hc_evp_md md4 = {
16,
64,
sizeof(MD4_CTX),
(hc_evp_md_init)MD4_Init,
(hc_evp_md_update)MD4_Update,
(hc_evp_md_final)MD4_Final,
NULL
};
return &md4;
}
/*
*
*/
static int
des_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
DES_key_schedule *k = ctx->cipher_data;
DES_cblock deskey;
memcpy(&deskey, key, sizeof(deskey));
DES_set_key_unchecked(&deskey, k);
return 1;
}
static int
des_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
DES_key_schedule *k = ctx->cipher_data;
DES_cbc_encrypt(in, out, size,
k, (DES_cblock *)ctx->iv, ctx->encrypt);
return 1;
}
/**
* The DES cipher type
*
* @return the DES-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_des_cbc(void)
{
static const EVP_CIPHER des_cbc = {
0,
8,
8,
8,
EVP_CIPH_CBC_MODE,
des_cbc_init,
des_cbc_do_cipher,
NULL,
sizeof(DES_key_schedule),
NULL,
NULL,
NULL,
NULL
};
return &des_cbc;
}
/*
*
*/
struct des_ede3_cbc {
DES_key_schedule ks[3];
};
static int
des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct des_ede3_cbc *k = ctx->cipher_data;
DES_cblock deskey;
memcpy(&deskey, key, sizeof(deskey));
DES_set_odd_parity(&deskey);
DES_set_key_unchecked(&deskey, &k->ks[0]);
memcpy(&deskey, key + 8, sizeof(deskey));
DES_set_odd_parity(&deskey);
DES_set_key_unchecked(&deskey, &k->ks[1]);
memcpy(&deskey, key + 16, sizeof(deskey));
DES_set_odd_parity(&deskey);
DES_set_key_unchecked(&deskey, &k->ks[2]);
return 1;
}
static int
des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct des_ede3_cbc *k = ctx->cipher_data;
DES_ede3_cbc_encrypt(in, out, size,
&k->ks[0], &k->ks[1], &k->ks[2],
(DES_cblock *)ctx->iv, ctx->encrypt);
return 1;
}
/**
* The triple DES cipher type - hcrypto
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_des_ede3_cbc(void)
{
static const EVP_CIPHER des_ede3_cbc = {
0,
8,
24,
8,
EVP_CIPH_CBC_MODE,
des_ede3_cbc_init,
des_ede3_cbc_do_cipher,
NULL,
sizeof(struct des_ede3_cbc),
NULL,
NULL,
NULL,
NULL
};
return &des_ede3_cbc;
}
/*
*
*/
struct rc2_cbc {
unsigned int maximum_effective_key;
RC2_KEY key;
};
static int
rc2_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
struct rc2_cbc *k = ctx->cipher_data;
k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;
RC2_set_key(&k->key,
EVP_CIPHER_CTX_key_length(ctx),
key,
k->maximum_effective_key);
return 1;
}
static int
rc2_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct rc2_cbc *k = ctx->cipher_data;
RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);
return 1;
}
/**
* The RC2 cipher type - hcrypto
*
* @return the RC2 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_rc2_cbc(void)
{
static const EVP_CIPHER rc2_cbc = {
0,
RC2_BLOCK_SIZE,
RC2_KEY_LENGTH,
RC2_BLOCK_SIZE,
EVP_CIPH_CBC_MODE|EVP_CIPH_VARIABLE_LENGTH,
rc2_init,
rc2_do_cipher,
NULL,
sizeof(struct rc2_cbc),
NULL,
NULL,
NULL,
NULL
};
return &rc2_cbc;
}
/**
* The RC2-40 cipher type
*
* @return the RC2-40 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_rc2_40_cbc(void)
{
static const EVP_CIPHER rc2_40_cbc = {
0,
RC2_BLOCK_SIZE,
5,
RC2_BLOCK_SIZE,
EVP_CIPH_CBC_MODE,
rc2_init,
rc2_do_cipher,
NULL,
sizeof(struct rc2_cbc),
NULL,
NULL,
NULL,
NULL
};
return &rc2_40_cbc;
}
/**
* The RC2-64 cipher type
*
* @return the RC2-64 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_rc2_64_cbc(void)
{
static const EVP_CIPHER rc2_64_cbc = {
0,
RC2_BLOCK_SIZE,
8,
RC2_BLOCK_SIZE,
EVP_CIPH_CBC_MODE,
rc2_init,
rc2_do_cipher,
NULL,
sizeof(struct rc2_cbc),
NULL,
NULL,
NULL,
NULL
};
return &rc2_64_cbc;
}
static int
camellia_init(EVP_CIPHER_CTX *ctx,
const unsigned char * key,
const unsigned char * iv,
int encp)
{
CAMELLIA_KEY *k = ctx->cipher_data;
k->bits = ctx->cipher->key_len * 8;
CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
return 1;
}
static int
camellia_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
CAMELLIA_KEY *k = ctx->cipher_data;
CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
return 1;
}
/**
* The Camellia-128 cipher type - hcrypto
*
* @return the Camellia-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_camellia_128_cbc(void)
{
static const EVP_CIPHER cipher = {
0,
16,
16,
16,
EVP_CIPH_CBC_MODE,
camellia_init,
camellia_do_cipher,
NULL,
sizeof(CAMELLIA_KEY),
NULL,
NULL,
NULL,
NULL
};
return &cipher;
}
/**
* The Camellia-198 cipher type - hcrypto
*
* @return the Camellia-198 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_camellia_192_cbc(void)
{
static const EVP_CIPHER cipher = {
0,
16,
24,
16,
EVP_CIPH_CBC_MODE,
camellia_init,
camellia_do_cipher,
NULL,
sizeof(CAMELLIA_KEY),
NULL,
NULL,
NULL,
NULL
};
return &cipher;
}
/**
* The Camellia-256 cipher type - hcrypto
*
* @return the Camellia-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
const EVP_CIPHER *
EVP_hcrypto_camellia_256_cbc(void)
{
static const EVP_CIPHER cipher = {
0,
16,
32,
16,
EVP_CIPH_CBC_MODE,
camellia_init,
camellia_do_cipher,
NULL,
sizeof(CAMELLIA_KEY),
NULL,
NULL,
NULL,
NULL
};
return &cipher;
}
static int
rc4_init(EVP_CIPHER_CTX *ctx,
const unsigned char *key,
const unsigned char *iv,
int enc)
{
RC4_KEY *k = ctx->cipher_data;
RC4_set_key(k, ctx->key_len, key);
return 1;
}
static int
rc4_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
RC4_KEY *k = ctx->cipher_data;
RC4(k, size, in, out);
return 1;
}
const EVP_CIPHER *
EVP_hcrypto_rc4(void)
{
static const EVP_CIPHER rc4 = {
0,
1,
16,
0,
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
rc4_init,
rc4_do_cipher,
NULL,
sizeof(RC4_KEY),
NULL,
NULL,
NULL,
NULL
};
return &rc4;
}
const EVP_CIPHER *
EVP_hcrypto_rc4_40(void)
{
static const EVP_CIPHER rc4_40 = {
0,
1,
5,
0,
EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
rc4_init,
rc4_do_cipher,
NULL,
sizeof(RC4_KEY),
NULL,
NULL,
NULL,
NULL
};
return &rc4_40;
}

View File

@@ -1,101 +0,0 @@
/*
* Copyright (c) 2009 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_HCRYPTO_H
#define HEIM_EVP_HCRYPTO_H 1
/* symbol renaming */
#define EVP_hcrypto_md4 hc_EVP_hcrypto_md4
#define EVP_hcrypto_md5 hc_EVP_hcrypto_md5
#define EVP_hcrypto_sha1 hc_EVP_hcrypto_sha1
#define EVP_hcrypto_sha256 hc_EVP_hcrypto_sha256
#define EVP_hcrypto_sha384 hc_EVP_hcrypto_sha384
#define EVP_hcrypto_sha512 hc_EVP_hcrypto_sha512
#define EVP_hcrypto_des_cbc hc_EVP_hcrypto_des_cbc
#define EVP_hcrypto_des_ede3_cbc hc_EVP_hcrypto_des_ede3_cbc
#define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc
#define EVP_hcrypto_aes_192_cbc hc_EVP_hcrypto_aes_192_cbc
#define EVP_hcrypto_aes_256_cbc hc_EVP_hcrypto_aes_256_cbc
#define EVP_hcrypto_aes_128_cfb8 hc_EVP_hcrypto_aes_128_cfb8
#define EVP_hcrypto_aes_192_cfb8 hc_EVP_hcrypto_aes_192_cfb8
#define EVP_hcrypto_aes_256_cfb8 hc_EVP_hcrypto_aes_256_cfb8
#define EVP_hcrypto_rc4 hc_EVP_hcrypto_rc4
#define EVP_hcrypto_rc4_40 hc_EVP_hcrypto_rc4_40
#define EVP_hcrypto_rc2_40_cbc hc_EVP_hcrypto_rc2_40_cbc
#define EVP_hcrypto_rc2_64_cbc hc_EVP_hcrypto_rc2_64_cbc
#define EVP_hcrypto_rc2_cbc hc_EVP_hcrypto_rc2_cbc
#define EVP_hcrypto_camellia_128_cbc hc_EVP_hcrypto_camellia_128_cbc
#define EVP_hcrypto_camellia_192_cbc hc_EVP_hcrypto_camellia_192_cbc
#define EVP_hcrypto_camellia_256_cbc hc_EVP_hcrypto_camellia_256_cbc
/*
*
*/
HC_CPP_BEGIN
const EVP_MD * EVP_hcrypto_md4(void);
const EVP_MD * EVP_hcrypto_md5(void);
const EVP_MD * EVP_hcrypto_sha1(void);
const EVP_MD * EVP_hcrypto_sha256(void);
const EVP_MD * EVP_hcrypto_sha384(void);
const EVP_MD * EVP_hcrypto_sha512(void);
const EVP_CIPHER * EVP_hcrypto_rc4(void);
const EVP_CIPHER * EVP_hcrypto_rc4_40(void);
const EVP_CIPHER * EVP_hcrypto_rc2_cbc(void);
const EVP_CIPHER * EVP_hcrypto_rc2_40_cbc(void);
const EVP_CIPHER * EVP_hcrypto_rc2_64_cbc(void);
const EVP_CIPHER * EVP_hcrypto_des_cbc(void);
const EVP_CIPHER * EVP_hcrypto_des_ede3_cbc(void);
const EVP_CIPHER * EVP_hcrypto_aes_128_cbc(void);
const EVP_CIPHER * EVP_hcrypto_aes_192_cbc(void);
const EVP_CIPHER * EVP_hcrypto_aes_256_cbc(void);
const EVP_CIPHER * EVP_hcrypto_aes_128_cfb8(void);
const EVP_CIPHER * EVP_hcrypto_aes_192_cfb8(void);
const EVP_CIPHER * EVP_hcrypto_aes_256_cfb8(void);
const EVP_CIPHER * EVP_hcrypto_camellia_128_cbc(void);
const EVP_CIPHER * EVP_hcrypto_camellia_192_cbc(void);
const EVP_CIPHER * EVP_hcrypto_camellia_256_cbc(void);
HC_CPP_END
#endif /* HEIM_EVP_HCRYPTO_H */

View File

@@ -1,659 +0,0 @@
/*
* Copyright (c) 2016, Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*/
/* OpenSSL provider */
#include "config.h"
#include <roken.h>
#include <heimbase.h>
#include <assert.h>
#include <evp.h>
#ifdef HAVE_HCRYPTO_W_OPENSSL
/*
* This is the OpenSSL 1.x backend for hcrypto. It has been tested with
* OpenSSL 1.0.1f and OpenSSL 1.1.0-pre3-dev.
*
* NOTE: In order for this to work with OpenSSL 1.1.x and up, it is
* critical to use opaque OpenSSL type accessors everywhere /
* never use knowledge of opaque OpenSSL type internals.
*/
#include <evp-openssl.h>
/*
* This being an OpenSSL backend for hcrypto... we need to be able to
* refer to types and objects (functions) from both, OpenSSL and
* hcrypto.
*
* The hcrypto API is *very* similar to the OpenSSL 1.0.x API, with the
* same type and symbol names in many cases, except that the hcrypto
* names are prefixed with hc_*. hcrypto has convenience macros that
* provide OpenSSL aliases for the hcrypto interfaces, and hcrypto
* applications are expected to use the OpenSSL names.
*
* Since here we must be able to refer to types and objects from both
* OpenSSL and from hcrypto, we disable the hcrypto renaming for the
* rest of this file. These #undefs could be collected into an
* <hcrypto/undef.h> for the purpose of permitting other applications to
* use both, hcrypto and OpenSSL in the same source files (provided that
* such applications refer to hcrypto types and objects by their proper
* hc_-prefixed names).
*/
#include <undef.h>
/* Now it's safe to include OpenSSL headers */
#include <openssl/evp.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
#define EVP_MD_CTX_new EVP_MD_CTX_create
#define EVP_MD_CTX_free EVP_MD_CTX_destroy
#endif
#if defined(HAVE_OPENSSL_FIPS_H) || defined(HAVE_OPENSSL_FIPS_MODE_SET_API)
int _heim_openssl_fips_enabled(void);
int
_heim_openssl_fips_enabled(void)
{
static int fips_enabled_res = -1;
if (fips_enabled_res != -1)
return fips_enabled_res;
#ifdef HAVE_OPENSSL_30
return fips_enabled_res = !!EVP_default_properties_is_fips_enabled(NULL);
#else
return fips_enabled_res = !!FIPS_mode();
#endif
}
#endif
/* A HEIM_BASE_ONCE argument struct for per-EVP one-time initialization */
struct once_init_cipher_ctx {
const hc_EVP_CIPHER **hc_memoizep;
hc_EVP_CIPHER *hc_memoize;
const hc_EVP_CIPHER *fallback;
unsigned long flags;
int nid;
};
/* Our wrapper for OpenSSL EVP_CIPHER_CTXs */
struct ossl_cipher_ctx {
EVP_CIPHER_CTX *ossl_cipher_ctx; /* OpenSSL cipher ctx */
const EVP_CIPHER *ossl_cipher; /* OpenSSL cipher */
int initialized;
};
/*
* Our hc_EVP_CIPHER init() method; wraps around OpenSSL
* EVP_CipherInit_ex().
*
* This is very similar to the init() function pointer in an OpenSSL
* EVP_CIPHER, but a) we can't access them in 1.1, and b) the method
* invocation protocols in hcrypto and OpenSSL are similar but not the
* same, thus we must have this wrapper.
*/
static int
cipher_ctx_init(hc_EVP_CIPHER_CTX *ctx, const unsigned char *key,
const unsigned char *iv, int enc)
{
struct ossl_cipher_ctx *ossl_ctx = ctx->cipher_data; /* EVP_CIPHER_CTX wrapper */
const EVP_CIPHER *c;
assert(ossl_ctx != NULL);
assert(ctx->cipher != NULL);
assert(ctx->cipher->app_data != NULL);
/*
* Here be dragons.
*
* We need to make sure that the OpenSSL EVP_CipherInit_ex() is
* called with cipher!=NULL just once per EVP_CIPHER_CTX, otherwise
* state in the OpenSSL EVP_CIPHER_CTX will get cleaned up and then
* we'll segfault.
*
* hcrypto applications can re-initialize an (hc_)EVP_CIPHER_CTX as
* usual by calling (hc)EVP_CipherInit_ex() with a non-NULL cipher
* argument, and that will cause cipher_cleanup() (below) to be
* called.
*/
c = ossl_ctx->ossl_cipher = ctx->cipher->app_data; /* OpenSSL's EVP_CIPHER * */
if (!ossl_ctx->initialized) {
ossl_ctx->ossl_cipher_ctx = EVP_CIPHER_CTX_new();
if (ossl_ctx->ossl_cipher_ctx == NULL)
return 0;
/*
* So we always call EVP_CipherInit_ex() with c!=NULL, but other
* things NULL...
*/
if (!EVP_CipherInit_ex(ossl_ctx->ossl_cipher_ctx, c, NULL, NULL, NULL, enc))
return 0;
ossl_ctx->initialized = 1;
}
/* ...and from here on always call EVP_CipherInit_ex() with c=NULL */
if ((ctx->cipher->flags & hc_EVP_CIPH_VARIABLE_LENGTH) &&
ctx->key_len > 0)
EVP_CIPHER_CTX_set_key_length(ossl_ctx->ossl_cipher_ctx, ctx->key_len);
return EVP_CipherInit_ex(ossl_ctx->ossl_cipher_ctx, NULL, NULL, key, iv, enc);
}
static int
cipher_do_cipher(hc_EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, unsigned int len)
{
struct ossl_cipher_ctx *ossl_ctx = ctx->cipher_data;
assert(ossl_ctx != NULL);
return EVP_Cipher(ossl_ctx->ossl_cipher_ctx, out, in, len) == 0 ? 0 : 1;
}
static int
cipher_cleanup(hc_EVP_CIPHER_CTX *ctx)
{
struct ossl_cipher_ctx *ossl_ctx = ctx->cipher_data;
if (ossl_ctx == NULL || !ossl_ctx->initialized)
return 1;
if (ossl_ctx->ossl_cipher_ctx != NULL)
EVP_CIPHER_CTX_free(ossl_ctx->ossl_cipher_ctx);
ossl_ctx->ossl_cipher_ctx = NULL;
ossl_ctx->ossl_cipher = NULL;
ossl_ctx->initialized = 0;
return 1;
}
static int
cipher_ctrl(hc_EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
{
struct ossl_cipher_ctx *ossl_ctx = ctx->cipher_data;
assert(ossl_ctx != NULL);
return EVP_CIPHER_CTX_ctrl(ossl_ctx->ossl_cipher_ctx, type, arg, ptr);
}
static void
get_EVP_CIPHER_once_cb(void *d)
{
struct once_init_cipher_ctx *arg = d;
const EVP_CIPHER *ossl_evp;
hc_EVP_CIPHER *hc_evp;
hc_evp = arg->hc_memoize;
/*
* We lookup EVP_CIPHER *s by NID so that we don't fail to find a
* symbol such as EVP_aes...() when libcrypto changes after build
* time (e.g., updates, LD_LIBRARY_PATH/LD_PRELOAD).
*/
ossl_evp = EVP_get_cipherbynid(arg->nid);
if (ossl_evp == NULL) {
(void) memset_s(hc_evp, sizeof(*hc_evp), 0, sizeof(*hc_evp));
#if HCRYPTO_FALLBACK
*arg->hc_memoizep = arg->fallback;
#endif
return;
}
/* Build the hc_EVP_CIPHER */
hc_evp->nid = EVP_CIPHER_nid(ossl_evp); /* We would an hcrypto NIDs if we had them */
hc_evp->block_size = EVP_CIPHER_block_size(ossl_evp);
hc_evp->key_len = EVP_CIPHER_key_length(ossl_evp);
hc_evp->iv_len = EVP_CIPHER_iv_length(ossl_evp);
/*
* We force hc_EVP_CipherInit_ex to always call our init() function,
* otherwise we don't get a chance to call EVP_CipherInit_ex()
* correctly.
*/
hc_evp->flags = hc_EVP_CIPH_ALWAYS_CALL_INIT | arg->flags;
/* Our cipher context */
hc_evp->ctx_size = sizeof(struct ossl_cipher_ctx);
/* Our wrappers */
hc_evp->init = cipher_ctx_init;
hc_evp->do_cipher = cipher_do_cipher;
hc_evp->cleanup = cipher_cleanup;
hc_evp->set_asn1_parameters = NULL;
hc_evp->get_asn1_parameters = NULL;
hc_evp->ctrl = cipher_ctrl;
/* Our link to the OpenSSL EVP_CIPHER */
hc_evp->app_data = (void *)ossl_evp;
/* Finally, set the static hc_EVP_CIPHER * to the one we just built */
*arg->hc_memoizep = hc_evp;
}
static const hc_EVP_CIPHER *
get_EVP_CIPHER(heim_base_once_t *once, hc_EVP_CIPHER *hc_memoize,
const hc_EVP_CIPHER **hc_memoizep,
const hc_EVP_CIPHER *fallback,
unsigned long flags, int nid)
{
struct once_init_cipher_ctx arg;
arg.flags = flags;
arg.hc_memoizep = hc_memoizep;
arg.hc_memoize = hc_memoize;
arg.fallback = fallback;
arg.nid = nid;
heim_base_once_f(once, &arg, get_EVP_CIPHER_once_cb);
return *hc_memoizep; /* May be NULL */
}
#define OSSL_CIPHER_ALGORITHM(name, flags) \
extern const hc_EVP_CIPHER *hc_EVP_hcrypto_##name(void); \
const hc_EVP_CIPHER *hc_EVP_ossl_##name(void) \
{ \
static hc_EVP_CIPHER ossl_##name##_st; \
static const hc_EVP_CIPHER *ossl_##name; \
static heim_base_once_t once = HEIM_BASE_ONCE_INIT; \
return get_EVP_CIPHER(&once, &ossl_##name##_st, &ossl_##name, \
hc_EVP_hcrypto_##name(), \
flags, NID_##name); \
}
/* As above, but for EVP_MDs */
struct ossl_md_ctx {
EVP_MD_CTX *ossl_md_ctx; /* OpenSSL md ctx */
const EVP_MD *ossl_md; /* OpenSSL md */
int initialized;
};
static int
ossl_md_init(struct ossl_md_ctx *ctx, const EVP_MD *md)
{
if (ctx->initialized)
EVP_MD_CTX_free(ctx->ossl_md_ctx);
ctx->initialized = 0;
ctx->ossl_md = md;
ctx->ossl_md_ctx = EVP_MD_CTX_new();
if (!EVP_DigestInit(ctx->ossl_md_ctx, md)) {
EVP_MD_CTX_free(ctx->ossl_md_ctx);
ctx->ossl_md_ctx = NULL;
ctx->ossl_md = NULL;
return 0;
}
ctx->initialized = 1;
return 1;
}
static int
ossl_md_update(hc_EVP_MD_CTX *d, const void *data, size_t count)
{
struct ossl_md_ctx *ctx = (void *)d;
return EVP_DigestUpdate(ctx->ossl_md_ctx, data, count);
}
static int
ossl_md_final(void *md_data, hc_EVP_MD_CTX *d)
{
struct ossl_md_ctx *ctx = (void *)d;
return EVP_DigestFinal(ctx->ossl_md_ctx, md_data, NULL);
}
static int
ossl_md_cleanup(hc_EVP_MD_CTX *d)
{
struct ossl_md_ctx *ctx = (void *)d;
if (!ctx->initialized)
return 1;
EVP_MD_CTX_free(ctx->ossl_md_ctx);
ctx->ossl_md = NULL;
ctx->initialized = 0;
return 1;
}
struct once_init_md_ctx {
const EVP_MD **ossl_memoizep;
const hc_EVP_MD **hc_memoizep;
hc_EVP_MD *hc_memoize;
const hc_EVP_MD *fallback;
hc_evp_md_init md_init;
int nid;
};
static void
get_EVP_MD_once_cb(void *d)
{
struct once_init_md_ctx *arg = d;
const EVP_MD *ossl_evp;
hc_EVP_MD *hc_evp;
hc_evp = arg->hc_memoize;
*arg->ossl_memoizep = ossl_evp = EVP_get_digestbynid(arg->nid);
if (ossl_evp == NULL) {
(void) memset_s(hc_evp, sizeof(*hc_evp), 0, sizeof(*hc_evp));
#if HCRYPTO_FALLBACK
*arg->hc_memoizep = arg->fallback;
#endif
return;
}
/* Build the hc_EVP_MD */
hc_evp->block_size = EVP_MD_block_size(ossl_evp);
hc_evp->hash_size = EVP_MD_size(ossl_evp);
hc_evp->ctx_size = sizeof(struct ossl_md_ctx);
hc_evp->init = arg->md_init;
hc_evp->update = ossl_md_update;
hc_evp->final = ossl_md_final;
hc_evp->cleanup = ossl_md_cleanup;
*arg->hc_memoizep = hc_evp;
}
static const hc_EVP_MD *
get_EVP_MD(heim_base_once_t *once, hc_EVP_MD *hc_memoize,
const hc_EVP_MD **hc_memoizep, const EVP_MD **ossl_memoizep,
const hc_EVP_MD *fallback,
hc_evp_md_init md_init, int nid)
{
struct once_init_md_ctx ctx;
ctx.ossl_memoizep = ossl_memoizep;
ctx.hc_memoizep = hc_memoizep;
ctx.hc_memoize = hc_memoize;
ctx.fallback = fallback;
ctx.md_init = md_init;
ctx.nid = nid;
heim_base_once_f(once, &ctx, get_EVP_MD_once_cb);
return *hc_memoizep; /* May be NULL */
}
#define OSSL_MD_ALGORITHM(name) \
extern const hc_EVP_MD *hc_EVP_hcrypto_##name(void); \
static const EVP_MD *ossl_EVP_##name; \
static const hc_EVP_MD *ossl_##name; \
static int ossl_init_##name(hc_EVP_MD_CTX *d) \
{ \
return ossl_md_init((void *)d, ossl_EVP_##name); \
} \
const hc_EVP_MD *hc_EVP_ossl_##name(void) \
{ \
static hc_EVP_MD ossl_##name##_st; \
static heim_base_once_t once = HEIM_BASE_ONCE_INIT; \
return get_EVP_MD(&once, &ossl_##name##_st, &ossl_##name, \
&ossl_EVP_##name, hc_EVP_hcrypto_##name(), \
ossl_init_##name, NID_##name); \
}
#else /* HAVE_HCRYPTO_W_OPENSSL */
#include "evp-hcrypto.h"
#define OSSL_CIPHER_ALGORITHM(name, flags) \
extern const hc_EVP_CIPHER *hc_EVP_ossl_##name(void); \
const hc_EVP_CIPHER *hc_EVP_ossl_##name(void) \
{ \
return hc_EVP_hcrypto_##name(); \
}
#define OSSL_MD_ALGORITHM(name) \
extern const hc_EVP_MD *hc_EVP_ossl_##name(void); \
const hc_EVP_MD *hc_EVP_ossl_##name(void) \
{ \
return hc_EVP_hcrypto_##name(); \
}
#endif /* HAVE_HCRYPTO_W_OPENSSL */
/**
* The triple DES cipher type (OpenSSL provider)
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(des_ede3_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The DES cipher type (OpenSSL provider)
*
* @return the DES-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
#ifndef HAVE_OPENSSL_30
OSSL_CIPHER_ALGORITHM(des_cbc, hc_EVP_CIPH_CBC_MODE)
#endif
/**
* The AES-128 cipher type (OpenSSL provider)
*
* @return the AES-128-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_128_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The AES-192 cipher type (OpenSSL provider)
*
* @return the AES-192-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_192_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The AES-256 cipher type (OpenSSL provider)
*
* @return the AES-256-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_256_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The AES-128 CFB8 cipher type (OpenSSL provider)
*
* @return the AES-128-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_128_cfb8, hc_EVP_CIPH_CFB8_MODE)
/**
* The AES-192 CFB8 cipher type (OpenSSL provider)
*
* @return the AES-192-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_192_cfb8, hc_EVP_CIPH_CFB8_MODE)
/**
* The AES-256 CFB8 cipher type (OpenSSL provider)
*
* @return the AES-256-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(aes_256_cfb8, hc_EVP_CIPH_CFB8_MODE)
#ifndef HAVE_OPENSSL_30
/*
* RC2 is only needed for tests of PKCS#12 support, which currently uses
* the RC2 PBE. So no RC2 -> tests fail.
*/
/**
* The RC2 cipher type - OpenSSL
*
* @return the RC2 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(rc2_cbc,
hc_EVP_CIPH_CBC_MODE |
hc_EVP_CIPH_VARIABLE_LENGTH)
/**
* The RC2-40 cipher type - OpenSSL
*
* @return the RC2-40 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(rc2_40_cbc,
hc_EVP_CIPH_CBC_MODE)
/**
* The RC2-64 cipher type - OpenSSL
*
* @return the RC2-64 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(rc2_64_cbc,
hc_EVP_CIPH_CBC_MODE |
hc_EVP_CIPH_VARIABLE_LENGTH)
#endif
/**
* The Camellia-128 cipher type - OpenSSL
*
* @return the Camellia-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(camellia_128_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The Camellia-198 cipher type - OpenSSL
*
* @return the Camellia-198 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(camellia_192_cbc, hc_EVP_CIPH_CBC_MODE)
/**
* The Camellia-256 cipher type - OpenSSL
*
* @return the Camellia-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(camellia_256_cbc, hc_EVP_CIPH_CBC_MODE)
#ifndef HAVE_OPENSSL_30
/**
* The RC4 cipher type (OpenSSL provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(rc4,
hc_EVP_CIPH_STREAM_CIPHER |
hc_EVP_CIPH_VARIABLE_LENGTH)
/**
* The RC4-40 cipher type (OpenSSL provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_CIPHER_ALGORITHM(rc4_40,
hc_EVP_CIPH_STREAM_CIPHER |
hc_EVP_CIPH_VARIABLE_LENGTH)
/**
* The MD4 hash algorithm (OpenSSL provider)
*
* @return the MD4 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(md4)
#endif
/**
* The MD5 hash algorithm (OpenSSL provider)
*
* @return the MD5 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(md5)
/**
* The SHA-1 hash algorithm (OpenSSL provider)
*
* @return the SHA-1 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(sha1)
/**
* The SHA-256 hash algorithm (OpenSSL provider)
*
* @return the SHA-256 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(sha256)
/**
* The SHA-384 hash algorithm (OpenSSL provider)
*
* @return the SHA-384 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(sha384)
/**
* The SHA-512 hash algorithm (OpenSSL provider)
*
* @return the SHA-512 EVP_MD pointer.
*
* @ingroup hcrypto_evp
*/
OSSL_MD_ALGORITHM(sha512)

View File

@@ -1,100 +0,0 @@
/*
* Copyright (c) 2009-2016 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_OSSL_H
#define HEIM_EVP_OSSL_H 1
/* symbol renaming */
#define EVP_ossl_md4 hc_EVP_ossl_md4
#define EVP_ossl_md5 hc_EVP_ossl_md5
#define EVP_ossl_sha1 hc_EVP_ossl_sha1
#define EVP_ossl_sha256 hc_EVP_ossl_sha256
#define EVP_ossl_sha384 hc_EVP_ossl_sha384
#define EVP_ossl_sha512 hc_EVP_ossl_sha512
#define EVP_ossl_des_cbc hc_EVP_ossl_des_cbc
#define EVP_ossl_des_ede3_cbc hc_EVP_ossl_des_ede3_cbc
#define EVP_ossl_aes_128_cbc hc_EVP_ossl_aes_128_cbc
#define EVP_ossl_aes_192_cbc hc_EVP_ossl_aes_192_cbc
#define EVP_ossl_aes_256_cbc hc_EVP_ossl_aes_256_cbc
#define EVP_ossl_aes_128_cfb8 hc_EVP_ossl_aes_128_cfb8
#define EVP_ossl_aes_192_cfb8 hc_EVP_ossl_aes_192_cfb8
#define EVP_ossl_aes_256_cfb8 hc_EVP_ossl_aes_256_cfb8
#define EVP_ossl_rc4 hc_EVP_ossl_rc4
#define EVP_ossl_rc4_40 hc_EVP_ossl_rc4_40
#define EVP_ossl_rc2_40_cbc hc_EVP_ossl_rc2_40_cbc
#define EVP_ossl_rc2_64_cbc hc_EVP_ossl_rc2_64_cbc
#define EVP_ossl_rc2_cbc hc_EVP_ossl_rc2_cbc
#define EVP_ossl_camellia_128_cbc hc_EVP_ossl_camellia_128_cbc
#define EVP_ossl_camellia_192_cbc hc_EVP_ossl_camellia_192_cbc
#define EVP_ossl_camellia_256_cbc hc_EVP_ossl_camellia_256_cbc
/*
*
*/
HC_CPP_BEGIN
const hc_EVP_MD * hc_EVP_ossl_md4(void);
const hc_EVP_MD * hc_EVP_ossl_md5(void);
const hc_EVP_MD * hc_EVP_ossl_sha1(void);
const hc_EVP_MD * hc_EVP_ossl_sha256(void);
const hc_EVP_MD * hc_EVP_ossl_sha384(void);
const hc_EVP_MD * hc_EVP_ossl_sha512(void);
const hc_EVP_CIPHER * hc_EVP_ossl_rc2_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_rc2_40_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_rc2_64_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_rc4(void);
const hc_EVP_CIPHER * hc_EVP_ossl_rc4_40(void);
const hc_EVP_CIPHER * hc_EVP_ossl_des_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_des_ede3_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_128_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_192_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_256_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_128_cfb8(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_192_cfb8(void);
const hc_EVP_CIPHER * hc_EVP_ossl_aes_256_cfb8(void);
const hc_EVP_CIPHER * hc_EVP_ossl_camellia_128_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_camellia_192_cbc(void);
const hc_EVP_CIPHER * hc_EVP_ossl_camellia_256_cbc(void);
HC_CPP_END
#endif /* HEIM_EVP_OSSL_H */

View File

@@ -1,831 +0,0 @@
/*
* Copyright (c) 2015-2016, 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.
*/
/* PKCS#11 provider */
#include <config.h>
#include <roken.h>
#include <assert.h>
#ifndef HAVE_DLFCN_H
#error PKCS11 support requires dlfcn.h
#endif
#include <heimbase.h>
#include <evp.h>
#include <evp-hcrypto.h>
#include <evp-pkcs11.h>
#include <ref/pkcs11.h>
#if __sun && !defined(PKCS11_MODULE_PATH)
# ifdef _LP64
# define PKCS11_MODULE_PATH "/usr/lib/64/libpkcs11.so"
# else
# define PKCS11_MODULE_PATH "/usr/lib/libpkcs11.so"
# endif
#elif defined(__linux__)
/*
* XXX We should have an autoconf check for OpenCryptoki and such
* things. However, there's no AC_CHECK_OBJECT(), and we'd have to
* write one. Today I'm feeling lazy. Another possibility would be to
* have a symlink from the libdir we'll install into, and then we could
* dlopen() that on all platforms.
*
* XXX Also, we should pick an appropriate shared object based on 32- vs
* 64-bits.
*/
# define PKCS11_MODULE_PATH "/usr/lib/pkcs11/PKCS11_API.so"
#endif
static CK_FUNCTION_LIST_PTR p11_module;
static int
p11_cleanup(EVP_CIPHER_CTX *ctx);
struct pkcs11_cipher_ctx {
CK_SESSION_HANDLE hSession;
CK_OBJECT_HANDLE hSecret;
};
struct pkcs11_md_ctx {
CK_SESSION_HANDLE hSession;
};
static void *pkcs11_module_handle;
static CK_RV
p11_module_load(CK_FUNCTION_LIST_PTR_PTR ppFunctionList)
{
CK_RV rv;
CK_RV (*C_GetFunctionList_fn)(CK_FUNCTION_LIST_PTR_PTR);
char *pkcs11ModulePath = secure_getenv("PKCS11_MODULE_PATH");
*ppFunctionList = NULL;
if (pkcs11ModulePath != NULL) {
pkcs11_module_handle =
dlopen(pkcs11ModulePath,
RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
if (pkcs11_module_handle == NULL)
fprintf(stderr, "p11_module_load(%s): %s\n", pkcs11ModulePath, dlerror());
}
#ifdef PKCS11_MODULE_PATH
if (pkcs11_module_handle == NULL) {
pkcs11_module_handle =
dlopen(PKCS11_MODULE_PATH,
RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
if (pkcs11_module_handle == NULL)
fprintf(stderr, "p11_module_load(%s): %s\n", PKCS11_MODULE_PATH, dlerror());
}
#endif
if (pkcs11_module_handle == NULL)
return CKR_LIBRARY_LOAD_FAILED;
C_GetFunctionList_fn = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
dlsym(pkcs11_module_handle, "C_GetFunctionList");
if (C_GetFunctionList_fn == NULL) {
dlclose(pkcs11_module_handle);
return CKR_LIBRARY_LOAD_FAILED;
}
rv = C_GetFunctionList_fn(ppFunctionList);
if (rv != CKR_OK) {
dlclose(pkcs11_module_handle);
return rv;
}
return CKR_OK;
}
static void
p11_module_load_once(void *context)
{
p11_module_load((CK_FUNCTION_LIST_PTR_PTR)context);
}
static CK_RV
p11_module_init(void)
{
static heim_base_once_t once = HEIM_BASE_ONCE_INIT;
CK_RV rv;
heim_base_once_f(&once, &p11_module, p11_module_load_once);
if (p11_module == NULL)
return CKR_LIBRARY_LOAD_FAILED;
/*
* Call C_Initialize() on every call, because it will be invalid after fork().
* Caching the initialization status using a once control and invalidating it
* on fork provided no measurable performance benefit on Solaris 11. Other
* approaches would not be thread-safe or would involve more intrusive code
* changes, such as exposing heimbase's atomics.
*/
rv = p11_module->C_Initialize(NULL);
if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
rv = CKR_OK;
return rv;
}
static CK_RV
p11_session_init(CK_MECHANISM_TYPE mechanismType,
CK_SESSION_HANDLE_PTR phSession,
CK_FLAGS *pFlags)
{
CK_RV rv;
CK_ULONG i, ulSlotCount = 0;
CK_SLOT_ID_PTR pSlotList = NULL;
CK_MECHANISM_INFO info;
if (phSession != NULL)
*phSession = CK_INVALID_HANDLE;
*pFlags = 0;
rv = p11_module_init();
if (rv != CKR_OK)
goto cleanup;
assert(p11_module != NULL);
rv = p11_module->C_GetSlotList(CK_FALSE, NULL, &ulSlotCount);
if (rv != CKR_OK)
goto cleanup;
pSlotList = (CK_SLOT_ID_PTR)calloc(ulSlotCount, sizeof(CK_SLOT_ID));
if (pSlotList == NULL) {
rv = CKR_HOST_MEMORY;
goto cleanup;
}
rv = p11_module->C_GetSlotList(CK_FALSE, pSlotList, &ulSlotCount);
if (rv != CKR_OK)
goto cleanup;
/*
* Note that this approach of using the first slot that supports the desired
* mechanism may not always be what the user wants (for example it may prefer
* software to hardware crypto). We're going to assume that this code will be
* principally used on Solaris (which has a meta-slot provider that sorts by
* hardware first) or in situations where the user can configure the slots in
* order of provider preference. In the future we should make this configurable.
*/
for (i = 0; i < ulSlotCount; i++) {
rv = p11_module->C_GetMechanismInfo(pSlotList[i], mechanismType, &info);
if (rv == CKR_OK) {
*pFlags = info.flags;
break;
}
}
if (i == ulSlotCount) {
rv = CKR_MECHANISM_INVALID;
goto cleanup;
}
if (phSession != NULL) {
rv = p11_module->C_OpenSession(pSlotList[i], CKF_SERIAL_SESSION, NULL, NULL, phSession);
if (rv != CKR_OK)
goto cleanup;
}
cleanup:
free(pSlotList);
return rv;
}
static int
p11_mech_available_p(CK_MECHANISM_TYPE mechanismType, CK_FLAGS reqFlags)
{
CK_RV rv;
CK_FLAGS flags;
rv = p11_session_init(mechanismType, NULL, &flags);
if (rv != CKR_OK)
return 0;
return (flags & reqFlags) == reqFlags;
}
static CK_KEY_TYPE
p11_key_type_for_mech(CK_MECHANISM_TYPE mechanismType)
{
CK_KEY_TYPE keyType = 0;
switch (mechanismType) {
case CKM_RC2_CBC:
keyType = CKK_RC2;
break;
case CKM_RC4:
keyType = CKK_RC4;
break;
case CKM_DES_CBC:
keyType = CKK_DES;
break;
case CKM_DES3_CBC:
keyType = CKK_DES3;
break;
case CKM_AES_CBC:
case CKM_AES_CFB8:
keyType = CKK_AES;
break;
case CKM_CAMELLIA_CBC:
keyType = CKK_CAMELLIA;
break;
default:
assert(0 && "Unknown PKCS#11 mechanism type");
break;
}
return keyType;
}
static int
p11_key_init(EVP_CIPHER_CTX *ctx,
const unsigned char *key,
const unsigned char *iv,
int encp)
{
CK_RV rv;
CK_BBOOL bFalse = CK_FALSE;
CK_BBOOL bTrue = CK_TRUE;
CK_MECHANISM_TYPE mechanismType = (CK_MECHANISM_TYPE)ctx->cipher->app_data;
CK_KEY_TYPE keyType = p11_key_type_for_mech(mechanismType);
CK_OBJECT_CLASS objectClass = CKO_SECRET_KEY;
CK_ATTRIBUTE_TYPE op = encp ? CKA_ENCRYPT : CKA_DECRYPT;
CK_ATTRIBUTE attributes[] = {
{ CKA_EXTRACTABLE, &bFalse, sizeof(bFalse) },
{ CKA_CLASS, &objectClass, sizeof(objectClass) },
{ CKA_KEY_TYPE, &keyType, sizeof(keyType) },
{ CKA_TOKEN, &bFalse, sizeof(bFalse) },
{ CKA_PRIVATE, &bFalse, sizeof(bFalse) },
{ CKA_SENSITIVE, &bTrue, sizeof(bTrue) },
{ CKA_VALUE, (void *)key, ctx->key_len },
{ op, &bTrue, sizeof(bTrue) }
};
CK_MECHANISM mechanism = {
mechanismType,
ctx->cipher->iv_len ? ctx->iv : NULL,
ctx->cipher->iv_len
};
struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
CK_FLAGS flags;
rv = CKR_OK;
if (p11ctx->hSession != CK_INVALID_HANDLE && key != NULL)
p11_cleanup(ctx); /* refresh session with new key */
if (p11ctx->hSession == CK_INVALID_HANDLE) {
rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
if (rv != CKR_OK)
goto cleanup;
if ((flags & (CKF_ENCRYPT|CKF_DECRYPT)) != (CKF_ENCRYPT|CKF_DECRYPT)) {
rv = CKR_MECHANISM_INVALID;
goto cleanup;
}
}
if (key != NULL) {
assert(p11_module != NULL);
assert(p11ctx->hSecret == CK_INVALID_HANDLE);
rv = p11_module->C_CreateObject(p11ctx->hSession, attributes,
sizeof(attributes) / sizeof(attributes[0]),
&p11ctx->hSecret);
if (rv != CKR_OK)
goto cleanup;
}
if (p11ctx->hSecret != CK_INVALID_HANDLE) {
if (op == CKA_ENCRYPT)
rv = p11_module->C_EncryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
else
rv = p11_module->C_DecryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
if (rv != CKR_OK)
goto cleanup;
}
cleanup:
if (rv != CKR_OK)
p11_cleanup(ctx);
return rv == CKR_OK;
}
static int
p11_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
CK_RV rv;
CK_ULONG ulCipherTextLen = size;
assert(p11_module != NULL);
assert(EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_STREAM_CIPHER ||
(size % ctx->cipher->block_size) == 0);
if (ctx->encrypt)
rv = p11_module->C_EncryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
else
rv = p11_module->C_DecryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
return rv == CKR_OK;
}
static int
p11_cleanup(EVP_CIPHER_CTX *ctx)
{
struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
if (p11ctx->hSecret != CK_INVALID_HANDLE) {
p11_module->C_DestroyObject(p11ctx->hSession, p11ctx->hSecret);
p11ctx->hSecret = CK_INVALID_HANDLE;
}
if (p11ctx->hSession != CK_INVALID_HANDLE) {
p11_module->C_CloseSession(p11ctx->hSession);
p11ctx->hSession = CK_INVALID_HANDLE;
}
return 1;
}
static int
p11_md_cleanup(EVP_MD_CTX *ctx);
static int
p11_md_hash_init(CK_MECHANISM_TYPE mechanismType, EVP_MD_CTX *ctx)
{
struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
CK_RV rv;
CK_FLAGS flags;
CK_MECHANISM mechanism = { mechanismType, NULL, 0 };
if (p11ctx->hSession != CK_INVALID_HANDLE)
p11_md_cleanup(ctx);
rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
if (rv != CKR_OK)
goto cleanup;
if ((flags & CKF_DIGEST) != CKF_DIGEST) {
rv = CKR_MECHANISM_INVALID;
goto cleanup;
}
assert(p11_module != NULL);
rv = p11_module->C_DigestInit(p11ctx->hSession, &mechanism);
cleanup:
return rv == CKR_OK;
}
static int
p11_md_update(EVP_MD_CTX *ctx, const void *data, size_t length)
{
struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
CK_RV rv;
assert(p11_module != NULL);
assert(data != NULL || length == 0);
rv = p11_module->C_DigestUpdate(p11ctx->hSession,
data ? (CK_BYTE_PTR)data : (CK_BYTE_PTR)"",
length);
return rv == CKR_OK;
}
static int
p11_md_final(void *digest, EVP_MD_CTX *ctx)
{
struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
CK_RV rv;
CK_ULONG digestLen = 0;
assert(p11_module != NULL);
rv = p11_module->C_DigestFinal(p11ctx->hSession, NULL, &digestLen);
if (rv == CKR_OK)
rv = p11_module->C_DigestFinal(p11ctx->hSession, digest, &digestLen);
return rv == CKR_OK;
}
static int
p11_md_cleanup(EVP_MD_CTX *ctx)
{
struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
CK_RV rv;
assert(p11_module != NULL);
rv = p11_module->C_CloseSession(p11ctx->hSession);
if (rv == CKR_OK)
p11ctx->hSession = CK_INVALID_HANDLE;
return rv == CKR_OK;
}
#define PKCS11_CIPHER_ALGORITHM(name, mechanismType, block_size, \
key_len, iv_len, flags) \
\
static EVP_CIPHER \
pkcs11_##name = { \
0, \
block_size, \
key_len, \
iv_len, \
(flags) | EVP_CIPH_ALWAYS_CALL_INIT, \
p11_key_init, \
p11_do_cipher, \
p11_cleanup, \
sizeof(struct pkcs11_cipher_ctx), \
NULL, \
NULL, \
NULL, \
(void *)mechanismType \
}; \
\
const EVP_CIPHER * \
hc_EVP_pkcs11_##name(void) \
{ \
if (p11_mech_available_p(mechanismType, CKF_ENCRYPT|CKF_DECRYPT)) \
return &pkcs11_##name; \
else \
return NULL; \
} \
\
static void \
pkcs11_hcrypto_##name##_init_once(void *context) \
{ \
const EVP_CIPHER *cipher; \
\
cipher = hc_EVP_pkcs11_ ##name(); \
if (cipher == NULL && HCRYPTO_FALLBACK) \
cipher = hc_EVP_hcrypto_ ##name(); \
\
*((const EVP_CIPHER **)context) = cipher; \
} \
\
const EVP_CIPHER * \
hc_EVP_pkcs11_hcrypto_##name(void) \
{ \
static const EVP_CIPHER *__cipher; \
static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
\
heim_base_once_f(&__init, &__cipher, \
pkcs11_hcrypto_##name##_init_once); \
\
return __cipher; \
}
#define PKCS11_MD_ALGORITHM(name, mechanismType, hash_size, block_size) \
\
static int p11_##name##_init(EVP_MD_CTX *ctx) \
{ \
return p11_md_hash_init(mechanismType, ctx); \
} \
\
const EVP_MD * \
hc_EVP_pkcs11_##name(void) \
{ \
static struct hc_evp_md name = { \
hash_size, \
block_size, \
sizeof(struct pkcs11_md_ctx), \
p11_##name##_init, \
p11_md_update, \
p11_md_final, \
p11_md_cleanup \
}; \
\
if (p11_mech_available_p(mechanismType, CKF_DIGEST)) \
return &name; \
else \
return NULL; \
} \
\
static void \
pkcs11_hcrypto_##name##_init_once(void *context) \
{ \
const EVP_MD *md; \
\
md = hc_EVP_pkcs11_ ##name(); \
if (md == NULL && HCRYPTO_FALLBACK) \
md = hc_EVP_hcrypto_ ##name(); \
\
*((const EVP_MD **)context) = md; \
} \
\
const EVP_MD * \
hc_EVP_pkcs11_hcrypto_##name(void) \
{ \
static const EVP_MD *__md; \
static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
\
heim_base_once_f(&__init, &__md, \
pkcs11_hcrypto_##name##_init_once); \
\
return __md; \
}
#define PKCS11_MD_ALGORITHM_UNAVAILABLE(name) \
\
const EVP_MD * \
hc_EVP_pkcs11_##name(void) \
{ \
return NULL; \
} \
\
const EVP_MD * \
hc_EVP_pkcs11_hcrypto_##name(void) \
{ \
return hc_EVP_hcrypto_ ##name(); \
}
/**
* The triple DES cipher type (PKCS#11 provider)
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(des_ede3_cbc,
CKM_DES3_CBC,
8,
24,
8,
EVP_CIPH_CBC_MODE)
/**
* The DES cipher type (PKCS#11 provider)
*
* @return the DES-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(des_cbc,
CKM_DES_CBC,
8,
8,
8,
EVP_CIPH_CBC_MODE)
/**
* The AES-128 cipher type (PKCS#11 provider)
*
* @return the AES-128-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_128_cbc,
CKM_AES_CBC,
16,
16,
16,
EVP_CIPH_CBC_MODE)
/**
* The AES-192 cipher type (PKCS#11 provider)
*
* @return the AES-192-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_192_cbc,
CKM_AES_CBC,
16,
24,
16,
EVP_CIPH_CBC_MODE)
/**
* The AES-256 cipher type (PKCS#11 provider)
*
* @return the AES-256-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_256_cbc,
CKM_AES_CBC,
16,
32,
16,
EVP_CIPH_CBC_MODE)
/**
* The AES-128 CFB8 cipher type (PKCS#11 provider)
*
* @return the AES-128-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_128_cfb8,
CKM_AES_CFB8,
16,
16,
16,
EVP_CIPH_CFB8_MODE)
/**
* The AES-192 CFB8 cipher type (PKCS#11 provider)
*
* @return the AES-192-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_192_cfb8,
CKM_AES_CFB8,
16,
24,
16,
EVP_CIPH_CFB8_MODE)
/**
* The AES-256 CFB8 cipher type (PKCS#11 provider)
*
* @return the AES-256-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(aes_256_cfb8,
CKM_AES_CFB8,
16,
32,
16,
EVP_CIPH_CFB8_MODE)
/**
* The RC2 cipher type - PKCS#11
*
* @return the RC2 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(rc2_cbc,
CKM_RC2_CBC,
8,
16,
8,
EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH)
/**
* The RC2-40 cipher type - PKCS#11
*
* @return the RC2-40 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(rc2_40_cbc,
CKM_RC2_CBC,
8,
5,
8,
EVP_CIPH_CBC_MODE)
/**
* The RC2-64 cipher type - PKCS#11
*
* @return the RC2-64 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(rc2_64_cbc,
CKM_RC2_CBC,
8,
8,
8,
EVP_CIPH_CBC_MODE)
/**
* The Camellia-128 cipher type - PKCS#11
*
* @return the Camellia-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(camellia_128_cbc,
CKM_CAMELLIA_CBC,
16,
16,
16,
EVP_CIPH_CBC_MODE)
/**
* The Camellia-198 cipher type - PKCS#11
*
* @return the Camellia-198 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(camellia_192_cbc,
CKM_CAMELLIA_CBC,
16,
24,
16,
EVP_CIPH_CBC_MODE)
/**
* The Camellia-256 cipher type - PKCS#11
*
* @return the Camellia-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(camellia_256_cbc,
CKM_CAMELLIA_CBC,
16,
32,
16,
EVP_CIPH_CBC_MODE)
/**
* The RC4 cipher type (PKCS#11 provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(rc4,
CKM_RC4,
1,
16,
0,
EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
/**
* The RC4-40 cipher type (PKCS#11 provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
PKCS11_CIPHER_ALGORITHM(rc4_40,
CKM_RC4,
1,
5,
0,
EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
#ifdef CKM_MD4 /* non-standard extension */
PKCS11_MD_ALGORITHM(md4, CKM_MD4, 16, 64)
#else
PKCS11_MD_ALGORITHM_UNAVAILABLE(md4)
#endif
PKCS11_MD_ALGORITHM(md5, CKM_MD5, 16, 64)
PKCS11_MD_ALGORITHM(sha1, CKM_SHA_1, 20, 64)
PKCS11_MD_ALGORITHM(sha256, CKM_SHA256, 32, 64)
PKCS11_MD_ALGORITHM(sha384, CKM_SHA384, 48, 128)
PKCS11_MD_ALGORITHM(sha512, CKM_SHA512, 64, 128)

View File

@@ -1,153 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_PKCS11_H
#define HEIM_EVP_PKCS11_H 1
/* symbol renaming */
#define EVP_pkcs11_md4() hc_EVP_pkcs11_md4()
#define EVP_pkcs11_md5() hc_EVP_pkcs11_md5()
#define EVP_pkcs11_sha1() hc_EVP_pkcs11_sha1()
#define EVP_pkcs11_sha256() hc_EVP_pkcs11_sha256()
#define EVP_pkcs11_sha384() hc_EVP_pkcs11_sha384()
#define EVP_pkcs11_sha512() hc_EVP_pkcs11_sha512()
#define EVP_pkcs11_des_cbc() hc_EVP_pkcs11_des_cbc()
#define EVP_pkcs11_des_ede3_cbc() hc_EVP_pkcs11_des_ede3_cbc()
#define EVP_pkcs11_aes_128_cbc() hc_EVP_pkcs11_aes_128_cbc()
#define EVP_pkcs11_aes_192_cbc() hc_EVP_pkcs11_aes_192_cbc()
#define EVP_pkcs11_aes_256_cbc() hc_EVP_pkcs11_aes_256_cbc()
#define EVP_pkcs11_aes_128_cfb8() hc_EVP_pkcs11_aes_128_cfb8()
#define EVP_pkcs11_aes_192_cfb8() hc_EVP_pkcs11_aes_192_cfb8()
#define EVP_pkcs11_aes_256_cfb8() hc_EVP_pkcs11_aes_256_cfb8()
#define EVP_pkcs11_rc4() hc_EVP_pkcs11_rc4()
#define EVP_pkcs11_rc4_40() hc_EVP_pkcs11_rc4_40()
#define EVP_pkcs11_rc2_40_cbc() hc_EVP_pkcs11_rc2_40_cbc()
#define EVP_pkcs11_rc2_64_cbc() hc_EVP_pkcs11_rc2_64_cbc()
#define EVP_pkcs11_rc2_cbc() hc_EVP_pkcs11_rc2_cbc()
#define EVP_pkcs11_camellia_128_cbc() hc_EVP_pkcs11_camellia_128_cbc()
#define EVP_pkcs11_camellia_192_cbc() hc_EVP_pkcs11_camellia_192_cbc()
#define EVP_pkcs11_camellia_256_cbc() hc_EVP_pkcs11_camellia_256_cbc()
#define EVP_pkcs11_hcrypto_md4() hc_EVP_pkcs11_hcrypto_md4()
#define EVP_pkcs11_hcrypto_md5() hc_EVP_pkcs11_hcrypto_md5()
#define EVP_pkcs11_hcrypto_sha1() hc_EVP_pkcs11_hcrypto_sha1()
#define EVP_pkcs11_hcrypto_sha256() hc_EVP_pkcs11_hcrypto_sha256()
#define EVP_pkcs11_hcrypto_sha384() hc_EVP_pkcs11_hcrypto_sha384()
#define EVP_pkcs11_hcrypto_sha512() hc_EVP_pkcs11_hcrypto_sha512()
#define EVP_pkcs11_hcrypto_des_cbc() hc_EVP_pkcs11_hcrypto_des_cbc()
#define EVP_pkcs11_hcrypto_des_ede3_cbc() hc_EVP_pkcs11_hcrypto_des_ede3_cbc()
#define EVP_pkcs11_hcrypto_aes_128_cbc() hc_EVP_pkcs11_hcrypto_aes_128_cbc()
#define EVP_pkcs11_hcrypto_aes_192_cbc() hc_EVP_pkcs11_hcrypto_aes_192_cbc()
#define EVP_pkcs11_hcrypto_aes_256_cbc() hc_EVP_pkcs11_hcrypto_aes_256_cbc()
#define EVP_pkcs11_hcrypto_aes_128_cfb8() hc_EVP_pkcs11_hcrypto_aes_128_cfb8()
#define EVP_pkcs11_hcrypto_aes_192_cfb8() hc_EVP_pkcs11_hcrypto_aes_192_cfb8()
#define EVP_pkcs11_hcrypto_aes_256_cfb8() hc_EVP_pkcs11_hcrypto_aes_256_cfb8()
#define EVP_pkcs11_hcrypto_rc4() hc_EVP_pkcs11_hcrypto_rc4()
#define EVP_pkcs11_hcrypto_rc4_40() hc_EVP_pkcs11_hcrypto_rc4_40()
#define EVP_pkcs11_hcrypto_rc2_40_cbc() hc_EVP_pkcs11_hcrypto_rc2_40_cbc()
#define EVP_pkcs11_hcrypto_rc2_64_cbc() hc_EVP_pkcs11_hcrypto_rc2_64_cbc()
#define EVP_pkcs11_hcrypto_rc2_cbc() hc_EVP_pkcs11_hcrypto_rc2_cbc()
#define EVP_pkcs11_hcrypto_camellia_128_cbc() hc_EVP_pkcs11_hcrypto_camellia_128_cbc()
#define EVP_pkcs11_hcrypto_camellia_192_cbc() hc_EVP_pkcs11_hcrypto_camellia_192_cbc()
#define EVP_pkcs11_hcrypto_camellia_256_cbc() hc_EVP_pkcs11_hcrypto_camellia_256_cbc()
HC_CPP_BEGIN
/*
* Strict PKCS#11 implementations (these will return NULL if the underlying
* PKCS#11 implementation does not implement the cipher or hash).
*/
const EVP_MD * hc_EVP_pkcs11_md4(void);
const EVP_MD * hc_EVP_pkcs11_md5(void);
const EVP_MD * hc_EVP_pkcs11_sha1(void);
const EVP_MD * hc_EVP_pkcs11_sha256(void);
const EVP_MD * hc_EVP_pkcs11_sha384(void);
const EVP_MD * hc_EVP_pkcs11_sha512(void);
const EVP_CIPHER * hc_EVP_pkcs11_rc2_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_rc2_40_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_rc2_64_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_rc4(void);
const EVP_CIPHER * hc_EVP_pkcs11_rc4_40(void);
const EVP_CIPHER * hc_EVP_pkcs11_des_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_des_ede3_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_128_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_192_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_256_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_128_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_192_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_aes_256_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_camellia_128_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_camellia_192_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_camellia_256_cbc(void);
/*
* PKCS#11 implementations with fallback to hcrypto.
*/
const EVP_MD * hc_EVP_pkcs11_hcrypto_md4(void);
const EVP_MD * hc_EVP_pkcs11_hcrypto_md5(void);
const EVP_MD * hc_EVP_pkcs11_hcrypto_sha1(void);
const EVP_MD * hc_EVP_pkcs11_hcrypto_sha256(void);
const EVP_MD * hc_EVP_pkcs11_hcrypto_sha384(void);
const EVP_MD * hc_EVP_pkcs11_hcrypto_sha512(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_rc2_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_rc2_40_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_rc2_64_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_rc4(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_rc4_40(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_des_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_des_ede3_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_128_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_192_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_256_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_128_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_192_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_aes_256_cfb8(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_camellia_128_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_camellia_192_cbc(void);
const EVP_CIPHER * hc_EVP_pkcs11_hcrypto_camellia_256_cbc(void);
HC_CPP_END
#endif /* HEIM_EVP_PKCS11_H */

View File

@@ -1,139 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
/*
* Windows fallback provider: decides whether to use hcrypto or
* wincng depending on whether bcrypt.dll is available (i.e. it
* is runtime compatible back to XP, but will use the native
* crypto APIs from Vista onwards).
*/
#include <config.h>
#include <roken.h>
#include <assert.h>
#include <evp.h>
#include <evp-w32.h>
#include <evp-hcrypto.h>
#include <evp-wincng.h>
static LONG wincng_available = -1;
static __inline int
wincng_check_availability(void)
{
if (wincng_available == -1) {
char szBCryptDllPath[MAX_PATH];
UINT cbBCryptDllPath;
cbBCryptDllPath = GetSystemDirectory(szBCryptDllPath,
sizeof(szBCryptDllPath));
if (cbBCryptDllPath > 0 &&
cbBCryptDllPath < sizeof(szBCryptDllPath) &&
strncat_s(szBCryptDllPath,
sizeof(szBCryptDllPath), "\\bcrypt.dll", 11) == 0) {
HANDLE hBCryptDll = LoadLibrary(szBCryptDllPath);
InterlockedCompareExchangeRelease(&wincng_available,
!!hBCryptDll, -1);
if (hBCryptDll)
FreeLibrary(hBCryptDll);
}
}
return wincng_available == 1;
}
BOOL WINAPI
_hc_w32crypto_DllMain(HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_DETACH) {
/*
* Don't bother cleaning up on process exit, only on
* FreeLibrary() (in which case lpvReserved will be NULL).
*/
if (lpvReserved == NULL)
_hc_wincng_cleanup();
}
return TRUE;
}
#define EVP_W32CRYPTO_PROVIDER(type, name) \
\
const type *hc_EVP_w32crypto_ ##name (void) \
{ \
if (wincng_check_availability()) \
return hc_EVP_wincng_ ##name (); \
else if (HCRYPTO_FALLBACK) \
return hc_EVP_hcrypto_ ##name (); \
else \
return NULL; \
}
#define EVP_W32CRYPTO_PROVIDER_CNG_UNAVAILABLE(type, name) \
\
const type *hc_EVP_w32crypto_ ##name (void) \
{ \
return hc_EVP_hcrypto_ ##name (); \
}
EVP_W32CRYPTO_PROVIDER(EVP_MD, md4)
EVP_W32CRYPTO_PROVIDER(EVP_MD, md5)
EVP_W32CRYPTO_PROVIDER(EVP_MD, sha1)
EVP_W32CRYPTO_PROVIDER(EVP_MD, sha256)
EVP_W32CRYPTO_PROVIDER(EVP_MD, sha384)
EVP_W32CRYPTO_PROVIDER(EVP_MD, sha512)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, rc2_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, rc2_40_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, rc2_64_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, rc4)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, rc4_40)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, des_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, des_ede3_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_128_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_192_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_256_cbc)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_128_cfb8)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_192_cfb8)
EVP_W32CRYPTO_PROVIDER(EVP_CIPHER, aes_256_cfb8)
EVP_W32CRYPTO_PROVIDER_CNG_UNAVAILABLE(EVP_CIPHER, camellia_128_cbc)
EVP_W32CRYPTO_PROVIDER_CNG_UNAVAILABLE(EVP_CIPHER, camellia_192_cbc)
EVP_W32CRYPTO_PROVIDER_CNG_UNAVAILABLE(EVP_CIPHER, camellia_256_cbc)

View File

@@ -1,98 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_W32_H
#define HEIM_EVP_W32_H 1
/* symbol renaming */
#define EVP_w32crypto_md4() hc_EVP_w32crypto_md4()
#define EVP_w32crypto_md5() hc_EVP_w32crypto_md5()
#define EVP_w32crypto_sha1() hc_EVP_w32crypto_sha1()
#define EVP_w32crypto_sha256() hc_EVP_w32crypto_sha256()
#define EVP_w32crypto_sha384() hc_EVP_w32crypto_sha384()
#define EVP_w32crypto_sha512() hc_EVP_w32crypto_sha512()
#define EVP_w32crypto_des_cbc() hc_EVP_w32crypto_des_cbc()
#define EVP_w32crypto_des_ede3_cbc() hc_EVP_w32crypto_des_ede3_cbc()
#define EVP_w32crypto_aes_128_cbc() hc_EVP_w32crypto_aes_128_cbc()
#define EVP_w32crypto_aes_192_cbc() hc_EVP_w32crypto_aes_192_cbc()
#define EVP_w32crypto_aes_256_cbc() hc_EVP_w32crypto_aes_256_cbc()
#define EVP_w32crypto_aes_128_cfb8() hc_EVP_w32crypto_aes_128_cfb8()
#define EVP_w32crypto_aes_192_cfb8() hc_EVP_w32crypto_aes_192_cfb8()
#define EVP_w32crypto_aes_256_cfb8() hc_EVP_w32crypto_aes_256_cfb8()
#define EVP_w32crypto_rc4() hc_EVP_w32crypto_rc4()
#define EVP_w32crypto_rc4_40() hc_EVP_w32crypto_rc4_40()
#define EVP_w32crypto_rc2_40_cbc() hc_EVP_w32crypto_rc2_40_cbc()
#define EVP_w32crypto_rc2_64_cbc() hc_EVP_w32crypto_rc2_64_cbc()
#define EVP_w32crypto_rc2_cbc() hc_EVP_w32crypto_rc2_cbc()
#define EVP_w32crypto_camellia_128_cbc() hc_EVP_w32crypto_camellia_128_cbc()
#define EVP_w32crypto_camellia_192_cbc() hc_EVP_w32crypto_camellia_192_cbc()
#define EVP_w32crypto_camellia_256_cbc() hc_EVP_w32crypto_camellia_256_cbc()
/*
* This provider dynamically selects between Windows CNG (if running
* on Vista or above) or the inbuilt provider (if running on XP).
*/
HC_CPP_BEGIN
const EVP_MD * hc_EVP_w32crypto_md4(void);
const EVP_MD * hc_EVP_w32crypto_md5(void);
const EVP_MD * hc_EVP_w32crypto_sha1(void);
const EVP_MD * hc_EVP_w32crypto_sha256(void);
const EVP_MD * hc_EVP_w32crypto_sha384(void);
const EVP_MD * hc_EVP_w32crypto_sha512(void);
const EVP_CIPHER * hc_EVP_w32crypto_des_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_des_ede3_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_128_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_192_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_256_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_128_cfb8(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_192_cfb8(void);
const EVP_CIPHER * hc_EVP_w32crypto_aes_256_cfb8(void);
const EVP_CIPHER * hc_EVP_w32crypto_rc4(void);
const EVP_CIPHER * hc_EVP_w32crypto_rc4_40(void);
const EVP_CIPHER * hc_EVP_w32crypto_rc2_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_rc2_40_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_rc2_64_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_camellia_128_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_camellia_192_cbc(void);
const EVP_CIPHER * hc_EVP_w32crypto_camellia_256_cbc(void);
HC_CPP_END
#endif /* HEIM_EVP_W32_H */

View File

@@ -1,725 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
/* Windows CNG provider */
#include <config.h>
#include <roken.h>
#include <assert.h>
#include <versionsupport.h>
#include <evp.h>
#include <evp-wincng.h>
#include <bcrypt.h>
#ifndef BCRYPT_HASH_REUSABLE_FLAG
#define BCRYPT_HASH_REUSABLE_FLAG 0x00000020
#endif
/*
* CNG cipher provider
*/
struct wincng_key {
BCRYPT_KEY_HANDLE hKey;
UCHAR rgbKeyObject[1];
};
#define WINCNG_KEY_OBJECT_SIZE(ctx) \
((ctx)->cipher->ctx_size - sizeof(struct wincng_key) + 1)
static int
wincng_do_cipher(EVP_CIPHER_CTX *ctx,
unsigned char *out,
const unsigned char *in,
unsigned int size)
{
struct wincng_key *cng = ctx->cipher_data;
NTSTATUS status;
ULONG cbResult;
assert(EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_STREAM_CIPHER ||
(size % ctx->cipher->block_size) == 0);
if (ctx->encrypt) {
status = BCryptEncrypt(cng->hKey,
(PUCHAR)in,
size,
NULL, /* pPaddingInfo */
ctx->cipher->iv_len ? ctx->iv : NULL,
ctx->cipher->iv_len,
out,
size,
&cbResult,
0);
} else {
status = BCryptDecrypt(cng->hKey,
(PUCHAR)in,
size,
NULL, /* pPaddingInfo */
ctx->cipher->iv_len ? ctx->iv : NULL,
ctx->cipher->iv_len,
out,
size,
&cbResult,
0);
}
return BCRYPT_SUCCESS(status) && cbResult == size;
}
static int
wincng_cleanup(EVP_CIPHER_CTX *ctx)
{
struct wincng_key *cng = ctx->cipher_data;
if (cng->hKey) {
BCryptDestroyKey(cng->hKey);
cng->hKey = (BCRYPT_KEY_HANDLE)0;
}
SecureZeroMemory(cng->rgbKeyObject, WINCNG_KEY_OBJECT_SIZE(ctx));
return 1;
}
static int
wincng_cipher_algorithm_init(EVP_CIPHER *cipher,
LPWSTR pszAlgId)
{
BCRYPT_ALG_HANDLE hAlgorithm = NULL;
NTSTATUS status;
LPCWSTR pszChainingMode;
ULONG cbKeyObject, cbChainingMode, cbData;
if (cipher->app_data)
return 1;
status = BCryptOpenAlgorithmProvider(&hAlgorithm,
pszAlgId,
NULL,
0);
if (!BCRYPT_SUCCESS(status))
return 0;
status = BCryptGetProperty(hAlgorithm,
BCRYPT_OBJECT_LENGTH,
(PUCHAR)&cbKeyObject,
sizeof(ULONG),
&cbData,
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return 0;
}
cipher->ctx_size = sizeof(struct wincng_key) + cbKeyObject - 1;
switch (cipher->flags & EVP_CIPH_MODE) {
case EVP_CIPH_CBC_MODE:
pszChainingMode = BCRYPT_CHAIN_MODE_CBC;
cbChainingMode = sizeof(BCRYPT_CHAIN_MODE_CBC);
break;
case EVP_CIPH_CFB8_MODE:
pszChainingMode = BCRYPT_CHAIN_MODE_CFB;
cbChainingMode = sizeof(BCRYPT_CHAIN_MODE_CFB);
break;
default:
pszChainingMode = NULL;
cbChainingMode = 0;
break;
}
if (cbChainingMode) {
status = BCryptSetProperty(hAlgorithm,
BCRYPT_CHAINING_MODE,
(PUCHAR)pszChainingMode,
cbChainingMode,
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return 0;
}
}
if (wcscmp(pszAlgId, BCRYPT_RC2_ALGORITHM) == 0) {
ULONG cbEffectiveKeyLength = EVP_CIPHER_key_length(cipher) * 8;
status = BCryptSetProperty(hAlgorithm,
BCRYPT_EFFECTIVE_KEY_LENGTH,
(PUCHAR)&cbEffectiveKeyLength,
sizeof(cbEffectiveKeyLength),
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return 0;
}
}
InterlockedCompareExchangePointerRelease(&cipher->app_data,
hAlgorithm, NULL);
return 1;
}
static int
wincng_key_init(EVP_CIPHER_CTX *ctx,
const unsigned char *key,
const unsigned char *iv,
int encp)
{
struct wincng_key *cng = ctx->cipher_data;
NTSTATUS status;
assert(cng != NULL);
assert(ctx->cipher != NULL);
if (ctx->cipher->app_data == NULL)
return 0;
wincng_cleanup(ctx);
/*
* Note: ctx->key_len not EVP_CIPHER_CTX_key_length() for
* variable length key support.
*/
status = BCryptGenerateSymmetricKey(ctx->cipher->app_data,
&cng->hKey,
cng->rgbKeyObject,
WINCNG_KEY_OBJECT_SIZE(ctx),
(PUCHAR)key,
ctx->key_len,
0);
return BCRYPT_SUCCESS(status);
}
#define WINCNG_CIPHER_ALGORITHM(name, alg_id, block_size, key_len, \
iv_len, flags) \
\
static EVP_CIPHER \
wincng_##name = { \
0, \
block_size, \
key_len, \
iv_len, \
flags, \
wincng_key_init, \
wincng_do_cipher, \
wincng_cleanup, \
0, \
NULL, \
NULL, \
NULL, \
NULL \
}; \
\
const EVP_CIPHER * \
hc_EVP_wincng_##name(void) \
{ \
wincng_cipher_algorithm_init(&wincng_##name, alg_id); \
return wincng_##name.app_data ? &wincng_##name : NULL; \
}
#define WINCNG_CIPHER_ALGORITHM_CLEANUP(name) do { \
if (wincng_##name.app_data) { \
BCryptCloseAlgorithmProvider(wincng_##name.app_data, 0); \
wincng_##name.app_data = NULL; \
} \
} while (0)
#define WINCNG_CIPHER_ALGORITHM_UNAVAILABLE(name) \
\
const EVP_CIPHER * \
hc_EVP_wincng_##name(void) \
{ \
return NULL; \
}
/**
* The triple DES cipher type (Windows CNG provider)
*
* @return the DES-EDE3-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(des_ede3_cbc,
BCRYPT_3DES_ALGORITHM,
8,
24,
8,
EVP_CIPH_CBC_MODE);
/**
* The DES cipher type (Windows CNG provider)
*
* @return the DES-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(des_cbc,
BCRYPT_DES_ALGORITHM,
8,
8,
8,
EVP_CIPH_CBC_MODE);
/**
* The AES-128 cipher type (Windows CNG provider)
*
* @return the AES-128-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_128_cbc,
BCRYPT_AES_ALGORITHM,
16,
16,
16,
EVP_CIPH_CBC_MODE);
/**
* The AES-192 cipher type (Windows CNG provider)
*
* @return the AES-192-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_192_cbc,
BCRYPT_AES_ALGORITHM,
16,
24,
16,
EVP_CIPH_CBC_MODE);
/**
* The AES-256 cipher type (Windows CNG provider)
*
* @return the AES-256-CBC EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_256_cbc,
BCRYPT_AES_ALGORITHM,
16,
32,
16,
EVP_CIPH_CBC_MODE);
/**
* The AES-128 CFB8 cipher type (Windows CNG provider)
*
* @return the AES-128-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_128_cfb8,
BCRYPT_AES_ALGORITHM,
16,
16,
16,
EVP_CIPH_CFB8_MODE);
/**
* The AES-192 CFB8 cipher type (Windows CNG provider)
*
* @return the AES-192-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_192_cfb8,
BCRYPT_AES_ALGORITHM,
16,
24,
16,
EVP_CIPH_CFB8_MODE);
/**
* The AES-256 CFB8 cipher type (Windows CNG provider)
*
* @return the AES-256-CFB8 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(aes_256_cfb8,
BCRYPT_AES_ALGORITHM,
16,
32,
16,
EVP_CIPH_CFB8_MODE);
/**
* The RC2 cipher type - Windows CNG
*
* @return the RC2 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(rc2_cbc,
BCRYPT_RC2_ALGORITHM,
8,
16,
8,
EVP_CIPH_CBC_MODE);
/**
* The RC2-40 cipher type - Windows CNG
*
* @return the RC2-40 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(rc2_40_cbc,
BCRYPT_RC2_ALGORITHM,
8,
5,
8,
EVP_CIPH_CBC_MODE);
/**
* The RC2-64 cipher type - Windows CNG
*
* @return the RC2-64 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(rc2_64_cbc,
BCRYPT_RC2_ALGORITHM,
8,
8,
8,
EVP_CIPH_CBC_MODE);
/**
* The Camellia-128 cipher type - CommonCrypto
*
* @return the Camellia-128 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM_UNAVAILABLE(camellia_128_cbc);
/**
* The Camellia-198 cipher type - CommonCrypto
*
* @return the Camellia-198 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM_UNAVAILABLE(camellia_192_cbc);
/**
* The Camellia-256 cipher type - CommonCrypto
*
* @return the Camellia-256 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM_UNAVAILABLE(camellia_256_cbc);
/**
* The RC4 cipher type (Windows CNG provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(rc4,
BCRYPT_RC4_ALGORITHM,
1,
16,
0,
EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH);
/**
* The RC4-40 cipher type (Windows CNG provider)
*
* @return the RC4 EVP_CIPHER pointer.
*
* @ingroup hcrypto_evp
*/
WINCNG_CIPHER_ALGORITHM(rc4_40,
BCRYPT_RC4_ALGORITHM,
1,
5,
0,
EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH);
static void
wincng_cipher_algorithm_cleanup(void)
{
WINCNG_CIPHER_ALGORITHM_CLEANUP(des_ede3_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(des_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_128_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_192_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_256_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_128_cfb8);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_192_cfb8);
WINCNG_CIPHER_ALGORITHM_CLEANUP(aes_256_cfb8);
WINCNG_CIPHER_ALGORITHM_CLEANUP(rc2_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(rc2_40_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(rc2_64_cbc);
WINCNG_CIPHER_ALGORITHM_CLEANUP(rc4);
WINCNG_CIPHER_ALGORITHM_CLEANUP(rc4_40);
}
/*
* CNG digest provider
*/
struct wincng_md_ctx {
BCRYPT_HASH_HANDLE hHash;
ULONG cbHashObject;
UCHAR rgbHashObject[1];
};
static BCRYPT_ALG_HANDLE
wincng_md_algorithm_init(EVP_MD *md,
LPCWSTR pszAlgId)
{
BCRYPT_ALG_HANDLE hAlgorithm;
NTSTATUS status;
ULONG cbHashObject, cbData;
ULONG cbHash = 0, cbBlock = 0;
status = BCryptOpenAlgorithmProvider(&hAlgorithm,
pszAlgId,
NULL,
0);
if (!BCRYPT_SUCCESS(status))
return NULL;
status = BCryptGetProperty(hAlgorithm,
BCRYPT_HASH_LENGTH,
(PUCHAR)&cbHash,
sizeof(ULONG),
&cbData,
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return NULL;
}
status = BCryptGetProperty(hAlgorithm,
BCRYPT_HASH_BLOCK_LENGTH,
(PUCHAR)&cbBlock,
sizeof(ULONG),
&cbData,
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return NULL;
}
status = BCryptGetProperty(hAlgorithm,
BCRYPT_OBJECT_LENGTH,
(PUCHAR)&cbHashObject,
sizeof(ULONG),
&cbData,
0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlgorithm, 0);
return NULL;
}
md->hash_size = cbHash;
md->block_size = cbBlock;
md->ctx_size = sizeof(struct wincng_md_ctx) + cbHashObject - 1;
return hAlgorithm;
}
static int
wincng_md_cleanup(EVP_MD_CTX *ctx);
static int
wincng_md_hash_init(BCRYPT_ALG_HANDLE hAlgorithm,
EVP_MD_CTX *ctx)
{
struct wincng_md_ctx *cng = (struct wincng_md_ctx *)ctx;
NTSTATUS status;
ULONG cbData, dwFlags = 0;
if (IsWindows8OrGreaterCached()) {
if (cng->hHash)
return 1;
else
dwFlags |= BCRYPT_HASH_REUSABLE_FLAG;
} else
wincng_md_cleanup(ctx);
status = BCryptGetProperty(hAlgorithm,
BCRYPT_OBJECT_LENGTH,
(PUCHAR)&cng->cbHashObject,
sizeof(ULONG),
&cbData,
0);
if (!BCRYPT_SUCCESS(status))
return 0;
status = BCryptCreateHash(hAlgorithm,
&cng->hHash,
cng->rgbHashObject,
cng->cbHashObject,
NULL,
0,
dwFlags);
return BCRYPT_SUCCESS(status);
}
static int
wincng_md_update(EVP_MD_CTX *ctx,
const void *data,
size_t length)
{
struct wincng_md_ctx *cng = (struct wincng_md_ctx *)ctx;
NTSTATUS status;
status = BCryptHashData(cng->hHash, (PUCHAR)data, length, 0);
return BCRYPT_SUCCESS(status);
}
static int
wincng_md_final(void *digest,
EVP_MD_CTX *ctx)
{
struct wincng_md_ctx *cng = (struct wincng_md_ctx *)ctx;
NTSTATUS status;
ULONG cbHash, cbData;
status = BCryptGetProperty(cng->hHash,
BCRYPT_HASH_LENGTH,
(PUCHAR)&cbHash,
sizeof(DWORD),
&cbData,
0);
if (!BCRYPT_SUCCESS(status))
return 0;
status = BCryptFinishHash(cng->hHash,
digest,
cbHash,
0);
return BCRYPT_SUCCESS(status);
}
static int
wincng_md_cleanup(EVP_MD_CTX *ctx)
{
struct wincng_md_ctx *cng = (struct wincng_md_ctx *)ctx;
if (cng->hHash) {
BCryptDestroyHash(cng->hHash);
cng->hHash = (BCRYPT_HASH_HANDLE)0;
}
SecureZeroMemory(cng->rgbHashObject, cng->cbHashObject);
return 1;
}
#define WINCNG_MD_ALGORITHM(name, alg_id) \
\
static BCRYPT_ALG_HANDLE wincng_hAlgorithm_##name; \
\
static int wincng_##name##_init(EVP_MD_CTX *ctx) \
{ \
return wincng_md_hash_init(wincng_hAlgorithm_##name, ctx); \
} \
\
const EVP_MD * \
hc_EVP_wincng_##name(void) \
{ \
static struct hc_evp_md name = { \
0, \
0, \
0, \
wincng_##name##_init, \
wincng_md_update, \
wincng_md_final, \
wincng_md_cleanup \
}; \
\
if (wincng_hAlgorithm_##name == NULL) { \
BCRYPT_ALG_HANDLE hAlgorithm = \
wincng_md_algorithm_init(&name, alg_id); \
InterlockedCompareExchangePointerRelease( \
&wincng_hAlgorithm_##name, hAlgorithm, NULL); \
} \
return wincng_hAlgorithm_##name ? &name : NULL; \
}
#define WINCNG_MD_ALGORITHM_CLEANUP(name) do { \
if (wincng_hAlgorithm_##name) { \
BCryptCloseAlgorithmProvider(wincng_hAlgorithm_##name, 0); \
wincng_hAlgorithm_##name = NULL; \
} \
} while (0)
WINCNG_MD_ALGORITHM(md4, BCRYPT_MD4_ALGORITHM);
WINCNG_MD_ALGORITHM(md5, BCRYPT_MD5_ALGORITHM);
WINCNG_MD_ALGORITHM(sha1, BCRYPT_SHA1_ALGORITHM);
WINCNG_MD_ALGORITHM(sha256, BCRYPT_SHA256_ALGORITHM);
WINCNG_MD_ALGORITHM(sha384, BCRYPT_SHA384_ALGORITHM);
WINCNG_MD_ALGORITHM(sha512, BCRYPT_SHA512_ALGORITHM);
static void
wincng_md_algorithm_cleanup(void)
{
WINCNG_MD_ALGORITHM_CLEANUP(md4);
WINCNG_MD_ALGORITHM_CLEANUP(md5);
WINCNG_MD_ALGORITHM_CLEANUP(sha1);
WINCNG_MD_ALGORITHM_CLEANUP(sha256);
WINCNG_MD_ALGORITHM_CLEANUP(sha384);
WINCNG_MD_ALGORITHM_CLEANUP(sha512);
}
void _hc_wincng_cleanup(void)
{
wincng_md_algorithm_cleanup();
wincng_cipher_algorithm_cleanup();
}

View File

@@ -1,95 +0,0 @@
/*
* Copyright (c) 2015, 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_WINCNG_H
#define HEIM_EVP_WINCNG_H 1
/* symbol renaming */
#define EVP_wincng_md4() EVP_wincng_md4()
#define EVP_wincng_md5() EVP_wincng_md5()
#define EVP_wincng_sha1() EVP_wincng_sha1()
#define EVP_wincng_sha256() EVP_wincng_sha256()
#define EVP_wincng_sha384() EVP_wincng_sha384()
#define EVP_wincng_sha512() EVP_wincng_sha512()
#define EVP_wincng_des_cbc() EVP_wincng_des_cbc()
#define EVP_wincng_des_ede3_cbc() EVP_wincng_des_ede3_cbc()
#define EVP_wincng_aes_128_cbc() EVP_wincng_aes_128_cbc()
#define EVP_wincng_aes_192_cbc() EVP_wincng_aes_192_cbc()
#define EVP_wincng_aes_256_cbc() EVP_wincng_aes_256_cbc()
#define EVP_wincng_aes_128_cfb8() EVP_wincng_aes_128_cfb8()
#define EVP_wincng_aes_192_cfb8() EVP_wincng_aes_192_cfb8()
#define EVP_wincng_aes_256_cfb8() EVP_wincng_aes_256_cfb8()
#define EVP_wincng_rc4() EVP_wincng_rc4()
#define EVP_wincng_rc4_40() EVP_wincng_rc4_40()
#define EVP_wincng_rc2_40_cbc() EVP_wincng_rc2_40_cbc()
#define EVP_wincng_rc2_64_cbc() EVP_wincng_rc2_64_cbc()
#define EVP_wincng_rc2_cbc() EVP_wincng_rc2_cbc()
#define EVP_wincng_camellia_128_cbc() EVP_wincng_camellia_128_cbc()
#define EVP_wincng_camellia_192_cbc() EVP_wincng_camellia_192_cbc()
#define EVP_wincng_camellia_256_cbc() EVP_wincng_camellia_256_cbc()
/*
*
*/
HC_CPP_BEGIN
const EVP_MD * hc_EVP_wincng_md4(void);
const EVP_MD * hc_EVP_wincng_md5(void);
const EVP_MD * hc_EVP_wincng_sha1(void);
const EVP_MD * hc_EVP_wincng_sha256(void);
const EVP_MD * hc_EVP_wincng_sha384(void);
const EVP_MD * hc_EVP_wincng_sha512(void);
const EVP_CIPHER * hc_EVP_wincng_rc2_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_rc2_40_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_rc2_64_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_rc4(void);
const EVP_CIPHER * hc_EVP_wincng_rc4_40(void);
const EVP_CIPHER * hc_EVP_wincng_des_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_des_ede3_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_aes_128_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_aes_192_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_aes_256_cbc(void);
const EVP_CIPHER * hc_EVP_wincng_aes_128_cfb8(void);
const EVP_CIPHER * hc_EVP_wincng_aes_192_cfb8(void);
const EVP_CIPHER * hc_EVP_wincng_aes_256_cfb8(void);
void _hc_wincng_cleanup(void);
HC_CPP_END
#endif /* HEIM_EVP_WINCNG_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,359 +0,0 @@
/*
* Copyright (c) 2005 - 2016 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_EVP_H
#define HEIM_EVP_H 1
#include <hcrypto/engine.h>
/* symbol renaming */
#define EVP_CIPHER_CTX_block_size hc_EVP_CIPHER_CTX_block_size
#define EVP_CIPHER_CTX_cipher hc_EVP_CIPHER_CTX_cipher
#define EVP_CIPHER_CTX_cleanup hc_EVP_CIPHER_CTX_cleanup
#define EVP_CIPHER_CTX_flags hc_EVP_CIPHER_CTX_flags
#define EVP_CIPHER_CTX_get_app_data hc_EVP_CIPHER_CTX_get_app_data
#define EVP_CIPHER_CTX_init hc_EVP_CIPHER_CTX_init
#define EVP_CIPHER_CTX_iv_length hc_EVP_CIPHER_CTX_iv_length
#define EVP_CIPHER_CTX_key_length hc_EVP_CIPHER_CTX_key_length
#define EVP_CIPHER_CTX_mode hc_EVP_CIPHER_CTX_mode
#define EVP_CIPHER_CTX_set_app_data hc_EVP_CIPHER_CTX_set_app_data
#define EVP_CIPHER_CTX_set_key_length hc_EVP_CIPHER_CTX_set_key_length
#define EVP_CIPHER_CTX_set_padding hc_EVP_CIPHER_CTX_set_padding
#define EVP_CIPHER_block_size hc_EVP_CIPHER_block_size
#define EVP_CIPHER_iv_length hc_EVP_CIPHER_iv_length
#define EVP_CIPHER_key_length hc_EVP_CIPHER_key_length
#define EVP_Cipher hc_EVP_Cipher
#define EVP_CipherInit_ex hc_EVP_CipherInit_ex
#define EVP_CipherUpdate hc_EVP_CipherUpdate
#define EVP_CipherFinal_ex hc_EVP_CipherFinal_ex
#define EVP_Digest hc_EVP_Digest
#define EVP_DigestFinal_ex hc_EVP_DigestFinal_ex
#define EVP_DigestInit_ex hc_EVP_DigestInit_ex
#define EVP_DigestUpdate hc_EVP_DigestUpdate
#define EVP_MD_CTX_block_size hc_EVP_MD_CTX_block_size
#define EVP_MD_CTX_cleanup hc_EVP_MD_CTX_cleanup
#define EVP_MD_CTX_create hc_EVP_MD_CTX_create
#define EVP_MD_CTX_init hc_EVP_MD_CTX_init
#define EVP_MD_CTX_destroy hc_EVP_MD_CTX_destroy
#define EVP_MD_CTX_md hc_EVP_MD_CTX_md
#define EVP_MD_CTX_size hc_EVP_MD_CTX_size
#define EVP_MD_block_size hc_EVP_MD_block_size
#define EVP_MD_size hc_EVP_MD_size
#define EVP_aes_128_cbc hc_EVP_aes_128_cbc
#define EVP_aes_192_cbc hc_EVP_aes_192_cbc
#define EVP_aes_256_cbc hc_EVP_aes_256_cbc
#define EVP_aes_128_cfb8 hc_EVP_aes_128_cfb8
#define EVP_aes_192_cfb8 hc_EVP_aes_192_cfb8
#define EVP_aes_256_cfb8 hc_EVP_aes_256_cfb8
#define EVP_des_cbc hc_EVP_des_cbc
#define EVP_des_ede3_cbc hc_EVP_des_ede3_cbc
#define EVP_enc_null hc_EVP_enc_null
#define EVP_md4 hc_EVP_md4
#define EVP_md5 hc_EVP_md5
#define EVP_md_null hc_EVP_md_null
#define EVP_rc2_40_cbc hc_EVP_rc2_40_cbc
#define EVP_rc2_64_cbc hc_EVP_rc2_64_cbc
#define EVP_rc2_cbc hc_EVP_rc2_cbc
#define EVP_rc4 hc_EVP_rc4
#define EVP_rc4_40 hc_EVP_rc4_40
#define EVP_camellia_128_cbc hc_EVP_camellia_128_cbc
#define EVP_camellia_192_cbc hc_EVP_camellia_192_cbc
#define EVP_camellia_256_cbc hc_EVP_camellia_256_cbc
#define EVP_sha hc_EVP_sha
#define EVP_sha1 hc_EVP_sha1
#define EVP_sha256 hc_EVP_sha256
#define EVP_sha384 hc_EVP_sha384
#define EVP_sha512 hc_EVP_sha512
#define PKCS5_PBKDF2_HMAC hc_PKCS5_PBKDF2_HMAC
#define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1
#define EVP_BytesToKey hc_EVP_BytesToKey
#define EVP_get_cipherbyname hc_EVP_get_cipherbyname
#define OpenSSL_add_all_algorithms hc_OpenSSL_add_all_algorithms
#define OpenSSL_add_all_algorithms_conf hc_OpenSSL_add_all_algorithms_conf
#define OpenSSL_add_all_algorithms_noconf hc_OpenSSL_add_all_algorithms_noconf
#define EVP_CIPHER_CTX_ctrl hc_EVP_CIPHER_CTX_ctrl
#define EVP_CIPHER_CTX_rand_key hc_EVP_CIPHER_CTX_rand_key
#define hcrypto_validate hc_hcrypto_validate
/* Type name renaming */
#define EVP_MD_CTX hc_EVP_MD_CTX
#define EVP_PKEY hc_EVP_PKEY
#define EVP_MD hc_EVP_MD
#define EVP_CIPHER hc_EVP_CIPHER
#define EVP_CIPHER_CTX hc_EVP_CIPHER_CTX
/* Constant renaming */
#define EVP_CIPH_STREAM_CIPHER hc_EVP_CIPH_STREAM_CIPHER
#define EVP_CIPH_CBC_MODE hc_EVP_CIPH_CBC_MODE
#define EVP_CIPH_CFB8_MODE hc_EVP_CIPH_CFB8_MODE
#define EVP_CIPH_MODE hc_EVP_CIPH_MODE
#define EVP_CIPH_CTRL_INIT hc_EVP_CIPH_CTRL_INIT
#define EVP_CIPH_VARIABLE_LENGTH hc_EVP_CIPH_VARIABLE_LENGTH
#define EVP_CIPH_ALWAYS_CALL_INIT hc_EVP_CIPH_ALWAYS_CALL_INIT
#define EVP_CIPH_RAND_KEY hc_EVP_CIPH_RAND_KEY
#define EVP_CTRL_INIT hc_EVP_CTRL_INIT
/*
*
*/
typedef struct hc_EVP_MD_CTX EVP_MD_CTX;
typedef struct hc_evp_pkey EVP_PKEY;
typedef struct hc_evp_md EVP_MD;
typedef struct hc_CIPHER EVP_CIPHER;
typedef struct hc_CIPHER_CTX EVP_CIPHER_CTX;
#define EVP_MAX_IV_LENGTH 16
#define EVP_MAX_BLOCK_LENGTH 32
#define EVP_MAX_MD_SIZE 64
struct hc_CIPHER {
int nid;
int block_size;
int key_len;
int iv_len;
unsigned long flags;
/* The lowest 3 bits is used as integer field for the mode the
* cipher is used in (use EVP_CIPHER.._mode() to extract the
* mode). The rest of the flag field is a bitfield.
*/
#define hc_EVP_CIPH_STREAM_CIPHER 0
#define hc_EVP_CIPH_CBC_MODE 2
#define hc_EVP_CIPH_CFB8_MODE 4
#define hc_EVP_CIPH_MODE 0x7
#define hc_EVP_CIPH_CTRL_INIT 0x40
#define hc_EVP_CTRL_INIT 0x0
#define hc_EVP_CIPH_VARIABLE_LENGTH 0x008 /* variable key length */
#define hc_EVP_CIPH_ALWAYS_CALL_INIT 0x020 /* backend maintains own cipherstate */
#define hc_EVP_CIPH_RAND_KEY 0x200
int (*init)(EVP_CIPHER_CTX*,const unsigned char*,const unsigned char*,int);
int (*do_cipher)(EVP_CIPHER_CTX *, unsigned char *,
const unsigned char *, unsigned int);
int (*cleanup)(EVP_CIPHER_CTX *);
int ctx_size;
int (*set_asn1_parameters)(void);
int (*get_asn1_parameters)(void);
int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr);
#define EVP_CTRL_RAND_KEY 0x6
void *app_data;
};
struct hc_CIPHER_CTX {
const EVP_CIPHER *cipher;
ENGINE *engine;
int encrypt;
int buf_len; /* bytes stored in buf for EVP_CipherUpdate */
unsigned char oiv[EVP_MAX_IV_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
int num;
void *app_data;
int key_len;
unsigned long flags;
void *cipher_data;
int final_used;
unsigned block_mask;
unsigned char final[EVP_MAX_BLOCK_LENGTH];
};
/*
* LIES. It's not an EVP_MD_CTX that gets passed to these functions
* here in hcrypto, but an object of ctx_size.
*/
typedef int (*hc_evp_md_init)(EVP_MD_CTX *);
typedef int (*hc_evp_md_update)(EVP_MD_CTX *,const void *, size_t);
typedef int (*hc_evp_md_final)(void *, EVP_MD_CTX *);
typedef int (*hc_evp_md_cleanup)(EVP_MD_CTX *);
struct hc_evp_md {
int hash_size;
int block_size;
int ctx_size;
hc_evp_md_init init;
hc_evp_md_update update;
hc_evp_md_final final;
hc_evp_md_cleanup cleanup;
};
#if !defined(__GNUC__) && !defined(__attribute__)
#define __attribute__(x)
#endif
#ifndef HC_DEPRECATED
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
#define HC_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER) && (_MSC_VER>1200)
#define HC_DEPRECATED __declspec(deprecated)
#else
#define HC_DEPRECATED
#endif
#endif
#ifndef HC_DEPRECATED_CRYPTO
#define HC_DEPRECATED_CRYPTO HC_DEPRECATED
#endif
#ifdef __cplusplus
#define HC_CPP_BEGIN extern "C" {
#define HC_CPP_END }
#else
#define HC_CPP_BEGIN
#define HC_CPP_END
#endif
HC_CPP_BEGIN
/*
* Avaible crypto algs
*/
const EVP_MD *EVP_md_null(void);
HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md4(void);
HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md5(void);
const EVP_MD *EVP_sha(void);
const EVP_MD *EVP_sha1(void);
const EVP_MD *EVP_sha256(void);
const EVP_MD *EVP_sha384(void);
const EVP_MD *EVP_sha512(void);
const EVP_CIPHER * EVP_aes_128_cbc(void);
const EVP_CIPHER * EVP_aes_192_cbc(void);
const EVP_CIPHER * EVP_aes_256_cbc(void);
const EVP_CIPHER * EVP_aes_128_cfb8(void);
const EVP_CIPHER * EVP_aes_192_cfb8(void);
const EVP_CIPHER * EVP_aes_256_cfb8(void);
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_des_cbc(void);
const EVP_CIPHER * EVP_des_ede3_cbc(void);
const EVP_CIPHER * EVP_enc_null(void);
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_40_cbc(void);
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_64_cbc(void);
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_cbc(void);
const EVP_CIPHER * EVP_rc4(void);
HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc4_40(void);
const EVP_CIPHER * EVP_camellia_128_cbc(void);
const EVP_CIPHER * EVP_camellia_192_cbc(void);
const EVP_CIPHER * EVP_camellia_256_cbc(void);
size_t EVP_MD_size(const EVP_MD *);
size_t EVP_MD_block_size(const EVP_MD *);
const EVP_MD *
EVP_MD_CTX_md(EVP_MD_CTX *);
size_t EVP_MD_CTX_size(EVP_MD_CTX *);
size_t EVP_MD_CTX_block_size(EVP_MD_CTX *);
EVP_MD_CTX *
EVP_MD_CTX_create(void);
void HC_DEPRECATED EVP_MD_CTX_init(EVP_MD_CTX *);
void EVP_MD_CTX_destroy(EVP_MD_CTX *);
int HC_DEPRECATED EVP_MD_CTX_cleanup(EVP_MD_CTX *);
int EVP_DigestInit_ex(EVP_MD_CTX *, const EVP_MD *, ENGINE *);
int EVP_DigestUpdate(EVP_MD_CTX *,const void *, size_t);
int EVP_DigestFinal_ex(EVP_MD_CTX *, void *, unsigned int *);
int EVP_Digest(const void *, size_t, void *, unsigned int *,
const EVP_MD *, ENGINE *);
/*
*
*/
const EVP_CIPHER *
EVP_get_cipherbyname(const char *);
size_t EVP_CIPHER_block_size(const EVP_CIPHER *);
size_t EVP_CIPHER_key_length(const EVP_CIPHER *);
size_t EVP_CIPHER_iv_length(const EVP_CIPHER *);
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *);
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *, int);
int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int);
unsigned long
EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *);
int EVP_CIPHER_CTX_mode(const EVP_CIPHER_CTX *);
const EVP_CIPHER *
EVP_CIPHER_CTX_cipher(EVP_CIPHER_CTX *);
size_t EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *);
size_t EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *);
size_t EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *);
void * EVP_CIPHER_CTX_get_app_data(EVP_CIPHER_CTX *);
void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *, void *);
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *, int, int, void *);
int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *, void *);
int EVP_CipherInit_ex(EVP_CIPHER_CTX *,const EVP_CIPHER *, ENGINE *,
const void *, const void *, int);
int EVP_CipherUpdate(EVP_CIPHER_CTX *, void *, int *, void *, size_t);
int EVP_CipherFinal_ex(EVP_CIPHER_CTX *, void *, int *);
int EVP_Cipher(EVP_CIPHER_CTX *,void *,const void *,size_t);
int PKCS5_PBKDF2_HMAC(const void *, size_t, const void *, size_t,
unsigned long, const EVP_MD *, size_t, void *);
int PKCS5_PBKDF2_HMAC_SHA1(const void *, size_t, const void *, size_t,
unsigned long, size_t, void *);
int EVP_BytesToKey(const EVP_CIPHER *, const EVP_MD *,
const void *, const void *, size_t,
unsigned int, void *, void *);
/*
*
*/
void OpenSSL_add_all_algorithms(void);
void OpenSSL_add_all_algorithms_conf(void);
void OpenSSL_add_all_algorithms_noconf(void);
void
hcrypto_validate(void);
HC_CPP_END
#endif /* HEIM_EVP_H */

View File

@@ -1,165 +0,0 @@
/*
* Copyright (c) 2008 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <krb5-types.h> /* should really be stdint.h */
#include <hcrypto/evp.h>
#include <hcrypto/evp-pkcs11.h>
#ifdef __APPLE__
#include <hcrypto/evp-cc.h>
#endif
#ifdef _WIN32
#include <hcrypto/evp-w32.h>
#endif
#include <err.h>
#include <assert.h>
/* key and initial vector */
static char key[16] =
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4"
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4";
static char ivec[16] =
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4"
"\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4";
static void
usage(int exit_code) __attribute__((noreturn));
static void
usage(int exit_code)
{
printf("usage: %s in out [pkcs11 | cc | w32]\n", getprogname());
exit(exit_code);
}
int
main(int argc, char **argv)
{
int encryptp = 1;
const char *ifn = NULL, *ofn = NULL;
FILE *in, *out;
void *ibuf, *obuf;
int ilen, olen;
size_t block_size = 0;
const EVP_CIPHER *c = EVP_aes_128_cbc();
EVP_CIPHER_CTX ctx;
int ret;
setprogname(argv[0]);
if (argc == 2) {
if (strcmp(argv[1], "--version") == 0) {
printf("version");
exit(0);
}
if (strcmp(argv[1], "--help") == 0)
usage(0);
usage(1);
} else if (argc == 4 || argc == 5) {
block_size = atoi(argv[1]);
if (block_size == 0)
errx(1, "invalid blocksize %s", argv[1]);
ifn = argv[2];
ofn = argv[3];
if (argc == 5) {
if (strcmp(argv[4], "pkcs11") == 0)
c = hc_EVP_pkcs11_aes_128_cbc();
#ifdef __APPLE__
else if (strcmp(argv[4], "cc") == 0)
c = hc_EVP_cc_aes_128_cbc();
#endif
#ifdef _WIN32
else if (strcmp(argv[4], "w32") == 0)
c = hc_EVP_w32crypto_aes_128_cbc();
#endif
else
usage(1);
}
} else
usage(1);
in = fopen(ifn, "r");
if (in == NULL)
errx(1, "failed to open input file");
out = fopen(ofn, "w+");
if (out == NULL)
errx(1, "failed to open output file");
/* Check that key and ivec are long enough */
assert(EVP_CIPHER_key_length(c) <= sizeof(key));
assert(EVP_CIPHER_iv_length(c) <= sizeof(ivec));
/*
* Allocate buffer, the output buffer is at least
* EVP_CIPHER_block_size() longer
*/
ibuf = malloc(block_size);
obuf = malloc(block_size + EVP_CIPHER_block_size(c));
/*
* Init the memory used for EVP_CIPHER_CTX and set the key and
* ivec.
*/
EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit_ex(&ctx, c, NULL, key, ivec, encryptp);
/* read in buffer */
while ((ilen = fread(ibuf, 1, block_size, in)) > 0) {
/* encrypto/decrypt */
ret = EVP_CipherUpdate(&ctx, obuf, &olen, ibuf, ilen);
if (ret != 1) {
EVP_CIPHER_CTX_cleanup(&ctx);
errx(1, "EVP_CipherUpdate failed");
}
/* write out to output file */
fwrite(obuf, 1, olen, out);
}
/* done reading */
fclose(in);
/* clear up any last bytes left in the output buffer */
ret = EVP_CipherFinal_ex(&ctx, obuf, &olen);
EVP_CIPHER_CTX_cleanup(&ctx);
if (ret != 1)
errx(1, "EVP_CipherFinal_ex failed");
/* write the last bytes out and close */
fwrite(obuf, 1, olen, out);
fclose(out);
return 0;
}

View File

@@ -1,217 +0,0 @@
#!/usr/pkg/bin/perl
#
# $Id$
use strict;
print "/* GENERATE FILE from gen-des.pl, do not edit */\n\n";
my $gen = 1;
sub gen_pattern
{
my $n = shift;
my $r = shift;
my $a = shift;
my $o = shift;
my $s = shift;
print "/* $n bit pattern ";
foreach my $k (@$a) {
print "$k ";
}
print "*/\n";
print "static int $n\[", $r + 1, "\] = {\n ";
foreach my $i (0..$r) {
my $j = 0;
my $b = 1;
foreach my $k (reverse @$a) {
if ($i & $b) {
$j |= ($s >>($k - $o - 1));
}
$b = $b << 1;
}
printf "0x%08x", $j;
print ", " if ($i != $r);
if (($i % 4) == 3) {
print "\n";
print " " if ($i != $r);
}
}
print "};\n";
}
if ($gen) {
gen_pattern("pc1_c_3", 7, [ 5, 13, 21 ], 0, 0x1000000);
gen_pattern("pc1_c_4", 15, [ 1, 9, 17, 25 ], 0, 0x1000000);
gen_pattern("pc1_d_3", 7, [ 49, 41, 33 ], 32, 0x1000000);
gen_pattern("pc1_d_4", 15, [ 57, 53, 45, 37 ], 32, 0x1000000);
gen_pattern("pc2_c_1", 63, [ 5, 24, 7, 16, 6, 10 ], 0, 0x800000);
gen_pattern("pc2_c_2", 63, [ 20, 18, 12, 3, 15, 23 ], 0, 0x800000);
gen_pattern("pc2_c_3", 63, [ 1, 9, 19, 2, 14, 22 ], 0, 0x800000);
gen_pattern("pc2_c_4", 63, [ 11, 13, 4, 17, 21, 8 ], 0, 0x800000);
gen_pattern("pc2_d_1", 63, [ 51, 35, 31, 52, 39, 45 ], 28, 0x800000);
gen_pattern("pc2_d_2", 63, [ 50, 32, 43, 36, 29, 48 ], 28, 0x800000);
gen_pattern("pc2_d_3", 63, [ 41, 38, 47, 33, 40, 42 ], 28, 0x800000);
gen_pattern("pc2_d_4", 63, [ 49, 37, 30, 46, 34, 44 ], 28, 0x800000);
}
sub
pbox_mutation
{
my $n = shift;
my $res = 0;
my @pbox = (
16, 7, 20, 21,
29, 12, 28, 17,
1, 15, 23, 26,
5, 18, 31, 10,
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25
);
foreach my $i (0..31) {
if ($n & (1 << ($pbox[$i] - 1))) {
# print "$i ", ($pbox[$i] - 1), "\n";
$res |= 1 << $i;
}
}
return $res;
}
my @S1 = (
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
);
my @S2 = (
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
);
my @S3 = (
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
);
my @S4 = (
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
);
my @S5 = (
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
);
my @S6 = (
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
);
my @S7 = (
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
);
my @S8 = (
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11,
);
my @SBox = ( \@S1, \@S2, \@S3, \@S4, \@S5, \@S6, \@S7, \@S8 );
sub
one_num_in_one_sbox
{
my $i = shift;
my $n = shift;
my $r = shift;
my $index = (($n & 1) << 4) | (($n & 0x20)) |
(($n >> 1) & 0x1) << 0 |
(($n >> 2) & 0x1) << 1 |
(($n >> 3) & 0x1) << 2 |
(($n >> 4) & 0x1) << 3;
die "argh" if ($index > 63 || $index < 0);
my $S = $SBox[$i - 1];
my $val = $$S[$index];
my $res = $val << (($i - 1) * 4);
my $p = &pbox_mutation($res);
print " $r ";
# $p = ($p >> $r) | ($p << (32 - $r - 1));
printf "0x%08x", $p;
print ", " if ($n != 63 or 1);
if (($n % 4) == 3) {
print " /* $i */" if ($n == 3);
print "\n";
print "\t" if ($n != 63);
}
}
sub
one_sbox
{
my $i = shift;
my $s = 0;
# print "static uint32_t sbox". $i ."[] = {\n\t";
print "\t";
foreach my $n (0..63) {
one_num_in_one_sbox($i, $n, $s);
}
print "\n";
# print "};\n";
}
if ($gen and 0) {
foreach my $sbox (7, 1, 3, 5, 4, 6, 8, 2) {
one_sbox($sbox, 1);
}
}
#my $num = 1;
#printf "pbox: %d -> 0x%08x\n", $num, pbox_mutation($num);
#$num = 0xc000000;
#printf "pbox: 0x%08x -> 0x%08x\n", $num, pbox_mutation($num);
print "static unsigned char odd_parity[256] = { \n";
foreach my $i (0..255) {
my $num = 0;
foreach my $b (1..7) {
$num++ if (($i >> $b) & 1);
}
my $t;
if (($num & 1) == 0) {
$t = $i | 1;
} else {
$t = 0xfe & $i;
}
printf "%3d,", $t;
printf "\n" if (($i % 16) == 15);
};
print " };\n";

View File

@@ -1,74 +0,0 @@
/*
* Copyright (c) 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of KTH nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY KTH AND ITS 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 KTH OR ITS 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. */
/* $Id$ */
/* stuff in common between md4, md5, and sha1 */
#ifndef __hash_h__
#define __hash_h__
#ifdef KRB5
#include <krb5-types.h>
#endif
#ifndef min
#define min(a,b) (((a)>(b))?(b):(a))
#endif
/* Vector Crays doesn't have a good 32-bit type, or more precisely,
int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
want to depend in being able to redefine this type. To cope with
this we have to clamp the result in some places to [0,2^32); no
need to do this on other machines. Did I say this was a mess?
*/
#ifdef _CRAY
#define CRAYFIX(X) ((X) & 0xffffffff)
#else
#define CRAYFIX(X) (X)
#endif
static inline uint32_t
cshift (uint32_t x, unsigned int n)
{
x = CRAYFIX(x);
return CRAYFIX((x << n) | (x >> (32 - n)));
}
static inline uint64_t
cshift64 (uint64_t x, unsigned int n)
{
return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n));
}
#endif /* __hash_h__ */

View File

@@ -1,179 +0,0 @@
/*
* Copyright (c) 2006 - 2007 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
#include <config.h>
#include <roken.h>
#include <hmac.h>
void
HMAC_CTX_init(HMAC_CTX *ctx)
{
memset(ctx, 0, sizeof(*ctx));
}
void
HMAC_CTX_cleanup(HMAC_CTX *ctx)
{
if (ctx->buf) {
memset_s(ctx->buf, ctx->key_length, 0, ctx->key_length);
free(ctx->buf);
ctx->buf = NULL;
}
if (ctx->opad) {
memset_s(ctx->opad, EVP_MD_block_size(ctx->md), 0, EVP_MD_block_size(ctx->md));
free(ctx->opad);
ctx->opad = NULL;
}
if (ctx->ipad) {
memset_s(ctx->ipad, EVP_MD_block_size(ctx->md), 0, EVP_MD_block_size(ctx->md));
free(ctx->ipad);
ctx->ipad = NULL;
}
if (ctx->ctx) {
EVP_MD_CTX_destroy(ctx->ctx);
ctx->ctx = NULL;
}
}
HMAC_CTX *
HMAC_CTX_new(void)
{
return calloc(1, sizeof(HMAC_CTX));
}
void
HMAC_CTX_free(HMAC_CTX *ctx)
{
HMAC_CTX_cleanup(ctx);
free(ctx);
}
size_t
HMAC_size(const HMAC_CTX *ctx)
{
return EVP_MD_size(ctx->md);
}
int
HMAC_Init_ex(HMAC_CTX *ctx,
const void *key,
size_t keylen,
const EVP_MD *md,
ENGINE *engine)
{
unsigned char *p;
size_t i, blockSize;
blockSize = EVP_MD_block_size(md);
if (ctx->md != md) {
if (ctx->md != NULL)
HMAC_CTX_cleanup(ctx);
ctx->md = md;
ctx->key_length = EVP_MD_size(ctx->md);
ctx->opad = NULL;
ctx->ipad = NULL;
ctx->ctx = NULL;
ctx->buf = malloc(ctx->key_length);
if (ctx->buf)
ctx->opad = malloc(blockSize);
if (ctx->opad)
ctx->ipad = malloc(blockSize);
if (ctx->ipad)
ctx->ctx = EVP_MD_CTX_create();
}
/* We do this check here to quiet scan-build */
if (!ctx->buf || !ctx->opad || !ctx->ipad || !ctx->ctx)
return 0;
#if 0
ctx->engine = engine;
#endif
if (keylen > blockSize) {
if (EVP_Digest(key, keylen, ctx->buf, NULL, ctx->md, engine) == 0)
return 0;
key = ctx->buf;
keylen = EVP_MD_size(ctx->md);
}
memset(ctx->ipad, 0x36, blockSize);
memset(ctx->opad, 0x5c, blockSize);
for (i = 0, p = ctx->ipad; i < keylen; i++)
p[i] ^= ((const unsigned char *)key)[i];
for (i = 0, p = ctx->opad; i < keylen; i++)
p[i] ^= ((const unsigned char *)key)[i];
if (EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine) == 0)
return 0;
EVP_DigestUpdate(ctx->ctx, ctx->ipad, EVP_MD_block_size(ctx->md));
return 1;
}
void
HMAC_Update(HMAC_CTX *ctx, const void *data, size_t len)
{
EVP_DigestUpdate(ctx->ctx, data, len);
}
void
HMAC_Final(HMAC_CTX *ctx, void *md, unsigned int *len)
{
EVP_DigestFinal_ex(ctx->ctx, ctx->buf, NULL);
EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine);
EVP_DigestUpdate(ctx->ctx, ctx->opad, EVP_MD_block_size(ctx->md));
EVP_DigestUpdate(ctx->ctx, ctx->buf, ctx->key_length);
EVP_DigestFinal_ex(ctx->ctx, md, len);
}
void *
HMAC(const EVP_MD *md,
const void *key, size_t key_size,
const void *data, size_t data_size,
void *hash, unsigned int *hash_len)
{
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
if (HMAC_Init_ex(&ctx, key, key_size, md, NULL) == 0) {
HMAC_CTX_cleanup(&ctx);
return NULL;
}
HMAC_Update(&ctx, data, data_size);
HMAC_Final(&ctx, hash, hash_len);
HMAC_CTX_cleanup(&ctx);
return hash;
}

View File

@@ -1,86 +0,0 @@
/*
* Copyright (c) 2005 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* 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.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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.
*/
/* $Id$ */
#ifndef HEIM_HMAC_H
#define HEIM_HMAC_H 1
#include <hcrypto/evp.h>
/* symbol renaming */
#define HMAC_CTX_new hc_HMAC_CTX_new
#define HMAC_CTX_free hc_HMAC_CTX_free
#define HMAC_CTX_init hc_HMAC_CTX_init
#define HMAC_CTX_cleanup hc_HMAC_CTX_cleanup
#define HMAC_size hc_HMAC_size
#define HMAC_Init_ex hc_HMAC_Init_ex
#define HMAC_Update hc_HMAC_Update
#define HMAC_Final hc_HMAC_Final
#define HMAC hc_HMAC
/*
*
*/
#define HMAC_MAX_MD_CBLOCK 64
typedef struct hc_HMAC_CTX HMAC_CTX;
struct hc_HMAC_CTX {
const EVP_MD *md;
ENGINE *engine;
EVP_MD_CTX *ctx;
size_t key_length;
void *opad;
void *ipad;
void *buf;
};
void HMAC_CTX_init(HMAC_CTX *);
void HMAC_CTX_cleanup(HMAC_CTX *ctx);
HMAC_CTX *HMAC_CTX_new(void);
void HMAC_CTX_free(HMAC_CTX *ctx);
size_t HMAC_size(const HMAC_CTX *ctx);
int HMAC_Init_ex(HMAC_CTX *, const void *, size_t,
const EVP_MD *, ENGINE *);
void HMAC_Update(HMAC_CTX *ctx, const void *data, size_t len);
void HMAC_Final(HMAC_CTX *ctx, void *md, unsigned int *len);
void * HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
const void *data, size_t n, void *md, unsigned int *md_len);
#endif /* HEIM_HMAC_H */

View File

@@ -1,345 +0,0 @@
EXPORTS
hc_AES_cbc_encrypt
hc_AES_cfb8_encrypt
hc_AES_decrypt
hc_AES_decrypt_key
hc_BN_CTX_end
hc_BN_CTX_free
hc_BN_CTX_get
hc_BN_CTX_new
hc_BN_CTX_start
hc_AES_encrypt
hc_AES_set_encrypt_key
hc_BN_GENCB_call
hc_BN_GENCB_set
hc_BN_bin2bn
hc_BN_bn2bin
hc_BN_bn2hex
hc_BN_clear
hc_BN_clear_bit
hc_BN_clear_free
hc_BN_cmp
hc_BN_dup
hc_BN_free
hc_BN_get_word
hc_BN_hex2bn
hc_BN_is_bit_set
hc_BN_is_negative
hc_BN_new
hc_BN_num_bits
hc_BN_num_bytes
hc_BN_rand
hc_BN_set_bit
hc_BN_set_negative
hc_BN_set_word
hc_BN_uadd
hc_DES_cbc_cksum
hc_DES_cbc_encrypt
hc_DES_cfb64_encrypt
hc_DES_check_key_parity
hc_DES_ecb3_encrypt
hc_DES_ecb_encrypt
hc_DES_ede3_cbc_encrypt
hc_DES_encrypt
hc_DES_generate_random_block
hc_DES_init_random_number_generator
hc_DES_is_weak_key
hc_DES_key_sched
;! hc_DES_mem_rand8
hc_DES_new_random_key
hc_DES_pcbc_encrypt
hc_DES_rand_data
hc_DES_rand_data_key
hc_DES_random_key
hc_DES_read_password
hc_DES_set_key
hc_DES_set_key_checked
hc_DES_set_key_unchecked
hc_DES_set_odd_parity
hc_DES_set_random_generator_seed
hc_DES_set_sequence_number
hc_DES_string_to_key
hc_DH_check_pubkey
hc_DH_compute_key
hc_DH_free
hc_DH_generate_key
hc_DH_generate_parameters_ex
hc_DH_get_default_method
hc_DH_get_ex_data
hc_DH_ltm_method
;! hc_DH_gmp_method
hc_DH_new
hc_DH_new_method
hc_DH_null_method
hc_DH_set_default_method
hc_DH_set_ex_data
hc_DH_set_method
hc_DH_size
hc_DH_up_ref
hc_DSA_free
hc_DSA_get_default_method
hc_DSA_new
hc_DSA_null_method
hc_DSA_set_default_method
hc_DSA_up_ref
hc_DSA_verify
hc_ENGINE_add_conf_module
hc_ENGINE_by_dso
hc_ENGINE_by_id
hc_ENGINE_finish
hc_ENGINE_free
hc_ENGINE_get_DH
hc_ENGINE_get_RAND
hc_ENGINE_get_RSA
hc_ENGINE_get_default_DH
hc_ENGINE_get_default_RSA
hc_ENGINE_get_id
hc_ENGINE_get_name
hc_ENGINE_load_builtin_engines
hc_ENGINE_new
hc_ENGINE_set_DH
hc_ENGINE_set_RSA
hc_ENGINE_set_default_DH
hc_ENGINE_set_default_RSA
hc_ENGINE_set_destroy_function
hc_ENGINE_set_id
hc_ENGINE_set_name
hc_ENGINE_up_ref
hc_EVP_BytesToKey
hc_EVP_CIPHER_CTX_block_size
hc_EVP_CIPHER_CTX_cipher
hc_EVP_CIPHER_CTX_cleanup
hc_EVP_CIPHER_CTX_flags
hc_EVP_CIPHER_CTX_get_app_data
hc_EVP_CIPHER_CTX_init
hc_EVP_CIPHER_CTX_iv_length
hc_EVP_CIPHER_CTX_key_length
hc_EVP_CIPHER_CTX_mode
hc_EVP_CIPHER_CTX_set_app_data
hc_EVP_CIPHER_block_size
hc_EVP_CIPHER_iv_length
hc_EVP_CIPHER_key_length
hc_EVP_Cipher
hc_EVP_CipherInit_ex
hc_EVP_Digest
hc_EVP_DigestFinal_ex
hc_EVP_DigestInit_ex
hc_EVP_DigestUpdate
hc_EVP_MD_CTX_block_size
hc_EVP_MD_CTX_cleanup
hc_EVP_MD_CTX_create
hc_EVP_MD_CTX_destroy
hc_EVP_MD_CTX_init
hc_EVP_MD_CTX_md
hc_EVP_MD_CTX_size
hc_EVP_MD_block_size
hc_EVP_MD_size
hc_EVP_aes_128_cbc
hc_EVP_aes_128_cfb8
hc_EVP_aes_192_cbc
hc_EVP_aes_192_cfb8
hc_EVP_aes_256_cbc
hc_EVP_aes_256_cfb8
hc_EVP_des_cbc
hc_EVP_des_ede3_cbc
hc_EVP_camellia_128_cbc
hc_EVP_camellia_192_cbc
hc_EVP_camellia_256_cbc
hc_EVP_enc_null
hc_EVP_get_cipherbyname
hc_EVP_md4
hc_EVP_md5
hc_EVP_md_null
hc_EVP_rc2_40_cbc
hc_EVP_rc2_64_cbc
hc_EVP_rc2_cbc
hc_EVP_rc4
hc_EVP_rc4_40
hc_EVP_sha
hc_EVP_sha1
hc_EVP_sha256
hc_EVP_sha384
hc_EVP_sha512
;! hc_EVP_cc_md4
;! hc_EVP_cc_md5
;! hc_EVP_cc_sha1
;! hc_EVP_cc_sha256
;! hc_EVP_cc_sha384
;! hc_EVP_cc_sha512
;! hc_EVP_cc_des_ede3_cbc
;! hc_EVP_cc_aes_128_cbc
;! hc_EVP_cc_aes_192_cbc
;! hc_EVP_cc_aes_256_cbc
;! hc_EVP_cc_aes_128_cfb8
;! hc_EVP_cc_aes_192_cfb8
;! hc_EVP_cc_aes_256_cfb8
hc_EVP_ossl_md4
hc_EVP_ossl_md5
hc_EVP_ossl_sha1
hc_EVP_ossl_sha256
hc_EVP_ossl_sha384
hc_EVP_ossl_sha512
hc_EVP_ossl_des_ede3_cbc
hc_EVP_ossl_aes_128_cbc
hc_EVP_ossl_aes_192_cbc
hc_EVP_ossl_aes_256_cbc
hc_EVP_ossl_aes_128_cfb8
hc_EVP_ossl_aes_192_cfb8
hc_EVP_ossl_aes_256_cfb8
hc_EVP_ossl_rc2_cbc
hc_EVP_ossl_rc2_40_cbc
hc_EVP_ossl_rc4
hc_EVP_ossl_rc4_40
hc_EVP_pkcs11_md4
hc_EVP_pkcs11_md5
hc_EVP_pkcs11_sha1
hc_EVP_pkcs11_sha256
hc_EVP_pkcs11_des_ede3_cbc
hc_EVP_pkcs11_aes_128_cbc
hc_EVP_pkcs11_aes_192_cbc
hc_EVP_pkcs11_aes_256_cbc
hc_EVP_pkcs11_aes_128_cfb8
hc_EVP_pkcs11_aes_192_cfb8
hc_EVP_pkcs11_aes_256_cfb8
hc_EVP_pkcs11_rc2_40_cbc
hc_EVP_pkcs11_rc2_64_cbc
hc_EVP_pkcs11_rc2_cbc
hc_EVP_pkcs11_rc4
hc_EVP_pkcs11_rc4_40
hc_EVP_w32crypto_md4 ;!
hc_EVP_w32crypto_md5 ;!
hc_EVP_w32crypto_sha1 ;!
hc_EVP_w32crypto_sha256 ;!
hc_EVP_w32crypto_sha384 ;!
hc_EVP_w32crypto_sha512 ;!
hc_EVP_w32crypto_des_ede3_cbc ;!
hc_EVP_w32crypto_aes_128_cbc ;!
hc_EVP_w32crypto_aes_192_cbc ;!
hc_EVP_w32crypto_aes_256_cbc ;!
hc_EVP_w32crypto_rc2_40_cbc ;!
hc_EVP_w32crypto_rc2_cbc ;!
hc_EVP_w32crypto_rc4 ;!
hc_EVP_w32crypto_rc4_40 ;!
hc_EVP_w32crypto_aes_128_cfb8 ;!
hc_EVP_w32crypto_aes_192_cfb8 ;!
hc_EVP_w32crypto_aes_256_cfb8 ;!
hc_EVP_hcrypto_md4
hc_EVP_hcrypto_md5
hc_EVP_hcrypto_sha1
hc_EVP_hcrypto_sha256
hc_EVP_hcrypto_sha384
hc_EVP_hcrypto_sha512
hc_EVP_hcrypto_des_ede3_cbc
hc_EVP_hcrypto_aes_128_cbc
hc_EVP_hcrypto_aes_192_cbc
hc_EVP_hcrypto_aes_256_cbc
hc_EVP_hcrypto_rc4
hc_EVP_hcrypto_rc4_40
hc_EVP_hcrypto_aes_128_cfb8
hc_EVP_hcrypto_aes_192_cfb8
hc_EVP_hcrypto_aes_256_cfb8
;! hc_EVP_hcrypto_aes_128_cts
;! hc_EVP_hcrypto_aes_192_cts
;! hc_EVP_hcrypto_aes_256_cts
hc_HMAC
hc_HMAC_CTX_cleanup
hc_HMAC_CTX_init
hc_HMAC_CTX_free
hc_HMAC_CTX_new
hc_HMAC_Final
hc_HMAC_Init_ex
hc_HMAC_Update
hc_HMAC_size
hc_MD4_Final
hc_MD4_Init
hc_MD4_Update
hc_MD5_Final
hc_MD5_Init
hc_MD5_Update
hc_OpenSSL_add_all_algorithms
hc_OpenSSL_add_all_algorithms_conf
hc_OpenSSL_add_all_algorithms_noconf
hc_PKCS12_key_gen
hc_PKCS5_PBKDF2_HMAC
hc_PKCS5_PBKDF2_HMAC_SHA1
hc_RAND_add
hc_RAND_bytes
hc_RAND_cleanup
hc_RAND_file_name
;! hc_RAND_fortuna_method
hc_RAND_get_rand_method
hc_RAND_load_file
hc_RAND_pseudo_bytes
hc_RAND_seed
hc_RAND_set_rand_engine
hc_RAND_set_rand_method
hc_RAND_status
;! hc_RAND_unix_method
;! hc_RAND_timer_method
hc_RAND_w32crypto_method ;!
hc_RAND_write_file
hc_RC2_cbc_encrypt
hc_RC2_decryptc
hc_RC2_encryptc
hc_RC2_set_key
hc_RC4
hc_RC4_set_key
hc_RSA_check_key
hc_RSA_free
hc_RSA_generate_key_ex
hc_RSA_get_app_data
hc_RSA_get_default_method
hc_RSA_get_method
hc_RSA_new
hc_RSA_new_method
hc_RSA_null_method
hc_RSA_private_decrypt
hc_RSA_private_encrypt
hc_RSA_public_decrypt
hc_RSA_public_encrypt
hc_RSA_set_app_data
hc_RSA_set_default_method
hc_RSA_set_method
hc_RSA_sign
hc_RSA_size
hc_RSA_up_ref
hc_RSA_verify
hc_SHA1_Final
hc_SHA1_Init
hc_SHA1_Update
hc_SHA256_Final
hc_SHA256_Init
hc_SHA256_Update
hc_SHA384_Final
hc_SHA384_Init
hc_SHA384_Update
hc_SHA512_Final
hc_SHA512_Init
hc_SHA512_Update
hc_UI_UTIL_read_pw_string
hc_i2d_DHparams
hc_d2i_RSAPrivateKey
hc_i2d_RSAPrivateKey
hc_i2d_RSAPublicKey
hc_d2i_RSAPublicKey
hc_EVP_CIPHER_CTX_ctrl
hc_EVP_CIPHER_CTX_rand_key
hc_EVP_CIPHER_CTX_set_key_length
hc_EVP_hcrypto_rc2_cbc
hc_EVP_hcrypto_rc2_40_cbc
hc_EVP_hcrypto_camellia_128_cbc
hc_EVP_CipherUpdate
hc_EVP_CipherFinal_ex
hc_hcrypto_validate
hc_hcrypto_scalarmult_curve25519
hc_hcrypto_scalarmult_curve25519_base

View File

@@ -1,26 +0,0 @@
The LibTom license
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View File

@@ -1,203 +0,0 @@
########################################################################
#
# 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\libtommath
!include ../../../windows/NTMakefile.w32
INCFILES= \
$(INCDIR)\tommath.h \
$(INCDIR)\tommath_class.h \
$(INCDIR)\tommath_superclass.h
libltm_OBJs= \
$(OBJ)\bn_cutoffs.obj \
$(OBJ)\bn_deprecated.obj \
$(OBJ)\bn_mp_2expt.obj \
$(OBJ)\bn_mp_abs.obj \
$(OBJ)\bn_mp_add.obj \
$(OBJ)\bn_mp_add_d.obj \
$(OBJ)\bn_mp_addmod.obj \
$(OBJ)\bn_mp_and.obj \
$(OBJ)\bn_mp_clamp.obj \
$(OBJ)\bn_mp_clear.obj \
$(OBJ)\bn_mp_clear_multi.obj \
$(OBJ)\bn_mp_cmp.obj \
$(OBJ)\bn_mp_cmp_d.obj \
$(OBJ)\bn_mp_cmp_mag.obj \
$(OBJ)\bn_mp_cnt_lsb.obj \
$(OBJ)\bn_mp_complement.obj \
$(OBJ)\bn_mp_copy.obj \
$(OBJ)\bn_mp_count_bits.obj \
$(OBJ)\bn_mp_decr.obj \
$(OBJ)\bn_mp_div.obj \
$(OBJ)\bn_mp_div_2.obj \
$(OBJ)\bn_mp_div_2d.obj \
$(OBJ)\bn_mp_div_3.obj \
$(OBJ)\bn_mp_div_d.obj \
$(OBJ)\bn_mp_dr_is_modulus.obj \
$(OBJ)\bn_mp_dr_reduce.obj \
$(OBJ)\bn_mp_dr_setup.obj \
$(OBJ)\bn_mp_error_to_string.obj\
$(OBJ)\bn_mp_exch.obj \
$(OBJ)\bn_mp_expt_u32.obj \
$(OBJ)\bn_mp_exptmod.obj \
$(OBJ)\bn_mp_exteuclid.obj \
$(OBJ)\bn_mp_fread.obj \
$(OBJ)\bn_mp_from_sbin.obj \
$(OBJ)\bn_mp_from_ubin.obj \
$(OBJ)\bn_mp_fwrite.obj \
$(OBJ)\bn_mp_gcd.obj \
$(OBJ)\bn_mp_get_double.obj \
$(OBJ)\bn_mp_get_i32.obj \
$(OBJ)\bn_mp_get_i64.obj \
$(OBJ)\bn_mp_get_l.obj \
$(OBJ)\bn_mp_get_ll.obj \
$(OBJ)\bn_mp_get_mag_u32.obj \
$(OBJ)\bn_mp_get_mag_u64.obj \
$(OBJ)\bn_mp_get_mag_ul.obj \
$(OBJ)\bn_mp_get_mag_ull.obj \
$(OBJ)\bn_mp_grow.obj \
$(OBJ)\bn_mp_incr.obj \
$(OBJ)\bn_mp_init.obj \
$(OBJ)\bn_mp_init_copy.obj \
$(OBJ)\bn_mp_init_i32.obj \
$(OBJ)\bn_mp_init_i64.obj \
$(OBJ)\bn_mp_init_l.obj \
$(OBJ)\bn_mp_init_ll.obj \
$(OBJ)\bn_mp_init_multi.obj \
$(OBJ)\bn_mp_init_set.obj \
$(OBJ)\bn_mp_init_size.obj \
$(OBJ)\bn_mp_init_u32.obj \
$(OBJ)\bn_mp_init_u64.obj \
$(OBJ)\bn_mp_init_ul.obj \
$(OBJ)\bn_mp_init_ull.obj \
$(OBJ)\bn_mp_invmod.obj \
$(OBJ)\bn_mp_is_square.obj \
$(OBJ)\bn_mp_iseven.obj \
$(OBJ)\bn_mp_isodd.obj \
$(OBJ)\bn_mp_kronecker.obj \
$(OBJ)\bn_mp_lcm.obj \
$(OBJ)\bn_mp_log_u32.obj \
$(OBJ)\bn_mp_lshd.obj \
$(OBJ)\bn_mp_mod.obj \
$(OBJ)\bn_mp_mod_2d.obj \
$(OBJ)\bn_mp_mod_d.obj \
$(OBJ)\bn_mp_montgomery_calc_normalization.obj \
$(OBJ)\bn_mp_montgomery_reduce.obj \
$(OBJ)\bn_mp_montgomery_setup.obj \
$(OBJ)\bn_mp_mul.obj \
$(OBJ)\bn_mp_mul_2.obj \
$(OBJ)\bn_mp_mul_2d.obj \
$(OBJ)\bn_mp_mul_d.obj \
$(OBJ)\bn_mp_mulmod.obj \
$(OBJ)\bn_mp_neg.obj \
$(OBJ)\bn_mp_or.obj \
$(OBJ)\bn_mp_pack.obj \
$(OBJ)\bn_mp_pack_count.obj \
$(OBJ)\bn_mp_prime_fermat.obj \
$(OBJ)\bn_mp_prime_frobenius_underwood.obj \
$(OBJ)\bn_mp_prime_is_prime.obj \
$(OBJ)\bn_mp_prime_miller_rabin.obj \
$(OBJ)\bn_mp_prime_next_prime.obj \
$(OBJ)\bn_mp_prime_rabin_miller_trials.obj \
$(OBJ)\bn_mp_prime_rand.obj \
$(OBJ)\bn_mp_prime_strong_lucas_selfridge.obj \
$(OBJ)\bn_mp_radix_size.obj \
$(OBJ)\bn_mp_radix_smap.obj \
$(OBJ)\bn_mp_rand.obj \
$(OBJ)\bn_mp_read_radix.obj \
$(OBJ)\bn_mp_reduce.obj \
$(OBJ)\bn_mp_reduce_2k.obj \
$(OBJ)\bn_mp_reduce_2k_l.obj \
$(OBJ)\bn_mp_reduce_2k_setup.obj \
$(OBJ)\bn_mp_reduce_2k_setup_l.obj \
$(OBJ)\bn_mp_reduce_is_2k.obj \
$(OBJ)\bn_mp_reduce_is_2k_l.obj \
$(OBJ)\bn_mp_reduce_setup.obj \
$(OBJ)\bn_mp_root_u32.obj \
$(OBJ)\bn_mp_rshd.obj \
$(OBJ)\bn_mp_sbin_size.obj \
$(OBJ)\bn_mp_set.obj \
$(OBJ)\bn_mp_set_double.obj \
$(OBJ)\bn_mp_set_i32.obj \
$(OBJ)\bn_mp_set_i64.obj \
$(OBJ)\bn_mp_set_l.obj \
$(OBJ)\bn_mp_set_ll.obj \
$(OBJ)\bn_mp_set_u32.obj \
$(OBJ)\bn_mp_set_u64.obj \
$(OBJ)\bn_mp_set_ul.obj \
$(OBJ)\bn_mp_set_ull.obj \
$(OBJ)\bn_mp_shrink.obj \
$(OBJ)\bn_mp_signed_rsh.obj \
$(OBJ)\bn_mp_sqr.obj \
$(OBJ)\bn_mp_sqrmod.obj \
$(OBJ)\bn_mp_sqrt.obj \
$(OBJ)\bn_mp_sqrtmod_prime.obj \
$(OBJ)\bn_mp_sub.obj \
$(OBJ)\bn_mp_sub_d.obj \
$(OBJ)\bn_mp_submod.obj \
$(OBJ)\bn_mp_to_radix.obj \
$(OBJ)\bn_mp_to_sbin.obj \
$(OBJ)\bn_mp_to_ubin.obj \
$(OBJ)\bn_mp_ubin_size.obj \
$(OBJ)\bn_mp_unpack.obj \
$(OBJ)\bn_mp_xor.obj \
$(OBJ)\bn_mp_zero.obj \
$(OBJ)\bn_prime_tab.obj \
$(OBJ)\bn_s_mp_add.obj \
$(OBJ)\bn_s_mp_balance_mul.obj \
$(OBJ)\bn_s_mp_exptmod.obj \
$(OBJ)\bn_s_mp_exptmod_fast.obj \
$(OBJ)\bn_s_mp_get_bit.obj \
$(OBJ)\bn_s_mp_invmod_fast.obj \
$(OBJ)\bn_s_mp_invmod_slow.obj \
$(OBJ)\bn_s_mp_karatsuba_mul.obj\
$(OBJ)\bn_s_mp_karatsuba_sqr.obj\
$(OBJ)\bn_s_mp_montgomery_reduce_fast.obj \
$(OBJ)\bn_s_mp_mul_digs.obj \
$(OBJ)\bn_s_mp_mul_digs_fast.obj\
$(OBJ)\bn_s_mp_mul_high_digs.obj\
$(OBJ)\bn_s_mp_mul_high_digs_fast.obj \
$(OBJ)\bn_s_mp_prime_is_divisible.obj \
$(OBJ)\bn_s_mp_rand_jenkins.obj \
$(OBJ)\bn_s_mp_rand_platform.obj\
$(OBJ)\bn_s_mp_reverse.obj \
$(OBJ)\bn_s_mp_sqr.obj \
$(OBJ)\bn_s_mp_sqr_fast.obj \
$(OBJ)\bn_s_mp_sub.obj \
$(OBJ)\bn_s_mp_toom_mul.obj \
$(OBJ)\bn_s_mp_toom_sqr.obj
$(LIBLTM): $(libltm_OBJs)
$(LIBCON)
all:: $(INCFILES) $(LIBLTM)

Some files were not shown because too many files have changed in this diff Show More