Compare commits
220 Commits
OpenSSL_1_
...
OpenSSL_1_
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cdac2e8928 | ||
![]() |
01fb34ad43 | ||
![]() |
08fac3fb6f | ||
![]() |
0c8dc6ebe5 | ||
![]() |
f4f1e80801 | ||
![]() |
36f309c50a | ||
![]() |
94e5cf36bd | ||
![]() |
23df532ec4 | ||
![]() |
b960060a0d | ||
![]() |
e9cb6eb1d3 | ||
![]() |
181ae2badb | ||
![]() |
a98051fb47 | ||
![]() |
225628f280 | ||
![]() |
ca39b261bf | ||
![]() |
c1beec0e6d | ||
![]() |
b095884a58 | ||
![]() |
f7fe3d235a | ||
![]() |
b2688c9161 | ||
![]() |
bf6fa208b5 | ||
![]() |
eb37b6aa41 | ||
![]() |
f66f76a24a | ||
![]() |
65c63da207 | ||
![]() |
9f028e4a78 | ||
![]() |
64eec8f898 | ||
![]() |
08a88774bd | ||
![]() |
802a070bb6 | ||
![]() |
31c65a7bc0 | ||
![]() |
208a6012be | ||
![]() |
d7f8a7cafd | ||
![]() |
0f1c30b00d | ||
![]() |
c4b969639a | ||
![]() |
bfb2e4b280 | ||
![]() |
d8c8a718a2 | ||
![]() |
40c2812f56 | ||
![]() |
2e3e3d278e | ||
![]() |
2ececf59de | ||
![]() |
a60536348b | ||
![]() |
9d410579a7 | ||
![]() |
4f90ef0c5b | ||
![]() |
eae2bb2f1f | ||
![]() |
c313270836 | ||
![]() |
af8a66d10d | ||
![]() |
ec5c25b3b4 | ||
![]() |
38afaa48ec | ||
![]() |
954818fe60 | ||
![]() |
027381f68c | ||
![]() |
a900b3b51c | ||
![]() |
82d7247fc5 | ||
![]() |
ceb4c684e4 | ||
![]() |
a8da754d84 | ||
![]() |
8ccb44e6f5 | ||
![]() |
bbfdd1f0c9 | ||
![]() |
8724f9f9cf | ||
![]() |
6d41cbb63a | ||
![]() |
04a73c844f | ||
![]() |
87ff17a05d | ||
![]() |
d93112abc6 | ||
![]() |
875a33d7f7 | ||
![]() |
cf48a6d7f6 | ||
![]() |
7f3490e685 | ||
![]() |
dcf7a2dc4a | ||
![]() |
6ff76b3347 | ||
![]() |
3b12515180 | ||
![]() |
4e73dc5b76 | ||
![]() |
67eb85d7d4 | ||
![]() |
915a3b1c21 | ||
![]() |
e1b1d82aab | ||
![]() |
c25456633c | ||
![]() |
aaf9335970 | ||
![]() |
cee17f96f1 | ||
![]() |
bd36615973 | ||
![]() |
db85611989 | ||
![]() |
9e5267fcdd | ||
![]() |
0d330ce5cc | ||
![]() |
2a303a5834 | ||
![]() |
8d81dfd0a6 | ||
![]() |
69c163ac81 | ||
![]() |
b7eaea7397 | ||
![]() |
2d2965d2c1 | ||
![]() |
56cee260d8 | ||
![]() |
e2e13b8f3a | ||
![]() |
13b2a4d06a | ||
![]() |
41da9188cc | ||
![]() |
e9fe4b1033 | ||
![]() |
6469c947f5 | ||
![]() |
9bf3ff1ca0 | ||
![]() |
74f77d40a9 | ||
![]() |
55513f3e48 | ||
![]() |
c8dd719095 | ||
![]() |
0bfd0bff17 | ||
![]() |
eb269523bb | ||
![]() |
802feda7fc | ||
![]() |
cdad6ad015 | ||
![]() |
4eca4cfbc8 | ||
![]() |
7e29be228e | ||
![]() |
8745c0815c | ||
![]() |
68828f167c | ||
![]() |
59dcfa21e5 | ||
![]() |
13f8ddacbe | ||
![]() |
ad8b204386 | ||
![]() |
7b7aef9bfd | ||
![]() |
93540299fe | ||
![]() |
1db72876dc | ||
![]() |
b55ff319f8 | ||
![]() |
9a6940a349 | ||
![]() |
c36ceb0b15 | ||
![]() |
904fcce0c6 | ||
![]() |
2518a35a51 | ||
![]() |
442ca2bd00 | ||
![]() |
09e62af4d4 | ||
![]() |
88f0c9797e | ||
![]() |
74f5307d57 | ||
![]() |
da8dd611ae | ||
![]() |
43711a589b | ||
![]() |
bf63eab048 | ||
![]() |
62ca466a54 | ||
![]() |
17d3b1ecea | ||
![]() |
73729e4cf3 | ||
![]() |
05f61fb27e | ||
![]() |
10be715b95 | ||
![]() |
e87a4a7011 | ||
![]() |
f2a57c101f | ||
![]() |
b88ffa2bce | ||
![]() |
27b0494153 | ||
![]() |
d38dcafe95 | ||
![]() |
b0873dbb44 | ||
![]() |
48ae65be09 | ||
![]() |
dd5d7447c1 | ||
![]() |
4ff9cbe635 | ||
![]() |
e164b34079 | ||
![]() |
679d0c8655 | ||
![]() |
1d5e58b53c | ||
![]() |
118149887b | ||
![]() |
bb505311c6 | ||
![]() |
f5fc85d382 | ||
![]() |
6e4929fcdb | ||
![]() |
03a12c1330 | ||
![]() |
57b0c4697a | ||
![]() |
9fd3555305 | ||
![]() |
67e53f73bf | ||
![]() |
2281d10a7b | ||
![]() |
e5861c885f | ||
![]() |
60be115771 | ||
![]() |
5ee775a4a5 | ||
![]() |
934ca0714a | ||
![]() |
ad007e0aaf | ||
![]() |
84361b898d | ||
![]() |
1a80d39021 | ||
![]() |
c5526a16b1 | ||
![]() |
b6b9670017 | ||
![]() |
469665f658 | ||
![]() |
c4eb02bcaa | ||
![]() |
97f336f25d | ||
![]() |
5e05728ace | ||
![]() |
061a5bdba2 | ||
![]() |
e6ed83fb74 | ||
![]() |
c3f2fc419b | ||
![]() |
ec9cb40da5 | ||
![]() |
ed1de3810d | ||
![]() |
df35da266d | ||
![]() |
26d60e29e3 | ||
![]() |
5a0df377ac | ||
![]() |
f7123634a5 | ||
![]() |
7aeb3d7937 | ||
![]() |
182f1ad8a1 | ||
![]() |
0819130188 | ||
![]() |
3fe4fc4774 | ||
![]() |
1326733457 | ||
![]() |
d8426e6b7d | ||
![]() |
aa90ff7d8e | ||
![]() |
aeae79951c | ||
![]() |
cf3792b3e4 | ||
![]() |
e6b98d5a40 | ||
![]() |
4054d95eb9 | ||
![]() |
a05e954b66 | ||
![]() |
ca4a339eeb | ||
![]() |
835e32f9f6 | ||
![]() |
23396f5500 | ||
![]() |
1c9b82a91f | ||
![]() |
99657430c0 | ||
![]() |
ce20ac72b4 | ||
![]() |
525b6c7585 | ||
![]() |
29ed482ffc | ||
![]() |
b38db8803f | ||
![]() |
59899c4d1b | ||
![]() |
eec4cc8878 | ||
![]() |
2e7124497d | ||
![]() |
c0eae35b3d | ||
![]() |
50c9141d00 | ||
![]() |
2617a3c44d | ||
![]() |
a7da2b8e17 | ||
![]() |
e617a506ff | ||
![]() |
80640bf0bc | ||
![]() |
f05bce4f2f | ||
![]() |
5cd3ae9f18 | ||
![]() |
d9d5a12823 | ||
![]() |
06f3746c62 | ||
![]() |
14247e4f59 | ||
![]() |
72bc04942a | ||
![]() |
8e28ef0d85 | ||
![]() |
996edff7e1 | ||
![]() |
532ee6e056 | ||
![]() |
08db2cc9c1 | ||
![]() |
f25e4263fe | ||
![]() |
2dc967ddd0 | ||
![]() |
a357acdd3b | ||
![]() |
7e98378d15 | ||
![]() |
d663f506dc | ||
![]() |
ead6774804 | ||
![]() |
e05282f8b0 | ||
![]() |
34b087c9d0 | ||
![]() |
9f81028969 | ||
![]() |
8781538f41 | ||
![]() |
8343fdc3c7 | ||
![]() |
e966578d2f | ||
![]() |
7bab3c16ff | ||
![]() |
e2d569973c | ||
![]() |
caff6fc593 | ||
![]() |
ccb0398da6 | ||
![]() |
1f163fce81 |
32
.gitignore
vendored
32
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
# Object files
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# editor artefacts
|
||||
*.swp
|
||||
@@ -47,6 +48,21 @@
|
||||
*.s
|
||||
!/crypto/bn/asm/pa-risc2.s
|
||||
!/crypto/bn/asm/pa-risc2W.s
|
||||
crypto/aes/asm/a_win32.asm
|
||||
crypto/bf/asm/b_win32.asm
|
||||
crypto/bn/asm/bn_win32.asm
|
||||
crypto/bn/asm/co_win32.asm
|
||||
crypto/bn/asm/mt_win32.asm
|
||||
crypto/cast/asm/c_win32.asm
|
||||
crypto/cpu_win32.asm
|
||||
crypto/des/asm/d_win32.asm
|
||||
crypto/des/asm/y_win32.asm
|
||||
crypto/md5/asm/m5_win32.asm
|
||||
crypto/rc4/asm/r4_win32.asm
|
||||
crypto/rc5/asm/r5_win32.asm
|
||||
crypto/ripemd/asm/rm_win32.asm
|
||||
crypto/sha/asm/s1_win32.asm
|
||||
crypto/sha/asm/sha512-sse2.asm
|
||||
|
||||
# Executables
|
||||
/apps/openssl
|
||||
@@ -75,3 +91,19 @@
|
||||
lib
|
||||
Makefile.save
|
||||
*.bak
|
||||
tags
|
||||
TAGS
|
||||
|
||||
# Windows
|
||||
/tmp32dll
|
||||
/tmp32dll.dbg
|
||||
/out32dll
|
||||
/out32dll.dbg
|
||||
/inc32
|
||||
/MINFO
|
||||
ms/bcb.mak
|
||||
ms/libeay32.def
|
||||
ms/nt.mak
|
||||
ms/ntdll.mak
|
||||
ms/ssleay32.def
|
||||
ms/version32.rc
|
||||
|
199
CHANGES
199
CHANGES
@@ -2,6 +2,205 @@
|
||||
OpenSSL CHANGES
|
||||
_______________
|
||||
|
||||
Changes between 1.0.0p and 1.0.0q [15 Jan 2015]
|
||||
|
||||
*) Build fixes for the Windows and OpenVMS platforms
|
||||
[Matt Caswell and Richard Levitte]
|
||||
|
||||
Changes between 1.0.0o and 1.0.0p [8 Jan 2015]
|
||||
|
||||
*) Fix DTLS segmentation fault in dtls1_get_record. A carefully crafted DTLS
|
||||
message can cause a segmentation fault in OpenSSL due to a NULL pointer
|
||||
dereference. This could lead to a Denial Of Service attack. Thanks to
|
||||
Markus Stenberg of Cisco Systems, Inc. for reporting this issue.
|
||||
(CVE-2014-3571)
|
||||
[Steve Henson]
|
||||
|
||||
*) Fix DTLS memory leak in dtls1_buffer_record. A memory leak can occur in the
|
||||
dtls1_buffer_record function under certain conditions. In particular this
|
||||
could occur if an attacker sent repeated DTLS records with the same
|
||||
sequence number but for the next epoch. The memory leak could be exploited
|
||||
by an attacker in a Denial of Service attack through memory exhaustion.
|
||||
Thanks to Chris Mueller for reporting this issue.
|
||||
(CVE-2015-0206)
|
||||
[Matt Caswell]
|
||||
|
||||
*) Fix issue where no-ssl3 configuration sets method to NULL. When openssl is
|
||||
built with the no-ssl3 option and a SSL v3 ClientHello is received the ssl
|
||||
method would be set to NULL which could later result in a NULL pointer
|
||||
dereference. Thanks to Frank Schmirler for reporting this issue.
|
||||
(CVE-2014-3569)
|
||||
[Kurt Roeckx]
|
||||
|
||||
*) Abort handshake if server key exchange message is omitted for ephemeral
|
||||
ECDH ciphersuites.
|
||||
|
||||
Thanks to Karthikeyan Bhargavan of the PROSECCO team at INRIA for
|
||||
reporting this issue.
|
||||
(CVE-2014-3572)
|
||||
[Steve Henson]
|
||||
|
||||
*) Remove non-export ephemeral RSA code on client and server. This code
|
||||
violated the TLS standard by allowing the use of temporary RSA keys in
|
||||
non-export ciphersuites and could be used by a server to effectively
|
||||
downgrade the RSA key length used to a value smaller than the server
|
||||
certificate. Thanks for Karthikeyan Bhargavan of the PROSECCO team at
|
||||
INRIA or reporting this issue.
|
||||
(CVE-2015-0204)
|
||||
[Steve Henson]
|
||||
|
||||
*) Fixed issue where DH client certificates are accepted without verification.
|
||||
An OpenSSL server will accept a DH certificate for client authentication
|
||||
without the certificate verify message. This effectively allows a client to
|
||||
authenticate without the use of a private key. This only affects servers
|
||||
which trust a client certificate authority which issues certificates
|
||||
containing DH keys: these are extremely rare and hardly ever encountered.
|
||||
Thanks for Karthikeyan Bhargavan of the PROSECCO team at INRIA or reporting
|
||||
this issue.
|
||||
(CVE-2015-0205)
|
||||
[Steve Henson]
|
||||
|
||||
*) Correct Bignum squaring. Bignum squaring (BN_sqr) may produce incorrect
|
||||
results on some platforms, including x86_64. This bug occurs at random
|
||||
with a very low probability, and is not known to be exploitable in any
|
||||
way, though its exact impact is difficult to determine. Thanks to Pieter
|
||||
Wuille (Blockstream) who reported this issue and also suggested an initial
|
||||
fix. Further analysis was conducted by the OpenSSL development team and
|
||||
Adam Langley of Google. The final fix was developed by Andy Polyakov of
|
||||
the OpenSSL core team.
|
||||
(CVE-2014-3570)
|
||||
[Andy Polyakov]
|
||||
|
||||
*) Fix various certificate fingerprint issues.
|
||||
|
||||
By using non-DER or invalid encodings outside the signed portion of a
|
||||
certificate the fingerprint can be changed without breaking the signature.
|
||||
Although no details of the signed portion of the certificate can be changed
|
||||
this can cause problems with some applications: e.g. those using the
|
||||
certificate fingerprint for blacklists.
|
||||
|
||||
1. Reject signatures with non zero unused bits.
|
||||
|
||||
If the BIT STRING containing the signature has non zero unused bits reject
|
||||
the signature. All current signature algorithms require zero unused bits.
|
||||
|
||||
2. Check certificate algorithm consistency.
|
||||
|
||||
Check the AlgorithmIdentifier inside TBS matches the one in the
|
||||
certificate signature. NB: this will result in signature failure
|
||||
errors for some broken certificates.
|
||||
|
||||
Thanks to Konrad Kraszewski from Google for reporting this issue.
|
||||
|
||||
3. Check DSA/ECDSA signatures use DER.
|
||||
|
||||
Reencode DSA/ECDSA signatures and compare with the original received
|
||||
signature. Return an error if there is a mismatch.
|
||||
|
||||
This will reject various cases including garbage after signature
|
||||
(thanks to Antti Karjalainen and Tuomo Untinen from the Codenomicon CROSS
|
||||
program for discovering this case) and use of BER or invalid ASN.1 INTEGERs
|
||||
(negative or with leading zeroes).
|
||||
|
||||
Further analysis was conducted and fixes were developed by Stephen Henson
|
||||
of the OpenSSL core team.
|
||||
|
||||
(CVE-2014-8275)
|
||||
[Steve Henson]
|
||||
|
||||
Changes between 1.0.0n and 1.0.0o [15 Oct 2014]
|
||||
|
||||
*) Session Ticket Memory Leak.
|
||||
|
||||
When an OpenSSL SSL/TLS/DTLS server receives a session ticket the
|
||||
integrity of that ticket is first verified. In the event of a session
|
||||
ticket integrity check failing, OpenSSL will fail to free memory
|
||||
causing a memory leak. By sending a large number of invalid session
|
||||
tickets an attacker could exploit this issue in a Denial Of Service
|
||||
attack.
|
||||
(CVE-2014-3567)
|
||||
[Steve Henson]
|
||||
|
||||
*) Build option no-ssl3 is incomplete.
|
||||
|
||||
When OpenSSL is configured with "no-ssl3" as a build option, servers
|
||||
could accept and complete a SSL 3.0 handshake, and clients could be
|
||||
configured to send them.
|
||||
(CVE-2014-3568)
|
||||
[Akamai and the OpenSSL team]
|
||||
|
||||
*) Add support for TLS_FALLBACK_SCSV.
|
||||
Client applications doing fallback retries should call
|
||||
SSL_set_mode(s, SSL_MODE_SEND_FALLBACK_SCSV).
|
||||
(CVE-2014-3566)
|
||||
[Adam Langley, Bodo Moeller]
|
||||
|
||||
*) Add additional DigestInfo checks.
|
||||
|
||||
Reencode DigestInto in DER and check against the original when
|
||||
verifying RSA signature: this will reject any improperly encoded
|
||||
DigestInfo structures.
|
||||
|
||||
Note: this is a precautionary measure and no attacks are currently known.
|
||||
|
||||
[Steve Henson]
|
||||
|
||||
Changes between 1.0.0m and 1.0.0n [6 Aug 2014]
|
||||
|
||||
*) OpenSSL DTLS clients enabling anonymous (EC)DH ciphersuites are subject
|
||||
to a denial of service attack. A malicious server can crash the client
|
||||
with a null pointer dereference (read) by specifying an anonymous (EC)DH
|
||||
ciphersuite and sending carefully crafted handshake messages.
|
||||
|
||||
Thanks to Felix Gr<47>bert (Google) for discovering and researching this
|
||||
issue.
|
||||
(CVE-2014-3510)
|
||||
[Emilia K<>sper]
|
||||
|
||||
*) By sending carefully crafted DTLS packets an attacker could cause openssl
|
||||
to leak memory. This can be exploited through a Denial of Service attack.
|
||||
Thanks to Adam Langley for discovering and researching this issue.
|
||||
(CVE-2014-3507)
|
||||
[Adam Langley]
|
||||
|
||||
*) An attacker can force openssl to consume large amounts of memory whilst
|
||||
processing DTLS handshake messages. This can be exploited through a
|
||||
Denial of Service attack.
|
||||
Thanks to Adam Langley for discovering and researching this issue.
|
||||
(CVE-2014-3506)
|
||||
[Adam Langley]
|
||||
|
||||
*) An attacker can force an error condition which causes openssl to crash
|
||||
whilst processing DTLS packets due to memory being freed twice. This
|
||||
can be exploited through a Denial of Service attack.
|
||||
Thanks to Adam Langley and Wan-Teh Chang for discovering and researching
|
||||
this issue.
|
||||
(CVE-2014-3505)
|
||||
[Adam Langley]
|
||||
|
||||
*) If a multithreaded client connects to a malicious server using a resumed
|
||||
session and the server sends an ec point format extension it could write
|
||||
up to 255 bytes to freed memory.
|
||||
|
||||
Thanks to Gabor Tyukasz (LogMeIn Inc) for discovering and researching this
|
||||
issue.
|
||||
(CVE-2014-3509)
|
||||
[Gabor Tyukasz]
|
||||
|
||||
*) A flaw in OBJ_obj2txt may cause pretty printing functions such as
|
||||
X509_name_oneline, X509_name_print_ex et al. to leak some information
|
||||
from the stack. Applications may be affected if they echo pretty printing
|
||||
output to the attacker.
|
||||
|
||||
Thanks to Ivan Fratric (Google) for discovering this issue.
|
||||
(CVE-2014-3508)
|
||||
[Emilia K<>sper, and Steve Henson]
|
||||
|
||||
*) Fix ec_GFp_simple_points_make_affine (thus, EC_POINTs_mul etc.)
|
||||
for corner cases. (Certain input points at infinity could lead to
|
||||
bogus results, with non-infinity inputs mapped to infinity too.)
|
||||
[Bodo Moeller]
|
||||
|
||||
Changes between 1.0.0l and 1.0.0m [5 Jun 2014]
|
||||
|
||||
*) Fix for SSL/TLS MITM flaw. An attacker using a carefully crafted
|
||||
|
5
FAQ
5
FAQ
@@ -113,11 +113,6 @@ that came with the version of OpenSSL you are using. The pod format
|
||||
documentation is included in each OpenSSL distribution under the docs
|
||||
directory.
|
||||
|
||||
For information on parts of libcrypto that are not yet documented, you
|
||||
might want to read Ariel Glenn's documentation on SSLeay 0.9, OpenSSL's
|
||||
predecessor, at <URL: http://www.columbia.edu/~ariel/ssleay/>. Much
|
||||
of this still applies to OpenSSL.
|
||||
|
||||
There is some documentation about certificate extensions and PKCS#12
|
||||
in doc/openssl.txt
|
||||
|
||||
|
39
NEWS
39
NEWS
@@ -5,10 +5,49 @@
|
||||
This file gives a brief overview of the major changes between each OpenSSL
|
||||
release. For more details please read the CHANGES file.
|
||||
|
||||
Major changes between OpenSSL 1.0.0p and OpenSSL 1.0.0q [15 Jan 2015]
|
||||
|
||||
o Build fixes for the Windows and OpenVMS platforms
|
||||
|
||||
Major changes between OpenSSL 1.0.0o and OpenSSL 1.0.0p [8 Jan 2015]
|
||||
|
||||
o Fix for CVE-2014-3571
|
||||
o Fix for CVE-2015-0206
|
||||
o Fix for CVE-2014-3569
|
||||
o Fix for CVE-2014-3572
|
||||
o Fix for CVE-2015-0204
|
||||
o Fix for CVE-2015-0205
|
||||
o Fix for CVE-2014-8275
|
||||
o Fix for CVE-2014-3570
|
||||
|
||||
Major changes between OpenSSL 1.0.0n and OpenSSL 1.0.0o [15 Oct 2014]
|
||||
|
||||
o Fix for CVE-2014-3513
|
||||
o Fix for CVE-2014-3567
|
||||
o Mitigation for CVE-2014-3566 (SSL protocol vulnerability)
|
||||
o Fix for CVE-2014-3568
|
||||
|
||||
Major changes between OpenSSL 1.0.0m and OpenSSL 1.0.0n [6 Aug 2014]
|
||||
|
||||
o Fix for CVE-2014-3510
|
||||
o Fix for CVE-2014-3507
|
||||
o Fix for CVE-2014-3506
|
||||
o Fix for CVE-2014-3505
|
||||
o Fix for CVE-2014-3509
|
||||
o Fix for CVE-2014-3508
|
||||
|
||||
Known issues in OpenSSL 1.0.0m:
|
||||
|
||||
o EAP-FAST and other applications using tls_session_secret_cb
|
||||
wont resume sessions. Fixed in 1.0.0n-dev
|
||||
o Compilation failure of s3_pkt.c on some platforms due to missing
|
||||
<limits.h> include. Fixed in 1.0.0n-dev
|
||||
|
||||
Major changes between OpenSSL 1.0.0l and OpenSSL 1.0.0m [5 Jun 2014]
|
||||
|
||||
o Fix for CVE-2014-0224
|
||||
o Fix for CVE-2014-0221
|
||||
o Fix for CVE-2014-0198
|
||||
o Fix for CVE-2014-0195
|
||||
o Fix for CVE-2014-3470
|
||||
o Fix for CVE-2014-0076
|
||||
|
2
README
2
README
@@ -1,5 +1,5 @@
|
||||
|
||||
OpenSSL 1.0.0m 5 Jun 2014
|
||||
OpenSSL 1.0.0q 15 Jan 2015
|
||||
|
||||
Copyright (c) 1998-2011 The OpenSSL Project
|
||||
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
|
||||
|
@@ -390,6 +390,8 @@ int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])
|
||||
{
|
||||
arg->count=20;
|
||||
arg->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count);
|
||||
if (arg->data == NULL)
|
||||
return 0;
|
||||
}
|
||||
for (i=0; i<arg->count; i++)
|
||||
arg->data[i]=NULL;
|
||||
@@ -1542,6 +1544,8 @@ char *make_config_name()
|
||||
|
||||
len=strlen(t)+strlen(OPENSSL_CONF)+2;
|
||||
p=OPENSSL_malloc(len);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
BUF_strlcpy(p,t,len);
|
||||
#ifndef OPENSSL_SYS_VMS
|
||||
BUF_strlcat(p,"/",len);
|
||||
|
@@ -1599,12 +1599,14 @@ static int certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509,
|
||||
{
|
||||
ok=0;
|
||||
BIO_printf(bio_err,"Signature verification problems....\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto err;
|
||||
}
|
||||
if (i == 0)
|
||||
{
|
||||
ok=0;
|
||||
BIO_printf(bio_err,"Signature did not match the certificate request\n");
|
||||
ERR_print_errors(bio_err);
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
@@ -2752,6 +2754,9 @@ char *make_revocation_str(int rev_type, char *rev_arg)
|
||||
|
||||
revtm = X509_gmtime_adj(NULL, 0);
|
||||
|
||||
if (!revtm)
|
||||
return NULL;
|
||||
|
||||
i = revtm->length + 1;
|
||||
|
||||
if (reason) i += strlen(reason) + 1;
|
||||
|
@@ -96,13 +96,7 @@ int MAIN(int argc, char **argv)
|
||||
char buf[512];
|
||||
BIO *STDout=NULL;
|
||||
|
||||
#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
|
||||
meth=SSLv23_server_method();
|
||||
#elif !defined(OPENSSL_NO_SSL3)
|
||||
meth=SSLv3_server_method();
|
||||
#elif !defined(OPENSSL_NO_SSL2)
|
||||
meth=SSLv2_server_method();
|
||||
#endif
|
||||
|
||||
apps_startup();
|
||||
|
||||
|
@@ -141,7 +141,13 @@ int MAIN(int argc, char **argv)
|
||||
{
|
||||
if (--argc < 1) goto bad;
|
||||
if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
|
||||
sk_OPENSSL_STRING_push(certflst,*(++argv));
|
||||
if (!certflst)
|
||||
goto end;
|
||||
if (!sk_OPENSSL_STRING_push(certflst,*(++argv)))
|
||||
{
|
||||
sk_OPENSSL_STRING_free(certflst);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -67,7 +67,9 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/pem.h>
|
||||
#ifndef OPENSSL_NO_COMP
|
||||
#include <openssl/comp.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
|
||||
int set_hex(char *in,unsigned char *out,int size);
|
||||
|
@@ -773,9 +773,12 @@ $ CCDEFS = "MONOLITH"
|
||||
$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
|
||||
$ CCEXTRAFLAGS = ""
|
||||
$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
|
||||
$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
|
||||
$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
|
||||
CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
|
||||
$ CCDISABLEWARNINGS = "" !!! "MAYLOSEDATA3" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
|
||||
$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. ""
|
||||
$ THEN
|
||||
$ IF CCDISABLEWARNINGS .NES. "" THEN CCDISABLEWARNINGS = CCDISABLEWARNINGS + ","
|
||||
$ CCDISABLEWARNINGS = CCDISABLEWARNINGS + USER_CCDISABLEWARNINGS
|
||||
$ ENDIF
|
||||
$!
|
||||
$! Check To See If We Have A ZLIB Option.
|
||||
$!
|
||||
@@ -1064,6 +1067,18 @@ $! Finish up the definition of CC.
|
||||
$!
|
||||
$ IF COMPILER .EQS. "DECC"
|
||||
$ THEN
|
||||
$! Not all compiler versions support MAYLOSEDATA3.
|
||||
$ OPT_TEST = "MAYLOSEDATA3"
|
||||
$ DEFINE /USER_MODE SYS$ERROR NL:
|
||||
$ DEFINE /USER_MODE SYS$OUTPUT NL:
|
||||
$ 'CC' /NOCROSS_REFERENCE /NOLIST /NOOBJECT -
|
||||
/WARNINGS = DISABLE = ('OPT_TEST', EMPTYFILE) NL:
|
||||
$ IF ($SEVERITY)
|
||||
$ THEN
|
||||
$ IF CCDISABLEWARNINGS .NES. "" THEN -
|
||||
CCDISABLEWARNINGS = CCDISABLEWARNINGS+ ","
|
||||
$ CCDISABLEWARNINGS = CCDISABLEWARNINGS+ OPT_TEST
|
||||
$ ENDIF
|
||||
$ IF CCDISABLEWARNINGS .NES. ""
|
||||
$ THEN
|
||||
$ CCDISABLEWARNINGS = " /WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
|
||||
|
91
apps/ocsp.c
91
apps/ocsp.c
@@ -583,51 +583,52 @@ int MAIN(int argc, char **argv)
|
||||
BIO_printf (bio_err, "OCSP utility\n");
|
||||
BIO_printf (bio_err, "Usage ocsp [options]\n");
|
||||
BIO_printf (bio_err, "where options are\n");
|
||||
BIO_printf (bio_err, "-out file output filename\n");
|
||||
BIO_printf (bio_err, "-issuer file issuer certificate\n");
|
||||
BIO_printf (bio_err, "-cert file certificate to check\n");
|
||||
BIO_printf (bio_err, "-serial n serial number to check\n");
|
||||
BIO_printf (bio_err, "-signer file certificate to sign OCSP request with\n");
|
||||
BIO_printf (bio_err, "-signkey file private key to sign OCSP request with\n");
|
||||
BIO_printf (bio_err, "-sign_other file additional certificates to include in signed request\n");
|
||||
BIO_printf (bio_err, "-no_certs don't include any certificates in signed request\n");
|
||||
BIO_printf (bio_err, "-req_text print text form of request\n");
|
||||
BIO_printf (bio_err, "-resp_text print text form of response\n");
|
||||
BIO_printf (bio_err, "-text print text form of request and response\n");
|
||||
BIO_printf (bio_err, "-reqout file write DER encoded OCSP request to \"file\"\n");
|
||||
BIO_printf (bio_err, "-respout file write DER encoded OCSP reponse to \"file\"\n");
|
||||
BIO_printf (bio_err, "-reqin file read DER encoded OCSP request from \"file\"\n");
|
||||
BIO_printf (bio_err, "-respin file read DER encoded OCSP reponse from \"file\"\n");
|
||||
BIO_printf (bio_err, "-nonce add OCSP nonce to request\n");
|
||||
BIO_printf (bio_err, "-no_nonce don't add OCSP nonce to request\n");
|
||||
BIO_printf (bio_err, "-url URL OCSP responder URL\n");
|
||||
BIO_printf (bio_err, "-host host:n send OCSP request to host on port n\n");
|
||||
BIO_printf (bio_err, "-path path to use in OCSP request\n");
|
||||
BIO_printf (bio_err, "-CApath dir trusted certificates directory\n");
|
||||
BIO_printf (bio_err, "-CAfile file trusted certificates file\n");
|
||||
BIO_printf (bio_err, "-VAfile file validator certificates file\n");
|
||||
BIO_printf (bio_err, "-validity_period n maximum validity discrepancy in seconds\n");
|
||||
BIO_printf (bio_err, "-status_age n maximum status age in seconds\n");
|
||||
BIO_printf (bio_err, "-noverify don't verify response at all\n");
|
||||
BIO_printf (bio_err, "-verify_other file additional certificates to search for signer\n");
|
||||
BIO_printf (bio_err, "-trust_other don't verify additional certificates\n");
|
||||
BIO_printf (bio_err, "-no_intern don't search certificates contained in response for signer\n");
|
||||
BIO_printf (bio_err, "-out file output filename\n");
|
||||
BIO_printf (bio_err, "-issuer file issuer certificate\n");
|
||||
BIO_printf (bio_err, "-cert file certificate to check\n");
|
||||
BIO_printf (bio_err, "-serial n serial number to check\n");
|
||||
BIO_printf (bio_err, "-signer file certificate to sign OCSP request with\n");
|
||||
BIO_printf (bio_err, "-signkey file private key to sign OCSP request with\n");
|
||||
BIO_printf (bio_err, "-sign_other file additional certificates to include in signed request\n");
|
||||
BIO_printf (bio_err, "-no_certs don't include any certificates in signed request\n");
|
||||
BIO_printf (bio_err, "-req_text print text form of request\n");
|
||||
BIO_printf (bio_err, "-resp_text print text form of response\n");
|
||||
BIO_printf (bio_err, "-text print text form of request and response\n");
|
||||
BIO_printf (bio_err, "-reqout file write DER encoded OCSP request to \"file\"\n");
|
||||
BIO_printf (bio_err, "-respout file write DER encoded OCSP reponse to \"file\"\n");
|
||||
BIO_printf (bio_err, "-reqin file read DER encoded OCSP request from \"file\"\n");
|
||||
BIO_printf (bio_err, "-respin file read DER encoded OCSP reponse from \"file\"\n");
|
||||
BIO_printf (bio_err, "-nonce add OCSP nonce to request\n");
|
||||
BIO_printf (bio_err, "-no_nonce don't add OCSP nonce to request\n");
|
||||
BIO_printf (bio_err, "-url URL OCSP responder URL\n");
|
||||
BIO_printf (bio_err, "-host host:n send OCSP request to host on port n\n");
|
||||
BIO_printf (bio_err, "-path path to use in OCSP request\n");
|
||||
BIO_printf (bio_err, "-CApath dir trusted certificates directory\n");
|
||||
BIO_printf (bio_err, "-CAfile file trusted certificates file\n");
|
||||
BIO_printf (bio_err, "-VAfile file validator certificates file\n");
|
||||
BIO_printf (bio_err, "-validity_period n maximum validity discrepancy in seconds\n");
|
||||
BIO_printf (bio_err, "-status_age n maximum status age in seconds\n");
|
||||
BIO_printf (bio_err, "-noverify don't verify response at all\n");
|
||||
BIO_printf (bio_err, "-verify_other file additional certificates to search for signer\n");
|
||||
BIO_printf (bio_err, "-trust_other don't verify additional certificates\n");
|
||||
BIO_printf (bio_err, "-no_intern don't search certificates contained in response for signer\n");
|
||||
BIO_printf (bio_err, "-no_signature_verify don't check signature on response\n");
|
||||
BIO_printf (bio_err, "-no_cert_verify don't check signing certificate\n");
|
||||
BIO_printf (bio_err, "-no_chain don't chain verify response\n");
|
||||
BIO_printf (bio_err, "-no_cert_checks don't do additional checks on signing certificate\n");
|
||||
BIO_printf (bio_err, "-port num port to run responder on\n");
|
||||
BIO_printf (bio_err, "-index file certificate status index file\n");
|
||||
BIO_printf (bio_err, "-CA file CA certificate\n");
|
||||
BIO_printf (bio_err, "-rsigner file responder certificate to sign responses with\n");
|
||||
BIO_printf (bio_err, "-rkey file responder key to sign responses with\n");
|
||||
BIO_printf (bio_err, "-rother file other certificates to include in response\n");
|
||||
BIO_printf (bio_err, "-resp_no_certs don't include any certificates in response\n");
|
||||
BIO_printf (bio_err, "-nmin n number of minutes before next update\n");
|
||||
BIO_printf (bio_err, "-ndays n number of days before next update\n");
|
||||
BIO_printf (bio_err, "-resp_key_id identify reponse by signing certificate key ID\n");
|
||||
BIO_printf (bio_err, "-nrequest n number of requests to accept (default unlimited)\n");
|
||||
BIO_printf (bio_err, "-<dgst alg> use specified digest in the request\n");
|
||||
BIO_printf (bio_err, "-no_cert_verify don't check signing certificate\n");
|
||||
BIO_printf (bio_err, "-no_chain don't chain verify response\n");
|
||||
BIO_printf (bio_err, "-no_cert_checks don't do additional checks on signing certificate\n");
|
||||
BIO_printf (bio_err, "-port num port to run responder on\n");
|
||||
BIO_printf (bio_err, "-index file certificate status index file\n");
|
||||
BIO_printf (bio_err, "-CA file CA certificate\n");
|
||||
BIO_printf (bio_err, "-rsigner file responder certificate to sign responses with\n");
|
||||
BIO_printf (bio_err, "-rkey file responder key to sign responses with\n");
|
||||
BIO_printf (bio_err, "-rother file other certificates to include in response\n");
|
||||
BIO_printf (bio_err, "-resp_no_certs don't include any certificates in response\n");
|
||||
BIO_printf (bio_err, "-nmin n number of minutes before next update\n");
|
||||
BIO_printf (bio_err, "-ndays n number of days before next update\n");
|
||||
BIO_printf (bio_err, "-resp_key_id identify reponse by signing certificate key ID\n");
|
||||
BIO_printf (bio_err, "-nrequest n number of requests to accept (default unlimited)\n");
|
||||
BIO_printf (bio_err, "-<dgst alg> use specified digest in the request\n");
|
||||
BIO_printf (bio_err, "-timeout n timeout connection to OCSP responder after n seconds\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -1419,7 +1420,7 @@ OCSP_RESPONSE *process_responder(BIO *err, OCSP_REQUEST *req,
|
||||
}
|
||||
resp = query_responder(err, cbio, path, headers, req, req_timeout);
|
||||
if (!resp)
|
||||
BIO_printf(bio_err, "Error querying OCSP responsder\n");
|
||||
BIO_printf(bio_err, "Error querying OCSP responder\n");
|
||||
end:
|
||||
if (cbio)
|
||||
BIO_free_all(cbio);
|
||||
|
@@ -106,16 +106,16 @@ FUNCTION functions[] = {
|
||||
{FUNC_TYPE_GENERAL,"gendsa",gendsa_main},
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"genpkey",genpkey_main},
|
||||
#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
{FUNC_TYPE_GENERAL,"s_server",s_server_main},
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
{FUNC_TYPE_GENERAL,"s_client",s_client_main},
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SPEED
|
||||
{FUNC_TYPE_GENERAL,"speed",speed_main},
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
{FUNC_TYPE_GENERAL,"s_time",s_time_main},
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"version",version_main},
|
||||
@@ -125,7 +125,7 @@ FUNCTION functions[] = {
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"crl2pkcs7",crl2pkcs7_main},
|
||||
{FUNC_TYPE_GENERAL,"sess_id",sess_id_main},
|
||||
#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
{FUNC_TYPE_GENERAL,"ciphers",ciphers_main},
|
||||
#endif
|
||||
{FUNC_TYPE_GENERAL,"nseq",nseq_main},
|
||||
|
@@ -32,7 +32,7 @@ foreach (@ARGV)
|
||||
push(@files,$_);
|
||||
$str="\t{FUNC_TYPE_GENERAL,\"$_\",${_}_main},\n";
|
||||
if (($_ =~ /^s_/) || ($_ =~ /^ciphers$/))
|
||||
{ print "#if !defined(OPENSSL_NO_SOCK) && !(defined(OPENSSL_NO_SSL2) && defined(OPENSSL_NO_SSL3))\n${str}#endif\n"; }
|
||||
{ print "#if !defined(OPENSSL_NO_SOCK)\n${str}#endif\n"; }
|
||||
elsif ( ($_ =~ /^speed$/))
|
||||
{ print "#ifndef OPENSSL_NO_SPEED\n${str}#endif\n"; }
|
||||
elsif ( ($_ =~ /^engine$/))
|
||||
|
@@ -284,6 +284,7 @@ static void sc_usage(void)
|
||||
BIO_printf(bio_err," -connect host:port - who to connect to (default is %s:%s)\n",SSL_HOST_NAME,PORT_STR);
|
||||
|
||||
BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n");
|
||||
BIO_printf(bio_err," -verify_return_error - return verification errors\n");
|
||||
BIO_printf(bio_err," -cert arg - certificate file to use, PEM format assumed\n");
|
||||
BIO_printf(bio_err," -certform arg - certificate format (PEM or DER) PEM default\n");
|
||||
BIO_printf(bio_err," -key arg - Private key file to use, in cert file if\n");
|
||||
@@ -294,6 +295,7 @@ static void sc_usage(void)
|
||||
BIO_printf(bio_err," -CAfile arg - PEM format file of CA's\n");
|
||||
BIO_printf(bio_err," -reconnect - Drop and re-make the connection with the same Session-ID\n");
|
||||
BIO_printf(bio_err," -pause - sleep(1) after each read(2) and write(2) system call\n");
|
||||
BIO_printf(bio_err," -prexit - print session information even on connection failure\n");
|
||||
BIO_printf(bio_err," -showcerts - show all certificates in the chain\n");
|
||||
BIO_printf(bio_err," -debug - extra output\n");
|
||||
#ifdef WATT32
|
||||
@@ -320,6 +322,7 @@ static void sc_usage(void)
|
||||
BIO_printf(bio_err," -ssl3 - just use SSLv3\n");
|
||||
BIO_printf(bio_err," -tls1 - just use TLSv1\n");
|
||||
BIO_printf(bio_err," -dtls1 - just use DTLSv1\n");
|
||||
BIO_printf(bio_err," -fallback_scsv - send TLS_FALLBACK_SCSV\n");
|
||||
BIO_printf(bio_err," -mtu - set the link layer MTU\n");
|
||||
BIO_printf(bio_err," -no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol\n");
|
||||
BIO_printf(bio_err," -bugs - Switch on all SSL implementation bug workarounds\n");
|
||||
@@ -434,6 +437,7 @@ int MAIN(int argc, char **argv)
|
||||
char *sess_out = NULL;
|
||||
struct sockaddr peer;
|
||||
int peerlen = sizeof(peer);
|
||||
int fallback_scsv = 0;
|
||||
int enable_timeouts = 0 ;
|
||||
long socket_mtu = 0;
|
||||
#ifndef OPENSSL_NO_JPAKE
|
||||
@@ -608,6 +612,10 @@ int MAIN(int argc, char **argv)
|
||||
socket_mtu = atol(*(++argv));
|
||||
}
|
||||
#endif
|
||||
else if (strcmp(*argv,"-fallback_scsv") == 0)
|
||||
{
|
||||
fallback_scsv = 1;
|
||||
}
|
||||
else if (strcmp(*argv,"-bugs") == 0)
|
||||
bugs=1;
|
||||
else if (strcmp(*argv,"-keyform") == 0)
|
||||
@@ -933,6 +941,10 @@ bad:
|
||||
SSL_set_session(con, sess);
|
||||
SSL_SESSION_free(sess);
|
||||
}
|
||||
|
||||
if (fallback_scsv)
|
||||
SSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);
|
||||
|
||||
#ifndef OPENSSL_NO_TLSEXT
|
||||
if (servername != NULL)
|
||||
{
|
||||
@@ -1006,10 +1018,22 @@ re_start:
|
||||
BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);
|
||||
}
|
||||
|
||||
if (socket_mtu > 28)
|
||||
if (socket_mtu)
|
||||
{
|
||||
if(socket_mtu < DTLS_get_link_min_mtu(con))
|
||||
{
|
||||
BIO_printf(bio_err,"MTU too small. Must be at least %ld\n",
|
||||
DTLS_get_link_min_mtu(con));
|
||||
BIO_free(sbio);
|
||||
goto shut;
|
||||
}
|
||||
SSL_set_options(con, SSL_OP_NO_QUERY_MTU);
|
||||
SSL_set_mtu(con, socket_mtu - 28);
|
||||
if(!DTLS_set_link_mtu(con, socket_mtu))
|
||||
{
|
||||
BIO_printf(bio_err, "Failed to set MTU\n");
|
||||
BIO_free(sbio);
|
||||
goto shut;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* want to do MTU discovery */
|
||||
|
@@ -410,6 +410,7 @@ static void sv_usage(void)
|
||||
BIO_printf(bio_err," -context arg - set session ID context\n");
|
||||
BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n");
|
||||
BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n");
|
||||
BIO_printf(bio_err," -verify_return_error - return verification errors\n");
|
||||
BIO_printf(bio_err," -cert arg - certificate file to use\n");
|
||||
BIO_printf(bio_err," (default is %s)\n",TEST_CERT);
|
||||
BIO_printf(bio_err," -crl_check - check the peer certificate has not been revoked by its CA.\n" \
|
||||
@@ -473,6 +474,7 @@ static void sv_usage(void)
|
||||
BIO_printf(bio_err," -no_ecdhe - Disable ephemeral ECDH\n");
|
||||
#endif
|
||||
BIO_printf(bio_err," -bugs - Turn on SSL bug compatibility\n");
|
||||
BIO_printf(bio_err," -hack - workaround for early Netscape code\n");
|
||||
BIO_printf(bio_err," -www - Respond to a 'GET /' with a status page\n");
|
||||
BIO_printf(bio_err," -WWW - Respond to a 'GET /<path> HTTP/1.0' with file ./<path>\n");
|
||||
BIO_printf(bio_err," -HTTP - Respond to a 'GET /<path> HTTP/1.0' with file ./<path>\n");
|
||||
@@ -493,6 +495,10 @@ static void sv_usage(void)
|
||||
BIO_printf(bio_err," -no_ticket - disable use of RFC4507bis session tickets\n");
|
||||
BIO_printf(bio_err," -legacy_renegotiation - enable use of legacy renegotiation (dangerous)\n");
|
||||
#endif
|
||||
BIO_printf(bio_err," -status - respond to certificate status requests\n");
|
||||
BIO_printf(bio_err," -status_verbose - enable status request verbose printout\n");
|
||||
BIO_printf(bio_err," -status_timeout n - status request responder timeout\n");
|
||||
BIO_printf(bio_err," -status_url URL - status request fallback URL\n");
|
||||
}
|
||||
|
||||
static int local_argc=0;
|
||||
@@ -670,7 +676,7 @@ static int MS_CALLBACK ssl_servername_cb(SSL *s, int *ad, void *arg)
|
||||
|
||||
if (servername)
|
||||
{
|
||||
if (strcmp(servername,p->servername))
|
||||
if (strcasecmp(servername,p->servername))
|
||||
return p->extension_error;
|
||||
if (ctx2)
|
||||
{
|
||||
@@ -1209,6 +1215,14 @@ bad:
|
||||
sv_usage();
|
||||
goto end;
|
||||
}
|
||||
#ifndef OPENSSL_NO_DTLS1
|
||||
if (www && socket_type == SOCK_DGRAM)
|
||||
{
|
||||
BIO_printf(bio_err,
|
||||
"Can't use -HTTP, -www or -WWW with DTLS\n");
|
||||
goto end;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
|
||||
if (jpake_secret)
|
||||
@@ -1842,10 +1856,24 @@ static int sv_body(char *hostname, int s, unsigned char *context)
|
||||
BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);
|
||||
}
|
||||
|
||||
if (socket_mtu > 28)
|
||||
if (socket_mtu)
|
||||
{
|
||||
if(socket_mtu < DTLS_get_link_min_mtu(con))
|
||||
{
|
||||
BIO_printf(bio_err,"MTU too small. Must be at least %ld\n",
|
||||
DTLS_get_link_min_mtu(con));
|
||||
ret = -1;
|
||||
BIO_free(sbio);
|
||||
goto err;
|
||||
}
|
||||
SSL_set_options(con, SSL_OP_NO_QUERY_MTU);
|
||||
SSL_set_mtu(con, socket_mtu - 28);
|
||||
if(!DTLS_set_link_mtu(con, socket_mtu))
|
||||
{
|
||||
BIO_printf(bio_err, "Failed to set MTU\n");
|
||||
ret = -1;
|
||||
BIO_free(sbio);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* want to do MTU discovery */
|
||||
|
33
apps/speed.c
33
apps/speed.c
@@ -2608,7 +2608,11 @@ static int do_multi(int multi)
|
||||
fds=malloc(multi*sizeof *fds);
|
||||
for(n=0 ; n < multi ; ++n)
|
||||
{
|
||||
pipe(fd);
|
||||
if (pipe(fd) == -1)
|
||||
{
|
||||
fprintf(stderr, "pipe failure\n");
|
||||
exit(1);
|
||||
}
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
if(fork())
|
||||
@@ -2620,7 +2624,11 @@ static int do_multi(int multi)
|
||||
{
|
||||
close(fd[0]);
|
||||
close(1);
|
||||
dup(fd[1]);
|
||||
if (dup(fd[1]) == -1)
|
||||
{
|
||||
fprintf(stderr, "dup failed\n");
|
||||
exit(1);
|
||||
}
|
||||
close(fd[1]);
|
||||
mr=1;
|
||||
usertime=0;
|
||||
@@ -2670,27 +2678,6 @@ static int do_multi(int multi)
|
||||
k=atoi(sstrsep(&p,sep));
|
||||
sstrsep(&p,sep);
|
||||
|
||||
d=atof(sstrsep(&p,sep));
|
||||
if(n)
|
||||
rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
|
||||
else
|
||||
rsa_results[k][0]=d;
|
||||
|
||||
d=atof(sstrsep(&p,sep));
|
||||
if(n)
|
||||
rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
|
||||
else
|
||||
rsa_results[k][1]=d;
|
||||
}
|
||||
else if(!strncmp(buf,"+F2:",4))
|
||||
{
|
||||
int k;
|
||||
double d;
|
||||
|
||||
p=buf+4;
|
||||
k=atoi(sstrsep(&p,sep));
|
||||
sstrsep(&p,sep);
|
||||
|
||||
d=atof(sstrsep(&p,sep));
|
||||
if(n)
|
||||
rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
|
||||
|
@@ -1,4 +1,3 @@
|
||||
/* $LP: LPlib/source/LPdir_vms.c,v 1.20 2004/08/26 13:36:05 _cvs_levitte Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
@@ -88,6 +87,12 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
size_t filespeclen = strlen(directory);
|
||||
char *filespec = NULL;
|
||||
|
||||
if (filespeclen == 0)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* MUST be a VMS directory specification! Let's estimate if it is. */
|
||||
if (directory[filespeclen-1] != ']'
|
||||
&& directory[filespeclen-1] != '>'
|
||||
|
@@ -1,4 +1,3 @@
|
||||
/* $LP: LPlib/source/LPdir_win.c,v 1.10 2004/08/26 13:36:05 _cvs_levitte Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||
* All rights reserved.
|
||||
@@ -37,7 +36,7 @@
|
||||
#if defined(LP_SYS_WINCE) && !defined(FindFirstFile)
|
||||
# define FindFirstFile FindFirstFileW
|
||||
#endif
|
||||
#if defined(LP_SYS_WINCE) && !defined(FindFirstFile)
|
||||
#if defined(LP_SYS_WINCE) && !defined(FindNextFile)
|
||||
# define FindNextFile FindNextFileW
|
||||
#endif
|
||||
|
||||
@@ -63,6 +62,16 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
errno = 0;
|
||||
if (*ctx == NULL)
|
||||
{
|
||||
const char *extdir = directory;
|
||||
char *extdirbuf = NULL;
|
||||
size_t dirlen = strlen (directory);
|
||||
|
||||
if (dirlen == 0)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX));
|
||||
if (*ctx == NULL)
|
||||
{
|
||||
@@ -71,15 +80,35 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
}
|
||||
memset(*ctx, '\0', sizeof(LP_DIR_CTX));
|
||||
|
||||
if (directory[dirlen-1] != '*')
|
||||
{
|
||||
extdirbuf = (char *)malloc(dirlen + 3);
|
||||
if (extdirbuf == NULL)
|
||||
{
|
||||
free(*ctx);
|
||||
*ctx = NULL;
|
||||
errno = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
if (directory[dirlen-1] != '/' && directory[dirlen-1] != '\\')
|
||||
extdir = strcat(strcpy (extdirbuf,directory),"/*");
|
||||
else
|
||||
extdir = strcat(strcpy (extdirbuf,directory),"*");
|
||||
}
|
||||
|
||||
if (sizeof(TCHAR) != sizeof(char))
|
||||
{
|
||||
TCHAR *wdir = NULL;
|
||||
/* len_0 denotes string length *with* trailing 0 */
|
||||
size_t index = 0,len_0 = strlen(directory) + 1;
|
||||
size_t index = 0,len_0 = strlen(extdir) + 1;
|
||||
|
||||
wdir = (TCHAR *)malloc(len_0 * sizeof(TCHAR));
|
||||
wdir = (TCHAR *)calloc(len_0, sizeof(TCHAR));
|
||||
if (wdir == NULL)
|
||||
{
|
||||
if (extdirbuf != NULL)
|
||||
{
|
||||
free (extdirbuf);
|
||||
}
|
||||
free(*ctx);
|
||||
*ctx = NULL;
|
||||
errno = ENOMEM;
|
||||
@@ -87,17 +116,23 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
}
|
||||
|
||||
#ifdef LP_MULTIBYTE_AVAILABLE
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, directory, len_0, (WCHAR *)wdir, len_0))
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, extdir, len_0, (WCHAR *)wdir, len_0))
|
||||
#endif
|
||||
for (index = 0; index < len_0; index++)
|
||||
wdir[index] = (TCHAR)directory[index];
|
||||
wdir[index] = (TCHAR)extdir[index];
|
||||
|
||||
(*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx);
|
||||
|
||||
free(wdir);
|
||||
}
|
||||
else
|
||||
(*ctx)->handle = FindFirstFile((TCHAR *)directory, &(*ctx)->ctx);
|
||||
{
|
||||
(*ctx)->handle = FindFirstFile((TCHAR *)extdir, &(*ctx)->ctx);
|
||||
}
|
||||
if (extdirbuf != NULL)
|
||||
{
|
||||
free (extdirbuf);
|
||||
}
|
||||
|
||||
if ((*ctx)->handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@@ -114,7 +149,6 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeof(TCHAR) != sizeof(char))
|
||||
{
|
||||
TCHAR *wdir = (*ctx)->ctx.cFileName;
|
||||
|
@@ -31,6 +31,7 @@ CPUID_OBJ=mem_clr.o
|
||||
LIBS=
|
||||
|
||||
GENERAL=Makefile README crypto-lib.com install.com
|
||||
TEST=constant_time_test.c
|
||||
|
||||
LIB= $(TOP)/libcrypto.a
|
||||
SHARED_LIB= libcrypto$(SHLIB_EXT)
|
||||
@@ -41,7 +42,8 @@ SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER= crypto.h opensslv.h opensslconf.h ebcdic.h symhacks.h \
|
||||
ossl_typ.h
|
||||
HEADER= cryptlib.h buildinf.h md32_common.h o_time.h o_str.h o_dir.h $(EXHEADER)
|
||||
HEADER= cryptlib.h buildinf.h md32_common.h o_time.h o_str.h o_dir.h \
|
||||
constant_time_locl.h $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
|
||||
@@ -51,12 +53,7 @@ top:
|
||||
all: shared
|
||||
|
||||
buildinf.h: ../Makefile
|
||||
( echo "#ifndef MK1MF_BUILD"; \
|
||||
echo ' /* auto-generated by crypto/Makefile for crypto/cversion.c */'; \
|
||||
echo ' #define CFLAGS "$(CC) $(CFLAG)"'; \
|
||||
echo ' #define PLATFORM "$(PLATFORM)"'; \
|
||||
echo " #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \
|
||||
echo '#endif' ) >buildinf.h
|
||||
$(PERL) $(TOP)/util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)" >buildinf.h
|
||||
|
||||
x86cpuid.s: x86cpuid.pl perlasm/x86asm.pl
|
||||
$(PERL) x86cpuid.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@
|
||||
|
@@ -136,11 +136,16 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
|
||||
|
||||
p= *pp;
|
||||
i= *(p++);
|
||||
if (i > 7)
|
||||
{
|
||||
i=ASN1_R_INVALID_BIT_STRING_BITS_LEFT;
|
||||
goto err;
|
||||
}
|
||||
/* We do this to preserve the settings. If we modify
|
||||
* the settings, via the _set_bit function, we will recalculate
|
||||
* on output */
|
||||
ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
|
||||
ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
|
||||
ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|i); /* set */
|
||||
|
||||
if (len-- > 1) /* using one because of the bits left byte */
|
||||
{
|
||||
|
@@ -283,17 +283,29 @@ err:
|
||||
ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
long len)
|
||||
{
|
||||
ASN1_OBJECT *ret=NULL;
|
||||
const unsigned char *p;
|
||||
unsigned char *data;
|
||||
int i;
|
||||
/* Sanity check OID encoding: can't have leading 0x80 in
|
||||
* subidentifiers, see: X.690 8.19.2
|
||||
int i, length;
|
||||
|
||||
/* Sanity check OID encoding.
|
||||
* Need at least one content octet.
|
||||
* MSB must be clear in the last octet.
|
||||
* can't have leading 0x80 in subidentifiers, see: X.690 8.19.2
|
||||
*/
|
||||
for (i = 0, p = *pp; i < len; i++, p++)
|
||||
if (len <= 0 || len > INT_MAX || pp == NULL || (p = *pp) == NULL ||
|
||||
p[len - 1] & 0x80)
|
||||
{
|
||||
ASN1err(ASN1_F_C2I_ASN1_OBJECT,ASN1_R_INVALID_OBJECT_ENCODING);
|
||||
return NULL;
|
||||
}
|
||||
/* Now 0 < len <= INT_MAX, so the cast is safe. */
|
||||
length = (int)len;
|
||||
for (i = 0; i < length; i++, p++)
|
||||
{
|
||||
if (*p == 0x80 && (!i || !(p[-1] & 0x80)))
|
||||
{
|
||||
@@ -316,23 +328,23 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
|
||||
data = (unsigned char *)ret->data;
|
||||
ret->data = NULL;
|
||||
/* once detached we can change it */
|
||||
if ((data == NULL) || (ret->length < len))
|
||||
if ((data == NULL) || (ret->length < length))
|
||||
{
|
||||
ret->length=0;
|
||||
if (data != NULL) OPENSSL_free(data);
|
||||
data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1);
|
||||
data=(unsigned char *)OPENSSL_malloc(length);
|
||||
if (data == NULL)
|
||||
{ i=ERR_R_MALLOC_FAILURE; goto err; }
|
||||
ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
|
||||
}
|
||||
memcpy(data,p,(int)len);
|
||||
memcpy(data,p,length);
|
||||
/* reattach data to object, after which it remains const */
|
||||
ret->data =data;
|
||||
ret->length=(int)len;
|
||||
ret->length=length;
|
||||
ret->sn=NULL;
|
||||
ret->ln=NULL;
|
||||
/* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
|
||||
p+=len;
|
||||
p+=length;
|
||||
|
||||
if (a != NULL) (*a)=ret;
|
||||
*pp=p;
|
||||
|
@@ -113,7 +113,7 @@ IMPLEMENT_STACK_OF(ASN1_TYPE)
|
||||
IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b)
|
||||
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
|
@@ -196,24 +196,29 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
|
||||
struct tm *ts;
|
||||
struct tm data;
|
||||
size_t len = 20;
|
||||
int free_s = 0;
|
||||
|
||||
if (s == NULL)
|
||||
{
|
||||
free_s = 1;
|
||||
s=M_ASN1_UTCTIME_new();
|
||||
}
|
||||
if (s == NULL)
|
||||
return(NULL);
|
||||
goto err;
|
||||
|
||||
|
||||
ts=OPENSSL_gmtime(&t, &data);
|
||||
if (ts == NULL)
|
||||
return(NULL);
|
||||
goto err;
|
||||
|
||||
if (offset_day || offset_sec)
|
||||
{
|
||||
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
|
||||
return NULL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if((ts->tm_year < 50) || (ts->tm_year >= 150))
|
||||
return NULL;
|
||||
goto err;
|
||||
|
||||
p=(char *)s->data;
|
||||
if ((p == NULL) || ((size_t)s->length < len))
|
||||
@@ -222,7 +227,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
|
||||
if (p == NULL)
|
||||
{
|
||||
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
|
||||
return(NULL);
|
||||
goto err;
|
||||
}
|
||||
if (s->data != NULL)
|
||||
OPENSSL_free(s->data);
|
||||
@@ -237,6 +242,10 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
|
||||
ebcdic2ascii(s->data, s->data, s->length);
|
||||
#endif
|
||||
return(s);
|
||||
err:
|
||||
if (free_s && s)
|
||||
M_ASN1_UTCTIME_free(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -90,6 +90,12 @@ int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature,
|
||||
ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
|
||||
{
|
||||
ASN1err(ASN1_F_ASN1_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
goto err;
|
||||
}
|
||||
|
||||
inl=i2d(data,NULL);
|
||||
buf_in=OPENSSL_malloc((unsigned int)inl);
|
||||
@@ -142,6 +148,12 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (signature->type == V_ASN1_BIT_STRING && signature->flags & 0x7)
|
||||
{
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
/* Convert signature OID into digest and public key OIDs */
|
||||
|
@@ -256,7 +256,12 @@ int EVP_PKEY_asn1_add_alias(int to, int from)
|
||||
if (!ameth)
|
||||
return 0;
|
||||
ameth->pkey_base_id = to;
|
||||
return EVP_PKEY_asn1_add0(ameth);
|
||||
if (!EVP_PKEY_asn1_add0(ameth))
|
||||
{
|
||||
EVP_PKEY_asn1_free(ameth);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_PKEY_asn1_get0_info(int *ppkey_id, int *ppkey_base_id, int *ppkey_flags,
|
||||
|
@@ -777,7 +777,7 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
|
||||
int ASN1_TYPE_get(ASN1_TYPE *a);
|
||||
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
|
||||
int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
|
||||
int ASN1_TYPE_cmp(ASN1_TYPE *a, ASN1_TYPE *b);
|
||||
int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
|
||||
|
||||
ASN1_OBJECT * ASN1_OBJECT_new(void );
|
||||
void ASN1_OBJECT_free(ASN1_OBJECT *a);
|
||||
@@ -1327,6 +1327,7 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_ILLEGAL_TIME_VALUE 184
|
||||
#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185
|
||||
#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
|
||||
#define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 220
|
||||
#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
|
||||
#define ASN1_R_INVALID_DIGIT 130
|
||||
#define ASN1_R_INVALID_MIME_TYPE 205
|
||||
@@ -1376,6 +1377,7 @@ void ERR_load_ASN1_strings(void);
|
||||
#define ASN1_R_TIME_NOT_ASCII_FORMAT 193
|
||||
#define ASN1_R_TOO_LONG 155
|
||||
#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
|
||||
#define ASN1_R_TYPE_NOT_PRIMITIVE 218
|
||||
#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
|
||||
#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158
|
||||
#define ASN1_R_UNEXPECTED_EOC 159
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/* crypto/asn1/asn1_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2009 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2014 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
|
||||
@@ -243,6 +243,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,"illegal time value"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),"integer not ascii format"},
|
||||
{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BIT_STRING_BITS_LEFT),"invalid bit string bits left"},
|
||||
{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"},
|
||||
{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"},
|
||||
{ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,"invalid mime type"},
|
||||
@@ -292,6 +293,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
|
||||
{ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT),"time not ascii format"},
|
||||
{ERR_REASON(ASN1_R_TOO_LONG) ,"too long"},
|
||||
{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) ,"type not constructed"},
|
||||
{ERR_REASON(ASN1_R_TYPE_NOT_PRIMITIVE) ,"type not primitive"},
|
||||
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY),"unable to decode rsa key"},
|
||||
{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY),"unable to decode rsa private key"},
|
||||
{ERR_REASON(ASN1_R_UNEXPECTED_EOC) ,"unexpected eoc"},
|
||||
|
@@ -131,6 +131,9 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
*pclass=xclass;
|
||||
if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
|
||||
|
||||
if (inf && !(ret & V_ASN1_CONSTRUCTED))
|
||||
goto err;
|
||||
|
||||
#if 0
|
||||
fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
|
||||
(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
|
||||
|
@@ -667,6 +667,8 @@ static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)
|
||||
int len, state, save_state = 0;
|
||||
|
||||
headers = sk_MIME_HEADER_new(mime_hdr_cmp);
|
||||
if (!headers)
|
||||
return NULL;
|
||||
while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {
|
||||
/* If whitespace at line start then continuation line */
|
||||
if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME;
|
||||
|
@@ -134,15 +134,23 @@ ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct)
|
||||
|
||||
if (!(octmp->length = i2d(obj, NULL))) {
|
||||
ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
|
||||
return NULL;
|
||||
goto err;
|
||||
}
|
||||
if (!(p = OPENSSL_malloc (octmp->length))) {
|
||||
ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
goto err;
|
||||
}
|
||||
octmp->data = p;
|
||||
i2d (obj, &p);
|
||||
return octmp;
|
||||
err:
|
||||
if (!oct || !*oct)
|
||||
{
|
||||
ASN1_STRING_free(octmp);
|
||||
if (oct)
|
||||
*oct = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -154,7 +154,10 @@ static int asn1_bio_new(BIO *b)
|
||||
if (!ctx)
|
||||
return 0;
|
||||
if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE))
|
||||
{
|
||||
OPENSSL_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
b->init = 1;
|
||||
b->ptr = (char *)ctx;
|
||||
b->flags = 0;
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#!/usr/local/bin/perl -w
|
||||
|
||||
# Written by Dr Stephen N Henson (steve@openssl.org).
|
||||
# Licensed under the terms of the OpenSSL license.
|
||||
|
||||
use strict;
|
||||
|
||||
my ($i, @arr);
|
||||
|
@@ -66,7 +66,11 @@ int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
|
||||
ASN1_STRING *os;
|
||||
|
||||
if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0);
|
||||
if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0);
|
||||
if (!M_ASN1_OCTET_STRING_set(os,data,len))
|
||||
{
|
||||
M_ASN1_OCTET_STRING_free(os);
|
||||
return 0;
|
||||
}
|
||||
ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
|
||||
return(1);
|
||||
}
|
||||
|
@@ -440,6 +440,8 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
|
||||
l=80-2-obase;
|
||||
|
||||
b=X509_NAME_oneline(name,NULL,0);
|
||||
if (!b)
|
||||
return 0;
|
||||
if (!*b)
|
||||
{
|
||||
OPENSSL_free(b);
|
||||
|
@@ -870,6 +870,14 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
|
||||
}
|
||||
else if (cst)
|
||||
{
|
||||
if (utype == V_ASN1_NULL || utype == V_ASN1_BOOLEAN
|
||||
|| utype == V_ASN1_OBJECT || utype == V_ASN1_INTEGER
|
||||
|| utype == V_ASN1_ENUMERATED)
|
||||
{
|
||||
ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
|
||||
ASN1_R_TYPE_NOT_PRIMITIVE);
|
||||
return 0;
|
||||
}
|
||||
buf.length = 0;
|
||||
buf.max = 0;
|
||||
buf.data = NULL;
|
||||
|
@@ -453,9 +453,14 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
{
|
||||
derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
|
||||
* sizeof(*derlst));
|
||||
tmpdat = OPENSSL_malloc(skcontlen);
|
||||
if (!derlst || !tmpdat)
|
||||
if (!derlst)
|
||||
return 0;
|
||||
tmpdat = OPENSSL_malloc(skcontlen);
|
||||
if (!tmpdat)
|
||||
{
|
||||
OPENSSL_free(derlst);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If not sorting just output each item */
|
||||
|
@@ -128,3 +128,13 @@ void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
|
||||
}
|
||||
}
|
||||
|
||||
int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b)
|
||||
{
|
||||
int rv;
|
||||
rv = OBJ_cmp(a->algorithm, b->algorithm);
|
||||
if (rv)
|
||||
return rv;
|
||||
if (!a->parameter && !b->parameter)
|
||||
return 0;
|
||||
return ASN1_TYPE_cmp(a->parameter, b->parameter);
|
||||
}
|
||||
|
@@ -270,6 +270,7 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
{
|
||||
/* We handle IDP and deltas */
|
||||
if ((nid == NID_issuing_distribution_point)
|
||||
|| (nid == NID_authority_key_identifier)
|
||||
|| (nid == NID_delta_crl))
|
||||
break;;
|
||||
crl->flags |= EXFLAG_CRITICAL;
|
||||
|
@@ -162,7 +162,8 @@ extern "C" {
|
||||
#define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */
|
||||
|
||||
#define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout to
|
||||
* adjust socket timeouts */
|
||||
* adjust socket timeouts */
|
||||
#define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49
|
||||
|
||||
/* modifiers */
|
||||
#define BIO_FP_READ 0x02
|
||||
@@ -553,6 +554,8 @@ int BIO_ctrl_reset_read_request(BIO *b);
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer)
|
||||
#define BIO_dgram_set_peer(b,peer) \
|
||||
(int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)
|
||||
#define BIO_dgram_get_mtu_overhead(b) \
|
||||
(unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL)
|
||||
|
||||
/* These two aren't currently implemented */
|
||||
/* int BIO_get_ex_num(BIO *bio); */
|
||||
|
@@ -132,8 +132,8 @@ int BIO_free(BIO *a)
|
||||
|
||||
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
|
||||
|
||||
if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
|
||||
a->method->destroy(a);
|
||||
if ((a->method != NULL) && (a->method->destroy != NULL))
|
||||
a->method->destroy(a);
|
||||
OPENSSL_free(a);
|
||||
return(1);
|
||||
}
|
||||
|
@@ -375,6 +375,36 @@ static int dgram_write(BIO *b, const char *in, int inl)
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static long dgram_get_mtu_overhead(bio_dgram_data *data)
|
||||
{
|
||||
long ret;
|
||||
|
||||
switch (data->peer.sa.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
/* Assume this is UDP - 20 bytes for IP, 8 bytes for UDP */
|
||||
ret = 28;
|
||||
break;
|
||||
#if OPENSSL_USE_IPV6
|
||||
case AF_INET6:
|
||||
#ifdef IN6_IS_ADDR_V4MAPPED
|
||||
if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
|
||||
/* Assume this is UDP - 20 bytes for IP, 8 bytes for UDP */
|
||||
ret = 28;
|
||||
else
|
||||
#endif
|
||||
/* Assume this is UDP - 40 bytes for IP, 8 bytes for UDP */
|
||||
ret = 48;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
/* We don't know. Go with the historical default */
|
||||
ret = 28;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
{
|
||||
long ret=1;
|
||||
@@ -551,23 +581,24 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
#endif
|
||||
break;
|
||||
case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
|
||||
ret = -dgram_get_mtu_overhead(data);
|
||||
switch (data->peer.sa.sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
ret = 576 - 20 - 8;
|
||||
ret += 576;
|
||||
break;
|
||||
#if OPENSSL_USE_IPV6
|
||||
case AF_INET6:
|
||||
#ifdef IN6_IS_ADDR_V4MAPPED
|
||||
if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
|
||||
ret = 576 - 20 - 8;
|
||||
ret += 576;
|
||||
else
|
||||
#endif
|
||||
ret = 1280 - 40 - 8;
|
||||
ret += 1280;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = 576 - 20 - 8;
|
||||
ret += 576;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -768,6 +799,9 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
||||
ret = 0;
|
||||
break;
|
||||
#endif
|
||||
case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD:
|
||||
ret = dgram_get_mtu_overhead(data);
|
||||
break;
|
||||
default:
|
||||
ret=0;
|
||||
break;
|
||||
|
@@ -1584,17 +1584,17 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -1609,63 +1609,63 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_3,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_3,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
sd c_1,24(a0)
|
||||
|
||||
dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_1,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_1,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_1,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -1680,93 +1680,93 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_2,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_2,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
sd c_3,40(a0)
|
||||
|
||||
dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_3,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_3,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -1781,108 +1781,108 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_1,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_1,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_1,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_1,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_1,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
sd c_2,56(a0)
|
||||
|
||||
dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_2,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_2,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -1897,78 +1897,78 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_3,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_3,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
sd c_1,72(a0)
|
||||
|
||||
dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_1,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_1,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_1,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -1983,48 +1983,48 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_2,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
sd c_3,88(a0)
|
||||
|
||||
dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_3,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_3,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -2039,17 +2039,17 @@ LEAF(bn_sqr_comba8)
|
||||
dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_1,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_1,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
sd c_2,104(a0)
|
||||
|
||||
dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
|
||||
@@ -2070,9 +2070,9 @@ LEAF(bn_sqr_comba4)
|
||||
.set reorder
|
||||
ld a_0,0(a1)
|
||||
ld a_1,8(a1)
|
||||
dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
|
||||
ld a_2,16(a1)
|
||||
ld a_3,24(a1)
|
||||
dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
|
||||
mflo c_1
|
||||
mfhi c_2
|
||||
sd c_1,0(a0)
|
||||
@@ -2093,17 +2093,17 @@ LEAF(bn_sqr_comba4)
|
||||
dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -2118,48 +2118,48 @@ LEAF(bn_sqr_comba4)
|
||||
dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_3,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_3,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt AT,t_2,zero
|
||||
daddu c_3,AT
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_1,t_1
|
||||
sltu AT,c_1,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_1,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_1,t_1
|
||||
daddu c_2,AT
|
||||
daddu t_2,t_1
|
||||
sltu AT,c_2,AT
|
||||
daddu c_2,t_2
|
||||
sltu AT,c_2,t_2
|
||||
daddu c_3,AT
|
||||
sltu t_2,c_2,t_2
|
||||
daddu c_3,t_2
|
||||
sd c_1,24(a0)
|
||||
|
||||
dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_1,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_2,t_1
|
||||
sltu AT,c_2,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_2,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_2,t_1
|
||||
daddu c_3,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_1,c_3,AT
|
||||
daddu c_3,t_2
|
||||
sltu AT,c_3,t_2
|
||||
daddu c_1,AT
|
||||
sltu t_2,c_3,t_2
|
||||
daddu c_1,t_2
|
||||
dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
@@ -2174,17 +2174,17 @@ LEAF(bn_sqr_comba4)
|
||||
dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
|
||||
mflo t_1
|
||||
mfhi t_2
|
||||
slt c_2,t_2,zero
|
||||
dsll t_2,1
|
||||
slt a2,t_1,zero
|
||||
daddu t_2,a2
|
||||
dsll t_1,1
|
||||
daddu c_3,t_1
|
||||
sltu AT,c_3,t_1
|
||||
daddu t_2,AT
|
||||
daddu c_3,t_1
|
||||
daddu AT,t_2
|
||||
sltu t_1,c_3,t_1
|
||||
daddu c_1,AT
|
||||
daddu t_2,t_1
|
||||
sltu c_2,c_1,AT
|
||||
daddu c_1,t_2
|
||||
sltu AT,c_1,t_2
|
||||
daddu c_2,AT
|
||||
sltu t_2,c_1,t_2
|
||||
daddu c_2,t_2
|
||||
sd c_3,40(a0)
|
||||
|
||||
dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
|
||||
|
@@ -189,7 +189,7 @@ BN_ULONG bn_add_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
|
||||
|
||||
if (n <= 0) return 0;
|
||||
|
||||
asm (
|
||||
asm volatile (
|
||||
" subq %2,%2 \n"
|
||||
".p2align 4 \n"
|
||||
"1: movq (%4,%2,8),%0 \n"
|
||||
@@ -200,7 +200,7 @@ BN_ULONG bn_add_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
|
||||
" sbbq %0,%0 \n"
|
||||
: "=&a"(ret),"+c"(n),"=&r"(i)
|
||||
: "r"(rp),"r"(ap),"r"(bp)
|
||||
: "cc"
|
||||
: "cc", "memory"
|
||||
);
|
||||
|
||||
return ret&1;
|
||||
@@ -212,7 +212,7 @@ BN_ULONG bn_sub_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
|
||||
|
||||
if (n <= 0) return 0;
|
||||
|
||||
asm (
|
||||
asm volatile (
|
||||
" subq %2,%2 \n"
|
||||
".p2align 4 \n"
|
||||
"1: movq (%4,%2,8),%0 \n"
|
||||
@@ -223,7 +223,7 @@ BN_ULONG bn_sub_words (BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int
|
||||
" sbbq %0,%0 \n"
|
||||
: "=&a"(ret),"+c"(n),"=&r"(i)
|
||||
: "r"(rp),"r"(ap),"r"(bp)
|
||||
: "cc"
|
||||
: "cc", "memory"
|
||||
);
|
||||
|
||||
return ret&1;
|
||||
@@ -273,6 +273,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
|
||||
/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
|
||||
/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
|
||||
|
||||
/*
|
||||
* Keep in mind that carrying into high part of multiplication result
|
||||
* can not overflow, because it cannot be all-ones.
|
||||
*/
|
||||
#if 0
|
||||
/* original macros are kept for reference purposes */
|
||||
#define mul_add_c(a,b,c0,c1,c2) { \
|
||||
@@ -287,10 +291,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
|
||||
BN_ULONG ta=(a),tb=(b),t0; \
|
||||
t1 = BN_UMULT_HIGH(ta,tb); \
|
||||
t0 = ta * tb; \
|
||||
t2 = t1+t1; c2 += (t2<t1)?1:0; \
|
||||
t1 = t0+t0; t2 += (t1<t0)?1:0; \
|
||||
c0 += t1; t2 += (c0<t1)?1:0; \
|
||||
c0 += t0; t2 = t1+((c0<t0)?1:0);\
|
||||
c1 += t2; c2 += (c1<t2)?1:0; \
|
||||
c0 += t0; t1 += (c0<t0)?1:0; \
|
||||
c1 += t1; c2 += (c1<t1)?1:0; \
|
||||
}
|
||||
#else
|
||||
#define mul_add_c(a,b,c0,c1,c2) do { \
|
||||
@@ -328,22 +332,14 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
|
||||
: "=a"(t1),"=d"(t2) \
|
||||
: "a"(a),"m"(b) \
|
||||
: "cc"); \
|
||||
asm ("addq %0,%0; adcq %2,%1" \
|
||||
: "+d"(t2),"+r"(c2) \
|
||||
: "g"(0) \
|
||||
: "cc"); \
|
||||
asm ("addq %0,%0; adcq %2,%1" \
|
||||
: "+a"(t1),"+d"(t2) \
|
||||
: "g"(0) \
|
||||
: "cc"); \
|
||||
asm ("addq %2,%0; adcq %3,%1" \
|
||||
: "+r"(c0),"+d"(t2) \
|
||||
: "a"(t1),"g"(0) \
|
||||
: "cc"); \
|
||||
asm ("addq %2,%0; adcq %3,%1" \
|
||||
: "+r"(c1),"+r"(c2) \
|
||||
: "d"(t2),"g"(0) \
|
||||
: "cc"); \
|
||||
asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
|
||||
: "+r"(c0),"+r"(c1),"+r"(c2) \
|
||||
: "r"(t1),"r"(t2),"g"(0) \
|
||||
: "cc"); \
|
||||
asm ("addq %3,%0; adcq %4,%1; adcq %5,%2" \
|
||||
: "+r"(c0),"+r"(c1),"+r"(c2) \
|
||||
: "r"(t1),"r"(t2),"g"(0) \
|
||||
: "cc"); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
|
@@ -438,6 +438,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
|
||||
/* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */
|
||||
/* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */
|
||||
|
||||
/*
|
||||
* Keep in mind that carrying into high part of multiplication result
|
||||
* can not overflow, because it cannot be all-ones.
|
||||
*/
|
||||
#ifdef BN_LLONG
|
||||
#define mul_add_c(a,b,c0,c1,c2) \
|
||||
t=(BN_ULLONG)a*b; \
|
||||
@@ -478,10 +482,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
|
||||
#define mul_add_c2(a,b,c0,c1,c2) { \
|
||||
BN_ULONG ta=(a),tb=(b),t0; \
|
||||
BN_UMULT_LOHI(t0,t1,ta,tb); \
|
||||
t2 = t1+t1; c2 += (t2<t1)?1:0; \
|
||||
t1 = t0+t0; t2 += (t1<t0)?1:0; \
|
||||
c0 += t1; t2 += (c0<t1)?1:0; \
|
||||
c0 += t0; t2 = t1+((c0<t0)?1:0);\
|
||||
c1 += t2; c2 += (c1<t2)?1:0; \
|
||||
c0 += t0; t1 += (c0<t0)?1:0; \
|
||||
c1 += t1; c2 += (c1<t1)?1:0; \
|
||||
}
|
||||
|
||||
#define sqr_add_c(a,i,c0,c1,c2) { \
|
||||
@@ -508,10 +512,10 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
|
||||
BN_ULONG ta=(a),tb=(b),t0; \
|
||||
t1 = BN_UMULT_HIGH(ta,tb); \
|
||||
t0 = ta * tb; \
|
||||
t2 = t1+t1; c2 += (t2<t1)?1:0; \
|
||||
t1 = t0+t0; t2 += (t1<t0)?1:0; \
|
||||
c0 += t1; t2 += (c0<t1)?1:0; \
|
||||
c0 += t0; t2 = t1+((c0<t0)?1:0);\
|
||||
c1 += t2; c2 += (c1<t2)?1:0; \
|
||||
c0 += t0; t1 += (c0<t0)?1:0; \
|
||||
c1 += t1; c2 += (c1<t1)?1:0; \
|
||||
}
|
||||
|
||||
#define sqr_add_c(a,i,c0,c1,c2) { \
|
||||
|
@@ -767,7 +767,14 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
|
||||
bits = BN_num_bits(p);
|
||||
if (bits == 0)
|
||||
{
|
||||
ret = BN_one(rr);
|
||||
/* x**0 mod 1 is still zero. */
|
||||
if (BN_is_one(m))
|
||||
{
|
||||
ret = 1;
|
||||
BN_zero(rr);
|
||||
}
|
||||
else
|
||||
ret = BN_one(rr);
|
||||
return ret;
|
||||
}
|
||||
if (a == 0)
|
||||
|
@@ -339,6 +339,15 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
|
||||
BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
|
||||
return(NULL);
|
||||
}
|
||||
#ifdef PURIFY
|
||||
/* Valgrind complains in BN_consttime_swap because we process the whole
|
||||
* array even if it's not initialised yet. This doesn't matter in that
|
||||
* function - what's important is constant time operation (we're not
|
||||
* actually going to use the data)
|
||||
*/
|
||||
memset(a, 0, sizeof(BN_ULONG)*words);
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
B=b->d;
|
||||
/* Check if the previous number needs to be copied */
|
||||
|
@@ -824,9 +824,9 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
|
||||
/* ... and right shift */
|
||||
for (val=t_d[0],i=0; i<BN_NIST_521_TOP-1; i++)
|
||||
{
|
||||
tmp = val>>BN_NIST_521_RSHIFT;
|
||||
val = t_d[i+1];
|
||||
t_d[i] = (tmp | val<<BN_NIST_521_LSHIFT) & BN_MASK2;
|
||||
t_d[i] = ( val>>BN_NIST_521_RSHIFT |
|
||||
(tmp=t_d[i+1])<<BN_NIST_521_LSHIFT ) & BN_MASK2;
|
||||
val=tmp;
|
||||
}
|
||||
t_d[i] = val>>BN_NIST_521_RSHIFT;
|
||||
/* lower 521 bits */
|
||||
|
@@ -77,6 +77,7 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
|
||||
if (al <= 0)
|
||||
{
|
||||
r->top=0;
|
||||
r->neg = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@@ -676,44 +676,98 @@ int test_mul(BIO *bp)
|
||||
|
||||
int test_sqr(BIO *bp, BN_CTX *ctx)
|
||||
{
|
||||
BIGNUM a,c,d,e;
|
||||
int i;
|
||||
BIGNUM *a,*c,*d,*e;
|
||||
int i, ret = 0;
|
||||
|
||||
BN_init(&a);
|
||||
BN_init(&c);
|
||||
BN_init(&d);
|
||||
BN_init(&e);
|
||||
a = BN_new();
|
||||
c = BN_new();
|
||||
d = BN_new();
|
||||
e = BN_new();
|
||||
if (a == NULL || c == NULL || d == NULL || e == NULL)
|
||||
{
|
||||
goto err;
|
||||
}
|
||||
|
||||
for (i=0; i<num0; i++)
|
||||
{
|
||||
BN_bntest_rand(&a,40+i*10,0,0);
|
||||
a.neg=rand_neg();
|
||||
BN_sqr(&c,&a,ctx);
|
||||
BN_bntest_rand(a,40+i*10,0,0);
|
||||
a->neg=rand_neg();
|
||||
BN_sqr(c,a,ctx);
|
||||
if (bp != NULL)
|
||||
{
|
||||
if (!results)
|
||||
{
|
||||
BN_print(bp,&a);
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," * ");
|
||||
BN_print(bp,&a);
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," - ");
|
||||
}
|
||||
BN_print(bp,&c);
|
||||
BN_print(bp,c);
|
||||
BIO_puts(bp,"\n");
|
||||
}
|
||||
BN_div(&d,&e,&c,&a,ctx);
|
||||
BN_sub(&d,&d,&a);
|
||||
if(!BN_is_zero(&d) || !BN_is_zero(&e))
|
||||
{
|
||||
fprintf(stderr,"Square test failed!\n");
|
||||
return 0;
|
||||
}
|
||||
BN_div(d,e,c,a,ctx);
|
||||
BN_sub(d,d,a);
|
||||
if(!BN_is_zero(d) || !BN_is_zero(e))
|
||||
{
|
||||
fprintf(stderr,"Square test failed!\n");
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
BN_free(&a);
|
||||
BN_free(&c);
|
||||
BN_free(&d);
|
||||
BN_free(&e);
|
||||
return(1);
|
||||
|
||||
/* Regression test for a BN_sqr overflow bug. */
|
||||
BN_hex2bn(&a,
|
||||
"80000000000000008000000000000001FFFFFFFFFFFFFFFE0000000000000000");
|
||||
BN_sqr(c, a, ctx);
|
||||
if (bp != NULL)
|
||||
{
|
||||
if (!results)
|
||||
{
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," * ");
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," - ");
|
||||
}
|
||||
BN_print(bp,c);
|
||||
BIO_puts(bp,"\n");
|
||||
}
|
||||
BN_mul(d, a, a, ctx);
|
||||
if (BN_cmp(c, d))
|
||||
{
|
||||
fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
|
||||
"different results!\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Regression test for a BN_sqr overflow bug. */
|
||||
BN_hex2bn(&a,
|
||||
"80000000000000000000000080000001FFFFFFFE000000000000000000000000");
|
||||
BN_sqr(c, a, ctx);
|
||||
if (bp != NULL)
|
||||
{
|
||||
if (!results)
|
||||
{
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," * ");
|
||||
BN_print(bp,a);
|
||||
BIO_puts(bp," - ");
|
||||
}
|
||||
BN_print(bp,c);
|
||||
BIO_puts(bp,"\n");
|
||||
}
|
||||
BN_mul(d, a, a, ctx);
|
||||
if (BN_cmp(c, d))
|
||||
{
|
||||
fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
|
||||
"different results!\n");
|
||||
goto err;
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
if (a != NULL) BN_free(a);
|
||||
if (c != NULL) BN_free(c);
|
||||
if (d != NULL) BN_free(d);
|
||||
if (e != NULL) BN_free(e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_mont(BIO *bp, BN_CTX *ctx)
|
||||
|
@@ -71,6 +71,43 @@
|
||||
|
||||
static const char rnd_seed[] = "string to make the random number generator think it has entropy";
|
||||
|
||||
/* test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. */
|
||||
static int test_exp_mod_zero() {
|
||||
BIGNUM a, p, m;
|
||||
BIGNUM r;
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
int ret = 1;
|
||||
|
||||
BN_init(&m);
|
||||
BN_one(&m);
|
||||
|
||||
BN_init(&a);
|
||||
BN_one(&a);
|
||||
|
||||
BN_init(&p);
|
||||
BN_zero(&p);
|
||||
|
||||
BN_init(&r);
|
||||
BN_mod_exp(&r, &a, &p, &m, ctx);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
if (BN_is_zero(&r))
|
||||
ret = 0;
|
||||
else
|
||||
{
|
||||
printf("1**0 mod 1 = ");
|
||||
BN_print_fp(stdout, &r);
|
||||
printf(", should be 0\n");
|
||||
}
|
||||
|
||||
BN_free(&r);
|
||||
BN_free(&a);
|
||||
BN_free(&p);
|
||||
BN_free(&m);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
BN_CTX *ctx;
|
||||
@@ -190,7 +227,13 @@ int main(int argc, char *argv[])
|
||||
ERR_remove_thread_state(NULL);
|
||||
CRYPTO_mem_leaks(out);
|
||||
BIO_free(out);
|
||||
printf(" done\n");
|
||||
printf("\n");
|
||||
|
||||
if (test_exp_mod_zero() != 0)
|
||||
goto err;
|
||||
|
||||
printf("done\n");
|
||||
|
||||
EXIT(0);
|
||||
err:
|
||||
ERR_load_crypto_strings();
|
||||
|
@@ -321,7 +321,7 @@ again:
|
||||
p=eat_ws(conf, end);
|
||||
if (*p != ']')
|
||||
{
|
||||
if (*p != '\0')
|
||||
if (*p != '\0' && ss != p)
|
||||
{
|
||||
ss=p;
|
||||
goto again;
|
||||
|
206
crypto/constant_time_locl.h
Normal file
206
crypto/constant_time_locl.h
Normal file
@@ -0,0 +1,206 @@
|
||||
/* crypto/constant_time_locl.h */
|
||||
/*
|
||||
* Utilities for constant-time cryptography.
|
||||
*
|
||||
* Author: Emilia Kasper (emilia@openssl.org)
|
||||
* Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley
|
||||
* (Google).
|
||||
* ====================================================================
|
||||
* Copyright (c) 2014 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 copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CONSTANT_TIME_LOCL_H
|
||||
#define HEADER_CONSTANT_TIME_LOCL_H
|
||||
|
||||
#include "e_os.h" /* For 'inline' */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The boolean methods return a bitmask of all ones (0xff...f) for true
|
||||
* and 0 for false. This is useful for choosing a value based on the result
|
||||
* of a conditional in constant time. For example,
|
||||
*
|
||||
* if (a < b) {
|
||||
* c = a;
|
||||
* } else {
|
||||
* c = b;
|
||||
* }
|
||||
*
|
||||
* can be written as
|
||||
*
|
||||
* unsigned int lt = constant_time_lt(a, b);
|
||||
* c = constant_time_select(lt, a, b);
|
||||
*/
|
||||
|
||||
/*
|
||||
* Returns the given value with the MSB copied to all the other
|
||||
* bits. Uses the fact that arithmetic shift shifts-in the sign bit.
|
||||
* However, this is not ensured by the C standard so you may need to
|
||||
* replace this with something else on odd CPUs.
|
||||
*/
|
||||
static inline unsigned int constant_time_msb(unsigned int a);
|
||||
|
||||
/*
|
||||
* Returns 0xff..f if a < b and 0 otherwise.
|
||||
*/
|
||||
static inline unsigned int constant_time_lt(unsigned int a, unsigned int b);
|
||||
/* Convenience method for getting an 8-bit mask. */
|
||||
static inline unsigned char constant_time_lt_8(unsigned int a, unsigned int b);
|
||||
|
||||
/*
|
||||
* Returns 0xff..f if a >= b and 0 otherwise.
|
||||
*/
|
||||
static inline unsigned int constant_time_ge(unsigned int a, unsigned int b);
|
||||
/* Convenience method for getting an 8-bit mask. */
|
||||
static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b);
|
||||
|
||||
/*
|
||||
* Returns 0xff..f if a == 0 and 0 otherwise.
|
||||
*/
|
||||
static inline unsigned int constant_time_is_zero(unsigned int a);
|
||||
/* Convenience method for getting an 8-bit mask. */
|
||||
static inline unsigned char constant_time_is_zero_8(unsigned int a);
|
||||
|
||||
|
||||
/*
|
||||
* Returns 0xff..f if a == b and 0 otherwise.
|
||||
*/
|
||||
static inline unsigned int constant_time_eq(unsigned int a, unsigned int b);
|
||||
/* Convenience method for getting an 8-bit mask. */
|
||||
static inline unsigned char constant_time_eq_8(unsigned int a, unsigned int b);
|
||||
/* Signed integers. */
|
||||
static inline unsigned int constant_time_eq_int(int a, int b);
|
||||
/* Convenience method for getting an 8-bit mask. */
|
||||
static inline unsigned char constant_time_eq_int_8(int a, int b);
|
||||
|
||||
|
||||
/*
|
||||
* Returns (mask & a) | (~mask & b).
|
||||
*
|
||||
* When |mask| is all 1s or all 0s (as returned by the methods above),
|
||||
* the select methods return either |a| (if |mask| is nonzero) or |b|
|
||||
* (if |mask| is zero).
|
||||
*/
|
||||
static inline unsigned int constant_time_select(unsigned int mask,
|
||||
unsigned int a, unsigned int b);
|
||||
/* Convenience method for unsigned chars. */
|
||||
static inline unsigned char constant_time_select_8(unsigned char mask,
|
||||
unsigned char a, unsigned char b);
|
||||
/* Convenience method for signed integers. */
|
||||
static inline int constant_time_select_int(unsigned int mask, int a, int b);
|
||||
|
||||
static inline unsigned int constant_time_msb(unsigned int a)
|
||||
{
|
||||
return 0-(a >> (sizeof(a) * 8 - 1));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_lt(unsigned int a, unsigned int b)
|
||||
{
|
||||
return constant_time_msb(a^((a^b)|((a-b)^b)));
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_lt_8(unsigned int a, unsigned int b)
|
||||
{
|
||||
return (unsigned char)(constant_time_lt(a, b));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_ge(unsigned int a, unsigned int b)
|
||||
{
|
||||
return ~constant_time_lt(a, b);
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b)
|
||||
{
|
||||
return (unsigned char)(constant_time_ge(a, b));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_is_zero(unsigned int a)
|
||||
{
|
||||
return constant_time_msb(~a & (a - 1));
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_is_zero_8(unsigned int a)
|
||||
{
|
||||
return (unsigned char)(constant_time_is_zero(a));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_eq(unsigned int a, unsigned int b)
|
||||
{
|
||||
return constant_time_is_zero(a ^ b);
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_eq_8(unsigned int a, unsigned int b)
|
||||
{
|
||||
return (unsigned char)(constant_time_eq(a, b));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_eq_int(int a, int b)
|
||||
{
|
||||
return constant_time_eq((unsigned)(a), (unsigned)(b));
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_eq_int_8(int a, int b)
|
||||
{
|
||||
return constant_time_eq_8((unsigned)(a), (unsigned)(b));
|
||||
}
|
||||
|
||||
static inline unsigned int constant_time_select(unsigned int mask,
|
||||
unsigned int a, unsigned int b)
|
||||
{
|
||||
return (mask & a) | (~mask & b);
|
||||
}
|
||||
|
||||
static inline unsigned char constant_time_select_8(unsigned char mask,
|
||||
unsigned char a, unsigned char b)
|
||||
{
|
||||
return (unsigned char)(constant_time_select(mask, a, b));
|
||||
}
|
||||
|
||||
static inline int constant_time_select_int(unsigned int mask, int a, int b)
|
||||
{
|
||||
return (int)(constant_time_select(mask, (unsigned)(a), (unsigned)(b)));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HEADER_CONSTANT_TIME_LOCL_H */
|
330
crypto/constant_time_test.c
Normal file
330
crypto/constant_time_test.c
Normal file
@@ -0,0 +1,330 @@
|
||||
/* crypto/constant_time_test.c */
|
||||
/*
|
||||
* Utilities for constant-time cryptography.
|
||||
*
|
||||
* Author: Emilia Kasper (emilia@openssl.org)
|
||||
* Based on previous work by Bodo Moeller, Emilia Kasper, Adam Langley
|
||||
* (Google).
|
||||
* ====================================================================
|
||||
* Copyright (c) 2014 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 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 "../crypto/constant_time_locl.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 < sizeof(test_values)/sizeof(int); ++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 < sizeof(test_values)/sizeof(int); ++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 < sizeof(signed_test_values)/sizeof(int); ++i)
|
||||
{
|
||||
c = signed_test_values[i];
|
||||
for (j = 0; j < sizeof(signed_test_values)/sizeof(int); ++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, "ok (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;
|
||||
}
|
||||
}
|
@@ -111,8 +111,8 @@ $ ET_WHIRLPOOL = "WHRLPOOL"
|
||||
$ IF ARCH .EQS. "VAX" THEN ET_WHIRLPOOL = ""
|
||||
$ ENCRYPT_TYPES = "Basic,"+ -
|
||||
"OBJECTS,"+ -
|
||||
"MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ET_WHIRLPOOL+","+ -
|
||||
"DES,AES,RC2,RC4,RC5,IDEA,BF,CAST,CAMELLIA,SEED,MODES,"+ -
|
||||
"MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ET_WHIRLPOOL+","+ -
|
||||
"DES,AES,RC2,RC4,IDEA,BF,CAST,CAMELLIA,SEED,MODES,"+ -
|
||||
"BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,"+ -
|
||||
"BUFFER,BIO,STACK,LHASH,RAND,ERR,"+ -
|
||||
"EVP,EVP_2,EVP_3,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
|
||||
@@ -204,10 +204,18 @@ $ GOSUB CHECK_OPT_FILE
|
||||
$!
|
||||
$! Define The Different Encryption "library" Strings.
|
||||
$!
|
||||
$ APPS_DES = "DES/DES,CBC3_ENC"
|
||||
$ APPS_PKCS7 = "ENC/ENC;DEC/DEC;SIGN/SIGN;VERIFY/VERIFY,EXAMPLE"
|
||||
$!!! Test apps disabled, as they aren't supported at all,
|
||||
$!!! not even in the unix build
|
||||
$!!! APPS_DES = "DES/DES,CBC3_ENC"
|
||||
$!!! APPS_PKCS7 = "ENC/ENC;DEC/DEC;SIGN/SIGN;VERIFY/VERIFY,EXAMPLE"
|
||||
$
|
||||
$ LIB_ = "cryptlib,mem,mem_clr,mem_dbg,cversion,ex_data,cpt_err,ebcdic,uid,o_time,o_str,o_dir"
|
||||
$! These variables are ordered as the SDIRS variable from the top Makefile.org
|
||||
$! The contents of these variables are copied from the LIBOBJ variable in the
|
||||
$! corresponding Makefile from each corresponding subdirectory, with .o stripped
|
||||
$! and spaces replaced with commas.
|
||||
$ LIB_ = "cryptlib,mem,mem_dbg,cversion,ex_data,cpt_err,ebcdic,"+ -
|
||||
"uid,o_time,o_str,o_dir,mem_clr"
|
||||
$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err,obj_xref"
|
||||
$ LIB_MD2 = "md2_dgst,md2_one"
|
||||
$ LIB_MD4 = "md4_dgst,md4_one"
|
||||
$ LIB_MD5 = "md5_dgst,md5_one"
|
||||
@@ -224,13 +232,13 @@ $ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
|
||||
"fcrypt,xcbc_enc,rpc_enc,cbc_cksm,"+ -
|
||||
"ede_cbcm_enc,des_old,des_old2,read2pwd"
|
||||
$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64"
|
||||
$ LIB_RC4 = "rc4_skey,rc4_enc"
|
||||
$ LIB_RC4 = "rc4_enc,rc4_skey"
|
||||
$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64"
|
||||
$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
|
||||
$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
|
||||
$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
|
||||
$ LIB_CAMELLIA = "camellia,cmll_misc,cmll_ecb,cmll_cbc,cmll_ofb,"+ -
|
||||
"cmll_cfb,cmll_ctr"
|
||||
$ LIB_CAMELLIA = "cmll_ecb,cmll_ofb,cmll_cfb,cmll_ctr,"+ -
|
||||
"camellia,cmll_misc,cmll_cbc"
|
||||
$ LIB_SEED = "seed,seed_ecb,seed_cbc,seed_cfb,seed_ofb"
|
||||
$ LIB_MODES = "cbc128,ctr128,cts128,cfb128,ofb128"
|
||||
$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
|
||||
@@ -261,22 +269,21 @@ $ LIB_ENGINE = "eng_err,eng_lib,eng_list,eng_init,eng_ctrl,"+ -
|
||||
"tb_rsa,tb_dsa,tb_ecdsa,tb_dh,tb_ecdh,tb_rand,tb_store,"+ -
|
||||
"tb_cipher,tb_digest,tb_pkmeth,tb_asnmth,"+ -
|
||||
"eng_openssl,eng_dyn,eng_cnf,eng_cryptodev"
|
||||
$ LIB_AES = "aes_core,aes_misc,aes_ecb,aes_cbc,aes_cfb,aes_ofb,aes_ctr,"+ -
|
||||
"aes_ige,aes_wrap"
|
||||
$ LIB_AES = "aes_misc,aes_ecb,aes_cfb,aes_ofb,aes_ctr,aes_ige,aes_wrap,"+ -
|
||||
"aes_core,aes_cbc"
|
||||
$ LIB_BUFFER = "buffer,buf_err"
|
||||
$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
|
||||
"bss_mem,bss_null,bss_fd,"+ -
|
||||
"bss_file,bss_sock,bss_conn,"+ -
|
||||
"bf_null,bf_buff,b_print,b_dump,"+ -
|
||||
"b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio,bss_log,"+ -
|
||||
"b_sock,bss_acpt,bf_nbio,bss_log,bss_bio,"+ -
|
||||
"bss_dgram,"+ -
|
||||
"bf_lbuf"
|
||||
"bf_lbuf,bss_rtcp" ! The last two are VMS specific
|
||||
$ LIB_STACK = "stack"
|
||||
$ LIB_LHASH = "lhash,lh_stats"
|
||||
$ LIB_RAND = "md_rand,randfile,rand_lib,rand_err,rand_egd,"+ -
|
||||
"rand_vms"
|
||||
"rand_vms" ! The last one is VMS specific
|
||||
$ LIB_ERR = "err,err_all,err_prn"
|
||||
$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err,obj_xref"
|
||||
$ LIB_EVP = "encode,digest,evp_enc,evp_key,evp_acnf,"+ -
|
||||
"e_des,e_bf,e_idea,e_des3,e_camellia,"+ -
|
||||
"e_rc4,e_aes,names,e_seed,"+ -
|
||||
@@ -337,6 +344,7 @@ $ LIB_TS = "ts_err,ts_req_utils,ts_req_print,ts_rsp_utils,ts_rsp_print,"+ -
|
||||
"ts_rsp_sign,ts_rsp_verify,ts_verify_ctx,ts_lib,ts_conf,"+ -
|
||||
"ts_asn1"
|
||||
$ LIB_JPAKE = "jpake,jpake_err"
|
||||
$ LIB_STORE = "str_err,str_lib,str_meth,str_mem"
|
||||
$!
|
||||
$! Setup exceptional compilations
|
||||
$!
|
||||
@@ -372,7 +380,7 @@ $ MODULE_NEXT:
|
||||
$!
|
||||
$! Extract The Module Name From The Encryption List.
|
||||
$!
|
||||
$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
|
||||
$ MODULE_NAME = F$EDIT(F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES),"COLLAPSE")
|
||||
$ IF MODULE_NAME.EQS."Basic" THEN MODULE_NAME = ""
|
||||
$ MODULE_NAME1 = MODULE_NAME
|
||||
$!
|
||||
@@ -456,7 +464,7 @@ $ THEN
|
||||
$!
|
||||
$! O.K, Extract The File Name From The File List.
|
||||
$!
|
||||
$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
|
||||
$ FILE_NAME = F$EDIT(F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE'),"COLLAPSE")
|
||||
$!
|
||||
$! else
|
||||
$!
|
||||
@@ -483,7 +491,7 @@ $! SHOW SYMBOL APPLICATION*
|
||||
$!
|
||||
$ IF APPLICATION .NES. ";"
|
||||
$ THEN
|
||||
$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",APPLICATION_OBJECTS)
|
||||
$ FILE_NAME = F$EDIT(F$ELEMENT(FILE_COUNTER,",",APPLICATION_OBJECTS),"COLLAPSE")
|
||||
$ IF FILE_NAME .EQS. ","
|
||||
$ THEN
|
||||
$ APPLICATION = ""
|
||||
@@ -1123,9 +1131,12 @@ $ CCDEFS = "TCPIP_TYPE_''P4',DSO_VMS"
|
||||
$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
|
||||
$ CCEXTRAFLAGS = ""
|
||||
$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
|
||||
$ CCDISABLEWARNINGS = "" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
|
||||
$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
|
||||
CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
|
||||
$ CCDISABLEWARNINGS = "" !!! "MAYLOSEDATA3" !!! "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
|
||||
$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. ""
|
||||
$ THEN
|
||||
$ IF CCDISABLEWARNINGS .NES. "" THEN CCDISABLEWARNINGS = CCDISABLEWARNINGS + ","
|
||||
$ CCDISABLEWARNINGS = CCDISABLEWARNINGS + USER_CCDISABLEWARNINGS
|
||||
$ ENDIF
|
||||
$!
|
||||
$! Check To See If We Have A ZLIB Option.
|
||||
$!
|
||||
@@ -1290,6 +1301,18 @@ $! Finish up the definition of CC.
|
||||
$!
|
||||
$ IF COMPILER .EQS. "DECC"
|
||||
$ THEN
|
||||
$! Not all compiler versions support MAYLOSEDATA3.
|
||||
$ OPT_TEST = "MAYLOSEDATA3"
|
||||
$ DEFINE /USER_MODE SYS$ERROR NL:
|
||||
$ DEFINE /USER_MODE SYS$OUTPUT NL:
|
||||
$ 'CC' /NOCROSS_REFERENCE /NOLIST /NOOBJECT -
|
||||
/WARNINGS = DISABLE = ('OPT_TEST', EMPTYFILE) NL:
|
||||
$ IF ($SEVERITY)
|
||||
$ THEN
|
||||
$ IF CCDISABLEWARNINGS .NES. "" THEN -
|
||||
CCDISABLEWARNINGS = CCDISABLEWARNINGS+ ","
|
||||
$ CCDISABLEWARNINGS = CCDISABLEWARNINGS+ OPT_TEST
|
||||
$ ENDIF
|
||||
$ IF CCDISABLEWARNINGS .EQS. ""
|
||||
$ THEN
|
||||
$ CC4DISABLEWARNINGS = "DOLLARID"
|
||||
|
@@ -69,10 +69,7 @@ const char *SSLeay_version(int t)
|
||||
if (t == SSLEAY_BUILT_ON)
|
||||
{
|
||||
#ifdef DATE
|
||||
static char buf[sizeof(DATE)+11];
|
||||
|
||||
BIO_snprintf(buf,sizeof buf,"built on: %s",DATE);
|
||||
return(buf);
|
||||
return(DATE);
|
||||
#else
|
||||
return("built on: date not available");
|
||||
#endif
|
||||
@@ -80,10 +77,7 @@ const char *SSLeay_version(int t)
|
||||
if (t == SSLEAY_CFLAGS)
|
||||
{
|
||||
#ifdef CFLAGS
|
||||
static char buf[sizeof(CFLAGS)+11];
|
||||
|
||||
BIO_snprintf(buf,sizeof buf,"compiler: %s",CFLAGS);
|
||||
return(buf);
|
||||
return(CFLAGS);
|
||||
#else
|
||||
return("compiler: information not available");
|
||||
#endif
|
||||
@@ -91,10 +85,7 @@ const char *SSLeay_version(int t)
|
||||
if (t == SSLEAY_PLATFORM)
|
||||
{
|
||||
#ifdef PLATFORM
|
||||
static char buf[sizeof(PLATFORM)+11];
|
||||
|
||||
BIO_snprintf(buf,sizeof buf,"platform: %s", PLATFORM);
|
||||
return(buf);
|
||||
return(PLATFORM);
|
||||
#else
|
||||
return("platform: information not available");
|
||||
#endif
|
||||
|
@@ -307,6 +307,12 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
|
||||
unsigned char *dp = NULL;
|
||||
int dplen;
|
||||
|
||||
if (!pkey->pkey.dsa || !pkey->pkey.dsa->priv_key)
|
||||
{
|
||||
DSAerr(DSA_F_DSA_PRIV_ENCODE,DSA_R_MISSING_PARAMETERS);
|
||||
goto err;
|
||||
}
|
||||
|
||||
params = ASN1_STRING_new();
|
||||
|
||||
if (!params)
|
||||
@@ -654,4 +660,3 @@ const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] =
|
||||
old_dsa_priv_encode
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -77,13 +77,25 @@ int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||
const unsigned char *sigbuf, int siglen, DSA *dsa)
|
||||
{
|
||||
DSA_SIG *s;
|
||||
const unsigned char *p = sigbuf;
|
||||
unsigned char *der = NULL;
|
||||
int derlen = -1;
|
||||
int ret=-1;
|
||||
|
||||
s = DSA_SIG_new();
|
||||
if (s == NULL) return(ret);
|
||||
if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
|
||||
if (d2i_DSA_SIG(&s,&p,siglen) == NULL) goto err;
|
||||
/* Ensure signature uses DER and doesn't have trailing garbage */
|
||||
derlen = i2d_DSA_SIG(s, &der);
|
||||
if (derlen != siglen || memcmp(sigbuf, der, derlen))
|
||||
goto err;
|
||||
ret=DSA_do_verify(dgst,dgst_len,s,dsa);
|
||||
err:
|
||||
if (derlen > 0)
|
||||
{
|
||||
OPENSSL_cleanse(der, derlen);
|
||||
OPENSSL_free(der);
|
||||
}
|
||||
DSA_SIG_free(s);
|
||||
return(ret);
|
||||
}
|
||||
|
@@ -609,7 +609,7 @@ int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN
|
||||
int EC_POINT_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
|
||||
int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
|
||||
|
||||
/** Computes r = generator * n sum_{i=0}^num p[i] * m[i]
|
||||
/** Computes r = generator * n sum_{i=0}^{num-1} p[i] * m[i]
|
||||
* \param group underlying EC_GROUP object
|
||||
* \param r EC_POINT object for the result
|
||||
* \param n BIGNUM with the multiplier for the group generator (optional)
|
||||
|
@@ -453,14 +453,16 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
|
||||
if (ktype > 0)
|
||||
{
|
||||
public_key = EC_KEY_get0_public_key(x);
|
||||
if ((pub_key = EC_POINT_point2bn(group, public_key,
|
||||
EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
|
||||
if (public_key != NULL)
|
||||
{
|
||||
reason = ERR_R_EC_LIB;
|
||||
goto err;
|
||||
}
|
||||
if (pub_key)
|
||||
if ((pub_key = EC_POINT_point2bn(group, public_key,
|
||||
EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
|
||||
{
|
||||
reason = ERR_R_EC_LIB;
|
||||
goto err;
|
||||
}
|
||||
buf_len = (size_t)BN_num_bytes(pub_key);
|
||||
}
|
||||
}
|
||||
|
||||
if (ktype == 2)
|
||||
|
@@ -1167,30 +1167,47 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ret->pub_key)
|
||||
EC_POINT_clear_free(ret->pub_key);
|
||||
ret->pub_key = EC_POINT_new(ret->group);
|
||||
if (ret->pub_key == NULL)
|
||||
{
|
||||
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (priv_key->publicKey)
|
||||
{
|
||||
const unsigned char *pub_oct;
|
||||
size_t pub_oct_len;
|
||||
int pub_oct_len;
|
||||
|
||||
if (ret->pub_key)
|
||||
EC_POINT_clear_free(ret->pub_key);
|
||||
ret->pub_key = EC_POINT_new(ret->group);
|
||||
if (ret->pub_key == NULL)
|
||||
{
|
||||
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
}
|
||||
pub_oct = M_ASN1_STRING_data(priv_key->publicKey);
|
||||
pub_oct_len = M_ASN1_STRING_length(priv_key->publicKey);
|
||||
/* save the point conversion form */
|
||||
/* The first byte - point conversion form - must be present. */
|
||||
if (pub_oct_len <= 0)
|
||||
{
|
||||
ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_BUFFER_TOO_SMALL);
|
||||
goto err;
|
||||
}
|
||||
/* Save the point conversion form. */
|
||||
ret->conv_form = (point_conversion_form_t)(pub_oct[0] & ~0x01);
|
||||
if (!EC_POINT_oct2point(ret->group, ret->pub_key,
|
||||
pub_oct, pub_oct_len, NULL))
|
||||
pub_oct, (size_t)(pub_oct_len), NULL))
|
||||
{
|
||||
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!EC_POINT_mul(ret->group, ret->pub_key, ret->priv_key, NULL, NULL, NULL))
|
||||
{
|
||||
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
}
|
||||
/* Remember the original private-key-only encoding. */
|
||||
ret->enc_flag |= EC_PKEY_NO_PUBKEY;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
err:
|
||||
@@ -1214,7 +1231,8 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
|
||||
size_t buf_len=0, tmp_len;
|
||||
EC_PRIVATEKEY *priv_key=NULL;
|
||||
|
||||
if (a == NULL || a->group == NULL || a->priv_key == NULL)
|
||||
if (a == NULL || a->group == NULL || a->priv_key == NULL ||
|
||||
(!(a->enc_flag & EC_PKEY_NO_PUBKEY) && a->pub_key == NULL))
|
||||
{
|
||||
ECerr(EC_F_I2D_ECPRIVATEKEY,
|
||||
ERR_R_PASSED_NULL_PARAMETER);
|
||||
|
@@ -64,7 +64,6 @@
|
||||
#include <string.h>
|
||||
#include "ec_lcl.h"
|
||||
#include <openssl/err.h>
|
||||
#include <string.h>
|
||||
|
||||
EC_KEY *EC_KEY_new(void)
|
||||
{
|
||||
|
@@ -1010,7 +1010,7 @@ int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *
|
||||
|
||||
int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
|
||||
{
|
||||
if (group->meth->dbl == 0)
|
||||
if (group->meth->invert == 0)
|
||||
{
|
||||
ECerr(EC_F_EC_POINT_INVERT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
|
||||
return 0;
|
||||
|
@@ -445,15 +445,16 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
|
||||
wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
|
||||
wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]); /* includes space for pivot */
|
||||
val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
|
||||
|
||||
|
||||
/* Ensure wNAF is initialised in case we end up going to err */
|
||||
if (wNAF) wNAF[0] = NULL; /* preliminary pivot */
|
||||
|
||||
if (!wsize || !wNAF_len || !wNAF || !val_sub)
|
||||
{
|
||||
ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
wNAF[0] = NULL; /* preliminary pivot */
|
||||
|
||||
/* num_val will be the total number of temporarily precomputed points */
|
||||
num_val = 0;
|
||||
|
||||
|
@@ -167,6 +167,7 @@ static int pkey_ec_verify(EVP_PKEY_CTX *ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_ECDH
|
||||
static int pkey_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
|
||||
{
|
||||
int ret;
|
||||
@@ -200,6 +201,7 @@ static int pkey_ec_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
|
||||
*keylen = ret;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
{
|
||||
@@ -332,7 +334,11 @@ const EVP_PKEY_METHOD ec_pkey_meth =
|
||||
0,0,
|
||||
|
||||
0,
|
||||
#ifndef OPENSSL_NO_ECDH
|
||||
pkey_ec_derive,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
|
||||
pkey_ec_ctrl,
|
||||
pkey_ec_ctrl_str
|
||||
|
@@ -1540,9 +1540,8 @@ int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ct
|
||||
int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
|
||||
{
|
||||
BN_CTX *new_ctx = NULL;
|
||||
BIGNUM *tmp0, *tmp1;
|
||||
size_t pow2 = 0;
|
||||
BIGNUM **heap = NULL;
|
||||
BIGNUM *tmp, *tmp_Z;
|
||||
BIGNUM **prod_Z = NULL;
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
|
||||
@@ -1557,124 +1556,104 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT
|
||||
}
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
tmp0 = BN_CTX_get(ctx);
|
||||
tmp1 = BN_CTX_get(ctx);
|
||||
if (tmp0 == NULL || tmp1 == NULL) goto err;
|
||||
tmp = BN_CTX_get(ctx);
|
||||
tmp_Z = BN_CTX_get(ctx);
|
||||
if (tmp == NULL || tmp_Z == NULL) goto err;
|
||||
|
||||
/* Before converting the individual points, compute inverses of all Z values.
|
||||
* Modular inversion is rather slow, but luckily we can do with a single
|
||||
* explicit inversion, plus about 3 multiplications per input value.
|
||||
*/
|
||||
|
||||
pow2 = 1;
|
||||
while (num > pow2)
|
||||
pow2 <<= 1;
|
||||
/* Now pow2 is the smallest power of 2 satifsying pow2 >= num.
|
||||
* We need twice that. */
|
||||
pow2 <<= 1;
|
||||
|
||||
heap = OPENSSL_malloc(pow2 * sizeof heap[0]);
|
||||
if (heap == NULL) goto err;
|
||||
|
||||
/* The array is used as a binary tree, exactly as in heapsort:
|
||||
*
|
||||
* heap[1]
|
||||
* heap[2] heap[3]
|
||||
* heap[4] heap[5] heap[6] heap[7]
|
||||
* heap[8]heap[9] heap[10]heap[11] heap[12]heap[13] heap[14] heap[15]
|
||||
*
|
||||
* We put the Z's in the last line;
|
||||
* then we set each other node to the product of its two child-nodes (where
|
||||
* empty or 0 entries are treated as ones);
|
||||
* then we invert heap[1];
|
||||
* then we invert each other node by replacing it by the product of its
|
||||
* parent (after inversion) and its sibling (before inversion).
|
||||
*/
|
||||
heap[0] = NULL;
|
||||
for (i = pow2/2 - 1; i > 0; i--)
|
||||
heap[i] = NULL;
|
||||
prod_Z = OPENSSL_malloc(num * sizeof prod_Z[0]);
|
||||
if (prod_Z == NULL) goto err;
|
||||
for (i = 0; i < num; i++)
|
||||
heap[pow2/2 + i] = &points[i]->Z;
|
||||
for (i = pow2/2 + num; i < pow2; i++)
|
||||
heap[i] = NULL;
|
||||
|
||||
/* set each node to the product of its children */
|
||||
for (i = pow2/2 - 1; i > 0; i--)
|
||||
{
|
||||
heap[i] = BN_new();
|
||||
if (heap[i] == NULL) goto err;
|
||||
|
||||
if (heap[2*i] != NULL)
|
||||
{
|
||||
if ((heap[2*i + 1] == NULL) || BN_is_zero(heap[2*i + 1]))
|
||||
{
|
||||
if (!BN_copy(heap[i], heap[2*i])) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BN_is_zero(heap[2*i]))
|
||||
{
|
||||
if (!BN_copy(heap[i], heap[2*i + 1])) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!group->meth->field_mul(group, heap[i],
|
||||
heap[2*i], heap[2*i + 1], ctx)) goto err;
|
||||
}
|
||||
}
|
||||
}
|
||||
prod_Z[i] = BN_new();
|
||||
if (prod_Z[i] == NULL) goto err;
|
||||
}
|
||||
|
||||
/* invert heap[1] */
|
||||
if (!BN_is_zero(heap[1]))
|
||||
{
|
||||
if (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))
|
||||
{
|
||||
ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (group->meth->field_encode != 0)
|
||||
{
|
||||
/* in the Montgomery case, we just turned R*H (representing H)
|
||||
* into 1/(R*H), but we need R*(1/H) (representing 1/H);
|
||||
* i.e. we have need to multiply by the Montgomery factor twice */
|
||||
if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
|
||||
if (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;
|
||||
}
|
||||
/* Set each prod_Z[i] to the product of points[0]->Z .. points[i]->Z,
|
||||
* skipping any zero-valued inputs (pretend that they're 1). */
|
||||
|
||||
/* set other heap[i]'s to their inverses */
|
||||
for (i = 2; i < pow2/2 + num; i += 2)
|
||||
if (!BN_is_zero(&points[0]->Z))
|
||||
{
|
||||
/* i is even */
|
||||
if ((heap[i + 1] != NULL) && !BN_is_zero(heap[i + 1]))
|
||||
if (!BN_copy(prod_Z[0], &points[0]->Z)) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (group->meth->field_set_to_one != 0)
|
||||
{
|
||||
if (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;
|
||||
if (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;
|
||||
if (!BN_copy(heap[i], tmp0)) goto err;
|
||||
if (!BN_copy(heap[i + 1], tmp1)) goto err;
|
||||
if (!group->meth->field_set_to_one(group, prod_Z[0], ctx)) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!BN_copy(heap[i], heap[i/2])) goto err;
|
||||
if (!BN_one(prod_Z[0])) goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* we have replaced all non-zero Z's by their inverses, now fix up all the points */
|
||||
for (i = 1; i < num; i++)
|
||||
{
|
||||
if (!BN_is_zero(&points[i]->Z))
|
||||
{
|
||||
if (!group->meth->field_mul(group, prod_Z[i], prod_Z[i - 1], &points[i]->Z, ctx)) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!BN_copy(prod_Z[i], prod_Z[i - 1])) goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now use a single explicit inversion to replace every
|
||||
* non-zero points[i]->Z by its inverse. */
|
||||
|
||||
if (!BN_mod_inverse(tmp, prod_Z[num - 1], &group->field, ctx))
|
||||
{
|
||||
ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
if (group->meth->field_encode != 0)
|
||||
{
|
||||
/* In the Montgomery case, we just turned R*H (representing H)
|
||||
* into 1/(R*H), but we need R*(1/H) (representing 1/H);
|
||||
* i.e. we need to multiply by the Montgomery factor twice. */
|
||||
if (!group->meth->field_encode(group, tmp, tmp, ctx)) goto err;
|
||||
if (!group->meth->field_encode(group, tmp, tmp, ctx)) goto err;
|
||||
}
|
||||
|
||||
for (i = num - 1; i > 0; --i)
|
||||
{
|
||||
/* Loop invariant: tmp is the product of the inverses of
|
||||
* points[0]->Z .. points[i]->Z (zero-valued inputs skipped). */
|
||||
if (!BN_is_zero(&points[i]->Z))
|
||||
{
|
||||
/* Set tmp_Z to the inverse of points[i]->Z (as product
|
||||
* of Z inverses 0 .. i, Z values 0 .. i - 1). */
|
||||
if (!group->meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx)) goto err;
|
||||
/* Update tmp to satisfy the loop invariant for i - 1. */
|
||||
if (!group->meth->field_mul(group, tmp, tmp, &points[i]->Z, ctx)) goto err;
|
||||
/* Replace points[i]->Z by its inverse. */
|
||||
if (!BN_copy(&points[i]->Z, tmp_Z)) goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (!BN_is_zero(&points[0]->Z))
|
||||
{
|
||||
/* Replace points[0]->Z by its inverse. */
|
||||
if (!BN_copy(&points[0]->Z, tmp)) goto err;
|
||||
}
|
||||
|
||||
/* Finally, fix up the X and Y coordinates for all points. */
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
EC_POINT *p = points[i];
|
||||
|
||||
|
||||
if (!BN_is_zero(&p->Z))
|
||||
{
|
||||
/* turn (X, Y, 1/Z) into (X/Z^2, Y/Z^3, 1) */
|
||||
|
||||
if (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;
|
||||
if (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;
|
||||
if (!group->meth->field_sqr(group, tmp, &p->Z, ctx)) goto err;
|
||||
if (!group->meth->field_mul(group, &p->X, &p->X, tmp, ctx)) goto err;
|
||||
|
||||
if (!group->meth->field_mul(group, tmp, tmp, &p->Z, ctx)) goto err;
|
||||
if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp, ctx)) goto err;
|
||||
|
||||
if (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;
|
||||
if (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;
|
||||
|
||||
if (group->meth->field_set_to_one != 0)
|
||||
{
|
||||
if (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;
|
||||
@@ -1688,20 +1667,19 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
if (new_ctx != NULL)
|
||||
BN_CTX_free(new_ctx);
|
||||
if (heap != NULL)
|
||||
if (prod_Z != NULL)
|
||||
{
|
||||
/* heap[pow2/2] .. heap[pow2-1] have not been allocated locally! */
|
||||
for (i = pow2/2 - 1; i > 0; i--)
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
if (heap[i] != NULL)
|
||||
BN_clear_free(heap[i]);
|
||||
if (prod_Z[i] == NULL) break;
|
||||
BN_clear_free(prod_Z[i]);
|
||||
}
|
||||
OPENSSL_free(heap);
|
||||
OPENSSL_free(prod_Z);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@@ -57,6 +57,7 @@
|
||||
*/
|
||||
|
||||
#include "ecs_locl.h"
|
||||
#include <string.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
@@ -84,13 +85,25 @@ int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
|
||||
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
|
||||
{
|
||||
ECDSA_SIG *s;
|
||||
const unsigned char *p = sigbuf;
|
||||
unsigned char *der = NULL;
|
||||
int derlen = -1;
|
||||
int ret=-1;
|
||||
|
||||
s = ECDSA_SIG_new();
|
||||
if (s == NULL) return(ret);
|
||||
if (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;
|
||||
if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) goto err;
|
||||
/* Ensure signature uses DER and doesn't have trailing garbage */
|
||||
derlen = i2d_ECDSA_SIG(s, &der);
|
||||
if (derlen != sig_len || memcmp(sigbuf, der, derlen))
|
||||
goto err;
|
||||
ret=ECDSA_do_verify(dgst, dgst_len, s, eckey);
|
||||
err:
|
||||
if (derlen > 0)
|
||||
{
|
||||
OPENSSL_cleanse(der, derlen);
|
||||
OPENSSL_free(der);
|
||||
}
|
||||
ECDSA_SIG_free(s);
|
||||
return(ret);
|
||||
}
|
||||
|
@@ -71,6 +71,7 @@ R SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
|
||||
R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
|
||||
R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
|
||||
R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
|
||||
R SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086
|
||||
R SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
|
||||
R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
|
||||
R SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110
|
||||
|
@@ -601,4 +601,3 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
|
||||
return in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@@ -254,7 +254,7 @@ int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
|
||||
{
|
||||
int cipher_nid, md_nid;
|
||||
if (cipher)
|
||||
cipher_nid = EVP_CIPHER_type(cipher);
|
||||
cipher_nid = EVP_CIPHER_nid(cipher);
|
||||
else
|
||||
cipher_nid = -1;
|
||||
if (md)
|
||||
|
@@ -199,10 +199,10 @@ static int cfb64_test(unsigned char *cfb_cipher)
|
||||
}
|
||||
memcpy(cfb_tmp,cfb_iv,8);
|
||||
n=0;
|
||||
idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
|
||||
idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)13,&eks,
|
||||
cfb_tmp,&n,IDEA_DECRYPT);
|
||||
idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
|
||||
(long)CFB_TEST_SIZE-17,&dks,
|
||||
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)
|
||||
{
|
||||
|
@@ -75,13 +75,13 @@ $!
|
||||
$ sdirs := , -
|
||||
'archd', -
|
||||
objects, -
|
||||
md2, md4, md5, sha, mdc2, hmac, ripemd, whrlpool, -
|
||||
des, aes, rc2, rc4, rc5, idea, bf, cast, camellia, seed, -
|
||||
md4, md5, sha, mdc2, hmac, ripemd, whrlpool, -
|
||||
des, aes, rc2, rc4, idea, bf, cast, camellia, seed, modes, -
|
||||
bn, ec, rsa, dsa, ecdsa, dh, ecdh, dso, engine, -
|
||||
buffer, bio, stack, lhash, rand, err, -
|
||||
evp, asn1, pem, x509, x509v3, conf, txt_db, pkcs7, pkcs12, comp, ocsp, -
|
||||
ui, krb5, -
|
||||
store, cms, pqueue, ts, jpake
|
||||
cms, pqueue, ts, jpake, store
|
||||
$!
|
||||
$ exheader_ := crypto.h, opensslv.h, ebcdic.h, symhacks.h, ossl_typ.h
|
||||
$ exheader_'archd' := opensslconf.h
|
||||
@@ -139,6 +139,9 @@ $ exheader_cms := cms.h
|
||||
$ exheader_pqueue := pqueue.h
|
||||
$ exheader_ts := ts.h
|
||||
$ exheader_jpake := jpake.h
|
||||
$ exheader_srp := srp.h
|
||||
$ exheader_store := store.h
|
||||
$ exheader_cmac := cmac.h
|
||||
$ libs := ssl_libcrypto
|
||||
$!
|
||||
$ exe_dir := [-.'archd'.exe.crypto]
|
||||
|
@@ -108,6 +108,7 @@ sub round4_step
|
||||
EOF
|
||||
}
|
||||
|
||||
no warnings qw(uninitialized);
|
||||
my $flavour = shift;
|
||||
my $output = shift;
|
||||
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
|
||||
@@ -119,7 +120,6 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; my $dir=$1; my $xlate;
|
||||
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
|
||||
die "can't locate x86_64-xlate.pl";
|
||||
|
||||
no warnings qw(uninitialized);
|
||||
open OUT,"| \"$^X\" $xlate $flavour $output";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
|
@@ -471,11 +471,12 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
|
||||
const unsigned char *p;
|
||||
char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
|
||||
|
||||
if ((a == NULL) || (a->data == NULL)) {
|
||||
buf[0]='\0';
|
||||
return(0);
|
||||
}
|
||||
/* Ensure that, at every state, |buf| is NUL-terminated. */
|
||||
if (buf && buf_len > 0)
|
||||
buf[0] = '\0';
|
||||
|
||||
if ((a == NULL) || (a->data == NULL))
|
||||
return(0);
|
||||
|
||||
if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef)
|
||||
{
|
||||
@@ -554,9 +555,10 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
|
||||
i=(int)(l/40);
|
||||
l-=(long)(i*40);
|
||||
}
|
||||
if (buf && (buf_len > 0))
|
||||
if (buf && (buf_len > 1))
|
||||
{
|
||||
*buf++ = i + '0';
|
||||
*buf = '\0';
|
||||
buf_len--;
|
||||
}
|
||||
n++;
|
||||
@@ -571,9 +573,10 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
|
||||
i = strlen(bndec);
|
||||
if (buf)
|
||||
{
|
||||
if (buf_len > 0)
|
||||
if (buf_len > 1)
|
||||
{
|
||||
*buf++ = '.';
|
||||
*buf = '\0';
|
||||
buf_len--;
|
||||
}
|
||||
BUF_strlcpy(buf,bndec,buf_len);
|
||||
@@ -807,4 +810,3 @@ err:
|
||||
OPENSSL_free(buf);
|
||||
return(ok);
|
||||
}
|
||||
|
||||
|
@@ -42,8 +42,6 @@ static const nid_triple sigoid_srt[] =
|
||||
|
||||
static const nid_triple * const sigoid_srt_xref[] =
|
||||
{
|
||||
&sigoid_srt[17],
|
||||
&sigoid_srt[18],
|
||||
&sigoid_srt[0],
|
||||
&sigoid_srt[1],
|
||||
&sigoid_srt[7],
|
||||
|
@@ -90,7 +90,10 @@ EOF
|
||||
|
||||
foreach (@srt2)
|
||||
{
|
||||
my $x = $xref_tbl{$_}[2];
|
||||
my ($p1, $p2, $x) = @{$xref_tbl{$_}};
|
||||
# If digest or signature algorithm is "undef" then the algorithm
|
||||
# needs special handling and is excluded from the cross reference table.
|
||||
next if $p1 eq "undef" || $p2 eq "undef";
|
||||
print "\t\&sigoid_srt\[$x\],\n";
|
||||
}
|
||||
|
||||
|
@@ -158,6 +158,8 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
|
||||
|
||||
OCSP_REQ_CTX *rctx;
|
||||
rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX));
|
||||
if (!rctx)
|
||||
return NULL;
|
||||
rctx->state = OHS_ERROR;
|
||||
rctx->mem = BIO_new(BIO_s_mem());
|
||||
rctx->io = io;
|
||||
@@ -167,18 +169,21 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
|
||||
else
|
||||
rctx->iobuflen = OCSP_MAX_LINE_LEN;
|
||||
rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
|
||||
if (!rctx->iobuf)
|
||||
return 0;
|
||||
if (!rctx->mem || !rctx->iobuf)
|
||||
goto err;
|
||||
if (!path)
|
||||
path = "/";
|
||||
|
||||
if (BIO_printf(rctx->mem, post_hdr, path) <= 0)
|
||||
return 0;
|
||||
goto err;
|
||||
|
||||
if (req && !OCSP_REQ_CTX_set1_req(rctx, req))
|
||||
return 0;
|
||||
goto err;
|
||||
|
||||
return rctx;
|
||||
err:
|
||||
OCSP_REQ_CTX_free(rctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Parse the HTTP response. This will look like this:
|
||||
@@ -490,6 +495,9 @@ OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
|
||||
|
||||
ctx = OCSP_sendreq_new(b, path, req, -1);
|
||||
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
||||
do
|
||||
{
|
||||
rv = OCSP_sendreq_nbio(&resp, ctx);
|
||||
|
@@ -221,8 +221,19 @@ int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pss
|
||||
|
||||
if (!*ppath) goto mem_err;
|
||||
|
||||
p = host;
|
||||
if(host[0] == '[')
|
||||
{
|
||||
/* ipv6 literal */
|
||||
host++;
|
||||
p = strchr(host, ']');
|
||||
if(!p) goto parse_err;
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Look for optional ':' for port number */
|
||||
if ((p = strchr(host, ':')))
|
||||
if ((p = strchr(p, ':')))
|
||||
{
|
||||
*p = 0;
|
||||
port = p + 1;
|
||||
|
@@ -25,11 +25,11 @@
|
||||
* (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
|
||||
* major minor fix final patch/beta)
|
||||
*/
|
||||
#define OPENSSL_VERSION_NUMBER 0x100000dfL
|
||||
#define OPENSSL_VERSION_NUMBER 0x1000011fL
|
||||
#ifdef OPENSSL_FIPS
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.0m-fips 5 Jun 2014"
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.0q-fips 15 Jan 2015"
|
||||
#else
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.0m 5 Jun 2014"
|
||||
#define OPENSSL_VERSION_TEXT "OpenSSL 1.0.0q 15 Jan 2015"
|
||||
#endif
|
||||
#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
|
||||
|
||||
|
@@ -755,6 +755,11 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
|
||||
/* Copy BLOBHEADER across, decrypt rest */
|
||||
memcpy(enctmp, p, 8);
|
||||
p += 8;
|
||||
if (keylen < 8)
|
||||
{
|
||||
PEMerr(PEM_F_DO_PVK_BODY, PEM_R_PVK_TOO_SHORT);
|
||||
return NULL;
|
||||
}
|
||||
inlen = keylen - 8;
|
||||
q = enctmp + 8;
|
||||
EVP_CIPHER_CTX_init(&cctx);
|
||||
|
@@ -39,20 +39,6 @@ test:
|
||||
|
||||
all: lib
|
||||
|
||||
testapps: enc dec sign verify
|
||||
|
||||
enc: enc.o lib
|
||||
$(CC) $(CFLAGS) -o enc enc.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
|
||||
|
||||
dec: dec.o lib
|
||||
$(CC) $(CFLAGS) -o dec dec.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
|
||||
|
||||
sign: sign.o lib
|
||||
$(CC) $(CFLAGS) -o sign sign.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
|
||||
|
||||
verify: verify.o example.o lib
|
||||
$(CC) $(CFLAGS) -o verify verify.o $(PEX_LIBS) example.o $(LIB) $(EX_LIBS)
|
||||
|
||||
lib: $(LIBOBJ)
|
||||
$(AR) $(LIB) $(LIBOBJ)
|
||||
$(RANLIB) $(LIB) || echo Never mind.
|
||||
|
@@ -1,466 +0,0 @@
|
||||
/* crypto/evp/bio_ber.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
static int ber_write(BIO *h,char *buf,int num);
|
||||
static int ber_read(BIO *h,char *buf,int size);
|
||||
/*static int ber_puts(BIO *h,char *str); */
|
||||
/*static int ber_gets(BIO *h,char *str,int size); */
|
||||
static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
|
||||
static int ber_new(BIO *h);
|
||||
static int ber_free(BIO *data);
|
||||
static long ber_callback_ctrl(BIO *h,int cmd,void *(*fp)());
|
||||
#define BER_BUF_SIZE (32)
|
||||
|
||||
/* This is used to hold the state of the BER objects being read. */
|
||||
typedef struct ber_struct
|
||||
{
|
||||
int tag;
|
||||
int class;
|
||||
long length;
|
||||
int inf;
|
||||
int num_left;
|
||||
int depth;
|
||||
} BER_CTX;
|
||||
|
||||
typedef struct bio_ber_struct
|
||||
{
|
||||
int tag;
|
||||
int class;
|
||||
long length;
|
||||
int inf;
|
||||
|
||||
/* most of the following are used when doing non-blocking IO */
|
||||
/* reading */
|
||||
long num_left; /* number of bytes still to read/write in block */
|
||||
int depth; /* used with indefinite encoding. */
|
||||
int finished; /* No more read data */
|
||||
|
||||
/* writting */
|
||||
char *w_addr;
|
||||
int w_offset;
|
||||
int w_left;
|
||||
|
||||
int buf_len;
|
||||
int buf_off;
|
||||
unsigned char buf[BER_BUF_SIZE];
|
||||
} BIO_BER_CTX;
|
||||
|
||||
static BIO_METHOD methods_ber=
|
||||
{
|
||||
BIO_TYPE_CIPHER,"cipher",
|
||||
ber_write,
|
||||
ber_read,
|
||||
NULL, /* ber_puts, */
|
||||
NULL, /* ber_gets, */
|
||||
ber_ctrl,
|
||||
ber_new,
|
||||
ber_free,
|
||||
ber_callback_ctrl,
|
||||
};
|
||||
|
||||
BIO_METHOD *BIO_f_ber(void)
|
||||
{
|
||||
return(&methods_ber);
|
||||
}
|
||||
|
||||
static int ber_new(BIO *bi)
|
||||
{
|
||||
BIO_BER_CTX *ctx;
|
||||
|
||||
ctx=(BIO_BER_CTX *)OPENSSL_malloc(sizeof(BIO_BER_CTX));
|
||||
if (ctx == NULL) return(0);
|
||||
|
||||
memset((char *)ctx,0,sizeof(BIO_BER_CTX));
|
||||
|
||||
bi->init=0;
|
||||
bi->ptr=(char *)ctx;
|
||||
bi->flags=0;
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int ber_free(BIO *a)
|
||||
{
|
||||
BIO_BER_CTX *b;
|
||||
|
||||
if (a == NULL) return(0);
|
||||
b=(BIO_BER_CTX *)a->ptr;
|
||||
OPENSSL_cleanse(a->ptr,sizeof(BIO_BER_CTX));
|
||||
OPENSSL_free(a->ptr);
|
||||
a->ptr=NULL;
|
||||
a->init=0;
|
||||
a->flags=0;
|
||||
return(1);
|
||||
}
|
||||
|
||||
int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx)
|
||||
{
|
||||
char buf[64];
|
||||
int i,j,n;
|
||||
int ret;
|
||||
unsigned char *p;
|
||||
unsigned long length
|
||||
int tag;
|
||||
int class;
|
||||
long max;
|
||||
|
||||
BIO_clear_retry_flags(b);
|
||||
|
||||
/* Pack the buffer down if there is a hole at the front */
|
||||
if (ctx->buf_off != 0)
|
||||
{
|
||||
p=ctx->buf;
|
||||
j=ctx->buf_off;
|
||||
n=ctx->buf_len-j;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
p[0]=p[j];
|
||||
p++;
|
||||
}
|
||||
ctx->buf_len-j;
|
||||
ctx->buf_off=0;
|
||||
}
|
||||
|
||||
/* If there is more room, read some more data */
|
||||
i=BER_BUF_SIZE-ctx->buf_len;
|
||||
if (i)
|
||||
{
|
||||
i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i);
|
||||
if (i <= 0)
|
||||
{
|
||||
BIO_copy_next_retry(b);
|
||||
return(i);
|
||||
}
|
||||
else
|
||||
ctx->buf_len+=i;
|
||||
}
|
||||
|
||||
max=ctx->buf_len;
|
||||
p=ctx->buf;
|
||||
ret=ASN1_get_object(&p,&length,&tag,&class,max);
|
||||
|
||||
if (ret & 0x80)
|
||||
{
|
||||
if ((ctx->buf_len < BER_BUF_SIZE) &&
|
||||
(ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG))
|
||||
{
|
||||
ERR_clear_error(); /* clear the error */
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* We have no error, we have a header, so make use of it */
|
||||
|
||||
if ((ctx->tag >= 0) && (ctx->tag != tag))
|
||||
{
|
||||
BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH);
|
||||
sprintf(buf,"tag=%d, got %d",ctx->tag,tag);
|
||||
ERR_add_error_data(1,buf);
|
||||
return(-1);
|
||||
}
|
||||
if (ret & 0x01)
|
||||
if (ret & V_ASN1_CONSTRUCTED)
|
||||
}
|
||||
|
||||
static int ber_read(BIO *b, char *out, int outl)
|
||||
{
|
||||
int ret=0,i,n;
|
||||
BIO_BER_CTX *ctx;
|
||||
|
||||
BIO_clear_retry_flags(b);
|
||||
|
||||
if (out == NULL) return(0);
|
||||
ctx=(BIO_BER_CTX *)b->ptr;
|
||||
|
||||
if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
|
||||
|
||||
if (ctx->finished) return(0);
|
||||
|
||||
again:
|
||||
/* First see if we are half way through reading a block */
|
||||
if (ctx->num_left > 0)
|
||||
{
|
||||
if (ctx->num_left < outl)
|
||||
n=ctx->num_left;
|
||||
else
|
||||
n=outl;
|
||||
i=BIO_read(b->next_bio,out,n);
|
||||
if (i <= 0)
|
||||
{
|
||||
BIO_copy_next_retry(b);
|
||||
return(i);
|
||||
}
|
||||
ctx->num_left-=i;
|
||||
outl-=i;
|
||||
ret+=i;
|
||||
if (ctx->num_left <= 0)
|
||||
{
|
||||
ctx->depth--;
|
||||
if (ctx->depth <= 0)
|
||||
ctx->finished=1;
|
||||
}
|
||||
if (outl <= 0)
|
||||
return(ret);
|
||||
else
|
||||
goto again;
|
||||
}
|
||||
else /* we need to read another BER header */
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static int ber_write(BIO *b, char *in, int inl)
|
||||
{
|
||||
int ret=0,n,i;
|
||||
BIO_ENC_CTX *ctx;
|
||||
|
||||
ctx=(BIO_ENC_CTX *)b->ptr;
|
||||
ret=inl;
|
||||
|
||||
BIO_clear_retry_flags(b);
|
||||
n=ctx->buf_len-ctx->buf_off;
|
||||
while (n > 0)
|
||||
{
|
||||
i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
|
||||
if (i <= 0)
|
||||
{
|
||||
BIO_copy_next_retry(b);
|
||||
return(i);
|
||||
}
|
||||
ctx->buf_off+=i;
|
||||
n-=i;
|
||||
}
|
||||
/* at this point all pending data has been written */
|
||||
|
||||
if ((in == NULL) || (inl <= 0)) return(0);
|
||||
|
||||
ctx->buf_off=0;
|
||||
while (inl > 0)
|
||||
{
|
||||
n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
|
||||
EVP_CipherUpdate(&(ctx->cipher),
|
||||
(unsigned char *)ctx->buf,&ctx->buf_len,
|
||||
(unsigned char *)in,n);
|
||||
inl-=n;
|
||||
in+=n;
|
||||
|
||||
ctx->buf_off=0;
|
||||
n=ctx->buf_len;
|
||||
while (n > 0)
|
||||
{
|
||||
i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
|
||||
if (i <= 0)
|
||||
{
|
||||
BIO_copy_next_retry(b);
|
||||
return(i);
|
||||
}
|
||||
n-=i;
|
||||
ctx->buf_off+=i;
|
||||
}
|
||||
ctx->buf_len=0;
|
||||
ctx->buf_off=0;
|
||||
}
|
||||
BIO_copy_next_retry(b);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
|
||||
{
|
||||
BIO *dbio;
|
||||
BIO_ENC_CTX *ctx,*dctx;
|
||||
long ret=1;
|
||||
int i;
|
||||
|
||||
ctx=(BIO_ENC_CTX *)b->ptr;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case BIO_CTRL_RESET:
|
||||
ctx->ok=1;
|
||||
ctx->finished=0;
|
||||
EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
|
||||
ctx->cipher.berrypt);
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
case BIO_CTRL_EOF: /* More to read */
|
||||
if (ctx->cont <= 0)
|
||||
ret=1;
|
||||
else
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
case BIO_CTRL_WPENDING:
|
||||
ret=ctx->buf_len-ctx->buf_off;
|
||||
if (ret <= 0)
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
case BIO_CTRL_PENDING: /* More to read in buffer */
|
||||
ret=ctx->buf_len-ctx->buf_off;
|
||||
if (ret <= 0)
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
case BIO_CTRL_FLUSH:
|
||||
/* do a final write */
|
||||
again:
|
||||
while (ctx->buf_len != ctx->buf_off)
|
||||
{
|
||||
i=ber_write(b,NULL,0);
|
||||
if (i < 0)
|
||||
{
|
||||
ret=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx->finished)
|
||||
{
|
||||
ctx->finished=1;
|
||||
ctx->buf_off=0;
|
||||
ret=EVP_CipherFinal_ex(&(ctx->cipher),
|
||||
(unsigned char *)ctx->buf,
|
||||
&(ctx->buf_len));
|
||||
ctx->ok=(int)ret;
|
||||
if (ret <= 0) break;
|
||||
|
||||
/* push out the bytes */
|
||||
goto again;
|
||||
}
|
||||
|
||||
/* Finally flush the underlying BIO */
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
case BIO_C_GET_CIPHER_STATUS:
|
||||
ret=(long)ctx->ok;
|
||||
break;
|
||||
case BIO_C_DO_STATE_MACHINE:
|
||||
BIO_clear_retry_flags(b);
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
BIO_copy_next_retry(b);
|
||||
break;
|
||||
|
||||
case BIO_CTRL_DUP:
|
||||
dbio=(BIO *)ptr;
|
||||
dctx=(BIO_ENC_CTX *)dbio->ptr;
|
||||
memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
|
||||
dbio->init=1;
|
||||
break;
|
||||
default:
|
||||
ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
|
||||
break;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static long ber_callback_ctrl(BIO *b, int cmd, void *(*fp)())
|
||||
{
|
||||
long ret=1;
|
||||
|
||||
if (b->next_bio == NULL) return(0);
|
||||
switch (cmd)
|
||||
{
|
||||
default:
|
||||
ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
|
||||
break;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
void BIO_set_cipher_ctx(b,c)
|
||||
BIO *b;
|
||||
EVP_CIPHER_ctx *c;
|
||||
{
|
||||
if (b == NULL) return;
|
||||
|
||||
if ((b->callback != NULL) &&
|
||||
(b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
|
||||
return;
|
||||
|
||||
b->init=1;
|
||||
ctx=(BIO_ENC_CTX *)b->ptr;
|
||||
memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
|
||||
|
||||
if (b->callback != NULL)
|
||||
b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
|
||||
}
|
||||
*/
|
||||
|
||||
void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
|
||||
int e)
|
||||
{
|
||||
BIO_ENC_CTX *ctx;
|
||||
|
||||
if (b == NULL) return;
|
||||
|
||||
if ((b->callback != NULL) &&
|
||||
(b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
|
||||
return;
|
||||
|
||||
b->init=1;
|
||||
ctx=(BIO_ENC_CTX *)b->ptr;
|
||||
EVP_CipherInit_ex(&(ctx->cipher),c,NULL,k,i,e);
|
||||
|
||||
if (b->callback != NULL)
|
||||
b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
|
||||
}
|
||||
|
@@ -1,248 +0,0 @@
|
||||
/* crypto/pkcs7/verify.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/asn1.h>
|
||||
|
||||
int verify_callback(int ok, X509_STORE_CTX *ctx);
|
||||
|
||||
BIO *bio_err=NULL;
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
char *keyfile=NULL;
|
||||
BIO *in;
|
||||
EVP_PKEY *pkey;
|
||||
X509 *x509;
|
||||
PKCS7 *p7;
|
||||
PKCS7_SIGNER_INFO *si;
|
||||
X509_STORE_CTX cert_ctx;
|
||||
X509_STORE *cert_store=NULL;
|
||||
BIO *data,*detached=NULL,*p7bio=NULL;
|
||||
char buf[1024*4];
|
||||
unsigned char *pp;
|
||||
int i,printit=0;
|
||||
STACK_OF(PKCS7_SIGNER_INFO) *sk;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
|
||||
|
||||
data=BIO_new(BIO_s_file());
|
||||
pp=NULL;
|
||||
while (argc > 1)
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
if (strcmp(argv[0],"-p") == 0)
|
||||
{
|
||||
printit=1;
|
||||
}
|
||||
else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) {
|
||||
keyfile = argv[1];
|
||||
argc-=1;
|
||||
argv+=1;
|
||||
} else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
|
||||
{
|
||||
detached=BIO_new(BIO_s_file());
|
||||
if (!BIO_read_filename(detached,argv[1]))
|
||||
goto err;
|
||||
argc-=1;
|
||||
argv+=1;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
if (!BIO_read_filename(data,argv[0])) goto err;
|
||||
|
||||
if(!keyfile) {
|
||||
fprintf(stderr, "No private key file specified\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
|
||||
if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
|
||||
BIO_reset(in);
|
||||
if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL)
|
||||
goto err;
|
||||
BIO_free(in);
|
||||
|
||||
if (pp == NULL)
|
||||
BIO_set_fp(data,stdin,BIO_NOCLOSE);
|
||||
|
||||
|
||||
/* Load the PKCS7 object from a file */
|
||||
if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err;
|
||||
|
||||
|
||||
|
||||
/* This stuff is being setup for certificate verification.
|
||||
* When using SSL, it could be replaced with a
|
||||
* cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
|
||||
cert_store=X509_STORE_new();
|
||||
X509_STORE_set_default_paths(cert_store);
|
||||
X509_STORE_load_locations(cert_store,NULL,"../../certs");
|
||||
X509_STORE_set_verify_cb_func(cert_store,verify_callback);
|
||||
|
||||
ERR_clear_error();
|
||||
|
||||
/* We need to process the data */
|
||||
/* We cannot support detached encryption */
|
||||
p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
|
||||
|
||||
if (p7bio == NULL)
|
||||
{
|
||||
printf("problems decoding\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* We now have to 'read' from p7bio to calculate digests etc. */
|
||||
for (;;)
|
||||
{
|
||||
i=BIO_read(p7bio,buf,sizeof(buf));
|
||||
/* print it? */
|
||||
if (i <= 0) break;
|
||||
fwrite(buf,1, i, stdout);
|
||||
}
|
||||
|
||||
/* We can now verify signatures */
|
||||
sk=PKCS7_get_signer_info(p7);
|
||||
if (sk == NULL)
|
||||
{
|
||||
fprintf(stderr, "there are no signatures on this data\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ok, first we need to, for each subject entry,
|
||||
* see if we can verify */
|
||||
ERR_clear_error();
|
||||
for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
|
||||
{
|
||||
si=sk_PKCS7_SIGNER_INFO_value(sk,i);
|
||||
i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
|
||||
if (i <= 0)
|
||||
goto err;
|
||||
else
|
||||
fprintf(stderr,"Signature verified\n");
|
||||
}
|
||||
}
|
||||
X509_STORE_free(cert_store);
|
||||
|
||||
exit(0);
|
||||
err:
|
||||
ERR_load_crypto_strings();
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* should be X509 * but we can just have them as char *. */
|
||||
int verify_callback(int ok, X509_STORE_CTX *ctx)
|
||||
{
|
||||
char buf[256];
|
||||
X509 *err_cert;
|
||||
int err,depth;
|
||||
|
||||
err_cert=X509_STORE_CTX_get_current_cert(ctx);
|
||||
err= X509_STORE_CTX_get_error(ctx);
|
||||
depth= X509_STORE_CTX_get_error_depth(ctx);
|
||||
|
||||
X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
|
||||
BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
|
||||
if (!ok)
|
||||
{
|
||||
BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
|
||||
X509_verify_cert_error_string(err));
|
||||
if (depth < 6)
|
||||
{
|
||||
ok=1;
|
||||
X509_STORE_CTX_set_error(ctx,X509_V_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
ok=0;
|
||||
X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
|
||||
}
|
||||
}
|
||||
switch (ctx->error)
|
||||
{
|
||||
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
|
||||
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
|
||||
BIO_printf(bio_err,"issuer= %s\n",buf);
|
||||
break;
|
||||
case X509_V_ERR_CERT_NOT_YET_VALID:
|
||||
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
|
||||
BIO_printf(bio_err,"notBefore=");
|
||||
ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
|
||||
BIO_printf(bio_err,"\n");
|
||||
break;
|
||||
case X509_V_ERR_CERT_HAS_EXPIRED:
|
||||
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
|
||||
BIO_printf(bio_err,"notAfter=");
|
||||
ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
|
||||
BIO_printf(bio_err,"\n");
|
||||
break;
|
||||
}
|
||||
BIO_printf(bio_err,"verify return:%d\n",ok);
|
||||
return(ok);
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
|
||||
MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
|
||||
A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
|
||||
dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
|
||||
ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
|
||||
/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
|
||||
AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
|
||||
QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
|
||||
UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
|
||||
CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
|
||||
WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
|
||||
oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
|
||||
lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
|
||||
5PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
|
||||
|
@@ -1,24 +0,0 @@
|
||||
int PKCS7_set_content_type(PKCS7 *p7, int type);
|
||||
Call to set the type of PKCS7 object we are working on
|
||||
|
||||
int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
|
||||
EVP_MD *dgst);
|
||||
Use this to setup a signer info
|
||||
There will also be functions to add signed and unsigned attributes.
|
||||
|
||||
int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
|
||||
Add a signer info to the content.
|
||||
|
||||
int PKCS7_add_certificae(PKCS7 *p7, X509 *x509);
|
||||
int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
|
||||
|
||||
----
|
||||
|
||||
p7=PKCS7_new();
|
||||
PKCS7_set_content_type(p7,NID_pkcs7_signed);
|
||||
|
||||
signer=PKCS7_SINGNER_INFO_new();
|
||||
PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5());
|
||||
PKCS7_add_signer(py,signer);
|
||||
|
||||
we are now setup.
|
@@ -1,174 +0,0 @@
|
||||
/* crypto/pkcs7/enc.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
X509 *x509;
|
||||
PKCS7 *p7;
|
||||
BIO *in;
|
||||
BIO *data,*p7bio;
|
||||
char buf[1024*4];
|
||||
int i;
|
||||
int nodetach=1;
|
||||
char *keyfile = NULL;
|
||||
const EVP_CIPHER *cipher=NULL;
|
||||
STACK_OF(X509) *recips=NULL;
|
||||
|
||||
OpenSSL_add_all_algorithms();
|
||||
|
||||
data=BIO_new(BIO_s_file());
|
||||
while(argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1],"-nd") == 0)
|
||||
{
|
||||
nodetach=1;
|
||||
argv++; argc--;
|
||||
}
|
||||
else if ((strcmp(argv[1],"-c") == 0) && (argc >= 2)) {
|
||||
if(!(cipher = EVP_get_cipherbyname(argv[2]))) {
|
||||
fprintf(stderr, "Unknown cipher %s\n", argv[2]);
|
||||
goto err;
|
||||
}
|
||||
argc-=2;
|
||||
argv+=2;
|
||||
} else if ((strcmp(argv[1],"-k") == 0) && (argc >= 2)) {
|
||||
keyfile = argv[2];
|
||||
argc-=2;
|
||||
argv+=2;
|
||||
if (!(in=BIO_new_file(keyfile,"r"))) goto err;
|
||||
if (!(x509=PEM_read_bio_X509(in,NULL,NULL,NULL)))
|
||||
goto err;
|
||||
if(!recips) recips = sk_X509_new_null();
|
||||
sk_X509_push(recips, x509);
|
||||
BIO_free(in);
|
||||
} else break;
|
||||
}
|
||||
|
||||
if(!recips) {
|
||||
fprintf(stderr, "No recipients\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!BIO_read_filename(data,argv[1])) goto err;
|
||||
|
||||
p7=PKCS7_new();
|
||||
#if 0
|
||||
BIO_reset(in);
|
||||
if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
|
||||
BIO_free(in);
|
||||
PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped);
|
||||
|
||||
if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
|
||||
/* we may want to add more */
|
||||
PKCS7_add_certificate(p7,x509);
|
||||
#else
|
||||
PKCS7_set_type(p7,NID_pkcs7_enveloped);
|
||||
#endif
|
||||
if(!cipher) {
|
||||
#ifndef OPENSSL_NO_DES
|
||||
cipher = EVP_des_ede3_cbc();
|
||||
#else
|
||||
fprintf(stderr, "No cipher selected\n");
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!PKCS7_set_cipher(p7,cipher)) goto err;
|
||||
for(i = 0; i < sk_X509_num(recips); i++) {
|
||||
if (!PKCS7_add_recipient(p7,sk_X509_value(recips, i))) goto err;
|
||||
}
|
||||
sk_X509_pop_free(recips, X509_free);
|
||||
|
||||
/* Set the content of the signed to 'data' */
|
||||
/* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */
|
||||
|
||||
/* could be used, but not in this version :-)
|
||||
if (!nodetach) PKCS7_set_detached(p7,1);
|
||||
*/
|
||||
|
||||
if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
i=BIO_read(data,buf,sizeof(buf));
|
||||
if (i <= 0) break;
|
||||
BIO_write(p7bio,buf,i);
|
||||
}
|
||||
BIO_flush(p7bio);
|
||||
|
||||
if (!PKCS7_dataFinal(p7,p7bio)) goto err;
|
||||
BIO_free(p7bio);
|
||||
|
||||
PEM_write_PKCS7(stdout,p7);
|
||||
PKCS7_free(p7);
|
||||
|
||||
exit(0);
|
||||
err:
|
||||
ERR_load_crypto_strings();
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
@@ -1,66 +0,0 @@
|
||||
-----BEGIN PKCS7-----
|
||||
MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
|
||||
A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
|
||||
dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
|
||||
ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqGSIb3DQEBAQUABEDWak0y/5XZJhQJeCLo
|
||||
KECcHXkTEbjzYkYNHIinbiPmRK4QbNfs9z2mA3z/c2ykQ4eAqFR2jyNrUMN/+I5XEiv6MIHw
|
||||
AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
|
||||
QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
|
||||
UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
|
||||
CSqGSIb3DQEBAQUABEAWg9+KgtCjc77Jdj1Ve4wGgHjVHbbSYEA1ZqKFDoi15vSr9hfpHmC4
|
||||
ycZzcRo16JkTfolefiHZzmyjVz94vSN6MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
|
||||
oAQI7X4Tk4mcbV6ggASBsHl1mCaJ3RhXWlNPCgCRU53d7M5x6TDZRkvwdtdvW96m1lupT03F
|
||||
XtonkBqk7oMkH7kGfs5/REQOPjx0QE2Ixmgt1W3szum82EZwA7pZNppcraK7W/odw/7bYZO+
|
||||
II3HPmRklE2N9qiu1LPaPUsnYogkO6SennyeL5tZ382vBweL/8pnG0qsbT1OBb65v+llnsjT
|
||||
pa1T/p+fIx/iJJGE6K9fYFokC6gXLQ6ozXRdOu5oBDB8mPCYYvAqKycidM/MrGGUkpEtS4f0
|
||||
lS31PwQi5YTim8Ig3/TOwVpPX32i46FTuEIEIMHkD/OvpfwCCzXUHHJnKnKUAUvIsSY3vGBs
|
||||
8ezpUDfBBBj9LHDy32hZ2tQilkDefP5VM2LLdrWgamYEgfiyITQvn08Ul5lQOQxbFKBheFq5
|
||||
otCCN4MR+w5eq12xQu6y+f9z0159ag2ru87D0lLtUtXXtCELbO1nUkT2sJ0k/iDs9TOXr6Cx
|
||||
go1XKYho83hlkXYiCteVizdAbgVGNsNRD4wtIdajsorET/LuJECgp11YeL9w1dlDB0HLEZfi
|
||||
XCsUphH4jGagba3hDeUSibnjSiJlN0ukfuQurBBbI2UkBAujiEAubKPn7C1FZJRSw6CPPX5t
|
||||
KEpmcqT1JNk6LO8Js6/1sCmmBh1VGCy1+EuTI9J1p7Dagf4nQ8cHitoCRpHuKZlFHnZyv7tw
|
||||
Rn/KOhHaYP2VzAh40gQIvKMAAWh9oFsEEIMwIoOmLwLH5wf+8QdbDhoECH8HwZt9a12dBAjL
|
||||
r4j2zlvtfgQIt7nmEM3wz1EECKlc3EIy1irCBBCAKINcermK3A+jI6ISN2RzBFA3dsh/xwMu
|
||||
l61aWMBBZzEz/SF92k6n35KZhCC0d6fIVC/1WMv0fnCwQ8oEDynSre216VEFiYKBaQLJe5o/
|
||||
mTAxC7Ht3goXnuc+i1FItOkLrgRI/wyvTICEn2WsNZiMADnGaee2bqPnUopo+VMGexJEtCPk
|
||||
l0ZNlDJGquPDkpUwaEtecVZzCNyVPYyyF4J/l8rmGDhDdYUIC8IKBEg/ip/E0BuubBLWVbv+
|
||||
HRl4QrnGpyCyeXRXXK603QP3sT1Zbbm1v5pI/loOhVHi724LmtXHSyp5qv9MDcxE1PoX10LY
|
||||
gBRtlwwESPeCF8bK5jk4xIQMhK5NMHj1Y1KQWTZ9NGITBL4hjRq2qp4Qk5GIpGgOVPopAuCo
|
||||
TIyPikpqBRNtLSPRSsDs6QPUPzWBh6JgxwRQblnDKKUkxUcnJiD4i9QtGa/ZabMn4KxtNOBL
|
||||
5JSh1nJkaLXCZY070131WWPAByLcd5TiXq8x84pmzV5NNk4tiMpoXhJNsx8e4rskQQlKd6ME
|
||||
SCe2eYDHKcKPX3WJbUzhrJSQ92/aWnI2iUY8WQ+kSNyiZ2QUjyuUg9Z66g/0d2STlvPOBHT/
|
||||
y5ODP2CwbcWX4QmCbUc9TT66fQRIrRVuwvtOfnUueyGgYhJ3HpAJfVaB/7kap5bj7Fi/azW4
|
||||
9JDfd1bC/W9h0Kyk7RO2gxvE0hIHc26mZJHTm9MNP5D328MnM2MdBEjKjQBtgrp+lFIii7MP
|
||||
nGHFTKUkG4WAIZJCf/CsT+p6/SW0qG71Me/YcSw5STB24j+a+HgMV8RVIeUlkP4z0IWWrSoB
|
||||
Gh4d/Z0EUMCVHs/HZ/bWgiyhtHpvuVAzidm8D81p1LJ5BQX5/5f/m+q5+fS/npL27dTEbNqs
|
||||
LSB6ij3MZAi7LwHWpTn9zWnDajCMEj9vlaV7mcKtHK5iBEg85agFi1h3MvicqLtoFe5hVv9T
|
||||
tG0j6CRkjkixPzivltlrf44KHv14gLM0XJxCGyq7vd3l8QYr3+9at0zNnX/yqTiBnsnE5dUE
|
||||
SIgrYuz87M2gi/ER9PcDoTtONH3+CkcqVy03q/Sj8cVWD/b1KgEhqnNOfc8Ak9PctyR/ItcR
|
||||
8Me5XVn1GJKkQJk4O29fxvgNoAQIrIESvUWGshAEQByXiFoFTDUByjTlgjcy77H1lrH+y3P/
|
||||
wAInJjJAut9kCNyGJV0PA4kdPB5USWltuO6t8gk4Pd2YBMl09zqUWkAEUCjFrtZ3mapjcGZI
|
||||
uQTASKR5LSjXoWxTT5gae/+64MerF/oCEeO3ehRTpjnPrsiRDo0rWIQTaj9+Nro8Z2xtWstw
|
||||
RnfoAHIxV1lEamPwjsceBEi2SD9hiifFeO5ECiVoaE1FdXUXhU+jwYAMx6jHWO9hMkYzS9pM
|
||||
Y3IyWR5ybtOjiQgkUdvRJPUPGf5DVVMPnymGX25aDh5PYpIESPbsM9akCpOOVuscywcUswmU
|
||||
o7dXvlB48WWCfg/al3BQKAZbn5ZXtWNwpUZkrEdHsrxAVv3rxRcdkT3Z1fzUbIuYkLJN200o
|
||||
WgRIJvn6RO8KEj7/HOg2sYuuM8nz1kR0TSgwX7/0y/7JfjBa0JIlP7o75sNJscE8oyoIMzuy
|
||||
Dvn6/U9g3BCDXn83A/s+ke60qn9gBFC6NAeLOlXal1YVWYhMQNOqCyUfAjiXBTawaysQb1Mk
|
||||
YgeNlF8xuEFcUQWIP+vNG7FJ5JPMaMRL4YEoaQ3sVFhYOERJR1cSb+8xt4QCYtBKQgRIUOmJ
|
||||
CHW5o1hXJWJiTkZK2qWFcEMzTINSj5EpYFySr8aVBjkRnI7vxegRT/+XZZXoYedQ3UNsnGI3
|
||||
DdkWii5VzX0PNF6C60pfBEiVpausYuX7Wjb3Lfm8cBj7GgN69i6Pm2gxtobVcmpo2nS4D714
|
||||
ePyhlX9n8kJ6QAcqWMRj22smDPrHVGNTizfzHBh5zNllK9gESJizILOWI327og3ZWp+qUht5
|
||||
kNDJCzMK7Z09UAy+h+vq0VTQuEo3FgLzVdqkJujjSL4Nx97lXg51AovrEn3nd4evydwcjKLX
|
||||
1wRIo72NaeWuUEQ+rt1SlCsOJ7k1ioJSqhrPOfvwcaFcb4beVet1JWiy4yvowTjLDGbUje2s
|
||||
xjrlVt4BJWI/uA6jbQsrxSe89ADZBAi5YAlR4qszeAQIXD3VSBVKbRUECNTtyvw9vvqXBAhb
|
||||
IZNn4H4cxgQI+XW7GkfL+ekECCCCg2reMyGDBAh1PYqkg3lw3gQQkNlggEPU+BH8eh7Gm7n7
|
||||
7AQIjC5EWbkil5cEEKcpuqwTWww/X89KnQAg8TcECJPomqHvrlZFBBiRSuIiHpmN+PaujXpv
|
||||
qZV2VhjkB2j09GEECOIdv8AVOJgKBAjlHgIqAD9jZQQIXHbs44+wogcEIGGqTACRJxrhMcMG
|
||||
X8drNjksIPt+snxTXUBIkTVpZWoABAh6unXPTyIr8QQgBF8xKoX27MWk7iTNmkSNZggZXa2a
|
||||
DWCGHSYLngbSOHIECD9XmO6VsvTgBAjfqB70CEW4WwQIVIBkbCocznUEEHB/zFXy/sR4OYHe
|
||||
UfbNPnIEEDWBB/NTCLMGE+o8BfyujcAECFik7GQnnF9VBBAhLXExQeWAofZNc6NtN7qZBCC1
|
||||
gVIS3ruTwKltmcrgx3heT3M8ZJhCfWa+6KzchnmKygQQ+1NL5sSzR4m/fdrqxHFyUAQYCT2x
|
||||
PamQr3wK3h0lyZER+4H0zPM86AhFBBC3CkmvL2vjflMfujnzPBVpBBge9rMbI5+0q9DLrTiT
|
||||
5F3AIgXLpD8PQWAECHkHVo6RomV3BAgMbi8E271UeAQIqtS8wnI3XngECG3TWmOMb3/iBEha
|
||||
y+mvCS6I3n3JfL8e1B5P4qX9/czJRaERLuKpGNjLiL4A+zxN0LZ0UHd0qfmJjwOTxAx3iJAC
|
||||
lGXX4nB9ATYPUT5EU+o1Y4sECN01pP6vWNIdBDAsiE0Ts8/9ltJlqX2B3AoOM4qOt9EaCjXf
|
||||
lB+aEmrhtjUwuZ6GqS5Ke7P6XnakTk4ECCLIMatNdootAAAAAAAAAAAAAA==
|
||||
-----END PKCS7-----
|
@@ -1,329 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/pkcs7.h>
|
||||
#include <openssl/asn1_mac.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
int add_signed_time(PKCS7_SIGNER_INFO *si)
|
||||
{
|
||||
ASN1_UTCTIME *sign_time;
|
||||
|
||||
/* The last parameter is the amount to add/subtract from the current
|
||||
* time (in seconds) */
|
||||
sign_time=X509_gmtime_adj(NULL,0);
|
||||
PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
|
||||
V_ASN1_UTCTIME,(char *)sign_time);
|
||||
return(1);
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
|
||||
so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
|
||||
if (so->type == V_ASN1_UTCTIME)
|
||||
return so->value.utctime;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int signed_string_nid= -1;
|
||||
|
||||
void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
|
||||
{
|
||||
ASN1_OCTET_STRING *os;
|
||||
|
||||
/* To a an object of OID 1.2.3.4.5, which is an octet string */
|
||||
if (signed_string_nid == -1)
|
||||
signed_string_nid=
|
||||
OBJ_create("1.2.3.4.5","OID_example","Our example OID");
|
||||
os=ASN1_OCTET_STRING_new();
|
||||
ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
|
||||
/* When we add, we do not free */
|
||||
PKCS7_add_signed_attribute(si,signed_string_nid,
|
||||
V_ASN1_OCTET_STRING,(char *)os);
|
||||
}
|
||||
|
||||
int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
ASN1_OCTET_STRING *os;
|
||||
int i;
|
||||
|
||||
if (signed_string_nid == -1)
|
||||
signed_string_nid=
|
||||
OBJ_create("1.2.3.4.5","OID_example","Our example OID");
|
||||
/* To retrieve */
|
||||
so=PKCS7_get_signed_attribute(si,signed_string_nid);
|
||||
if (so != NULL)
|
||||
{
|
||||
if (so->type == V_ASN1_OCTET_STRING)
|
||||
{
|
||||
os=so->value.octet_string;
|
||||
i=os->length;
|
||||
if ((i+1) > len)
|
||||
i=len-1;
|
||||
memcpy(buf,os->data,i);
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int signed_seq2string_nid= -1;
|
||||
/* ########################################### */
|
||||
int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
|
||||
{
|
||||
/* To add an object of OID 1.9.999, which is a sequence containing
|
||||
* 2 octet strings */
|
||||
unsigned char *p;
|
||||
ASN1_OCTET_STRING *os1,*os2;
|
||||
ASN1_STRING *seq;
|
||||
unsigned char *data;
|
||||
int i,total;
|
||||
|
||||
if (signed_seq2string_nid == -1)
|
||||
signed_seq2string_nid=
|
||||
OBJ_create("1.9.9999","OID_example","Our example OID");
|
||||
|
||||
os1=ASN1_OCTET_STRING_new();
|
||||
os2=ASN1_OCTET_STRING_new();
|
||||
ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
|
||||
ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
|
||||
i =i2d_ASN1_OCTET_STRING(os1,NULL);
|
||||
i+=i2d_ASN1_OCTET_STRING(os2,NULL);
|
||||
total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
|
||||
|
||||
data=malloc(total);
|
||||
p=data;
|
||||
ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
|
||||
i2d_ASN1_OCTET_STRING(os1,&p);
|
||||
i2d_ASN1_OCTET_STRING(os2,&p);
|
||||
|
||||
seq=ASN1_STRING_new();
|
||||
ASN1_STRING_set(seq,data,total);
|
||||
free(data);
|
||||
ASN1_OCTET_STRING_free(os1);
|
||||
ASN1_OCTET_STRING_free(os2);
|
||||
|
||||
PKCS7_add_signed_attribute(si,signed_seq2string_nid,
|
||||
V_ASN1_SEQUENCE,(char *)seq);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* For this case, I will malloc the return strings */
|
||||
int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
|
||||
if (signed_seq2string_nid == -1)
|
||||
signed_seq2string_nid=
|
||||
OBJ_create("1.9.9999","OID_example","Our example OID");
|
||||
/* To retrieve */
|
||||
so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
|
||||
if (so && (so->type == V_ASN1_SEQUENCE))
|
||||
{
|
||||
ASN1_const_CTX c;
|
||||
ASN1_STRING *s;
|
||||
long length;
|
||||
ASN1_OCTET_STRING *os1,*os2;
|
||||
|
||||
s=so->value.sequence;
|
||||
c.p=ASN1_STRING_data(s);
|
||||
c.max=c.p+ASN1_STRING_length(s);
|
||||
if (!asn1_GetSequence(&c,&length)) goto err;
|
||||
/* Length is the length of the seqence */
|
||||
|
||||
c.q=c.p;
|
||||
if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
|
||||
goto err;
|
||||
c.slen-=(c.p-c.q);
|
||||
|
||||
c.q=c.p;
|
||||
if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
|
||||
goto err;
|
||||
c.slen-=(c.p-c.q);
|
||||
|
||||
if (!asn1_const_Finish(&c)) goto err;
|
||||
*str1=malloc(os1->length+1);
|
||||
*str2=malloc(os2->length+1);
|
||||
memcpy(*str1,os1->data,os1->length);
|
||||
memcpy(*str2,os2->data,os2->length);
|
||||
(*str1)[os1->length]='\0';
|
||||
(*str2)[os2->length]='\0';
|
||||
ASN1_OCTET_STRING_free(os1);
|
||||
ASN1_OCTET_STRING_free(os2);
|
||||
return(1);
|
||||
}
|
||||
err:
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* #######################################
|
||||
* THE OTHER WAY TO DO THINGS
|
||||
* #######################################
|
||||
*/
|
||||
X509_ATTRIBUTE *create_time(void)
|
||||
{
|
||||
ASN1_UTCTIME *sign_time;
|
||||
X509_ATTRIBUTE *ret;
|
||||
|
||||
/* The last parameter is the amount to add/subtract from the current
|
||||
* time (in seconds) */
|
||||
sign_time=X509_gmtime_adj(NULL,0);
|
||||
ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
|
||||
V_ASN1_UTCTIME,(char *)sign_time);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
PKCS7_SIGNER_INFO si;
|
||||
|
||||
si.auth_attr=sk;
|
||||
so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
|
||||
if (so->type == V_ASN1_UTCTIME)
|
||||
return so->value.utctime;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *create_string(char *str)
|
||||
{
|
||||
ASN1_OCTET_STRING *os;
|
||||
X509_ATTRIBUTE *ret;
|
||||
|
||||
/* To a an object of OID 1.2.3.4.5, which is an octet string */
|
||||
if (signed_string_nid == -1)
|
||||
signed_string_nid=
|
||||
OBJ_create("1.2.3.4.5","OID_example","Our example OID");
|
||||
os=ASN1_OCTET_STRING_new();
|
||||
ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
|
||||
/* When we add, we do not free */
|
||||
ret=X509_ATTRIBUTE_create(signed_string_nid,
|
||||
V_ASN1_OCTET_STRING,(char *)os);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
ASN1_OCTET_STRING *os;
|
||||
int i;
|
||||
PKCS7_SIGNER_INFO si;
|
||||
|
||||
si.auth_attr=sk;
|
||||
|
||||
if (signed_string_nid == -1)
|
||||
signed_string_nid=
|
||||
OBJ_create("1.2.3.4.5","OID_example","Our example OID");
|
||||
/* To retrieve */
|
||||
so=PKCS7_get_signed_attribute(&si,signed_string_nid);
|
||||
if (so != NULL)
|
||||
{
|
||||
if (so->type == V_ASN1_OCTET_STRING)
|
||||
{
|
||||
os=so->value.octet_string;
|
||||
i=os->length;
|
||||
if ((i+1) > len)
|
||||
i=len-1;
|
||||
memcpy(buf,os->data,i);
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
|
||||
{
|
||||
/* To add an object of OID 1.9.999, which is a sequence containing
|
||||
* 2 octet strings */
|
||||
unsigned char *p;
|
||||
ASN1_OCTET_STRING *os1,*os2;
|
||||
ASN1_STRING *seq;
|
||||
X509_ATTRIBUTE *ret;
|
||||
unsigned char *data;
|
||||
int i,total;
|
||||
|
||||
if (signed_seq2string_nid == -1)
|
||||
signed_seq2string_nid=
|
||||
OBJ_create("1.9.9999","OID_example","Our example OID");
|
||||
|
||||
os1=ASN1_OCTET_STRING_new();
|
||||
os2=ASN1_OCTET_STRING_new();
|
||||
ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
|
||||
ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
|
||||
i =i2d_ASN1_OCTET_STRING(os1,NULL);
|
||||
i+=i2d_ASN1_OCTET_STRING(os2,NULL);
|
||||
total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
|
||||
|
||||
data=malloc(total);
|
||||
p=data;
|
||||
ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
|
||||
i2d_ASN1_OCTET_STRING(os1,&p);
|
||||
i2d_ASN1_OCTET_STRING(os2,&p);
|
||||
|
||||
seq=ASN1_STRING_new();
|
||||
ASN1_STRING_set(seq,data,total);
|
||||
free(data);
|
||||
ASN1_OCTET_STRING_free(os1);
|
||||
ASN1_OCTET_STRING_free(os2);
|
||||
|
||||
ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
|
||||
V_ASN1_SEQUENCE,(char *)seq);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/* For this case, I will malloc the return strings */
|
||||
int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
|
||||
{
|
||||
ASN1_TYPE *so;
|
||||
PKCS7_SIGNER_INFO si;
|
||||
|
||||
if (signed_seq2string_nid == -1)
|
||||
signed_seq2string_nid=
|
||||
OBJ_create("1.9.9999","OID_example","Our example OID");
|
||||
|
||||
si.auth_attr=sk;
|
||||
/* To retrieve */
|
||||
so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
|
||||
if (so->type == V_ASN1_SEQUENCE)
|
||||
{
|
||||
ASN1_const_CTX c;
|
||||
ASN1_STRING *s;
|
||||
long length;
|
||||
ASN1_OCTET_STRING *os1,*os2;
|
||||
|
||||
s=so->value.sequence;
|
||||
c.p=ASN1_STRING_data(s);
|
||||
c.max=c.p+ASN1_STRING_length(s);
|
||||
if (!asn1_GetSequence(&c,&length)) goto err;
|
||||
/* Length is the length of the seqence */
|
||||
|
||||
c.q=c.p;
|
||||
if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
|
||||
goto err;
|
||||
c.slen-=(c.p-c.q);
|
||||
|
||||
c.q=c.p;
|
||||
if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
|
||||
goto err;
|
||||
c.slen-=(c.p-c.q);
|
||||
|
||||
if (!asn1_const_Finish(&c)) goto err;
|
||||
*str1=malloc(os1->length+1);
|
||||
*str2=malloc(os2->length+1);
|
||||
memcpy(*str1,os1->data,os1->length);
|
||||
memcpy(*str2,os2->data,os2->length);
|
||||
(*str1)[os1->length]='\0';
|
||||
(*str2)[os2->length]='\0';
|
||||
ASN1_OCTET_STRING_free(os1);
|
||||
ASN1_OCTET_STRING_free(os2);
|
||||
return(1);
|
||||
}
|
||||
err:
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@@ -1,57 +0,0 @@
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
||||
*
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@openssl.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
int add_signed_time(PKCS7_SIGNER_INFO *si);
|
||||
ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si);
|
||||
int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2);
|
@@ -1,57 +0,0 @@
|
||||
issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
|
||||
subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
|
||||
serial :047D
|
||||
|
||||
Certificate:
|
||||
Data:
|
||||
Version: 3 (0x2)
|
||||
Serial Number: 1149 (0x47d)
|
||||
Signature Algorithm: md5withRSAEncryption
|
||||
Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
|
||||
Validity
|
||||
Not Before: May 13 05:40:58 1998 GMT
|
||||
Not After : May 12 05:40:58 2000 GMT
|
||||
Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
|
||||
Subject Public Key Info:
|
||||
Public Key Algorithm: rsaEncryption
|
||||
Modulus:
|
||||
00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
|
||||
73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
|
||||
89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
|
||||
fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
|
||||
e7:e7:0c:4d:0b
|
||||
Exponent: 65537 (0x10001)
|
||||
X509v3 extensions:
|
||||
Netscape Comment:
|
||||
Generated with SSLeay
|
||||
Signature Algorithm: md5withRSAEncryption
|
||||
52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
|
||||
f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
|
||||
d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
|
||||
50:74:ad:92:cb:4e:90:e5:fa:7d
|
||||
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
|
||||
MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
|
||||
ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
|
||||
IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
|
||||
NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
|
||||
UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
|
||||
dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
|
||||
aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
|
||||
9w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
|
||||
lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
|
||||
hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
|
||||
UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
|
||||
4A3ZItobUHStkstOkOX6fQ==
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
|
||||
mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
|
||||
fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
|
||||
zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
|
||||
p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
|
||||
bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
|
||||
IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
|
||||
-----END RSA PRIVATE KEY-----
|
@@ -1,9 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
|
||||
mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
|
||||
fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
|
||||
zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
|
||||
p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
|
||||
bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
|
||||
IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
|
||||
-----END RSA PRIVATE KEY-----
|
@@ -1,2 +0,0 @@
|
||||
j,H>_<15><>_<>D<EFBFBD>zE<>L<EFBFBD> VJ<56><4A>觬<10><><1D>E3<45><33>Y<08>x%_<>k
|
||||
3<EFBFBD>)DLSc<53>8%<0C>M
|
@@ -1 +0,0 @@
|
||||
k~@a<>,N<>M<> <O( KP<4B>騠<EFBFBD>K<EFBFBD>><3E><>U<>o_<6F>Bqrm<72>?٠t?t<><74>ρ<EFBFBD>Id2<><32>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -233,10 +233,6 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
|
||||
(OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
|
||||
#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
|
||||
#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
|
||||
#define PKCS7_type_is_encrypted(a) \
|
||||
(OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
|
||||
|
||||
#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
|
||||
|
||||
#define PKCS7_set_detached(p,v) \
|
||||
PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
|
||||
|
@@ -1,24 +0,0 @@
|
||||
issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
|
||||
subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
|
||||
BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
|
||||
VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
|
||||
MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
|
||||
A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
|
||||
cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
|
||||
Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
|
||||
Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
|
||||
mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
|
||||
xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
|
||||
irObpESxAZLySCmPPg==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
|
||||
TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
|
||||
OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
|
||||
gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
|
||||
rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
|
||||
PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
|
||||
vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
|
||||
-----END RSA PRIVATE KEY-----
|
@@ -1,154 +0,0 @@
|
||||
/* crypto/pkcs7/sign.c */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
X509 *x509;
|
||||
EVP_PKEY *pkey;
|
||||
PKCS7 *p7;
|
||||
PKCS7_SIGNER_INFO *si;
|
||||
BIO *in;
|
||||
BIO *data,*p7bio;
|
||||
char buf[1024*4];
|
||||
int i;
|
||||
int nodetach=0;
|
||||
|
||||
#ifndef OPENSSL_NO_MD2
|
||||
EVP_add_digest(EVP_md2());
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_MD5
|
||||
EVP_add_digest(EVP_md5());
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_SHA1
|
||||
EVP_add_digest(EVP_sha1());
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_MDC2
|
||||
EVP_add_digest(EVP_mdc2());
|
||||
#endif
|
||||
|
||||
data=BIO_new(BIO_s_file());
|
||||
again:
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1],"-nd") == 0)
|
||||
{
|
||||
nodetach=1;
|
||||
argv++; argc--;
|
||||
goto again;
|
||||
}
|
||||
if (!BIO_read_filename(data,argv[1]))
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
BIO_set_fp(data,stdin,BIO_NOCLOSE);
|
||||
|
||||
if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
|
||||
if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
|
||||
BIO_reset(in);
|
||||
if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
|
||||
BIO_free(in);
|
||||
|
||||
p7=PKCS7_new();
|
||||
PKCS7_set_type(p7,NID_pkcs7_signed);
|
||||
|
||||
si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1());
|
||||
if (si == NULL) goto err;
|
||||
|
||||
/* If you do this then you get signing time automatically added */
|
||||
PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
|
||||
OBJ_nid2obj(NID_pkcs7_data));
|
||||
|
||||
/* we may want to add more */
|
||||
PKCS7_add_certificate(p7,x509);
|
||||
|
||||
/* Set the content of the signed to 'data' */
|
||||
PKCS7_content_new(p7,NID_pkcs7_data);
|
||||
|
||||
if (!nodetach)
|
||||
PKCS7_set_detached(p7,1);
|
||||
|
||||
if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
i=BIO_read(data,buf,sizeof(buf));
|
||||
if (i <= 0) break;
|
||||
BIO_write(p7bio,buf,i);
|
||||
}
|
||||
|
||||
if (!PKCS7_dataFinal(p7,p7bio)) goto err;
|
||||
BIO_free(p7bio);
|
||||
|
||||
PEM_write_PKCS7(stdout,p7);
|
||||
PKCS7_free(p7);
|
||||
|
||||
exit(0);
|
||||
err:
|
||||
ERR_load_crypto_strings();
|
||||
ERR_print_errors_fp(stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
@@ -1,16 +0,0 @@
|
||||
-----BEGIN PKCS7-----
|
||||
MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
|
||||
A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
|
||||
dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
|
||||
ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
|
||||
/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
|
||||
AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
|
||||
QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
|
||||
UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
|
||||
CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
|
||||
WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
|
||||
oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
|
||||
lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
|
||||
5PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
|
||||
-----END PKCS7-----
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user