This commit was manufactured by cvs2svn to create branch 'BRANCH_engine'.
This commit is contained in:
commit
7dfded5c26
12
apps/dh2048.pem
Normal file
12
apps/dh2048.pem
Normal file
@ -0,0 +1,12 @@
|
||||
-----BEGIN DH PARAMETERS-----
|
||||
MIIBCAKCAQEA9kJXtwh/CBdyorrWqULzBej5UxE5T7bxbrlLOCDaAadWoxTpj0BV
|
||||
89AHxstDqZSt90xkhkn4DIO9ZekX1KHTUPj1WV/cdlJPPT2N286Z4VeSWc39uK50
|
||||
T8X8dryDxUcwYc58yWb/Ffm7/ZFexwGq01uejaClcjrUGvC/RgBYK+X0iP1YTknb
|
||||
zSC0neSRBzZrM2w4DUUdD3yIsxx8Wy2O9vPJI8BD8KVbGI2Ou1WMuF040zT9fBdX
|
||||
Q6MdGGzeMyEstSr/POGxKUAYEY18hKcKctaGxAMZyAcpesqVDNmWn6vQClCbAkbT
|
||||
CD1mpF1Bn5x8vYlLIhkmuquiXsNV6TILOwIBAg==
|
||||
-----END DH PARAMETERS-----
|
||||
|
||||
These are the 2048 bit DH parameters from "Assigned Number for SKIP Protocols"
|
||||
(http://www.skip-vpn.org/spec/numbers.html).
|
||||
See there for how they were generated.
|
18
apps/dh4096.pem
Normal file
18
apps/dh4096.pem
Normal file
@ -0,0 +1,18 @@
|
||||
-----BEGIN DH PARAMETERS-----
|
||||
MIICCAKCAgEA+hRyUsFN4VpJ1O8JLcCo/VWr19k3BCgJ4uk+d+KhehjdRqNDNyOQ
|
||||
l/MOyQNQfWXPeGKmOmIig6Ev/nm6Nf9Z2B1h3R4hExf+zTiHnvVPeRBhjdQi81rt
|
||||
Xeoh6TNrSBIKIHfUJWBh3va0TxxjQIs6IZOLeVNRLMqzeylWqMf49HsIXqbcokUS
|
||||
Vt1BkvLdW48j8PPv5DsKRN3tloTxqDJGo9tKvj1Fuk74A+Xda1kNhB7KFlqMyN98
|
||||
VETEJ6c7KpfOo30mnK30wqw3S8OtaIR/maYX72tGOno2ehFDkq3pnPtEbD2CScxc
|
||||
alJC+EL7RPk5c/tgeTvCngvc1KZn92Y//EI7G9tPZtylj2b56sHtMftIoYJ9+ODM
|
||||
sccD5Piz/rejE3Ome8EOOceUSCYAhXn8b3qvxVI1ddd1pED6FHRhFvLrZxFvBEM9
|
||||
ERRMp5QqOaHJkM+Dxv8Cj6MqrCbfC4u+ZErxodzuusgDgvZiLF22uxMZbobFWyte
|
||||
OvOzKGtwcTqO/1wV5gKkzu1ZVswVUQd5Gg8lJicwqRWyyNRczDDoG9jVDxmogKTH
|
||||
AaqLulO7R8Ifa1SwF2DteSGVtgWEN8gDpN3RBmmPTDngyF2DHb5qmpnznwtFKdTL
|
||||
KWbuHn491xNO25CQWMtem80uKw+pTnisBRF/454n1Jnhub144YRBoN8CAQI=
|
||||
-----END DH PARAMETERS-----
|
||||
|
||||
These are the 4096 bit DH parameters from "Assigned Number for SKIP Protocols"
|
||||
(http://www.skip-vpn.org/spec/numbers.html).
|
||||
See there for how they were generated.
|
||||
Note that g is not a generator, but this is not a problem since p is a safe prime.
|
9
apps/dh512.pem
Normal file
9
apps/dh512.pem
Normal file
@ -0,0 +1,9 @@
|
||||
-----BEGIN DH PARAMETERS-----
|
||||
MEYCQQD1Kv884bEpQBgRjXyEpwpy1obEAxnIByl6ypUM2Zafq9AKUJsCRtMIPWak
|
||||
XUGfnHy9iUsiGSa6q6Jew1XpKgVfAgEC
|
||||
-----END DH PARAMETERS-----
|
||||
|
||||
These are the 512 bit DH parameters from "Assigned Number for SKIP Protocols"
|
||||
(http://www.skip-vpn.org/spec/numbers.html).
|
||||
See there for how they were generated.
|
||||
Note that g is not a generator, but this is not a problem since p is a safe prime.
|
281
apps/rsautl.c
Normal file
281
apps/rsautl.c
Normal file
@ -0,0 +1,281 @@
|
||||
/* rsautl.c */
|
||||
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2000 The OpenSSL Project. 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. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* licensing@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
#include "apps.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/pem.h>
|
||||
|
||||
#define RSA_SIGN 1
|
||||
#define RSA_VERIFY 2
|
||||
#define RSA_ENCRYPT 3
|
||||
#define RSA_DECRYPT 4
|
||||
|
||||
#define KEY_PRIVKEY 1
|
||||
#define KEY_PUBKEY 2
|
||||
#define KEY_CERT 3
|
||||
|
||||
static void usage(void);
|
||||
|
||||
#undef PROG
|
||||
|
||||
#define PROG rsautl_main
|
||||
|
||||
int MAIN(int argc, char **);
|
||||
|
||||
int MAIN(int argc, char **argv)
|
||||
{
|
||||
BIO *in = NULL, *out = NULL;
|
||||
char *infile = NULL, *outfile = NULL;
|
||||
char *keyfile = NULL;
|
||||
char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY;
|
||||
int keyform = FORMAT_PEM;
|
||||
char need_priv = 0, badarg = 0, rev = 0;
|
||||
char hexdump = 0, asn1parse = 0;
|
||||
X509 *x;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
RSA *rsa = NULL;
|
||||
unsigned char *rsa_in = NULL, *rsa_out = NULL, pad;
|
||||
int rsa_inlen, rsa_outlen = 0;
|
||||
int keysize;
|
||||
|
||||
int ret = 1;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
|
||||
ERR_load_crypto_strings();
|
||||
OpenSSL_add_all_algorithms();
|
||||
pad = RSA_PKCS1_PADDING;
|
||||
|
||||
while(argc >= 1)
|
||||
{
|
||||
if (!strcmp(*argv,"-in")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
infile= *(++argv);
|
||||
} else if (!strcmp(*argv,"-out")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
outfile= *(++argv);
|
||||
} else if(!strcmp(*argv, "-inkey")) {
|
||||
if (--argc < 1) badarg = 1;
|
||||
keyfile = *(++argv);
|
||||
} else if(!strcmp(*argv, "-pubin")) {
|
||||
key_type = KEY_PUBKEY;
|
||||
} else if(!strcmp(*argv, "-certin")) {
|
||||
key_type = KEY_CERT;
|
||||
}
|
||||
else if(!strcmp(*argv, "-asn1parse")) asn1parse = 1;
|
||||
else if(!strcmp(*argv, "-hexdump")) hexdump = 1;
|
||||
else if(!strcmp(*argv, "-raw")) pad = RSA_NO_PADDING;
|
||||
else if(!strcmp(*argv, "-oaep")) pad = RSA_PKCS1_OAEP_PADDING;
|
||||
else if(!strcmp(*argv, "-ssl")) pad = RSA_SSLV23_PADDING;
|
||||
else if(!strcmp(*argv, "-pkcs")) pad = RSA_PKCS1_PADDING;
|
||||
else if(!strcmp(*argv, "-sign")) {
|
||||
rsa_mode = RSA_SIGN;
|
||||
need_priv = 1;
|
||||
} else if(!strcmp(*argv, "-verify")) rsa_mode = RSA_VERIFY;
|
||||
else if(!strcmp(*argv, "-rev")) rev = 1;
|
||||
else if(!strcmp(*argv, "-encrypt")) rsa_mode = RSA_ENCRYPT;
|
||||
else if(!strcmp(*argv, "-decrypt")) {
|
||||
rsa_mode = RSA_DECRYPT;
|
||||
need_priv = 1;
|
||||
} else badarg = 1;
|
||||
if(badarg) {
|
||||
usage();
|
||||
goto end;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if(need_priv && (key_type != KEY_PRIVKEY)) {
|
||||
BIO_printf(bio_err, "A private key is needed for this operation\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* FIXME: seed PRNG only if needed */
|
||||
app_RAND_load_file(NULL, bio_err, 0);
|
||||
|
||||
switch(key_type) {
|
||||
case KEY_PRIVKEY:
|
||||
pkey = load_key(bio_err, keyfile, keyform, NULL);
|
||||
break;
|
||||
|
||||
case KEY_PUBKEY:
|
||||
pkey = load_pubkey(bio_err, keyfile, keyform);
|
||||
break;
|
||||
|
||||
case KEY_CERT:
|
||||
x = load_cert(bio_err, keyfile, keyform);
|
||||
if(x) {
|
||||
pkey = X509_get_pubkey(x);
|
||||
X509_free(x);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(!pkey) {
|
||||
BIO_printf(bio_err, "Error loading key\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rsa = EVP_PKEY_get1_RSA(pkey);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
if(!rsa) {
|
||||
BIO_printf(bio_err, "Error getting RSA key\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
if(infile) {
|
||||
if(!(in = BIO_new_file(infile, "rb"))) {
|
||||
BIO_printf(bio_err, "Error Reading Input File\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
} else in = BIO_new_fp(stdin, BIO_NOCLOSE);
|
||||
|
||||
if(outfile) {
|
||||
if(!(out = BIO_new_file(outfile, "wb"))) {
|
||||
BIO_printf(bio_err, "Error Reading Output File\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
} else out = BIO_new_fp(stdout, BIO_NOCLOSE);
|
||||
|
||||
keysize = RSA_size(rsa);
|
||||
|
||||
rsa_in = OPENSSL_malloc(keysize * 2);
|
||||
rsa_out = OPENSSL_malloc(keysize);
|
||||
|
||||
/* Read the input data */
|
||||
rsa_inlen = BIO_read(in, rsa_in, keysize * 2);
|
||||
if(rsa_inlen <= 0) {
|
||||
BIO_printf(bio_err, "Error reading input Data\n");
|
||||
exit(1);
|
||||
}
|
||||
if(rev) {
|
||||
int i;
|
||||
unsigned char ctmp;
|
||||
for(i = 0; i < rsa_inlen/2; i++) {
|
||||
ctmp = rsa_in[i];
|
||||
rsa_in[i] = rsa_in[rsa_inlen - 1 - i];
|
||||
rsa_in[rsa_inlen - 1 - i] = ctmp;
|
||||
}
|
||||
}
|
||||
switch(rsa_mode) {
|
||||
|
||||
case RSA_VERIFY:
|
||||
rsa_outlen = RSA_public_decrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
|
||||
break;
|
||||
|
||||
case RSA_SIGN:
|
||||
rsa_outlen = RSA_private_encrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
|
||||
break;
|
||||
|
||||
case RSA_ENCRYPT:
|
||||
rsa_outlen = RSA_public_encrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
|
||||
break;
|
||||
|
||||
case RSA_DECRYPT:
|
||||
rsa_outlen = RSA_private_decrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(rsa_outlen <= 0) {
|
||||
BIO_printf(bio_err, "RSA operation error\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto end;
|
||||
}
|
||||
ret = 0;
|
||||
if(asn1parse) {
|
||||
if(!ASN1_parse_dump(out, rsa_out, rsa_outlen, 1, -1)) {
|
||||
ERR_print_errors(bio_err);
|
||||
}
|
||||
} else if(hexdump) BIO_dump(out, (char *)rsa_out, rsa_outlen);
|
||||
else BIO_write(out, rsa_out, rsa_outlen);
|
||||
end:
|
||||
RSA_free(rsa);
|
||||
BIO_free(in);
|
||||
BIO_free(out);
|
||||
if(rsa_in) OPENSSL_free(rsa_in);
|
||||
if(rsa_out) OPENSSL_free(rsa_out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void usage()
|
||||
{
|
||||
BIO_printf(bio_err, "Usage: rsautl [options]\n");
|
||||
BIO_printf(bio_err, "-in file input file\n");
|
||||
BIO_printf(bio_err, "-out file output file\n");
|
||||
BIO_printf(bio_err, "-inkey file input key\n");
|
||||
BIO_printf(bio_err, "-pubin input is an RSA public\n");
|
||||
BIO_printf(bio_err, "-certin input is a certificate carrying an RSA public key\n");
|
||||
BIO_printf(bio_err, "-ssl use SSL v2 padding\n");
|
||||
BIO_printf(bio_err, "-raw use no padding\n");
|
||||
BIO_printf(bio_err, "-pkcs use PKCS#1 v1.5 padding (default)\n");
|
||||
BIO_printf(bio_err, "-oaep use PKCS#1 OAEP\n");
|
||||
BIO_printf(bio_err, "-sign sign with private key\n");
|
||||
BIO_printf(bio_err, "-verify verify with public key\n");
|
||||
BIO_printf(bio_err, "-encrypt encrypt with public key\n");
|
||||
BIO_printf(bio_err, "-decrypt decrypt with private key\n");
|
||||
BIO_printf(bio_err, "-hexdump hex dump output\n");
|
||||
}
|
||||
|
83
crypto/evp/m_md4.c
Normal file
83
crypto/evp/m_md4.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* crypto/evp/m_md4.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef NO_MD4
|
||||
#include <stdio.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
static EVP_MD md4_md=
|
||||
{
|
||||
NID_md4,
|
||||
0,
|
||||
MD4_DIGEST_LENGTH,
|
||||
MD4_Init,
|
||||
MD4_Update,
|
||||
MD4_Final,
|
||||
EVP_PKEY_RSA_method,
|
||||
MD4_CBLOCK,
|
||||
sizeof(EVP_MD *)+sizeof(MD4_CTX),
|
||||
};
|
||||
|
||||
EVP_MD *EVP_md4(void)
|
||||
{
|
||||
return(&md4_md);
|
||||
}
|
||||
#endif
|
2
crypto/md4/.cvsignore
Normal file
2
crypto/md4/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
||||
lib
|
||||
Makefile.save
|
84
crypto/md4/Makefile.ssl
Normal file
84
crypto/md4/Makefile.ssl
Normal file
@ -0,0 +1,84 @@
|
||||
#
|
||||
# SSLeay/crypto/md4/Makefile
|
||||
#
|
||||
|
||||
DIR= md4
|
||||
TOP= ../..
|
||||
CC= cc
|
||||
CPP= $(CC) -E
|
||||
INCLUDES=
|
||||
CFLAG=-g
|
||||
INSTALL_PREFIX=
|
||||
OPENSSLDIR= /usr/local/ssl
|
||||
INSTALLTOP=/usr/local/ssl
|
||||
MAKE= make -f Makefile.ssl
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP)
|
||||
MAKEFILE= Makefile.ssl
|
||||
AR= ar r
|
||||
|
||||
CFLAGS= $(INCLUDES) $(CFLAG)
|
||||
|
||||
GENERAL=Makefile
|
||||
TEST=md4test.c
|
||||
APPS=md4.c
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC=md4_dgst.c md4_one.c
|
||||
LIBOBJ=md4_dgst.o md4_one.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER= md4.h
|
||||
HEADER= md4_locl.h $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
top:
|
||||
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
|
||||
|
||||
all: lib
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
$(AR) $(LIB) $(LIBOBJ)
|
||||
$(RANLIB) $(LIB)
|
||||
@touch lib
|
||||
|
||||
files:
|
||||
$(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
|
||||
|
||||
links:
|
||||
@$(TOP)/util/point.sh Makefile.ssl Makefile
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
|
||||
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
|
||||
|
||||
install:
|
||||
@for i in $(EXHEADER) ; \
|
||||
do \
|
||||
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
|
||||
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
|
||||
done;
|
||||
|
||||
tags:
|
||||
ctags $(SRC)
|
||||
|
||||
tests:
|
||||
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
depend:
|
||||
$(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
|
||||
|
||||
dclean:
|
||||
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
|
||||
mv -f Makefile.new $(MAKEFILE)
|
||||
|
||||
clean:
|
||||
rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
md4_dgst.o: ../../include/openssl/md4.h ../../include/openssl/opensslconf.h
|
||||
md4_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md4_locl.h
|
||||
md4_one.o: ../../include/openssl/md4.h
|
127
crypto/md4/md4.c
Normal file
127
crypto/md4/md4.c
Normal file
@ -0,0 +1,127 @@
|
||||
/* crypto/md4/md4.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/md4.h>
|
||||
|
||||
#define BUFSIZE 1024*16
|
||||
|
||||
void do_fp(FILE *f);
|
||||
void pt(unsigned char *md);
|
||||
#ifndef _OSD_POSIX
|
||||
int read(int, void *, unsigned int);
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i,err=0;
|
||||
FILE *IN;
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
do_fp(stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
IN=fopen(argv[i],"r");
|
||||
if (IN == NULL)
|
||||
{
|
||||
perror(argv[i]);
|
||||
err++;
|
||||
continue;
|
||||
}
|
||||
printf("MD4(%s)= ",argv[i]);
|
||||
do_fp(IN);
|
||||
fclose(IN);
|
||||
}
|
||||
}
|
||||
exit(err);
|
||||
}
|
||||
|
||||
void do_fp(FILE *f)
|
||||
{
|
||||
MD4_CTX c;
|
||||
unsigned char md[MD4_DIGEST_LENGTH];
|
||||
int fd;
|
||||
int i;
|
||||
static unsigned char buf[BUFSIZE];
|
||||
|
||||
fd=fileno(f);
|
||||
MD4_Init(&c);
|
||||
for (;;)
|
||||
{
|
||||
i=read(fd,buf,BUFSIZE);
|
||||
if (i <= 0) break;
|
||||
MD4_Update(&c,buf,(unsigned long)i);
|
||||
}
|
||||
MD4_Final(&(md[0]),&c);
|
||||
pt(md);
|
||||
}
|
||||
|
||||
void pt(unsigned char *md)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<MD4_DIGEST_LENGTH; i++)
|
||||
printf("%02x",md[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
114
crypto/md4/md4.h
Normal file
114
crypto/md4/md4.h
Normal file
@ -0,0 +1,114 @@
|
||||
/* crypto/md4/md4.h */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_MD4_H
|
||||
#define HEADER_MD4_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef NO_MD4
|
||||
#error MD4 is disabled.
|
||||
#endif
|
||||
|
||||
/*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* ! MD4_LONG has to be at least 32 bits wide. If it's wider, then !
|
||||
* ! MD4_LONG_LOG2 has to be defined along. !
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
|
||||
#if defined(WIN16) || defined(__LP32__)
|
||||
#define MD4_LONG unsigned long
|
||||
#elif defined(_CRAY) || defined(__ILP64__)
|
||||
#define MD4_LONG unsigned long
|
||||
#define MD4_LONG_LOG2 3
|
||||
/*
|
||||
* _CRAY note. I could declare short, but I have no idea what impact
|
||||
* does it have on performance on none-T3E machines. I could declare
|
||||
* int, but at least on C90 sizeof(int) can be chosen at compile time.
|
||||
* So I've chosen long...
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
#else
|
||||
#define MD4_LONG unsigned int
|
||||
#endif
|
||||
|
||||
#define MD4_CBLOCK 64
|
||||
#define MD4_LBLOCK (MD4_CBLOCK/4)
|
||||
#define MD4_DIGEST_LENGTH 16
|
||||
|
||||
typedef struct MD4state_st
|
||||
{
|
||||
MD4_LONG A,B,C,D;
|
||||
MD4_LONG Nl,Nh;
|
||||
MD4_LONG data[MD4_LBLOCK];
|
||||
int num;
|
||||
} MD4_CTX;
|
||||
|
||||
void MD4_Init(MD4_CTX *c);
|
||||
void MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
|
||||
void MD4_Final(unsigned char *md, MD4_CTX *c);
|
||||
unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
|
||||
void MD4_Transform(MD4_CTX *c, const unsigned char *b);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
285
crypto/md4/md4_dgst.c
Normal file
285
crypto/md4/md4_dgst.c
Normal file
@ -0,0 +1,285 @@
|
||||
/* crypto/md4/md4_dgst.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "md4_locl.h"
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
|
||||
|
||||
/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
|
||||
*/
|
||||
|
||||
#define INIT_DATA_A (unsigned long)0x67452301L
|
||||
#define INIT_DATA_B (unsigned long)0xefcdab89L
|
||||
#define INIT_DATA_C (unsigned long)0x98badcfeL
|
||||
#define INIT_DATA_D (unsigned long)0x10325476L
|
||||
|
||||
void MD4_Init(MD4_CTX *c)
|
||||
{
|
||||
c->A=INIT_DATA_A;
|
||||
c->B=INIT_DATA_B;
|
||||
c->C=INIT_DATA_C;
|
||||
c->D=INIT_DATA_D;
|
||||
c->Nl=0;
|
||||
c->Nh=0;
|
||||
c->num=0;
|
||||
}
|
||||
|
||||
#ifndef md4_block_host_order
|
||||
void md4_block_host_order (MD4_CTX *c, const void *data, int num)
|
||||
{
|
||||
const MD4_LONG *X=data;
|
||||
register unsigned long A,B,C,D;
|
||||
/*
|
||||
* In case you wonder why A-D are declared as long and not
|
||||
* as MD4_LONG. Doing so results in slight performance
|
||||
* boost on LP64 architectures. The catch is we don't
|
||||
* really care if 32 MSBs of a 64-bit register get polluted
|
||||
* with eventual overflows as we *save* only 32 LSBs in
|
||||
* *either* case. Now declaring 'em long excuses the compiler
|
||||
* from keeping 32 MSBs zeroed resulting in 13% performance
|
||||
* improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
|
||||
* Well, to be honest it should say that this *prevents*
|
||||
* performance degradation.
|
||||
*
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
|
||||
A=c->A;
|
||||
B=c->B;
|
||||
C=c->C;
|
||||
D=c->D;
|
||||
|
||||
for (;num--;X+=HASH_LBLOCK)
|
||||
{
|
||||
/* Round 0 */
|
||||
R0(A,B,C,D,X[ 0], 3,0);
|
||||
R0(D,A,B,C,X[ 1], 7,0);
|
||||
R0(C,D,A,B,X[ 2],11,0);
|
||||
R0(B,C,D,A,X[ 3],19,0);
|
||||
R0(A,B,C,D,X[ 4], 3,0);
|
||||
R0(D,A,B,C,X[ 5], 7,0);
|
||||
R0(C,D,A,B,X[ 6],11,0);
|
||||
R0(B,C,D,A,X[ 7],19,0);
|
||||
R0(A,B,C,D,X[ 8], 3,0);
|
||||
R0(D,A,B,C,X[ 9], 7,0);
|
||||
R0(C,D,A,B,X[10],11,0);
|
||||
R0(B,C,D,A,X[11],19,0);
|
||||
R0(A,B,C,D,X[12], 3,0);
|
||||
R0(D,A,B,C,X[13], 7,0);
|
||||
R0(C,D,A,B,X[14],11,0);
|
||||
R0(B,C,D,A,X[15],19,0);
|
||||
/* Round 1 */
|
||||
R1(A,B,C,D,X[ 0], 3,0x5A827999L);
|
||||
R1(D,A,B,C,X[ 4], 5,0x5A827999L);
|
||||
R1(C,D,A,B,X[ 8], 9,0x5A827999L);
|
||||
R1(B,C,D,A,X[12],13,0x5A827999L);
|
||||
R1(A,B,C,D,X[ 1], 3,0x5A827999L);
|
||||
R1(D,A,B,C,X[ 5], 5,0x5A827999L);
|
||||
R1(C,D,A,B,X[ 9], 9,0x5A827999L);
|
||||
R1(B,C,D,A,X[13],13,0x5A827999L);
|
||||
R1(A,B,C,D,X[ 2], 3,0x5A827999L);
|
||||
R1(D,A,B,C,X[ 6], 5,0x5A827999L);
|
||||
R1(C,D,A,B,X[10], 9,0x5A827999L);
|
||||
R1(B,C,D,A,X[14],13,0x5A827999L);
|
||||
R1(A,B,C,D,X[ 3], 3,0x5A827999L);
|
||||
R1(D,A,B,C,X[ 7], 5,0x5A827999L);
|
||||
R1(C,D,A,B,X[11], 9,0x5A827999L);
|
||||
R1(B,C,D,A,X[15],13,0x5A827999L);
|
||||
/* Round 2 */
|
||||
R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
|
||||
R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
|
||||
R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
|
||||
R2(B,C,D,A,X[12],15,0x6ED9EBA1);
|
||||
R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
|
||||
R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
|
||||
R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
|
||||
R2(B,C,D,A,X[14],15,0x6ED9EBA1);
|
||||
R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
|
||||
R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
|
||||
R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
|
||||
R2(B,C,D,A,X[13],15,0x6ED9EBA1);
|
||||
R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
|
||||
R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
|
||||
R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
|
||||
R2(B,C,D,A,X[15],15,0x6ED9EBA1);
|
||||
|
||||
A = c->A += A;
|
||||
B = c->B += B;
|
||||
C = c->C += C;
|
||||
D = c->D += D;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef md4_block_data_order
|
||||
#ifdef X
|
||||
#undef X
|
||||
#endif
|
||||
void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
|
||||
{
|
||||
const unsigned char *data=data_;
|
||||
register unsigned long A,B,C,D,l;
|
||||
/*
|
||||
* In case you wonder why A-D are declared as long and not
|
||||
* as MD4_LONG. Doing so results in slight performance
|
||||
* boost on LP64 architectures. The catch is we don't
|
||||
* really care if 32 MSBs of a 64-bit register get polluted
|
||||
* with eventual overflows as we *save* only 32 LSBs in
|
||||
* *either* case. Now declaring 'em long excuses the compiler
|
||||
* from keeping 32 MSBs zeroed resulting in 13% performance
|
||||
* improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
|
||||
* Well, to be honest it should say that this *prevents*
|
||||
* performance degradation.
|
||||
*
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
#ifndef MD32_XARRAY
|
||||
/* See comment in crypto/sha/sha_locl.h for details. */
|
||||
unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
|
||||
XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
|
||||
# define X(i) XX##i
|
||||
#else
|
||||
MD4_LONG XX[MD4_LBLOCK];
|
||||
# define X(i) XX[i]
|
||||
#endif
|
||||
|
||||
A=c->A;
|
||||
B=c->B;
|
||||
C=c->C;
|
||||
D=c->D;
|
||||
|
||||
for (;num--;)
|
||||
{
|
||||
HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
|
||||
/* Round 0 */
|
||||
R0(A,B,C,D,X( 0), 3,0); HOST_c2l(data,l); X( 2)=l;
|
||||
R0(D,A,B,C,X( 1), 7,0); HOST_c2l(data,l); X( 3)=l;
|
||||
R0(C,D,A,B,X( 2),11,0); HOST_c2l(data,l); X( 4)=l;
|
||||
R0(B,C,D,A,X( 3),19,0); HOST_c2l(data,l); X( 5)=l;
|
||||
R0(A,B,C,D,X( 4), 3,0); HOST_c2l(data,l); X( 6)=l;
|
||||
R0(D,A,B,C,X( 5), 7,0); HOST_c2l(data,l); X( 7)=l;
|
||||
R0(C,D,A,B,X( 6),11,0); HOST_c2l(data,l); X( 8)=l;
|
||||
R0(B,C,D,A,X( 7),19,0); HOST_c2l(data,l); X( 9)=l;
|
||||
R0(A,B,C,D,X( 8), 3,0); HOST_c2l(data,l); X(10)=l;
|
||||
R0(D,A,B,C,X( 9), 7,0); HOST_c2l(data,l); X(11)=l;
|
||||
R0(C,D,A,B,X(10),11,0); HOST_c2l(data,l); X(12)=l;
|
||||
R0(B,C,D,A,X(11),19,0); HOST_c2l(data,l); X(13)=l;
|
||||
R0(A,B,C,D,X(12), 3,0); HOST_c2l(data,l); X(14)=l;
|
||||
R0(D,A,B,C,X(13), 7,0); HOST_c2l(data,l); X(15)=l;
|
||||
R0(C,D,A,B,X(14),11,0);
|
||||
R0(B,C,D,A,X(15),19,0);
|
||||
/* Round 1 */
|
||||
R1(A,B,C,D,X( 0), 3,0x5A827999L);
|
||||
R1(D,A,B,C,X( 4), 5,0x5A827999L);
|
||||
R1(C,D,A,B,X( 8), 9,0x5A827999L);
|
||||
R1(B,C,D,A,X(12),13,0x5A827999L);
|
||||
R1(A,B,C,D,X( 1), 3,0x5A827999L);
|
||||
R1(D,A,B,C,X( 5), 5,0x5A827999L);
|
||||
R1(C,D,A,B,X( 9), 9,0x5A827999L);
|
||||
R1(B,C,D,A,X(13),13,0x5A827999L);
|
||||
R1(A,B,C,D,X( 2), 3,0x5A827999L);
|
||||
R1(D,A,B,C,X( 6), 5,0x5A827999L);
|
||||
R1(C,D,A,B,X(10), 9,0x5A827999L);
|
||||
R1(B,C,D,A,X(14),13,0x5A827999L);
|
||||
R1(A,B,C,D,X( 3), 3,0x5A827999L);
|
||||
R1(D,A,B,C,X( 7), 5,0x5A827999L);
|
||||
R1(C,D,A,B,X(11), 9,0x5A827999L);
|
||||
R1(B,C,D,A,X(15),13,0x5A827999L);
|
||||
/* Round 2 */
|
||||
R2(A,B,C,D,X( 0), 3,0x6ED9EBA1L);
|
||||
R2(D,A,B,C,X( 8), 9,0x6ED9EBA1L);
|
||||
R2(C,D,A,B,X( 4),11,0x6ED9EBA1L);
|
||||
R2(B,C,D,A,X(12),15,0x6ED9EBA1L);
|
||||
R2(A,B,C,D,X( 2), 3,0x6ED9EBA1L);
|
||||
R2(D,A,B,C,X(10), 9,0x6ED9EBA1L);
|
||||
R2(C,D,A,B,X( 6),11,0x6ED9EBA1L);
|
||||
R2(B,C,D,A,X(14),15,0x6ED9EBA1L);
|
||||
R2(A,B,C,D,X( 1), 3,0x6ED9EBA1L);
|
||||
R2(D,A,B,C,X( 9), 9,0x6ED9EBA1L);
|
||||
R2(C,D,A,B,X( 5),11,0x6ED9EBA1L);
|
||||
R2(B,C,D,A,X(13),15,0x6ED9EBA1L);
|
||||
R2(A,B,C,D,X( 3), 3,0x6ED9EBA1L);
|
||||
R2(D,A,B,C,X(11), 9,0x6ED9EBA1L);
|
||||
R2(C,D,A,B,X( 7),11,0x6ED9EBA1L);
|
||||
R2(B,C,D,A,X(15),15,0x6ED9EBA1L);
|
||||
|
||||
A = c->A += A;
|
||||
B = c->B += B;
|
||||
C = c->C += C;
|
||||
D = c->D += D;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef undef
|
||||
int printit(unsigned long *l)
|
||||
{
|
||||
int i,ii;
|
||||
|
||||
for (i=0; i<2; i++)
|
||||
{
|
||||
for (ii=0; ii<8; ii++)
|
||||
{
|
||||
fprintf(stderr,"%08lx ",l[i*8+ii]);
|
||||
}
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
}
|
||||
#endif
|
154
crypto/md4/md4_locl.h
Normal file
154
crypto/md4/md4_locl.h
Normal file
@ -0,0 +1,154 @@
|
||||
/* crypto/md4/md4_locl.h */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
#include <openssl/md4.h>
|
||||
|
||||
#ifndef MD4_LONG_LOG2
|
||||
#define MD4_LONG_LOG2 2 /* default to 32 bits */
|
||||
#endif
|
||||
|
||||
void md4_block_host_order (MD4_CTX *c, const void *p,int num);
|
||||
void md4_block_data_order (MD4_CTX *c, const void *p,int num);
|
||||
|
||||
#if defined(__i386) || defined(_M_IX86) || defined(__INTEL__)
|
||||
/*
|
||||
* *_block_host_order is expected to handle aligned data while
|
||||
* *_block_data_order - unaligned. As algorithm and host (x86)
|
||||
* are in this case of the same "endianness" these two are
|
||||
* otherwise indistinguishable. But normally you don't want to
|
||||
* call the same function because unaligned access in places
|
||||
* where alignment is expected is usually a "Bad Thing". Indeed,
|
||||
* on RISCs you get punished with BUS ERROR signal or *severe*
|
||||
* performance degradation. Intel CPUs are in turn perfectly
|
||||
* capable of loading unaligned data without such drastic side
|
||||
* effect. Yes, they say it's slower than aligned load, but no
|
||||
* exception is generated and therefore performance degradation
|
||||
* is *incomparable* with RISCs. What we should weight here is
|
||||
* costs of unaligned access against costs of aligning data.
|
||||
* According to my measurements allowing unaligned access results
|
||||
* in ~9% performance improvement on Pentium II operating at
|
||||
* 266MHz. I won't be surprised if the difference will be higher
|
||||
* on faster systems:-)
|
||||
*
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
#define md4_block_data_order md4_block_host_order
|
||||
#endif
|
||||
|
||||
#define DATA_ORDER_IS_LITTLE_ENDIAN
|
||||
|
||||
#define HASH_LONG MD4_LONG
|
||||
#define HASH_LONG_LOG2 MD4_LONG_LOG2
|
||||
#define HASH_CTX MD4_CTX
|
||||
#define HASH_CBLOCK MD4_CBLOCK
|
||||
#define HASH_LBLOCK MD4_LBLOCK
|
||||
#define HASH_UPDATE MD4_Update
|
||||
#define HASH_TRANSFORM MD4_Transform
|
||||
#define HASH_FINAL MD4_Final
|
||||
#define HASH_MAKE_STRING(c,s) do { \
|
||||
unsigned long ll; \
|
||||
ll=(c)->A; HOST_l2c(ll,(s)); \
|
||||
ll=(c)->B; HOST_l2c(ll,(s)); \
|
||||
ll=(c)->C; HOST_l2c(ll,(s)); \
|
||||
ll=(c)->D; HOST_l2c(ll,(s)); \
|
||||
} while (0)
|
||||
#define HASH_BLOCK_HOST_ORDER md4_block_host_order
|
||||
#if !defined(L_ENDIAN) || defined(md4_block_data_order)
|
||||
#define HASH_BLOCK_DATA_ORDER md4_block_data_order
|
||||
/*
|
||||
* Little-endians (Intel and Alpha) feel better without this.
|
||||
* It looks like memcpy does better job than generic
|
||||
* md4_block_data_order on copying-n-aligning input data.
|
||||
* But frankly speaking I didn't expect such result on Alpha.
|
||||
* On the other hand I've got this with egcs-1.0.2 and if
|
||||
* program is compiled with another (better?) compiler it
|
||||
* might turn out other way around.
|
||||
*
|
||||
* <appro@fy.chalmers.se>
|
||||
*/
|
||||
#endif
|
||||
|
||||
#include "md32_common.h"
|
||||
|
||||
/*
|
||||
#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
|
||||
#define G(x,y,z) (((x) & (y)) | ((x) & ((z))) | ((y) & ((z))))
|
||||
*/
|
||||
|
||||
/* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
|
||||
* simplified to the code below. Wei attributes these optimizations
|
||||
* to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
|
||||
*/
|
||||
#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
|
||||
#define G(b,c,d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
|
||||
#define H(b,c,d) ((b) ^ (c) ^ (d))
|
||||
|
||||
#define R0(a,b,c,d,k,s,t) { \
|
||||
a+=((k)+(t)+F((b),(c),(d))); \
|
||||
a=ROTATE(a,s); };
|
||||
|
||||
#define R1(a,b,c,d,k,s,t) { \
|
||||
a+=((k)+(t)+G((b),(c),(d))); \
|
||||
a=ROTATE(a,s); };\
|
||||
|
||||
#define R2(a,b,c,d,k,s,t) { \
|
||||
a+=((k)+(t)+H((b),(c),(d))); \
|
||||
a=ROTATE(a,s); };
|
95
crypto/md4/md4_one.c
Normal file
95
crypto/md4/md4_one.c
Normal file
@ -0,0 +1,95 @@
|
||||
/* crypto/md4/md4_one.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/md4.h>
|
||||
|
||||
#ifdef CHARSET_EBCDIC
|
||||
#include <openssl/ebcdic.h>
|
||||
#endif
|
||||
|
||||
unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md)
|
||||
{
|
||||
MD4_CTX c;
|
||||
static unsigned char m[MD4_DIGEST_LENGTH];
|
||||
|
||||
if (md == NULL) md=m;
|
||||
MD4_Init(&c);
|
||||
#ifndef CHARSET_EBCDIC
|
||||
MD4_Update(&c,d,n);
|
||||
#else
|
||||
{
|
||||
char temp[1024];
|
||||
unsigned long chunk;
|
||||
|
||||
while (n > 0)
|
||||
{
|
||||
chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
|
||||
ebcdic2ascii(temp, d, chunk);
|
||||
MD4_Update(&c,temp,chunk);
|
||||
n -= chunk;
|
||||
d += chunk;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
MD4_Final(md,&c);
|
||||
memset(&c,0,sizeof(c)); /* security consideration */
|
||||
return(md);
|
||||
}
|
||||
|
78
crypto/md4/md4s.cpp
Normal file
78
crypto/md4/md4s.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// gettsc.inl
|
||||
//
|
||||
// gives access to the Pentium's (secret) cycle counter
|
||||
//
|
||||
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
|
||||
// in 1996-7 and is entered, by him, into the public domain.
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
void GetTSC(unsigned long&);
|
||||
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
|
||||
#elif defined(__GNUC__)
|
||||
inline
|
||||
void GetTSC(unsigned long& tsc)
|
||||
{
|
||||
asm volatile(".byte 15, 49\n\t"
|
||||
: "=eax" (tsc)
|
||||
:
|
||||
: "%edx", "%eax");
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
inline
|
||||
void GetTSC(unsigned long& tsc)
|
||||
{
|
||||
unsigned long a;
|
||||
__asm _emit 0fh
|
||||
__asm _emit 31h
|
||||
__asm mov a, eax;
|
||||
tsc=a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/md4.h>
|
||||
|
||||
extern "C" {
|
||||
void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
|
||||
}
|
||||
|
||||
void main(int argc,char *argv[])
|
||||
{
|
||||
unsigned char buffer[64*256];
|
||||
MD4_CTX ctx;
|
||||
unsigned long s1,s2,e1,e2;
|
||||
unsigned char k[16];
|
||||
unsigned long data[2];
|
||||
unsigned char iv[8];
|
||||
int i,num=0,numm;
|
||||
int j=0;
|
||||
|
||||
if (argc >= 2)
|
||||
num=atoi(argv[1]);
|
||||
|
||||
if (num == 0) num=16;
|
||||
if (num > 250) num=16;
|
||||
numm=num+2;
|
||||
num*=64;
|
||||
numm*=64;
|
||||
|
||||
for (j=0; j<6; j++)
|
||||
{
|
||||
for (i=0; i<10; i++) /**/
|
||||
{
|
||||
md4_block_x86(&ctx,buffer,numm);
|
||||
GetTSC(s1);
|
||||
md4_block_x86(&ctx,buffer,numm);
|
||||
GetTSC(e1);
|
||||
GetTSC(s2);
|
||||
md4_block_x86(&ctx,buffer,num);
|
||||
GetTSC(e2);
|
||||
md4_block_x86(&ctx,buffer,num);
|
||||
}
|
||||
printf("md4 (%d bytes) %d %d (%.2f)\n",num,
|
||||
e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
|
||||
}
|
||||
}
|
||||
|
131
crypto/md4/md4test.c
Normal file
131
crypto/md4/md4test.c
Normal file
@ -0,0 +1,131 @@
|
||||
/* crypto/md4/md4test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* 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 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef NO_MD4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MD4 support\n");
|
||||
return(0);
|
||||
}
|
||||
#else
|
||||
#include <openssl/md4.h>
|
||||
|
||||
static char *test[]={
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static char *ret[]={
|
||||
"31d6cfe0d16ae931b73c59d7e0c089c0",
|
||||
"bde52cb31de33e46245e05fbdbd6fb24",
|
||||
"a448017aaf21d8525fc10ae87aa6729d",
|
||||
"d9130a8164549fe818874806e1c7014b",
|
||||
"d79e1c308aa5bbcdeea8ed63df412da9",
|
||||
"043f8582f241db351ce627e153e7f0e4",
|
||||
"e33b4ddc9c38f2199c3e7b164fcc0536",
|
||||
};
|
||||
|
||||
static char *pt(unsigned char *md);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i,err=0;
|
||||
unsigned char **P,**R;
|
||||
char *p;
|
||||
|
||||
P=(unsigned char **)test;
|
||||
R=(unsigned char **)ret;
|
||||
i=1;
|
||||
while (*P != NULL)
|
||||
{
|
||||
p=pt(MD4(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
|
||||
if (strcmp(p,(char *)*R) != 0)
|
||||
{
|
||||
printf("error calculating MD4 on '%s'\n",*P);
|
||||
printf("got %s instead of %s\n",p,*R);
|
||||
err++;
|
||||
}
|
||||
else
|
||||
printf("test %d ok\n",i);
|
||||
i++;
|
||||
R++;
|
||||
P++;
|
||||
}
|
||||
exit(err);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *md)
|
||||
{
|
||||
int i;
|
||||
static char buf[80];
|
||||
|
||||
for (i=0; i<MD4_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i*2]),"%02x",md[i]);
|
||||
return(buf);
|
||||
}
|
||||
#endif
|
127
crypto/symhacks.h
Normal file
127
crypto/symhacks.h
Normal file
@ -0,0 +1,127 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. 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. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED 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 OpenSSL PROJECT 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_SYMHACKS_H
|
||||
#define HEADER_SYMHACKS_H
|
||||
|
||||
/* Hacks to solve the problem with linkers incapable of handling very long
|
||||
symbol names. In the case of VMS, the limit is 31 characters on VMS for
|
||||
VAX. */
|
||||
#ifdef VMS
|
||||
|
||||
/* Hack a long name in crypto/asn1/a_mbstr.c */
|
||||
#undef ASN1_STRING_set_default_mask_asc
|
||||
#define ASN1_STRING_set_default_mask_asc ASN1_STRING_set_def_mask_asc
|
||||
|
||||
/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */
|
||||
#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO
|
||||
#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF
|
||||
#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO
|
||||
#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF
|
||||
|
||||
/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */
|
||||
#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO
|
||||
#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECGINF
|
||||
#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO
|
||||
#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECGINF
|
||||
|
||||
/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */
|
||||
#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION
|
||||
#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION i2d_ASN1_SET_OF_ACC_DESC
|
||||
#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION
|
||||
#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION d2i_ASN1_SET_OF_ACC_DESC
|
||||
|
||||
/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */
|
||||
#undef PEM_read_NETSCAPE_CERT_SEQUENCE
|
||||
#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQ
|
||||
#undef PEM_write_NETSCAPE_CERT_SEQUENCE
|
||||
#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQ
|
||||
#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE
|
||||
#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQ
|
||||
#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE
|
||||
#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQ
|
||||
#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE
|
||||
#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQ
|
||||
|
||||
/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */
|
||||
#undef PEM_read_PKCS8_PRIV_KEY_INFO
|
||||
#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO
|
||||
#undef PEM_write_PKCS8_PRIV_KEY_INFO
|
||||
#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO
|
||||
#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO
|
||||
#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO
|
||||
#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO
|
||||
#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO
|
||||
#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO
|
||||
#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_wrt_cb_bio_P8_PRIV_KEY_INFO
|
||||
|
||||
/* Hack other PEM names */
|
||||
#undef PEM_write_bio_PKCS8PrivateKey_nid
|
||||
#define PEM_write_bio_PKCS8PrivateKey_nid PEM_write_bio_PKCS8PrivKey_nid
|
||||
|
||||
/* Hack some long X509 names */
|
||||
#undef X509_REVOKED_get_ext_by_critical
|
||||
#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
|
||||
|
||||
#endif /* defined VMS */
|
||||
|
||||
|
||||
/* Case insensiteve linking causes problems.... */
|
||||
#if defined(WIN16) || defined(VMS)
|
||||
#undef ERR_load_CRYPTO_strings
|
||||
#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* ! defined HEADER_VMS_IDHACKS_H */
|
183
doc/apps/rsautl.pod
Normal file
183
doc/apps/rsautl.pod
Normal file
@ -0,0 +1,183 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
rsautl - RSA utility
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
B<openssl> B<rsautl>
|
||||
[B<-in file>]
|
||||
[B<-out file>]
|
||||
[B<-inkey file>]
|
||||
[B<-pubin>]
|
||||
[B<-certin>]
|
||||
[B<-sign>]
|
||||
[B<-verify>]
|
||||
[B<-encrypt>]
|
||||
[B<-decrypt>]
|
||||
[B<-pkcs>]
|
||||
[B<-ssl>]
|
||||
[B<-raw>]
|
||||
[B<-hexdump>]
|
||||
[B<-asn1parse>]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
The B<rsautl> command can be used to sign, verify, encrypt and decrypt
|
||||
data using the RSA algorithm.
|
||||
|
||||
=head1 COMMAND OPTIONS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<-in filename>
|
||||
|
||||
This specifies the input filename to read data from or standard input
|
||||
if this option is not specified.
|
||||
|
||||
=item B<-out filename>
|
||||
|
||||
specifies the output filename to write to or standard output by
|
||||
default.
|
||||
|
||||
=item B<-inkey file>
|
||||
|
||||
the input key file, by default it should be an RSA private key.
|
||||
|
||||
=item B<-pubin>
|
||||
|
||||
the input file is an RSA public key.
|
||||
|
||||
=item B<-certin>
|
||||
|
||||
the input is a certificate containing an RSA public key.
|
||||
|
||||
=item B<-sign>
|
||||
|
||||
sign the input data and output the signed result. This requires
|
||||
and RSA private key.
|
||||
|
||||
=item B<-verify>
|
||||
|
||||
verify the input data and output the recovered data.
|
||||
|
||||
=item B<-encrypt>
|
||||
|
||||
encrypt the input data using an RSA public key.
|
||||
|
||||
=item B<-decrypt>
|
||||
|
||||
decrypt the input data using an RSA private key.
|
||||
|
||||
=item B<-pkcs, -oaep, -ssl, -raw>
|
||||
|
||||
the padding to use: PKCS#1 v1.5 (the default), PKCS#1 OAEP,
|
||||
special padding used in SSL v2 backwards compatible handshakes,
|
||||
or no padding, respectively.
|
||||
For signatures, only B<-pkcs> and B<-raw> can be used.
|
||||
|
||||
=item B<-hexdump>
|
||||
|
||||
hex dump the output data.
|
||||
|
||||
=item B<-asn1parse>
|
||||
|
||||
asn1parse the output data, this is useful when combined with the
|
||||
B<-verify> option.
|
||||
|
||||
=back
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
B<rsautl> because it uses the RSA algorithm directly can only be
|
||||
used to sign or verify small pieces of data.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
Sign some data using a private key:
|
||||
|
||||
openssl rsautl -sign -in file -inkey key.pem -out sig
|
||||
|
||||
Recover the signed data
|
||||
|
||||
openssl rsautl -sign -in sig -inkey key.pem
|
||||
|
||||
Examine the raw signed data:
|
||||
|
||||
openssl rsautl -sign -in file -inkey key.pem -raw -hexdump
|
||||
|
||||
0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................
|
||||
0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world
|
||||
|
||||
The PKCS#1 block formatting is evident from this. If this was done using
|
||||
encrypt and decrypt the block would have been of type 2 (the second byte)
|
||||
and random padding data visible instead of the 0xff bytes.
|
||||
|
||||
It is possible to analyse the signature of certificates using this
|
||||
utility in conjunction with B<asn1parse>. Consider the self signed
|
||||
example in certs/pca-cert.pem . Running B<asn1parse> as follows yields:
|
||||
|
||||
openssl asn1parse -in pca-cert.pem
|
||||
|
||||
0:d=0 hl=4 l= 742 cons: SEQUENCE
|
||||
4:d=1 hl=4 l= 591 cons: SEQUENCE
|
||||
8:d=2 hl=2 l= 3 cons: cont [ 0 ]
|
||||
10:d=3 hl=2 l= 1 prim: INTEGER :02
|
||||
13:d=2 hl=2 l= 1 prim: INTEGER :00
|
||||
16:d=2 hl=2 l= 13 cons: SEQUENCE
|
||||
18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
|
||||
29:d=3 hl=2 l= 0 prim: NULL
|
||||
31:d=2 hl=2 l= 92 cons: SEQUENCE
|
||||
33:d=3 hl=2 l= 11 cons: SET
|
||||
35:d=4 hl=2 l= 9 cons: SEQUENCE
|
||||
37:d=5 hl=2 l= 3 prim: OBJECT :countryName
|
||||
42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU
|
||||
....
|
||||
599:d=1 hl=2 l= 13 cons: SEQUENCE
|
||||
601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
|
||||
612:d=2 hl=2 l= 0 prim: NULL
|
||||
614:d=1 hl=3 l= 129 prim: BIT STRING
|
||||
|
||||
|
||||
The final BIT STRING contains the actual signature. It can be extracted with:
|
||||
|
||||
openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
|
||||
|
||||
The certificate public key can be extracted with:
|
||||
|
||||
openssl x509 -in test/testx509.pem -pubout -noout >pubkey.pem
|
||||
|
||||
The signature can be analysed with:
|
||||
|
||||
openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
|
||||
|
||||
0:d=0 hl=2 l= 32 cons: SEQUENCE
|
||||
2:d=1 hl=2 l= 12 cons: SEQUENCE
|
||||
4:d=2 hl=2 l= 8 prim: OBJECT :md5
|
||||
14:d=2 hl=2 l= 0 prim: NULL
|
||||
16:d=1 hl=2 l= 16 prim: OCTET STRING
|
||||
0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
|
||||
|
||||
This is the parsed version of an ASN1 DigestInfo structure. It can be seen that
|
||||
the digest used was md5. The actual part of the certificate that was signed can
|
||||
be extracted with:
|
||||
|
||||
openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
|
||||
|
||||
and its digest computed with:
|
||||
|
||||
openssl md5 -c tbs
|
||||
MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
|
||||
|
||||
which it can be seen agrees with the recovered value above.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<dgst(1)|dgst(1)>, L<rsa(1)|rsa(1)>, L<genrsa(1)|genrsa(1)>
|
65
doc/crypto/BIO_new.pod
Normal file
65
doc/crypto/BIO_new.pod
Normal file
@ -0,0 +1,65 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
BIO_new, BIO_set, BIO_free, BIO_vfree, BIO_free_all - BIO allocation and freeing functions
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
BIO * BIO_new(BIO_METHOD *type);
|
||||
int BIO_set(BIO *a,BIO_METHOD *type);
|
||||
int BIO_free(BIO *a);
|
||||
void BIO_vfree(BIO *a);
|
||||
void BIO_free_all(BIO *a);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
The BIO_new() function returns a new BIO using method B<type>.
|
||||
|
||||
BIO_set() sets the method of an already existing BIO.
|
||||
|
||||
BIO_free() frees up a single BIO, BIO_vfree() also frees up a single BIO
|
||||
but it does not return a value. Calling BIO_free() may also have some effect
|
||||
on the underlying I/O structure, for example it may close the file being
|
||||
referred to under certain circumstances. For more details see the individual
|
||||
BIO_METHOD descriptions.
|
||||
|
||||
BIO_free_all() frees up an entire BIO chain, it does not halt if an error
|
||||
occurs freeing up an individual BIO in the chain.
|
||||
|
||||
=head1 RETURN VALUES
|
||||
|
||||
BIO_new() returns a newly created BIO or NULL if the call fails.
|
||||
|
||||
BIO_set(), BIO_free() return 1 for success and 0 for failure.
|
||||
|
||||
BIO_free_all() and BIO_vfree() do not return values.
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
Some BIOs (such as memory BIOs) can be used immediately after calling
|
||||
BIO_new(). Others (such as file BIOs) need some additional initialisation,
|
||||
and frequently a utility function exists to create and initialize such BIOs.
|
||||
|
||||
If BIO_free() is called on a BIO chain it will only free one BIO resulting
|
||||
in a memory leak.
|
||||
|
||||
Calling BIO_free_all() a single BIO has the same effect as calling BIO_free()
|
||||
on it other than the discarded return value.
|
||||
|
||||
Normally the B<type> argument is supplied by a function which returns a
|
||||
pointer to a BIO_METHOD. There is a naming convention for such functions:
|
||||
a source/sink BIO is normally called BIO_s_*() and a filter BIO
|
||||
BIO_f_*();
|
||||
|
||||
=head1 EXAMPLE
|
||||
|
||||
Create a memory BIO:
|
||||
|
||||
BIO *mem = BIO_new(BIO_s_mem());
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
TBA
|
69
doc/crypto/BIO_push.pod
Normal file
69
doc/crypto/BIO_push.pod
Normal file
@ -0,0 +1,69 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
BIO_push, BIO_pop - add and remove BIOs from a chain.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
BIO * BIO_push(BIO *b,BIO *append);
|
||||
BIO * BIO_pop(BIO *b);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
The BIO_push() function appends the BIO B<append> to B<b>, it returns
|
||||
B<b>.
|
||||
|
||||
BIO_pop() removes the BIO B<b> from a chain and returns the next BIO
|
||||
in the chain, or NULL if there is no next BIO. The removed BIO then
|
||||
becomes a single BIO with no association with the original chain,
|
||||
it can thus be freed or attached to a different chain.
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
The names of these functions are perhaps a little misleading. BIO_push()
|
||||
joins two BIO chains whereas BIO_pop() deletes a single BIO from a chain,
|
||||
the deleted BIO does not need to be at the end of a chain.
|
||||
|
||||
The process of calling BIO_push() and BIO_pop() on a BIO may have additional
|
||||
consequences (a control call is made to the affected BIOs) any effects will
|
||||
be noted in the descriptions of individual BIOs.
|
||||
|
||||
=head1 EXAMPLES
|
||||
|
||||
For these examples suppose B<md1> and B<md2> are digest BIOs, B<b64> is
|
||||
a base64 BIO and B<f> is a file BIO.
|
||||
|
||||
If the call:
|
||||
|
||||
BIO_push(b64, f);
|
||||
|
||||
is made then the new chain will be B<b64-chain>. After making the calls
|
||||
|
||||
BIO_push(md2, b64);
|
||||
BIO_push(md1, md2);
|
||||
|
||||
the new chain is B<md1-md2-b64-f>. Data written to B<md1> will be digested
|
||||
by B<md1> and B<md2>, B<base64> encoded and written to B<f>.
|
||||
|
||||
It should be noted that reading causes data to pass in the reverse
|
||||
direction, that is data is read from B<f>, base64 B<decoded> and digested
|
||||
by B<md1> and B<md2>. If the call:
|
||||
|
||||
BIO_pop(md2);
|
||||
|
||||
The call will return B<b64> and the new chain will be B<md1-b64-f> data can
|
||||
be written to B<md1> as before.
|
||||
|
||||
=head1 RETURN VALUES
|
||||
|
||||
BIO_push() returns the end of the chain, B<b>.
|
||||
|
||||
BIO_pop() returns the next BIO in the chain, or NULL if there is no next
|
||||
BIO.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
TBA
|
42
doc/crypto/bio.pod
Normal file
42
doc/crypto/bio.pod
Normal file
@ -0,0 +1,42 @@
|
||||
=pod
|
||||
|
||||
=head1 NAME
|
||||
|
||||
bio - I/O abstraction
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#include <openssl/bio.h>
|
||||
|
||||
TBA
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A BIO is an I/O abstraction, it hides many of the underlying I/O
|
||||
details from an application. If an application uses a BIO for its
|
||||
I/O it can transparently handle SSL connections, unencrypted network
|
||||
connections and file I/O.
|
||||
|
||||
There are two type of BIO, a source/sink BIO and a filter BIO.
|
||||
|
||||
As its name implies a source/sink BIO is a source and/or sink of data,
|
||||
examples include a socket BIO and a file BIO.
|
||||
|
||||
A filter BIO takes data from one BIO and passes it through to
|
||||
another, or the application. The data may be left unmodified (for
|
||||
example a message digest BIO) or translated (for example an
|
||||
encryption BIO). The effect of a filter BIO may change according
|
||||
to the I/O operation it is performing: for example an encryption
|
||||
BIO will encrypt data if it is being written to and decrypt data
|
||||
if it is being read from.
|
||||
|
||||
BIOs can be joined together to form a chain (a single BIO is a chain
|
||||
with one component). A chain normally consist of one source/sink
|
||||
BIO and one or more filter BIOs. Data read from or written to the
|
||||
end BIO then traverses the chain to the end (normally a source/sink
|
||||
BIO).
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
TBA
|
78
times/x86/md4s.cpp
Normal file
78
times/x86/md4s.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// gettsc.inl
|
||||
//
|
||||
// gives access to the Pentium's (secret) cycle counter
|
||||
//
|
||||
// This software was written by Leonard Janke (janke@unixg.ubc.ca)
|
||||
// in 1996-7 and is entered, by him, into the public domain.
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
void GetTSC(unsigned long&);
|
||||
#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
|
||||
#elif defined(__GNUC__)
|
||||
inline
|
||||
void GetTSC(unsigned long& tsc)
|
||||
{
|
||||
asm volatile(".byte 15, 49\n\t"
|
||||
: "=eax" (tsc)
|
||||
:
|
||||
: "%edx", "%eax");
|
||||
}
|
||||
#elif defined(_MSC_VER)
|
||||
inline
|
||||
void GetTSC(unsigned long& tsc)
|
||||
{
|
||||
unsigned long a;
|
||||
__asm _emit 0fh
|
||||
__asm _emit 31h
|
||||
__asm mov a, eax;
|
||||
tsc=a;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/md4.h>
|
||||
|
||||
extern "C" {
|
||||
void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
|
||||
}
|
||||
|
||||
void main(int argc,char *argv[])
|
||||
{
|
||||
unsigned char buffer[64*256];
|
||||
MD4_CTX ctx;
|
||||
unsigned long s1,s2,e1,e2;
|
||||
unsigned char k[16];
|
||||
unsigned long data[2];
|
||||
unsigned char iv[8];
|
||||
int i,num=0,numm;
|
||||
int j=0;
|
||||
|
||||
if (argc >= 2)
|
||||
num=atoi(argv[1]);
|
||||
|
||||
if (num == 0) num=16;
|
||||
if (num > 250) num=16;
|
||||
numm=num+2;
|
||||
num*=64;
|
||||
numm*=64;
|
||||
|
||||
for (j=0; j<6; j++)
|
||||
{
|
||||
for (i=0; i<10; i++) /**/
|
||||
{
|
||||
md4_block_x86(&ctx,buffer,numm);
|
||||
GetTSC(s1);
|
||||
md4_block_x86(&ctx,buffer,numm);
|
||||
GetTSC(e1);
|
||||
GetTSC(s2);
|
||||
md4_block_x86(&ctx,buffer,num);
|
||||
GetTSC(e2);
|
||||
md4_block_x86(&ctx,buffer,num);
|
||||
}
|
||||
printf("md4 (%d bytes) %d %d (%.2f)\n",num,
|
||||
e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user