mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-24 22:24:03 +08:00
quantum init
This commit is contained in:
@@ -36,7 +36,7 @@ certs = $dir/certs # Where the issued certs are kept
|
||||
crl_dir = $dir/crl # Where the issued crl are kept
|
||||
database = $dir/index.txt # database index file.
|
||||
#unique_subject = no # Set to 'no' to allow creation of
|
||||
# several certificates with same subject.
|
||||
# several ctificates with same subject.
|
||||
new_certs_dir = $dir/newcerts # default place for new certs.
|
||||
|
||||
certificate = $dir/cacert.pem # The CA certificate
|
||||
@@ -45,7 +45,7 @@ crl = $dir/crl.pem # The current CRL
|
||||
private_key = $dir/private/cakey.pem# The private key
|
||||
RANDFILE = $dir/private/.rand # private random number file
|
||||
|
||||
x509_extensions = v3_ca # The extensions to add to the cert
|
||||
x509_extensions = v3_ca # The extentions to add to the cert
|
||||
|
||||
name_opt = ca_default # Subject Name options
|
||||
cert_opt = ca_default # Certificate field options
|
||||
@@ -71,6 +71,6 @@ emailAddress = optional
|
||||
[ v3_ca ]
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid:always,issuer:always
|
||||
basicConstraints = critical,CA:true,pathlen:1
|
||||
basicConstraints = CA:true,pathlen:1
|
||||
keyUsage = cRLSign, keyCertSign
|
||||
issuerAltName=issuer:copy
|
||||
|
||||
@@ -35,7 +35,7 @@ private_key = $dir/private/cakey.pem# The private key
|
||||
RANDFILE = $dir/private/.rand # private random number file
|
||||
|
||||
default_days = 365 # how long to certify for
|
||||
default_md = sha256 # which md to use.
|
||||
default_md = sha1 # which md to use.
|
||||
preserve = no # keep passed DN ordering
|
||||
|
||||
policy = policy_match
|
||||
@@ -51,13 +51,13 @@ emailAddress = optional
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
default_bits = 1024
|
||||
default_md = sha1
|
||||
distinguished_name = $ENV::TSDNSECT
|
||||
encrypt_rsa_key = no
|
||||
prompt = no
|
||||
# attributes = req_attributes
|
||||
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
||||
|
||||
string_mask = nombstr
|
||||
|
||||
@@ -132,11 +132,11 @@ signer_cert = $dir/tsa_cert1.pem # The TSA signing certificate
|
||||
certs = $dir/tsaca.pem # Certificate chain to include in reply
|
||||
# (optional)
|
||||
signer_key = $dir/tsa_key1.pem # The TSA private key (optional)
|
||||
signer_digest = sha256 # Signing digest to use. (Optional)
|
||||
|
||||
default_policy = tsa_policy1 # Policy if request did not specify it
|
||||
# (optional)
|
||||
other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
|
||||
digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory)
|
||||
digests = md5, sha1 # Acceptable message digests (mandatory)
|
||||
accuracy = secs:1, millisecs:500, microsecs:100 # (optional)
|
||||
ordering = yes # Is ordering defined for timestamps?
|
||||
# (optional, default: no)
|
||||
@@ -156,8 +156,8 @@ signer_cert = $dir/tsa_cert2.pem # The TSA signing certificate
|
||||
certs = $dir/demoCA/cacert.pem# Certificate chain to include in reply
|
||||
# (optional)
|
||||
signer_key = $dir/tsa_key2.pem # The TSA private key (optional)
|
||||
signer_digest = sha256 # Signing digest to use. (Optional)
|
||||
|
||||
default_policy = tsa_policy1 # Policy if request did not specify it
|
||||
# (optional)
|
||||
other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
|
||||
digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory)
|
||||
digests = md5, sha1 # Acceptable message digests (mandatory)
|
||||
|
||||
@@ -7,11 +7,11 @@ RANDFILE = ./.rnd
|
||||
|
||||
####################################################################
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
default_bits = 1024
|
||||
default_keyfile = keySS.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
encrypt_rsa_key = no
|
||||
default_md = sha256
|
||||
default_md = md2
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = Country Name (2 letter code)
|
||||
|
||||
@@ -7,11 +7,11 @@ RANDFILE = ./.rnd
|
||||
|
||||
####################################################################
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
default_bits = 1024
|
||||
default_keyfile = keySS.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
encrypt_rsa_key = no
|
||||
default_md = sha256
|
||||
default_md = md2
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = Country Name (2 letter code)
|
||||
|
||||
33
test/Uss.cnf
33
test/Uss.cnf
@@ -4,7 +4,6 @@
|
||||
#
|
||||
|
||||
RANDFILE = ./.rnd
|
||||
CN2 = Brother 2
|
||||
|
||||
####################################################################
|
||||
[ req ]
|
||||
@@ -12,30 +11,26 @@ default_bits = 2048
|
||||
default_keyfile = keySS.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
encrypt_rsa_key = no
|
||||
default_md = sha256
|
||||
prompt = no
|
||||
default_md = sha256
|
||||
|
||||
[ req_distinguished_name ]
|
||||
countryName = AU
|
||||
organizationName = Dodgy Brothers
|
||||
0.commonName = Brother 1
|
||||
1.commonName = $ENV::CN2
|
||||
countryName = Country Name (2 letter code)
|
||||
countryName_default = AU
|
||||
countryName_value = AU
|
||||
|
||||
organizationName = Organization Name (eg, company)
|
||||
organizationName_value = Dodgy Brothers
|
||||
|
||||
0.commonName = Common Name (eg, YOUR name)
|
||||
0.commonName_value = Brother 1
|
||||
|
||||
1.commonName = Common Name (eg, YOUR name)
|
||||
1.commonName_value = Brother 2
|
||||
|
||||
[ v3_ee ]
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid,issuer:always
|
||||
basicConstraints = CA:false
|
||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
||||
|
||||
[ v3_ee_dsa ]
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid:always
|
||||
basicConstraints = CA:false
|
||||
keyUsage = nonRepudiation, digitalSignature
|
||||
|
||||
[ v3_ee_ec ]
|
||||
subjectKeyIdentifier=hash
|
||||
authorityKeyIdentifier=keyid:always
|
||||
basicConstraints = CA:false
|
||||
keyUsage = nonRepudiation, digitalSignature, keyAgreement
|
||||
issuerAltName=issuer:copy
|
||||
|
||||
|
||||
1
test/VMSca-response.1
Normal file
1
test/VMSca-response.1
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
2
test/VMSca-response.2
Normal file
2
test/VMSca-response.2
Normal file
@@ -0,0 +1,2 @@
|
||||
y
|
||||
y
|
||||
21
test/asn1test.c
Normal file
21
test/asn1test.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1_mac.h>
|
||||
|
||||
typedef struct X {
|
||||
STACK_OF(X509_EXTENSION) *ext;
|
||||
} X;
|
||||
|
||||
/* This isn't meant to run particularly, it's just to test type checking */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
X *x = NULL;
|
||||
unsigned char **pp = NULL;
|
||||
|
||||
M_ASN1_I2D_vars(x);
|
||||
M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION, x->ext,
|
||||
i2d_X509_EXTENSION);
|
||||
M_ASN1_I2D_seq_total();
|
||||
M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION, x->ext,
|
||||
i2d_X509_EXTENSION);
|
||||
M_ASN1_I2D_finish();
|
||||
}
|
||||
@@ -1,630 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Unit test for Cisco DTLS1_BAD_VER session resume, as used by
|
||||
* AnyConnect VPN protocol.
|
||||
*
|
||||
* This is designed to exercise the code paths in
|
||||
* http://git.infradead.org/users/dwmw2/openconnect.git/blob/HEAD:/dtls.c
|
||||
* which have frequently been affected by regressions in DTLS1_BAD_VER
|
||||
* support.
|
||||
*
|
||||
* Note that unlike other SSL tests, we don't test against our own SSL
|
||||
* server method. Firstly because we don't have one; we *only* support
|
||||
* DTLS1_BAD_VER as a client. And secondly because even if that were
|
||||
* fixed up it's the wrong thing to test against — because if changes
|
||||
* are made in generic DTLS code which don't take DTLS1_BAD_VER into
|
||||
* account, there's plenty of scope for making those changes such that
|
||||
* they break *both* the client and the server in the same way.
|
||||
*
|
||||
* So we handle the server side manually. In a session resume there isn't
|
||||
* much to be done anyway.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/kdf.h>
|
||||
|
||||
#include "../ssl/packet_locl.h"
|
||||
#include "../e_os.h" /* for OSSL_NELEM() */
|
||||
|
||||
/* For DTLS1_BAD_VER packets the MAC doesn't include the handshake header */
|
||||
#define MAC_OFFSET (DTLS1_RT_HEADER_LENGTH + DTLS1_HM_HEADER_LENGTH)
|
||||
|
||||
static unsigned char client_random[SSL3_RANDOM_SIZE];
|
||||
static unsigned char server_random[SSL3_RANDOM_SIZE];
|
||||
|
||||
/* These are all generated locally, sized purely according to our own whim */
|
||||
static unsigned char session_id[32];
|
||||
static unsigned char master_secret[48];
|
||||
static unsigned char cookie[20];
|
||||
|
||||
/* We've hard-coded the cipher suite; we know it's 104 bytes */
|
||||
static unsigned char key_block[104];
|
||||
#define mac_key (key_block + 20)
|
||||
#define dec_key (key_block + 40)
|
||||
#define enc_key (key_block + 56)
|
||||
|
||||
static EVP_MD_CTX *handshake_md;
|
||||
|
||||
static int do_PRF(const void *seed1, int seed1_len,
|
||||
const void *seed2, int seed2_len,
|
||||
const void *seed3, int seed3_len,
|
||||
unsigned char *out, int olen)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_TLS1_PRF, NULL);
|
||||
size_t outlen = olen;
|
||||
|
||||
/* No error handling. If it all screws up, the test will fail anyway */
|
||||
EVP_PKEY_derive_init(pctx);
|
||||
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_SHA1)
|
||||
EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_md5_sha1());
|
||||
#elif !defined(OPENSSL_NO_SM3)
|
||||
EVP_PKEY_CTX_set_tls1_prf_md(pctx, EVP_sm3());
|
||||
#else
|
||||
# error "no avaiable digest"
|
||||
#endif
|
||||
EVP_PKEY_CTX_set1_tls1_prf_secret(pctx, master_secret, sizeof(master_secret));
|
||||
EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed1, seed1_len);
|
||||
EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed2, seed2_len);
|
||||
EVP_PKEY_CTX_add1_tls1_prf_seed(pctx, seed3, seed3_len);
|
||||
EVP_PKEY_derive(pctx, out, &outlen);
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SSL_SESSION *client_session(void)
|
||||
{
|
||||
static unsigned char session_asn1[] = {
|
||||
0x30, 0x5F, /* SEQUENCE, length 0x5F */
|
||||
0x02, 0x01, 0x01, /* INTEGER, SSL_SESSION_ASN1_VERSION */
|
||||
0x02, 0x02, 0x01, 0x00, /* INTEGER, DTLS1_BAD_VER */
|
||||
0x04, 0x02, 0x00, 0x2F, /* OCTET_STRING, AES128-SHA */
|
||||
0x04, 0x20, /* OCTET_STRING, session id */
|
||||
#define SS_SESSID_OFS 15 /* Session ID goes here */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x04, 0x30, /* OCTET_STRING, master secret */
|
||||
#define SS_SECRET_OFS 49 /* Master secret goes here */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const unsigned char *p = session_asn1;
|
||||
|
||||
/* Copy the randomly-generated fields into the above ASN1 */
|
||||
memcpy(session_asn1 + SS_SESSID_OFS, session_id, sizeof(session_id));
|
||||
memcpy(session_asn1 + SS_SECRET_OFS, master_secret, sizeof(master_secret));
|
||||
|
||||
return d2i_SSL_SESSION(NULL, &p, sizeof(session_asn1));
|
||||
}
|
||||
|
||||
/* Returns 1 for initial ClientHello, 2 for ClientHello with cookie */
|
||||
static int validate_client_hello(BIO *wbio)
|
||||
{
|
||||
PACKET pkt, pkt2;
|
||||
long len;
|
||||
unsigned char *data;
|
||||
int cookie_found = 0;
|
||||
unsigned int u;
|
||||
|
||||
len = BIO_get_mem_data(wbio, (char **)&data);
|
||||
if (!PACKET_buf_init(&pkt, data, len))
|
||||
return 0;
|
||||
|
||||
/* Check record header type */
|
||||
if (!PACKET_get_1(&pkt, &u) || u != SSL3_RT_HANDSHAKE)
|
||||
return 0;
|
||||
/* Version */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != DTLS1_BAD_VER)
|
||||
return 0;
|
||||
/* Skip the rest of the record header */
|
||||
if (!PACKET_forward(&pkt, DTLS1_RT_HEADER_LENGTH - 3))
|
||||
return 0;
|
||||
|
||||
/* Check it's a ClientHello */
|
||||
if (!PACKET_get_1(&pkt, &u) || u != SSL3_MT_CLIENT_HELLO)
|
||||
return 0;
|
||||
/* Skip the rest of the handshake message header */
|
||||
if (!PACKET_forward(&pkt, DTLS1_HM_HEADER_LENGTH - 1))
|
||||
return 0;
|
||||
|
||||
/* Check client version */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != DTLS1_BAD_VER)
|
||||
return 0;
|
||||
|
||||
/* Store random */
|
||||
if (!PACKET_copy_bytes(&pkt, client_random, SSL3_RANDOM_SIZE))
|
||||
return 0;
|
||||
|
||||
/* Check session id length and content */
|
||||
if (!PACKET_get_length_prefixed_1(&pkt, &pkt2) ||
|
||||
!PACKET_equal(&pkt2, session_id, sizeof(session_id)))
|
||||
return 0;
|
||||
|
||||
/* Check cookie */
|
||||
if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
|
||||
return 0;
|
||||
if (PACKET_remaining(&pkt2)) {
|
||||
if (!PACKET_equal(&pkt2, cookie, sizeof(cookie)))
|
||||
return 0;
|
||||
cookie_found = 1;
|
||||
}
|
||||
|
||||
/* Skip ciphers */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || !PACKET_forward(&pkt, u))
|
||||
return 0;
|
||||
|
||||
/* Skip compression */
|
||||
if (!PACKET_get_1(&pkt, &u) || !PACKET_forward(&pkt, u))
|
||||
return 0;
|
||||
|
||||
/* Skip extensions */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || !PACKET_forward(&pkt, u))
|
||||
return 0;
|
||||
|
||||
/* Now we are at the end */
|
||||
if (PACKET_remaining(&pkt))
|
||||
return 0;
|
||||
|
||||
/* Update handshake MAC for second ClientHello (with cookie) */
|
||||
if (cookie_found && !EVP_DigestUpdate(handshake_md, data + MAC_OFFSET,
|
||||
len - MAC_OFFSET))
|
||||
printf("EVP_DigestUpdate() failed\n");
|
||||
|
||||
(void)BIO_reset(wbio);
|
||||
|
||||
return 1 + cookie_found;
|
||||
}
|
||||
|
||||
static int send_hello_verify(BIO *rbio)
|
||||
{
|
||||
static unsigned char hello_verify[] = {
|
||||
0x16, /* Handshake */
|
||||
0x01, 0x00, /* DTLS1_BAD_VER */
|
||||
0x00, 0x00, /* Epoch 0 */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Seq# 0 */
|
||||
0x00, 0x23, /* Length */
|
||||
0x03, /* Hello Verify */
|
||||
0x00, 0x00, 0x17, /* Length */
|
||||
0x00, 0x00, /* Seq# 0 */
|
||||
0x00, 0x00, 0x00, /* Fragment offset */
|
||||
0x00, 0x00, 0x17, /* Fragment length */
|
||||
0x01, 0x00, /* DTLS1_BAD_VER */
|
||||
0x14, /* Cookie length */
|
||||
#define HV_COOKIE_OFS 28 /* Cookie goes here */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
memcpy(hello_verify + HV_COOKIE_OFS, cookie, sizeof(cookie));
|
||||
|
||||
BIO_write(rbio, hello_verify, sizeof(hello_verify));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int send_server_hello(BIO *rbio)
|
||||
{
|
||||
static unsigned char server_hello[] = {
|
||||
0x16, /* Handshake */
|
||||
0x01, 0x00, /* DTLS1_BAD_VER */
|
||||
0x00, 0x00, /* Epoch 0 */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* Seq# 1 */
|
||||
0x00, 0x52, /* Length */
|
||||
0x02, /* Server Hello */
|
||||
0x00, 0x00, 0x46, /* Length */
|
||||
0x00, 0x01, /* Seq# */
|
||||
0x00, 0x00, 0x00, /* Fragment offset */
|
||||
0x00, 0x00, 0x46, /* Fragment length */
|
||||
0x01, 0x00, /* DTLS1_BAD_VER */
|
||||
#define SH_RANDOM_OFS 27 /* Server random goes here */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x20, /* Session ID length */
|
||||
#define SH_SESSID_OFS 60 /* Session ID goes here */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x2f, /* Cipher suite AES128-SHA */
|
||||
0x00, /* Compression null */
|
||||
};
|
||||
static unsigned char change_cipher_spec[] = {
|
||||
0x14, /* Change Cipher Spec */
|
||||
0x01, 0x00, /* DTLS1_BAD_VER */
|
||||
0x00, 0x00, /* Epoch 0 */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, /* Seq# 2 */
|
||||
0x00, 0x03, /* Length */
|
||||
0x01, 0x00, 0x02, /* Message */
|
||||
};
|
||||
|
||||
memcpy(server_hello + SH_RANDOM_OFS, server_random, sizeof(server_random));
|
||||
memcpy(server_hello + SH_SESSID_OFS, session_id, sizeof(session_id));
|
||||
|
||||
if (!EVP_DigestUpdate(handshake_md, server_hello + MAC_OFFSET,
|
||||
sizeof(server_hello) - MAC_OFFSET))
|
||||
printf("EVP_DigestUpdate() failed\n");
|
||||
|
||||
BIO_write(rbio, server_hello, sizeof(server_hello));
|
||||
BIO_write(rbio, change_cipher_spec, sizeof(change_cipher_spec));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create header, HMAC, pad, encrypt and send a record */
|
||||
static int send_record(BIO *rbio, unsigned char type, unsigned long seqnr,
|
||||
const void *msg, size_t len)
|
||||
{
|
||||
/* Note that the order of the record header fields on the wire,
|
||||
* and in the HMAC, is different. So we just keep them in separate
|
||||
* variables and handle them individually. */
|
||||
static unsigned char epoch[2] = { 0x00, 0x01 };
|
||||
static unsigned char seq[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
static unsigned char ver[2] = { 0x01, 0x00 }; /* DTLS1_BAD_VER */
|
||||
unsigned char lenbytes[2];
|
||||
HMAC_CTX *ctx;
|
||||
EVP_CIPHER_CTX *enc_ctx;
|
||||
unsigned char iv[16];
|
||||
unsigned char pad;
|
||||
unsigned char *enc;
|
||||
|
||||
#ifdef SIXTY_FOUR_BIT_LONG
|
||||
seq[0] = (seqnr >> 40) & 0xff;
|
||||
seq[1] = (seqnr >> 32) & 0xff;
|
||||
#endif
|
||||
seq[2] = (seqnr >> 24) & 0xff;
|
||||
seq[3] = (seqnr >> 16) & 0xff;
|
||||
seq[4] = (seqnr >> 8) & 0xff;
|
||||
seq[5] = seqnr & 0xff;
|
||||
|
||||
pad = 15 - ((len + SHA_DIGEST_LENGTH) % 16);
|
||||
enc = OPENSSL_malloc(len + SHA_DIGEST_LENGTH + 1 + pad);
|
||||
if (enc == NULL)
|
||||
return 0;
|
||||
|
||||
/* Copy record to encryption buffer */
|
||||
memcpy(enc, msg, len);
|
||||
|
||||
/* Append HMAC to data */
|
||||
ctx = HMAC_CTX_new();
|
||||
HMAC_Init_ex(ctx, mac_key, 20, EVP_sha1(), NULL);
|
||||
HMAC_Update(ctx, epoch, 2);
|
||||
HMAC_Update(ctx, seq, 6);
|
||||
HMAC_Update(ctx, &type, 1);
|
||||
HMAC_Update(ctx, ver, 2); /* Version */
|
||||
lenbytes[0] = len >> 8;
|
||||
lenbytes[1] = len & 0xff;
|
||||
HMAC_Update(ctx, lenbytes, 2); /* Length */
|
||||
HMAC_Update(ctx, enc, len); /* Finally the data itself */
|
||||
HMAC_Final(ctx, enc + len, NULL);
|
||||
HMAC_CTX_free(ctx);
|
||||
|
||||
/* Append padding bytes */
|
||||
len += SHA_DIGEST_LENGTH;
|
||||
do {
|
||||
enc[len++] = pad;
|
||||
} while (len % 16);
|
||||
|
||||
/* Generate IV, and encrypt */
|
||||
RAND_bytes(iv, sizeof(iv));
|
||||
enc_ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CipherInit_ex(enc_ctx, EVP_aes_128_cbc(), NULL, enc_key, iv, 1);
|
||||
EVP_Cipher(enc_ctx, enc, enc, len);
|
||||
EVP_CIPHER_CTX_free(enc_ctx);
|
||||
|
||||
/* Finally write header (from fragmented variables), IV and encrypted record */
|
||||
BIO_write(rbio, &type, 1);
|
||||
BIO_write(rbio, ver, 2);
|
||||
BIO_write(rbio, epoch, 2);
|
||||
BIO_write(rbio, seq, 6);
|
||||
lenbytes[0] = (len + sizeof(iv)) >> 8;
|
||||
lenbytes[1] = (len + sizeof(iv)) & 0xff;
|
||||
BIO_write(rbio, lenbytes, 2);
|
||||
|
||||
BIO_write(rbio, iv, sizeof(iv));
|
||||
BIO_write(rbio, enc, len);
|
||||
|
||||
OPENSSL_free(enc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int send_finished(SSL *s, BIO *rbio)
|
||||
{
|
||||
static unsigned char finished_msg[DTLS1_HM_HEADER_LENGTH +
|
||||
TLS1_FINISH_MAC_LENGTH] = {
|
||||
0x14, /* Finished */
|
||||
0x00, 0x00, 0x0c, /* Length */
|
||||
0x00, 0x03, /* Seq# 3 */
|
||||
0x00, 0x00, 0x00, /* Fragment offset */
|
||||
0x00, 0x00, 0x0c, /* Fragment length */
|
||||
/* Finished MAC (12 bytes) */
|
||||
};
|
||||
unsigned char handshake_hash[EVP_MAX_MD_SIZE];
|
||||
|
||||
/* Derive key material */
|
||||
do_PRF(TLS_MD_KEY_EXPANSION_CONST, TLS_MD_KEY_EXPANSION_CONST_SIZE,
|
||||
server_random, SSL3_RANDOM_SIZE,
|
||||
client_random, SSL3_RANDOM_SIZE,
|
||||
key_block, sizeof(key_block));
|
||||
|
||||
/* Generate Finished MAC */
|
||||
if (!EVP_DigestFinal_ex(handshake_md, handshake_hash, NULL))
|
||||
printf("EVP_DigestFinal_ex() failed\n");
|
||||
|
||||
do_PRF(TLS_MD_SERVER_FINISH_CONST, TLS_MD_SERVER_FINISH_CONST_SIZE,
|
||||
handshake_hash, EVP_MD_CTX_size(handshake_md),
|
||||
NULL, 0,
|
||||
finished_msg + DTLS1_HM_HEADER_LENGTH, TLS1_FINISH_MAC_LENGTH);
|
||||
|
||||
return send_record(rbio, SSL3_RT_HANDSHAKE, 0,
|
||||
finished_msg, sizeof(finished_msg));
|
||||
}
|
||||
|
||||
static int validate_ccs(BIO *wbio)
|
||||
{
|
||||
PACKET pkt;
|
||||
long len;
|
||||
unsigned char *data;
|
||||
unsigned int u;
|
||||
|
||||
len = BIO_get_mem_data(wbio, (char **)&data);
|
||||
if (!PACKET_buf_init(&pkt, data, len))
|
||||
return 0;
|
||||
|
||||
/* Check record header type */
|
||||
if (!PACKET_get_1(&pkt, &u) || u != SSL3_RT_CHANGE_CIPHER_SPEC)
|
||||
return 0;
|
||||
/* Version */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != DTLS1_BAD_VER)
|
||||
return 0;
|
||||
/* Skip the rest of the record header */
|
||||
if (!PACKET_forward(&pkt, DTLS1_RT_HEADER_LENGTH - 3))
|
||||
return 0;
|
||||
|
||||
/* Check ChangeCipherSpec message */
|
||||
if (!PACKET_get_1(&pkt, &u) || u != SSL3_MT_CCS)
|
||||
return 0;
|
||||
/* A DTLS1_BAD_VER ChangeCipherSpec also contains the
|
||||
* handshake sequence number (which is 2 here) */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != 0x0002)
|
||||
return 0;
|
||||
|
||||
/* Now check the Finished packet */
|
||||
if (!PACKET_get_1(&pkt, &u) || u != SSL3_RT_HANDSHAKE)
|
||||
return 0;
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != DTLS1_BAD_VER)
|
||||
return 0;
|
||||
|
||||
/* Check epoch is now 1 */
|
||||
if (!PACKET_get_net_2(&pkt, &u) || u != 0x0001)
|
||||
return 0;
|
||||
|
||||
/* That'll do for now. If OpenSSL accepted *our* Finished packet
|
||||
* then it's evidently remembered that DTLS1_BAD_VER doesn't
|
||||
* include the handshake header in the MAC. There's not a lot of
|
||||
* point in implementing decryption here, just to check that it
|
||||
* continues to get it right for one more packet. */
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define NODROP(x) { x##UL, 0 }
|
||||
#define DROP(x) { x##UL, 1 }
|
||||
|
||||
static struct {
|
||||
unsigned long seq;
|
||||
int drop;
|
||||
} tests[] = {
|
||||
NODROP(1), NODROP(3), NODROP(2),
|
||||
NODROP(0x1234), NODROP(0x1230), NODROP(0x1235),
|
||||
NODROP(0xffff), NODROP(0x10001), NODROP(0xfffe), NODROP(0x10000),
|
||||
DROP(0x10001), DROP(0xff), NODROP(0x100000), NODROP(0x800000), NODROP(0x7fffe1),
|
||||
NODROP(0xffffff), NODROP(0x1000000), NODROP(0xfffffe), DROP(0xffffff), NODROP(0x1000010),
|
||||
NODROP(0xfffffd), NODROP(0x1000011), DROP(0x12), NODROP(0x1000012),
|
||||
NODROP(0x1ffffff), NODROP(0x2000000), DROP(0x1ff00fe), NODROP(0x2000001),
|
||||
NODROP(0x20fffff), NODROP(0x2105500), DROP(0x20ffffe), NODROP(0x21054ff),
|
||||
NODROP(0x211ffff), DROP(0x2110000), NODROP(0x2120000)
|
||||
/* The last test should be NODROP, because a DROP wouldn't get tested. */
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SSL_SESSION *sess;
|
||||
SSL_CTX *ctx;
|
||||
SSL *con;
|
||||
BIO *rbio;
|
||||
BIO *wbio;
|
||||
BIO *err;
|
||||
time_t now = 0;
|
||||
int testresult = 0;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_bytes(session_id, sizeof(session_id));
|
||||
RAND_bytes(master_secret, sizeof(master_secret));
|
||||
RAND_bytes(cookie, sizeof(cookie));
|
||||
RAND_bytes(server_random + 4, sizeof(server_random) - 4);
|
||||
|
||||
now = time(NULL);
|
||||
memcpy(server_random, &now, sizeof(now));
|
||||
|
||||
sess = client_session();
|
||||
if (sess == NULL) {
|
||||
printf("Failed to generate SSL_SESSION\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
handshake_md = EVP_MD_CTX_new();
|
||||
if (handshake_md == NULL ||
|
||||
!EVP_DigestInit_ex(handshake_md, EVP_md5_sha1(), NULL)) {
|
||||
printf("Failed to initialise handshake_md\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
ctx = SSL_CTX_new(DTLS_client_method());
|
||||
if (ctx == NULL) {
|
||||
printf("Failed to allocate SSL_CTX\n");
|
||||
goto end_md;
|
||||
}
|
||||
if (!SSL_CTX_set_min_proto_version(ctx, DTLS1_BAD_VER)) {
|
||||
printf("SSL_CTX_set_min_proto_version() failed\n");
|
||||
goto end_ctx;
|
||||
}
|
||||
if (!SSL_CTX_set_max_proto_version(ctx, DTLS1_BAD_VER)) {
|
||||
printf("SSL_CTX_set_max_proto_version() failed\n");
|
||||
goto end_ctx;
|
||||
}
|
||||
|
||||
if (!SSL_CTX_set_cipher_list(ctx, "AES128-SHA")) {
|
||||
printf("SSL_CTX_set_cipher_list() failed\n");
|
||||
goto end_ctx;
|
||||
}
|
||||
|
||||
con = SSL_new(ctx);
|
||||
if (!SSL_set_session(con, sess)) {
|
||||
printf("SSL_set_session() failed\n");
|
||||
goto end_con;
|
||||
}
|
||||
SSL_SESSION_free(sess);
|
||||
|
||||
rbio = BIO_new(BIO_s_mem());
|
||||
wbio = BIO_new(BIO_s_mem());
|
||||
|
||||
BIO_set_nbio(rbio, 1);
|
||||
BIO_set_nbio(wbio, 1);
|
||||
|
||||
SSL_set_bio(con, rbio, wbio);
|
||||
SSL_set_connect_state(con);
|
||||
|
||||
/* Send initial ClientHello */
|
||||
ret = SSL_do_handshake(con);
|
||||
if (ret > 0 || SSL_get_error(con, ret) != SSL_ERROR_WANT_READ) {
|
||||
printf("Unexpected handshake result at initial call!\n");
|
||||
goto end_con;
|
||||
}
|
||||
|
||||
if (validate_client_hello(wbio) != 1) {
|
||||
printf("Initial ClientHello failed validation\n");
|
||||
goto end_con;
|
||||
}
|
||||
if (send_hello_verify(rbio) != 1) {
|
||||
printf("Failed to send HelloVerify\n");
|
||||
goto end_con;
|
||||
}
|
||||
ret = SSL_do_handshake(con);
|
||||
if (ret > 0 || SSL_get_error(con, ret) != SSL_ERROR_WANT_READ) {
|
||||
printf("Unexpected handshake result after HelloVerify!\n");
|
||||
goto end_con;
|
||||
}
|
||||
if (validate_client_hello(wbio) != 2) {
|
||||
printf("Second ClientHello failed validation\n");
|
||||
goto end_con;
|
||||
}
|
||||
if (send_server_hello(rbio) != 1) {
|
||||
printf("Failed to send ServerHello\n");
|
||||
goto end_con;
|
||||
}
|
||||
ret = SSL_do_handshake(con);
|
||||
if (ret > 0 || SSL_get_error(con, ret) != SSL_ERROR_WANT_READ) {
|
||||
printf("Unexpected handshake result after ServerHello!\n");
|
||||
goto end_con;
|
||||
}
|
||||
if (send_finished(con, rbio) != 1) {
|
||||
printf("Failed to send Finished\n");
|
||||
goto end_con;
|
||||
}
|
||||
ret = SSL_do_handshake(con);
|
||||
if (ret < 1) {
|
||||
printf("Handshake not successful after Finished!\n");
|
||||
goto end_con;
|
||||
}
|
||||
if (validate_ccs(wbio) != 1) {
|
||||
printf("Failed to validate client CCS/Finished\n");
|
||||
goto end_con;
|
||||
}
|
||||
|
||||
/* While we're here and crafting packets by hand, we might as well do a
|
||||
bit of a stress test on the DTLS record replay handling. Not Cisco-DTLS
|
||||
specific but useful anyway for the general case. It's been broken
|
||||
before, and in fact was broken even for a basic 0, 2, 1 test case
|
||||
when this test was first added.... */
|
||||
for (i = 0; i < (int)OSSL_NELEM(tests); i++) {
|
||||
unsigned long recv_buf[2];
|
||||
|
||||
if (send_record(rbio, SSL3_RT_APPLICATION_DATA, tests[i].seq,
|
||||
&tests[i].seq, sizeof(unsigned long)) != 1) {
|
||||
printf("Failed to send data seq #0x%lx (%d)\n",
|
||||
tests[i].seq, i);
|
||||
goto end_con;
|
||||
}
|
||||
|
||||
if (tests[i].drop)
|
||||
continue;
|
||||
|
||||
ret = SSL_read(con, recv_buf, 2 * sizeof(unsigned long));
|
||||
if (ret != sizeof(unsigned long)) {
|
||||
printf("SSL_read failed or wrong size on seq#0x%lx (%d)\n",
|
||||
tests[i].seq, i);
|
||||
goto end_con;
|
||||
}
|
||||
if (recv_buf[0] != tests[i].seq) {
|
||||
printf("Wrong data packet received (0x%lx not 0x%lx) at packet %d\n",
|
||||
recv_buf[0], tests[i].seq, i);
|
||||
goto end_con;
|
||||
}
|
||||
}
|
||||
if (tests[i-1].drop) {
|
||||
printf("Error: last test cannot be DROP()\n");
|
||||
goto end_con;
|
||||
}
|
||||
testresult=1;
|
||||
|
||||
end_con:
|
||||
SSL_free(con);
|
||||
end_ctx:
|
||||
SSL_CTX_free(ctx);
|
||||
end_md:
|
||||
EVP_MD_CTX_free(handshake_md);
|
||||
end:
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
if (!testresult) {
|
||||
printf("Cisco BadDTLS test: FAILED\n");
|
||||
}
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(err) <= 0)
|
||||
testresult = 0;
|
||||
#endif
|
||||
BIO_free(err);
|
||||
|
||||
return testresult?0:1;
|
||||
}
|
||||
1
test/bad_dtls_test.c
Symbolic link
1
test/bad_dtls_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/bad_dtls_test.c
|
||||
152
test/bctest.com
Normal file
152
test/bctest.com
Normal file
@@ -0,0 +1,152 @@
|
||||
$!
|
||||
$! Check operation of "bc".
|
||||
$!
|
||||
$! 2010-04-05 SMS. New. Based (loosely) on "bctest".
|
||||
$!
|
||||
$!
|
||||
$ tmp_file_name = "tmp.bctest"
|
||||
$ failure = ""
|
||||
$!
|
||||
$! Basic command test.
|
||||
$!
|
||||
$ on warning then goto bc_fail
|
||||
$ bc
|
||||
$ on error then exit
|
||||
$!
|
||||
$! Test for SunOS 5.[78] bc bug.
|
||||
$!
|
||||
$ if (failure .eqs. "")
|
||||
$ then
|
||||
$!
|
||||
$ define /user_mode sys$output 'tmp_file_name'
|
||||
$ bc
|
||||
obase=16
|
||||
ibase=16
|
||||
a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
|
||||
CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
|
||||
10F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
|
||||
C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
|
||||
3BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
|
||||
4FC3CADF855448B24A9D7640BCF473E
|
||||
b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
|
||||
9209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
|
||||
8B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
|
||||
3ED0E2017D60A68775B75481449
|
||||
(a/b)*b + (a%b) - a
|
||||
$ status = $status
|
||||
$ output_expected = "0"
|
||||
$ gosub check_output
|
||||
$ if (output .ne. 1)
|
||||
$ then
|
||||
$ failure = "SunOStest"
|
||||
$ else
|
||||
$ delete 'f$parse( tmp_file_name)'
|
||||
$ endif
|
||||
$ endif
|
||||
$!
|
||||
$! Test for SCO bc bug.
|
||||
$!
|
||||
$ if (failure .eqs. "")
|
||||
$ then
|
||||
$!
|
||||
$ define /user_mode sys$output 'tmp_file_name'
|
||||
$ bc
|
||||
obase=16
|
||||
ibase=16
|
||||
-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
|
||||
9DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
|
||||
11B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
|
||||
1239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
|
||||
AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
|
||||
F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
|
||||
B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
|
||||
02EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
|
||||
85EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
|
||||
A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
|
||||
E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
|
||||
8C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
|
||||
04E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
|
||||
89C8D71
|
||||
AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
|
||||
928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
|
||||
8A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
|
||||
37F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
|
||||
E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
|
||||
F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
|
||||
9E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
|
||||
D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
|
||||
5296964
|
||||
$ status = $status
|
||||
$ output_expected = "0\0"
|
||||
$ gosub check_output
|
||||
$ if (output .ne. 1)
|
||||
$ then
|
||||
$ failure = "SCOtest"
|
||||
$ else
|
||||
$ delete 'f$parse( tmp_file_name)'
|
||||
$ endif
|
||||
$ endif
|
||||
$!
|
||||
$! Test for working 'print' command.
|
||||
$!
|
||||
$ if (failure .eqs. "")
|
||||
$ then
|
||||
$!
|
||||
$ define /user_mode sys$output 'tmp_file_name'
|
||||
$ bc
|
||||
print "OK"
|
||||
$ status = $status
|
||||
$ output_expected = "OK"
|
||||
$ gosub check_output
|
||||
$ if (output .ne. 1)
|
||||
$ then
|
||||
$ failure = "printtest"
|
||||
$ else
|
||||
$ delete 'f$parse( tmp_file_name)'
|
||||
$ endif
|
||||
$ endif
|
||||
$!
|
||||
$ if (failure .nes. "")
|
||||
$ then
|
||||
$ write sys$output -
|
||||
"No working bc found. Consider installing GNU bc."
|
||||
$ exit %X00030000 ! %DCL-W-NORMAL
|
||||
$ endif
|
||||
$!
|
||||
$ exit
|
||||
$!
|
||||
$!
|
||||
$! Complete "bc" command failure.
|
||||
$!
|
||||
$ bc_fail:
|
||||
$ write sys$output -
|
||||
"No ""bc"" program/symbol found. Consider installing GNU bc."
|
||||
$ exit %X00030000 ! %DCL-W-NORMAL
|
||||
$!
|
||||
$!
|
||||
$! Output check subroutine.
|
||||
$!
|
||||
$ check_output:
|
||||
$ eof = 0
|
||||
$ line_nr = 0
|
||||
$ open /read tmp_file 'tmp_file_name'
|
||||
$ c_o_loop:
|
||||
$ read /error = error_read tmp_file line
|
||||
$ goto ok_read
|
||||
$ error_read:
|
||||
$ eof = 1
|
||||
$ ok_read:
|
||||
$ line_expected = f$element( line_nr, "\", output_expected)
|
||||
$ line_nr = line_nr+ 1
|
||||
$ if ((line_expected .nes. "\") .and. (.not. eof) .and. -
|
||||
(line_expected .eqs. line)) then goto c_o_loop
|
||||
$!
|
||||
$ if ((line_expected .eqs. "\") .and. eof)
|
||||
$ then
|
||||
$ output = 1
|
||||
$ else
|
||||
$ output = 0
|
||||
$ endif
|
||||
$ close tmp_file
|
||||
$ return
|
||||
$!
|
||||
484
test/bftest.c
484
test/bftest.c
@@ -1,484 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This has been a quickly hacked 'ideatest.c'. When I add tests for other
|
||||
* RC2 modes, more of the code will be uncommented.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_BF is defined */
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_BF
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No BF support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/blowfish.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
static char bf_key[2][30] = {
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"Who is John Galt?"
|
||||
};
|
||||
|
||||
/* big endian */
|
||||
static BF_LONG bf_plain[2][2] = {
|
||||
{0x424c4f57L, 0x46495348L},
|
||||
{0xfedcba98L, 0x76543210L}
|
||||
};
|
||||
|
||||
static BF_LONG bf_cipher[2][2] = {
|
||||
{0x324ed0feL, 0xf413a203L},
|
||||
{0xcc91732bL, 0x8022f684L}
|
||||
};
|
||||
|
||||
/************/
|
||||
|
||||
/* Lets use the DES test vectors :-) */
|
||||
# define NUM_TESTS 34
|
||||
static unsigned char ecb_data[NUM_TESTS][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
|
||||
{0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57},
|
||||
{0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E},
|
||||
{0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86},
|
||||
{0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E},
|
||||
{0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6},
|
||||
{0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE},
|
||||
{0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6},
|
||||
{0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE},
|
||||
{0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16},
|
||||
{0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F},
|
||||
{0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46},
|
||||
{0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E},
|
||||
{0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76},
|
||||
{0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07},
|
||||
{0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F},
|
||||
{0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7},
|
||||
{0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF},
|
||||
{0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6},
|
||||
{0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF},
|
||||
{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
|
||||
{0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E},
|
||||
{0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}
|
||||
};
|
||||
|
||||
static unsigned char plain_data[NUM_TESTS][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42},
|
||||
{0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA},
|
||||
{0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72},
|
||||
{0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A},
|
||||
{0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2},
|
||||
{0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A},
|
||||
{0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2},
|
||||
{0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A},
|
||||
{0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02},
|
||||
{0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A},
|
||||
{0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32},
|
||||
{0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA},
|
||||
{0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62},
|
||||
{0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2},
|
||||
{0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA},
|
||||
{0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92},
|
||||
{0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A},
|
||||
{0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2},
|
||||
{0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
|
||||
};
|
||||
|
||||
static unsigned char cipher_data[NUM_TESTS][8] = {
|
||||
{0x4E, 0xF9, 0x97, 0x45, 0x61, 0x98, 0xDD, 0x78},
|
||||
{0x51, 0x86, 0x6F, 0xD5, 0xB8, 0x5E, 0xCB, 0x8A},
|
||||
{0x7D, 0x85, 0x6F, 0x9A, 0x61, 0x30, 0x63, 0xF2},
|
||||
{0x24, 0x66, 0xDD, 0x87, 0x8B, 0x96, 0x3C, 0x9D},
|
||||
{0x61, 0xF9, 0xC3, 0x80, 0x22, 0x81, 0xB0, 0x96},
|
||||
{0x7D, 0x0C, 0xC6, 0x30, 0xAF, 0xDA, 0x1E, 0xC7},
|
||||
{0x4E, 0xF9, 0x97, 0x45, 0x61, 0x98, 0xDD, 0x78},
|
||||
{0x0A, 0xCE, 0xAB, 0x0F, 0xC6, 0xA0, 0xA2, 0x8D},
|
||||
{0x59, 0xC6, 0x82, 0x45, 0xEB, 0x05, 0x28, 0x2B},
|
||||
{0xB1, 0xB8, 0xCC, 0x0B, 0x25, 0x0F, 0x09, 0xA0},
|
||||
{0x17, 0x30, 0xE5, 0x77, 0x8B, 0xEA, 0x1D, 0xA4},
|
||||
{0xA2, 0x5E, 0x78, 0x56, 0xCF, 0x26, 0x51, 0xEB},
|
||||
{0x35, 0x38, 0x82, 0xB1, 0x09, 0xCE, 0x8F, 0x1A},
|
||||
{0x48, 0xF4, 0xD0, 0x88, 0x4C, 0x37, 0x99, 0x18},
|
||||
{0x43, 0x21, 0x93, 0xB7, 0x89, 0x51, 0xFC, 0x98},
|
||||
{0x13, 0xF0, 0x41, 0x54, 0xD6, 0x9D, 0x1A, 0xE5},
|
||||
{0x2E, 0xED, 0xDA, 0x93, 0xFF, 0xD3, 0x9C, 0x79},
|
||||
{0xD8, 0x87, 0xE0, 0x39, 0x3C, 0x2D, 0xA6, 0xE3},
|
||||
{0x5F, 0x99, 0xD0, 0x4F, 0x5B, 0x16, 0x39, 0x69},
|
||||
{0x4A, 0x05, 0x7A, 0x3B, 0x24, 0xD3, 0x97, 0x7B},
|
||||
{0x45, 0x20, 0x31, 0xC1, 0xE4, 0xFA, 0xDA, 0x8E},
|
||||
{0x75, 0x55, 0xAE, 0x39, 0xF5, 0x9B, 0x87, 0xBD},
|
||||
{0x53, 0xC5, 0x5F, 0x9C, 0xB4, 0x9F, 0xC0, 0x19},
|
||||
{0x7A, 0x8E, 0x7B, 0xFA, 0x93, 0x7E, 0x89, 0xA3},
|
||||
{0xCF, 0x9C, 0x5D, 0x7A, 0x49, 0x86, 0xAD, 0xB5},
|
||||
{0xD1, 0xAB, 0xB2, 0x90, 0x65, 0x8B, 0xC7, 0x78},
|
||||
{0x55, 0xCB, 0x37, 0x74, 0xD1, 0x3E, 0xF2, 0x01},
|
||||
{0xFA, 0x34, 0xEC, 0x48, 0x47, 0xB2, 0x68, 0xB2},
|
||||
{0xA7, 0x90, 0x79, 0x51, 0x08, 0xEA, 0x3C, 0xAE},
|
||||
{0xC3, 0x9E, 0x07, 0x2D, 0x9F, 0xAC, 0x63, 0x1D},
|
||||
{0x01, 0x49, 0x33, 0xE0, 0xCD, 0xAF, 0xF6, 0xE4},
|
||||
{0xF2, 0x1E, 0x9A, 0x77, 0xB7, 0x1C, 0x49, 0xBC},
|
||||
{0x24, 0x59, 0x46, 0x88, 0x57, 0x54, 0x36, 0x9A},
|
||||
{0x6B, 0x5C, 0x5A, 0x9C, 0x5D, 0x9E, 0x0A, 0x5A},
|
||||
};
|
||||
|
||||
static unsigned char cbc_key[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87
|
||||
};
|
||||
static unsigned char cbc_iv[8] =
|
||||
{ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
|
||||
static char cbc_data[40] = "7654321 Now is the time for ";
|
||||
static unsigned char cbc_ok[32] = {
|
||||
0x6B, 0x77, 0xB4, 0xD6, 0x30, 0x06, 0xDE, 0xE6,
|
||||
0x05, 0xB1, 0x56, 0xE2, 0x74, 0x03, 0x97, 0x93,
|
||||
0x58, 0xDE, 0xB9, 0xE7, 0x15, 0x46, 0x16, 0xD9,
|
||||
0x59, 0xF1, 0x65, 0x2B, 0xD5, 0xFF, 0x92, 0xCC
|
||||
};
|
||||
|
||||
static unsigned char cfb64_ok[] = {
|
||||
0xE7, 0x32, 0x14, 0xA2, 0x82, 0x21, 0x39, 0xCA,
|
||||
0xF2, 0x6E, 0xCF, 0x6D, 0x2E, 0xB9, 0xE7, 0x6E,
|
||||
0x3D, 0xA3, 0xDE, 0x04, 0xD1, 0x51, 0x72, 0x00,
|
||||
0x51, 0x9D, 0x57, 0xA6, 0xC3
|
||||
};
|
||||
|
||||
static unsigned char ofb64_ok[] = {
|
||||
0xE7, 0x32, 0x14, 0xA2, 0x82, 0x21, 0x39, 0xCA,
|
||||
0x62, 0xB3, 0x43, 0xCC, 0x5B, 0x65, 0x58, 0x73,
|
||||
0x10, 0xDD, 0x90, 0x8D, 0x0C, 0x24, 0x1B, 0x22,
|
||||
0x63, 0xC2, 0xCF, 0x80, 0xDA
|
||||
};
|
||||
|
||||
# define KEY_TEST_NUM 25
|
||||
static unsigned char key_test[KEY_TEST_NUM] = {
|
||||
0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87,
|
||||
0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88
|
||||
};
|
||||
|
||||
static unsigned char key_data[8] =
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 };
|
||||
|
||||
static unsigned char key_out[KEY_TEST_NUM][8] = {
|
||||
{0xF9, 0xAD, 0x59, 0x7C, 0x49, 0xDB, 0x00, 0x5E},
|
||||
{0xE9, 0x1D, 0x21, 0xC1, 0xD9, 0x61, 0xA6, 0xD6},
|
||||
{0xE9, 0xC2, 0xB7, 0x0A, 0x1B, 0xC6, 0x5C, 0xF3},
|
||||
{0xBE, 0x1E, 0x63, 0x94, 0x08, 0x64, 0x0F, 0x05},
|
||||
{0xB3, 0x9E, 0x44, 0x48, 0x1B, 0xDB, 0x1E, 0x6E},
|
||||
{0x94, 0x57, 0xAA, 0x83, 0xB1, 0x92, 0x8C, 0x0D},
|
||||
{0x8B, 0xB7, 0x70, 0x32, 0xF9, 0x60, 0x62, 0x9D},
|
||||
{0xE8, 0x7A, 0x24, 0x4E, 0x2C, 0xC8, 0x5E, 0x82},
|
||||
{0x15, 0x75, 0x0E, 0x7A, 0x4F, 0x4E, 0xC5, 0x77},
|
||||
{0x12, 0x2B, 0xA7, 0x0B, 0x3A, 0xB6, 0x4A, 0xE0},
|
||||
{0x3A, 0x83, 0x3C, 0x9A, 0xFF, 0xC5, 0x37, 0xF6},
|
||||
{0x94, 0x09, 0xDA, 0x87, 0xA9, 0x0F, 0x6B, 0xF2},
|
||||
{0x88, 0x4F, 0x80, 0x62, 0x50, 0x60, 0xB8, 0xB4},
|
||||
{0x1F, 0x85, 0x03, 0x1C, 0x19, 0xE1, 0x19, 0x68},
|
||||
{0x79, 0xD9, 0x37, 0x3A, 0x71, 0x4C, 0xA3, 0x4F},
|
||||
{0x93, 0x14, 0x28, 0x87, 0xEE, 0x3B, 0xE1, 0x5C},
|
||||
{0x03, 0x42, 0x9E, 0x83, 0x8C, 0xE2, 0xD1, 0x4B},
|
||||
{0xA4, 0x29, 0x9E, 0x27, 0x46, 0x9F, 0xF6, 0x7B},
|
||||
{0xAF, 0xD5, 0xAE, 0xD1, 0xC1, 0xBC, 0x96, 0xA8},
|
||||
{0x10, 0x85, 0x1C, 0x0E, 0x38, 0x58, 0xDA, 0x9F},
|
||||
{0xE6, 0xF5, 0x1E, 0xD7, 0x9B, 0x9D, 0xB2, 0x1F},
|
||||
{0x64, 0xA6, 0xE1, 0x4A, 0xFD, 0x36, 0xB4, 0x6F},
|
||||
{0x80, 0xC7, 0xD7, 0xD4, 0x5A, 0x54, 0x79, 0xAD},
|
||||
{0x05, 0x04, 0x4B, 0x62, 0xFA, 0x52, 0xD0, 0x80},
|
||||
};
|
||||
|
||||
static int test(void);
|
||||
static int print_test_data(void);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (argc > 1)
|
||||
ret = print_test_data();
|
||||
else
|
||||
ret = test();
|
||||
|
||||
EXIT(ret);
|
||||
}
|
||||
|
||||
static int print_test_data(void)
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
printf("ecb test data\n");
|
||||
printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", ecb_data[i][j]);
|
||||
printf("\t");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", plain_data[i][j]);
|
||||
printf("\t");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", cipher_data[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("set_key test data\n");
|
||||
printf("data[8]= ");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", key_data[j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < KEY_TEST_NUM - 1; i++) {
|
||||
printf("c=");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", key_out[i][j]);
|
||||
printf(" k[%2u]=", i + 1);
|
||||
for (j = 0; j < i + 1; j++)
|
||||
printf("%02X", key_test[j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("\nchaining mode test data\n");
|
||||
printf("key[16] = ");
|
||||
for (j = 0; j < 16; j++)
|
||||
printf("%02X", cbc_key[j]);
|
||||
printf("\niv[8] = ");
|
||||
for (j = 0; j < 8; j++)
|
||||
printf("%02X", cbc_iv[j]);
|
||||
printf("\ndata[%d] = '%s'", (int)strlen(cbc_data) + 1, cbc_data);
|
||||
printf("\ndata[%d] = ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", cbc_data[j]);
|
||||
printf("\n");
|
||||
printf("cbc cipher text\n");
|
||||
printf("cipher[%d]= ", 32);
|
||||
for (j = 0; j < 32; j++)
|
||||
printf("%02X", cbc_ok[j]);
|
||||
printf("\n");
|
||||
|
||||
printf("cfb64 cipher text\n");
|
||||
printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", cfb64_ok[j]);
|
||||
printf("\n");
|
||||
|
||||
printf("ofb64 cipher text\n");
|
||||
printf("cipher[%d]= ", (int)strlen(cbc_data) + 1);
|
||||
for (j = 0; j < strlen(cbc_data) + 1; j++)
|
||||
printf("%02X", ofb64_ok[j]);
|
||||
printf("\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int test(void)
|
||||
{
|
||||
unsigned char cbc_in[40], cbc_out[40], iv[8];
|
||||
int i, n, err = 0;
|
||||
BF_KEY key;
|
||||
BF_LONG data[2];
|
||||
unsigned char out[8];
|
||||
BF_LONG len;
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
|
||||
# endif
|
||||
|
||||
printf("testing blowfish in raw ecb mode\n");
|
||||
for (n = 0; n < 2; n++) {
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
|
||||
# endif
|
||||
BF_set_key(&key, strlen(bf_key[n]), (unsigned char *)bf_key[n]);
|
||||
|
||||
data[0] = bf_plain[n][0];
|
||||
data[1] = bf_plain[n][1];
|
||||
BF_encrypt(data, &key);
|
||||
if (memcmp(&(bf_cipher[n][0]), &(data[0]), 8) != 0) {
|
||||
printf("BF_encrypt error encrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)data[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)bf_cipher[n][i]);
|
||||
err = 1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
BF_decrypt(&(data[0]), &key);
|
||||
if (memcmp(&(bf_plain[n][0]), &(data[0]), 8) != 0) {
|
||||
printf("BF_encrypt error decrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)data[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 2; i++)
|
||||
printf("%08lX ", (unsigned long)bf_plain[n][i]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish in ecb mode\n");
|
||||
|
||||
for (n = 0; n < NUM_TESTS; n++) {
|
||||
BF_set_key(&key, 8, ecb_data[n]);
|
||||
|
||||
BF_ecb_encrypt(&(plain_data[n][0]), out, &key, BF_ENCRYPT);
|
||||
if (memcmp(&(cipher_data[n][0]), out, 8) != 0) {
|
||||
printf("BF_ecb_encrypt blowfish error encrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", cipher_data[n][i]);
|
||||
err = 1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
BF_ecb_encrypt(out, out, &key, BF_DECRYPT);
|
||||
if (memcmp(&(plain_data[n][0]), out, 8) != 0) {
|
||||
printf("BF_ecb_encrypt error decrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", plain_data[n][i]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish set_key\n");
|
||||
for (n = 1; n < KEY_TEST_NUM; n++) {
|
||||
BF_set_key(&key, n, key_test);
|
||||
BF_ecb_encrypt(key_data, out, &key, BF_ENCRYPT);
|
||||
/* mips-sgi-irix6.5-gcc vv -mabi=64 bug workaround */
|
||||
if (memcmp(out, &(key_out[i = n - 1][0]), 8) != 0) {
|
||||
printf("blowfish setkey error\n");
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("testing blowfish in cbc mode\n");
|
||||
len = strlen(cbc_data) + 1;
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, sizeof(cbc_in));
|
||||
memset(cbc_out, 0, sizeof(cbc_out));
|
||||
memcpy(iv, cbc_iv, sizeof iv);
|
||||
BF_cbc_encrypt((unsigned char *)cbc_data, cbc_out, len,
|
||||
&key, iv, BF_ENCRYPT);
|
||||
if (memcmp(cbc_out, cbc_ok, 32) != 0) {
|
||||
err = 1;
|
||||
printf("BF_cbc_encrypt encrypt error\n");
|
||||
for (i = 0; i < 32; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_cbc_encrypt(cbc_out, cbc_in, len, &key, iv, BF_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen(cbc_data) + 1) != 0) {
|
||||
printf("BF_cbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("testing blowfish in cfb64 mode\n");
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, 40);
|
||||
memset(cbc_out, 0, 40);
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
n = 0;
|
||||
BF_cfb64_encrypt((unsigned char *)cbc_data, cbc_out, (long)13,
|
||||
&key, iv, &n, BF_ENCRYPT);
|
||||
BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]), &(cbc_out[13]),
|
||||
len - 13, &key, iv, &n, BF_ENCRYPT);
|
||||
if (memcmp(cbc_out, cfb64_ok, (int)len) != 0) {
|
||||
err = 1;
|
||||
printf("BF_cfb64_encrypt encrypt error\n");
|
||||
for (i = 0; i < (int)len; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
n = 0;
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_cfb64_encrypt(cbc_out, cbc_in, 17, &key, iv, &n, BF_DECRYPT);
|
||||
BF_cfb64_encrypt(&(cbc_out[17]), &(cbc_in[17]), len - 17,
|
||||
&key, iv, &n, BF_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, (int)len) != 0) {
|
||||
printf("BF_cfb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("testing blowfish in ofb64\n");
|
||||
|
||||
BF_set_key(&key, 16, cbc_key);
|
||||
memset(cbc_in, 0, 40);
|
||||
memset(cbc_out, 0, 40);
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
n = 0;
|
||||
BF_ofb64_encrypt((unsigned char *)cbc_data, cbc_out, (long)13, &key, iv,
|
||||
&n);
|
||||
BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]), &(cbc_out[13]),
|
||||
len - 13, &key, iv, &n);
|
||||
if (memcmp(cbc_out, ofb64_ok, (int)len) != 0) {
|
||||
err = 1;
|
||||
printf("BF_ofb64_encrypt encrypt error\n");
|
||||
for (i = 0; i < (int)len; i++)
|
||||
printf("0x%02X,", cbc_out[i]);
|
||||
}
|
||||
n = 0;
|
||||
memcpy(iv, cbc_iv, 8);
|
||||
BF_ofb64_encrypt(cbc_out, cbc_in, 17, &key, iv, &n);
|
||||
BF_ofb64_encrypt(&(cbc_out[17]), &(cbc_in[17]), len - 17, &key, iv, &n);
|
||||
if (memcmp(cbc_in, cbc_data, (int)len) != 0) {
|
||||
printf("BF_ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
#endif
|
||||
1
test/bftest.c
Symbolic link
1
test/bftest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/bf/bftest.c
|
||||
2094
test/bntest.c
2094
test/bntest.c
File diff suppressed because it is too large
Load Diff
1
test/bntest.c
Symbolic link
1
test/bntest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/bn/bntest.c
|
||||
76
test/bntest.com
Normal file
76
test/bntest.com
Normal file
@@ -0,0 +1,76 @@
|
||||
$!
|
||||
$! Analyze bntest output file.
|
||||
$!
|
||||
$! Exit status = 1 (success) if all tests passed,
|
||||
$! 0 (warning) if any test failed.
|
||||
$!
|
||||
$! 2011-02-20 SMS. Added code to skip "#" comments in the input file.
|
||||
$!
|
||||
$! 2010-04-05 SMS. New. Based (loosely) on perl code in bntest-vms.sh.
|
||||
$!
|
||||
$! Expect data like:
|
||||
$! test test_name1
|
||||
$! 0
|
||||
$! [...]
|
||||
$! test test_name2
|
||||
$! 0
|
||||
$! [...]
|
||||
$! [...]
|
||||
$!
|
||||
$! Some tests have no following "0" lines.
|
||||
$!
|
||||
$ result_file_name = f$edit( p1, "TRIM")
|
||||
$ if (result_file_name .eqs. "")
|
||||
$ then
|
||||
$ result_file_name = "bntest-vms.out"
|
||||
$ endif
|
||||
$!
|
||||
$ fail = 0
|
||||
$ passed = 0
|
||||
$ tests = 0
|
||||
$!
|
||||
$ on control_c then goto tidy
|
||||
$ on error then goto tidy
|
||||
$!
|
||||
$ open /read result_file 'result_file_name'
|
||||
$!
|
||||
$ read_loop:
|
||||
$ read /end = read_loop_end /error = tidy result_file line
|
||||
$ t1 = f$element( 0, " ", line)
|
||||
$!
|
||||
$! Skip "#" comment lines.
|
||||
$ if (f$extract( 0, 1, f$edit( line, "TRIM")) .eqs. "#") then -
|
||||
goto read_loop
|
||||
$!
|
||||
$ if (t1 .eqs. "test")
|
||||
$ then
|
||||
$ passed = passed+ 1
|
||||
$ tests = tests+ 1
|
||||
$ fail = 1
|
||||
$ t2 = f$extract( 5, 1000, line)
|
||||
$ write sys$output "verify ''t2'"
|
||||
$ else
|
||||
$ if (t1 .nes. "0")
|
||||
$ then
|
||||
$ write sys$output "Failed! bc: ''line'"
|
||||
$ passed = passed- fail
|
||||
$ fail = 0
|
||||
$ endif
|
||||
$ endif
|
||||
$ goto read_loop
|
||||
$ read_loop_end:
|
||||
$ write sys$output "''passed'/''tests' tests passed"
|
||||
$!
|
||||
$ tidy:
|
||||
$ if f$trnlnm( "result_file", "LNM$PROCESS_TABLE", , "SUPERVISOR", , "CONFINE")
|
||||
$ then
|
||||
$ close result_file
|
||||
$ endif
|
||||
$!
|
||||
$ if ((tests .gt. 0) .and. (tests .eq. passed))
|
||||
$ then
|
||||
$ exit 1
|
||||
$ else
|
||||
$ exit 0
|
||||
$ endif
|
||||
$!
|
||||
163
test/casttest.c
163
test/casttest.c
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_CAST is defined */
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_CAST
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No CAST support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/cast.h>
|
||||
|
||||
# define FULL_TEST
|
||||
|
||||
static unsigned char k[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
static unsigned char in[8] =
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
|
||||
|
||||
static int k_len[3] = { 16, 10, 5 };
|
||||
|
||||
static unsigned char c[3][8] = {
|
||||
{0x23, 0x8B, 0x4F, 0xE5, 0x84, 0x7E, 0x44, 0xB2},
|
||||
{0xEB, 0x6A, 0x71, 0x1A, 0x2C, 0x02, 0x27, 0x1B},
|
||||
{0x7A, 0xC8, 0x16, 0xD1, 0x6E, 0x9B, 0x30, 0x2E},
|
||||
};
|
||||
|
||||
static unsigned char out[80];
|
||||
|
||||
static unsigned char in_a[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
static unsigned char in_b[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
static unsigned char c_a[16] = {
|
||||
0xEE, 0xA9, 0xD0, 0xA2, 0x49, 0xFD, 0x3B, 0xA6,
|
||||
0xB3, 0x43, 0x6F, 0xB8, 0x9D, 0x6D, 0xCA, 0x92
|
||||
};
|
||||
|
||||
static unsigned char c_b[16] = {
|
||||
0xB2, 0xC9, 0x5E, 0xB0, 0x0C, 0x31, 0xAD, 0x71,
|
||||
0x80, 0xAC, 0x05, 0xB8, 0xE8, 0x3D, 0x69, 0x6E
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
# ifdef FULL_TEST
|
||||
long l;
|
||||
CAST_KEY key_b;
|
||||
# endif
|
||||
int i, z, err = 0;
|
||||
CAST_KEY key;
|
||||
|
||||
for (z = 0; z < 3; z++) {
|
||||
CAST_set_key(&key, k_len[z], k);
|
||||
|
||||
CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
|
||||
if (memcmp(out, &(c[z][0]), 8) != 0) {
|
||||
printf("ecb cast error encrypting for keysize %d\n",
|
||||
k_len[z] * 8);
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", c[z][i]);
|
||||
err = 20;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
|
||||
if (memcmp(out, in, 8) != 0) {
|
||||
printf("ecb cast error decrypting for keysize %d\n",
|
||||
k_len[z] * 8);
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", in[i]);
|
||||
printf("\n");
|
||||
err = 3;
|
||||
}
|
||||
}
|
||||
if (err == 0)
|
||||
printf("ecb cast5 ok\n");
|
||||
|
||||
# ifdef FULL_TEST
|
||||
{
|
||||
unsigned char out_a[16], out_b[16];
|
||||
static char *hex = "0123456789ABCDEF";
|
||||
|
||||
printf("This test will take some time....");
|
||||
fflush(stdout);
|
||||
memcpy(out_a, in_a, sizeof(in_a));
|
||||
memcpy(out_b, in_b, sizeof(in_b));
|
||||
i = 1;
|
||||
|
||||
for (l = 0; l < 1000000L; l++) {
|
||||
CAST_set_key(&key_b, 16, out_b);
|
||||
CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_a[8]), &(out_a[8]), &key_b, CAST_ENCRYPT);
|
||||
CAST_set_key(&key, 16, out_a);
|
||||
CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT);
|
||||
if ((l & 0xffff) == 0xffff) {
|
||||
printf("%c", hex[i & 0x0f]);
|
||||
fflush(stdout);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((memcmp(out_a, c_a, sizeof(c_a)) != 0) ||
|
||||
(memcmp(out_b, c_b, sizeof(c_b)) != 0)) {
|
||||
printf("\n");
|
||||
printf("Error\n");
|
||||
|
||||
printf("A out =");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", out_a[i]);
|
||||
printf("\nactual=");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", c_a[i]);
|
||||
printf("\n");
|
||||
|
||||
printf("B out =");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", out_b[i]);
|
||||
printf("\nactual=");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", c_b[i]);
|
||||
printf("\n");
|
||||
} else
|
||||
printf(" ok\n");
|
||||
}
|
||||
# endif
|
||||
|
||||
EXIT(err);
|
||||
}
|
||||
#endif
|
||||
1
test/casttest.c
Symbolic link
1
test/casttest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/cast/casttest.c
|
||||
21
test/certs/pss1.pem
Normal file
21
test/certs/pss1.pem
Normal file
@@ -0,0 +1,21 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDdjCCAjqgAwIBAgIJANcwZLyfEv7DMD4GCSqGSIb3DQEBCjAxoA0wCwYJYIZI
|
||||
AWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIEAgIA3jAnMSUwIwYD
|
||||
VQQDDBxUZXN0IEludmFsaWQgUFNTIGNlcnRpZmljYXRlMB4XDTE1MTEwNDE2MDIz
|
||||
NVoXDTE1MTIwNDE2MDIzNVowJzElMCMGA1UEAwwcVGVzdCBJbnZhbGlkIFBTUyBj
|
||||
ZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTaM7WH
|
||||
qVCAGAIA+zL1KWvvASTrhlq+1ePdO7wsrWX2KiYoTYrJYTnxhLnn0wrHqApt79nL
|
||||
IBG7cfShyZqFHOY/IzlYPMVt+gPo293gw96Fds5JBsjhjkyGnOyr9OUntFqvxDbT
|
||||
IIFU7o9IdxD4edaqjRv+fegVE+B79pDk4s0ujsk6dULtCg9Rst0ucGFo19mr+b7k
|
||||
dbfn8pZ72ZNDJPueVdrUAWw9oll61UcYfk75XdrLk6JlL41GrYHc8KlfXf43gGQq
|
||||
QfrpHkg4Ih2cI6Wt2nhFGAzrlcorzLliQIUJRIhM8h4IgDfpBpaPdVQLqS2pFbXa
|
||||
5eQjqiyJwak2vJ8CAwEAAaNQME4wHQYDVR0OBBYEFCt180N4oGUt5LbzBwQ4Ia+2
|
||||
4V97MB8GA1UdIwQYMBaAFCt180N4oGUt5LbzBwQ4Ia+24V97MAwGA1UdEwQFMAMB
|
||||
Af8wMQYJKoZIhvcNAQEKMCSgDTALBglghkgBZQMEAgGhDTALBgkqhkiG9w0BAQii
|
||||
BAICAN4DggEBAAjBtm90lGxgddjc4Xu/nbXXFHVs2zVcHv/mqOZoQkGB9r/BVgLb
|
||||
xhHrFZ2pHGElbUYPfifdS9ztB73e1d4J+P29o0yBqfd4/wGAc/JA8qgn6AAEO/Xn
|
||||
plhFeTRJQtLZVl75CkHXgUGUd3h+ADvKtcBuW9dSUncaUrgNKR8u/h/2sMG38RWY
|
||||
DzBddC/66YTa3r7KkVUfW7yqRQfELiGKdcm+bjlTEMsvS+EhHup9CzbpoCx2Fx9p
|
||||
NPtFY3yEObQhmL1JyoCRWqBE75GzFPbRaiux5UpEkns+i3trkGssZzsOuVqHNTNZ
|
||||
lC9+9hPHIoc9UMmAQNo1vGIW3NWVoeGbaJ8=
|
||||
-----END CERTIFICATE-----
|
||||
35
test/clean_test.com
Executable file
35
test/clean_test.com
Executable file
@@ -0,0 +1,35 @@
|
||||
$!
|
||||
$! Delete various test results files.
|
||||
$!
|
||||
$ def_orig = f$environment( "default")
|
||||
$ proc = f$environment( "procedure")
|
||||
$ proc_dev_dir = f$parse( "A.;", proc) - "A.;"
|
||||
$!
|
||||
$ on control_c then goto tidy
|
||||
$ on error then goto tidy
|
||||
$!
|
||||
$ set default 'proc_dev_dir'
|
||||
$!
|
||||
$ files := *.cms;*, *.srl;*, *.ss;*, -
|
||||
cms.err;*, cms.out;*, newreq.pem;*, -
|
||||
p.txt-zlib-cipher;*, -
|
||||
smtst.txt;*, testkey.pem;*, testreq.pem;*, -
|
||||
test_*.err;*, test_*.out;*, -
|
||||
.rnd;*
|
||||
$!
|
||||
$ delim = ","
|
||||
$ i = 0
|
||||
$ loop:
|
||||
$ file = f$edit( f$element( i, delim, files), "trim")
|
||||
$ if (file .eqs. delim) then goto loop_end
|
||||
$ if (f$search( file) .nes. "") then -
|
||||
delete 'p1' 'file'
|
||||
$ i = i+ 1
|
||||
$ goto loop
|
||||
$ loop_end:
|
||||
$!
|
||||
$ tidy:
|
||||
$
|
||||
$ if (f$type( def_orig) .nes. "") then -
|
||||
set default 'def_orig'
|
||||
$!
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "../ssl/packet_locl.h"
|
||||
|
||||
#define CLIENT_VERSION_LEN 2
|
||||
|
||||
|
||||
#define TOTAL_NUM_TESTS 1
|
||||
|
||||
/*
|
||||
* Test that explicitly setting ticket data results in it appearing in the
|
||||
* ClientHello for a negotiated SSL/TLS version
|
||||
*/
|
||||
#define TEST_SET_SESSION_TICK_DATA_VER_NEG 0
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SSL_CTX *ctx;
|
||||
SSL *con;
|
||||
BIO *rbio;
|
||||
BIO *wbio;
|
||||
BIO *err;
|
||||
long len;
|
||||
unsigned char *data;
|
||||
PACKET pkt, pkt2, pkt3;
|
||||
char *dummytick = "Hello World!";
|
||||
unsigned int type;
|
||||
int testresult = 0;
|
||||
int currtest = 0;
|
||||
|
||||
err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
/*
|
||||
* For each test set up an SSL_CTX and SSL and see what ClientHello gets
|
||||
* produced when we try to connect
|
||||
*/
|
||||
for (; currtest < TOTAL_NUM_TESTS; currtest++) {
|
||||
testresult = 0;
|
||||
ctx = SSL_CTX_new(TLS_method());
|
||||
con = SSL_new(ctx);
|
||||
|
||||
rbio = BIO_new(BIO_s_mem());
|
||||
wbio = BIO_new(BIO_s_mem());
|
||||
SSL_set_bio(con, rbio, wbio);
|
||||
SSL_set_connect_state(con);
|
||||
|
||||
if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
|
||||
if (!SSL_set_session_ticket_ext(con, dummytick, strlen(dummytick)))
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (SSL_connect(con) > 0) {
|
||||
/* This shouldn't succeed because we don't have a server! */
|
||||
goto end;
|
||||
}
|
||||
|
||||
len = BIO_get_mem_data(wbio, (char **)&data);
|
||||
if (!PACKET_buf_init(&pkt, data, len))
|
||||
goto end;
|
||||
|
||||
/* Skip the record header */
|
||||
if (!PACKET_forward(&pkt, SSL3_RT_HEADER_LENGTH))
|
||||
goto end;
|
||||
|
||||
/* Skip the handshake message header */
|
||||
if (!PACKET_forward(&pkt, SSL3_HM_HEADER_LENGTH))
|
||||
goto end;
|
||||
|
||||
/* Skip client version and random */
|
||||
if (!PACKET_forward(&pkt, CLIENT_VERSION_LEN + SSL3_RANDOM_SIZE))
|
||||
goto end;
|
||||
|
||||
/* Skip session id */
|
||||
if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
|
||||
goto end;
|
||||
|
||||
/* Skip ciphers */
|
||||
if (!PACKET_get_length_prefixed_2(&pkt, &pkt2))
|
||||
goto end;
|
||||
|
||||
/* Skip compression */
|
||||
if (!PACKET_get_length_prefixed_1(&pkt, &pkt2))
|
||||
goto end;
|
||||
|
||||
/* Extensions len */
|
||||
if (!PACKET_as_length_prefixed_2(&pkt, &pkt2))
|
||||
goto end;
|
||||
|
||||
/* Loop through all extensions */
|
||||
while (PACKET_remaining(&pkt2)) {
|
||||
|
||||
if (!PACKET_get_net_2(&pkt2, &type) ||
|
||||
!PACKET_get_length_prefixed_2(&pkt2, &pkt3))
|
||||
goto end;
|
||||
|
||||
if (type == TLSEXT_TYPE_session_ticket) {
|
||||
if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {
|
||||
if (PACKET_equal(&pkt3, dummytick, strlen(dummytick))) {
|
||||
/* Ticket data is as we expected */
|
||||
testresult = 1;
|
||||
} else {
|
||||
printf("Received session ticket is not as expected\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
end:
|
||||
SSL_free(con);
|
||||
SSL_CTX_free(ctx);
|
||||
if (!testresult) {
|
||||
printf("ClientHello test: FAILED (Test %d)\n", currtest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(err) <= 0)
|
||||
testresult = 0;
|
||||
#endif
|
||||
BIO_free(err);
|
||||
|
||||
return testresult?0:1;
|
||||
}
|
||||
1
test/clienthellotest.c
Symbolic link
1
test/clienthellotest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/clienthellotest.c
|
||||
@@ -1,10 +1,54 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# test/cms-examples.pl
|
||||
# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
# project.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
# ====================================================================
|
||||
# Copyright (c) 2008 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.
|
||||
# ====================================================================
|
||||
|
||||
# Perl script to run tests against S/MIME examples in RFC4134
|
||||
# Assumes RFC is in current directory and called "rfc4134.txt"
|
||||
|
||||
622
test/cms-test.pl
Normal file
622
test/cms-test.pl
Normal file
@@ -0,0 +1,622 @@
|
||||
# test/cms-test.pl
|
||||
# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
# project.
|
||||
#
|
||||
# ====================================================================
|
||||
# Copyright (c) 2008 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.
|
||||
# ====================================================================
|
||||
|
||||
# CMS, PKCS7 consistency test script. Run extensive tests on
|
||||
# OpenSSL PKCS#7 and CMS implementations.
|
||||
|
||||
my $ossl_path;
|
||||
my $redir = " 2> cms.err > cms.out";
|
||||
# Make VMS work
|
||||
if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
|
||||
$ossl_path = "pipe mcr OSSLX:openssl";
|
||||
$null_path = "NL:";
|
||||
# On VMS, the lowest 3 bits of the exit code indicates severity
|
||||
# 1 is success (perl translates it to 0 for $?), 2 is error
|
||||
# (perl doesn't translate it)
|
||||
$failure_code = 512; # 2 << 8 = 512
|
||||
}
|
||||
# Make MSYS work
|
||||
elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
|
||||
$ossl_path = "cmd /c ..\\apps\\openssl";
|
||||
$null_path = "NUL";
|
||||
$failure_code = 256;
|
||||
}
|
||||
elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
|
||||
$ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
|
||||
$null_path = "/dev/null";
|
||||
$failure_code = 256;
|
||||
}
|
||||
elsif ( -f "..\\out32dll\\openssl.exe" ) {
|
||||
$ossl_path = "..\\out32dll\\openssl.exe";
|
||||
$null_path = "NUL";
|
||||
$failure_code = 256;
|
||||
}
|
||||
elsif ( -f "..\\out32\\openssl.exe" ) {
|
||||
$ossl_path = "..\\out32\\openssl.exe";
|
||||
$null_path = "NUL";
|
||||
$failure_code = 256;
|
||||
}
|
||||
else {
|
||||
die "Can't find OpenSSL executable";
|
||||
}
|
||||
|
||||
my $pk7cmd = "$ossl_path smime ";
|
||||
my $cmscmd = "$ossl_path cms ";
|
||||
my $smdir = "smime-certs";
|
||||
my $halt_err = 1;
|
||||
|
||||
my $badcmd = 0;
|
||||
my $no_ec;
|
||||
my $no_ec2m;
|
||||
my $no_ecdh;
|
||||
my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
|
||||
|
||||
system ("$ossl_path no-ec > $null_path");
|
||||
if ($? == 0)
|
||||
{
|
||||
$no_ec = 1;
|
||||
}
|
||||
elsif ($? == $failure_code)
|
||||
{
|
||||
$no_ec = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
die "Error checking for EC support\n";
|
||||
}
|
||||
|
||||
system ("$ossl_path no-ec2m > $null_path");
|
||||
if ($? == 0)
|
||||
{
|
||||
$no_ec2m = 1;
|
||||
}
|
||||
elsif ($? == $failure_code)
|
||||
{
|
||||
$no_ec2m = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
die "Error checking for EC2M support\n";
|
||||
}
|
||||
|
||||
system ("$ossl_path no-ec > $null_path");
|
||||
if ($? == 0)
|
||||
{
|
||||
$no_ecdh = 1;
|
||||
}
|
||||
elsif ($? == $failure_code)
|
||||
{
|
||||
$no_ecdh = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
die "Error checking for ECDH support\n";
|
||||
}
|
||||
|
||||
my @smime_pkcs7_tests = (
|
||||
|
||||
[
|
||||
"signed content DER format, RSA key",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach"
|
||||
. " -certfile $smdir/smroot.pem"
|
||||
. " -signer $smdir/smrsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed detached content DER format, RSA key",
|
||||
"-sign -in smcont.txt -outform \"DER\""
|
||||
. " -signer $smdir/smrsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming BER format, RSA",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach"
|
||||
. " -stream -signer $smdir/smrsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content DER format, DSA key",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach"
|
||||
. " -signer $smdir/smdsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed detached content DER format, DSA key",
|
||||
"-sign -in smcont.txt -outform \"DER\""
|
||||
. " -signer $smdir/smdsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed detached content DER format, add RSA signer",
|
||||
"-resign -inform \"DER\" -in test.cms -outform \"DER\""
|
||||
. " -signer $smdir/smrsa1.pem -out test2.cms",
|
||||
"-verify -in test2.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming BER format, DSA key",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach"
|
||||
. " -stream -signer $smdir/smdsa1.pem -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming BER format, 2 DSA and 2 RSA keys",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
|
||||
"-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
|
||||
"-sign -in smcont.txt -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
|
||||
"-sign -in smcont.txt"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, 3 recipients",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
|
||||
"-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
|
||||
"-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, 3 recipients, key only used",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
|
||||
"-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -aes256 -stream -out test.cms"
|
||||
. " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
|
||||
"-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
my @smime_cms_tests = (
|
||||
|
||||
[
|
||||
"signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
|
||||
"-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms -inform \"DER\" "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming PEM format, 2 DSA and 2 RSA keys",
|
||||
"-sign -in smcont.txt -outform PEM -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
|
||||
. " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
|
||||
. " -stream -out test.cms",
|
||||
"-verify -in test.cms -inform PEM "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content MIME format, RSA key, signed receipt request",
|
||||
"-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
|
||||
. " -receipt_request_to test\@openssl.org -receipt_request_all"
|
||||
. " -out test.cms",
|
||||
"-verify -in test.cms "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed receipt MIME format, RSA key",
|
||||
"-sign_receipt -in test.cms"
|
||||
. " -signer $smdir/smrsa2.pem"
|
||||
. " -out test2.cms",
|
||||
"-verify_receipt test2.cms -in test.cms"
|
||||
. " \"-CAfile\" $smdir/smroot.pem"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, 3 recipients, keyid",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms -keyid"
|
||||
. " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
|
||||
"-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming PEM format, KEK",
|
||||
"-encrypt -in smcont.txt -outform PEM -aes128"
|
||||
. " -stream -out test.cms "
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F "
|
||||
. " -secretkeyid C0FEE0",
|
||||
"-decrypt -in test.cms -out smtst.txt -inform PEM"
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F "
|
||||
. " -secretkeyid C0FEE0"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming PEM format, KEK, key only",
|
||||
"-encrypt -in smcont.txt -outform PEM -aes128"
|
||||
. " -stream -out test.cms "
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F "
|
||||
. " -secretkeyid C0FEE0",
|
||||
"-decrypt -in test.cms -out smtst.txt -inform PEM"
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F "
|
||||
],
|
||||
|
||||
[
|
||||
"data content test streaming PEM format",
|
||||
"-data_create -in smcont.txt -outform PEM -nodetach"
|
||||
. " -stream -out test.cms",
|
||||
"-data_out -in test.cms -inform PEM -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"encrypted content test streaming PEM format, 128 bit RC2 key",
|
||||
"\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
|
||||
. " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
|
||||
. " -stream -out test.cms",
|
||||
"\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"encrypted content test streaming PEM format, 40 bit RC2 key",
|
||||
"\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
|
||||
. " -rc2 -secretkey 0001020304"
|
||||
. " -stream -out test.cms",
|
||||
"\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
|
||||
. " -secretkey 0001020304 -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"encrypted content test streaming PEM format, triple DES key",
|
||||
"\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
|
||||
. " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
|
||||
. " -stream -out test.cms",
|
||||
"\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
|
||||
. " -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"encrypted content test streaming PEM format, 128 bit AES key",
|
||||
"\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
|
||||
. " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
|
||||
. " -stream -out test.cms",
|
||||
"\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
|
||||
. " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
|
||||
],
|
||||
|
||||
);
|
||||
|
||||
my @smime_cms_comp_tests = (
|
||||
|
||||
[
|
||||
"compressed content test streaming PEM format",
|
||||
"-compress -in smcont.txt -outform PEM -nodetach"
|
||||
. " -stream -out test.cms",
|
||||
"-uncompress -in test.cms -inform PEM -out smtst.txt"
|
||||
]
|
||||
|
||||
);
|
||||
|
||||
my @smime_cms_param_tests = (
|
||||
[
|
||||
"signed content test streaming PEM format, RSA keys, PSS signature",
|
||||
"-sign -in smcont.txt -outform PEM -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
|
||||
. " -out test.cms",
|
||||
"-verify -in test.cms -inform PEM "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
|
||||
"-sign -in smcont.txt -outform PEM -nodetach -noattr"
|
||||
. " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
|
||||
. " -out test.cms",
|
||||
"-verify -in test.cms -inform PEM "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
|
||||
"-sign -in smcont.txt -outform PEM -nodetach"
|
||||
. " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
|
||||
. " -keyopt rsa_mgf1_md:sha384 -out test.cms",
|
||||
"-verify -in test.cms -inform PEM "
|
||||
. " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, OAEP default parameters",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep",
|
||||
"-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, OAEP SHA256",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep"
|
||||
. " -keyopt rsa_oaep_md:sha256",
|
||||
"-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, ECDH",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smec1.pem",
|
||||
"-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, ECDH, key identifier",
|
||||
"-encrypt -keyid -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smec1.pem",
|
||||
"-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smec1.pem -aes128 -keyopt ecdh_kdf_md:sha256",
|
||||
"-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smec2.pem -aes128"
|
||||
. " -keyopt ecdh_kdf_md:sha256 -keyopt ecdh_cofactor_mode:1",
|
||||
"-decrypt -recip $smdir/smec2.pem -in test.cms -out smtst.txt"
|
||||
],
|
||||
|
||||
[
|
||||
"enveloped content test streaming S/MIME format, X9.42 DH",
|
||||
"-encrypt -in smcont.txt"
|
||||
. " -stream -out test.cms"
|
||||
. " -recip $smdir/smdh.pem -aes128",
|
||||
"-decrypt -recip $smdir/smdh.pem -in test.cms -out smtst.txt"
|
||||
]
|
||||
);
|
||||
|
||||
print "CMS => PKCS#7 compatibility tests\n";
|
||||
|
||||
run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
|
||||
|
||||
print "CMS <= PKCS#7 compatibility tests\n";
|
||||
|
||||
run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
|
||||
|
||||
print "CMS <=> CMS consistency tests\n";
|
||||
|
||||
run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
|
||||
run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd );
|
||||
|
||||
print "CMS <=> CMS consistency tests, modified key parameters\n";
|
||||
run_smime_tests( \$badcmd, \@smime_cms_param_tests, $cmscmd, $cmscmd );
|
||||
|
||||
if ( `$ossl_path version -f` =~ /ZLIB/ ) {
|
||||
run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
|
||||
}
|
||||
else {
|
||||
print "Zlib not supported: compression tests skipped\n";
|
||||
}
|
||||
|
||||
print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
|
||||
|
||||
if ($badcmd) {
|
||||
print "$badcmd TESTS FAILED!!\n";
|
||||
}
|
||||
else {
|
||||
print "ALL TESTS SUCCESSFUL.\n";
|
||||
}
|
||||
|
||||
unlink "test.cms";
|
||||
unlink "test2.cms";
|
||||
unlink "smtst.txt";
|
||||
unlink "cms.out";
|
||||
unlink "cms.err";
|
||||
|
||||
sub run_smime_tests {
|
||||
my ( $rv, $aref, $scmd, $vcmd ) = @_;
|
||||
|
||||
foreach $smtst (@$aref) {
|
||||
my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
|
||||
if ($ossl8)
|
||||
{
|
||||
# Skip smime resign: 0.9.8 smime doesn't support -resign
|
||||
next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
|
||||
# Disable streaming: option not supported in 0.9.8
|
||||
$tnam =~ s/streaming//;
|
||||
$rscmd =~ s/-stream//;
|
||||
$rvcmd =~ s/-stream//;
|
||||
}
|
||||
if ($no_ec && $tnam =~ /ECDH/)
|
||||
{
|
||||
print "$tnam: skipped, EC disabled\n";
|
||||
next;
|
||||
}
|
||||
if ($no_ecdh && $tnam =~ /ECDH/)
|
||||
{
|
||||
print "$tnam: skipped, ECDH disabled\n";
|
||||
next;
|
||||
}
|
||||
if ($no_ec2m && $tnam =~ /K-283/)
|
||||
{
|
||||
print "$tnam: skipped, EC2M disabled\n";
|
||||
next;
|
||||
}
|
||||
system("$scmd$rscmd$redir");
|
||||
if ($?) {
|
||||
print "$tnam: generation error\n";
|
||||
$$rv++;
|
||||
exit 1 if $halt_err;
|
||||
next;
|
||||
}
|
||||
system("$vcmd$rvcmd$redir");
|
||||
if ($?) {
|
||||
print "$tnam: verify error\n";
|
||||
$$rv++;
|
||||
exit 1 if $halt_err;
|
||||
next;
|
||||
}
|
||||
if (!cmp_files("smtst.txt", "smcont.txt")) {
|
||||
print "$tnam: content verify error\n";
|
||||
$$rv++;
|
||||
exit 1 if $halt_err;
|
||||
next;
|
||||
}
|
||||
print "$tnam: OK\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub cmp_files {
|
||||
use FileHandle;
|
||||
my ( $f1, $f2 ) = @_;
|
||||
my $fp1 = FileHandle->new();
|
||||
my $fp2 = FileHandle->new();
|
||||
|
||||
my ( $rd1, $rd2 );
|
||||
|
||||
if ( !open( $fp1, "<$f1" ) ) {
|
||||
print STDERR "Can't Open file $f1\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( !open( $fp2, "<$f2" ) ) {
|
||||
print STDERR "Can't Open file $f2\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
binmode $fp1;
|
||||
binmode $fp2;
|
||||
|
||||
my $ret = 0;
|
||||
|
||||
for ( ; ; ) {
|
||||
$n1 = sysread $fp1, $rd1, 4096;
|
||||
$n2 = sysread $fp2, $rd2, 4096;
|
||||
last if ( $n1 != $n2 );
|
||||
last if ( $rd1 ne $rd2 );
|
||||
|
||||
if ( $n1 == 0 ) {
|
||||
$ret = 1;
|
||||
last;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
close $fp1;
|
||||
close $fp2;
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/constant_time_locl.h"
|
||||
#include "e_os.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const unsigned int CONSTTIME_TRUE = (unsigned)(~0);
|
||||
static const unsigned int CONSTTIME_FALSE = 0;
|
||||
static const unsigned char CONSTTIME_TRUE_8 = 0xff;
|
||||
static const unsigned char CONSTTIME_FALSE_8 = 0;
|
||||
|
||||
static int test_binary_op(unsigned int (*op) (unsigned int a, unsigned int b),
|
||||
const char *op_name, unsigned int a, unsigned int b,
|
||||
int is_true)
|
||||
{
|
||||
unsigned c = op(a, b);
|
||||
if (is_true && c != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %du "
|
||||
"(TRUE), got %du\n", op_name, a, b, CONSTTIME_TRUE, c);
|
||||
return 1;
|
||||
} else if (!is_true && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %du "
|
||||
"(FALSE), got %du\n", op_name, a, b, CONSTTIME_FALSE, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_binary_op_8(unsigned
|
||||
char (*op) (unsigned int a, unsigned int b),
|
||||
const char *op_name, unsigned int a,
|
||||
unsigned int b, int is_true)
|
||||
{
|
||||
unsigned char c = op(a, b);
|
||||
if (is_true && c != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %u "
|
||||
"(TRUE), got %u\n", op_name, a, b, CONSTTIME_TRUE_8, c);
|
||||
return 1;
|
||||
} else if (!is_true && c != CONSTTIME_FALSE_8) {
|
||||
fprintf(stderr, "Test failed for %s(%du, %du): expected %u "
|
||||
"(FALSE), got %u\n", op_name, a, b, CONSTTIME_FALSE_8, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_is_zero(unsigned int a)
|
||||
{
|
||||
unsigned int c = constant_time_is_zero(a);
|
||||
if (a == 0 && c != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %du (TRUE), got %du\n", a, CONSTTIME_TRUE, c);
|
||||
return 1;
|
||||
} else if (a != 0 && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %du (FALSE), got %du\n", a, CONSTTIME_FALSE, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_is_zero_8(unsigned int a)
|
||||
{
|
||||
unsigned char c = constant_time_is_zero_8(a);
|
||||
if (a == 0 && c != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %u (TRUE), got %u\n", a, CONSTTIME_TRUE_8, c);
|
||||
return 1;
|
||||
} else if (a != 0 && c != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_is_zero(%du): "
|
||||
"expected %u (FALSE), got %u\n", a, CONSTTIME_FALSE_8, c);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select(unsigned int a, unsigned int b)
|
||||
{
|
||||
unsigned int selected = constant_time_select(CONSTTIME_TRUE, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
|
||||
"%du): expected %du(first value), got %du\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select(CONSTTIME_FALSE, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %du,"
|
||||
"%du): expected %du(second value), got %du\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select_8(unsigned char a, unsigned char b)
|
||||
{
|
||||
unsigned char selected = constant_time_select_8(CONSTTIME_TRUE_8, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
|
||||
"%u): expected %u(first value), got %u\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select_8(CONSTTIME_FALSE_8, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%u, %u,"
|
||||
"%u): expected %u(second value), got %u\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_select_int(int a, int b)
|
||||
{
|
||||
int selected = constant_time_select_int(CONSTTIME_TRUE, a, b);
|
||||
if (selected != a) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
|
||||
"%d): expected %d(first value), got %d\n",
|
||||
CONSTTIME_TRUE, a, b, a, selected);
|
||||
return 1;
|
||||
}
|
||||
selected = constant_time_select_int(CONSTTIME_FALSE, a, b);
|
||||
if (selected != b) {
|
||||
fprintf(stderr, "Test failed for constant_time_select(%du, %d,"
|
||||
"%d): expected %d(second value), got %d\n",
|
||||
CONSTTIME_FALSE, a, b, b, selected);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_eq_int(int a, int b)
|
||||
{
|
||||
unsigned int equal = constant_time_eq_int(a, b);
|
||||
if (a == b && equal != CONSTTIME_TRUE) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
|
||||
"expected %du(TRUE), got %du\n", a, b, CONSTTIME_TRUE, equal);
|
||||
return 1;
|
||||
} else if (a != b && equal != CONSTTIME_FALSE) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int(%d, %d): "
|
||||
"expected %du(FALSE), got %du\n",
|
||||
a, b, CONSTTIME_FALSE, equal);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_eq_int_8(int a, int b)
|
||||
{
|
||||
unsigned char equal = constant_time_eq_int_8(a, b);
|
||||
if (a == b && equal != CONSTTIME_TRUE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
|
||||
"expected %u(TRUE), got %u\n", a, b, CONSTTIME_TRUE_8, equal);
|
||||
return 1;
|
||||
} else if (a != b && equal != CONSTTIME_FALSE_8) {
|
||||
fprintf(stderr, "Test failed for constant_time_eq_int_8(%d, %d): "
|
||||
"expected %u(FALSE), got %u\n",
|
||||
a, b, CONSTTIME_FALSE_8, equal);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int test_values[] =
|
||||
{ 0, 1, 1024, 12345, 32000, UINT_MAX / 2 - 1,
|
||||
UINT_MAX / 2, UINT_MAX / 2 + 1, UINT_MAX - 1,
|
||||
UINT_MAX
|
||||
};
|
||||
|
||||
static unsigned char test_values_8[] =
|
||||
{ 0, 1, 2, 20, 32, 127, 128, 129, 255 };
|
||||
|
||||
static int signed_test_values[] = { 0, 1, -1, 1024, -1024, 12345, -12345,
|
||||
32000, -32000, INT_MAX, INT_MIN, INT_MAX - 1,
|
||||
INT_MIN + 1
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int a, b, i, j;
|
||||
int c, d;
|
||||
unsigned char e, f;
|
||||
int num_failed = 0, num_all = 0;
|
||||
fprintf(stdout, "Testing constant time operations...\n");
|
||||
|
||||
for (i = 0; i < OSSL_NELEM(test_values); ++i) {
|
||||
a = test_values[i];
|
||||
num_failed += test_is_zero(a);
|
||||
num_failed += test_is_zero_8(a);
|
||||
num_all += 2;
|
||||
for (j = 0; j < OSSL_NELEM(test_values); ++j) {
|
||||
b = test_values[j];
|
||||
num_failed += test_binary_op(&constant_time_lt,
|
||||
"constant_time_lt", a, b, a < b);
|
||||
num_failed += test_binary_op_8(&constant_time_lt_8,
|
||||
"constant_time_lt_8", a, b, a < b);
|
||||
num_failed += test_binary_op(&constant_time_lt,
|
||||
"constant_time_lt_8", b, a, b < a);
|
||||
num_failed += test_binary_op_8(&constant_time_lt_8,
|
||||
"constant_time_lt_8", b, a, b < a);
|
||||
num_failed += test_binary_op(&constant_time_ge,
|
||||
"constant_time_ge", a, b, a >= b);
|
||||
num_failed += test_binary_op_8(&constant_time_ge_8,
|
||||
"constant_time_ge_8", a, b,
|
||||
a >= b);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_ge, "constant_time_ge", b, a,
|
||||
b >= a);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_ge_8, "constant_time_ge_8", b,
|
||||
a, b >= a);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_eq, "constant_time_eq", a, b,
|
||||
a == b);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", a,
|
||||
b, a == b);
|
||||
num_failed +=
|
||||
test_binary_op(&constant_time_eq, "constant_time_eq", b, a,
|
||||
b == a);
|
||||
num_failed +=
|
||||
test_binary_op_8(&constant_time_eq_8, "constant_time_eq_8", b,
|
||||
a, b == a);
|
||||
num_failed += test_select(a, b);
|
||||
num_all += 13;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < OSSL_NELEM(signed_test_values); ++i) {
|
||||
c = signed_test_values[i];
|
||||
for (j = 0; j < OSSL_NELEM(signed_test_values); ++j) {
|
||||
d = signed_test_values[j];
|
||||
num_failed += test_select_int(c, d);
|
||||
num_failed += test_eq_int(c, d);
|
||||
num_failed += test_eq_int_8(c, d);
|
||||
num_all += 3;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(test_values_8); ++i) {
|
||||
e = test_values_8[i];
|
||||
for (j = 0; j < sizeof(test_values_8); ++j) {
|
||||
f = test_values_8[j];
|
||||
num_failed += test_select_8(e, f);
|
||||
num_all += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!num_failed) {
|
||||
fprintf(stdout, "success (ran %d tests)\n", num_all);
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
fprintf(stdout, "%d of %d tests failed!\n", num_failed, num_all);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
1
test/constant_time_test.c
Symbolic link
1
test/constant_time_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/constant_time_test.c
|
||||
804
test/destest.c
804
test/destest.c
@@ -1,804 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/e_os2.h>
|
||||
#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINDOWS)
|
||||
# ifndef OPENSSL_SYS_MSDOS
|
||||
# define OPENSSL_SYS_MSDOS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_SYS_MSDOS
|
||||
# if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
|
||||
# include OPENSSL_UNISTD
|
||||
# endif
|
||||
#else
|
||||
# include <io.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DES
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DES support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/des.h>
|
||||
|
||||
/* tisk tisk - the test keys don't all have odd parity :-( */
|
||||
/* test data */
|
||||
# define NUM_TESTS 34
|
||||
static unsigned char key_data[NUM_TESTS][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
|
||||
{0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57},
|
||||
{0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E},
|
||||
{0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86},
|
||||
{0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E},
|
||||
{0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6},
|
||||
{0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE},
|
||||
{0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6},
|
||||
{0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE},
|
||||
{0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16},
|
||||
{0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F},
|
||||
{0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46},
|
||||
{0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E},
|
||||
{0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76},
|
||||
{0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07},
|
||||
{0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F},
|
||||
{0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7},
|
||||
{0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF},
|
||||
{0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6},
|
||||
{0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF},
|
||||
{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01},
|
||||
{0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E},
|
||||
{0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}
|
||||
};
|
||||
|
||||
static unsigned char plain_data[NUM_TESTS][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42},
|
||||
{0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA},
|
||||
{0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72},
|
||||
{0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A},
|
||||
{0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2},
|
||||
{0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A},
|
||||
{0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2},
|
||||
{0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A},
|
||||
{0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02},
|
||||
{0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A},
|
||||
{0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32},
|
||||
{0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA},
|
||||
{0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62},
|
||||
{0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2},
|
||||
{0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA},
|
||||
{0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92},
|
||||
{0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A},
|
||||
{0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2},
|
||||
{0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
|
||||
};
|
||||
|
||||
static unsigned char cipher_data[NUM_TESTS][8] = {
|
||||
{0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7},
|
||||
{0x73, 0x59, 0xB2, 0x16, 0x3E, 0x4E, 0xDC, 0x58},
|
||||
{0x95, 0x8E, 0x6E, 0x62, 0x7A, 0x05, 0x55, 0x7B},
|
||||
{0xF4, 0x03, 0x79, 0xAB, 0x9E, 0x0E, 0xC5, 0x33},
|
||||
{0x17, 0x66, 0x8D, 0xFC, 0x72, 0x92, 0x53, 0x2D},
|
||||
{0x8A, 0x5A, 0xE1, 0xF8, 0x1A, 0xB8, 0xF2, 0xDD},
|
||||
{0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7},
|
||||
{0xED, 0x39, 0xD9, 0x50, 0xFA, 0x74, 0xBC, 0xC4},
|
||||
{0x69, 0x0F, 0x5B, 0x0D, 0x9A, 0x26, 0x93, 0x9B},
|
||||
{0x7A, 0x38, 0x9D, 0x10, 0x35, 0x4B, 0xD2, 0x71},
|
||||
{0x86, 0x8E, 0xBB, 0x51, 0xCA, 0xB4, 0x59, 0x9A},
|
||||
{0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A},
|
||||
{0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95},
|
||||
{0x86, 0xA5, 0x60, 0xF1, 0x0E, 0xC6, 0xD8, 0x5B},
|
||||
{0x0C, 0xD3, 0xDA, 0x02, 0x00, 0x21, 0xDC, 0x09},
|
||||
{0xEA, 0x67, 0x6B, 0x2C, 0xB7, 0xDB, 0x2B, 0x7A},
|
||||
{0xDF, 0xD6, 0x4A, 0x81, 0x5C, 0xAF, 0x1A, 0x0F},
|
||||
{0x5C, 0x51, 0x3C, 0x9C, 0x48, 0x86, 0xC0, 0x88},
|
||||
{0x0A, 0x2A, 0xEE, 0xAE, 0x3F, 0xF4, 0xAB, 0x77},
|
||||
{0xEF, 0x1B, 0xF0, 0x3E, 0x5D, 0xFA, 0x57, 0x5A},
|
||||
{0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56},
|
||||
{0xA1, 0xF9, 0x91, 0x55, 0x41, 0x02, 0x0B, 0x56},
|
||||
{0x6F, 0xBF, 0x1C, 0xAF, 0xCF, 0xFD, 0x05, 0x56},
|
||||
{0x2F, 0x22, 0xE4, 0x9B, 0xAB, 0x7C, 0xA1, 0xAC},
|
||||
{0x5A, 0x6B, 0x61, 0x2C, 0xC2, 0x6C, 0xCE, 0x4A},
|
||||
{0x5F, 0x4C, 0x03, 0x8E, 0xD1, 0x2B, 0x2E, 0x41},
|
||||
{0x63, 0xFA, 0xC0, 0xD0, 0x34, 0xD9, 0xF7, 0x93},
|
||||
{0x61, 0x7B, 0x3A, 0x0C, 0xE8, 0xF0, 0x71, 0x00},
|
||||
{0xDB, 0x95, 0x86, 0x05, 0xF8, 0xC8, 0xC6, 0x06},
|
||||
{0xED, 0xBF, 0xD1, 0xC6, 0x6C, 0x29, 0xCC, 0xC7},
|
||||
{0x35, 0x55, 0x50, 0xB2, 0x15, 0x0E, 0x24, 0x51},
|
||||
{0xCA, 0xAA, 0xAF, 0x4D, 0xEA, 0xF1, 0xDB, 0xAE},
|
||||
{0xD5, 0xD4, 0x4F, 0xF7, 0x20, 0x68, 0x3D, 0x0D},
|
||||
{0x2A, 0x2B, 0xB0, 0x08, 0xDF, 0x97, 0xC2, 0xF2}
|
||||
};
|
||||
|
||||
static unsigned char cipher_ecb2[NUM_TESTS - 1][8] = {
|
||||
{0x92, 0x95, 0xB5, 0x9B, 0xB3, 0x84, 0x73, 0x6E},
|
||||
{0x19, 0x9E, 0x9D, 0x6D, 0xF3, 0x9A, 0xA8, 0x16},
|
||||
{0x2A, 0x4B, 0x4D, 0x24, 0x52, 0x43, 0x84, 0x27},
|
||||
{0x35, 0x84, 0x3C, 0x01, 0x9D, 0x18, 0xC5, 0xB6},
|
||||
{0x4A, 0x5B, 0x2F, 0x42, 0xAA, 0x77, 0x19, 0x25},
|
||||
{0xA0, 0x6B, 0xA9, 0xB8, 0xCA, 0x5B, 0x17, 0x8A},
|
||||
{0xAB, 0x9D, 0xB7, 0xFB, 0xED, 0x95, 0xF2, 0x74},
|
||||
{0x3D, 0x25, 0x6C, 0x23, 0xA7, 0x25, 0x2F, 0xD6},
|
||||
{0xB7, 0x6F, 0xAB, 0x4F, 0xBD, 0xBD, 0xB7, 0x67},
|
||||
{0x8F, 0x68, 0x27, 0xD6, 0x9C, 0xF4, 0x1A, 0x10},
|
||||
{0x82, 0x57, 0xA1, 0xD6, 0x50, 0x5E, 0x81, 0x85},
|
||||
{0xA2, 0x0F, 0x0A, 0xCD, 0x80, 0x89, 0x7D, 0xFA},
|
||||
{0xCD, 0x2A, 0x53, 0x3A, 0xDB, 0x0D, 0x7E, 0xF3},
|
||||
{0xD2, 0xC2, 0xBE, 0x27, 0xE8, 0x1B, 0x68, 0xE3},
|
||||
{0xE9, 0x24, 0xCF, 0x4F, 0x89, 0x3C, 0x5B, 0x0A},
|
||||
{0xA7, 0x18, 0xC3, 0x9F, 0xFA, 0x9F, 0xD7, 0x69},
|
||||
{0x77, 0x2C, 0x79, 0xB1, 0xD2, 0x31, 0x7E, 0xB1},
|
||||
{0x49, 0xAB, 0x92, 0x7F, 0xD0, 0x22, 0x00, 0xB7},
|
||||
{0xCE, 0x1C, 0x6C, 0x7D, 0x85, 0xE3, 0x4A, 0x6F},
|
||||
{0xBE, 0x91, 0xD6, 0xE1, 0x27, 0xB2, 0xE9, 0x87},
|
||||
{0x70, 0x28, 0xAE, 0x8F, 0xD1, 0xF5, 0x74, 0x1A},
|
||||
{0xAA, 0x37, 0x80, 0xBB, 0xF3, 0x22, 0x1D, 0xDE},
|
||||
{0xA6, 0xC4, 0xD2, 0x5E, 0x28, 0x93, 0xAC, 0xB3},
|
||||
{0x22, 0x07, 0x81, 0x5A, 0xE4, 0xB7, 0x1A, 0xAD},
|
||||
{0xDC, 0xCE, 0x05, 0xE7, 0x07, 0xBD, 0xF5, 0x84},
|
||||
{0x26, 0x1D, 0x39, 0x2C, 0xB3, 0xBA, 0xA5, 0x85},
|
||||
{0xB4, 0xF7, 0x0F, 0x72, 0xFB, 0x04, 0xF0, 0xDC},
|
||||
{0x95, 0xBA, 0xA9, 0x4E, 0x87, 0x36, 0xF2, 0x89},
|
||||
{0xD4, 0x07, 0x3A, 0xF1, 0x5A, 0x17, 0x82, 0x0E},
|
||||
{0xEF, 0x6F, 0xAF, 0xA7, 0x66, 0x1A, 0x7E, 0x89},
|
||||
{0xC1, 0x97, 0xF5, 0x58, 0x74, 0x8A, 0x20, 0xE7},
|
||||
{0x43, 0x34, 0xCF, 0xDA, 0x22, 0xC4, 0x86, 0xC8},
|
||||
{0x08, 0xD7, 0xB4, 0xFB, 0x62, 0x9D, 0x08, 0x85}
|
||||
};
|
||||
|
||||
static unsigned char cbc_key[8] =
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
static unsigned char cbc2_key[8] =
|
||||
{ 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86 };
|
||||
static unsigned char cbc3_key[8] =
|
||||
{ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
|
||||
static unsigned char cbc_iv[8] =
|
||||
{ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
|
||||
/*
|
||||
* Changed the following text constant to binary so it will work on ebcdic
|
||||
* machines :-)
|
||||
*/
|
||||
/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
|
||||
static unsigned char cbc_data[40] = {
|
||||
0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20,
|
||||
0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
|
||||
0x68, 0x65, 0x20, 0x74, 0x69, 0x6D, 0x65, 0x20,
|
||||
0x66, 0x6F, 0x72, 0x20, 0x00, 0x31, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
static unsigned char cbc_ok[32] = {
|
||||
0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
|
||||
0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb,
|
||||
0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68,
|
||||
0x1d, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4
|
||||
};
|
||||
|
||||
# ifdef SCREW_THE_PARITY
|
||||
# error "SCREW_THE_PARITY is not meant to be defined."
|
||||
# error "Original vectors are preserved for reference only."
|
||||
static unsigned char cbc2_key[8] =
|
||||
{ 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 };
|
||||
static unsigned char xcbc_ok[32] = {
|
||||
0x86, 0x74, 0x81, 0x0D, 0x61, 0xA4, 0xA5, 0x48,
|
||||
0xB9, 0x93, 0x03, 0xE1, 0xB8, 0xBB, 0xBD, 0xBD,
|
||||
0x64, 0x30, 0x0B, 0xB9, 0x06, 0x65, 0x81, 0x76,
|
||||
0x04, 0x1D, 0x77, 0x62, 0x17, 0xCA, 0x2B, 0xD2,
|
||||
};
|
||||
# else
|
||||
static unsigned char xcbc_ok[32] = {
|
||||
0x84, 0x6B, 0x29, 0x14, 0x85, 0x1E, 0x9A, 0x29,
|
||||
0x54, 0x73, 0x2F, 0x8A, 0xA0, 0xA6, 0x11, 0xC1,
|
||||
0x15, 0xCD, 0xC2, 0xD7, 0x95, 0x1B, 0x10, 0x53,
|
||||
0xA6, 0x3C, 0x5E, 0x03, 0xB2, 0x1A, 0xA3, 0xC4,
|
||||
};
|
||||
# endif
|
||||
|
||||
static unsigned char cbc3_ok[32] = {
|
||||
0x3F, 0xE3, 0x01, 0xC9, 0x62, 0xAC, 0x01, 0xD0,
|
||||
0x22, 0x13, 0x76, 0x3C, 0x1C, 0xBD, 0x4C, 0xDC,
|
||||
0x79, 0x96, 0x57, 0xC0, 0x64, 0xEC, 0xF5, 0xD4,
|
||||
0x1C, 0x67, 0x38, 0x12, 0xCF, 0xDE, 0x96, 0x75
|
||||
};
|
||||
|
||||
static unsigned char pcbc_ok[32] = {
|
||||
0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4,
|
||||
0x6d, 0xec, 0xb4, 0x70, 0xa0, 0xe5, 0x6b, 0x15,
|
||||
0xae, 0xa6, 0xbf, 0x61, 0xed, 0x7d, 0x9c, 0x9f,
|
||||
0xf7, 0x17, 0x46, 0x3b, 0x8a, 0xb3, 0xcc, 0x88
|
||||
};
|
||||
|
||||
static unsigned char cfb_key[8] =
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
static unsigned char cfb_iv[8] =
|
||||
{ 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
|
||||
static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
|
||||
static unsigned char plain[24] = {
|
||||
0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
|
||||
0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher8[24] = {
|
||||
0xf3, 0x1f, 0xda, 0x07, 0x01, 0x14, 0x62, 0xee, 0x18, 0x7f, 0x43, 0xd8,
|
||||
0x0a, 0x7c, 0xd9, 0xb5, 0xb0, 0xd2, 0x90, 0xda, 0x6e, 0x5b, 0x9a, 0x87
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher16[24] = {
|
||||
0xF3, 0x09, 0x87, 0x87, 0x7F, 0x57, 0xF7, 0x3C, 0x36, 0xB6, 0xDB, 0x70,
|
||||
0xD8, 0xD5, 0x34, 0x19, 0xD3, 0x86, 0xB2, 0x23, 0xB7, 0xB2, 0xAD, 0x1B
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher32[24] = {
|
||||
0xF3, 0x09, 0x62, 0x49, 0xA4, 0xDF, 0xA4, 0x9F, 0x33, 0xDC, 0x7B, 0xAD,
|
||||
0x4C, 0xC8, 0x9F, 0x64, 0xE4, 0x53, 0xE5, 0xEC, 0x67, 0x20, 0xDA, 0xB6
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher48[24] = {
|
||||
0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x30, 0xB5, 0x15, 0xEC, 0xBB, 0x85,
|
||||
0x97, 0x5A, 0x13, 0x8C, 0x68, 0x60, 0xE2, 0x38, 0x34, 0x3C, 0xDC, 0x1F
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher64[24] = {
|
||||
0xF3, 0x09, 0x62, 0x49, 0xC7, 0xF4, 0x6E, 0x51, 0xA6, 0x9E, 0x83, 0x9B,
|
||||
0x1A, 0x92, 0xF7, 0x84, 0x03, 0x46, 0x71, 0x33, 0x89, 0x8E, 0xA6, 0x22
|
||||
};
|
||||
|
||||
static unsigned char ofb_key[8] =
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||
static unsigned char ofb_iv[8] =
|
||||
{ 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };
|
||||
static unsigned char ofb_buf1[24], ofb_buf2[24], ofb_tmp[8];
|
||||
static unsigned char ofb_cipher[24] = {
|
||||
0xf3, 0x09, 0x62, 0x49, 0xc7, 0xf4, 0x6e, 0x51,
|
||||
0x35, 0xf2, 0x4a, 0x24, 0x2e, 0xeb, 0x3d, 0x3f,
|
||||
0x3d, 0x6d, 0x5b, 0xe3, 0x25, 0x5a, 0xf8, 0xc3
|
||||
};
|
||||
static DES_LONG cbc_cksum_ret = 0xF7FE62B4L;
|
||||
static unsigned char cbc_cksum_data[8] =
|
||||
{ 0x1D, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4 };
|
||||
|
||||
static char *pt(unsigned char *p);
|
||||
static int cfb_test(int bits, unsigned char *cfb_cipher);
|
||||
static int cfb64_test(unsigned char *cfb_cipher);
|
||||
static int ede_cfb64_test(unsigned char *cfb_cipher);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int j, err = 0;
|
||||
unsigned int i;
|
||||
DES_cblock in, out, outin, iv3;
|
||||
DES_key_schedule ks, ks2, ks3;
|
||||
unsigned char cbc_in[40];
|
||||
unsigned char cbc_out[40];
|
||||
DES_LONG cs;
|
||||
unsigned char cret[8];
|
||||
DES_LONG lqret[4];
|
||||
int num;
|
||||
char *str;
|
||||
|
||||
printf("Doing ecb\n");
|
||||
for (i = 0; i < NUM_TESTS; i++) {
|
||||
DES_set_key_unchecked(&key_data[i], &ks);
|
||||
memcpy(in, plain_data[i], 8);
|
||||
memset(out, 0, 8);
|
||||
memset(outin, 0, 8);
|
||||
DES_ecb_encrypt(&in, &out, &ks, DES_ENCRYPT);
|
||||
DES_ecb_encrypt(&out, &outin, &ks, DES_DECRYPT);
|
||||
|
||||
if (memcmp(out, cipher_data[i], 8) != 0) {
|
||||
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(in), pt(cipher_data[i]),
|
||||
pt(out));
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(in, outin, 8) != 0) {
|
||||
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing ede ecb\n");
|
||||
for (i = 0; i < (NUM_TESTS - 2); i++) {
|
||||
DES_set_key_unchecked(&key_data[i], &ks);
|
||||
DES_set_key_unchecked(&key_data[i + 1], &ks2);
|
||||
DES_set_key_unchecked(&key_data[i + 2], &ks3);
|
||||
memcpy(in, plain_data[i], 8);
|
||||
memset(out, 0, 8);
|
||||
memset(outin, 0, 8);
|
||||
DES_ecb3_encrypt(&in,&out,&ks,&ks2,&ks,DES_ENCRYPT);
|
||||
DES_ecb3_encrypt(&out,&outin,&ks,&ks2,&ks,DES_DECRYPT);
|
||||
|
||||
if (memcmp(out, cipher_ecb2[i], 8) != 0) {
|
||||
printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(in), pt(cipher_ecb2[i]),
|
||||
pt(out));
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(in, outin, 8) != 0) {
|
||||
printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
|
||||
i + 1, pt(key_data[i]), pt(out), pt(in), pt(outin));
|
||||
err = 1;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
printf("Doing cbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
DES_ncbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, &ks,
|
||||
&iv3, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, cbc_ok, 32) != 0) {
|
||||
printf("cbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
DES_ncbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, &ks,
|
||||
&iv3, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data)) != 0) {
|
||||
printf("cbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing desx cbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
DES_xcbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, &ks,
|
||||
&iv3, &cbc2_key, &cbc3_key, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, xcbc_ok, 32) != 0) {
|
||||
printf("des_xcbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
DES_xcbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, &ks,
|
||||
&iv3, &cbc2_key, &cbc3_key, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
printf("des_xcbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
printf("Doing ede cbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
if ((j = DES_set_key_checked(&cbc2_key, &ks2)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
if ((j = DES_set_key_checked(&cbc3_key, &ks3)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
i = strlen((char *)cbc_data) + 1;
|
||||
/* i=((i+7)/8)*8; */
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
|
||||
DES_ede3_cbc_encrypt(cbc_data, cbc_out, 16L, &ks, &ks2, &ks3, &iv3,
|
||||
DES_ENCRYPT);
|
||||
DES_ede3_cbc_encrypt(&(cbc_data[16]), &(cbc_out[16]), i - 16, &ks, &ks2,
|
||||
&ks3, &iv3, DES_ENCRYPT);
|
||||
if (memcmp
|
||||
(cbc_out, cbc3_ok,
|
||||
(unsigned int)(strlen((char *)cbc_data) + 1 + 7) / 8 * 8) != 0) {
|
||||
unsigned int n;
|
||||
|
||||
printf("des_ede3_cbc_encrypt encrypt error\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc_out[n]);
|
||||
printf("\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc3_ok[n]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(iv3, cbc_iv, sizeof(cbc_iv));
|
||||
DES_ede3_cbc_encrypt(cbc_out, cbc_in, i, &ks, &ks2, &ks3, &iv3, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
unsigned int n;
|
||||
|
||||
printf("DES_ede3_cbc_encrypt decrypt error\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc_data[n]);
|
||||
printf("\n");
|
||||
for (n = 0; n < i; ++n)
|
||||
printf(" %02x", cbc_in[n]);
|
||||
printf("\n");
|
||||
err = 1;
|
||||
}
|
||||
# ifndef LIBDES_LIT
|
||||
printf("Doing pcbc\n");
|
||||
if ((j = DES_set_key_checked(&cbc_key, &ks)) != 0) {
|
||||
printf("Key error %d\n", j);
|
||||
err = 1;
|
||||
}
|
||||
memset(cbc_out, 0, 40);
|
||||
memset(cbc_in, 0, 40);
|
||||
DES_pcbc_encrypt(cbc_data, cbc_out, strlen((char *)cbc_data) + 1, &ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
if (memcmp(cbc_out, pcbc_ok, 32) != 0) {
|
||||
printf("pcbc_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
DES_pcbc_encrypt(cbc_out, cbc_in, strlen((char *)cbc_data) + 1, &ks,
|
||||
&cbc_iv, DES_DECRYPT);
|
||||
if (memcmp(cbc_in, cbc_data, strlen((char *)cbc_data) + 1) != 0) {
|
||||
printf("pcbc_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ");
|
||||
printf("cfb8 ");
|
||||
err += cfb_test(8, cfb_cipher8);
|
||||
printf("cfb16 ");
|
||||
err += cfb_test(16, cfb_cipher16);
|
||||
printf("cfb32 ");
|
||||
err += cfb_test(32, cfb_cipher32);
|
||||
printf("cfb48 ");
|
||||
err += cfb_test(48, cfb_cipher48);
|
||||
printf("cfb64 ");
|
||||
err += cfb_test(64, cfb_cipher64);
|
||||
|
||||
printf("cfb64() ");
|
||||
err += cfb64_test(cfb_cipher64);
|
||||
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
for (i = 0; i < sizeof(plain); i++)
|
||||
DES_cfb_encrypt(&(plain[i]), &(cfb_buf1[i]),
|
||||
8, 1, &ks, &cfb_tmp, DES_ENCRYPT);
|
||||
if (memcmp(cfb_cipher8, cfb_buf1, sizeof(plain)) != 0) {
|
||||
printf("cfb_encrypt small encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
for (i = 0; i < sizeof(plain); i++)
|
||||
DES_cfb_encrypt(&(cfb_buf1[i]), &(cfb_buf2[i]),
|
||||
8, 1, &ks, &cfb_tmp, DES_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
|
||||
printf("cfb_encrypt small decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("ede_cfb64() ");
|
||||
err += ede_cfb64_test(cfb_cipher64);
|
||||
|
||||
printf("done\n");
|
||||
|
||||
printf("Doing ofb\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
DES_ofb_encrypt(plain, ofb_buf1, 64, sizeof(plain) / 8, &ks, &ofb_tmp);
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ofb_encrypt encrypt error\n");
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
|
||||
ofb_buf1[8 + 0], ofb_buf1[8 + 1], ofb_buf1[8 + 2],
|
||||
ofb_buf1[8 + 3], ofb_buf1[8 + 4], ofb_buf1[8 + 5],
|
||||
ofb_buf1[8 + 6], ofb_buf1[8 + 7]);
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", ofb_buf1[8 + 0],
|
||||
ofb_cipher[8 + 1], ofb_cipher[8 + 2], ofb_cipher[8 + 3],
|
||||
ofb_buf1[8 + 4], ofb_cipher[8 + 5], ofb_cipher[8 + 6],
|
||||
ofb_cipher[8 + 7]);
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
DES_ofb_encrypt(ofb_buf1, ofb_buf2, 64, sizeof(ofb_buf1) / 8, &ks,
|
||||
&ofb_tmp);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ofb_encrypt decrypt error\n");
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
|
||||
ofb_buf2[8 + 0], ofb_buf2[8 + 1], ofb_buf2[8 + 2],
|
||||
ofb_buf2[8 + 3], ofb_buf2[8 + 4], ofb_buf2[8 + 5],
|
||||
ofb_buf2[8 + 6], ofb_buf2[8 + 7]);
|
||||
printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", plain[8 + 0],
|
||||
plain[8 + 1], plain[8 + 2], plain[8 + 3], plain[8 + 4],
|
||||
plain[8 + 5], plain[8 + 6], plain[8 + 7]);
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ofb64\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
memset(ofb_buf1, 0, sizeof(ofb_buf1));
|
||||
memset(ofb_buf2, 0, sizeof(ofb_buf1));
|
||||
num = 0;
|
||||
for (i = 0; i < sizeof(plain); i++) {
|
||||
DES_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, &ks, &ofb_tmp, &num);
|
||||
}
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ofb64_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
num = 0;
|
||||
DES_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), &ks, &ofb_tmp,
|
||||
&num);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing ede_ofb64\n");
|
||||
DES_set_key_checked(&ofb_key, &ks);
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
memset(ofb_buf1, 0, sizeof(ofb_buf1));
|
||||
memset(ofb_buf2, 0, sizeof(ofb_buf1));
|
||||
num = 0;
|
||||
for (i = 0; i < sizeof(plain); i++) {
|
||||
DES_ede3_ofb64_encrypt(&(plain[i]), &(ofb_buf1[i]), 1, &ks, &ks,
|
||||
&ks, &ofb_tmp, &num);
|
||||
}
|
||||
if (memcmp(ofb_cipher, ofb_buf1, sizeof(ofb_buf1)) != 0) {
|
||||
printf("ede_ofb64_encrypt encrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
memcpy(ofb_tmp, ofb_iv, sizeof(ofb_iv));
|
||||
num = 0;
|
||||
DES_ede3_ofb64_encrypt(ofb_buf1, ofb_buf2, sizeof(ofb_buf1), &ks, &ks, &ks,
|
||||
&ofb_tmp, &num);
|
||||
if (memcmp(plain, ofb_buf2, sizeof(ofb_buf2)) != 0) {
|
||||
printf("ede_ofb64_encrypt decrypt error\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing cbc_cksum\n");
|
||||
DES_set_key_checked(&cbc_key, &ks);
|
||||
cs = DES_cbc_cksum(cbc_data, &cret, strlen((char *)cbc_data), &ks,
|
||||
&cbc_iv);
|
||||
if (cs != cbc_cksum_ret) {
|
||||
printf("bad return value (%08lX), should be %08lX\n",
|
||||
(unsigned long)cs, (unsigned long)cbc_cksum_ret);
|
||||
err = 1;
|
||||
}
|
||||
if (memcmp(cret, cbc_cksum_data, 8) != 0) {
|
||||
printf("bad cbc_cksum block returned\n");
|
||||
err = 1;
|
||||
}
|
||||
|
||||
printf("Doing quad_cksum\n");
|
||||
cs = DES_quad_cksum(cbc_data, (DES_cblock *)lqret,
|
||||
(long)strlen((char *)cbc_data), 2,
|
||||
(DES_cblock *)cbc_iv);
|
||||
if (cs != 0x70d7a63aL) {
|
||||
printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
|
||||
(unsigned long)cs);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[0] != 0x327eba8dL) {
|
||||
printf("quad_cksum error, out[0] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[0], 0x327eba8dUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[1] != 0x201a49ccL) {
|
||||
printf("quad_cksum error, out[1] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[1], 0x201a49ccUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[2] != 0x70d7a63aL) {
|
||||
printf("quad_cksum error, out[2] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[2], 0x70d7a63aUL);
|
||||
err = 1;
|
||||
}
|
||||
if (lqret[3] != 0x501c2c26L) {
|
||||
printf("quad_cksum error, out[3] %08lx is not %08lx\n",
|
||||
(unsigned long)lqret[3], 0x501c2c26UL);
|
||||
err = 1;
|
||||
}
|
||||
# endif
|
||||
|
||||
printf("input word alignment test");
|
||||
for (i = 0; i < 4; i++) {
|
||||
printf(" %d", i);
|
||||
DES_ncbc_encrypt(&(cbc_out[i]), cbc_in,
|
||||
strlen((char *)cbc_data) + 1, &ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
}
|
||||
printf("\noutput word alignment test");
|
||||
for (i = 0; i < 4; i++) {
|
||||
printf(" %d", i);
|
||||
DES_ncbc_encrypt(cbc_out, &(cbc_in[i]),
|
||||
strlen((char *)cbc_data) + 1, &ks,
|
||||
&cbc_iv, DES_ENCRYPT);
|
||||
}
|
||||
printf("\n");
|
||||
printf("fast crypt test ");
|
||||
str = DES_crypt("testing", "ef");
|
||||
if (strcmp("efGnQx2725bI2", str) != 0) {
|
||||
printf("fast crypt error, %s should be efGnQx2725bI2\n", str);
|
||||
err = 1;
|
||||
}
|
||||
str = DES_crypt("bca76;23", "yA");
|
||||
if (strcmp("yA1Rp/1hZXIJk", str) != 0) {
|
||||
printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n", str);
|
||||
err = 1;
|
||||
}
|
||||
str = DES_crypt("testing", "y\202");
|
||||
if (str != NULL) {
|
||||
printf("salt error only usascii are accepted\n");
|
||||
err = 1;
|
||||
}
|
||||
str = DES_crypt("testing", "\0A");
|
||||
if (str != NULL) {
|
||||
printf("salt error cannot contain null terminator\n");
|
||||
err = 1;
|
||||
}
|
||||
str = DES_crypt("testing", "A");
|
||||
if (str != NULL) {
|
||||
printf("salt error must be at least 2\n");
|
||||
err = 1;
|
||||
}
|
||||
printf("\n");
|
||||
return (err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *p)
|
||||
{
|
||||
static char bufs[10][20];
|
||||
static int bnum = 0;
|
||||
char *ret;
|
||||
int i;
|
||||
static char *f = "0123456789ABCDEF";
|
||||
|
||||
ret = &(bufs[bnum++][0]);
|
||||
bnum %= 10;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ret[i * 2] = f[(p[i] >> 4) & 0xf];
|
||||
ret[i * 2 + 1] = f[p[i] & 0xf];
|
||||
}
|
||||
ret[16] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
|
||||
# ifndef LIBDES_LIT
|
||||
|
||||
static int cfb_test(int bits, unsigned char *cfb_cipher)
|
||||
{
|
||||
DES_key_schedule ks;
|
||||
int i, err = 0;
|
||||
|
||||
DES_set_key_checked(&cfb_key, &ks);
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
DES_cfb_encrypt(plain, cfb_buf1, bits, sizeof(plain), &ks, &cfb_tmp,
|
||||
DES_ENCRYPT);
|
||||
if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("cfb_encrypt encrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
DES_cfb_encrypt(cfb_buf1, cfb_buf2, bits, sizeof(plain), &ks, &cfb_tmp,
|
||||
DES_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static int cfb64_test(unsigned char *cfb_cipher)
|
||||
{
|
||||
DES_key_schedule ks;
|
||||
int err = 0, i, n;
|
||||
|
||||
DES_set_key_checked(&cfb_key, &ks);
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
n = 0;
|
||||
DES_cfb64_encrypt(plain, cfb_buf1, 12, &ks, &cfb_tmp, &n, DES_ENCRYPT);
|
||||
DES_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]), sizeof(plain) - 12, &ks,
|
||||
&cfb_tmp, &n, DES_ENCRYPT);
|
||||
if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("cfb_encrypt encrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
n = 0;
|
||||
DES_cfb64_encrypt(cfb_buf1, cfb_buf2, 17, &ks, &cfb_tmp, &n, DES_DECRYPT);
|
||||
DES_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
|
||||
sizeof(plain) - 17, &ks, &cfb_tmp, &n, DES_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf2[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static int ede_cfb64_test(unsigned char *cfb_cipher)
|
||||
{
|
||||
DES_key_schedule ks;
|
||||
int err = 0, i, n;
|
||||
|
||||
DES_set_key_checked(&cfb_key, &ks);
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
n = 0;
|
||||
DES_ede3_cfb64_encrypt(plain, cfb_buf1, 12, &ks, &ks, &ks, &cfb_tmp, &n,
|
||||
DES_ENCRYPT);
|
||||
DES_ede3_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]),
|
||||
sizeof(plain) - 12, &ks, &ks, &ks,
|
||||
&cfb_tmp, &n, DES_ENCRYPT);
|
||||
if (memcmp(cfb_cipher, cfb_buf1, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("ede_cfb_encrypt encrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, sizeof(cfb_iv));
|
||||
n = 0;
|
||||
DES_ede3_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)17, &ks, &ks, &ks,
|
||||
&cfb_tmp, &n, DES_DECRYPT);
|
||||
DES_ede3_cfb64_encrypt(&(cfb_buf1[17]), &(cfb_buf2[17]),
|
||||
sizeof(plain) - 17, &ks, &ks, &ks,
|
||||
&cfb_tmp, &n, DES_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, sizeof(plain)) != 0) {
|
||||
err = 1;
|
||||
printf("ede_cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf2[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
# endif
|
||||
#endif
|
||||
1
test/destest.c
Symbolic link
1
test/destest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/des/destest.c
|
||||
598
test/dhtest.c
598
test/dhtest.c
@@ -1,598 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DH
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DH support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/dh.h>
|
||||
|
||||
static int cb(int p, int n, BN_GENCB *arg);
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
static int run_rfc5114_tests(void);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BN_GENCB *_cb = NULL;
|
||||
DH *a = NULL;
|
||||
DH *b = NULL;
|
||||
const BIGNUM *ap = NULL, *ag = NULL, *apub_key = NULL, *priv_key = NULL;
|
||||
const BIGNUM *bpub_key = NULL;
|
||||
BIGNUM *bp = NULL, *bg = NULL;
|
||||
char buf[12] = {0};
|
||||
unsigned char *abuf = NULL;
|
||||
unsigned char *bbuf = NULL;
|
||||
int i, alen, blen, aout, bout;
|
||||
int ret = 1;
|
||||
BIO *out = NULL;
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed);
|
||||
|
||||
out = BIO_new(BIO_s_file());
|
||||
if (out == NULL)
|
||||
EXIT(1);
|
||||
BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
_cb = BN_GENCB_new();
|
||||
if (_cb == NULL)
|
||||
goto err;
|
||||
BN_GENCB_set(_cb, &cb, out);
|
||||
if (((a = DH_new()) == NULL)
|
||||
|| (!DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, _cb)))
|
||||
goto err;
|
||||
|
||||
if (!DH_check(a, &i))
|
||||
goto err;
|
||||
if (i & DH_CHECK_P_NOT_PRIME)
|
||||
BIO_puts(out, "p value is not prime\n");
|
||||
if (i & DH_CHECK_P_NOT_SAFE_PRIME)
|
||||
BIO_puts(out, "p value is not a safe prime\n");
|
||||
if (i & DH_UNABLE_TO_CHECK_GENERATOR)
|
||||
BIO_puts(out, "unable to check the generator value\n");
|
||||
if (i & DH_NOT_SUITABLE_GENERATOR)
|
||||
BIO_puts(out, "the g value is not a generator\n");
|
||||
|
||||
DH_get0_pqg(a, &ap, NULL, &ag);
|
||||
BIO_puts(out, "\np =");
|
||||
BN_print(out, ap);
|
||||
BIO_puts(out, "\ng =");
|
||||
BN_print(out, ag);
|
||||
BIO_puts(out, "\n");
|
||||
|
||||
b = DH_new();
|
||||
if (b == NULL)
|
||||
goto err;
|
||||
|
||||
bp = BN_dup(ap);
|
||||
bg = BN_dup(ag);
|
||||
if ((bp == NULL) || (bg == NULL) || !DH_set0_pqg(b, bp, NULL, bg))
|
||||
goto err;
|
||||
bp = bg = NULL;
|
||||
|
||||
if (!DH_generate_key(a))
|
||||
goto err;
|
||||
DH_get0_key(a, &apub_key, &priv_key);
|
||||
BIO_puts(out, "pri 1=");
|
||||
BN_print(out, priv_key);
|
||||
BIO_puts(out, "\npub 1=");
|
||||
BN_print(out, apub_key);
|
||||
BIO_puts(out, "\n");
|
||||
|
||||
if (!DH_generate_key(b))
|
||||
goto err;
|
||||
DH_get0_key(b, &bpub_key, &priv_key);
|
||||
BIO_puts(out, "pri 2=");
|
||||
BN_print(out, priv_key);
|
||||
BIO_puts(out, "\npub 2=");
|
||||
BN_print(out, bpub_key);
|
||||
BIO_puts(out, "\n");
|
||||
|
||||
alen = DH_size(a);
|
||||
abuf = OPENSSL_malloc(alen);
|
||||
if (abuf == NULL)
|
||||
goto err;
|
||||
|
||||
aout = DH_compute_key(abuf, bpub_key, a);
|
||||
|
||||
BIO_puts(out, "key1 =");
|
||||
for (i = 0; i < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
|
||||
blen = DH_size(b);
|
||||
bbuf = OPENSSL_malloc(blen);
|
||||
if (bbuf == NULL)
|
||||
goto err;
|
||||
|
||||
bout = DH_compute_key(bbuf, apub_key, b);
|
||||
|
||||
BIO_puts(out, "key2 =");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) {
|
||||
fprintf(stderr, "Error in DH routines\n");
|
||||
ret = 1;
|
||||
} else
|
||||
ret = 0;
|
||||
if (!run_rfc5114_tests())
|
||||
ret = 1;
|
||||
err:
|
||||
(void)BIO_flush(out);
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
OPENSSL_free(abuf);
|
||||
OPENSSL_free(bbuf);
|
||||
DH_free(b);
|
||||
DH_free(a);
|
||||
BN_free(bp);
|
||||
BN_free(bg);
|
||||
BN_GENCB_free(_cb);
|
||||
BIO_free(out);
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||
ret = 1;
|
||||
#endif
|
||||
|
||||
EXIT(ret);
|
||||
}
|
||||
|
||||
static int cb(int p, int n, BN_GENCB *arg)
|
||||
{
|
||||
char c = '*';
|
||||
|
||||
if (p == 0)
|
||||
c = '.';
|
||||
if (p == 1)
|
||||
c = '+';
|
||||
if (p == 2)
|
||||
c = '*';
|
||||
if (p == 3)
|
||||
c = '\n';
|
||||
BIO_write(BN_GENCB_get_arg(arg), &c, 1);
|
||||
(void)BIO_flush(BN_GENCB_get_arg(arg));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Test data from RFC 5114 */
|
||||
|
||||
static const unsigned char dhtest_1024_160_xA[] = {
|
||||
0xB9, 0xA3, 0xB3, 0xAE, 0x8F, 0xEF, 0xC1, 0xA2, 0x93, 0x04, 0x96, 0x50,
|
||||
0x70, 0x86, 0xF8, 0x45, 0x5D, 0x48, 0x94, 0x3E
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_yA[] = {
|
||||
0x2A, 0x85, 0x3B, 0x3D, 0x92, 0x19, 0x75, 0x01, 0xB9, 0x01, 0x5B, 0x2D,
|
||||
0xEB, 0x3E, 0xD8, 0x4F, 0x5E, 0x02, 0x1D, 0xCC, 0x3E, 0x52, 0xF1, 0x09,
|
||||
0xD3, 0x27, 0x3D, 0x2B, 0x75, 0x21, 0x28, 0x1C, 0xBA, 0xBE, 0x0E, 0x76,
|
||||
0xFF, 0x57, 0x27, 0xFA, 0x8A, 0xCC, 0xE2, 0x69, 0x56, 0xBA, 0x9A, 0x1F,
|
||||
0xCA, 0x26, 0xF2, 0x02, 0x28, 0xD8, 0x69, 0x3F, 0xEB, 0x10, 0x84, 0x1D,
|
||||
0x84, 0xA7, 0x36, 0x00, 0x54, 0xEC, 0xE5, 0xA7, 0xF5, 0xB7, 0xA6, 0x1A,
|
||||
0xD3, 0xDF, 0xB3, 0xC6, 0x0D, 0x2E, 0x43, 0x10, 0x6D, 0x87, 0x27, 0xDA,
|
||||
0x37, 0xDF, 0x9C, 0xCE, 0x95, 0xB4, 0x78, 0x75, 0x5D, 0x06, 0xBC, 0xEA,
|
||||
0x8F, 0x9D, 0x45, 0x96, 0x5F, 0x75, 0xA5, 0xF3, 0xD1, 0xDF, 0x37, 0x01,
|
||||
0x16, 0x5F, 0xC9, 0xE5, 0x0C, 0x42, 0x79, 0xCE, 0xB0, 0x7F, 0x98, 0x95,
|
||||
0x40, 0xAE, 0x96, 0xD5, 0xD8, 0x8E, 0xD7, 0x76
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_xB[] = {
|
||||
0x93, 0x92, 0xC9, 0xF9, 0xEB, 0x6A, 0x7A, 0x6A, 0x90, 0x22, 0xF7, 0xD8,
|
||||
0x3E, 0x72, 0x23, 0xC6, 0x83, 0x5B, 0xBD, 0xDA
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_yB[] = {
|
||||
0x71, 0x7A, 0x6C, 0xB0, 0x53, 0x37, 0x1F, 0xF4, 0xA3, 0xB9, 0x32, 0x94,
|
||||
0x1C, 0x1E, 0x56, 0x63, 0xF8, 0x61, 0xA1, 0xD6, 0xAD, 0x34, 0xAE, 0x66,
|
||||
0x57, 0x6D, 0xFB, 0x98, 0xF6, 0xC6, 0xCB, 0xF9, 0xDD, 0xD5, 0xA5, 0x6C,
|
||||
0x78, 0x33, 0xF6, 0xBC, 0xFD, 0xFF, 0x09, 0x55, 0x82, 0xAD, 0x86, 0x8E,
|
||||
0x44, 0x0E, 0x8D, 0x09, 0xFD, 0x76, 0x9E, 0x3C, 0xEC, 0xCD, 0xC3, 0xD3,
|
||||
0xB1, 0xE4, 0xCF, 0xA0, 0x57, 0x77, 0x6C, 0xAA, 0xF9, 0x73, 0x9B, 0x6A,
|
||||
0x9F, 0xEE, 0x8E, 0x74, 0x11, 0xF8, 0xD6, 0xDA, 0xC0, 0x9D, 0x6A, 0x4E,
|
||||
0xDB, 0x46, 0xCC, 0x2B, 0x5D, 0x52, 0x03, 0x09, 0x0E, 0xAE, 0x61, 0x26,
|
||||
0x31, 0x1E, 0x53, 0xFD, 0x2C, 0x14, 0xB5, 0x74, 0xE6, 0xA3, 0x10, 0x9A,
|
||||
0x3D, 0xA1, 0xBE, 0x41, 0xBD, 0xCE, 0xAA, 0x18, 0x6F, 0x5C, 0xE0, 0x67,
|
||||
0x16, 0xA2, 0xB6, 0xA0, 0x7B, 0x3C, 0x33, 0xFE
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_1024_160_Z[] = {
|
||||
0x5C, 0x80, 0x4F, 0x45, 0x4D, 0x30, 0xD9, 0xC4, 0xDF, 0x85, 0x27, 0x1F,
|
||||
0x93, 0x52, 0x8C, 0x91, 0xDF, 0x6B, 0x48, 0xAB, 0x5F, 0x80, 0xB3, 0xB5,
|
||||
0x9C, 0xAA, 0xC1, 0xB2, 0x8F, 0x8A, 0xCB, 0xA9, 0xCD, 0x3E, 0x39, 0xF3,
|
||||
0xCB, 0x61, 0x45, 0x25, 0xD9, 0x52, 0x1D, 0x2E, 0x64, 0x4C, 0x53, 0xB8,
|
||||
0x07, 0xB8, 0x10, 0xF3, 0x40, 0x06, 0x2F, 0x25, 0x7D, 0x7D, 0x6F, 0xBF,
|
||||
0xE8, 0xD5, 0xE8, 0xF0, 0x72, 0xE9, 0xB6, 0xE9, 0xAF, 0xDA, 0x94, 0x13,
|
||||
0xEA, 0xFB, 0x2E, 0x8B, 0x06, 0x99, 0xB1, 0xFB, 0x5A, 0x0C, 0xAC, 0xED,
|
||||
0xDE, 0xAE, 0xAD, 0x7E, 0x9C, 0xFB, 0xB3, 0x6A, 0xE2, 0xB4, 0x20, 0x83,
|
||||
0x5B, 0xD8, 0x3A, 0x19, 0xFB, 0x0B, 0x5E, 0x96, 0xBF, 0x8F, 0xA4, 0xD0,
|
||||
0x9E, 0x34, 0x55, 0x25, 0x16, 0x7E, 0xCD, 0x91, 0x55, 0x41, 0x6F, 0x46,
|
||||
0xF4, 0x08, 0xED, 0x31, 0xB6, 0x3C, 0x6E, 0x6D
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_xA[] = {
|
||||
0x22, 0xE6, 0x26, 0x01, 0xDB, 0xFF, 0xD0, 0x67, 0x08, 0xA6, 0x80, 0xF7,
|
||||
0x47, 0xF3, 0x61, 0xF7, 0x6D, 0x8F, 0x4F, 0x72, 0x1A, 0x05, 0x48, 0xE4,
|
||||
0x83, 0x29, 0x4B, 0x0C
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_yA[] = {
|
||||
0x1B, 0x3A, 0x63, 0x45, 0x1B, 0xD8, 0x86, 0xE6, 0x99, 0xE6, 0x7B, 0x49,
|
||||
0x4E, 0x28, 0x8B, 0xD7, 0xF8, 0xE0, 0xD3, 0x70, 0xBA, 0xDD, 0xA7, 0xA0,
|
||||
0xEF, 0xD2, 0xFD, 0xE7, 0xD8, 0xF6, 0x61, 0x45, 0xCC, 0x9F, 0x28, 0x04,
|
||||
0x19, 0x97, 0x5E, 0xB8, 0x08, 0x87, 0x7C, 0x8A, 0x4C, 0x0C, 0x8E, 0x0B,
|
||||
0xD4, 0x8D, 0x4A, 0x54, 0x01, 0xEB, 0x1E, 0x87, 0x76, 0xBF, 0xEE, 0xE1,
|
||||
0x34, 0xC0, 0x38, 0x31, 0xAC, 0x27, 0x3C, 0xD9, 0xD6, 0x35, 0xAB, 0x0C,
|
||||
0xE0, 0x06, 0xA4, 0x2A, 0x88, 0x7E, 0x3F, 0x52, 0xFB, 0x87, 0x66, 0xB6,
|
||||
0x50, 0xF3, 0x80, 0x78, 0xBC, 0x8E, 0xE8, 0x58, 0x0C, 0xEF, 0xE2, 0x43,
|
||||
0x96, 0x8C, 0xFC, 0x4F, 0x8D, 0xC3, 0xDB, 0x08, 0x45, 0x54, 0x17, 0x1D,
|
||||
0x41, 0xBF, 0x2E, 0x86, 0x1B, 0x7B, 0xB4, 0xD6, 0x9D, 0xD0, 0xE0, 0x1E,
|
||||
0xA3, 0x87, 0xCB, 0xAA, 0x5C, 0xA6, 0x72, 0xAF, 0xCB, 0xE8, 0xBD, 0xB9,
|
||||
0xD6, 0x2D, 0x4C, 0xE1, 0x5F, 0x17, 0xDD, 0x36, 0xF9, 0x1E, 0xD1, 0xEE,
|
||||
0xDD, 0x65, 0xCA, 0x4A, 0x06, 0x45, 0x5C, 0xB9, 0x4C, 0xD4, 0x0A, 0x52,
|
||||
0xEC, 0x36, 0x0E, 0x84, 0xB3, 0xC9, 0x26, 0xE2, 0x2C, 0x43, 0x80, 0xA3,
|
||||
0xBF, 0x30, 0x9D, 0x56, 0x84, 0x97, 0x68, 0xB7, 0xF5, 0x2C, 0xFD, 0xF6,
|
||||
0x55, 0xFD, 0x05, 0x3A, 0x7E, 0xF7, 0x06, 0x97, 0x9E, 0x7E, 0x58, 0x06,
|
||||
0xB1, 0x7D, 0xFA, 0xE5, 0x3A, 0xD2, 0xA5, 0xBC, 0x56, 0x8E, 0xBB, 0x52,
|
||||
0x9A, 0x7A, 0x61, 0xD6, 0x8D, 0x25, 0x6F, 0x8F, 0xC9, 0x7C, 0x07, 0x4A,
|
||||
0x86, 0x1D, 0x82, 0x7E, 0x2E, 0xBC, 0x8C, 0x61, 0x34, 0x55, 0x31, 0x15,
|
||||
0xB7, 0x0E, 0x71, 0x03, 0x92, 0x0A, 0xA1, 0x6D, 0x85, 0xE5, 0x2B, 0xCB,
|
||||
0xAB, 0x8D, 0x78, 0x6A, 0x68, 0x17, 0x8F, 0xA8, 0xFF, 0x7C, 0x2F, 0x5C,
|
||||
0x71, 0x64, 0x8D, 0x6F
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_xB[] = {
|
||||
0x4F, 0xF3, 0xBC, 0x96, 0xC7, 0xFC, 0x6A, 0x6D, 0x71, 0xD3, 0xB3, 0x63,
|
||||
0x80, 0x0A, 0x7C, 0xDF, 0xEF, 0x6F, 0xC4, 0x1B, 0x44, 0x17, 0xEA, 0x15,
|
||||
0x35, 0x3B, 0x75, 0x90
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_yB[] = {
|
||||
0x4D, 0xCE, 0xE9, 0x92, 0xA9, 0x76, 0x2A, 0x13, 0xF2, 0xF8, 0x38, 0x44,
|
||||
0xAD, 0x3D, 0x77, 0xEE, 0x0E, 0x31, 0xC9, 0x71, 0x8B, 0x3D, 0xB6, 0xC2,
|
||||
0x03, 0x5D, 0x39, 0x61, 0x18, 0x2C, 0x3E, 0x0B, 0xA2, 0x47, 0xEC, 0x41,
|
||||
0x82, 0xD7, 0x60, 0xCD, 0x48, 0xD9, 0x95, 0x99, 0x97, 0x06, 0x22, 0xA1,
|
||||
0x88, 0x1B, 0xBA, 0x2D, 0xC8, 0x22, 0x93, 0x9C, 0x78, 0xC3, 0x91, 0x2C,
|
||||
0x66, 0x61, 0xFA, 0x54, 0x38, 0xB2, 0x07, 0x66, 0x22, 0x2B, 0x75, 0xE2,
|
||||
0x4C, 0x2E, 0x3A, 0xD0, 0xC7, 0x28, 0x72, 0x36, 0x12, 0x95, 0x25, 0xEE,
|
||||
0x15, 0xB5, 0xDD, 0x79, 0x98, 0xAA, 0x04, 0xC4, 0xA9, 0x69, 0x6C, 0xAC,
|
||||
0xD7, 0x17, 0x20, 0x83, 0xA9, 0x7A, 0x81, 0x66, 0x4E, 0xAD, 0x2C, 0x47,
|
||||
0x9E, 0x44, 0x4E, 0x4C, 0x06, 0x54, 0xCC, 0x19, 0xE2, 0x8D, 0x77, 0x03,
|
||||
0xCE, 0xE8, 0xDA, 0xCD, 0x61, 0x26, 0xF5, 0xD6, 0x65, 0xEC, 0x52, 0xC6,
|
||||
0x72, 0x55, 0xDB, 0x92, 0x01, 0x4B, 0x03, 0x7E, 0xB6, 0x21, 0xA2, 0xAC,
|
||||
0x8E, 0x36, 0x5D, 0xE0, 0x71, 0xFF, 0xC1, 0x40, 0x0A, 0xCF, 0x07, 0x7A,
|
||||
0x12, 0x91, 0x3D, 0xD8, 0xDE, 0x89, 0x47, 0x34, 0x37, 0xAB, 0x7B, 0xA3,
|
||||
0x46, 0x74, 0x3C, 0x1B, 0x21, 0x5D, 0xD9, 0xC1, 0x21, 0x64, 0xA7, 0xE4,
|
||||
0x05, 0x31, 0x18, 0xD1, 0x99, 0xBE, 0xC8, 0xEF, 0x6F, 0xC5, 0x61, 0x17,
|
||||
0x0C, 0x84, 0xC8, 0x7D, 0x10, 0xEE, 0x9A, 0x67, 0x4A, 0x1F, 0xA8, 0xFF,
|
||||
0xE1, 0x3B, 0xDF, 0xBA, 0x1D, 0x44, 0xDE, 0x48, 0x94, 0x6D, 0x68, 0xDC,
|
||||
0x0C, 0xDD, 0x77, 0x76, 0x35, 0xA7, 0xAB, 0x5B, 0xFB, 0x1E, 0x4B, 0xB7,
|
||||
0xB8, 0x56, 0xF9, 0x68, 0x27, 0x73, 0x4C, 0x18, 0x41, 0x38, 0xE9, 0x15,
|
||||
0xD9, 0xC3, 0x00, 0x2E, 0xBC, 0xE5, 0x31, 0x20, 0x54, 0x6A, 0x7E, 0x20,
|
||||
0x02, 0x14, 0x2B, 0x6C
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_224_Z[] = {
|
||||
0x34, 0xD9, 0xBD, 0xDC, 0x1B, 0x42, 0x17, 0x6C, 0x31, 0x3F, 0xEA, 0x03,
|
||||
0x4C, 0x21, 0x03, 0x4D, 0x07, 0x4A, 0x63, 0x13, 0xBB, 0x4E, 0xCD, 0xB3,
|
||||
0x70, 0x3F, 0xFF, 0x42, 0x45, 0x67, 0xA4, 0x6B, 0xDF, 0x75, 0x53, 0x0E,
|
||||
0xDE, 0x0A, 0x9D, 0xA5, 0x22, 0x9D, 0xE7, 0xD7, 0x67, 0x32, 0x28, 0x6C,
|
||||
0xBC, 0x0F, 0x91, 0xDA, 0x4C, 0x3C, 0x85, 0x2F, 0xC0, 0x99, 0xC6, 0x79,
|
||||
0x53, 0x1D, 0x94, 0xC7, 0x8A, 0xB0, 0x3D, 0x9D, 0xEC, 0xB0, 0xA4, 0xE4,
|
||||
0xCA, 0x8B, 0x2B, 0xB4, 0x59, 0x1C, 0x40, 0x21, 0xCF, 0x8C, 0xE3, 0xA2,
|
||||
0x0A, 0x54, 0x1D, 0x33, 0x99, 0x40, 0x17, 0xD0, 0x20, 0x0A, 0xE2, 0xC9,
|
||||
0x51, 0x6E, 0x2F, 0xF5, 0x14, 0x57, 0x79, 0x26, 0x9E, 0x86, 0x2B, 0x0F,
|
||||
0xB4, 0x74, 0xA2, 0xD5, 0x6D, 0xC3, 0x1E, 0xD5, 0x69, 0xA7, 0x70, 0x0B,
|
||||
0x4C, 0x4A, 0xB1, 0x6B, 0x22, 0xA4, 0x55, 0x13, 0x53, 0x1E, 0xF5, 0x23,
|
||||
0xD7, 0x12, 0x12, 0x07, 0x7B, 0x5A, 0x16, 0x9B, 0xDE, 0xFF, 0xAD, 0x7A,
|
||||
0xD9, 0x60, 0x82, 0x84, 0xC7, 0x79, 0x5B, 0x6D, 0x5A, 0x51, 0x83, 0xB8,
|
||||
0x70, 0x66, 0xDE, 0x17, 0xD8, 0xD6, 0x71, 0xC9, 0xEB, 0xD8, 0xEC, 0x89,
|
||||
0x54, 0x4D, 0x45, 0xEC, 0x06, 0x15, 0x93, 0xD4, 0x42, 0xC6, 0x2A, 0xB9,
|
||||
0xCE, 0x3B, 0x1C, 0xB9, 0x94, 0x3A, 0x1D, 0x23, 0xA5, 0xEA, 0x3B, 0xCF,
|
||||
0x21, 0xA0, 0x14, 0x71, 0xE6, 0x7E, 0x00, 0x3E, 0x7F, 0x8A, 0x69, 0xC7,
|
||||
0x28, 0xBE, 0x49, 0x0B, 0x2F, 0xC8, 0x8C, 0xFE, 0xB9, 0x2D, 0xB6, 0xA2,
|
||||
0x15, 0xE5, 0xD0, 0x3C, 0x17, 0xC4, 0x64, 0xC9, 0xAC, 0x1A, 0x46, 0xE2,
|
||||
0x03, 0xE1, 0x3F, 0x95, 0x29, 0x95, 0xFB, 0x03, 0xC6, 0x9D, 0x3C, 0xC4,
|
||||
0x7F, 0xCB, 0x51, 0x0B, 0x69, 0x98, 0xFF, 0xD3, 0xAA, 0x6D, 0xE7, 0x3C,
|
||||
0xF9, 0xF6, 0x38, 0x69
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_xA[] = {
|
||||
0x08, 0x81, 0x38, 0x2C, 0xDB, 0x87, 0x66, 0x0C, 0x6D, 0xC1, 0x3E, 0x61,
|
||||
0x49, 0x38, 0xD5, 0xB9, 0xC8, 0xB2, 0xF2, 0x48, 0x58, 0x1C, 0xC5, 0xE3,
|
||||
0x1B, 0x35, 0x45, 0x43, 0x97, 0xFC, 0xE5, 0x0E
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_yA[] = {
|
||||
0x2E, 0x93, 0x80, 0xC8, 0x32, 0x3A, 0xF9, 0x75, 0x45, 0xBC, 0x49, 0x41,
|
||||
0xDE, 0xB0, 0xEC, 0x37, 0x42, 0xC6, 0x2F, 0xE0, 0xEC, 0xE8, 0x24, 0xA6,
|
||||
0xAB, 0xDB, 0xE6, 0x6C, 0x59, 0xBE, 0xE0, 0x24, 0x29, 0x11, 0xBF, 0xB9,
|
||||
0x67, 0x23, 0x5C, 0xEB, 0xA3, 0x5A, 0xE1, 0x3E, 0x4E, 0xC7, 0x52, 0xBE,
|
||||
0x63, 0x0B, 0x92, 0xDC, 0x4B, 0xDE, 0x28, 0x47, 0xA9, 0xC6, 0x2C, 0xB8,
|
||||
0x15, 0x27, 0x45, 0x42, 0x1F, 0xB7, 0xEB, 0x60, 0xA6, 0x3C, 0x0F, 0xE9,
|
||||
0x15, 0x9F, 0xCC, 0xE7, 0x26, 0xCE, 0x7C, 0xD8, 0x52, 0x3D, 0x74, 0x50,
|
||||
0x66, 0x7E, 0xF8, 0x40, 0xE4, 0x91, 0x91, 0x21, 0xEB, 0x5F, 0x01, 0xC8,
|
||||
0xC9, 0xB0, 0xD3, 0xD6, 0x48, 0xA9, 0x3B, 0xFB, 0x75, 0x68, 0x9E, 0x82,
|
||||
0x44, 0xAC, 0x13, 0x4A, 0xF5, 0x44, 0x71, 0x1C, 0xE7, 0x9A, 0x02, 0xDC,
|
||||
0xC3, 0x42, 0x26, 0x68, 0x47, 0x80, 0xDD, 0xDC, 0xB4, 0x98, 0x59, 0x41,
|
||||
0x06, 0xC3, 0x7F, 0x5B, 0xC7, 0x98, 0x56, 0x48, 0x7A, 0xF5, 0xAB, 0x02,
|
||||
0x2A, 0x2E, 0x5E, 0x42, 0xF0, 0x98, 0x97, 0xC1, 0xA8, 0x5A, 0x11, 0xEA,
|
||||
0x02, 0x12, 0xAF, 0x04, 0xD9, 0xB4, 0xCE, 0xBC, 0x93, 0x7C, 0x3C, 0x1A,
|
||||
0x3E, 0x15, 0xA8, 0xA0, 0x34, 0x2E, 0x33, 0x76, 0x15, 0xC8, 0x4E, 0x7F,
|
||||
0xE3, 0xB8, 0xB9, 0xB8, 0x7F, 0xB1, 0xE7, 0x3A, 0x15, 0xAF, 0x12, 0xA3,
|
||||
0x0D, 0x74, 0x6E, 0x06, 0xDF, 0xC3, 0x4F, 0x29, 0x0D, 0x79, 0x7C, 0xE5,
|
||||
0x1A, 0xA1, 0x3A, 0xA7, 0x85, 0xBF, 0x66, 0x58, 0xAF, 0xF5, 0xE4, 0xB0,
|
||||
0x93, 0x00, 0x3C, 0xBE, 0xAF, 0x66, 0x5B, 0x3C, 0x2E, 0x11, 0x3A, 0x3A,
|
||||
0x4E, 0x90, 0x52, 0x69, 0x34, 0x1D, 0xC0, 0x71, 0x14, 0x26, 0x68, 0x5F,
|
||||
0x4E, 0xF3, 0x7E, 0x86, 0x8A, 0x81, 0x26, 0xFF, 0x3F, 0x22, 0x79, 0xB5,
|
||||
0x7C, 0xA6, 0x7E, 0x29
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_xB[] = {
|
||||
0x7D, 0x62, 0xA7, 0xE3, 0xEF, 0x36, 0xDE, 0x61, 0x7B, 0x13, 0xD1, 0xAF,
|
||||
0xB8, 0x2C, 0x78, 0x0D, 0x83, 0xA2, 0x3B, 0xD4, 0xEE, 0x67, 0x05, 0x64,
|
||||
0x51, 0x21, 0xF3, 0x71, 0xF5, 0x46, 0xA5, 0x3D
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_yB[] = {
|
||||
0x57, 0x5F, 0x03, 0x51, 0xBD, 0x2B, 0x1B, 0x81, 0x74, 0x48, 0xBD, 0xF8,
|
||||
0x7A, 0x6C, 0x36, 0x2C, 0x1E, 0x28, 0x9D, 0x39, 0x03, 0xA3, 0x0B, 0x98,
|
||||
0x32, 0xC5, 0x74, 0x1F, 0xA2, 0x50, 0x36, 0x3E, 0x7A, 0xCB, 0xC7, 0xF7,
|
||||
0x7F, 0x3D, 0xAC, 0xBC, 0x1F, 0x13, 0x1A, 0xDD, 0x8E, 0x03, 0x36, 0x7E,
|
||||
0xFF, 0x8F, 0xBB, 0xB3, 0xE1, 0xC5, 0x78, 0x44, 0x24, 0x80, 0x9B, 0x25,
|
||||
0xAF, 0xE4, 0xD2, 0x26, 0x2A, 0x1A, 0x6F, 0xD2, 0xFA, 0xB6, 0x41, 0x05,
|
||||
0xCA, 0x30, 0xA6, 0x74, 0xE0, 0x7F, 0x78, 0x09, 0x85, 0x20, 0x88, 0x63,
|
||||
0x2F, 0xC0, 0x49, 0x23, 0x37, 0x91, 0xAD, 0x4E, 0xDD, 0x08, 0x3A, 0x97,
|
||||
0x8B, 0x88, 0x3E, 0xE6, 0x18, 0xBC, 0x5E, 0x0D, 0xD0, 0x47, 0x41, 0x5F,
|
||||
0x2D, 0x95, 0xE6, 0x83, 0xCF, 0x14, 0x82, 0x6B, 0x5F, 0xBE, 0x10, 0xD3,
|
||||
0xCE, 0x41, 0xC6, 0xC1, 0x20, 0xC7, 0x8A, 0xB2, 0x00, 0x08, 0xC6, 0x98,
|
||||
0xBF, 0x7F, 0x0B, 0xCA, 0xB9, 0xD7, 0xF4, 0x07, 0xBE, 0xD0, 0xF4, 0x3A,
|
||||
0xFB, 0x29, 0x70, 0xF5, 0x7F, 0x8D, 0x12, 0x04, 0x39, 0x63, 0xE6, 0x6D,
|
||||
0xDD, 0x32, 0x0D, 0x59, 0x9A, 0xD9, 0x93, 0x6C, 0x8F, 0x44, 0x13, 0x7C,
|
||||
0x08, 0xB1, 0x80, 0xEC, 0x5E, 0x98, 0x5C, 0xEB, 0xE1, 0x86, 0xF3, 0xD5,
|
||||
0x49, 0x67, 0x7E, 0x80, 0x60, 0x73, 0x31, 0xEE, 0x17, 0xAF, 0x33, 0x80,
|
||||
0xA7, 0x25, 0xB0, 0x78, 0x23, 0x17, 0xD7, 0xDD, 0x43, 0xF5, 0x9D, 0x7A,
|
||||
0xF9, 0x56, 0x8A, 0x9B, 0xB6, 0x3A, 0x84, 0xD3, 0x65, 0xF9, 0x22, 0x44,
|
||||
0xED, 0x12, 0x09, 0x88, 0x21, 0x93, 0x02, 0xF4, 0x29, 0x24, 0xC7, 0xCA,
|
||||
0x90, 0xB8, 0x9D, 0x24, 0xF7, 0x1B, 0x0A, 0xB6, 0x97, 0x82, 0x3D, 0x7D,
|
||||
0xEB, 0x1A, 0xFF, 0x5B, 0x0E, 0x8E, 0x4A, 0x45, 0xD4, 0x9F, 0x7F, 0x53,
|
||||
0x75, 0x7E, 0x19, 0x13
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_2048_256_Z[] = {
|
||||
0x86, 0xC7, 0x0B, 0xF8, 0xD0, 0xBB, 0x81, 0xBB, 0x01, 0x07, 0x8A, 0x17,
|
||||
0x21, 0x9C, 0xB7, 0xD2, 0x72, 0x03, 0xDB, 0x2A, 0x19, 0xC8, 0x77, 0xF1,
|
||||
0xD1, 0xF1, 0x9F, 0xD7, 0xD7, 0x7E, 0xF2, 0x25, 0x46, 0xA6, 0x8F, 0x00,
|
||||
0x5A, 0xD5, 0x2D, 0xC8, 0x45, 0x53, 0xB7, 0x8F, 0xC6, 0x03, 0x30, 0xBE,
|
||||
0x51, 0xEA, 0x7C, 0x06, 0x72, 0xCA, 0xC1, 0x51, 0x5E, 0x4B, 0x35, 0xC0,
|
||||
0x47, 0xB9, 0xA5, 0x51, 0xB8, 0x8F, 0x39, 0xDC, 0x26, 0xDA, 0x14, 0xA0,
|
||||
0x9E, 0xF7, 0x47, 0x74, 0xD4, 0x7C, 0x76, 0x2D, 0xD1, 0x77, 0xF9, 0xED,
|
||||
0x5B, 0xC2, 0xF1, 0x1E, 0x52, 0xC8, 0x79, 0xBD, 0x95, 0x09, 0x85, 0x04,
|
||||
0xCD, 0x9E, 0xEC, 0xD8, 0xA8, 0xF9, 0xB3, 0xEF, 0xBD, 0x1F, 0x00, 0x8A,
|
||||
0xC5, 0x85, 0x30, 0x97, 0xD9, 0xD1, 0x83, 0x7F, 0x2B, 0x18, 0xF7, 0x7C,
|
||||
0xD7, 0xBE, 0x01, 0xAF, 0x80, 0xA7, 0xC7, 0xB5, 0xEA, 0x3C, 0xA5, 0x4C,
|
||||
0xC0, 0x2D, 0x0C, 0x11, 0x6F, 0xEE, 0x3F, 0x95, 0xBB, 0x87, 0x39, 0x93,
|
||||
0x85, 0x87, 0x5D, 0x7E, 0x86, 0x74, 0x7E, 0x67, 0x6E, 0x72, 0x89, 0x38,
|
||||
0xAC, 0xBF, 0xF7, 0x09, 0x8E, 0x05, 0xBE, 0x4D, 0xCF, 0xB2, 0x40, 0x52,
|
||||
0xB8, 0x3A, 0xEF, 0xFB, 0x14, 0x78, 0x3F, 0x02, 0x9A, 0xDB, 0xDE, 0x7F,
|
||||
0x53, 0xFA, 0xE9, 0x20, 0x84, 0x22, 0x40, 0x90, 0xE0, 0x07, 0xCE, 0xE9,
|
||||
0x4D, 0x4B, 0xF2, 0xBA, 0xCE, 0x9F, 0xFD, 0x4B, 0x57, 0xD2, 0xAF, 0x7C,
|
||||
0x72, 0x4D, 0x0C, 0xAA, 0x19, 0xBF, 0x05, 0x01, 0xF6, 0xF1, 0x7B, 0x4A,
|
||||
0xA1, 0x0F, 0x42, 0x5E, 0x3E, 0xA7, 0x60, 0x80, 0xB4, 0xB9, 0xD6, 0xB3,
|
||||
0xCE, 0xFE, 0xA1, 0x15, 0xB2, 0xCE, 0xB8, 0x78, 0x9B, 0xB8, 0xA3, 0xB0,
|
||||
0xEA, 0x87, 0xFE, 0xBE, 0x63, 0xB6, 0xC8, 0xF8, 0x46, 0xEC, 0x6D, 0xB0,
|
||||
0xC2, 0x6C, 0x5D, 0x7C
|
||||
};
|
||||
|
||||
static const unsigned char dhtest_rfc5114_2048_224_bad_y[] = {
|
||||
0x45, 0x32, 0x5F, 0x51, 0x07, 0xE5, 0xDF, 0x1C, 0xD6, 0x02, 0x82, 0xB3,
|
||||
0x32, 0x8F, 0xA4, 0x0F, 0x87, 0xB8, 0x41, 0xFE, 0xB9, 0x35, 0xDE, 0xAD,
|
||||
0xC6, 0x26, 0x85, 0xB4, 0xFF, 0x94, 0x8C, 0x12, 0x4C, 0xBF, 0x5B, 0x20,
|
||||
0xC4, 0x46, 0xA3, 0x26, 0xEB, 0xA4, 0x25, 0xB7, 0x68, 0x8E, 0xCC, 0x67,
|
||||
0xBA, 0xEA, 0x58, 0xD0, 0xF2, 0xE9, 0xD2, 0x24, 0x72, 0x60, 0xDA, 0x88,
|
||||
0x18, 0x9C, 0xE0, 0x31, 0x6A, 0xAD, 0x50, 0x6D, 0x94, 0x35, 0x8B, 0x83,
|
||||
0x4A, 0x6E, 0xFA, 0x48, 0x73, 0x0F, 0x83, 0x87, 0xFF, 0x6B, 0x66, 0x1F,
|
||||
0xA8, 0x82, 0xC6, 0x01, 0xE5, 0x80, 0xB5, 0xB0, 0x52, 0xD0, 0xE9, 0xD8,
|
||||
0x72, 0xF9, 0x7D, 0x5B, 0x8B, 0xA5, 0x4C, 0xA5, 0x25, 0x95, 0x74, 0xE2,
|
||||
0x7A, 0x61, 0x4E, 0xA7, 0x8F, 0x12, 0xE2, 0xD2, 0x9D, 0x8C, 0x02, 0x70,
|
||||
0x34, 0x44, 0x32, 0xC7, 0xB2, 0xF3, 0xB9, 0xFE, 0x17, 0x2B, 0xD6, 0x1F,
|
||||
0x8B, 0x7E, 0x4A, 0xFA, 0xA3, 0xB5, 0x3E, 0x7A, 0x81, 0x9A, 0x33, 0x66,
|
||||
0x62, 0xA4, 0x50, 0x18, 0x3E, 0xA2, 0x5F, 0x00, 0x07, 0xD8, 0x9B, 0x22,
|
||||
0xE4, 0xEC, 0x84, 0xD5, 0xEB, 0x5A, 0xF3, 0x2A, 0x31, 0x23, 0xD8, 0x44,
|
||||
0x22, 0x2A, 0x8B, 0x37, 0x44, 0xCC, 0xC6, 0x87, 0x4B, 0xBE, 0x50, 0x9D,
|
||||
0x4A, 0xC4, 0x8E, 0x45, 0xCF, 0x72, 0x4D, 0xC0, 0x89, 0xB3, 0x72, 0xED,
|
||||
0x33, 0x2C, 0xBC, 0x7F, 0x16, 0x39, 0x3B, 0xEB, 0xD2, 0xDD, 0xA8, 0x01,
|
||||
0x73, 0x84, 0x62, 0xB9, 0x29, 0xD2, 0xC9, 0x51, 0x32, 0x9E, 0x7A, 0x6A,
|
||||
0xCF, 0xC1, 0x0A, 0xDB, 0x0E, 0xE0, 0x62, 0x77, 0x6F, 0x59, 0x62, 0x72,
|
||||
0x5A, 0x69, 0xA6, 0x5B, 0x70, 0xCA, 0x65, 0xC4, 0x95, 0x6F, 0x9A, 0xC2,
|
||||
0xDF, 0x72, 0x6D, 0xB1, 0x1E, 0x54, 0x7B, 0x51, 0xB4, 0xEF, 0x7F, 0x89,
|
||||
0x93, 0x74, 0x89, 0x59
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
DH *(*get_param) (void);
|
||||
const unsigned char *xA;
|
||||
size_t xA_len;
|
||||
const unsigned char *yA;
|
||||
size_t yA_len;
|
||||
const unsigned char *xB;
|
||||
size_t xB_len;
|
||||
const unsigned char *yB;
|
||||
size_t yB_len;
|
||||
const unsigned char *Z;
|
||||
size_t Z_len;
|
||||
} rfc5114_td;
|
||||
|
||||
# define make_rfc5114_td(pre) { \
|
||||
DH_get_##pre, \
|
||||
dhtest_##pre##_xA, sizeof(dhtest_##pre##_xA), \
|
||||
dhtest_##pre##_yA, sizeof(dhtest_##pre##_yA), \
|
||||
dhtest_##pre##_xB, sizeof(dhtest_##pre##_xB), \
|
||||
dhtest_##pre##_yB, sizeof(dhtest_##pre##_yB), \
|
||||
dhtest_##pre##_Z, sizeof(dhtest_##pre##_Z) \
|
||||
}
|
||||
|
||||
static const rfc5114_td rfctd[] = {
|
||||
make_rfc5114_td(1024_160),
|
||||
make_rfc5114_td(2048_224),
|
||||
make_rfc5114_td(2048_256)
|
||||
};
|
||||
|
||||
static int run_rfc5114_tests(void)
|
||||
{
|
||||
int i;
|
||||
DH *dhA = NULL;
|
||||
DH *dhB = NULL;
|
||||
unsigned char *Z1 = NULL;
|
||||
unsigned char *Z2 = NULL;
|
||||
const rfc5114_td *td = NULL;
|
||||
BIGNUM *bady = NULL, *priv_key = NULL, *pub_key = NULL;
|
||||
const BIGNUM *pub_key_tmp;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(rfctd); i++) {
|
||||
td = rfctd + i;
|
||||
/* Set up DH structures setting key components */
|
||||
dhA = td->get_param();
|
||||
dhB = td->get_param();
|
||||
if ((dhA == NULL) || (dhB == NULL))
|
||||
goto bad_err;
|
||||
|
||||
priv_key = BN_bin2bn(td->xA, td->xA_len, NULL);
|
||||
pub_key = BN_bin2bn(td->yA, td->yA_len, NULL);
|
||||
if (priv_key == NULL || pub_key == NULL
|
||||
|| !DH_set0_key(dhA, pub_key, priv_key))
|
||||
goto bad_err;
|
||||
|
||||
priv_key = BN_bin2bn(td->xB, td->xB_len, NULL);
|
||||
pub_key = BN_bin2bn(td->yB, td->yB_len, NULL);
|
||||
|
||||
if (priv_key == NULL || pub_key == NULL
|
||||
|| !DH_set0_key(dhB, pub_key, priv_key))
|
||||
goto bad_err;
|
||||
priv_key = pub_key = NULL;
|
||||
|
||||
if ((td->Z_len != (size_t)DH_size(dhA))
|
||||
|| (td->Z_len != (size_t)DH_size(dhB)))
|
||||
goto err;
|
||||
|
||||
Z1 = OPENSSL_malloc(DH_size(dhA));
|
||||
Z2 = OPENSSL_malloc(DH_size(dhB));
|
||||
if ((Z1 == NULL) || (Z2 == NULL))
|
||||
goto bad_err;
|
||||
/*
|
||||
* Work out shared secrets using both sides and compare with expected
|
||||
* values.
|
||||
*/
|
||||
DH_get0_key(dhB, &pub_key_tmp, NULL);
|
||||
if (DH_compute_key(Z1, pub_key_tmp, dhA) == -1)
|
||||
goto bad_err;
|
||||
|
||||
DH_get0_key(dhA, &pub_key_tmp, NULL);
|
||||
if (DH_compute_key(Z2, pub_key_tmp, dhB) == -1)
|
||||
goto bad_err;
|
||||
|
||||
if (memcmp(Z1, td->Z, td->Z_len))
|
||||
goto err;
|
||||
if (memcmp(Z2, td->Z, td->Z_len))
|
||||
goto err;
|
||||
|
||||
printf("RFC5114 parameter test %d OK\n", i + 1);
|
||||
|
||||
DH_free(dhA);
|
||||
DH_free(dhB);
|
||||
OPENSSL_free(Z1);
|
||||
OPENSSL_free(Z2);
|
||||
dhA = NULL;
|
||||
dhB = NULL;
|
||||
Z1 = NULL;
|
||||
Z2 = NULL;
|
||||
}
|
||||
|
||||
/* Now i == OSSL_NELEM(rfctd) */
|
||||
/* RFC5114 uses unsafe primes, so now test an invalid y value */
|
||||
dhA = DH_get_2048_224();
|
||||
if (dhA == NULL)
|
||||
goto bad_err;
|
||||
Z1 = OPENSSL_malloc(DH_size(dhA));
|
||||
if (Z1 == NULL)
|
||||
goto bad_err;
|
||||
|
||||
bady = BN_bin2bn(dhtest_rfc5114_2048_224_bad_y,
|
||||
sizeof(dhtest_rfc5114_2048_224_bad_y), NULL);
|
||||
if (bady == NULL)
|
||||
goto bad_err;
|
||||
|
||||
if (!DH_generate_key(dhA))
|
||||
goto bad_err;
|
||||
|
||||
if (DH_compute_key(Z1, bady, dhA) != -1) {
|
||||
/*
|
||||
* DH_compute_key should fail with -1. If we get here we unexpectedly
|
||||
* allowed an invalid y value
|
||||
*/
|
||||
goto err;
|
||||
}
|
||||
/* We'll have a stale error on the queue from the above test so clear it */
|
||||
ERR_clear_error();
|
||||
|
||||
printf("RFC5114 parameter test %d OK\n", i + 1);
|
||||
|
||||
BN_free(bady);
|
||||
DH_free(dhA);
|
||||
OPENSSL_free(Z1);
|
||||
|
||||
return 1;
|
||||
bad_err:
|
||||
BN_free(bady);
|
||||
DH_free(dhA);
|
||||
DH_free(dhB);
|
||||
BN_free(pub_key);
|
||||
BN_free(priv_key);
|
||||
OPENSSL_free(Z1);
|
||||
OPENSSL_free(Z2);
|
||||
|
||||
fprintf(stderr, "Initialisation error RFC5114 set %d\n", i + 1);
|
||||
ERR_print_errors_fp(stderr);
|
||||
return 0;
|
||||
err:
|
||||
BN_free(bady);
|
||||
DH_free(dhA);
|
||||
DH_free(dhB);
|
||||
OPENSSL_free(Z1);
|
||||
OPENSSL_free(Z2);
|
||||
|
||||
fprintf(stderr, "Test failed RFC5114 set %d\n", i + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
1
test/dhtest.c
Symbolic link
1
test/dhtest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/dh/dhtest.c
|
||||
196
test/dsatest.c
196
test/dsatest.c
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#ifdef OPENSSL_NO_DSA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No DSA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/dsa.h>
|
||||
|
||||
static int dsa_cb(int p, int n, BN_GENCB *arg);
|
||||
|
||||
/*
|
||||
* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to FIPS
|
||||
* PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1
|
||||
*/
|
||||
static unsigned char seed[20] = {
|
||||
0xd5, 0x01, 0x4e, 0x4b, 0x60, 0xef, 0x2b, 0xa8, 0xb6, 0x21, 0x1b, 0x40,
|
||||
0x62, 0xba, 0x32, 0x24, 0xe0, 0x42, 0x7d, 0xd3,
|
||||
};
|
||||
|
||||
static unsigned char out_p[] = {
|
||||
0x8d, 0xf2, 0xa4, 0x94, 0x49, 0x22, 0x76, 0xaa,
|
||||
0x3d, 0x25, 0x75, 0x9b, 0xb0, 0x68, 0x69, 0xcb,
|
||||
0xea, 0xc0, 0xd8, 0x3a, 0xfb, 0x8d, 0x0c, 0xf7,
|
||||
0xcb, 0xb8, 0x32, 0x4f, 0x0d, 0x78, 0x82, 0xe5,
|
||||
0xd0, 0x76, 0x2f, 0xc5, 0xb7, 0x21, 0x0e, 0xaf,
|
||||
0xc2, 0xe9, 0xad, 0xac, 0x32, 0xab, 0x7a, 0xac,
|
||||
0x49, 0x69, 0x3d, 0xfb, 0xf8, 0x37, 0x24, 0xc2,
|
||||
0xec, 0x07, 0x36, 0xee, 0x31, 0xc8, 0x02, 0x91,
|
||||
};
|
||||
|
||||
static unsigned char out_q[] = {
|
||||
0xc7, 0x73, 0x21, 0x8c, 0x73, 0x7e, 0xc8, 0xee,
|
||||
0x99, 0x3b, 0x4f, 0x2d, 0xed, 0x30, 0xf4, 0x8e,
|
||||
0xda, 0xce, 0x91, 0x5f,
|
||||
};
|
||||
|
||||
static unsigned char out_g[] = {
|
||||
0x62, 0x6d, 0x02, 0x78, 0x39, 0xea, 0x0a, 0x13,
|
||||
0x41, 0x31, 0x63, 0xa5, 0x5b, 0x4c, 0xb5, 0x00,
|
||||
0x29, 0x9d, 0x55, 0x22, 0x95, 0x6c, 0xef, 0xcb,
|
||||
0x3b, 0xff, 0x10, 0xf3, 0x99, 0xce, 0x2c, 0x2e,
|
||||
0x71, 0xcb, 0x9d, 0xe5, 0xfa, 0x24, 0xba, 0xbf,
|
||||
0x58, 0xe5, 0xb7, 0x95, 0x21, 0x92, 0x5c, 0x9c,
|
||||
0xc4, 0x2e, 0x9f, 0x6f, 0x46, 0x4b, 0x08, 0x8c,
|
||||
0xc5, 0x72, 0xaf, 0x53, 0xe6, 0xd7, 0x88, 0x02,
|
||||
};
|
||||
|
||||
static const unsigned char str1[] = "12345678901234567890";
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
static BIO *bio_err = NULL;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BN_GENCB *cb;
|
||||
DSA *dsa = NULL;
|
||||
int counter, ret = 0, i, j;
|
||||
unsigned char buf[256];
|
||||
unsigned long h;
|
||||
unsigned char sig[256];
|
||||
unsigned int siglen;
|
||||
const BIGNUM *p = NULL, *q = NULL, *g = NULL;
|
||||
|
||||
if (bio_err == NULL)
|
||||
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed);
|
||||
|
||||
BIO_printf(bio_err, "test generation of DSA parameters\n");
|
||||
|
||||
cb = BN_GENCB_new();
|
||||
if (!cb)
|
||||
goto end;
|
||||
|
||||
BN_GENCB_set(cb, dsa_cb, bio_err);
|
||||
if (((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512,
|
||||
seed, 20,
|
||||
&counter,
|
||||
&h, cb))
|
||||
goto end;
|
||||
|
||||
BIO_printf(bio_err, "seed\n");
|
||||
for (i = 0; i < 20; i += 4) {
|
||||
BIO_printf(bio_err, "%02X%02X%02X%02X ",
|
||||
seed[i], seed[i + 1], seed[i + 2], seed[i + 3]);
|
||||
}
|
||||
BIO_printf(bio_err, "\ncounter=%d h=%ld\n", counter, h);
|
||||
|
||||
DSA_print(bio_err, dsa, 0);
|
||||
if (counter != 105) {
|
||||
BIO_printf(bio_err, "counter should be 105\n");
|
||||
goto end;
|
||||
}
|
||||
if (h != 2) {
|
||||
BIO_printf(bio_err, "h should be 2\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
DSA_get0_pqg(dsa, &p, &q, &g);
|
||||
i = BN_bn2bin(q, buf);
|
||||
j = sizeof(out_q);
|
||||
if ((i != j) || (memcmp(buf, out_q, i) != 0)) {
|
||||
BIO_printf(bio_err, "q value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
i = BN_bn2bin(p, buf);
|
||||
j = sizeof(out_p);
|
||||
if ((i != j) || (memcmp(buf, out_p, i) != 0)) {
|
||||
BIO_printf(bio_err, "p value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
i = BN_bn2bin(g, buf);
|
||||
j = sizeof(out_g);
|
||||
if ((i != j) || (memcmp(buf, out_g, i) != 0)) {
|
||||
BIO_printf(bio_err, "g value is wrong\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
DSA_generate_key(dsa);
|
||||
DSA_sign(0, str1, 20, sig, &siglen, dsa);
|
||||
if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
|
||||
ret = 1;
|
||||
|
||||
end:
|
||||
if (!ret)
|
||||
ERR_print_errors(bio_err);
|
||||
DSA_free(dsa);
|
||||
BN_GENCB_free(cb);
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(bio_err) <= 0)
|
||||
ret = 0;
|
||||
#endif
|
||||
BIO_free(bio_err);
|
||||
bio_err = NULL;
|
||||
EXIT(!ret);
|
||||
}
|
||||
|
||||
static int dsa_cb(int p, int n, BN_GENCB *arg)
|
||||
{
|
||||
char c = '*';
|
||||
static int ok = 0, num = 0;
|
||||
|
||||
if (p == 0) {
|
||||
c = '.';
|
||||
num++;
|
||||
};
|
||||
if (p == 1)
|
||||
c = '+';
|
||||
if (p == 2) {
|
||||
c = '*';
|
||||
ok++;
|
||||
}
|
||||
if (p == 3)
|
||||
c = '\n';
|
||||
BIO_write(BN_GENCB_get_arg(arg), &c, 1);
|
||||
(void)BIO_flush(BN_GENCB_get_arg(arg));
|
||||
|
||||
if (!ok && (p == 0) && (num > 1)) {
|
||||
BIO_printf(BN_GENCB_get_arg(arg), "error in dsatest\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
1
test/dsatest.c
Symbolic link
1
test/dsatest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/dsa/dsatest.c
|
||||
142
test/dtlstest.c
142
test/dtlstest.c
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "ssltestlib.h"
|
||||
#include "testutil.h"
|
||||
|
||||
static char *cert = NULL;
|
||||
static char *privkey = NULL;
|
||||
|
||||
#define NUM_TESTS 2
|
||||
|
||||
|
||||
#define DUMMY_CERT_STATUS_LEN 12
|
||||
|
||||
static unsigned char certstatus[] = {
|
||||
SSL3_RT_HANDSHAKE, /* Content type */
|
||||
0xfe, 0xfd, /* Record version */
|
||||
0, 1, /* Epoch */
|
||||
0, 0, 0, 0, 0, 0x0f, /* Record sequence number */
|
||||
0, DTLS1_HM_HEADER_LENGTH + DUMMY_CERT_STATUS_LEN - 2,
|
||||
SSL3_MT_CERTIFICATE_STATUS, /* Cert Status handshake message type */
|
||||
0, 0, DUMMY_CERT_STATUS_LEN, /* Message len */
|
||||
0, 5, /* Message sequence */
|
||||
0, 0, 0, /* Fragment offset */
|
||||
0, 0, DUMMY_CERT_STATUS_LEN - 2, /* Fragment len */
|
||||
0x80, 0x80, 0x80, 0x80, 0x80,
|
||||
0x80, 0x80, 0x80, 0x80, 0x80 /* Dummy data */
|
||||
};
|
||||
|
||||
#define RECORD_SEQUENCE 10
|
||||
|
||||
static int test_dtls_unprocessed(int testidx)
|
||||
{
|
||||
SSL_CTX *sctx = NULL, *cctx = NULL;
|
||||
SSL *serverssl1 = NULL, *clientssl1 = NULL;
|
||||
BIO *c_to_s_fbio, *c_to_s_mempacket;
|
||||
int testresult = 0;
|
||||
|
||||
printf("Starting Test %d\n", testidx);
|
||||
|
||||
if (!create_ssl_ctx_pair(DTLS_server_method(), DTLS_client_method(), &sctx,
|
||||
&cctx, cert, privkey)) {
|
||||
printf("Unable to create SSL_CTX pair\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!SSL_CTX_set_cipher_list(cctx, "AES128-SHA")) {
|
||||
printf("Failed setting cipher list\n");
|
||||
}
|
||||
|
||||
c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());
|
||||
if (c_to_s_fbio == NULL) {
|
||||
printf("Failed to create filter BIO\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* BIO is freed by create_ssl_connection on error */
|
||||
if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,
|
||||
c_to_s_fbio)) {
|
||||
printf("Unable to create SSL objects\n");
|
||||
ERR_print_errors_fp(stdout);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (testidx == 1)
|
||||
certstatus[RECORD_SEQUENCE] = 0xff;
|
||||
|
||||
/*
|
||||
* Inject a dummy record from the next epoch. In test 0, this should never
|
||||
* get used because the message sequence number is too big. In test 1 we set
|
||||
* the record sequence number to be way off in the future. This should not
|
||||
* have an impact on the record replay protection because the record should
|
||||
* be dropped before it is marked as arrived
|
||||
*/
|
||||
c_to_s_mempacket = SSL_get_wbio(clientssl1);
|
||||
c_to_s_mempacket = BIO_next(c_to_s_mempacket);
|
||||
mempacket_test_inject(c_to_s_mempacket, (char *)certstatus,
|
||||
sizeof(certstatus), 1, INJECT_PACKET_IGNORE_REC_SEQ);
|
||||
|
||||
if (!create_ssl_connection(serverssl1, clientssl1)) {
|
||||
printf("Unable to create SSL connection\n");
|
||||
ERR_print_errors_fp(stdout);
|
||||
goto end;
|
||||
}
|
||||
|
||||
testresult = 1;
|
||||
end:
|
||||
SSL_free(serverssl1);
|
||||
SSL_free(clientssl1);
|
||||
SSL_CTX_free(sctx);
|
||||
SSL_CTX_free(cctx);
|
||||
|
||||
return testresult;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BIO *err = NULL;
|
||||
int testresult = 1;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Invalid argument count\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cert = argv[1];
|
||||
privkey = argv[2];
|
||||
|
||||
err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
ADD_ALL_TESTS(test_dtls_unprocessed, NUM_TESTS);
|
||||
|
||||
testresult = run_tests(argv[0]);
|
||||
|
||||
bio_f_tls_dump_filter_free();
|
||||
bio_s_mempacket_test_free();
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(err) <= 0)
|
||||
testresult = 1;
|
||||
#endif
|
||||
BIO_free(err);
|
||||
|
||||
if (!testresult)
|
||||
printf("PASS\n");
|
||||
|
||||
return testresult;
|
||||
}
|
||||
1
test/dtlstest.c
Symbolic link
1
test/dtlstest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/dtlstest.c
|
||||
57
test/dummytest.c
Normal file
57
test/dummytest.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <openssl/e_os2.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *p, *q = 0, *program;
|
||||
|
||||
p = strrchr(argv[0], '/');
|
||||
if (!p)
|
||||
p = strrchr(argv[0], '\\');
|
||||
#ifdef OPENSSL_SYS_VMS
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ']');
|
||||
if (p)
|
||||
q = strrchr(p, '>');
|
||||
if (q)
|
||||
p = q;
|
||||
if (!p)
|
||||
p = strrchr(argv[0], ':');
|
||||
q = 0;
|
||||
#endif
|
||||
if (p)
|
||||
p++;
|
||||
if (!p)
|
||||
p = argv[0];
|
||||
if (p)
|
||||
q = strchr(p, '.');
|
||||
if (p && !q)
|
||||
q = p + strlen(p);
|
||||
|
||||
if (!p)
|
||||
program = BUF_strdup("(unknown)");
|
||||
else {
|
||||
program = OPENSSL_malloc((q - p) + 1);
|
||||
strncpy(program, p, q - p);
|
||||
program[q - p] = '\0';
|
||||
}
|
||||
|
||||
for (p = program; *p; p++)
|
||||
if (islower((unsigned char)(*p)))
|
||||
*p = toupper((unsigned char)(*p));
|
||||
|
||||
q = strstr(program, "TEST");
|
||||
if (q > p && q[-1] == '_')
|
||||
q--;
|
||||
*q = '\0';
|
||||
|
||||
printf("No %s support\n", program);
|
||||
|
||||
OPENSSL_free(program);
|
||||
return (0);
|
||||
}
|
||||
612
test/ecdhtest.c
612
test/ecdhtest.c
@@ -1,612 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* The Elliptic Curve Public-Key Crypto Library (ECC Code) included
|
||||
* herein is developed by SUN MICROSYSTEMS, INC., and is contributed
|
||||
* to the OpenSSL project.
|
||||
*
|
||||
* The ECC Code is licensed pursuant to the OpenSSL open source
|
||||
* license provided below.
|
||||
*
|
||||
* The ECDH software is originally written by Douglas Stebila of
|
||||
* Sun Microsystems Laboratories.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/opensslconf.h> /* for OPENSSL_NO_EC */
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#ifdef OPENSSL_NO_EC
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ECDH support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/ec.h>
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
static const int KDF1_SHA1_len = 20;
|
||||
static void *KDF1_SHA1(const void *in, size_t inlen, void *out,
|
||||
size_t *outlen)
|
||||
{
|
||||
if (*outlen < SHA_DIGEST_LENGTH)
|
||||
return NULL;
|
||||
*outlen = SHA_DIGEST_LENGTH;
|
||||
return SHA1(in, inlen, out);
|
||||
}
|
||||
|
||||
static int test_ecdh_curve(int nid, BN_CTX *ctx, BIO *out)
|
||||
{
|
||||
EC_KEY *a = NULL;
|
||||
EC_KEY *b = NULL;
|
||||
BIGNUM *x_a = NULL, *y_a = NULL, *x_b = NULL, *y_b = NULL;
|
||||
char buf[12];
|
||||
unsigned char *abuf = NULL, *bbuf = NULL;
|
||||
int i, alen, blen, aout, bout, ret = 0;
|
||||
const EC_GROUP *group;
|
||||
|
||||
a = EC_KEY_new_by_curve_name(nid);
|
||||
b = EC_KEY_new_by_curve_name(nid);
|
||||
if (a == NULL || b == NULL)
|
||||
goto err;
|
||||
|
||||
group = EC_KEY_get0_group(a);
|
||||
|
||||
if ((x_a = BN_new()) == NULL)
|
||||
goto err;
|
||||
if ((y_a = BN_new()) == NULL)
|
||||
goto err;
|
||||
if ((x_b = BN_new()) == NULL)
|
||||
goto err;
|
||||
if ((y_b = BN_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
BIO_puts(out, "Testing key generation with ");
|
||||
BIO_puts(out, OBJ_nid2sn(nid));
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
if (!EC_KEY_generate_key(a))
|
||||
goto err;
|
||||
|
||||
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
|
||||
NID_X9_62_prime_field) {
|
||||
if (!EC_POINT_get_affine_coordinates_GFp
|
||||
(group, EC_KEY_get0_public_key(a), x_a, y_a, ctx))
|
||||
goto err;
|
||||
}
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
else {
|
||||
if (!EC_POINT_get_affine_coordinates_GF2m(group,
|
||||
EC_KEY_get0_public_key(a),
|
||||
x_a, y_a, ctx))
|
||||
goto err;
|
||||
}
|
||||
# endif
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, " pri 1=");
|
||||
BN_print(out, a->priv_key);
|
||||
BIO_puts(out, "\n pub 1=");
|
||||
BN_print(out, x_a);
|
||||
BIO_puts(out, ",");
|
||||
BN_print(out, y_a);
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, " .");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
if (!EC_KEY_generate_key(b))
|
||||
goto err;
|
||||
|
||||
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==
|
||||
NID_X9_62_prime_field) {
|
||||
if (!EC_POINT_get_affine_coordinates_GFp
|
||||
(group, EC_KEY_get0_public_key(b), x_b, y_b, ctx))
|
||||
goto err;
|
||||
}
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
else {
|
||||
if (!EC_POINT_get_affine_coordinates_GF2m(group,
|
||||
EC_KEY_get0_public_key(b),
|
||||
x_b, y_b, ctx))
|
||||
goto err;
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, " pri 2=");
|
||||
BN_print(out, b->priv_key);
|
||||
BIO_puts(out, "\n pub 2=");
|
||||
BN_print(out, x_b);
|
||||
BIO_puts(out, ",");
|
||||
BN_print(out, y_b);
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
alen = KDF1_SHA1_len;
|
||||
abuf = OPENSSL_malloc(alen);
|
||||
aout =
|
||||
ECDH_compute_key(abuf, alen, EC_KEY_get0_public_key(b), a, KDF1_SHA1);
|
||||
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, " key1 =");
|
||||
for (i = 0; i < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
blen = KDF1_SHA1_len;
|
||||
bbuf = OPENSSL_malloc(blen);
|
||||
bout =
|
||||
ECDH_compute_key(bbuf, blen, EC_KEY_get0_public_key(a), b, KDF1_SHA1);
|
||||
|
||||
# ifdef NOISY
|
||||
BIO_puts(out, " key2 =");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_puts(out, "\n");
|
||||
# else
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
# endif
|
||||
|
||||
if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) {
|
||||
# ifndef NOISY
|
||||
BIO_printf(out, " failed\n\n");
|
||||
BIO_printf(out, "key a:\n");
|
||||
BIO_printf(out, "private key: ");
|
||||
BN_print(out, EC_KEY_get0_private_key(a));
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "public key (x,y): ");
|
||||
BN_print(out, x_a);
|
||||
BIO_printf(out, ",");
|
||||
BN_print(out, y_a);
|
||||
BIO_printf(out, "\nkey b:\n");
|
||||
BIO_printf(out, "private key: ");
|
||||
BN_print(out, EC_KEY_get0_private_key(b));
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "public key (x,y): ");
|
||||
BN_print(out, x_b);
|
||||
BIO_printf(out, ",");
|
||||
BN_print(out, y_b);
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "generated key a: ");
|
||||
for (i = 0; i < bout; i++) {
|
||||
sprintf(buf, "%02X", bbuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
BIO_printf(out, "generated key b: ");
|
||||
for (i = 0; i < aout; i++) {
|
||||
sprintf(buf, "%02X", abuf[i]);
|
||||
BIO_puts(out, buf);
|
||||
}
|
||||
BIO_printf(out, "\n");
|
||||
# endif
|
||||
fprintf(stderr, "Error in ECDH routines\n");
|
||||
ret = 0;
|
||||
} else {
|
||||
# ifndef NOISY
|
||||
BIO_printf(out, " ok\n");
|
||||
# endif
|
||||
ret = 1;
|
||||
}
|
||||
err:
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
OPENSSL_free(abuf);
|
||||
OPENSSL_free(bbuf);
|
||||
BN_free(x_a);
|
||||
BN_free(y_a);
|
||||
BN_free(x_b);
|
||||
BN_free(y_b);
|
||||
EC_KEY_free(b);
|
||||
EC_KEY_free(a);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const int nid;
|
||||
const char *da;
|
||||
const char *db;
|
||||
const char *Z;
|
||||
} ecdh_kat_t;
|
||||
|
||||
static const ecdh_kat_t ecdh_kats[] = {
|
||||
/* Keys and shared secrets from RFC 5114 */
|
||||
{ NID_X9_62_prime192v1,
|
||||
"323FA3169D8E9C6593F59476BC142000AB5BE0E249C43426",
|
||||
"631F95BB4A67632C9C476EEE9AB695AB240A0499307FCF62",
|
||||
"AD420182633F8526BFE954ACDA376F05E5FF4F837F54FEBE" },
|
||||
{ NID_secp224r1,
|
||||
"B558EB6C288DA707BBB4F8FBAE2AB9E9CB62E3BC5C7573E22E26D37F",
|
||||
"AC3B1ADD3D9770E6F6A708EE9F3B8E0AB3B480E9F27F85C88B5E6D18",
|
||||
"52272F50F46F4EDC9151569092F46DF2D96ECC3B6DC1714A4EA949FA" },
|
||||
{ NID_X9_62_prime256v1,
|
||||
"814264145F2F56F2E96A8E337A1284993FAF432A5ABCE59E867B7291D507A3AF",
|
||||
"2CE1788EC197E096DB95A200CC0AB26A19CE6BCCAD562B8EEE1B593761CF7F41",
|
||||
"DD0F5396219D1EA393310412D19A08F1F5811E9DC8EC8EEA7F80D21C820C2788" },
|
||||
{ NID_secp384r1,
|
||||
"D27335EA71664AF244DD14E9FD1260715DFD8A7965571C48D709EE7A7962A156"
|
||||
"D706A90CBCB5DF2986F05FEADB9376F1",
|
||||
"52D1791FDB4B70F89C0F00D456C2F7023B6125262C36A7DF1F80231121CCE3D3"
|
||||
"9BE52E00C194A4132C4A6C768BCD94D2",
|
||||
"5EA1FC4AF7256D2055981B110575E0A8CAE53160137D904C59D926EB1B8456E4"
|
||||
"27AA8A4540884C37DE159A58028ABC0E" },
|
||||
{ NID_secp521r1,
|
||||
"0113F82DA825735E3D97276683B2B74277BAD27335EA71664AF2430CC4F33459"
|
||||
"B9669EE78B3FFB9B8683015D344DCBFEF6FB9AF4C6C470BE254516CD3C1A1FB4"
|
||||
"7362",
|
||||
"00CEE3480D8645A17D249F2776D28BAE616952D1791FDB4B70F7C3378732AA1B"
|
||||
"22928448BCD1DC2496D435B01048066EBE4F72903C361B1A9DC1193DC2C9D089"
|
||||
"1B96",
|
||||
"00CDEA89621CFA46B132F9E4CFE2261CDE2D4368EB5656634C7CC98C7A00CDE5"
|
||||
"4ED1866A0DD3E6126C9D2F845DAFF82CEB1DA08F5D87521BB0EBECA77911169C"
|
||||
"20CC" },
|
||||
/* Keys and shared secrets from RFC 5903 */
|
||||
{ NID_X9_62_prime256v1,
|
||||
"C88F01F510D9AC3F70A292DAA2316DE544E9AAB8AFE84049C62A9C57862D1433",
|
||||
"C6EF9C5D78AE012A011164ACB397CE2088685D8F06BF9BE0B283AB46476BEE53",
|
||||
"D6840F6B42F6EDAFD13116E0E12565202FEF8E9ECE7DCE03812464D04B9442DE" },
|
||||
{ NID_secp384r1,
|
||||
"099F3C7034D4A2C699884D73A375A67F7624EF7C6B3C0F160647B67414DCE655"
|
||||
"E35B538041E649EE3FAEF896783AB194",
|
||||
"41CB0779B4BDB85D47846725FBEC3C9430FAB46CC8DC5060855CC9BDA0AA2942"
|
||||
"E0308312916B8ED2960E4BD55A7448FC",
|
||||
"11187331C279962D93D604243FD592CB9D0A926F422E47187521287E7156C5C4"
|
||||
"D603135569B9E9D09CF5D4A270F59746" },
|
||||
{ NID_secp521r1,
|
||||
"0037ADE9319A89F4DABDB3EF411AACCCA5123C61ACAB57B5393DCE47608172A0"
|
||||
"95AA85A30FE1C2952C6771D937BA9777F5957B2639BAB072462F68C27A57382D"
|
||||
"4A52",
|
||||
"0145BA99A847AF43793FDD0E872E7CDFA16BE30FDC780F97BCCC3F078380201E"
|
||||
"9C677D600B343757A3BDBF2A3163E4C2F869CCA7458AA4A4EFFC311F5CB15168"
|
||||
"5EB9",
|
||||
"01144C7D79AE6956BC8EDB8E7C787C4521CB086FA64407F97894E5E6B2D79B04"
|
||||
"D1427E73CA4BAA240A34786859810C06B3C715A3A8CC3151F2BEE417996D19F3"
|
||||
"DDEA" },
|
||||
/* Keys and shared secrets from RFC 7027 */
|
||||
{ NID_brainpoolP256r1,
|
||||
"81DB1EE100150FF2EA338D708271BE38300CB54241D79950F77B063039804F1D",
|
||||
"55E40BC41E37E3E2AD25C3C6654511FFA8474A91A0032087593852D3E7D76BD3",
|
||||
"89AFC39D41D3B327814B80940B042590F96556EC91E6AE7939BCE31F3A18BF2B" },
|
||||
{ NID_brainpoolP384r1,
|
||||
"1E20F5E048A5886F1F157C74E91BDE2B98C8B52D58E5003D57053FC4B0BD65D6"
|
||||
"F15EB5D1EE1610DF870795143627D042",
|
||||
"032640BC6003C59260F7250C3DB58CE647F98E1260ACCE4ACDA3DD869F74E01F"
|
||||
"8BA5E0324309DB6A9831497ABAC96670",
|
||||
"0BD9D3A7EA0B3D519D09D8E48D0785FB744A6B355E6304BC51C229FBBCE239BB"
|
||||
"ADF6403715C35D4FB2A5444F575D4F42" },
|
||||
{ NID_brainpoolP512r1,
|
||||
"16302FF0DBBB5A8D733DAB7141C1B45ACBC8715939677F6A56850A38BD87BD59"
|
||||
"B09E80279609FF333EB9D4C061231FB26F92EEB04982A5F1D1764CAD57665422",
|
||||
"230E18E1BCC88A362FA54E4EA3902009292F7F8033624FD471B5D8ACE49D12CF"
|
||||
"ABBC19963DAB8E2F1EBA00BFFB29E4D72D13F2224562F405CB80503666B25429",
|
||||
"A7927098655F1F9976FA50A9D566865DC530331846381C87256BAF3226244B76"
|
||||
"D36403C024D7BBF0AA0803EAFF405D3D24F11A9B5C0BEF679FE1454B21C4CD1F" }
|
||||
};
|
||||
|
||||
/* Given private value and NID, create EC_KEY structure */
|
||||
|
||||
static EC_KEY *mk_eckey(int nid, const char *str)
|
||||
{
|
||||
int ok = 0;
|
||||
EC_KEY *k = NULL;
|
||||
BIGNUM *priv = NULL;
|
||||
EC_POINT *pub = NULL;
|
||||
const EC_GROUP *grp;
|
||||
k = EC_KEY_new_by_curve_name(nid);
|
||||
if (!k)
|
||||
goto err;
|
||||
if(!BN_hex2bn(&priv, str))
|
||||
goto err;
|
||||
if (!priv)
|
||||
goto err;
|
||||
if (!EC_KEY_set_private_key(k, priv))
|
||||
goto err;
|
||||
grp = EC_KEY_get0_group(k);
|
||||
pub = EC_POINT_new(grp);
|
||||
if (!pub)
|
||||
goto err;
|
||||
if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL))
|
||||
goto err;
|
||||
if (!EC_KEY_set_public_key(k, pub))
|
||||
goto err;
|
||||
ok = 1;
|
||||
err:
|
||||
BN_clear_free(priv);
|
||||
EC_POINT_free(pub);
|
||||
if (ok)
|
||||
return k;
|
||||
EC_KEY_free(k);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Known answer test: compute shared secret and check it matches expected
|
||||
* value.
|
||||
*/
|
||||
|
||||
static int ecdh_kat(BIO *out, const ecdh_kat_t *kat)
|
||||
{
|
||||
int rv = 0;
|
||||
EC_KEY *key1 = NULL, *key2 = NULL;
|
||||
BIGNUM *bnz = NULL;
|
||||
unsigned char *Ztmp = NULL, *Z = NULL;
|
||||
size_t Ztmplen, Zlen;
|
||||
BIO_puts(out, "Testing ECDH shared secret with ");
|
||||
BIO_puts(out, OBJ_nid2sn(kat->nid));
|
||||
if(!BN_hex2bn(&bnz, kat->Z))
|
||||
goto err;
|
||||
key1 = mk_eckey(kat->nid, kat->da);
|
||||
key2 = mk_eckey(kat->nid, kat->db);
|
||||
if (!key1 || !key2)
|
||||
goto err;
|
||||
Ztmplen = (EC_GROUP_get_degree(EC_KEY_get0_group(key1)) + 7) / 8;
|
||||
Zlen = BN_num_bytes(bnz);
|
||||
if (Zlen > Ztmplen)
|
||||
goto err;
|
||||
if((Ztmp = OPENSSL_zalloc(Ztmplen)) == NULL)
|
||||
goto err;
|
||||
if((Z = OPENSSL_zalloc(Ztmplen)) == NULL)
|
||||
goto err;
|
||||
if(!BN_bn2binpad(bnz, Z, Ztmplen))
|
||||
goto err;
|
||||
if (!ECDH_compute_key(Ztmp, Ztmplen,
|
||||
EC_KEY_get0_public_key(key2), key1, 0))
|
||||
goto err;
|
||||
if (memcmp(Ztmp, Z, Ztmplen))
|
||||
goto err;
|
||||
memset(Ztmp, 0, Ztmplen);
|
||||
if (!ECDH_compute_key(Ztmp, Ztmplen,
|
||||
EC_KEY_get0_public_key(key1), key2, 0))
|
||||
goto err;
|
||||
if (memcmp(Ztmp, Z, Ztmplen))
|
||||
goto err;
|
||||
rv = 1;
|
||||
err:
|
||||
EC_KEY_free(key1);
|
||||
EC_KEY_free(key2);
|
||||
OPENSSL_free(Ztmp);
|
||||
OPENSSL_free(Z);
|
||||
BN_free(bnz);
|
||||
if (rv)
|
||||
BIO_puts(out, " ok\n");
|
||||
else {
|
||||
fprintf(stderr, "Error in ECDH routines\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#include "ecdhtest_cavs.h"
|
||||
|
||||
/*
|
||||
* NIST SP800-56A co-factor ECDH tests.
|
||||
* KATs taken from NIST documents with parameters:
|
||||
*
|
||||
* - (QCAVSx,QCAVSy) is the public key for CAVS.
|
||||
* - dIUT is the private key for IUT.
|
||||
* - (QIUTx,QIUTy) is the public key for IUT.
|
||||
* - ZIUT is the shared secret KAT.
|
||||
*
|
||||
* CAVS: Cryptographic Algorithm Validation System
|
||||
* IUT: Implementation Under Test
|
||||
*
|
||||
* This function tests two things:
|
||||
*
|
||||
* 1. dIUT * G = (QIUTx,QIUTy)
|
||||
* i.e. public key for IUT computes correctly.
|
||||
* 2. x-coord of cofactor * dIUT * (QCAVSx,QCAVSy) = ZIUT
|
||||
* i.e. co-factor ECDH key computes correctly.
|
||||
*
|
||||
* returns zero on failure or unsupported curve. One otherwise.
|
||||
*/
|
||||
static int ecdh_cavs_kat(BIO *out, const ecdh_cavs_kat_t *kat)
|
||||
{
|
||||
int rv = 0, is_char_two = 0;
|
||||
EC_KEY *key1 = NULL;
|
||||
EC_POINT *pub = NULL;
|
||||
const EC_GROUP *group = NULL;
|
||||
BIGNUM *bnz = NULL, *x = NULL, *y = NULL;
|
||||
unsigned char *Ztmp = NULL, *Z = NULL;
|
||||
size_t Ztmplen, Zlen;
|
||||
BIO_puts(out, "Testing ECC CDH Primitive SP800-56A with ");
|
||||
BIO_puts(out, OBJ_nid2sn(kat->nid));
|
||||
|
||||
/* dIUT is IUT's private key */
|
||||
if ((key1 = mk_eckey(kat->nid, kat->dIUT)) == NULL)
|
||||
goto err;
|
||||
/* these are cofactor ECDH KATs */
|
||||
EC_KEY_set_flags(key1, EC_FLAG_COFACTOR_ECDH);
|
||||
|
||||
if ((group = EC_KEY_get0_group(key1)) == NULL)
|
||||
goto err;
|
||||
if ((pub = EC_POINT_new(group)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_characteristic_two_field)
|
||||
is_char_two = 1;
|
||||
|
||||
/* (QIUTx, QIUTy) is IUT's public key */
|
||||
if(!BN_hex2bn(&x, kat->QIUTx))
|
||||
goto err;
|
||||
if(!BN_hex2bn(&y, kat->QIUTy))
|
||||
goto err;
|
||||
if (is_char_two) {
|
||||
#ifdef OPENSSL_NO_EC2M
|
||||
goto err;
|
||||
#else
|
||||
if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (!EC_POINT_set_affine_coordinates_GFp(group, pub, x, y, NULL))
|
||||
goto err;
|
||||
}
|
||||
/* dIUT * G = (QIUTx, QIUTy) should hold */
|
||||
if (EC_POINT_cmp(group, EC_KEY_get0_public_key(key1), pub, NULL))
|
||||
goto err;
|
||||
|
||||
/* (QCAVSx, QCAVSy) is CAVS's public key */
|
||||
if(!BN_hex2bn(&x, kat->QCAVSx))
|
||||
goto err;
|
||||
if(!BN_hex2bn(&y, kat->QCAVSy))
|
||||
goto err;
|
||||
if (is_char_two) {
|
||||
#ifdef OPENSSL_NO_EC2M
|
||||
goto err;
|
||||
#else
|
||||
if (!EC_POINT_set_affine_coordinates_GF2m(group, pub, x, y, NULL))
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (!EC_POINT_set_affine_coordinates_GFp(group, pub, x, y, NULL))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* ZIUT is the shared secret */
|
||||
if(!BN_hex2bn(&bnz, kat->ZIUT))
|
||||
goto err;
|
||||
Ztmplen = (EC_GROUP_get_degree(EC_KEY_get0_group(key1)) + 7) / 8;
|
||||
Zlen = BN_num_bytes(bnz);
|
||||
if (Zlen > Ztmplen)
|
||||
goto err;
|
||||
if((Ztmp = OPENSSL_zalloc(Ztmplen)) == NULL)
|
||||
goto err;
|
||||
if((Z = OPENSSL_zalloc(Ztmplen)) == NULL)
|
||||
goto err;
|
||||
if(!BN_bn2binpad(bnz, Z, Ztmplen))
|
||||
goto err;
|
||||
if (!ECDH_compute_key(Ztmp, Ztmplen, pub, key1, 0))
|
||||
goto err;
|
||||
/* shared secrets should be identical */
|
||||
if (memcmp(Ztmp, Z, Ztmplen))
|
||||
goto err;
|
||||
rv = 1;
|
||||
err:
|
||||
EC_KEY_free(key1);
|
||||
EC_POINT_free(pub);
|
||||
BN_free(bnz);
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
OPENSSL_free(Ztmp);
|
||||
OPENSSL_free(Z);
|
||||
if (rv) {
|
||||
BIO_puts(out, " ok\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Error in ECC CDH routines\n");
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BN_CTX *ctx = NULL;
|
||||
int nid, ret = 1;
|
||||
EC_builtin_curve *curves = NULL;
|
||||
size_t crv_len = 0, n = 0;
|
||||
BIO *out;
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed);
|
||||
|
||||
out = BIO_new(BIO_s_file());
|
||||
if (out == NULL)
|
||||
EXIT(1);
|
||||
BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
if ((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
/* get a list of all internal curves */
|
||||
crv_len = EC_get_builtin_curves(NULL, 0);
|
||||
curves = OPENSSL_malloc(sizeof(*curves) * crv_len);
|
||||
if (curves == NULL) goto err;
|
||||
|
||||
if (!EC_get_builtin_curves(curves, crv_len)) goto err;
|
||||
|
||||
/* NAMED CURVES TESTS */
|
||||
for (n = 0; n < crv_len; n++) {
|
||||
nid = curves[n].nid;
|
||||
/*
|
||||
* Skipped for X25519 because affine coordinate operations are not
|
||||
* supported for this curve.
|
||||
* Higher level ECDH tests are performed in evptests.txt instead.
|
||||
*/
|
||||
if (nid == NID_X25519)
|
||||
continue;
|
||||
if (!test_ecdh_curve(nid, ctx, out)) goto err;
|
||||
}
|
||||
|
||||
/* KATs */
|
||||
for (n = 0; n < (sizeof(ecdh_kats)/sizeof(ecdh_kat_t)); n++) {
|
||||
if (!ecdh_kat(out, &ecdh_kats[n]))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* NIST SP800-56A co-factor ECDH KATs */
|
||||
for (n = 0; n < (sizeof(ecdh_cavs_kats)/sizeof(ecdh_cavs_kat_t)); n++) {
|
||||
if (!ecdh_cavs_kat(out, &ecdh_cavs_kats[n]))
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
err:
|
||||
ERR_print_errors_fp(stderr);
|
||||
OPENSSL_free(curves);
|
||||
BN_CTX_free(ctx);
|
||||
BIO_free(out);
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||
ret = 1;
|
||||
#endif
|
||||
EXIT(ret);
|
||||
}
|
||||
#endif
|
||||
1
test/ecdhtest.c
Symbolic link
1
test/ecdhtest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/ecdh/ecdhtest.c
|
||||
519
test/ecdsatest.c
519
test/ecdsatest.c
@@ -1,519 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
||||
*
|
||||
* Portions of the attached software ("Contribution") are developed by
|
||||
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
|
||||
*
|
||||
* The Contribution is licensed pursuant to the OpenSSL open source
|
||||
* license provided above.
|
||||
*
|
||||
* The elliptic curve binary polynomial software is originally written by
|
||||
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_EC is defined */
|
||||
|
||||
#ifdef OPENSSL_NO_EC
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
puts("Elliptic curves are disabled.");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/bio.h>
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/bn.h>
|
||||
# include <openssl/ec.h>
|
||||
# ifndef OPENSSL_NO_ENGINE
|
||||
# include <openssl/engine.h>
|
||||
# endif
|
||||
# include <openssl/err.h>
|
||||
# include <openssl/rand.h>
|
||||
|
||||
static const char rnd_seed[] = "string to make the random number generator "
|
||||
"think it has entropy";
|
||||
|
||||
/* declaration of the test functions */
|
||||
int x9_62_tests(BIO *);
|
||||
int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s);
|
||||
int test_builtin(BIO *);
|
||||
|
||||
/* functions to change the RAND_METHOD */
|
||||
int change_rand(void);
|
||||
int restore_rand(void);
|
||||
int fbytes(unsigned char *buf, int num);
|
||||
|
||||
static RAND_METHOD fake_rand;
|
||||
static const RAND_METHOD *old_rand;
|
||||
|
||||
int change_rand(void)
|
||||
{
|
||||
/* save old rand method */
|
||||
if ((old_rand = RAND_get_rand_method()) == NULL)
|
||||
return 0;
|
||||
|
||||
fake_rand.seed = old_rand->seed;
|
||||
fake_rand.cleanup = old_rand->cleanup;
|
||||
fake_rand.add = old_rand->add;
|
||||
fake_rand.status = old_rand->status;
|
||||
/* use own random function */
|
||||
fake_rand.bytes = fbytes;
|
||||
fake_rand.pseudorand = old_rand->bytes;
|
||||
/* set new RAND_METHOD */
|
||||
if (!RAND_set_rand_method(&fake_rand))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int restore_rand(void)
|
||||
{
|
||||
if (!RAND_set_rand_method(old_rand))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int fbytes_counter = 0, use_fake = 0;
|
||||
static const char *numbers[8] = {
|
||||
"651056770906015076056810763456358567190100156695615665659",
|
||||
"6140507067065001063065065565667405560006161556565665656654",
|
||||
"8763001015071075675010661307616710783570106710677817767166"
|
||||
"71676178726717",
|
||||
"7000000175690566466555057817571571075705015757757057795755"
|
||||
"55657156756655",
|
||||
"1275552191113212300012030439187146164646146646466749494799",
|
||||
"1542725565216523985789236956265265265235675811949404040041",
|
||||
"1456427555219115346513212300075341203043918714616464614664"
|
||||
"64667494947990",
|
||||
"1712787255652165239672857892369562652652652356758119494040"
|
||||
"40041670216363"
|
||||
};
|
||||
|
||||
int fbytes(unsigned char *buf, int num)
|
||||
{
|
||||
int ret;
|
||||
BIGNUM *tmp = NULL;
|
||||
|
||||
if (use_fake == 0)
|
||||
return old_rand->bytes(buf, num);
|
||||
|
||||
use_fake = 0;
|
||||
|
||||
if (fbytes_counter >= 8)
|
||||
return 0;
|
||||
tmp = BN_new();
|
||||
if (!tmp)
|
||||
return 0;
|
||||
if (!BN_dec2bn(&tmp, numbers[fbytes_counter])) {
|
||||
BN_free(tmp);
|
||||
return 0;
|
||||
}
|
||||
fbytes_counter++;
|
||||
if (num != BN_num_bytes(tmp) || !BN_bn2bin(tmp, buf))
|
||||
ret = 0;
|
||||
else
|
||||
ret = 1;
|
||||
BN_free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* some tests from the X9.62 draft */
|
||||
int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in)
|
||||
{
|
||||
int ret = 0;
|
||||
const char message[] = "abc";
|
||||
unsigned char digest[20];
|
||||
unsigned int dgst_len = 0;
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
EC_KEY *key = NULL;
|
||||
ECDSA_SIG *signature = NULL;
|
||||
BIGNUM *r = NULL, *s = NULL;
|
||||
BIGNUM *kinv = NULL, *rp = NULL;
|
||||
const BIGNUM *sig_r, *sig_s;
|
||||
|
||||
if (md_ctx == NULL)
|
||||
goto x962_int_err;
|
||||
|
||||
/* get the message digest */
|
||||
if (!EVP_DigestInit(md_ctx, EVP_sha1())
|
||||
|| !EVP_DigestUpdate(md_ctx, (const void *)message, 3)
|
||||
|| !EVP_DigestFinal(md_ctx, digest, &dgst_len))
|
||||
goto x962_int_err;
|
||||
|
||||
BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));
|
||||
/* create the key */
|
||||
if ((key = EC_KEY_new_by_curve_name(nid)) == NULL)
|
||||
goto x962_int_err;
|
||||
use_fake = 1;
|
||||
if (!EC_KEY_generate_key(key))
|
||||
goto x962_int_err;
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* create the signature */
|
||||
use_fake = 1;
|
||||
/* Use ECDSA_sign_setup to avoid use of ECDSA nonces */
|
||||
if (!ECDSA_sign_setup(key, NULL, &kinv, &rp))
|
||||
goto x962_int_err;
|
||||
signature = ECDSA_do_sign_ex(digest, 20, kinv, rp, key);
|
||||
if (signature == NULL)
|
||||
goto x962_int_err;
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* compare the created signature with the expected signature */
|
||||
if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)
|
||||
goto x962_int_err;
|
||||
if (!BN_dec2bn(&r, r_in) || !BN_dec2bn(&s, s_in))
|
||||
goto x962_int_err;
|
||||
ECDSA_SIG_get0(signature, &sig_r, &sig_s);
|
||||
if (BN_cmp(sig_r, r) || BN_cmp(sig_s, s))
|
||||
goto x962_int_err;
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* verify the signature */
|
||||
if (ECDSA_do_verify(digest, 20, signature, key) != 1)
|
||||
goto x962_int_err;
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
|
||||
BIO_printf(out, " ok\n");
|
||||
ret = 1;
|
||||
x962_int_err:
|
||||
if (!ret)
|
||||
BIO_printf(out, " failed\n");
|
||||
EC_KEY_free(key);
|
||||
ECDSA_SIG_free(signature);
|
||||
BN_free(r);
|
||||
BN_free(s);
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
BN_clear_free(kinv);
|
||||
BN_clear_free(rp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int x9_62_tests(BIO *out)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
BIO_printf(out, "some tests from X9.62:\n");
|
||||
|
||||
/* set own rand method */
|
||||
if (!change_rand())
|
||||
goto x962_err;
|
||||
|
||||
if (!x9_62_test_internal(out, NID_X9_62_prime192v1,
|
||||
"3342403536405981729393488334694600415596881826869351677613",
|
||||
"5735822328888155254683894997897571951568553642892029982342"))
|
||||
goto x962_err;
|
||||
if (!x9_62_test_internal(out, NID_X9_62_prime239v1,
|
||||
"3086361431751678114926225473006680188549593787585317781474"
|
||||
"62058306432176",
|
||||
"3238135532097973577080787768312505059318910517550078427819"
|
||||
"78505179448783"))
|
||||
goto x962_err;
|
||||
# ifndef OPENSSL_NO_EC2M
|
||||
if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1,
|
||||
"87194383164871543355722284926904419997237591535066528048",
|
||||
"308992691965804947361541664549085895292153777025772063598"))
|
||||
goto x962_err;
|
||||
if (!x9_62_test_internal(out, NID_X9_62_c2tnb239v1,
|
||||
"2159633321041961198501834003903461262881815148684178964245"
|
||||
"5876922391552",
|
||||
"1970303740007316867383349976549972270528498040721988191026"
|
||||
"49413465737174"))
|
||||
goto x962_err;
|
||||
# endif
|
||||
ret = 1;
|
||||
x962_err:
|
||||
if (!restore_rand())
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_builtin(BIO *out)
|
||||
{
|
||||
EC_builtin_curve *curves = NULL;
|
||||
size_t crv_len = 0, n = 0;
|
||||
EC_KEY *eckey = NULL, *wrong_eckey = NULL;
|
||||
EC_GROUP *group;
|
||||
ECDSA_SIG *ecdsa_sig = NULL, *modified_sig = NULL;
|
||||
unsigned char digest[20], wrong_digest[20];
|
||||
unsigned char *signature = NULL;
|
||||
const unsigned char *sig_ptr;
|
||||
unsigned char *sig_ptr2;
|
||||
unsigned char *raw_buf = NULL;
|
||||
const BIGNUM *sig_r, *sig_s;
|
||||
BIGNUM *modified_r = NULL, *modified_s = NULL;
|
||||
BIGNUM *unmodified_r = NULL, *unmodified_s = NULL;
|
||||
unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len;
|
||||
int nid, ret = 0;
|
||||
|
||||
/* fill digest values with some random data */
|
||||
if (RAND_bytes(digest, 20) <= 0 || RAND_bytes(wrong_digest, 20) <= 0) {
|
||||
BIO_printf(out, "ERROR: unable to get random data\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
/*
|
||||
* create and verify a ecdsa signature with every available curve (with )
|
||||
*/
|
||||
BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() "
|
||||
"with some internal curves:\n");
|
||||
|
||||
/* get a list of all internal curves */
|
||||
crv_len = EC_get_builtin_curves(NULL, 0);
|
||||
curves = OPENSSL_malloc(sizeof(*curves) * crv_len);
|
||||
if (curves == NULL) {
|
||||
BIO_printf(out, "malloc error\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
if (!EC_get_builtin_curves(curves, crv_len)) {
|
||||
BIO_printf(out, "unable to get internal curves\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
/* now create and verify a signature for every curve */
|
||||
for (n = 0; n < crv_len; n++) {
|
||||
unsigned char dirt, offset;
|
||||
|
||||
nid = curves[n].nid;
|
||||
if (nid == NID_ipsec4 || nid == NID_X25519)
|
||||
continue;
|
||||
/* create new ecdsa key (== EC_KEY) */
|
||||
if ((eckey = EC_KEY_new()) == NULL)
|
||||
goto builtin_err;
|
||||
group = EC_GROUP_new_by_curve_name(nid);
|
||||
if (group == NULL)
|
||||
goto builtin_err;
|
||||
if (EC_KEY_set_group(eckey, group) == 0)
|
||||
goto builtin_err;
|
||||
EC_GROUP_free(group);
|
||||
degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey));
|
||||
if (degree < 160) {
|
||||
/* drop the curve */
|
||||
EC_KEY_free(eckey);
|
||||
eckey = NULL;
|
||||
continue;
|
||||
}
|
||||
BIO_printf(out, "%s: ", OBJ_nid2sn(nid));
|
||||
/* create key */
|
||||
if (!EC_KEY_generate_key(eckey)) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
/* create second key */
|
||||
if ((wrong_eckey = EC_KEY_new()) == NULL)
|
||||
goto builtin_err;
|
||||
group = EC_GROUP_new_by_curve_name(nid);
|
||||
if (group == NULL)
|
||||
goto builtin_err;
|
||||
if (EC_KEY_set_group(wrong_eckey, group) == 0)
|
||||
goto builtin_err;
|
||||
EC_GROUP_free(group);
|
||||
if (!EC_KEY_generate_key(wrong_eckey)) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* check key */
|
||||
if (!EC_KEY_check_key(eckey)) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* create signature */
|
||||
sig_len = ECDSA_size(eckey);
|
||||
if ((signature = OPENSSL_malloc(sig_len)) == NULL)
|
||||
goto builtin_err;
|
||||
if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* verify signature */
|
||||
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* verify signature with the wrong key */
|
||||
if (ECDSA_verify(0, digest, 20, signature, sig_len, wrong_eckey) == 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* wrong digest */
|
||||
if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, eckey) == 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
/* wrong length */
|
||||
if (ECDSA_verify(0, digest, 20, signature, sig_len - 1, eckey) == 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
|
||||
/*
|
||||
* Modify a single byte of the signature: to ensure we don't garble
|
||||
* the ASN1 structure, we read the raw signature and modify a byte in
|
||||
* one of the bignums directly.
|
||||
*/
|
||||
sig_ptr = signature;
|
||||
if ((ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len)) == NULL) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
ECDSA_SIG_get0(ecdsa_sig, &sig_r, &sig_s);
|
||||
|
||||
/* Store the two BIGNUMs in raw_buf. */
|
||||
r_len = BN_num_bytes(sig_r);
|
||||
s_len = BN_num_bytes(sig_s);
|
||||
bn_len = (degree + 7) / 8;
|
||||
if ((r_len > bn_len) || (s_len > bn_len)) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
buf_len = 2 * bn_len;
|
||||
if ((raw_buf = OPENSSL_zalloc(buf_len)) == NULL)
|
||||
goto builtin_err;
|
||||
BN_bn2bin(sig_r, raw_buf + bn_len - r_len);
|
||||
BN_bn2bin(sig_s, raw_buf + buf_len - s_len);
|
||||
|
||||
/* Modify a single byte in the buffer. */
|
||||
offset = raw_buf[10] % buf_len;
|
||||
dirt = raw_buf[11] ? raw_buf[11] : 1;
|
||||
raw_buf[offset] ^= dirt;
|
||||
/* Now read the BIGNUMs back in from raw_buf. */
|
||||
modified_sig = ECDSA_SIG_new();
|
||||
if (modified_sig == NULL)
|
||||
goto builtin_err;
|
||||
if (((modified_r = BN_bin2bn(raw_buf, bn_len, NULL)) == NULL)
|
||||
|| ((modified_s = BN_bin2bn(raw_buf + bn_len, bn_len, NULL)) == NULL)
|
||||
|| !ECDSA_SIG_set0(modified_sig, modified_r, modified_s)) {
|
||||
BN_free(modified_r);
|
||||
BN_free(modified_s);
|
||||
goto builtin_err;
|
||||
}
|
||||
sig_ptr2 = signature;
|
||||
sig_len = i2d_ECDSA_SIG(modified_sig, &sig_ptr2);
|
||||
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
/*
|
||||
* Sanity check: undo the modification and verify signature.
|
||||
*/
|
||||
raw_buf[offset] ^= dirt;
|
||||
if (((unmodified_r = BN_bin2bn(raw_buf, bn_len, NULL)) == NULL)
|
||||
|| ((unmodified_s = BN_bin2bn(raw_buf + bn_len, bn_len, NULL)) == NULL)
|
||||
|| !ECDSA_SIG_set0(modified_sig, unmodified_r, unmodified_s)) {
|
||||
BN_free(unmodified_r);
|
||||
BN_free(unmodified_s);
|
||||
goto builtin_err;
|
||||
}
|
||||
|
||||
sig_ptr2 = signature;
|
||||
sig_len = i2d_ECDSA_SIG(modified_sig, &sig_ptr2);
|
||||
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) {
|
||||
BIO_printf(out, " failed\n");
|
||||
goto builtin_err;
|
||||
}
|
||||
BIO_printf(out, ".");
|
||||
(void)BIO_flush(out);
|
||||
|
||||
BIO_printf(out, " ok\n");
|
||||
/* cleanup */
|
||||
/* clean bogus errors */
|
||||
ERR_clear_error();
|
||||
OPENSSL_free(signature);
|
||||
signature = NULL;
|
||||
EC_KEY_free(eckey);
|
||||
eckey = NULL;
|
||||
EC_KEY_free(wrong_eckey);
|
||||
wrong_eckey = NULL;
|
||||
ECDSA_SIG_free(ecdsa_sig);
|
||||
ecdsa_sig = NULL;
|
||||
ECDSA_SIG_free(modified_sig);
|
||||
modified_sig = NULL;
|
||||
OPENSSL_free(raw_buf);
|
||||
raw_buf = NULL;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
builtin_err:
|
||||
EC_KEY_free(eckey);
|
||||
EC_KEY_free(wrong_eckey);
|
||||
ECDSA_SIG_free(ecdsa_sig);
|
||||
ECDSA_SIG_free(modified_sig);
|
||||
OPENSSL_free(signature);
|
||||
OPENSSL_free(raw_buf);
|
||||
OPENSSL_free(curves);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ret = 1;
|
||||
BIO *out;
|
||||
char *p;
|
||||
|
||||
out = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
p = getenv("OPENSSL_DEBUG_MEMORY");
|
||||
if (p != NULL && strcmp(p, "on") == 0)
|
||||
CRYPTO_set_mem_debug(1);
|
||||
|
||||
/* initialize the prng */
|
||||
RAND_seed(rnd_seed, sizeof(rnd_seed));
|
||||
|
||||
/* the tests */
|
||||
if (!x9_62_tests(out))
|
||||
goto err;
|
||||
if (!test_builtin(out))
|
||||
goto err;
|
||||
|
||||
ret = 0;
|
||||
err:
|
||||
if (ret)
|
||||
BIO_printf(out, "\nECDSA test failed\n");
|
||||
else
|
||||
BIO_printf(out, "\nECDSA test passed\n");
|
||||
if (ret)
|
||||
ERR_print_errors(out);
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(out) <= 0)
|
||||
ret = 1;
|
||||
#endif
|
||||
BIO_free(out);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
1
test/ecdsatest.c
Symbolic link
1
test/ecdsatest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/ecdsa/ecdsatest.c
|
||||
1776
test/ectest.c
1776
test/ectest.c
File diff suppressed because it is too large
Load Diff
1
test/ectest.c
Symbolic link
1
test/ectest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/ec/ectest.c
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/e_os2.h>
|
||||
|
||||
#ifdef OPENSSL_NO_ENGINE
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ENGINE support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/buffer.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/engine.h>
|
||||
# include <openssl/err.h>
|
||||
|
||||
static void display_engine_list(void)
|
||||
{
|
||||
ENGINE *h;
|
||||
int loop;
|
||||
|
||||
h = ENGINE_get_first();
|
||||
loop = 0;
|
||||
printf("listing available engine types\n");
|
||||
while (h) {
|
||||
printf("engine %i, id = \"%s\", name = \"%s\"\n",
|
||||
loop++, ENGINE_get_id(h), ENGINE_get_name(h));
|
||||
h = ENGINE_get_next(h);
|
||||
}
|
||||
printf("end of list\n");
|
||||
/*
|
||||
* ENGINE_get_first() increases the struct_ref counter, so we must call
|
||||
* ENGINE_free() to decrease it again
|
||||
*/
|
||||
ENGINE_free(h);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ENGINE *block[512];
|
||||
char buf[256];
|
||||
const char *id, *name, *p;
|
||||
ENGINE *ptr;
|
||||
int loop;
|
||||
int to_return = 1;
|
||||
ENGINE *new_h1 = NULL;
|
||||
ENGINE *new_h2 = NULL;
|
||||
ENGINE *new_h3 = NULL;
|
||||
ENGINE *new_h4 = NULL;
|
||||
|
||||
p = getenv("OPENSSL_DEBUG_MEMORY");
|
||||
if (p != NULL && strcmp(p, "on") == 0)
|
||||
CRYPTO_set_mem_debug(1);
|
||||
|
||||
memset(block, 0, sizeof(block));
|
||||
if (((new_h1 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h1, "test_id0") ||
|
||||
!ENGINE_set_name(new_h1, "First test item") ||
|
||||
((new_h2 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h2, "test_id1") ||
|
||||
!ENGINE_set_name(new_h2, "Second test item") ||
|
||||
((new_h3 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h3, "test_id2") ||
|
||||
!ENGINE_set_name(new_h3, "Third test item") ||
|
||||
((new_h4 = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(new_h4, "test_id3") ||
|
||||
!ENGINE_set_name(new_h4, "Fourth test item")) {
|
||||
printf("Couldn't set up test ENGINE structures\n");
|
||||
goto end;
|
||||
}
|
||||
printf("\nenginetest beginning\n\n");
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h1)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
ptr = ENGINE_get_first();
|
||||
if (!ENGINE_remove(ptr)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
ENGINE_free(ptr);
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_remove(new_h2)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h4)) {
|
||||
printf("Add failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (ENGINE_add(new_h3)) {
|
||||
printf("Add *should* have failed but didn't!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Add that should fail did.\n");
|
||||
ERR_clear_error();
|
||||
if (ENGINE_remove(new_h2)) {
|
||||
printf("Remove *should* have failed but didn't!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Remove that should fail did.\n");
|
||||
ERR_clear_error();
|
||||
if (!ENGINE_remove(new_h3)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
if (!ENGINE_remove(new_h4)) {
|
||||
printf("Remove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
display_engine_list();
|
||||
/*
|
||||
* Depending on whether there's any hardware support compiled in, this
|
||||
* remove may be destined to fail.
|
||||
*/
|
||||
ptr = ENGINE_get_first();
|
||||
if (ptr)
|
||||
if (!ENGINE_remove(ptr))
|
||||
printf("Remove failed!i - probably no hardware "
|
||||
"support present.\n");
|
||||
ENGINE_free(ptr);
|
||||
display_engine_list();
|
||||
if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) {
|
||||
printf("Couldn't add and remove to an empty list!\n");
|
||||
goto end;
|
||||
} else
|
||||
printf("Successfully added and removed to an empty list!\n");
|
||||
printf("About to beef up the engine-type list\n");
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
sprintf(buf, "id%i", loop);
|
||||
id = OPENSSL_strdup(buf);
|
||||
sprintf(buf, "Fake engine type %i", loop);
|
||||
name = OPENSSL_strdup(buf);
|
||||
if (((block[loop] = ENGINE_new()) == NULL) ||
|
||||
!ENGINE_set_id(block[loop], id) ||
|
||||
!ENGINE_set_name(block[loop], name)) {
|
||||
printf("Couldn't create block of ENGINE structures.\n"
|
||||
"I'll probably also core-dump now, damn.\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
if (!ENGINE_add(block[loop])) {
|
||||
printf("\nAdding stopped at %i, (%s,%s)\n",
|
||||
loop, ENGINE_get_id(block[loop]),
|
||||
ENGINE_get_name(block[loop]));
|
||||
goto cleanup_loop;
|
||||
} else
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
cleanup_loop:
|
||||
printf("\nAbout to empty the engine-type list\n");
|
||||
while ((ptr = ENGINE_get_first()) != NULL) {
|
||||
if (!ENGINE_remove(ptr)) {
|
||||
printf("\nRemove failed!\n");
|
||||
goto end;
|
||||
}
|
||||
ENGINE_free(ptr);
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
for (loop = 0; loop < 512; loop++) {
|
||||
OPENSSL_free((void *)ENGINE_get_id(block[loop]));
|
||||
OPENSSL_free((void *)ENGINE_get_name(block[loop]));
|
||||
}
|
||||
printf("\nTests completed happily\n");
|
||||
to_return = 0;
|
||||
end:
|
||||
if (to_return)
|
||||
ERR_print_errors_fp(stderr);
|
||||
ENGINE_free(new_h1);
|
||||
ENGINE_free(new_h2);
|
||||
ENGINE_free(new_h3);
|
||||
ENGINE_free(new_h4);
|
||||
for (loop = 0; loop < 512; loop++)
|
||||
ENGINE_free(block[loop]);
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||
to_return = 1;
|
||||
#endif
|
||||
return to_return;
|
||||
}
|
||||
#endif
|
||||
1
test/enginetest.c
Symbolic link
1
test/enginetest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/engine/enginetest.c
|
||||
@@ -1,409 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
/*
|
||||
* kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
|
||||
* should never use this key anywhere but in an example.
|
||||
*/
|
||||
static const unsigned char kExampleRSAKeyDER[] = {
|
||||
0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf8,
|
||||
0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5, 0xb4, 0x59,
|
||||
0x76, 0x8c, 0x54, 0x1d, 0x79, 0xeb, 0x22, 0x52, 0x04, 0x7e, 0xd3, 0x37,
|
||||
0xeb, 0x41, 0xfd, 0x83, 0xf9, 0xf0, 0xa6, 0x85, 0x15, 0x34, 0x75, 0x71,
|
||||
0x5a, 0x84, 0xa8, 0x3c, 0xd2, 0xef, 0x5a, 0x4e, 0xd3, 0xde, 0x97, 0x8a,
|
||||
0xdd, 0xff, 0xbb, 0xcf, 0x0a, 0xaa, 0x86, 0x92, 0xbe, 0xb8, 0x50, 0xe4,
|
||||
0xcd, 0x6f, 0x80, 0x33, 0x30, 0x76, 0x13, 0x8f, 0xca, 0x7b, 0xdc, 0xec,
|
||||
0x5a, 0xca, 0x63, 0xc7, 0x03, 0x25, 0xef, 0xa8, 0x8a, 0x83, 0x58, 0x76,
|
||||
0x20, 0xfa, 0x16, 0x77, 0xd7, 0x79, 0x92, 0x63, 0x01, 0x48, 0x1a, 0xd8,
|
||||
0x7b, 0x67, 0xf1, 0x52, 0x55, 0x49, 0x4e, 0xd6, 0x6e, 0x4a, 0x5c, 0xd7,
|
||||
0x7a, 0x37, 0x36, 0x0c, 0xde, 0xdd, 0x8f, 0x44, 0xe8, 0xc2, 0xa7, 0x2c,
|
||||
0x2b, 0xb5, 0xaf, 0x64, 0x4b, 0x61, 0x07, 0x02, 0x03, 0x01, 0x00, 0x01,
|
||||
0x02, 0x81, 0x80, 0x74, 0x88, 0x64, 0x3f, 0x69, 0x45, 0x3a, 0x6d, 0xc7,
|
||||
0x7f, 0xb9, 0xa3, 0xc0, 0x6e, 0xec, 0xdc, 0xd4, 0x5a, 0xb5, 0x32, 0x85,
|
||||
0x5f, 0x19, 0xd4, 0xf8, 0xd4, 0x3f, 0x3c, 0xfa, 0xc2, 0xf6, 0x5f, 0xee,
|
||||
0xe6, 0xba, 0x87, 0x74, 0x2e, 0xc7, 0x0c, 0xd4, 0x42, 0xb8, 0x66, 0x85,
|
||||
0x9c, 0x7b, 0x24, 0x61, 0xaa, 0x16, 0x11, 0xf6, 0xb5, 0xb6, 0xa4, 0x0a,
|
||||
0xc9, 0x55, 0x2e, 0x81, 0xa5, 0x47, 0x61, 0xcb, 0x25, 0x8f, 0xc2, 0x15,
|
||||
0x7b, 0x0e, 0x7c, 0x36, 0x9f, 0x3a, 0xda, 0x58, 0x86, 0x1c, 0x5b, 0x83,
|
||||
0x79, 0xe6, 0x2b, 0xcc, 0xe6, 0xfa, 0x2c, 0x61, 0xf2, 0x78, 0x80, 0x1b,
|
||||
0xe2, 0xf3, 0x9d, 0x39, 0x2b, 0x65, 0x57, 0x91, 0x3d, 0x71, 0x99, 0x73,
|
||||
0xa5, 0xc2, 0x79, 0x20, 0x8c, 0x07, 0x4f, 0xe5, 0xb4, 0x60, 0x1f, 0x99,
|
||||
0xa2, 0xb1, 0x4f, 0x0c, 0xef, 0xbc, 0x59, 0x53, 0x00, 0x7d, 0xb1, 0x02,
|
||||
0x41, 0x00, 0xfc, 0x7e, 0x23, 0x65, 0x70, 0xf8, 0xce, 0xd3, 0x40, 0x41,
|
||||
0x80, 0x6a, 0x1d, 0x01, 0xd6, 0x01, 0xff, 0xb6, 0x1b, 0x3d, 0x3d, 0x59,
|
||||
0x09, 0x33, 0x79, 0xc0, 0x4f, 0xde, 0x96, 0x27, 0x4b, 0x18, 0xc6, 0xd9,
|
||||
0x78, 0xf1, 0xf4, 0x35, 0x46, 0xe9, 0x7c, 0x42, 0x7a, 0x5d, 0x9f, 0xef,
|
||||
0x54, 0xb8, 0xf7, 0x9f, 0xc4, 0x33, 0x6c, 0xf3, 0x8c, 0x32, 0x46, 0x87,
|
||||
0x67, 0x30, 0x7b, 0xa7, 0xac, 0xe3, 0x02, 0x41, 0x00, 0xfc, 0x2c, 0xdf,
|
||||
0x0c, 0x0d, 0x88, 0xf5, 0xb1, 0x92, 0xa8, 0x93, 0x47, 0x63, 0x55, 0xf5,
|
||||
0xca, 0x58, 0x43, 0xba, 0x1c, 0xe5, 0x9e, 0xb6, 0x95, 0x05, 0xcd, 0xb5,
|
||||
0x82, 0xdf, 0xeb, 0x04, 0x53, 0x9d, 0xbd, 0xc2, 0x38, 0x16, 0xb3, 0x62,
|
||||
0xdd, 0xa1, 0x46, 0xdb, 0x6d, 0x97, 0x93, 0x9f, 0x8a, 0xc3, 0x9b, 0x64,
|
||||
0x7e, 0x42, 0xe3, 0x32, 0x57, 0x19, 0x1b, 0xd5, 0x6e, 0x85, 0xfa, 0xb8,
|
||||
0x8d, 0x02, 0x41, 0x00, 0xbc, 0x3d, 0xde, 0x6d, 0xd6, 0x97, 0xe8, 0xba,
|
||||
0x9e, 0x81, 0x37, 0x17, 0xe5, 0xa0, 0x64, 0xc9, 0x00, 0xb7, 0xe7, 0xfe,
|
||||
0xf4, 0x29, 0xd9, 0x2e, 0x43, 0x6b, 0x19, 0x20, 0xbd, 0x99, 0x75, 0xe7,
|
||||
0x76, 0xf8, 0xd3, 0xae, 0xaf, 0x7e, 0xb8, 0xeb, 0x81, 0xf4, 0x9d, 0xfe,
|
||||
0x07, 0x2b, 0x0b, 0x63, 0x0b, 0x5a, 0x55, 0x90, 0x71, 0x7d, 0xf1, 0xdb,
|
||||
0xd9, 0xb1, 0x41, 0x41, 0x68, 0x2f, 0x4e, 0x39, 0x02, 0x40, 0x5a, 0x34,
|
||||
0x66, 0xd8, 0xf5, 0xe2, 0x7f, 0x18, 0xb5, 0x00, 0x6e, 0x26, 0x84, 0x27,
|
||||
0x14, 0x93, 0xfb, 0xfc, 0xc6, 0x0f, 0x5e, 0x27, 0xe6, 0xe1, 0xe9, 0xc0,
|
||||
0x8a, 0xe4, 0x34, 0xda, 0xe9, 0xa2, 0x4b, 0x73, 0xbc, 0x8c, 0xb9, 0xba,
|
||||
0x13, 0x6c, 0x7a, 0x2b, 0x51, 0x84, 0xa3, 0x4a, 0xe0, 0x30, 0x10, 0x06,
|
||||
0x7e, 0xed, 0x17, 0x5a, 0x14, 0x00, 0xc9, 0xef, 0x85, 0xea, 0x52, 0x2c,
|
||||
0xbc, 0x65, 0x02, 0x40, 0x51, 0xe3, 0xf2, 0x83, 0x19, 0x9b, 0xc4, 0x1e,
|
||||
0x2f, 0x50, 0x3d, 0xdf, 0x5a, 0xa2, 0x18, 0xca, 0x5f, 0x2e, 0x49, 0xaf,
|
||||
0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9, 0xd1, 0x8a,
|
||||
0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae, 0x17, 0x17,
|
||||
0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d, 0x08, 0xf1,
|
||||
0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
|
||||
};
|
||||
|
||||
static const unsigned char kMsg[] = { 1, 2, 3, 4 };
|
||||
|
||||
static const unsigned char kSignature[] = {
|
||||
0xa5, 0xf0, 0x8a, 0x47, 0x5d, 0x3c, 0xb3, 0xcc, 0xa9, 0x79, 0xaf, 0x4d,
|
||||
0x8c, 0xae, 0x4c, 0x14, 0xef, 0xc2, 0x0b, 0x34, 0x36, 0xde, 0xf4, 0x3e,
|
||||
0x3d, 0xbb, 0x4a, 0x60, 0x5c, 0xc8, 0x91, 0x28, 0xda, 0xfb, 0x7e, 0x04,
|
||||
0x96, 0x7e, 0x63, 0x13, 0x90, 0xce, 0xb9, 0xb4, 0x62, 0x7a, 0xfd, 0x09,
|
||||
0x3d, 0xc7, 0x67, 0x78, 0x54, 0x04, 0xeb, 0x52, 0x62, 0x6e, 0x24, 0x67,
|
||||
0xb4, 0x40, 0xfc, 0x57, 0x62, 0xc6, 0xf1, 0x67, 0xc1, 0x97, 0x8f, 0x6a,
|
||||
0xa8, 0xae, 0x44, 0x46, 0x5e, 0xab, 0x67, 0x17, 0x53, 0x19, 0x3a, 0xda,
|
||||
0x5a, 0xc8, 0x16, 0x3e, 0x86, 0xd5, 0xc5, 0x71, 0x2f, 0xfc, 0x23, 0x48,
|
||||
0xd9, 0x0b, 0x13, 0xdd, 0x7b, 0x5a, 0x25, 0x79, 0xef, 0xa5, 0x7b, 0x04,
|
||||
0xed, 0x44, 0xf6, 0x18, 0x55, 0xe4, 0x0a, 0xe9, 0x57, 0x79, 0x5d, 0xd7,
|
||||
0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42,
|
||||
};
|
||||
|
||||
/*
|
||||
* kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
|
||||
* PrivateKeyInfo.
|
||||
*/
|
||||
static const unsigned char kExampleRSAKeyPKCS8[] = {
|
||||
0x30, 0x82, 0x02, 0x76, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
|
||||
0x02, 0x60, 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81,
|
||||
0x00, 0xf8, 0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5,
|
||||
0xb4, 0x59, 0x76, 0x8c, 0x54, 0x1d, 0x79, 0xeb, 0x22, 0x52, 0x04, 0x7e,
|
||||
0xd3, 0x37, 0xeb, 0x41, 0xfd, 0x83, 0xf9, 0xf0, 0xa6, 0x85, 0x15, 0x34,
|
||||
0x75, 0x71, 0x5a, 0x84, 0xa8, 0x3c, 0xd2, 0xef, 0x5a, 0x4e, 0xd3, 0xde,
|
||||
0x97, 0x8a, 0xdd, 0xff, 0xbb, 0xcf, 0x0a, 0xaa, 0x86, 0x92, 0xbe, 0xb8,
|
||||
0x50, 0xe4, 0xcd, 0x6f, 0x80, 0x33, 0x30, 0x76, 0x13, 0x8f, 0xca, 0x7b,
|
||||
0xdc, 0xec, 0x5a, 0xca, 0x63, 0xc7, 0x03, 0x25, 0xef, 0xa8, 0x8a, 0x83,
|
||||
0x58, 0x76, 0x20, 0xfa, 0x16, 0x77, 0xd7, 0x79, 0x92, 0x63, 0x01, 0x48,
|
||||
0x1a, 0xd8, 0x7b, 0x67, 0xf1, 0x52, 0x55, 0x49, 0x4e, 0xd6, 0x6e, 0x4a,
|
||||
0x5c, 0xd7, 0x7a, 0x37, 0x36, 0x0c, 0xde, 0xdd, 0x8f, 0x44, 0xe8, 0xc2,
|
||||
0xa7, 0x2c, 0x2b, 0xb5, 0xaf, 0x64, 0x4b, 0x61, 0x07, 0x02, 0x03, 0x01,
|
||||
0x00, 0x01, 0x02, 0x81, 0x80, 0x74, 0x88, 0x64, 0x3f, 0x69, 0x45, 0x3a,
|
||||
0x6d, 0xc7, 0x7f, 0xb9, 0xa3, 0xc0, 0x6e, 0xec, 0xdc, 0xd4, 0x5a, 0xb5,
|
||||
0x32, 0x85, 0x5f, 0x19, 0xd4, 0xf8, 0xd4, 0x3f, 0x3c, 0xfa, 0xc2, 0xf6,
|
||||
0x5f, 0xee, 0xe6, 0xba, 0x87, 0x74, 0x2e, 0xc7, 0x0c, 0xd4, 0x42, 0xb8,
|
||||
0x66, 0x85, 0x9c, 0x7b, 0x24, 0x61, 0xaa, 0x16, 0x11, 0xf6, 0xb5, 0xb6,
|
||||
0xa4, 0x0a, 0xc9, 0x55, 0x2e, 0x81, 0xa5, 0x47, 0x61, 0xcb, 0x25, 0x8f,
|
||||
0xc2, 0x15, 0x7b, 0x0e, 0x7c, 0x36, 0x9f, 0x3a, 0xda, 0x58, 0x86, 0x1c,
|
||||
0x5b, 0x83, 0x79, 0xe6, 0x2b, 0xcc, 0xe6, 0xfa, 0x2c, 0x61, 0xf2, 0x78,
|
||||
0x80, 0x1b, 0xe2, 0xf3, 0x9d, 0x39, 0x2b, 0x65, 0x57, 0x91, 0x3d, 0x71,
|
||||
0x99, 0x73, 0xa5, 0xc2, 0x79, 0x20, 0x8c, 0x07, 0x4f, 0xe5, 0xb4, 0x60,
|
||||
0x1f, 0x99, 0xa2, 0xb1, 0x4f, 0x0c, 0xef, 0xbc, 0x59, 0x53, 0x00, 0x7d,
|
||||
0xb1, 0x02, 0x41, 0x00, 0xfc, 0x7e, 0x23, 0x65, 0x70, 0xf8, 0xce, 0xd3,
|
||||
0x40, 0x41, 0x80, 0x6a, 0x1d, 0x01, 0xd6, 0x01, 0xff, 0xb6, 0x1b, 0x3d,
|
||||
0x3d, 0x59, 0x09, 0x33, 0x79, 0xc0, 0x4f, 0xde, 0x96, 0x27, 0x4b, 0x18,
|
||||
0xc6, 0xd9, 0x78, 0xf1, 0xf4, 0x35, 0x46, 0xe9, 0x7c, 0x42, 0x7a, 0x5d,
|
||||
0x9f, 0xef, 0x54, 0xb8, 0xf7, 0x9f, 0xc4, 0x33, 0x6c, 0xf3, 0x8c, 0x32,
|
||||
0x46, 0x87, 0x67, 0x30, 0x7b, 0xa7, 0xac, 0xe3, 0x02, 0x41, 0x00, 0xfc,
|
||||
0x2c, 0xdf, 0x0c, 0x0d, 0x88, 0xf5, 0xb1, 0x92, 0xa8, 0x93, 0x47, 0x63,
|
||||
0x55, 0xf5, 0xca, 0x58, 0x43, 0xba, 0x1c, 0xe5, 0x9e, 0xb6, 0x95, 0x05,
|
||||
0xcd, 0xb5, 0x82, 0xdf, 0xeb, 0x04, 0x53, 0x9d, 0xbd, 0xc2, 0x38, 0x16,
|
||||
0xb3, 0x62, 0xdd, 0xa1, 0x46, 0xdb, 0x6d, 0x97, 0x93, 0x9f, 0x8a, 0xc3,
|
||||
0x9b, 0x64, 0x7e, 0x42, 0xe3, 0x32, 0x57, 0x19, 0x1b, 0xd5, 0x6e, 0x85,
|
||||
0xfa, 0xb8, 0x8d, 0x02, 0x41, 0x00, 0xbc, 0x3d, 0xde, 0x6d, 0xd6, 0x97,
|
||||
0xe8, 0xba, 0x9e, 0x81, 0x37, 0x17, 0xe5, 0xa0, 0x64, 0xc9, 0x00, 0xb7,
|
||||
0xe7, 0xfe, 0xf4, 0x29, 0xd9, 0x2e, 0x43, 0x6b, 0x19, 0x20, 0xbd, 0x99,
|
||||
0x75, 0xe7, 0x76, 0xf8, 0xd3, 0xae, 0xaf, 0x7e, 0xb8, 0xeb, 0x81, 0xf4,
|
||||
0x9d, 0xfe, 0x07, 0x2b, 0x0b, 0x63, 0x0b, 0x5a, 0x55, 0x90, 0x71, 0x7d,
|
||||
0xf1, 0xdb, 0xd9, 0xb1, 0x41, 0x41, 0x68, 0x2f, 0x4e, 0x39, 0x02, 0x40,
|
||||
0x5a, 0x34, 0x66, 0xd8, 0xf5, 0xe2, 0x7f, 0x18, 0xb5, 0x00, 0x6e, 0x26,
|
||||
0x84, 0x27, 0x14, 0x93, 0xfb, 0xfc, 0xc6, 0x0f, 0x5e, 0x27, 0xe6, 0xe1,
|
||||
0xe9, 0xc0, 0x8a, 0xe4, 0x34, 0xda, 0xe9, 0xa2, 0x4b, 0x73, 0xbc, 0x8c,
|
||||
0xb9, 0xba, 0x13, 0x6c, 0x7a, 0x2b, 0x51, 0x84, 0xa3, 0x4a, 0xe0, 0x30,
|
||||
0x10, 0x06, 0x7e, 0xed, 0x17, 0x5a, 0x14, 0x00, 0xc9, 0xef, 0x85, 0xea,
|
||||
0x52, 0x2c, 0xbc, 0x65, 0x02, 0x40, 0x51, 0xe3, 0xf2, 0x83, 0x19, 0x9b,
|
||||
0xc4, 0x1e, 0x2f, 0x50, 0x3d, 0xdf, 0x5a, 0xa2, 0x18, 0xca, 0x5f, 0x2e,
|
||||
0x49, 0xaf, 0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9,
|
||||
0xd1, 0x8a, 0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae,
|
||||
0x17, 0x17, 0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d,
|
||||
0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
|
||||
};
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
/*
|
||||
* kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure.
|
||||
*/
|
||||
static const unsigned char kExampleECKeyDER[] = {
|
||||
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x07, 0x0f, 0x08, 0x72, 0x7a,
|
||||
0xd4, 0xa0, 0x4a, 0x9c, 0xdd, 0x59, 0xc9, 0x4d, 0x89, 0x68, 0x77, 0x08,
|
||||
0xb5, 0x6f, 0xc9, 0x5d, 0x30, 0x77, 0x0e, 0xe8, 0xd1, 0xc9, 0xce, 0x0a,
|
||||
0x8b, 0xb4, 0x6a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
|
||||
0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0xe6, 0x2b, 0x69,
|
||||
0xe2, 0xbf, 0x65, 0x9f, 0x97, 0xbe, 0x2f, 0x1e, 0x0d, 0x94, 0x8a, 0x4c,
|
||||
0xd5, 0x97, 0x6b, 0xb7, 0xa9, 0x1e, 0x0d, 0x46, 0xfb, 0xdd, 0xa9, 0xa9,
|
||||
0x1e, 0x9d, 0xdc, 0xba, 0x5a, 0x01, 0xe7, 0xd6, 0x97, 0xa8, 0x0a, 0x18,
|
||||
0xf9, 0xc3, 0xc4, 0xa3, 0x1e, 0x56, 0xe2, 0x7c, 0x83, 0x48, 0xdb, 0x16,
|
||||
0x1a, 0x1c, 0xf5, 0x1d, 0x7e, 0xf1, 0x94, 0x2d, 0x4b, 0xcf, 0x72, 0x22,
|
||||
0xc1,
|
||||
};
|
||||
|
||||
/*
|
||||
* kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
|
||||
* structure. The private key is equal to the order and will fail to import
|
||||
*/
|
||||
static const unsigned char kExampleBadECKeyDER[] = {
|
||||
0x30, 0x66, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48,
|
||||
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03,
|
||||
0x01, 0x07, 0x04, 0x4C, 0x30, 0x4A, 0x02, 0x01, 0x01, 0x04, 0x20, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3,
|
||||
0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51, 0xA1, 0x23, 0x03, 0x21, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
|
||||
0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
|
||||
};
|
||||
#endif
|
||||
|
||||
static EVP_PKEY *load_example_rsa_key(void)
|
||||
{
|
||||
EVP_PKEY *ret = NULL;
|
||||
const unsigned char *derp = kExampleRSAKeyDER;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
RSA *rsa = NULL;
|
||||
|
||||
if (!d2i_RSAPrivateKey(&rsa, &derp, sizeof(kExampleRSAKeyDER))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pkey = EVP_PKEY_new();
|
||||
if (pkey == NULL || !EVP_PKEY_set1_RSA(pkey, rsa)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = pkey;
|
||||
pkey = NULL;
|
||||
|
||||
out:
|
||||
EVP_PKEY_free(pkey);
|
||||
RSA_free(rsa);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestSignInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
unsigned char *sig = NULL;
|
||||
size_t sig_len = 0;
|
||||
EVP_MD_CTX *md_ctx, *md_ctx_verify;
|
||||
|
||||
md_ctx = EVP_MD_CTX_new();
|
||||
md_ctx_verify = EVP_MD_CTX_new();
|
||||
if (md_ctx == NULL || md_ctx_verify == NULL)
|
||||
goto out;
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestSignInit(md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestSignUpdate(md_ctx, kMsg, sizeof(kMsg))) {
|
||||
goto out;
|
||||
}
|
||||
/* Determine the size of the signature. */
|
||||
if (!EVP_DigestSignFinal(md_ctx, NULL, &sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
/* Sanity check for testing. */
|
||||
if (sig_len != (size_t)EVP_PKEY_size(pkey)) {
|
||||
fprintf(stderr, "sig_len mismatch\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sig = OPENSSL_malloc(sig_len);
|
||||
if (sig == NULL || !EVP_DigestSignFinal(md_ctx, sig, &sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Ensure that the signature round-trips. */
|
||||
if (!EVP_DigestVerifyInit(md_ctx_verify, NULL, EVP_sha256(), NULL, pkey)
|
||||
|| !EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, sizeof(kMsg))
|
||||
|| !EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
EVP_MD_CTX_free(md_ctx_verify);
|
||||
EVP_PKEY_free(pkey);
|
||||
OPENSSL_free(sig);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_EVP_DigestVerifyInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_MD_CTX *md_ctx;
|
||||
|
||||
md_ctx = EVP_MD_CTX_new();
|
||||
|
||||
pkey = load_example_rsa_key();
|
||||
if (pkey == NULL ||
|
||||
!EVP_DigestVerifyInit(md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
|
||||
!EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg)) ||
|
||||
!EVP_DigestVerifyFinal(md_ctx, kSignature, sizeof(kSignature))) {
|
||||
goto out;
|
||||
}
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_d2i_AutoPrivateKey(const unsigned char *input,
|
||||
size_t input_len, int expected_id)
|
||||
{
|
||||
int ret = 0;
|
||||
const unsigned char *p;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p = input;
|
||||
pkey = d2i_AutoPrivateKey(NULL, &p, input_len);
|
||||
if (pkey == NULL || p != input + input_len) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey failed\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (EVP_PKEY_id(pkey) != expected_id) {
|
||||
fprintf(stderr, "Did not decode expected type\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
if (!ret) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
}
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
/* Tests loading a bad key in PKCS8 format */
|
||||
static int test_EVP_PKCS82PKEY(void)
|
||||
{
|
||||
int ret = 0;
|
||||
const unsigned char *derp = kExampleBadECKeyDER;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER));
|
||||
|
||||
if (!p8inf || derp != kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER)) {
|
||||
fprintf(stderr, "Failed to parse key\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
pkey = EVP_PKCS82PKEY(p8inf);
|
||||
if (pkey) {
|
||||
fprintf(stderr, "Imported invalid EC key\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
done:
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
|
||||
if (!test_EVP_DigestSignInit()) {
|
||||
fprintf(stderr, "EVP_DigestSignInit failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_DigestVerifyInit()) {
|
||||
fprintf(stderr, "EVP_DigestVerifyInit failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
|
||||
EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyDER) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_d2i_AutoPrivateKey
|
||||
(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), EVP_PKEY_RSA)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyPKCS8) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
if (!test_d2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
|
||||
EVP_PKEY_EC)) {
|
||||
fprintf(stderr, "d2i_AutoPrivateKey(kExampleECKeyDER) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!test_EVP_PKCS82PKEY()) {
|
||||
fprintf(stderr, "test_EVP_PKCS82PKEY failed\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
}
|
||||
1
test/evp_extra_test.c
Symbolic link
1
test/evp_extra_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/evp/evp_extra_test.c
|
||||
2019
test/evp_test.c
2019
test/evp_test.c
File diff suppressed because it is too large
Load Diff
1
test/evp_test.c
Symbolic link
1
test/evp_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/evp/evp_test.c
|
||||
3786
test/evptests.txt
3786
test/evptests.txt
File diff suppressed because it is too large
Load Diff
268
test/exptest.c
268
test/exptest.c
@@ -1,268 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#define NUM_BITS (BN_BITS2 * 4)
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
/*
|
||||
* Test that r == 0 in test_exp_mod_zero(). Returns one on success,
|
||||
* returns zero and prints debug output otherwise.
|
||||
*/
|
||||
static int a_is_zero_mod_one(const char *method, const BIGNUM *r,
|
||||
const BIGNUM *a) {
|
||||
if (!BN_is_zero(r)) {
|
||||
fprintf(stderr, "%s failed:\n", method);
|
||||
fprintf(stderr, "a ** 0 mod 1 = r (should be 0)\n");
|
||||
fprintf(stderr, "a = ");
|
||||
BN_print_fp(stderr, a);
|
||||
fprintf(stderr, "\nr = ");
|
||||
BN_print_fp(stderr, r);
|
||||
fprintf(stderr, "\n");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success.
|
||||
*/
|
||||
static int test_exp_mod_zero()
|
||||
{
|
||||
BIGNUM *a = NULL, *p = NULL, *m = NULL;
|
||||
BIGNUM *r = NULL;
|
||||
BN_ULONG one_word = 1;
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
int ret = 1, failed = 0;
|
||||
|
||||
m = BN_new();
|
||||
if (!m)
|
||||
goto err;
|
||||
BN_one(m);
|
||||
|
||||
a = BN_new();
|
||||
if (!a)
|
||||
goto err;
|
||||
BN_one(a);
|
||||
|
||||
p = BN_new();
|
||||
if (!p)
|
||||
goto err;
|
||||
BN_zero(p);
|
||||
|
||||
r = BN_new();
|
||||
if (!r)
|
||||
goto err;
|
||||
|
||||
if (!BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
|
||||
goto err;
|
||||
|
||||
if (!BN_mod_exp(r, a, p, m, ctx))
|
||||
goto err;
|
||||
|
||||
if (!a_is_zero_mod_one("BN_mod_exp", r, a))
|
||||
failed = 1;
|
||||
|
||||
if (!BN_mod_exp_recp(r, a, p, m, ctx))
|
||||
goto err;
|
||||
|
||||
if (!a_is_zero_mod_one("BN_mod_exp_recp", r, a))
|
||||
failed = 1;
|
||||
|
||||
if (!BN_mod_exp_simple(r, a, p, m, ctx))
|
||||
goto err;
|
||||
|
||||
if (!a_is_zero_mod_one("BN_mod_exp_simple", r, a))
|
||||
failed = 1;
|
||||
|
||||
if (!BN_mod_exp_mont(r, a, p, m, ctx, NULL))
|
||||
goto err;
|
||||
|
||||
if (!a_is_zero_mod_one("BN_mod_exp_mont", r, a))
|
||||
failed = 1;
|
||||
|
||||
if (!BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a))
|
||||
failed = 1;
|
||||
|
||||
/*
|
||||
* A different codepath exists for single word multiplication
|
||||
* in non-constant-time only.
|
||||
*/
|
||||
if (!BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL))
|
||||
goto err;
|
||||
|
||||
if (!BN_is_zero(r)) {
|
||||
fprintf(stderr, "BN_mod_exp_mont_word failed:\n");
|
||||
fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\n");
|
||||
fprintf(stderr, "r = ");
|
||||
BN_print_fp(stderr, r);
|
||||
fprintf(stderr, "\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = failed;
|
||||
|
||||
err:
|
||||
BN_free(r);
|
||||
BN_free(a);
|
||||
BN_free(p);
|
||||
BN_free(m);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
BIO *out = NULL;
|
||||
int i, ret;
|
||||
unsigned char c;
|
||||
BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, *a, *b, *m;
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we
|
||||
* don't even check its return
|
||||
* value (which we should) */
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL)
|
||||
EXIT(1);
|
||||
r_mont = BN_new();
|
||||
r_mont_const = BN_new();
|
||||
r_recp = BN_new();
|
||||
r_simple = BN_new();
|
||||
a = BN_new();
|
||||
b = BN_new();
|
||||
m = BN_new();
|
||||
if ((r_mont == NULL) || (r_recp == NULL) || (a == NULL) || (b == NULL))
|
||||
goto err;
|
||||
|
||||
out = BIO_new(BIO_s_file());
|
||||
|
||||
if (out == NULL)
|
||||
EXIT(1);
|
||||
BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
for (i = 0; i < 200; i++) {
|
||||
RAND_bytes(&c, 1);
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
BN_rand(a, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);
|
||||
|
||||
RAND_bytes(&c, 1);
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
BN_rand(b, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);
|
||||
|
||||
RAND_bytes(&c, 1);
|
||||
c = (c % BN_BITS) - BN_BITS2;
|
||||
BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD);
|
||||
|
||||
BN_mod(a, a, m, ctx);
|
||||
BN_mod(b, b, m, ctx);
|
||||
|
||||
ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL);
|
||||
if (ret <= 0) {
|
||||
printf("BN_mod_exp_mont() problems\n");
|
||||
ERR_print_errors(out);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
ret = BN_mod_exp_recp(r_recp, a, b, m, ctx);
|
||||
if (ret <= 0) {
|
||||
printf("BN_mod_exp_recp() problems\n");
|
||||
ERR_print_errors(out);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
ret = BN_mod_exp_simple(r_simple, a, b, m, ctx);
|
||||
if (ret <= 0) {
|
||||
printf("BN_mod_exp_simple() problems\n");
|
||||
ERR_print_errors(out);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
ret = BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL);
|
||||
if (ret <= 0) {
|
||||
printf("BN_mod_exp_mont_consttime() problems\n");
|
||||
ERR_print_errors(out);
|
||||
EXIT(1);
|
||||
}
|
||||
|
||||
if (BN_cmp(r_simple, r_mont) == 0
|
||||
&& BN_cmp(r_simple, r_recp) == 0
|
||||
&& BN_cmp(r_simple, r_mont_const) == 0) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
} else {
|
||||
if (BN_cmp(r_simple, r_mont) != 0)
|
||||
printf("\nsimple and mont results differ\n");
|
||||
if (BN_cmp(r_simple, r_mont_const) != 0)
|
||||
printf("\nsimple and mont const time results differ\n");
|
||||
if (BN_cmp(r_simple, r_recp) != 0)
|
||||
printf("\nsimple and recp results differ\n");
|
||||
|
||||
printf("a (%3d) = ", BN_num_bits(a));
|
||||
BN_print(out, a);
|
||||
printf("\nb (%3d) = ", BN_num_bits(b));
|
||||
BN_print(out, b);
|
||||
printf("\nm (%3d) = ", BN_num_bits(m));
|
||||
BN_print(out, m);
|
||||
printf("\nsimple =");
|
||||
BN_print(out, r_simple);
|
||||
printf("\nrecp =");
|
||||
BN_print(out, r_recp);
|
||||
printf("\nmont =");
|
||||
BN_print(out, r_mont);
|
||||
printf("\nmont_ct =");
|
||||
BN_print(out, r_mont_const);
|
||||
printf("\n");
|
||||
EXIT(1);
|
||||
}
|
||||
}
|
||||
BN_free(r_mont);
|
||||
BN_free(r_mont_const);
|
||||
BN_free(r_recp);
|
||||
BN_free(r_simple);
|
||||
BN_free(a);
|
||||
BN_free(b);
|
||||
BN_free(m);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
if (test_exp_mod_zero() != 0)
|
||||
goto err;
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(out) <= 0)
|
||||
goto err;
|
||||
#endif
|
||||
BIO_free(out);
|
||||
printf("\n");
|
||||
|
||||
printf("done\n");
|
||||
|
||||
EXIT(0);
|
||||
err:
|
||||
ERR_print_errors(out);
|
||||
EXIT(1);
|
||||
}
|
||||
1
test/exptest.c
Symbolic link
1
test/exptest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/bn/exptest.c
|
||||
@@ -1,378 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Unit test for TLS heartbeats.
|
||||
*
|
||||
* Acts as a regression test against the Heartbleed bug (CVE-2014-0160).
|
||||
*
|
||||
* Author: Mike Bland (mbland@acm.org, http://mike-bland.com/)
|
||||
* Date: 2014-04-12
|
||||
* License: Creative Commons Attribution 4.0 International (CC By 4.0)
|
||||
* http://creativecommons.org/licenses/by/4.0/deed.en_US
|
||||
*
|
||||
* OUTPUT
|
||||
* ------
|
||||
* The program returns zero on success. It will print a message with a count
|
||||
* of the number of failed tests and return nonzero if any tests fail.
|
||||
*
|
||||
* It will print the contents of the request and response buffers for each
|
||||
* failing test. In a "fixed" version, all the tests should pass and there
|
||||
* should be no output.
|
||||
*
|
||||
* In a "bleeding" version, you'll see:
|
||||
*
|
||||
* test_dtls1_heartbleed failed:
|
||||
* expected payload len: 0
|
||||
* received: 1024
|
||||
* sent 26 characters
|
||||
* "HEARTBLEED "
|
||||
* received 1024 characters
|
||||
* "HEARTBLEED \xde\xad\xbe\xef..."
|
||||
* ** test_dtls1_heartbleed failed **
|
||||
*
|
||||
* The contents of the returned buffer in the failing test will depend on the
|
||||
* contents of memory on your machine.
|
||||
*
|
||||
* MORE INFORMATION
|
||||
* ----------------
|
||||
* http://mike-bland.com/2014/04/12/heartbleed.html
|
||||
* http://mike-bland.com/tags/heartbleed.html
|
||||
*/
|
||||
|
||||
#define OPENSSL_UNIT_TEST
|
||||
|
||||
#include "../ssl/ssl_locl.h"
|
||||
|
||||
#include "testutil.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_HEARTBEATS) && !defined(OPENSSL_NO_UNIT_TEST)
|
||||
|
||||
/* As per https://tools.ietf.org/html/rfc6520#section-4 */
|
||||
# define MIN_PADDING_SIZE 16
|
||||
|
||||
/* Maximum number of payload characters to print as test output */
|
||||
# define MAX_PRINTABLE_CHARACTERS 1024
|
||||
|
||||
typedef struct heartbeat_test_fixture {
|
||||
SSL_CTX *ctx;
|
||||
SSL *s;
|
||||
const char *test_case_name;
|
||||
int (*process_heartbeat) (SSL *s, unsigned char *p, unsigned int length);
|
||||
unsigned char *payload;
|
||||
int sent_payload_len;
|
||||
int expected_return_value;
|
||||
int return_payload_offset;
|
||||
int expected_payload_len;
|
||||
const char *expected_return_payload;
|
||||
} HEARTBEAT_TEST_FIXTURE;
|
||||
|
||||
static HEARTBEAT_TEST_FIXTURE set_up(const char *const test_case_name,
|
||||
const SSL_METHOD *meth)
|
||||
{
|
||||
HEARTBEAT_TEST_FIXTURE fixture;
|
||||
int setup_ok = 1;
|
||||
memset(&fixture, 0, sizeof(fixture));
|
||||
fixture.test_case_name = test_case_name;
|
||||
|
||||
fixture.ctx = SSL_CTX_new(meth);
|
||||
if (!fixture.ctx) {
|
||||
fprintf(stderr, "Failed to allocate SSL_CTX for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fixture.s = SSL_new(fixture.ctx);
|
||||
if (!fixture.s) {
|
||||
fprintf(stderr, "Failed to allocate SSL for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!ssl_init_wbio_buffer(fixture.s)) {
|
||||
fprintf(stderr, "Failed to set up wbio buffer for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!ssl3_setup_buffers(fixture.s)) {
|
||||
fprintf(stderr, "Failed to setup buffers for test: %s\n",
|
||||
test_case_name);
|
||||
setup_ok = 0;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the memory for the return buffer, since this isn't automatically
|
||||
* zeroed in opt mode and will cause spurious test failures that will
|
||||
* change with each execution.
|
||||
*/
|
||||
memset(fixture.s->rlayer.wbuf.buf, 0, fixture.s->rlayer.wbuf.len);
|
||||
|
||||
fail:
|
||||
if (!setup_ok) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return fixture;
|
||||
}
|
||||
|
||||
static HEARTBEAT_TEST_FIXTURE set_up_dtls(const char *const test_case_name)
|
||||
{
|
||||
HEARTBEAT_TEST_FIXTURE fixture = set_up(test_case_name,
|
||||
DTLS_server_method());
|
||||
fixture.process_heartbeat = dtls1_process_heartbeat;
|
||||
|
||||
/*
|
||||
* As per dtls1_get_record(), skipping the following from the beginning
|
||||
* of the returned heartbeat message: type-1 byte; version-2 bytes;
|
||||
* sequence number-8 bytes; length-2 bytes And then skipping the 1-byte
|
||||
* type encoded by process_heartbeat for a total of 14 bytes, at which
|
||||
* point we can grab the length and the payload we seek.
|
||||
*/
|
||||
fixture.return_payload_offset = 14;
|
||||
return fixture;
|
||||
}
|
||||
|
||||
/* Needed by ssl3_write_bytes() */
|
||||
static int dummy_handshake(SSL *s)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void tear_down(HEARTBEAT_TEST_FIXTURE fixture)
|
||||
{
|
||||
ERR_print_errors_fp(stderr);
|
||||
SSL_free(fixture.s);
|
||||
SSL_CTX_free(fixture.ctx);
|
||||
}
|
||||
|
||||
static void print_payload(const char *const prefix,
|
||||
const unsigned char *payload, const int n)
|
||||
{
|
||||
const int end = n < MAX_PRINTABLE_CHARACTERS ? n
|
||||
: MAX_PRINTABLE_CHARACTERS;
|
||||
int i = 0;
|
||||
|
||||
printf("%s %d character%s", prefix, n, n == 1 ? "" : "s");
|
||||
if (end != n)
|
||||
printf(" (first %d shown)", end);
|
||||
printf("\n \"");
|
||||
|
||||
for (; i != end; ++i) {
|
||||
const unsigned char c = payload[i];
|
||||
if (isprint(c))
|
||||
fputc(c, stdout);
|
||||
else
|
||||
printf("\\x%02x", c);
|
||||
}
|
||||
printf("\"\n");
|
||||
}
|
||||
|
||||
static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture)
|
||||
{
|
||||
int result = 0;
|
||||
SSL *s = fixture.s;
|
||||
unsigned char *payload = fixture.payload;
|
||||
unsigned char sent_buf[MAX_PRINTABLE_CHARACTERS + 1];
|
||||
int return_value;
|
||||
unsigned const char *p;
|
||||
int actual_payload_len;
|
||||
|
||||
s->rlayer.rrec.data = payload;
|
||||
s->rlayer.rrec.length = strlen((const char *)payload);
|
||||
*payload++ = TLS1_HB_REQUEST;
|
||||
s2n(fixture.sent_payload_len, payload);
|
||||
|
||||
/*
|
||||
* Make a local copy of the request, since it gets overwritten at some
|
||||
* point
|
||||
*/
|
||||
memcpy(sent_buf, payload, sizeof(sent_buf));
|
||||
|
||||
return_value = fixture.process_heartbeat(s, s->rlayer.rrec.data,
|
||||
s->rlayer.rrec.length);
|
||||
|
||||
if (return_value != fixture.expected_return_value) {
|
||||
printf("%s failed: expected return value %d, received %d\n",
|
||||
fixture.test_case_name, fixture.expected_return_value,
|
||||
return_value);
|
||||
result = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there is any byte alignment, it will be stored in wbuf.offset.
|
||||
*/
|
||||
p = &(s->rlayer.
|
||||
wbuf.buf[fixture.return_payload_offset + s->rlayer.wbuf.offset]);
|
||||
actual_payload_len = 0;
|
||||
n2s(p, actual_payload_len);
|
||||
|
||||
if (actual_payload_len != fixture.expected_payload_len) {
|
||||
printf("%s failed:\n expected payload len: %d\n received: %d\n",
|
||||
fixture.test_case_name, fixture.expected_payload_len,
|
||||
actual_payload_len);
|
||||
print_payload("sent", sent_buf, strlen((const char *)sent_buf));
|
||||
print_payload("received", p, actual_payload_len);
|
||||
result = 1;
|
||||
} else {
|
||||
char *actual_payload =
|
||||
OPENSSL_strndup((const char *)p, actual_payload_len);
|
||||
if (strcmp(actual_payload, fixture.expected_return_payload) != 0) {
|
||||
printf
|
||||
("%s failed:\n expected payload: \"%s\"\n received: \"%s\"\n",
|
||||
fixture.test_case_name, fixture.expected_return_payload,
|
||||
actual_payload);
|
||||
result = 1;
|
||||
}
|
||||
OPENSSL_free(actual_payload);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
printf("** %s failed **\n--------\n", fixture.test_case_name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int honest_payload_size(unsigned char payload_buf[])
|
||||
{
|
||||
/* Omit three-byte pad at the beginning for type and payload length */
|
||||
return strlen((const char *)&payload_buf[3]) - MIN_PADDING_SIZE;
|
||||
}
|
||||
|
||||
# define SETUP_HEARTBEAT_TEST_FIXTURE(type)\
|
||||
SETUP_TEST_FIXTURE(HEARTBEAT_TEST_FIXTURE, set_up_##type)
|
||||
|
||||
# define EXECUTE_HEARTBEAT_TEST()\
|
||||
EXECUTE_TEST(execute_heartbeat, tear_down)
|
||||
|
||||
static int test_dtls1_not_bleeding()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4] =
|
||||
" Not bleeding, sixteen spaces of padding" " ";
|
||||
const int payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload =
|
||||
"Not bleeding, sixteen spaces of padding";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_not_bleeding_empty_payload()
|
||||
{
|
||||
int payload_buf_len;
|
||||
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Three-byte pad at the beginning for type and payload length, plus a
|
||||
* NUL at the end
|
||||
*/
|
||||
unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 3);
|
||||
payload_buf[MIN_PADDING_SIZE + 3] = '\0';
|
||||
payload_buf_len = honest_payload_size(payload_buf);
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = payload_buf_len;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = payload_buf_len;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/* Three-byte pad at the beginning for type and payload length */
|
||||
unsigned char payload_buf[4 + MAX_PRINTABLE_CHARACTERS] =
|
||||
" HEARTBLEED ";
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed_empty_payload()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Excluding the NUL at the end, one byte short of type + payload length
|
||||
* + minimum padding
|
||||
*/
|
||||
unsigned char payload_buf[MAX_PRINTABLE_CHARACTERS + 4];
|
||||
memset(payload_buf, ' ', MIN_PADDING_SIZE + 2);
|
||||
payload_buf[MIN_PADDING_SIZE + 2] = '\0';
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = MAX_PRINTABLE_CHARACTERS;
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
static int test_dtls1_heartbleed_excessive_plaintext_length()
|
||||
{
|
||||
SETUP_HEARTBEAT_TEST_FIXTURE(dtls);
|
||||
/*
|
||||
* Excluding the NUL at the end, one byte in excess of maximum allowed
|
||||
* heartbeat message length
|
||||
*/
|
||||
unsigned char payload_buf[SSL3_RT_MAX_PLAIN_LENGTH + 2];
|
||||
memset(payload_buf, ' ', sizeof(payload_buf));
|
||||
payload_buf[sizeof(payload_buf) - 1] = '\0';
|
||||
|
||||
fixture.payload = &payload_buf[0];
|
||||
fixture.sent_payload_len = honest_payload_size(payload_buf);
|
||||
fixture.expected_return_value = 0;
|
||||
fixture.expected_payload_len = 0;
|
||||
fixture.expected_return_payload = "";
|
||||
EXECUTE_HEARTBEAT_TEST();
|
||||
}
|
||||
|
||||
# undef EXECUTE_HEARTBEAT_TEST
|
||||
# undef SETUP_HEARTBEAT_TEST_FIXTURE
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
ADD_TEST(test_dtls1_not_bleeding);
|
||||
ADD_TEST(test_dtls1_not_bleeding_empty_payload);
|
||||
ADD_TEST(test_dtls1_heartbleed);
|
||||
ADD_TEST(test_dtls1_heartbleed_empty_payload);
|
||||
ADD_TEST(test_dtls1_heartbleed_excessive_plaintext_length);
|
||||
|
||||
result = run_tests(argv[0]);
|
||||
ERR_print_errors_fp(stderr);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else /* OPENSSL_NO_HEARTBEATS */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif /* OPENSSL_NO_HEARTBEATS */
|
||||
1
test/heartbeat_test.c
Symbolic link
1
test/heartbeat_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/heartbeat_test.c
|
||||
312
test/hmactest.c
312
test/hmactest.c
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
# include <openssl/hmac.h>
|
||||
# include <openssl/sha.h>
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
# include <openssl/md5.h>
|
||||
# endif
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
static struct test_st {
|
||||
unsigned char key[16];
|
||||
int key_len;
|
||||
unsigned char data[64];
|
||||
int data_len;
|
||||
unsigned char *digest;
|
||||
} test[8] = {
|
||||
{
|
||||
"", 0, "More text test vectors to stuff up EBCDIC machines :-)", 54,
|
||||
(unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86",
|
||||
},
|
||||
{
|
||||
{
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
}, 16, "Hi There", 8,
|
||||
(unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d",
|
||||
},
|
||||
{
|
||||
"Jefe", 4, "what do ya want for nothing?", 28,
|
||||
(unsigned char *)"750c783e6ab0b503eaa86e310a5db738",
|
||||
},
|
||||
{
|
||||
{
|
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||
0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
||||
}, 16, {
|
||||
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
|
||||
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
|
||||
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
|
||||
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd,
|
||||
0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd
|
||||
}, 50, (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6",
|
||||
},
|
||||
{
|
||||
"", 0, "My test data", 12,
|
||||
(unsigned char *)"61afdecb95429ef494d61fdee15990cabf0826fc"
|
||||
},
|
||||
{
|
||||
"", 0, "My test data", 12,
|
||||
(unsigned char *)"2274b195d90ce8e03406f4b526a47e0787a88a65479938f1a5baa3ce0f079776"
|
||||
},
|
||||
{
|
||||
"123456", 6, "My test data", 12,
|
||||
(unsigned char *)"bab53058ae861a7f191abe2d0145cbb123776a6369ee3f9d79ce455667e411dd"
|
||||
},
|
||||
{
|
||||
"12345", 5, "My test data again", 18,
|
||||
(unsigned char *)"a12396ceddd2a85f4c656bc1e0aa50c78cffde3e"
|
||||
}
|
||||
};
|
||||
# endif
|
||||
|
||||
static char *pt(unsigned char *md, unsigned int len);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
int i;
|
||||
char *p;
|
||||
# endif
|
||||
int err = 0;
|
||||
HMAC_CTX *ctx = NULL, *ctx2 = NULL;
|
||||
unsigned char buf[EVP_MAX_MD_SIZE];
|
||||
unsigned int len;
|
||||
|
||||
# ifdef OPENSSL_NO_MD5
|
||||
printf("test skipped: MD5 disabled\n");
|
||||
# else
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(test[0].data, test[0].data, test[0].data_len);
|
||||
ebcdic2ascii(test[1].data, test[1].data, test[1].data_len);
|
||||
ebcdic2ascii(test[2].key, test[2].key, test[2].key_len);
|
||||
ebcdic2ascii(test[2].data, test[2].data, test[2].data_len);
|
||||
# endif
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
p = pt(HMAC(EVP_md5(),
|
||||
test[i].key, test[i].key_len,
|
||||
test[i].data, test[i].data_len, NULL, NULL),
|
||||
MD5_DIGEST_LENGTH);
|
||||
|
||||
if (strcmp(p, (char *)test[i].digest) != 0) {
|
||||
printf("Error calculating HMAC on %d entry'\n", i);
|
||||
printf("got %s instead of %s\n", p, test[i].digest);
|
||||
err++;
|
||||
} else
|
||||
printf("test %d ok\n", i);
|
||||
}
|
||||
# endif /* OPENSSL_NO_MD5 */
|
||||
|
||||
/* test4 */
|
||||
ctx = HMAC_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
printf("HMAC malloc failure (test 4)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
if (HMAC_CTX_get_md(ctx) != NULL) {
|
||||
printf("Message digest not NULL for HMAC (test 4)\n");
|
||||
err++;
|
||||
goto test5;
|
||||
}
|
||||
if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL)) {
|
||||
printf("Should fail to initialise HMAC with empty MD and key (test 4)\n");
|
||||
err++;
|
||||
goto test5;
|
||||
}
|
||||
if (HMAC_Update(ctx, test[4].data, test[4].data_len)) {
|
||||
printf("Should fail HMAC_Update with ctx not set up (test 4)\n");
|
||||
err++;
|
||||
goto test5;
|
||||
}
|
||||
if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha1(), NULL)) {
|
||||
printf("Should fail to initialise HMAC with empty key (test 4)\n");
|
||||
err++;
|
||||
goto test5;
|
||||
}
|
||||
if (HMAC_Update(ctx, test[4].data, test[4].data_len)) {
|
||||
printf("Should fail HMAC_Update with ctx not set up (test 4)\n");
|
||||
err++;
|
||||
goto test5;
|
||||
}
|
||||
printf("test 4 ok\n");
|
||||
test5:
|
||||
/* Test 5 has empty key; test that single-shot accepts a NULL key. */
|
||||
p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len,
|
||||
NULL, NULL), SHA_DIGEST_LENGTH);
|
||||
if (strcmp(p, (char *)test[4].digest) != 0) {
|
||||
printf("Error calculating HMAC on %d entry'\n", i);
|
||||
printf("got %s instead of %s\n", p, test[4].digest);
|
||||
err++;
|
||||
}
|
||||
|
||||
HMAC_CTX_reset(ctx);
|
||||
if (HMAC_CTX_get_md(ctx) != NULL) {
|
||||
printf("Message digest not NULL for HMAC (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (HMAC_Init_ex(ctx, test[4].key, test[4].key_len, NULL, NULL)) {
|
||||
printf("Should fail to initialise HMAC with empty MD (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (HMAC_Update(ctx, test[4].data, test[4].data_len)) {
|
||||
printf("Should fail HMAC_Update with ctx not set up (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (HMAC_Init_ex(ctx, test[4].key, -1, EVP_sha1(), NULL)) {
|
||||
printf("Should fail to initialise HMAC with invalid key len(test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Init_ex(ctx, test[4].key, test[4].key_len, EVP_sha1(), NULL)) {
|
||||
printf("Failed to initialise HMAC (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Update(ctx, test[4].data, test[4].data_len)) {
|
||||
printf("Error updating HMAC with data (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Final(ctx, buf, &len)) {
|
||||
printf("Error finalising data (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
p = pt(buf, len);
|
||||
if (strcmp(p, (char *)test[4].digest) != 0) {
|
||||
printf("Error calculating interim HMAC on test 5\n");
|
||||
printf("got %s instead of %s\n", p, test[4].digest);
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha256(), NULL)) {
|
||||
printf("Should disallow changing MD without a new key (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Init_ex(ctx, test[5].key, test[5].key_len, EVP_sha256(), NULL)) {
|
||||
printf("Failed to reinitialise HMAC (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (HMAC_CTX_get_md(ctx) != EVP_sha256()) {
|
||||
printf("Unexpected message digest for HMAC (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Update(ctx, test[5].data, test[5].data_len)) {
|
||||
printf("Error updating HMAC with data (sha256) (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Final(ctx, buf, &len)) {
|
||||
printf("Error finalising data (sha256) (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
p = pt(buf, len);
|
||||
if (strcmp(p, (char *)test[5].digest) != 0) {
|
||||
printf("Error calculating 2nd interim HMAC on test 5\n");
|
||||
printf("got %s instead of %s\n", p, test[5].digest);
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Init_ex(ctx, test[6].key, test[6].key_len, NULL, NULL)) {
|
||||
printf("Failed to reinitialise HMAC with key (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Update(ctx, test[6].data, test[6].data_len)) {
|
||||
printf("Error updating HMAC with data (new key) (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
if (!HMAC_Final(ctx, buf, &len)) {
|
||||
printf("Error finalising data (new key) (test 5)\n");
|
||||
err++;
|
||||
goto test6;
|
||||
}
|
||||
p = pt(buf, len);
|
||||
if (strcmp(p, (char *)test[6].digest) != 0) {
|
||||
printf("error calculating HMAC on test 5\n");
|
||||
printf("got %s instead of %s\n", p, test[6].digest);
|
||||
err++;
|
||||
} else {
|
||||
printf("test 5 ok\n");
|
||||
}
|
||||
test6:
|
||||
HMAC_CTX_reset(ctx);
|
||||
ctx2 = HMAC_CTX_new();
|
||||
if (ctx2 == NULL) {
|
||||
printf("HMAC malloc failure (test 6)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
if (!HMAC_Init_ex(ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) {
|
||||
printf("Failed to initialise HMAC (test 6)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
if (!HMAC_Update(ctx, test[7].data, test[7].data_len)) {
|
||||
printf("Error updating HMAC with data (test 6)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
if (!HMAC_CTX_copy(ctx2, ctx)) {
|
||||
printf("Failed to copy HMAC_CTX (test 6)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
if (!HMAC_Final(ctx2, buf, &len)) {
|
||||
printf("Error finalising data (test 6)\n");
|
||||
err++;
|
||||
goto end;
|
||||
}
|
||||
p = pt(buf, len);
|
||||
if (strcmp(p, (char *)test[7].digest) != 0) {
|
||||
printf("Error calculating HMAC on test 6\n");
|
||||
printf("got %s instead of %s\n", p, test[7].digest);
|
||||
err++;
|
||||
} else {
|
||||
printf("test 6 ok\n");
|
||||
}
|
||||
end:
|
||||
HMAC_CTX_free(ctx2);
|
||||
HMAC_CTX_free(ctx);
|
||||
EXIT(err);
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_MD5
|
||||
static char *pt(unsigned char *md, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
static char buf[80];
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
# endif
|
||||
1
test/hmactest.c
Symbolic link
1
test/hmactest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/hmac/hmactest.c
|
||||
178
test/ideatest.c
178
test/ideatest.c
@@ -1,178 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_IDEA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No IDEA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/idea.h>
|
||||
|
||||
static const unsigned char k[16] = {
|
||||
0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
|
||||
0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08
|
||||
};
|
||||
|
||||
static const unsigned char in[8] = { 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03 };
|
||||
static const unsigned char c[8] = { 0x11, 0xFB, 0xED, 0x2B, 0x01, 0x98, 0x6D, 0xE5 };
|
||||
|
||||
static unsigned char out[80];
|
||||
|
||||
static const char text[] = "Hello to all people out there";
|
||||
|
||||
static const unsigned char cfb_key[16] = {
|
||||
0xe1, 0xf0, 0xc3, 0xd2, 0xa5, 0xb4, 0x87, 0x96,
|
||||
0x69, 0x78, 0x4b, 0x5a, 0x2d, 0x3c, 0x0f, 0x1e,
|
||||
};
|
||||
static const unsigned char cfb_iv[80] =
|
||||
{ 0x34, 0x12, 0x78, 0x56, 0xab, 0x90, 0xef, 0xcd };
|
||||
static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
|
||||
# define CFB_TEST_SIZE 24
|
||||
static const unsigned char plain[CFB_TEST_SIZE] = {
|
||||
0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
|
||||
0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20
|
||||
};
|
||||
|
||||
static const unsigned char cfb_cipher64[CFB_TEST_SIZE] = {
|
||||
0x59, 0xD8, 0xE2, 0x65, 0x00, 0x58, 0x6C, 0x3F,
|
||||
0x2C, 0x17, 0x25, 0xD0, 0x1A, 0x38, 0xB7, 0x2A,
|
||||
0x39, 0x61, 0x37, 0xDC, 0x79, 0xFB, 0x9F, 0x45
|
||||
/*- 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
|
||||
0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
|
||||
0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
|
||||
};
|
||||
|
||||
static int cfb64_test(const unsigned char *cfb_cipher);
|
||||
static char *pt(unsigned char *p);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, err = 0;
|
||||
IDEA_KEY_SCHEDULE key, dkey;
|
||||
unsigned char iv[8];
|
||||
|
||||
IDEA_set_encrypt_key(k, &key);
|
||||
IDEA_ecb_encrypt(in, out, &key);
|
||||
if (memcmp(out, c, 8) != 0) {
|
||||
printf("ecb idea error encrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", c[i]);
|
||||
err = 20;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
IDEA_set_decrypt_key(&key, &dkey);
|
||||
IDEA_ecb_encrypt(c, out, &dkey);
|
||||
if (memcmp(out, in, 8) != 0) {
|
||||
printf("ecb idea error decrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", in[i]);
|
||||
printf("\n");
|
||||
err = 3;
|
||||
}
|
||||
|
||||
if (err == 0)
|
||||
printf("ecb idea ok\n");
|
||||
|
||||
memcpy(iv, k, 8);
|
||||
IDEA_cbc_encrypt((unsigned char *)text, out, strlen(text) + 1, &key, iv,
|
||||
1);
|
||||
memcpy(iv, k, 8);
|
||||
IDEA_cbc_encrypt(out, out, 8, &dkey, iv, 0);
|
||||
IDEA_cbc_encrypt(&(out[8]), &(out[8]), strlen(text) + 1 - 8, &dkey, iv,
|
||||
0);
|
||||
if (memcmp(text, out, strlen(text) + 1) != 0) {
|
||||
printf("cbc idea bad\n");
|
||||
err = 4;
|
||||
} else
|
||||
printf("cbc idea ok\n");
|
||||
|
||||
printf("cfb64 idea ");
|
||||
if (cfb64_test(cfb_cipher64)) {
|
||||
printf("bad\n");
|
||||
err = 5;
|
||||
} else
|
||||
printf("ok\n");
|
||||
|
||||
EXIT(err);
|
||||
}
|
||||
|
||||
static int cfb64_test(const unsigned char *cfb_cipher)
|
||||
{
|
||||
IDEA_KEY_SCHEDULE eks, dks;
|
||||
int err = 0, i, n;
|
||||
|
||||
IDEA_set_encrypt_key(cfb_key, &eks);
|
||||
IDEA_set_decrypt_key(&eks, &dks);
|
||||
memcpy(cfb_tmp, cfb_iv, 8);
|
||||
n = 0;
|
||||
IDEA_cfb64_encrypt(plain, cfb_buf1, (long)12, &eks,
|
||||
cfb_tmp, &n, IDEA_ENCRYPT);
|
||||
IDEA_cfb64_encrypt(&(plain[12]), &(cfb_buf1[12]),
|
||||
(long)CFB_TEST_SIZE - 12, &eks,
|
||||
cfb_tmp, &n, IDEA_ENCRYPT);
|
||||
if (memcmp(cfb_cipher, cfb_buf1, CFB_TEST_SIZE) != 0) {
|
||||
err = 1;
|
||||
printf("IDEA_cfb64_encrypt encrypt error\n");
|
||||
for (i = 0; i < CFB_TEST_SIZE; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf1[i])));
|
||||
}
|
||||
memcpy(cfb_tmp, cfb_iv, 8);
|
||||
n = 0;
|
||||
IDEA_cfb64_encrypt(cfb_buf1, cfb_buf2, (long)13, &eks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
IDEA_cfb64_encrypt(&(cfb_buf1[13]), &(cfb_buf2[13]),
|
||||
(long)CFB_TEST_SIZE - 13, &eks,
|
||||
cfb_tmp, &n, IDEA_DECRYPT);
|
||||
if (memcmp(plain, cfb_buf2, CFB_TEST_SIZE) != 0) {
|
||||
err = 1;
|
||||
printf("IDEA_cfb_encrypt decrypt error\n");
|
||||
for (i = 0; i < 24; i += 8)
|
||||
printf("%s\n", pt(&(cfb_buf2[i])));
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *p)
|
||||
{
|
||||
static char bufs[10][20];
|
||||
static int bnum = 0;
|
||||
char *ret;
|
||||
int i;
|
||||
static char *f = "0123456789ABCDEF";
|
||||
|
||||
ret = &(bufs[bnum++][0]);
|
||||
bnum %= 10;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ret[i * 2] = f[(p[i] >> 4) & 0xf];
|
||||
ret[i * 2 + 1] = f[p[i] & 0xf];
|
||||
}
|
||||
ret[16] = '\0';
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
1
test/ideatest.c
Symbolic link
1
test/ideatest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/idea/ideatest.c
|
||||
@@ -1,19 +1,59 @@
|
||||
/*
|
||||
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
/* test/igetest.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2006 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.
|
||||
* ====================================================================
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "e_os.h"
|
||||
|
||||
#define TEST_SIZE 128
|
||||
#define BIG_TEST_SIZE 10240
|
||||
@@ -150,7 +190,8 @@ static int run_test_vectors(void)
|
||||
unsigned int n;
|
||||
int errs = 0;
|
||||
|
||||
for (n = 0; n < OSSL_NELEM(ige_test_vectors); ++n) {
|
||||
for (n = 0; n < sizeof(ige_test_vectors) / sizeof(ige_test_vectors[0]);
|
||||
++n) {
|
||||
const struct ige_test *const v = &ige_test_vectors[n];
|
||||
AES_KEY key;
|
||||
unsigned char buf[MAX_VECTOR_SIZE];
|
||||
@@ -193,7 +234,9 @@ static int run_test_vectors(void)
|
||||
}
|
||||
}
|
||||
|
||||
for (n = 0; n < OSSL_NELEM(bi_ige_test_vectors); ++n) {
|
||||
for (n = 0;
|
||||
n < sizeof(bi_ige_test_vectors) / sizeof(bi_ige_test_vectors[0]);
|
||||
++n) {
|
||||
const struct bi_ige_test *const v = &bi_ige_test_vectors[n];
|
||||
AES_KEY key1;
|
||||
AES_KEY key2;
|
||||
@@ -245,9 +288,9 @@ int main(int argc, char **argv)
|
||||
|
||||
assert(BIG_TEST_SIZE >= TEST_SIZE);
|
||||
|
||||
RAND_bytes(rkey, sizeof rkey);
|
||||
RAND_bytes(plaintext, sizeof plaintext);
|
||||
RAND_bytes(iv, sizeof iv);
|
||||
RAND_pseudo_bytes(rkey, sizeof rkey);
|
||||
RAND_pseudo_bytes(plaintext, sizeof plaintext);
|
||||
RAND_pseudo_bytes(iv, sizeof iv);
|
||||
memcpy(saved_iv, iv, sizeof saved_iv);
|
||||
|
||||
/* Forward IGE only... */
|
||||
@@ -346,7 +389,7 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
/* possible with biIGE, so the IV is not updated. */
|
||||
|
||||
RAND_bytes(rkey2, sizeof rkey2);
|
||||
RAND_pseudo_bytes(rkey2, sizeof rkey2);
|
||||
|
||||
/* Straight encrypt/decrypt */
|
||||
AES_set_encrypt_key(rkey, 8 * sizeof rkey, &key);
|
||||
|
||||
1
test/jpaketest.c
Symbolic link
1
test/jpaketest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
dummytest.c
|
||||
1115
test/maketests.com
Normal file
1115
test/maketests.com
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_MD4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MD4 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# 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;
|
||||
char **P, **R;
|
||||
char *p;
|
||||
unsigned char md[MD4_DIGEST_LENGTH];
|
||||
|
||||
P = test;
|
||||
R = ret;
|
||||
i = 1;
|
||||
while (*P != NULL) {
|
||||
if (!EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md4(),
|
||||
NULL)) {
|
||||
printf("EVP Digest error.\n");
|
||||
EXIT(1);
|
||||
}
|
||||
p = pt(md);
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
1
test/md4test.c
Symbolic link
1
test/md4test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/md4/md4test.c
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_MD5
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MD5 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/md5.h>
|
||||
|
||||
static char *test[] = {
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
NULL,
|
||||
};
|
||||
|
||||
static char *ret[] = {
|
||||
"d41d8cd98f00b204e9800998ecf8427e",
|
||||
"0cc175b9c0f1b6a831c399e269772661",
|
||||
"900150983cd24fb0d6963f7d28e17f72",
|
||||
"f96b697d7cb7938d525a2f31aaf161d0",
|
||||
"c3fcd3d76192e4007dfb496cca67e13b",
|
||||
"d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
"57edf4a22be3c955ac49da2e2107b67a",
|
||||
};
|
||||
|
||||
static char *pt(unsigned char *md);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, err = 0;
|
||||
char **P, **R;
|
||||
char *p;
|
||||
unsigned char md[MD5_DIGEST_LENGTH];
|
||||
|
||||
P = test;
|
||||
R = ret;
|
||||
i = 1;
|
||||
while (*P != NULL) {
|
||||
if (!EVP_Digest(&(P[0][0]), strlen((char *)*P), md, NULL, EVP_md5(),
|
||||
NULL)) {
|
||||
printf("EVP Digest error.\n");
|
||||
EXIT(1);
|
||||
}
|
||||
p = pt(md);
|
||||
if (strcmp(p, (char *)*R) != 0) {
|
||||
printf("error calculating MD5 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);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *md)
|
||||
{
|
||||
int i;
|
||||
static char buf[80];
|
||||
|
||||
for (i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
1
test/md5test.c
Symbolic link
1
test/md5test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/md5/md5test.c
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
|
||||
# define OPENSSL_NO_MDC2
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSL_NO_MDC2
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No MDC2 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/mdc2.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
static unsigned char pad1[16] = {
|
||||
0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
|
||||
0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
|
||||
};
|
||||
|
||||
static unsigned char pad2[16] = {
|
||||
0x2E, 0x46, 0x79, 0xB5, 0xAD, 0xD9, 0xCA, 0x75,
|
||||
0x35, 0xD8, 0x7A, 0xFE, 0xAB, 0x33, 0xBE, 0xE2
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret = 1;
|
||||
unsigned char md[MDC2_DIGEST_LENGTH];
|
||||
int i;
|
||||
EVP_MD_CTX *c;
|
||||
static char text[] = "Now is the time for all ";
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(text, text, strlen(text));
|
||||
# endif
|
||||
|
||||
c = EVP_MD_CTX_new();
|
||||
if (c == NULL
|
||||
|| !EVP_DigestInit_ex(c, EVP_mdc2(), NULL)
|
||||
|| !EVP_DigestUpdate(c, (unsigned char *)text, strlen(text))
|
||||
|| !EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
||||
goto err;
|
||||
|
||||
if (memcmp(md, pad1, MDC2_DIGEST_LENGTH) != 0) {
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", md[i]);
|
||||
printf(" <- generated\n");
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", pad1[i]);
|
||||
printf(" <- correct\n");
|
||||
goto err;
|
||||
} else {
|
||||
printf("pad1 - ok\n");
|
||||
}
|
||||
|
||||
if (!EVP_DigestInit_ex(c, EVP_mdc2(), NULL))
|
||||
goto err;
|
||||
/* FIXME: use a ctl function? */
|
||||
((MDC2_CTX *)EVP_MD_CTX_md_data(c))->pad_type = 2;
|
||||
if (!EVP_DigestUpdate(c, (unsigned char *)text, strlen(text))
|
||||
|| !EVP_DigestFinal_ex(c, &(md[0]), NULL))
|
||||
goto err;
|
||||
|
||||
if (memcmp(md, pad2, MDC2_DIGEST_LENGTH) != 0) {
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", md[i]);
|
||||
printf(" <- generated\n");
|
||||
for (i = 0; i < MDC2_DIGEST_LENGTH; i++)
|
||||
printf("%02X", pad2[i]);
|
||||
printf(" <- correct\n");
|
||||
} else {
|
||||
printf("pad2 - ok\n");
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
err:
|
||||
EVP_MD_CTX_free(c);
|
||||
EXIT(ret);
|
||||
}
|
||||
#endif
|
||||
1
test/mdc2test.c
Symbolic link
1
test/mdc2test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/mdc2/mdc2test.c
|
||||
@@ -1,10 +1,59 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
/* test/methtest.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
* 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>
|
||||
@@ -51,6 +100,7 @@ char *argv[];
|
||||
METH_control(tmp2, METH_CONTROL_DUMP, stdout);
|
||||
EXIT(0);
|
||||
err:
|
||||
ERR_load_crypto_strings();
|
||||
ERR_print_errors_fp(stderr);
|
||||
EXIT(1);
|
||||
return (0);
|
||||
|
||||
@@ -1,10 +1,54 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
# test/pkits-test.pl
|
||||
# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
# project.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
# ====================================================================
|
||||
# Copyright (c) 2008 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.
|
||||
# ====================================================================
|
||||
|
||||
# Perl utility to run PKITS tests for RFC3280 compliance.
|
||||
|
||||
|
||||
@@ -1,9 +1,57 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
/* test/r160test.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
* 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.]
|
||||
*/
|
||||
|
||||
|
||||
145
test/randtest.c
145
test/randtest.c
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
/* some FIPS 140-1 random number test */
|
||||
/* some simple tests */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char buf[2500];
|
||||
int i, j, k, s, sign, nsign, err = 0;
|
||||
unsigned long n1;
|
||||
unsigned long n2[16];
|
||||
unsigned long runs[2][34];
|
||||
/*
|
||||
* double d;
|
||||
*/
|
||||
long d;
|
||||
|
||||
i = RAND_bytes(buf, 2500);
|
||||
if (i <= 0) {
|
||||
printf("init failed, the rand method is not properly installed\n");
|
||||
err++;
|
||||
goto err;
|
||||
}
|
||||
|
||||
n1 = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
n2[i] = 0;
|
||||
for (i = 0; i < 34; i++)
|
||||
runs[0][i] = runs[1][i] = 0;
|
||||
|
||||
/* test 1 and 2 */
|
||||
sign = 0;
|
||||
nsign = 0;
|
||||
for (i = 0; i < 2500; i++) {
|
||||
j = buf[i];
|
||||
|
||||
n2[j & 0x0f]++;
|
||||
n2[(j >> 4) & 0x0f]++;
|
||||
|
||||
for (k = 0; k < 8; k++) {
|
||||
s = (j & 0x01);
|
||||
if (s == sign)
|
||||
nsign++;
|
||||
else {
|
||||
if (nsign > 34)
|
||||
nsign = 34;
|
||||
if (nsign != 0) {
|
||||
runs[sign][nsign - 1]++;
|
||||
if (nsign > 6)
|
||||
runs[sign][5]++;
|
||||
}
|
||||
sign = s;
|
||||
nsign = 1;
|
||||
}
|
||||
|
||||
if (s)
|
||||
n1++;
|
||||
j >>= 1;
|
||||
}
|
||||
}
|
||||
if (nsign > 34)
|
||||
nsign = 34;
|
||||
if (nsign != 0)
|
||||
runs[sign][nsign - 1]++;
|
||||
|
||||
/* test 1 */
|
||||
if (!((9654 < n1) && (n1 < 10346))) {
|
||||
printf("test 1 failed, X=%lu\n", n1);
|
||||
err++;
|
||||
}
|
||||
printf("test 1 done\n");
|
||||
|
||||
/* test 2 */
|
||||
d = 0;
|
||||
for (i = 0; i < 16; i++)
|
||||
d += n2[i] * n2[i];
|
||||
d = (d * 8) / 25 - 500000;
|
||||
if (!((103 < d) && (d < 5740))) {
|
||||
printf("test 2 failed, X=%ld.%02ld\n", d / 100L, d % 100L);
|
||||
err++;
|
||||
}
|
||||
printf("test 2 done\n");
|
||||
|
||||
/* test 3 */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 1, runs[i][0]);
|
||||
err++;
|
||||
}
|
||||
if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 2, runs[i][1]);
|
||||
err++;
|
||||
}
|
||||
if (!((502 < runs[i][2]) && (runs[i][2] < 748))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 3, runs[i][2]);
|
||||
err++;
|
||||
}
|
||||
if (!((223 < runs[i][3]) && (runs[i][3] < 402))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 4, runs[i][3]);
|
||||
err++;
|
||||
}
|
||||
if (!((90 < runs[i][4]) && (runs[i][4] < 223))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 5, runs[i][4]);
|
||||
err++;
|
||||
}
|
||||
if (!((90 < runs[i][5]) && (runs[i][5] < 223))) {
|
||||
printf("test 3 failed, bit=%d run=%d num=%lu\n",
|
||||
i, 6, runs[i][5]);
|
||||
err++;
|
||||
}
|
||||
}
|
||||
printf("test 3 done\n");
|
||||
|
||||
/* test 4 */
|
||||
if (runs[0][33] != 0) {
|
||||
printf("test 4 failed, bit=%d run=%d num=%lu\n", 0, 34, runs[0][33]);
|
||||
err++;
|
||||
}
|
||||
if (runs[1][33] != 0) {
|
||||
printf("test 4 failed, bit=%d run=%d num=%lu\n", 1, 34, runs[1][33]);
|
||||
err++;
|
||||
}
|
||||
printf("test 4 done\n");
|
||||
err:
|
||||
err = ((err) ? 1 : 0);
|
||||
EXIT(err);
|
||||
}
|
||||
1
test/randtest.c
Symbolic link
1
test/randtest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/rand/randtest.c
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* This has been a quickly hacked 'ideatest.c'. When I add tests for other
|
||||
* RC2 modes, more of the code will be uncommented.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RC2
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RC2 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rc2.h>
|
||||
|
||||
static unsigned char RC2key[4][16] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
|
||||
};
|
||||
|
||||
static unsigned char RC2plain[4][8] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
};
|
||||
|
||||
static unsigned char RC2cipher[4][8] = {
|
||||
{0x1C, 0x19, 0x8A, 0x83, 0x8D, 0xF0, 0x28, 0xB7},
|
||||
{0x21, 0x82, 0x9C, 0x78, 0xA9, 0xF9, 0xC0, 0x74},
|
||||
{0x13, 0xDB, 0x35, 0x17, 0xD3, 0x21, 0x86, 0x9E},
|
||||
{0x50, 0xDC, 0x01, 0x62, 0xBD, 0x75, 0x7F, 0x31},
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, n, err = 0;
|
||||
RC2_KEY key;
|
||||
unsigned char buf[8], buf2[8];
|
||||
|
||||
for (n = 0; n < 4; n++) {
|
||||
RC2_set_key(&key, 16, &(RC2key[n][0]), 0 /* or 1024 */ );
|
||||
|
||||
RC2_ecb_encrypt(&(RC2plain[n][0]), buf, &key, RC2_ENCRYPT);
|
||||
if (memcmp(&(RC2cipher[n][0]), buf, 8) != 0) {
|
||||
printf("ecb rc2 error encrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", buf[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", RC2cipher[n][i]);
|
||||
err = 20;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
RC2_ecb_encrypt(buf, buf2, &key, RC2_DECRYPT);
|
||||
if (memcmp(&(RC2plain[n][0]), buf2, 8) != 0) {
|
||||
printf("ecb RC2 error decrypting\n");
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", buf[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", RC2plain[n][i]);
|
||||
printf("\n");
|
||||
err = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (err == 0)
|
||||
printf("ecb RC2 ok\n");
|
||||
|
||||
EXIT(err);
|
||||
}
|
||||
|
||||
#endif
|
||||
1
test/rc2test.c
Symbolic link
1
test/rc2test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/rc2/rc2test.c
|
||||
175
test/rc4test.c
175
test/rc4test.c
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RC4
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RC4 support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rc4.h>
|
||||
# include <openssl/sha.h>
|
||||
|
||||
static unsigned char keys[7][30] = {
|
||||
{8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
|
||||
{8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
|
||||
{8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
{4, 0xef, 0x01, 0x23, 0x45},
|
||||
{8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
|
||||
{4, 0xef, 0x01, 0x23, 0x45},
|
||||
};
|
||||
|
||||
static unsigned char data_len[7] = { 8, 8, 8, 20, 28, 10 };
|
||||
|
||||
static unsigned char data[7][30] = {
|
||||
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xff},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xff},
|
||||
{0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
||||
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
||||
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
||||
0x12, 0x34, 0x56, 0x78, 0xff},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff},
|
||||
{0},
|
||||
};
|
||||
|
||||
static unsigned char output[7][30] = {
|
||||
{0x75, 0xb7, 0x87, 0x80, 0x99, 0xe0, 0xc5, 0x96, 0x00},
|
||||
{0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79, 0x00},
|
||||
{0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a, 0x00},
|
||||
{0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf,
|
||||
0xbd, 0x61, 0x5a, 0x11, 0x62, 0xe1, 0xc7, 0xba,
|
||||
0x36, 0xb6, 0x78, 0x58, 0x00},
|
||||
{0x66, 0xa0, 0x94, 0x9f, 0x8a, 0xf7, 0xd6, 0x89,
|
||||
0x1f, 0x7f, 0x83, 0x2b, 0xa8, 0x33, 0xc0, 0x0c,
|
||||
0x89, 0x2e, 0xbe, 0x30, 0x14, 0x3c, 0xe2, 0x87,
|
||||
0x40, 0x01, 0x1e, 0xcf, 0x00},
|
||||
{0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf, 0xbd, 0x61, 0x00},
|
||||
{0},
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, err = 0;
|
||||
int j;
|
||||
unsigned char *p;
|
||||
RC4_KEY key;
|
||||
unsigned char obuf[512];
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
RC4_set_key(&key, keys[i][0], &(keys[i][1]));
|
||||
memset(obuf, 0, sizeof(obuf));
|
||||
RC4(&key, data_len[i], &(data[i][0]), obuf);
|
||||
if (memcmp(obuf, output[i], data_len[i] + 1) != 0) {
|
||||
printf("error calculating RC4\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < data_len[i] + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[i][0]);
|
||||
for (j = 0; j < data_len[i] + 1; j++)
|
||||
printf(" %02x", *(p++));
|
||||
printf("\n");
|
||||
err++;
|
||||
} else
|
||||
printf("test %d ok\n", i);
|
||||
}
|
||||
printf("test end processing ");
|
||||
for (i = 0; i < data_len[3]; i++) {
|
||||
RC4_set_key(&key, keys[3][0], &(keys[3][1]));
|
||||
memset(obuf, 0, sizeof(obuf));
|
||||
RC4(&key, i, &(data[3][0]), obuf);
|
||||
if ((memcmp(obuf, output[3], i) != 0) || (obuf[i] != 0)) {
|
||||
printf("error in RC4 length processing\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < i + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[3][0]);
|
||||
for (j = 0; j < i; j++)
|
||||
printf(" %02x", *(p++));
|
||||
printf(" 00\n");
|
||||
err++;
|
||||
} else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
printf("done\n");
|
||||
printf("test multi-call ");
|
||||
for (i = 0; i < data_len[3]; i++) {
|
||||
RC4_set_key(&key, keys[3][0], &(keys[3][1]));
|
||||
memset(obuf, 0, sizeof(obuf));
|
||||
RC4(&key, i, &(data[3][0]), obuf);
|
||||
RC4(&key, data_len[3] - i, &(data[3][i]), &(obuf[i]));
|
||||
if (memcmp(obuf, output[3], data_len[3] + 1) != 0) {
|
||||
printf("error in RC4 multi-call processing\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < data_len[3] + 1; j++)
|
||||
printf(" %02x", obuf[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
p = &(output[3][0]);
|
||||
for (j = 0; j < data_len[3] + 1; j++)
|
||||
printf(" %02x", *(p++));
|
||||
err++;
|
||||
} else {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
printf("done\n");
|
||||
printf("bulk test ");
|
||||
{
|
||||
unsigned char buf[513];
|
||||
SHA_CTX c;
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
static unsigned char expected[] = {
|
||||
0xa4, 0x7b, 0xcc, 0x00, 0x3d, 0xd0, 0xbd, 0xe1, 0xac, 0x5f,
|
||||
0x12, 0x1e, 0x45, 0xbc, 0xfb, 0x1a, 0xa1, 0xf2, 0x7f, 0xc5
|
||||
};
|
||||
|
||||
RC4_set_key(&key, keys[0][0], &(keys[3][1]));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
SHA1_Init(&c);
|
||||
for (i = 0; i < 2571; i++) {
|
||||
RC4(&key, sizeof(buf), buf, buf);
|
||||
SHA1_Update(&c, buf, sizeof(buf));
|
||||
}
|
||||
SHA1_Final(md, &c);
|
||||
|
||||
if (memcmp(md, expected, sizeof(md))) {
|
||||
printf("error in RC4 bulk test\n");
|
||||
printf("output:");
|
||||
for (j = 0; j < (int)sizeof(md); j++)
|
||||
printf(" %02x", md[j]);
|
||||
printf("\n");
|
||||
printf("expect:");
|
||||
for (j = 0; j < (int)sizeof(md); j++)
|
||||
printf(" %02x", expected[j]);
|
||||
printf("\n");
|
||||
err++;
|
||||
} else
|
||||
printf("ok\n");
|
||||
}
|
||||
EXIT(err);
|
||||
}
|
||||
#endif
|
||||
1
test/rc4test.c
Symbolic link
1
test/rc4test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/rc4/rc4test.c
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
|
||||
#ifdef OPENSSL_NO_RMD160
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No ripemd support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/ripemd.h>
|
||||
# include <openssl/evp.h>
|
||||
|
||||
# ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
# endif
|
||||
|
||||
static char test[][100] = {
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012345678901234567890" }
|
||||
};
|
||||
|
||||
static char *ret[] = {
|
||||
"9c1185a5c5e9fc54612808977ee8f548b2258d31",
|
||||
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
|
||||
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
|
||||
"5d0689ef49d2fae572b881b123a85ffa21595f36",
|
||||
"f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
|
||||
"12a053384a9c0c88e405a06c27dcf49ada62eb2b",
|
||||
"b0e20b6e3116640286ed3a87a5713079b21f5189",
|
||||
"9b752e45573d4b39f4dbd3323cab82bf63326bfb",
|
||||
};
|
||||
|
||||
static char *pt(unsigned char *md);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int i;
|
||||
int err = 0;
|
||||
char **R;
|
||||
char *p;
|
||||
unsigned char md[RIPEMD160_DIGEST_LENGTH];
|
||||
|
||||
R = ret;
|
||||
for (i = 0; i < OSSL_NELEM(test); i++) {
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(test[i], test[i], strlen(test[i]));
|
||||
# endif
|
||||
if (!EVP_Digest(test[i], strlen(test[i]), md, NULL, EVP_ripemd160(),
|
||||
NULL)) {
|
||||
printf("EVP Digest error.\n");
|
||||
EXIT(1);
|
||||
}
|
||||
p = pt(md);
|
||||
if (strcmp(p, (char *)*R) != 0) {
|
||||
printf("error calculating RIPEMD160 on '%s'\n", test[i]);
|
||||
printf("got %s instead of %s\n", p, *R);
|
||||
err++;
|
||||
} else
|
||||
printf("test %d ok\n", i + 1);
|
||||
R++;
|
||||
}
|
||||
EXIT(err);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *md)
|
||||
{
|
||||
int i;
|
||||
static char buf[80];
|
||||
|
||||
for (i = 0; i < RIPEMD160_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
#endif
|
||||
1
test/rmdtest.c
Symbolic link
1
test/rmdtest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/ripemd/rmdtest.c
|
||||
344
test/rsa_test.c
344
test/rsa_test.c
@@ -1,344 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
/* test vectors from p1ovect1.txt */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "e_os.h"
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bn.h>
|
||||
#ifdef OPENSSL_NO_RSA
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No RSA support\n");
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
# include <openssl/rsa.h>
|
||||
|
||||
# define SetKey \
|
||||
RSA_set0_key(key, \
|
||||
BN_bin2bn(n, sizeof(n)-1, NULL), \
|
||||
BN_bin2bn(e, sizeof(e)-1, NULL), \
|
||||
BN_bin2bn(d, sizeof(d)-1, NULL)); \
|
||||
RSA_set0_factors(key, \
|
||||
BN_bin2bn(p, sizeof(p)-1, NULL), \
|
||||
BN_bin2bn(q, sizeof(q)-1, NULL)); \
|
||||
RSA_set0_crt_params(key, \
|
||||
BN_bin2bn(dmp1, sizeof(dmp1)-1, NULL), \
|
||||
BN_bin2bn(dmq1, sizeof(dmq1)-1, NULL), \
|
||||
BN_bin2bn(iqmp, sizeof(iqmp)-1, NULL)); \
|
||||
memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
|
||||
return (sizeof(ctext_ex) - 1);
|
||||
|
||||
static int key1(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
|
||||
"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
|
||||
"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
|
||||
"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
|
||||
"\xF5";
|
||||
|
||||
static unsigned char e[] = "\x11";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
|
||||
"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
|
||||
"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
|
||||
"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
|
||||
"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
|
||||
"\x0D";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
|
||||
"\x89";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
|
||||
"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
|
||||
"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
|
||||
"\x51";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
|
||||
"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
|
||||
"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
|
||||
"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
|
||||
"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int key2(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
|
||||
"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
|
||||
"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
|
||||
"\x34\x77\xCF";
|
||||
|
||||
static unsigned char e[] = "\x3";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
|
||||
"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
|
||||
"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
|
||||
"\xE5\xEB";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
|
||||
"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
|
||||
"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
|
||||
"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
|
||||
"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
|
||||
"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
|
||||
"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
|
||||
"\x62\x51";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int key3(RSA *key, unsigned char *c)
|
||||
{
|
||||
static unsigned char n[] =
|
||||
"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
|
||||
"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
|
||||
"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
|
||||
"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
|
||||
"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
|
||||
"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
|
||||
"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
|
||||
"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
|
||||
"\xCB";
|
||||
|
||||
static unsigned char e[] = "\x11";
|
||||
|
||||
static unsigned char d[] =
|
||||
"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
|
||||
"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
|
||||
"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
|
||||
"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
|
||||
"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
|
||||
"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
|
||||
"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
|
||||
"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
|
||||
"\xC1";
|
||||
|
||||
static unsigned char p[] =
|
||||
"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
|
||||
"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
|
||||
"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
|
||||
"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
|
||||
"\x99";
|
||||
|
||||
static unsigned char q[] =
|
||||
"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
|
||||
"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
|
||||
"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
|
||||
"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
|
||||
"\x03";
|
||||
|
||||
static unsigned char dmp1[] =
|
||||
"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
|
||||
"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
|
||||
"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
|
||||
"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
|
||||
|
||||
static unsigned char dmq1[] =
|
||||
"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
|
||||
"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
|
||||
"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
|
||||
"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
|
||||
|
||||
static unsigned char iqmp[] =
|
||||
"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
|
||||
"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
|
||||
"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
|
||||
"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
|
||||
"\xF7";
|
||||
|
||||
static unsigned char ctext_ex[] =
|
||||
"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
|
||||
"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
|
||||
"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
|
||||
"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
|
||||
"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
|
||||
"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
|
||||
"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
|
||||
"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
|
||||
|
||||
SetKey;
|
||||
}
|
||||
|
||||
static int pad_unknown(void)
|
||||
{
|
||||
unsigned long l;
|
||||
while ((l = ERR_get_error()) != 0)
|
||||
if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static const char rnd_seed[] =
|
||||
"string to make the random number generator think it has entropy";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int err = 0;
|
||||
int v;
|
||||
RSA *key;
|
||||
unsigned char ptext[256];
|
||||
unsigned char ctext[256];
|
||||
static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
|
||||
unsigned char ctext_ex[256];
|
||||
int plen;
|
||||
int clen = 0;
|
||||
int num;
|
||||
int n;
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
|
||||
|
||||
plen = sizeof(ptext_ex) - 1;
|
||||
|
||||
for (v = 0; v < 3; v++) {
|
||||
key = RSA_new();
|
||||
switch (v) {
|
||||
case 0:
|
||||
clen = key1(key, ctext_ex);
|
||||
break;
|
||||
case 1:
|
||||
clen = key2(key, ctext_ex);
|
||||
break;
|
||||
case 2:
|
||||
clen = key3(key, ctext_ex);
|
||||
break;
|
||||
}
|
||||
|
||||
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
|
||||
RSA_PKCS1_PADDING);
|
||||
if (num != clen) {
|
||||
printf("PKCS#1 v1.5 encryption failed!\n");
|
||||
err = 1;
|
||||
goto oaep;
|
||||
}
|
||||
|
||||
num = RSA_private_decrypt(num, ctext, ptext, key, RSA_PKCS1_PADDING);
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("PKCS#1 v1.5 decryption failed!\n");
|
||||
err = 1;
|
||||
} else
|
||||
printf("PKCS #1 v1.5 encryption/decryption ok\n");
|
||||
|
||||
oaep:
|
||||
ERR_clear_error();
|
||||
num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num == -1 && pad_unknown()) {
|
||||
printf("No OAEP support\n");
|
||||
goto next;
|
||||
}
|
||||
if (num != clen) {
|
||||
printf("OAEP encryption failed!\n");
|
||||
err = 1;
|
||||
goto next;
|
||||
}
|
||||
|
||||
num = RSA_private_decrypt(num, ctext, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("OAEP decryption (encrypted data) failed!\n");
|
||||
err = 1;
|
||||
} else if (memcmp(ctext, ctext_ex, num) == 0)
|
||||
printf("OAEP test vector %d passed!\n", v);
|
||||
|
||||
/*
|
||||
* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). Try
|
||||
* decrypting ctext_ex
|
||||
*/
|
||||
|
||||
num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
|
||||
if (num != plen || memcmp(ptext, ptext_ex, num) != 0) {
|
||||
printf("OAEP decryption (test vector data) failed!\n");
|
||||
err = 1;
|
||||
} else
|
||||
printf("OAEP encryption/decryption ok\n");
|
||||
|
||||
/* Try decrypting corrupted ciphertexts. */
|
||||
for (n = 0; n < clen; ++n) {
|
||||
ctext[n] ^= 1;
|
||||
num = RSA_private_decrypt(clen, ctext, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num > 0) {
|
||||
printf("Corrupt data decrypted!\n");
|
||||
err = 1;
|
||||
break;
|
||||
}
|
||||
ctext[n] ^= 1;
|
||||
}
|
||||
|
||||
/* Test truncated ciphertexts, as well as negative length. */
|
||||
for (n = -1; n < clen; ++n) {
|
||||
num = RSA_private_decrypt(n, ctext, ptext, key,
|
||||
RSA_PKCS1_OAEP_PADDING);
|
||||
if (num > 0) {
|
||||
printf("Truncated data decrypted!\n");
|
||||
err = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
next:
|
||||
RSA_free(key);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
|
||||
err = 1;
|
||||
#endif
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
1
test/rsa_test.c
Symbolic link
1
test/rsa_test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/rsa/rsa_test.c
|
||||
111
test/sha1test.c
111
test/sha1test.c
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../e_os.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#ifdef CHARSET_EBCDIC
|
||||
# include <openssl/ebcdic.h>
|
||||
#endif
|
||||
|
||||
static char test[][80] = {
|
||||
{ "abc" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }
|
||||
};
|
||||
|
||||
static char *ret[] = {
|
||||
"a9993e364706816aba3e25717850c26c9cd0d89d",
|
||||
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
|
||||
};
|
||||
|
||||
static char *bigret = "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
|
||||
|
||||
static char *pt(unsigned char *md);
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int i;
|
||||
int err = 0;
|
||||
char **R;
|
||||
static unsigned char buf[1000];
|
||||
char *p, *r;
|
||||
EVP_MD_CTX *c;
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
|
||||
c = EVP_MD_CTX_new();
|
||||
R = ret;
|
||||
for (i = 0; i < OSSL_NELEM(test); i++) {
|
||||
# ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(test[i], test[i], strlen(test[i]));
|
||||
# endif
|
||||
if (!EVP_Digest(test[i], strlen(test[i]), md, NULL, EVP_sha1(),
|
||||
NULL)) {
|
||||
printf("EVP_Digest() error\n");
|
||||
err++;
|
||||
goto err;
|
||||
}
|
||||
p = pt(md);
|
||||
if (strcmp(p, (char *)*R) != 0) {
|
||||
printf("error calculating SHA1 on '%s'\n", test[i]);
|
||||
printf("got %s instead of %s\n", p, *R);
|
||||
err++;
|
||||
} else
|
||||
printf("test %d ok\n", i + 1);
|
||||
R++;
|
||||
}
|
||||
|
||||
memset(buf, 'a', 1000);
|
||||
#ifdef CHARSET_EBCDIC
|
||||
ebcdic2ascii(buf, buf, 1000);
|
||||
#endif /* CHARSET_EBCDIC */
|
||||
if (!EVP_DigestInit_ex(c, EVP_sha1(), NULL)) {
|
||||
printf("EVP_DigestInit_ex() error\n");
|
||||
err++;
|
||||
goto err;
|
||||
}
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (!EVP_DigestUpdate(c, buf, 1000)) {
|
||||
printf("EVP_DigestUpdate() error\n");
|
||||
err++;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(c, md, NULL)) {
|
||||
printf("EVP_DigestFinal() error\n");
|
||||
err++;
|
||||
goto err;
|
||||
}
|
||||
p = pt(md);
|
||||
|
||||
r = bigret;
|
||||
if (strcmp(p, r) != 0) {
|
||||
printf("error calculating SHA1 on 'a' * 1000\n");
|
||||
printf("got %s instead of %s\n", p, r);
|
||||
err++;
|
||||
} else
|
||||
printf("test 3 ok\n");
|
||||
err:
|
||||
EVP_MD_CTX_free(c);
|
||||
EXIT(err);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static char *pt(unsigned char *md)
|
||||
{
|
||||
int i;
|
||||
static char buf[80];
|
||||
|
||||
for (i = 0; i < SHA_DIGEST_LENGTH; i++)
|
||||
sprintf(&(buf[i * 2]), "%02x", md[i]);
|
||||
return (buf);
|
||||
}
|
||||
1
test/sha1test.c
Symbolic link
1
test/sha1test.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/sha/sha1test.c
|
||||
177
test/sha256t.c
177
test/sha256t.c
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
static const unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
|
||||
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
|
||||
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
|
||||
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
|
||||
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
|
||||
};
|
||||
|
||||
static const unsigned char app_b2[SHA256_DIGEST_LENGTH] = {
|
||||
0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
|
||||
0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
|
||||
0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
|
||||
0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
|
||||
};
|
||||
|
||||
static const unsigned char app_b3[SHA256_DIGEST_LENGTH] = {
|
||||
0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92,
|
||||
0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
|
||||
0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e,
|
||||
0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0
|
||||
};
|
||||
|
||||
static const unsigned char addenum_1[SHA224_DIGEST_LENGTH] = {
|
||||
0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
|
||||
0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
|
||||
0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
|
||||
0xe3, 0x6c, 0x9d, 0xa7
|
||||
};
|
||||
|
||||
static const unsigned char addenum_2[SHA224_DIGEST_LENGTH] = {
|
||||
0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc,
|
||||
0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50,
|
||||
0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19,
|
||||
0x52, 0x52, 0x25, 0x25
|
||||
};
|
||||
|
||||
static const unsigned char addenum_3[SHA224_DIGEST_LENGTH] = {
|
||||
0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8,
|
||||
0xbb, 0xb4, 0xc1, 0xea, 0x97, 0x61, 0x8a, 0x4b,
|
||||
0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48, 0xb2, 0xee,
|
||||
0x4e, 0xe7, 0xad, 0x67
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char md[SHA256_DIGEST_LENGTH];
|
||||
int i;
|
||||
EVP_MD_CTX *evp;
|
||||
|
||||
fprintf(stdout, "Testing SHA-256 ");
|
||||
|
||||
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha256(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_b1, sizeof(app_b1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
if (!EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
|
||||
"ijkljklm" "klmnlmno" "mnopnopq", 56, md,
|
||||
NULL, EVP_sha256(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_b2, sizeof(app_b2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
evp = EVP_MD_CTX_new();
|
||||
if (evp == NULL) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed. (malloc failure)\n");
|
||||
return 1;
|
||||
}
|
||||
if (!EVP_DigestInit_ex(evp, EVP_sha256(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < 1000000; i += 288) {
|
||||
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 288 ? 1000000 - i : 288))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(evp, md, NULL))
|
||||
goto err;
|
||||
|
||||
if (memcmp(md, app_b3, sizeof(app_b3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, "Testing SHA-224 ");
|
||||
|
||||
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha224(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, addenum_1, sizeof(addenum_1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
if (!EVP_Digest("abcdbcde" "cdefdefg" "efghfghi" "ghijhijk"
|
||||
"ijkljklm" "klmnlmno" "mnopnopq", 56, md,
|
||||
NULL, EVP_sha224(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, addenum_2, sizeof(addenum_2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
EVP_MD_CTX_reset(evp);
|
||||
if (!EVP_DigestInit_ex(evp, EVP_sha224(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < 1000000; i += 64) {
|
||||
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 64 ? 1000000 - i : 64))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(evp, md, NULL))
|
||||
goto err;
|
||||
EVP_MD_CTX_free(evp);
|
||||
|
||||
if (memcmp(md, addenum_3, sizeof(addenum_3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
fprintf(stderr, "Fatal EVP error!\n");
|
||||
return 1;
|
||||
}
|
||||
1
test/sha256t.c
Symbolic link
1
test/sha256t.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/sha/sha256t.c
|
||||
199
test/sha512t.c
199
test/sha512t.c
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
static const unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
|
||||
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
|
||||
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
|
||||
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
|
||||
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
|
||||
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
|
||||
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
|
||||
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
|
||||
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
|
||||
};
|
||||
|
||||
static const unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
|
||||
0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
|
||||
0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
|
||||
0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
|
||||
0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
|
||||
0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
|
||||
0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
|
||||
0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
|
||||
0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
|
||||
};
|
||||
|
||||
static const unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
|
||||
0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
|
||||
0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
|
||||
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
|
||||
0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
|
||||
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
|
||||
0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
|
||||
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
|
||||
0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b
|
||||
};
|
||||
|
||||
static const unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
|
||||
0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
|
||||
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
|
||||
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
|
||||
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
|
||||
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
|
||||
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
|
||||
};
|
||||
|
||||
static const unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
|
||||
0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
|
||||
0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
|
||||
0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
|
||||
0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
|
||||
0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
|
||||
0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
|
||||
};
|
||||
|
||||
static const unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
|
||||
0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
|
||||
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
|
||||
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
|
||||
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
|
||||
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
|
||||
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char md[SHA512_DIGEST_LENGTH];
|
||||
int i;
|
||||
EVP_MD_CTX *evp;
|
||||
|
||||
fprintf(stdout, "Testing SHA-512 ");
|
||||
|
||||
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_c1, sizeof(app_c1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
if (!EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
|
||||
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
|
||||
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
|
||||
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha512(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_c2, sizeof(app_c2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
evp = EVP_MD_CTX_new();
|
||||
if (evp == NULL) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed. (malloc failure)\n");
|
||||
return 1;
|
||||
}
|
||||
if (!EVP_DigestInit_ex(evp, EVP_sha512(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < 1000000; i += 288) {
|
||||
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 288 ? 1000000 - i : 288))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(evp, md, NULL))
|
||||
goto err;
|
||||
EVP_MD_CTX_reset(evp);
|
||||
|
||||
if (memcmp(md, app_c3, sizeof(app_c3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, "Testing SHA-384 ");
|
||||
|
||||
if (!EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_d1, sizeof(app_d1))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 1 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
if (!EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
|
||||
"efghijkl" "fghijklm" "ghijklmn" "hijklmno"
|
||||
"ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
|
||||
"mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha384(), NULL))
|
||||
goto err;
|
||||
if (memcmp(md, app_d2, sizeof(app_d2))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 2 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
if (!EVP_DigestInit_ex(evp, EVP_sha384(), NULL))
|
||||
goto err;
|
||||
for (i = 0; i < 1000000; i += 64) {
|
||||
if (!EVP_DigestUpdate(evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
|
||||
"aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
|
||||
(1000000 - i) < 64 ? 1000000 - i : 64))
|
||||
goto err;
|
||||
}
|
||||
if (!EVP_DigestFinal_ex(evp, md, NULL))
|
||||
goto err;
|
||||
EVP_MD_CTX_free(evp);
|
||||
|
||||
if (memcmp(md, app_d3, sizeof(app_d3))) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nTEST 3 of 3 failed.\n");
|
||||
return 1;
|
||||
} else
|
||||
fprintf(stdout, ".");
|
||||
fflush(stdout);
|
||||
|
||||
fprintf(stdout, " passed.\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "\nFatal EVP error!\n");
|
||||
return 1;
|
||||
}
|
||||
1
test/sha512t.c
Symbolic link
1
test/sha512t.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/sha/sha512t.c
|
||||
@@ -1 +1 @@
|
||||
Somewhat longer test content for OpenSSL CMS utility to handle, and a bit longer...
|
||||
Some test content for OpenSSL CMS
|
||||
@@ -16,7 +16,7 @@ default_keyfile = privkey.pem
|
||||
# Don't prompt for fields: use those in section directly
|
||||
prompt = no
|
||||
distinguished_name = req_distinguished_name
|
||||
x509_extensions = v3_ca # The extensions to add to the self signed cert
|
||||
x509_extensions = v3_ca # The extentions to add to the self signed cert
|
||||
string_mask = utf8only
|
||||
|
||||
# req_extensions = v3_req # The extensions to add to a certificate request
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#!/bin/sh
|
||||
# Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
|
||||
# Utility to recreate S/MIME certificates
|
||||
|
||||
|
||||
312
test/srptest.c
312
test/srptest.c
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
#ifdef OPENSSL_NO_SRP
|
||||
|
||||
# include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No SRP support\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# include <openssl/srp.h>
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/err.h>
|
||||
|
||||
static void showbn(const char *name, const BIGNUM *bn)
|
||||
{
|
||||
fputs(name, stdout);
|
||||
fputs(" = ", stdout);
|
||||
BN_print_fp(stdout, bn);
|
||||
putc('\n', stdout);
|
||||
}
|
||||
|
||||
# define RANDOM_SIZE 32 /* use 256 bits on each side */
|
||||
|
||||
static int run_srp(const char *username, const char *client_pass,
|
||||
const char *server_pass)
|
||||
{
|
||||
int ret = -1;
|
||||
BIGNUM *s = NULL;
|
||||
BIGNUM *v = NULL;
|
||||
BIGNUM *a = NULL;
|
||||
BIGNUM *b = NULL;
|
||||
BIGNUM *u = NULL;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *Apub = NULL;
|
||||
BIGNUM *Bpub = NULL;
|
||||
BIGNUM *Kclient = NULL;
|
||||
BIGNUM *Kserver = NULL;
|
||||
unsigned char rand_tmp[RANDOM_SIZE];
|
||||
/* use builtin 1024-bit params */
|
||||
const SRP_gN *GN = SRP_get_default_gN("1024");
|
||||
|
||||
if (GN == NULL) {
|
||||
fprintf(stderr, "Failed to get SRP parameters\n");
|
||||
return -1;
|
||||
}
|
||||
/* Set up server's password entry */
|
||||
if (!SRP_create_verifier_BN(username, server_pass, &s, &v, GN->N, GN->g)) {
|
||||
fprintf(stderr, "Failed to create SRP verifier\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
showbn("N", GN->N);
|
||||
showbn("g", GN->g);
|
||||
showbn("Salt", s);
|
||||
showbn("Verifier", v);
|
||||
|
||||
/* Server random */
|
||||
RAND_bytes(rand_tmp, sizeof(rand_tmp));
|
||||
b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);
|
||||
/* TODO - check b != 0 */
|
||||
showbn("b", b);
|
||||
|
||||
/* Server's first message */
|
||||
Bpub = SRP_Calc_B(b, GN->N, GN->g, v);
|
||||
showbn("B", Bpub);
|
||||
|
||||
if (!SRP_Verify_B_mod_N(Bpub, GN->N)) {
|
||||
fprintf(stderr, "Invalid B\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Client random */
|
||||
RAND_bytes(rand_tmp, sizeof(rand_tmp));
|
||||
a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);
|
||||
/* TODO - check a != 0 */
|
||||
showbn("a", a);
|
||||
|
||||
/* Client's response */
|
||||
Apub = SRP_Calc_A(a, GN->N, GN->g);
|
||||
showbn("A", Apub);
|
||||
|
||||
if (!SRP_Verify_A_mod_N(Apub, GN->N)) {
|
||||
fprintf(stderr, "Invalid A\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Both sides calculate u */
|
||||
u = SRP_Calc_u(Apub, Bpub, GN->N);
|
||||
|
||||
/* Client's key */
|
||||
x = SRP_Calc_x(s, username, client_pass);
|
||||
Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);
|
||||
showbn("Client's key", Kclient);
|
||||
|
||||
/* Server's key */
|
||||
Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);
|
||||
showbn("Server's key", Kserver);
|
||||
|
||||
if (BN_cmp(Kclient, Kserver) == 0) {
|
||||
ret = 0;
|
||||
} else {
|
||||
fprintf(stderr, "Keys mismatch\n");
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
BN_clear_free(Kclient);
|
||||
BN_clear_free(Kserver);
|
||||
BN_clear_free(x);
|
||||
BN_free(u);
|
||||
BN_free(Apub);
|
||||
BN_clear_free(a);
|
||||
BN_free(Bpub);
|
||||
BN_clear_free(b);
|
||||
BN_free(s);
|
||||
BN_clear_free(v);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_bn(const char *name, const BIGNUM *bn, const char *hexbn)
|
||||
{
|
||||
BIGNUM *tmp = NULL;
|
||||
int rv;
|
||||
if (BN_hex2bn(&tmp, hexbn) == 0)
|
||||
return 0;
|
||||
rv = BN_cmp(bn, tmp);
|
||||
if (rv == 0) {
|
||||
printf("%s = ", name);
|
||||
BN_print_fp(stdout, bn);
|
||||
printf("\n");
|
||||
BN_free(tmp);
|
||||
return 1;
|
||||
}
|
||||
printf("Unexpected %s value\n", name);
|
||||
printf("Expecting: ");
|
||||
BN_print_fp(stdout, tmp);
|
||||
printf("\nReceived: ");
|
||||
BN_print_fp(stdout, bn);
|
||||
printf("\n");
|
||||
BN_free(tmp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SRP test vectors from RFC5054 */
|
||||
static int run_srp_kat(void)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *s = NULL;
|
||||
BIGNUM *v = NULL;
|
||||
BIGNUM *a = NULL;
|
||||
BIGNUM *b = NULL;
|
||||
BIGNUM *u = NULL;
|
||||
BIGNUM *x = NULL;
|
||||
BIGNUM *Apub = NULL;
|
||||
BIGNUM *Bpub = NULL;
|
||||
BIGNUM *Kclient = NULL;
|
||||
BIGNUM *Kserver = NULL;
|
||||
/* use builtin 1024-bit params */
|
||||
const SRP_gN *GN = SRP_get_default_gN("1024");
|
||||
|
||||
if (GN == NULL) {
|
||||
fprintf(stderr, "Failed to get SRP parameters\n");
|
||||
goto err;
|
||||
}
|
||||
BN_hex2bn(&s, "BEB25379D1A8581EB5A727673A2441EE");
|
||||
/* Set up server's password entry */
|
||||
if (!SRP_create_verifier_BN("alice", "password123", &s, &v, GN->N,
|
||||
GN->g)) {
|
||||
fprintf(stderr, "Failed to create SRP verifier\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!check_bn("v", v,
|
||||
"7E273DE8696FFC4F4E337D05B4B375BEB0DDE1569E8FA00A9886D812"
|
||||
"9BADA1F1822223CA1A605B530E379BA4729FDC59F105B4787E5186F5"
|
||||
"C671085A1447B52A48CF1970B4FB6F8400BBF4CEBFBB168152E08AB5"
|
||||
"EA53D15C1AFF87B2B9DA6E04E058AD51CC72BFC9033B564E26480D78"
|
||||
"E955A5E29E7AB245DB2BE315E2099AFB"))
|
||||
goto err;
|
||||
|
||||
/* Server random */
|
||||
BN_hex2bn(&b, "E487CB59D31AC550471E81F00F6928E01DDA08E974A004F49E61F5D1"
|
||||
"05284D20");
|
||||
|
||||
/* Server's first message */
|
||||
Bpub = SRP_Calc_B(b, GN->N, GN->g, v);
|
||||
|
||||
if (!SRP_Verify_B_mod_N(Bpub, GN->N)) {
|
||||
fprintf(stderr, "Invalid B\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!check_bn("B", Bpub,
|
||||
"BD0C61512C692C0CB6D041FA01BB152D4916A1E77AF46AE105393011"
|
||||
"BAF38964DC46A0670DD125B95A981652236F99D9B681CBF87837EC99"
|
||||
"6C6DA04453728610D0C6DDB58B318885D7D82C7F8DEB75CE7BD4FBAA"
|
||||
"37089E6F9C6059F388838E7A00030B331EB76840910440B1B27AAEAE"
|
||||
"EB4012B7D7665238A8E3FB004B117B58"))
|
||||
goto err;
|
||||
|
||||
/* Client random */
|
||||
BN_hex2bn(&a, "60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DD"
|
||||
"DA2D4393");
|
||||
|
||||
/* Client's response */
|
||||
Apub = SRP_Calc_A(a, GN->N, GN->g);
|
||||
|
||||
if (!SRP_Verify_A_mod_N(Apub, GN->N)) {
|
||||
fprintf(stderr, "Invalid A\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!check_bn("A", Apub,
|
||||
"61D5E490F6F1B79547B0704C436F523DD0E560F0C64115BB72557EC4"
|
||||
"4352E8903211C04692272D8B2D1A5358A2CF1B6E0BFCF99F921530EC"
|
||||
"8E39356179EAE45E42BA92AEACED825171E1E8B9AF6D9C03E1327F44"
|
||||
"BE087EF06530E69F66615261EEF54073CA11CF5858F0EDFDFE15EFEA"
|
||||
"B349EF5D76988A3672FAC47B0769447B"))
|
||||
goto err;
|
||||
|
||||
/* Both sides calculate u */
|
||||
u = SRP_Calc_u(Apub, Bpub, GN->N);
|
||||
|
||||
if (!check_bn("u", u, "CE38B9593487DA98554ED47D70A7AE5F462EF019"))
|
||||
goto err;
|
||||
|
||||
/* Client's key */
|
||||
x = SRP_Calc_x(s, "alice", "password123");
|
||||
Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);
|
||||
if (!check_bn("Client's key", Kclient,
|
||||
"B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D"
|
||||
"233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C"
|
||||
"41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F"
|
||||
"3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D"
|
||||
"C346D7E474B29EDE8A469FFECA686E5A"))
|
||||
goto err;
|
||||
/* Server's key */
|
||||
Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);
|
||||
if (!check_bn("Server's key", Kserver,
|
||||
"B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D"
|
||||
"233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C"
|
||||
"41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F"
|
||||
"3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D"
|
||||
"C346D7E474B29EDE8A469FFECA686E5A"))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_clear_free(Kclient);
|
||||
BN_clear_free(Kserver);
|
||||
BN_clear_free(x);
|
||||
BN_free(u);
|
||||
BN_free(Apub);
|
||||
BN_clear_free(a);
|
||||
BN_free(Bpub);
|
||||
BN_clear_free(b);
|
||||
BN_free(s);
|
||||
BN_clear_free(v);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BIO *bio_err;
|
||||
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
|
||||
|
||||
CRYPTO_set_mem_debug(1);
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
|
||||
/* "Negative" test, expect a mismatch */
|
||||
if (run_srp("alice", "password1", "password2") == 0) {
|
||||
fprintf(stderr, "Mismatched SRP run failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* "Positive" test, should pass */
|
||||
if (run_srp("alice", "password", "password") != 0) {
|
||||
fprintf(stderr, "Plain SRP run failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* KAT from RFC5054: should pass */
|
||||
if (run_srp_kat() != 1) {
|
||||
fprintf(stderr, "SRP KAT failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
|
||||
if (CRYPTO_mem_leaks(bio_err) <= 0)
|
||||
return 1;
|
||||
#endif
|
||||
BIO_free(bio_err);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
1
test/srptest.c
Symbolic link
1
test/srptest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../crypto/srp/srptest.c
|
||||
1
test/ssltest.c
Symbolic link
1
test/ssltest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/ssltest.c
|
||||
@@ -8,9 +8,14 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <openssl/safestack.h>
|
||||
|
||||
#include "ssltestlib.h"
|
||||
|
||||
#define SSL_IS_DTLS(s) (s->method->version == DTLS_ANY_VERSION \
|
||||
|| s->method->version == DTLS1_2_VERSION \
|
||||
|| s->method->version == DTLS1_VERSION)
|
||||
|
||||
static int tls_dump_new(BIO *bi);
|
||||
static int tls_dump_free(BIO *a);
|
||||
static int tls_dump_read(BIO *b, char *out, int outl);
|
||||
@@ -24,42 +29,32 @@ static int tls_dump_puts(BIO *bp, const char *str);
|
||||
|
||||
# define BIO_TYPE_MEMPACKET_TEST 0x81
|
||||
|
||||
static BIO_METHOD *method_tls_dump = NULL;
|
||||
static BIO_METHOD *method_mempacket_test = NULL;
|
||||
static BIO_METHOD method_tls_dump = {
|
||||
BIO_TYPE_TLS_DUMP_FILTER,
|
||||
"TLS dump filter",
|
||||
tls_dump_write,
|
||||
tls_dump_read,
|
||||
tls_dump_puts,
|
||||
tls_dump_gets,
|
||||
tls_dump_ctrl,
|
||||
tls_dump_new,
|
||||
tls_dump_free
|
||||
};
|
||||
|
||||
/* Note: Not thread safe! */
|
||||
const BIO_METHOD *bio_f_tls_dump_filter(void)
|
||||
BIO_METHOD *bio_f_tls_dump_filter(void)
|
||||
{
|
||||
if (method_tls_dump == NULL) {
|
||||
method_tls_dump = BIO_meth_new(BIO_TYPE_TLS_DUMP_FILTER,
|
||||
"TLS dump filter");
|
||||
if ( method_tls_dump == NULL
|
||||
|| !BIO_meth_set_write(method_tls_dump, tls_dump_write)
|
||||
|| !BIO_meth_set_read(method_tls_dump, tls_dump_read)
|
||||
|| !BIO_meth_set_puts(method_tls_dump, tls_dump_puts)
|
||||
|| !BIO_meth_set_gets(method_tls_dump, tls_dump_gets)
|
||||
|| !BIO_meth_set_ctrl(method_tls_dump, tls_dump_ctrl)
|
||||
|| !BIO_meth_set_create(method_tls_dump, tls_dump_new)
|
||||
|| !BIO_meth_set_destroy(method_tls_dump, tls_dump_free))
|
||||
return NULL;
|
||||
}
|
||||
return method_tls_dump;
|
||||
}
|
||||
|
||||
void bio_f_tls_dump_filter_free(void)
|
||||
{
|
||||
BIO_meth_free(method_tls_dump);
|
||||
return &method_tls_dump;
|
||||
}
|
||||
|
||||
static int tls_dump_new(BIO *bio)
|
||||
{
|
||||
BIO_set_init(bio, 1);
|
||||
bio->init = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tls_dump_free(BIO *bio)
|
||||
{
|
||||
BIO_set_init(bio, 0);
|
||||
bio->init = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -231,12 +226,39 @@ static int tls_dump_puts(BIO *bio, const char *str)
|
||||
}
|
||||
|
||||
|
||||
struct mempacket_st {
|
||||
typedef struct mempacket_st {
|
||||
unsigned char *data;
|
||||
int len;
|
||||
unsigned int num;
|
||||
unsigned int type;
|
||||
};
|
||||
} MEMPACKET;
|
||||
|
||||
/*
|
||||
* These defines would normally be auto-generated and in safestack.h...but this
|
||||
* is just for tests so its probably not an appropriate place
|
||||
*/
|
||||
# define sk_MEMPACKET_new(cmp) SKM_sk_new(MEMPACKET, (cmp))
|
||||
# define sk_MEMPACKET_new_null() SKM_sk_new_null(MEMPACKET)
|
||||
# define sk_MEMPACKET_free(st) SKM_sk_free(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_num(st) SKM_sk_num(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_value(st, i) SKM_sk_value(MEMPACKET, (st), (i))
|
||||
# define sk_MEMPACKET_set(st, i, val) SKM_sk_set(MEMPACKET, (st), (i), (val))
|
||||
# define sk_MEMPACKET_zero(st) SKM_sk_zero(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_push(st, val) SKM_sk_push(MEMPACKET, (st), (val))
|
||||
# define sk_MEMPACKET_unshift(st, val) SKM_sk_unshift(MEMPACKET, (st), (val))
|
||||
# define sk_MEMPACKET_find(st, val) SKM_sk_find(MEMPACKET, (st), (val))
|
||||
# define sk_MEMPACKET_find_ex(st, val) SKM_sk_find_ex(MEMPACKET, (st), (val))
|
||||
# define sk_MEMPACKET_delete(st, i) SKM_sk_delete(MEMPACKET, (st), (i))
|
||||
# define sk_MEMPACKET_delete_ptr(st, ptr) SKM_sk_delete_ptr(MEMPACKET, (st), (ptr))
|
||||
# define sk_MEMPACKET_insert(st, val, i) SKM_sk_insert(MEMPACKET, (st), (val), (i))
|
||||
# define sk_MEMPACKET_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(MEMPACKET, (st), (cmp))
|
||||
# define sk_MEMPACKET_dup(st) SKM_sk_dup(MEMPACKET, st)
|
||||
# define sk_MEMPACKET_pop_free(st, free_func) SKM_sk_pop_free(MEMPACKET, (st), (free_func))
|
||||
# define sk_MEMPACKET_deep_copy(st, copy_func, free_func) SKM_sk_deep_copy(MEMPACKET, (st), (copy_func), (free_func))
|
||||
# define sk_MEMPACKET_shift(st) SKM_sk_shift(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_pop(st) SKM_sk_pop(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_sort(st) SKM_sk_sort(MEMPACKET, (st))
|
||||
# define sk_MEMPACKET_is_sorted(st) SKM_sk_is_sorted(MEMPACKET, (st))
|
||||
|
||||
static void mempacket_free(MEMPACKET *pkt)
|
||||
{
|
||||
@@ -262,52 +284,48 @@ static long mempacket_test_ctrl(BIO *b, int cmd, long num, void *ptr);
|
||||
static int mempacket_test_gets(BIO *bp, char *buf, int size);
|
||||
static int mempacket_test_puts(BIO *bp, const char *str);
|
||||
|
||||
const BIO_METHOD *bio_s_mempacket_test(void)
|
||||
{
|
||||
if (method_mempacket_test == NULL) {
|
||||
method_mempacket_test = BIO_meth_new(BIO_TYPE_MEMPACKET_TEST,
|
||||
"Mem Packet Test");
|
||||
if ( method_mempacket_test == NULL
|
||||
|| !BIO_meth_set_write(method_mempacket_test, mempacket_test_write)
|
||||
|| !BIO_meth_set_read(method_mempacket_test, mempacket_test_read)
|
||||
|| !BIO_meth_set_puts(method_mempacket_test, mempacket_test_puts)
|
||||
|| !BIO_meth_set_gets(method_mempacket_test, mempacket_test_gets)
|
||||
|| !BIO_meth_set_ctrl(method_mempacket_test, mempacket_test_ctrl)
|
||||
|| !BIO_meth_set_create(method_mempacket_test, mempacket_test_new)
|
||||
|| !BIO_meth_set_destroy(method_mempacket_test, mempacket_test_free))
|
||||
return NULL;
|
||||
}
|
||||
return method_mempacket_test;
|
||||
}
|
||||
static BIO_METHOD method_mempacket_test = {
|
||||
BIO_TYPE_MEMPACKET_TEST,
|
||||
"Mem Packet Test",
|
||||
mempacket_test_write,
|
||||
mempacket_test_read,
|
||||
mempacket_test_puts,
|
||||
mempacket_test_gets,
|
||||
mempacket_test_ctrl,
|
||||
mempacket_test_new,
|
||||
mempacket_test_free
|
||||
};
|
||||
|
||||
void bio_s_mempacket_test_free(void)
|
||||
BIO_METHOD *bio_s_mempacket_test(void)
|
||||
{
|
||||
BIO_meth_free(method_mempacket_test);
|
||||
return &method_mempacket_test;
|
||||
}
|
||||
|
||||
static int mempacket_test_new(BIO *bio)
|
||||
{
|
||||
MEMPACKET_TEST_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
|
||||
MEMPACKET_TEST_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->pkts = sk_MEMPACKET_new_null();
|
||||
if (ctx->pkts == NULL) {
|
||||
OPENSSL_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
BIO_set_init(bio, 1);
|
||||
BIO_set_data(bio, ctx);
|
||||
bio->init = 1;
|
||||
bio->ptr = ctx;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mempacket_test_free(BIO *bio)
|
||||
{
|
||||
MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
|
||||
MEMPACKET_TEST_CTX *ctx = bio->ptr;
|
||||
|
||||
sk_MEMPACKET_pop_free(ctx->pkts, mempacket_free);
|
||||
OPENSSL_free(ctx);
|
||||
BIO_set_data(bio, NULL);
|
||||
BIO_set_init(bio, 0);
|
||||
bio->ptr = NULL;
|
||||
bio->init = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -323,7 +341,7 @@ static int mempacket_test_free(BIO *bio)
|
||||
|
||||
static int mempacket_test_read(BIO *bio, char *out, int outl)
|
||||
{
|
||||
MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
|
||||
MEMPACKET_TEST_CTX *ctx = bio->ptr;
|
||||
MEMPACKET *thispkt;
|
||||
unsigned char *rec;
|
||||
int rem;
|
||||
@@ -388,7 +406,7 @@ static int mempacket_test_read(BIO *bio, char *out, int outl)
|
||||
int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
|
||||
int type)
|
||||
{
|
||||
MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
|
||||
MEMPACKET_TEST_CTX *ctx = bio->ptr;
|
||||
MEMPACKET *thispkt, *looppkt, *nextpkt;
|
||||
int i;
|
||||
|
||||
@@ -474,7 +492,7 @@ static int mempacket_test_write(BIO *bio, const char *in, int inl)
|
||||
static long mempacket_test_ctrl(BIO *bio, int cmd, long num, void *ptr)
|
||||
{
|
||||
long ret = 1;
|
||||
MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
|
||||
MEMPACKET_TEST_CTX *ctx = bio->ptr;
|
||||
MEMPACKET *thispkt;
|
||||
|
||||
switch (cmd) {
|
||||
@@ -482,10 +500,10 @@ static long mempacket_test_ctrl(BIO *bio, int cmd, long num, void *ptr)
|
||||
ret = (long)(sk_MEMPACKET_num(ctx->pkts) == 0);
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
ret = BIO_get_shutdown(bio);
|
||||
ret = bio->shutdown;
|
||||
break;
|
||||
case BIO_CTRL_SET_CLOSE:
|
||||
BIO_set_shutdown(bio, (int)num);
|
||||
bio->shutdown = (int)num;
|
||||
break;
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret = 0L;
|
||||
@@ -550,10 +568,6 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
|
||||
goto err;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
SSL_CTX_set_dh_auto(serverctx, 1);
|
||||
#endif
|
||||
|
||||
*sctx = serverctx;
|
||||
*cctx = clientctx;
|
||||
|
||||
@@ -575,23 +589,17 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
|
||||
SSL *serverssl, *clientssl;
|
||||
BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
|
||||
|
||||
if (*sssl == NULL)
|
||||
serverssl = SSL_new(serverctx);
|
||||
else
|
||||
serverssl = *sssl;
|
||||
if (*cssl == NULL)
|
||||
clientssl = SSL_new(clientctx);
|
||||
else
|
||||
clientssl = *cssl;
|
||||
serverssl = SSL_new(serverctx);
|
||||
clientssl = SSL_new(clientctx);
|
||||
|
||||
if (serverssl == NULL || clientssl == NULL) {
|
||||
printf("Failed to create SSL object\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (SSL_is_dtls(clientssl)) {
|
||||
if (SSL_IS_DTLS(clientssl)) {
|
||||
s_to_c_bio = BIO_new(bio_s_mempacket_test());
|
||||
c_to_s_bio = BIO_new(bio_s_mempacket_test());
|
||||
c_to_s_bio = BIO_new(bio_s_mempacket_test());;
|
||||
} else {
|
||||
s_to_c_bio = BIO_new(BIO_s_mem());
|
||||
c_to_s_bio = BIO_new(BIO_s_mem());
|
||||
@@ -615,8 +623,8 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
|
||||
BIO_set_mem_eof_return(c_to_s_bio, -1);
|
||||
|
||||
/* Up ref these as we are passing them to two SSL objects */
|
||||
BIO_up_ref(s_to_c_bio);
|
||||
BIO_up_ref(c_to_s_bio);
|
||||
CRYPTO_add(&s_to_c_bio->references, 1, CRYPTO_LOCK_BIO);
|
||||
CRYPTO_add(&c_to_s_bio->references, 1, CRYPTO_LOCK_BIO);
|
||||
|
||||
SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);
|
||||
SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);
|
||||
@@ -644,34 +652,31 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
|
||||
int create_ssl_connection(SSL *serverssl, SSL *clientssl)
|
||||
{
|
||||
int retc = -1, rets = -1, err, abortctr = 0;
|
||||
int clienterr = 0, servererr = 0;
|
||||
|
||||
do {
|
||||
err = SSL_ERROR_WANT_WRITE;
|
||||
while (!clienterr && retc <= 0 && err == SSL_ERROR_WANT_WRITE) {
|
||||
while (retc <= 0 && err == SSL_ERROR_WANT_WRITE) {
|
||||
retc = SSL_connect(clientssl);
|
||||
if (retc <= 0)
|
||||
err = SSL_get_error(clientssl, retc);
|
||||
}
|
||||
|
||||
if (!clienterr && retc <= 0 && err != SSL_ERROR_WANT_READ) {
|
||||
if (retc <= 0 && err != SSL_ERROR_WANT_READ) {
|
||||
printf("SSL_connect() failed %d, %d\n", retc, err);
|
||||
clienterr = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = SSL_ERROR_WANT_WRITE;
|
||||
while (!servererr && rets <= 0 && err == SSL_ERROR_WANT_WRITE) {
|
||||
while (rets <= 0 && err == SSL_ERROR_WANT_WRITE) {
|
||||
rets = SSL_accept(serverssl);
|
||||
if (rets <= 0)
|
||||
err = SSL_get_error(serverssl, rets);
|
||||
}
|
||||
|
||||
if (!servererr && rets <= 0 && err != SSL_ERROR_WANT_READ) {
|
||||
if (rets <= 0 && err != SSL_ERROR_WANT_READ) {
|
||||
printf("SSL_accept() failed %d, %d\n", retc, err);
|
||||
servererr = 1;
|
||||
}
|
||||
if (clienterr && servererr)
|
||||
return 0;
|
||||
}
|
||||
if (++abortctr == MAXLOOPS) {
|
||||
printf("No progress made\n");
|
||||
return 0;
|
||||
|
||||
@@ -20,10 +20,10 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
|
||||
int create_ssl_connection(SSL *serverssl, SSL *clientssl);
|
||||
|
||||
/* Note: Not thread safe! */
|
||||
const BIO_METHOD *bio_f_tls_dump_filter(void);
|
||||
BIO_METHOD *bio_f_tls_dump_filter(void);
|
||||
void bio_f_tls_dump_filter_free(void);
|
||||
|
||||
const BIO_METHOD *bio_s_mempacket_test(void);
|
||||
BIO_METHOD *bio_s_mempacket_test(void);
|
||||
void bio_s_mempacket_test_free(void);
|
||||
|
||||
/* Packet types - value 0 is reserved */
|
||||
@@ -33,8 +33,4 @@ void bio_s_mempacket_test_free(void);
|
||||
int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
|
||||
int type);
|
||||
|
||||
typedef struct mempacket_st MEMPACKET;
|
||||
|
||||
DEFINE_STACK_OF(MEMPACKET)
|
||||
|
||||
#endif /* HEADER_SSLTESTLIB_H */
|
||||
|
||||
1
test/sslv2conftest.c
Symbolic link
1
test/sslv2conftest.c
Symbolic link
@@ -0,0 +1 @@
|
||||
../ssl/sslv2conftest.c
|
||||
78
test/tcrl
Normal file
78
test/tcrl
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/sh
|
||||
|
||||
cmd='../util/shlib_wrap.sh ../apps/openssl crl'
|
||||
|
||||
if [ "$1"x != "x" ]; then
|
||||
t=$1
|
||||
else
|
||||
t=testcrl.pem
|
||||
fi
|
||||
|
||||
echo testing crl conversions
|
||||
cp $t crl-fff.p
|
||||
|
||||
echo "p -> d"
|
||||
$cmd -in crl-fff.p -inform p -outform d >crl-f.d
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
#echo "p -> t"
|
||||
#$cmd -in crl-fff.p -inform p -outform t >crl-f.t
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
echo "p -> p"
|
||||
$cmd -in crl-fff.p -inform p -outform p >crl-f.p
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
echo "d -> d"
|
||||
$cmd -in crl-f.d -inform d -outform d >crl-ff.d1
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
#echo "t -> d"
|
||||
#$cmd -in crl-f.t -inform t -outform d >crl-ff.d2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
echo "p -> d"
|
||||
$cmd -in crl-f.p -inform p -outform d >crl-ff.d3
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
#echo "d -> t"
|
||||
#$cmd -in crl-f.d -inform d -outform t >crl-ff.t1
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
#echo "t -> t"
|
||||
#$cmd -in crl-f.t -inform t -outform t >crl-ff.t2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
#echo "p -> t"
|
||||
#$cmd -in crl-f.p -inform p -outform t >crl-ff.t3
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
echo "d -> p"
|
||||
$cmd -in crl-f.d -inform d -outform p >crl-ff.p1
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
#echo "t -> p"
|
||||
#$cmd -in crl-f.t -inform t -outform p >crl-ff.p2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
echo "p -> p"
|
||||
$cmd -in crl-f.p -inform p -outform p >crl-ff.p3
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
cmp crl-fff.p crl-f.p
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
cmp crl-fff.p crl-ff.p1
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
#cmp crl-fff.p crl-ff.p2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
cmp crl-fff.p crl-ff.p3
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
#cmp crl-f.t crl-ff.t1
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
#cmp crl-f.t crl-ff.t2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
#cmp crl-f.t crl-ff.t3
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
cmp crl-f.p crl-ff.p1
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
#cmp crl-f.p crl-ff.p2
|
||||
#if [ $? != 0 ]; then exit 1; fi
|
||||
cmp crl-f.p crl-ff.p3
|
||||
if [ $? != 0 ]; then exit 1; fi
|
||||
|
||||
/bin/rm -f crl-f.* crl-ff.* crl-fff.*
|
||||
exit 0
|
||||
88
test/tcrl.com
Normal file
88
test/tcrl.com
Normal file
@@ -0,0 +1,88 @@
|
||||
$! TCRL.COM -- Tests crl keys
|
||||
$
|
||||
$ __arch = "VAX"
|
||||
$ if f$getsyi("cpu") .ge. 128 then -
|
||||
__arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
|
||||
$ if __arch .eqs. "" then __arch = "UNK"
|
||||
$!
|
||||
$ if (p2 .eqs. "64") then __arch = __arch+ "_64"
|
||||
$!
|
||||
$ exe_dir = "sys$disk:[-.''__arch'.exe.apps]"
|
||||
$
|
||||
$ cmd = "mcr ''exe_dir'openssl crl"
|
||||
$
|
||||
$ t = "testcrl.pem"
|
||||
$ if p1 .nes. "" then t = p1
|
||||
$
|
||||
$ write sys$output "testing CRL conversions"
|
||||
$ if f$search("fff.*") .nes "" then delete fff.*;*
|
||||
$ if f$search("ff.*") .nes "" then delete ff.*;*
|
||||
$ if f$search("f.*") .nes "" then delete f.*;*
|
||||
$ convert/fdl=sys$input: 't' fff.p
|
||||
RECORD
|
||||
FORMAT STREAM_LF
|
||||
$
|
||||
$ write sys$output "p -> d"
|
||||
$ 'cmd' -in fff.p -inform p -outform d -out f.d
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$! write sys$output "p -> t"
|
||||
$! 'cmd' -in fff.p -inform p -outform t -out f.t
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$ write sys$output "p -> p"
|
||||
$ 'cmd' -in fff.p -inform p -outform p -out f.p
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ write sys$output "d -> d"
|
||||
$ 'cmd' -in f.d -inform d -outform d -out ff.d1
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$! write sys$output "t -> d"
|
||||
$! 'cmd' -in f.t -inform t -outform d -out ff.d2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$ write sys$output "p -> d"
|
||||
$ 'cmd' -in f.p -inform p -outform d -out ff.d3
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$! write sys$output "d -> t"
|
||||
$! 'cmd' -in f.d -inform d -outform t -out ff.t1
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$! write sys$output "t -> t"
|
||||
$! 'cmd' -in f.t -inform t -outform t -out ff.t2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$! write sys$output "p -> t"
|
||||
$! 'cmd' -in f.p -inform p -outform t -out ff.t3
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ write sys$output "d -> p"
|
||||
$ 'cmd' -in f.d -inform d -outform p -out ff.p1
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$! write sys$output "t -> p"
|
||||
$! 'cmd' -in f.t -inform t -outform p -out ff.p2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$ write sys$output "p -> p"
|
||||
$ 'cmd' -in f.p -inform p -outform p -out ff.p3
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ backup/compare fff.p f.p
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$ backup/compare fff.p ff.p1
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$! backup/compare fff.p ff.p2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$ backup/compare fff.p ff.p3
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$! backup/compare f.t ff.t1
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$! backup/compare f.t ff.t2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$! backup/compare f.t ff.t3
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ backup/compare f.p ff.p1
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$! backup/compare f.p ff.p2
|
||||
$! if $severity .ne. 1 then exit 3
|
||||
$ backup/compare f.p ff.p3
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ delete f.*;*,ff.*;*,fff.*;*
|
||||
@@ -56,7 +56,7 @@ emailAddress = optional
|
||||
|
||||
####################################################################
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
default_bits = 1024
|
||||
default_keyfile = testkey.pem
|
||||
distinguished_name = req_distinguished_name
|
||||
encrypt_rsa_key = no
|
||||
|
||||
64
test/test_padlock
Executable file
64
test/test_padlock
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
PROG=$1
|
||||
|
||||
if [ -x $PROG ]; then
|
||||
if expr "x`$PROG version`" : "xOpenSSL" > /dev/null; then
|
||||
:
|
||||
else
|
||||
echo "$PROG is not OpenSSL executable"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "$PROG is not executable"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if $PROG engine padlock | grep -v no-ACE; then
|
||||
|
||||
HASH=`cat $PROG | $PROG dgst -hex`
|
||||
|
||||
ACE_ALGS=" aes-128-ecb aes-192-ecb aes-256-ecb \
|
||||
aes-128-cbc aes-192-cbc aes-256-cbc \
|
||||
aes-128-cfb aes-192-cfb aes-256-cfb \
|
||||
aes-128-ofb aes-192-ofb aes-256-ofb"
|
||||
|
||||
nerr=0
|
||||
|
||||
for alg in $ACE_ALGS; do
|
||||
echo $alg
|
||||
TEST=`( cat $PROG | \
|
||||
$PROG enc -e -k "$HASH" -$alg -bufsize 999 -engine padlock | \
|
||||
$PROG enc -d -k "$HASH" -$alg | \
|
||||
$PROG dgst -hex ) 2>/dev/null`
|
||||
if [ "$TEST" != "$HASH" ]; then
|
||||
echo "-$alg encrypt test failed"
|
||||
nerr=`expr $nerr + 1`
|
||||
fi
|
||||
TEST=`( cat $PROG | \
|
||||
$PROG enc -e -k "$HASH" -$alg | \
|
||||
$PROG enc -d -k "$HASH" -$alg -bufsize 999 -engine padlock | \
|
||||
$PROG dgst -hex ) 2>/dev/null`
|
||||
if [ "$TEST" != "$HASH" ]; then
|
||||
echo "-$alg decrypt test failed"
|
||||
nerr=`expr $nerr + 1`
|
||||
fi
|
||||
TEST=`( cat $PROG | \
|
||||
$PROG enc -e -k "$HASH" -$alg -engine padlock | \
|
||||
$PROG enc -d -k "$HASH" -$alg -engine padlock | \
|
||||
$PROG dgst -hex ) 2>/dev/null`
|
||||
if [ "$TEST" != "$HASH" ]; then
|
||||
echo "-$alg en/decrypt test failed"
|
||||
nerr=`expr $nerr + 1`
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $nerr -gt 0 ]; then
|
||||
echo "PadLock ACE test failed."
|
||||
exit 1;
|
||||
fi
|
||||
else
|
||||
echo "PadLock ACE is not available"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
51
test/testca
Normal file
51
test/testca
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
SH="/bin/sh"
|
||||
if test "$OSTYPE" = msdosdjgpp; then
|
||||
PATH="../apps\;$PATH"
|
||||
else
|
||||
PATH="../apps:$PATH"
|
||||
fi
|
||||
export SH PATH
|
||||
|
||||
SSLEAY_CONFIG="-config CAss.cnf"
|
||||
export SSLEAY_CONFIG
|
||||
|
||||
OPENSSL="`pwd`/../util/opensslwrap.sh"
|
||||
export OPENSSL
|
||||
|
||||
/bin/rm -fr demoCA
|
||||
$SH ../apps/CA.sh -newca <<EOF
|
||||
EOF
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
SSLEAY_CONFIG="-config Uss.cnf"
|
||||
export SSLEAY_CONFIG
|
||||
$SH ../apps/CA.sh -newreq
|
||||
if [ $? != 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
SSLEAY_CONFIG="-config ../apps/openssl.cnf"
|
||||
export SSLEAY_CONFIG
|
||||
$SH ../apps/CA.sh -sign <<EOF
|
||||
y
|
||||
y
|
||||
EOF
|
||||
if [ $? != 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
$SH ../apps/CA.sh -verify newcert.pem
|
||||
if [ $? != 0 ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
/bin/rm -fr demoCA newcert.pem newreq.pem
|
||||
#usage: CA -newcert|-newreq|-newca|-sign|-verify
|
||||
|
||||
52
test/testca.com
Normal file
52
test/testca.com
Normal file
@@ -0,0 +1,52 @@
|
||||
$! TESTCA.COM
|
||||
$
|
||||
$ __arch = "VAX"
|
||||
$ if f$getsyi("cpu") .ge. 128 then -
|
||||
__arch = f$edit( f$getsyi( "ARCH_NAME"), "UPCASE")
|
||||
$ if __arch .eqs. "" then __arch = "UNK"
|
||||
$!
|
||||
$ if (p1 .eqs. "64") then __arch = __arch+ "_64"
|
||||
$
|
||||
$ openssl = "mcr ''exe_dir'openssl"
|
||||
$
|
||||
$ SSLEAY_CONFIG="-config ""CAss.cnf"""
|
||||
$
|
||||
$ set noon
|
||||
$ if f$search("demoCA.dir") .nes. ""
|
||||
$ then
|
||||
$ @[-.util]deltree [.demoCA]*.*
|
||||
$ set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
|
||||
$ delete demoCA.dir;*
|
||||
$ endif
|
||||
$ set on
|
||||
$ open/read sys$ca_input VMSca-response.1
|
||||
$ @[-.apps]CA.com -input sys$ca_input -newca
|
||||
$ close sys$ca_input
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$
|
||||
$ SSLEAY_CONFIG="-config ""Uss.cnf"""
|
||||
$ @[-.apps]CA.com -newreq
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$
|
||||
$ SSLEAY_CONFIG="-config [-.apps]openssl-vms.cnf"
|
||||
$ open/read sys$ca_input VMSca-response.2
|
||||
$ @[-.apps]CA.com -input sys$ca_input -sign
|
||||
$ close sys$ca_input
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$
|
||||
$ @[-.apps]CA.com -verify newcert.pem
|
||||
$ if $severity .ne. 1 then exit 3
|
||||
$
|
||||
$ set noon
|
||||
$ @[-.util]deltree [.demoCA]*.*
|
||||
$ set file/prot=(S:RWED,O:RWED,G:RWED,W:RWED) demoCA.dir;*
|
||||
$ delete demoCA.dir;*
|
||||
$ if f$search("newcert.pem") .nes. "" then delete newcert.pem;*
|
||||
$ if f$search("newcert.pem") .nes. "" then delete newreq.pem;*
|
||||
$ set on
|
||||
$! #usage: CA -newcert|-newreq|-newca|-sign|-verify
|
||||
$
|
||||
$ exit
|
||||
54
test/testenc
Normal file
54
test/testenc
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
|
||||
testsrc=testenc
|
||||
test=./p
|
||||
cmd="../util/shlib_wrap.sh ../apps/openssl"
|
||||
|
||||
cat $testsrc >$test;
|
||||
|
||||
echo cat
|
||||
$cmd enc < $test > $test.cipher
|
||||
$cmd enc < $test.cipher >$test.clear
|
||||
cmp $test $test.clear
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
exit 1
|
||||
else
|
||||
/bin/rm $test.cipher $test.clear
|
||||
fi
|
||||
echo base64
|
||||
$cmd enc -a -e < $test > $test.cipher
|
||||
$cmd enc -a -d < $test.cipher >$test.clear
|
||||
cmp $test $test.clear
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
exit 1
|
||||
else
|
||||
/bin/rm $test.cipher $test.clear
|
||||
fi
|
||||
|
||||
for i in `$cmd list-cipher-commands`
|
||||
do
|
||||
echo $i
|
||||
$cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher
|
||||
$cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear
|
||||
cmp $test $test.$i.clear
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
exit 1
|
||||
else
|
||||
/bin/rm $test.$i.cipher $test.$i.clear
|
||||
fi
|
||||
|
||||
echo $i base64
|
||||
$cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher
|
||||
$cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear
|
||||
cmp $test $test.$i.clear
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
exit 1
|
||||
else
|
||||
/bin/rm $test.$i.cipher $test.$i.clear
|
||||
fi
|
||||
done
|
||||
rm -f $test
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user