Compare commits

...

623 Commits

Author SHA1 Message Date
Richard Levitte
782ded56e5 Update STATUS 2002-11-19 09:34:38 +00:00
Richard Levitte
8e458d52b5 Time to release 0.9.7-beta4.
The tag will be OpenSSL_0_9_7-beta4
2002-11-19 09:34:29 +00:00
Richard Levitte
1f475c1f6f make update 2002-11-19 08:55:06 +00:00
Richard Levitte
bc9867e672 Add news items for 0.9.6h and expand on the 0.9.7 news as well. 2002-11-18 23:58:33 +00:00
Richard Levitte
412fd4708d Determine HZ exactly as in apps/speed.c. 2002-11-18 23:06:46 +00:00
Richard Levitte
273c624442 Make sure sysconf exists (it doesn't in the VMS C RTL lesser than version 7). 2002-11-18 23:05:50 +00:00
Bodo Möller
8b591c2f8e fix memory leak in memory debuggin code ...
Submitted by: Nils Larsch
2002-11-18 14:01:24 +00:00
Bodo Möller
8f4a23e3b7 allocate bio_err before memory debugging is enabled to avoid memory leaks
(we can't release it before the CRYPTO_mem_leaks() call!)

Submitted by: Nils Larsch
2002-11-18 13:38:30 +00:00
Richard Levitte
c83d8e2ba6 A variable of type time_t is supposed to be a time measurement starting at
Epoch.  offset isn't such a measurement, so let's stop pretend it is.
2002-11-18 13:04:29 +00:00
Lutz Jänicke
6afc70be84 Better workaround to the "=head1 NAME OPTIONS" pod2latex problem:
NAME OPTIONS are a subset of OPTIONS, so just make it =head2!
Submitted by:
Reviewed by:
PR: 333
2002-11-18 08:14:20 +00:00
Richard Levitte
f503c2c9e6 Make it possible to build for more than one CPU.
Clarify what the CE tests do.
2002-11-17 19:48:34 +00:00
Richard Levitte
7656893d51 Ignore openssl.pc. This way, there's no risk that I'll add it again :-). 2002-11-17 08:07:12 +00:00
Richard Levitte
ff38d68237 Adding openssl.pc to the repository was a mistake,
since it's generated.
2002-11-17 08:05:43 +00:00
Richard Levitte
aff3e60754 Add the file openssl.pc that I forgot a while ago. 2002-11-17 07:47:25 +00:00
Richard Levitte
8196d87371 I forgot this is compiled in test/, not crypto/ec/... 2002-11-16 10:10:49 +00:00
Richard Levitte
61b1ad197a We don't want TARGETCPU expanded here. 2002-11-16 09:42:17 +00:00
Richard Levitte
293bb4b1b8 Mention ActiveState Perl much earlier in INSTALL.WCE. 2002-11-15 22:54:26 +00:00
Richard Levitte
29ca164513 WinCE patches 2002-11-15 22:44:08 +00:00
cvs2svn
97d58eadbf This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-11-15 22:37:19 +00:00
Lutz Jänicke
8cdeec9f54 Fix buggy #! magic and update ssleay->openssl
Submitted by:
Reviewed by:
PR: 305
2002-11-15 21:26:02 +00:00
Richard Levitte
082cd4e564 Changes to make shared library building and use work better with Cygwin 2002-11-15 16:49:34 +00:00
Richard Levitte
2115a89212 Document the change to remove the 'done' flag variable in the
OpenSSL_add_all_*() routines
2002-11-15 14:01:15 +00:00
Richard Levitte
af3ec1e24e make update 2002-11-15 11:22:25 +00:00
Richard Levitte
f275683ae8 A few more Microsoft OIDs added 2002-11-15 11:18:22 +00:00
Lutz Jänicke
da91e37d37 The pointer to the cipher object is not yet set, when session was reloaded
from external cache (using d2i_SSL_SESSION). Perform comparison based on
the cipher's id instead.
Submitted by: Steve Haslam <araqnid@innocent.com>
Reviewed by:
PR: 288
2002-11-15 10:51:40 +00:00
Richard Levitte
2758c44398 The architecture name is i486, not just 486 2002-11-15 10:28:55 +00:00
Richard Levitte
4e056a2894 -Wid-clash-n isn't support in gcc 3, and I get better result from continuously
rebuilding on a VMS box.
2002-11-15 10:19:47 +00:00
Richard Levitte
f60b017da8 I know ANSI C doesn't like 'long long', and I don't want to see it 2002-11-15 10:16:07 +00:00
Richard Levitte
08634f1156 Spell prototypes correctly :-) 2002-11-15 09:56:41 +00:00
Richard Levitte
a50d6a801f Add -Wstrict-prototype and -Wmissing-prototype to my debugging targets 2002-11-15 09:54:06 +00:00
Richard Levitte
0439a5a8a7 We need to read one more byte of the REQUEST-CERTIFICATE message.
PR: 300
2002-11-15 09:17:45 +00:00
Richard Levitte
8ffe66b4ce make update 2002-11-14 23:54:12 +00:00
Richard Levitte
d62ec8362a Close the implicitely opened registry key.
PR: 264
2002-11-14 23:34:07 +00:00
Lutz Jänicke
259b33d5a3 No such reference to link to (found running pod2latex).
Submitted by:
Reviewed by:
PR:
2002-11-14 21:40:12 +00:00
Dr. Stephen Henson
6393c09cda Fix documentation of i2d_X509_fp and i2d_X509_bio. 2002-11-14 18:12:45 +00:00
Richard Levitte
9421f1ab9c Add Tandem OSS target.
PR: 192
2002-11-14 16:30:44 +00:00
Richard Levitte
5bf0d0ea1e Remove warnings. 2002-11-14 15:58:01 +00:00
Richard Levitte
769f74b818 It seems like gcc 2.9aix5.1 doesn't do will with optimization level 3.
PR: 115
2002-11-14 14:08:21 +00:00
Richard Levitte
64051a3a71 Add a FAQ on how to check the authenticity of the openSSL distribution.
PR: 292
2002-11-14 13:01:35 +00:00
Richard Levitte
8260eded07 Cygwin fixes 2002-11-14 12:39:56 +00:00
Bodo Möller
402b4a784d use same entry as in more recent CHANGES revision in CVS head 2002-11-14 12:11:44 +00:00
Bodo Möller
651e7ddf7e fix order again 2002-11-14 12:08:16 +00:00
Richard Levitte
40bace2da6 Fix to build better with DJGPP.
PR: 338

Here's the description, submitted by Gisle Vanem <giva@bgnett.no>:

1. sock_init() renamed to ssl_sock_init() in ./apps/s_socket.c due
   to name-clash with Watt-32.

2. rand() renamed to Rand() in ./crypto/bn/divtest.c due to name-clash
   with <stdlib.h>

3. Added calls to dbug_init()/sock_init() in some demo programs.

4. Changed cflags/lflags in configure. Watt-32 install root now taken
   from $WATT_ROOT.
2002-11-14 11:22:46 +00:00
Lutz Jänicke
e89c82f549 Don't declare 2 WARNINGS sections
Submitted by:
Reviewed by:
PR:
2002-11-14 11:12:14 +00:00
Lutz Jänicke
812d100d06 Opportunistic change to work around pod2latex bug: rename NAME OPTIONS
section to SUBJECT AND ISSUER NAME OPTIONS
Submitted by:
Reviewed by:
PR: 333
2002-11-14 11:08:23 +00:00
Lutz Jänicke
b759742352 Correct reference to section name.
Submitted by:
Reviewed by:
PR:
2002-11-14 11:02:25 +00:00
Lutz Jänicke
475e4d23bd Missing =back
Submitted by:
Reviewed by:
PR:
2002-11-14 10:49:42 +00:00
Richard Levitte
bf4ae6dcfa The directory 'rijndael' doesn't exist any more, let's check the aes
directory instead (this should have been done long ago...).
2002-11-14 08:23:37 +00:00
Richard Levitte
17d4f07658 When AES is skipped because the option 'no-rijndael' was given,
make sure it's skipped from SDIRS as well.
2002-11-14 08:20:50 +00:00
Richard Levitte
5ec797f263 Make the Windows test scripts consistent in their echoing 2002-11-14 08:09:07 +00:00
Richard Levitte
5b1aea7afe Handle last lines that aren't properly terminated.
PR: 308
2002-11-14 06:50:32 +00:00
Dr. Stephen Henson
327e113775 Fix get_email: 0 is a valid return value 2002-11-14 00:45:04 +00:00
Richard Levitte
58f3009aba Constification needed.
PR: 241
2002-11-13 23:47:52 +00:00
Richard Levitte
b193f29a9b free() -> OPENSSL_free() 2002-11-13 20:25:56 +00:00
Richard Levitte
7ab58bf012 Correct support for SunOS 4.1.3_U1.
PR: 227
2002-11-13 15:49:51 +00:00
Richard Levitte
cd10ba9c39 When build as dynamic engines, the loading functions should be defined
static.
2002-11-13 15:29:01 +00:00
Richard Levitte
96a3369c4a Make internal functions static. 2002-11-13 14:31:55 +00:00
Richard Levitte
e8ad570e3f Changes from HEAD. 2002-11-13 14:31:01 +00:00
Richard Levitte
ad1ddf413c The loading functions should be static if we build a dynamic engine. 2002-11-13 14:30:34 +00:00
Bodo Möller
e2c2152be9 disable weird assert()s 2002-11-13 14:01:19 +00:00
Bodo Möller
919b2a9673 remove unused old directory crypto/rijndael (superseded by crypto/aes) 2002-11-13 13:55:24 +00:00
Richard Levitte
024a20905d C++ comments in C code, 'nuff said... 2002-11-13 13:36:29 +00:00
Richard Levitte
69ba8a00ad make update 2002-11-13 11:35:51 +00:00
Richard Levitte
f6a0c4f853 Make OpenSSLdie() visible (it's a must to get a proper reference in
libeay.num).
2002-11-13 11:35:12 +00:00
Dr. Stephen Henson
040ade9bee As main trun 2002-11-13 01:22:40 +00:00
Bodo Möller
46ce790727 fix order of changes -- if B depends on A, A should be listed
after B (reversed 'chronological' order)
2002-11-12 13:35:27 +00:00
Ben Laurie
9831d941ca Many security improvements (CHATS) and a warning fix. 2002-11-12 13:23:40 +00:00
Richard Levitte
707ceb29e0 Make it possible to run individual tests even when linked with libcrypto.so and libssl.so 2002-11-12 11:25:33 +00:00
Richard Levitte
3d470fc7b7 Make the CBC mode od AES accept lengths that aren't multiples of 16.
PR: 330
2002-11-12 11:00:35 +00:00
Richard Levitte
edb7b28a00 Variables on the stack must be initialized or we can't depend on any
initial value.  For errline/errorline, we did depend on that, erroneously
2002-11-11 21:35:00 +00:00
Richard Levitte
c4efde7403 make update 2002-11-11 20:51:06 +00:00
Richard Levitte
a1edc87664 Make the programs link against the static library on MacOS X.
PR: 335
2002-11-11 20:49:01 +00:00
Lutz Jänicke
9cbc3356e7 Typo.
Submitted by: assar <assar@kth.se>
Reviewed by:
PR:
2002-11-11 11:18:19 +00:00
Lutz Jänicke
9161c2ff51 Make sure permissions are friendly when building release tar file.
Submitted by:
Reviewed by:
PR: 171
2002-11-11 08:56:37 +00:00
Lutz Jänicke
21f8cf65e6 More information to the important issue of seeding the PRNG
Submitted by:
Reviewed by:
PR: 285
2002-11-11 08:32:37 +00:00
Richard Levitte
8bcc049399 X509_NAME_cmp() now compares PrintableString and emailAddress with a value of type
ia5String correctly.
PR: 244
2002-11-09 21:55:12 +00:00
Richard Levitte
95900b8592 -CAserial does take a filename argument.
PR: 332
2002-11-09 21:53:56 +00:00
Dr. Stephen Henson
20a50cb517 Typo 2002-11-09 18:11:15 +00:00
Richard Levitte
a71a482250 -CAcreateserial doesn't take a filename argument.
PR: 332
2002-11-08 21:51:33 +00:00
Richard Levitte
8b6ee018c2 Windows doesn't know sys/file.h 2002-11-07 21:40:17 +00:00
Dr. Stephen Henson
ddab3c9327 Typo in OCSP ASN1 module 2002-11-07 17:43:45 +00:00
Richard Levitte
6a9a7ff259 Keep on using ${CC}, since gcc may act in disguise.
PR: 329
2002-11-06 23:47:16 +00:00
Richard Levitte
f7cd5462c9 Generate openssl.pc so pkg-config can return proper data.
PR: 163
2002-11-06 23:34:17 +00:00
Richard Levitte
d268511c84 some people just can't read the instructions 2002-11-06 06:03:07 +00:00
Dr. Stephen Henson
190467767e CRL revocation reason docs. 2002-11-06 01:27:16 +00:00
Dr. Stephen Henson
8d699c8c93 Check for NULL ASN1_ITEM when initializeing
boolean option in ASN1_TYPE.
2002-11-05 13:49:04 +00:00
Bodo Möller
e2a93e38d6 avoid Purify warnings
Submitted by: Nils Larsch
2002-11-05 12:28:10 +00:00
Richard Levitte
41c2fb962c Return my normal debug targets to something not so extreme, and make
the extreme ones special (or 'extreme', if you will :-)).
2002-11-04 16:33:59 +00:00
Richard Levitte
455bacd4d3 Off-by-one-error corrected.
PR: 235
2002-11-04 11:30:38 +00:00
Richard Levitte
e85cbdad7a Cosmetic change 2002-11-04 06:26:27 +00:00
Richard Levitte
c752563e43 Remove all referenses to RSAref, since that's been gone for more than
a year.
2002-10-31 16:46:18 +00:00
Richard Levitte
0eae6cd5f2 Plug potential memory leak.
Identified by Goetz Babin-Ebell <babinebell@trustcenter.de>
2002-10-30 09:42:47 +00:00
Geoff Thorpe
0bf707e346 Add a HISTORY section to the man page to mention the new flags. 2002-10-29 18:06:09 +00:00
Geoff Thorpe
96a2c35d91 The recent CHANGES note between 0.9.6g and 0.9.6h needs copying into the
other branches.
2002-10-29 17:59:18 +00:00
Geoff Thorpe
f9fde13590 Correct another inconsistency in my recent commits. 2002-10-29 17:47:43 +00:00
Geoff Thorpe
74174b9d05 Bodo spotted this keyslip in my patch to 0.9.7-stable. 2002-10-29 17:00:33 +00:00
Richard Levitte
89eda1fc01 Revert, that was an incorrect change.
PR: 156
2002-10-29 04:34:13 +00:00
Richard Levitte
bbec79a0c1 A small detail: since 0.9.7, DH_new_method() and DSA_new_method()
don't take an ENGINE* as parameter any more.
PR: 156
2002-10-29 04:31:13 +00:00
Geoff Thorpe
6f7ba4be1f Correct and enhance the behaviour of "internal" session caching as it
relates to SSL_CTX flags and the use of "external" session caching. The
existing flag, "SSL_SESS_CACHE_NO_INTERNAL_LOOKUP" remains but is
supplemented with a complimentary flag, "SSL_SESS_CACHE_NO_INTERNAL_STORE".
The bitwise OR of the two flags is also defined as
"SSL_SESS_CACHE_NO_INTERNAL" and is the flag that should be used by most
applications wanting to implement session caching *entirely* by its own
provided callbacks. As the documented behaviour contradicted actual
behaviour up until recently, and since that point behaviour has itself been
inconsistent anyway, this change should not introduce any compatibility
problems. I've adjusted the relevant documentation to elaborate about how
this works.

Kudos to "Nadav Har'El" <nyh@math.technion.ac.il> for diagnosing these
anomalies and testing this patch for correctness.

PR: 311
2002-10-29 00:31:14 +00:00
Bodo Möller
2ccb522c5b increase permissible message length so that we can handle
CertificateVerify for 4096 bit RSA signatures
2002-10-28 15:47:44 +00:00
Richard Levitte
0bf76767b0 Make sure toupper() is declared 2002-10-25 09:51:50 +00:00
Richard Levitte
732c9fe179 There's a name clash between OpenSSL and RSAref. Since this engine handles
RSAref data, pretend we don't care for OpenSSL's MD2 and MD5 structures or
implementation.
Remove all kinds of silly warning
2002-10-24 17:02:42 +00:00
Richard Levitte
4f99ab58f7 On certain platforms, we redefine certain symbols using macros in
apps.h.  For those, it's better to include apps.h after the system
headers where those symbols may be defined, since there's otherwise a
chance that the C compiler will barf when it sees something that looks
like this after expansion:

int VMS_strcasecmp((str1),(str2))(const char *, const char *);
2002-10-24 09:41:45 +00:00
Richard Levitte
339abc9bd9 An engine changed name. 2002-10-23 22:09:08 +00:00
Richard Levitte
4407fbc2d4 Signal an error if the entered output password didn't match itself.
PR: 314
2002-10-23 15:07:18 +00:00
Bodo Möller
27f08d6d48 fix warnings, and harmonize indentation 2002-10-23 13:14:10 +00:00
Bodo Möller
a9e0953900 I don't like c-tab-always-indent ... 2002-10-23 13:09:11 +00:00
Dr. Stephen Henson
9597027693 Typo. 2002-10-21 00:10:55 +00:00
Dr. Stephen Henson
78f41a4e89 Update docs. 2002-10-20 13:25:34 +00:00
cvs2svn
76dcae8020 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-10-20 13:20:58 +00:00
Geoff Thorpe
190ef122b2 Make pod2man happier. 2002-10-18 22:05:19 +00:00
Lutz Jänicke
dc74e7d5d7 Corrected exchanged parameters in example for EVP_EncryptInit_ex()
Submitted by: "Marcus Carey" <marcus.carey@verizon.net>
Reviewed by:
PR: 265
2002-10-18 09:46:01 +00:00
Bodo Möller
3d76ceddff change Emacs indentation style to make it easier to insert
tabs manually

Submitted by: Pierre Bacquet <pbacquet@delta.fr>
2002-10-17 09:17:28 +00:00
Geoff Thorpe
b963f807be - Remo Inverardi noticed that ENGINEs don't have an "up_ref" function in the
normal 'structural' case (ENGINE_init() satisfies this in the less normal
'functional' case). This change provides such a function.

- Correct some "read" locks that should actually be "write" locks.

- make update.
2002-10-16 01:32:46 +00:00
Richard Levitte
005bbb52ff Typos.
PR: 189
2002-10-15 20:31:07 +00:00
Richard Levitte
a690102da2 Typos.
PR: 189
2002-10-15 20:29:27 +00:00
Richard Levitte
09db11783d When BN_add_word() reaches top, it shouldn't try to add the the corresponding
word, since that word may not be zero.
2002-10-14 11:27:16 +00:00
Richard Levitte
f6733ae577 makedepend complains when a header file is included more than once in
the same source file.
2002-10-14 09:53:46 +00:00
Richard Levitte
2d2ca3aab1 Complete the VxWorks fix by implementing a NULL RAND_poll() for it.
PR: 253
2002-10-14 09:44:51 +00:00
Richard Levitte
cfc7620572 make update 2002-10-14 09:40:46 +00:00
Richard Levitte
9a01bc0732 Add more commentary. Check that *num is smaller than the block size. 2002-10-11 22:42:40 +00:00
Richard Levitte
dbcc560717 The AES CTR API was buggy, we need to save the encrypted counter as well
between calls, or that will be lost if it returned with *num non-zero.
2002-10-11 22:37:44 +00:00
Richard Levitte
449d39f41c Merge string protection from main trunk 2002-10-11 20:35:45 +00:00
Bodo Möller
84236041c1 synchronize with 0.9.6-stable version of this file 2002-10-11 17:53:21 +00:00
Bodo Möller
8d44d96ec3 remove redundant empty line 2002-10-11 17:29:07 +00:00
Richard Levitte
707e098687 Add a configuration target for A/UX.
PR: 271
2002-10-11 14:39:12 +00:00
Richard Levitte
88de74ad83 make update 2002-10-11 12:23:49 +00:00
Richard Levitte
97b8718f15 There may be more than one single quote to fix.
PR: 256
2002-10-11 11:34:28 +00:00
Richard Levitte
388a6f937f Make sure $fname will not give us any surprises with any funny characters.
PR: 256
2002-10-11 11:07:39 +00:00
Richard Levitte
a61050ad96 BN_bn2hex() returns "0" instead of "00" for zero. This disrputs the
requirement that the serial number always be an even amount of characters.
PR: 248
2002-10-11 09:39:32 +00:00
Richard Levitte
baaeac3036 Rhapsody had ftime, Darwin doesn't (any longer?) 2002-10-10 13:36:04 +00:00
Richard Levitte
d19370b617 VMS below version 7 doesn't have strcasecmp, so let's roll our own on VMS.
PR: 184
2002-10-10 09:05:46 +00:00
Richard Levitte
8376acbf7f Typo 2002-10-10 08:32:45 +00:00
Richard Levitte
12a2ff9625 RFC 2712 redefines the codes for use of Kerberos 5 in SSL/TLS.
PR: 189
2002-10-10 07:59:45 +00:00
Dr. Stephen Henson
292a217b51 More docs. 2002-10-09 17:18:58 +00:00
Dr. Stephen Henson
104117c5e7 New documentation from main trunk. 2002-10-09 17:14:41 +00:00
cvs2svn
7ab3c662e3 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-10-09 17:05:06 +00:00
Richard Levitte
4fd5e85a18 Make sure that the 'config' variable is correctly defined and declared
for monolithic as well as non-monolithic biuld.
More work is probably needed in this area.
PR: 144
2002-10-09 15:36:42 +00:00
Richard Levitte
e9a9211e75 Remove redundancy and use the main makefile better 2002-10-09 15:13:34 +00:00
Richard Levitte
d438845ac8 Don't fuss with the demo binaries 2002-10-09 13:58:03 +00:00
cvs2svn
b1d495b2c4 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-10-09 13:57:58 +00:00
Richard Levitte
6b7a46b721 Add a few more VxWorks targets.
Correct misspelled VXWORKS macros.
Add VXWORKS identifying macros to e_os2.h.
Add required inclusions and mappings for VxWorks in e_os.h.
A few small modifications to make OpenSSL build and work on VxWorks.
PR: 253, except for the  change that was handled in an earlier
         commit, and a request for easy build of just parts of OpenSSL.
2002-10-09 13:41:31 +00:00
Richard Levitte
ff90d659e6 Use double dashes so makedepend doesn't misunderstand the flags we
give it.
For 0.9.7 and up, that means util/domd needs to remove those double
dashes from the argument list when gcc is used to find the
dependencies.
2002-10-09 13:21:33 +00:00
Richard Levitte
8f841c70c4 The dissapearing destroy callback reappears 2002-10-09 12:19:13 +00:00
Richard Levitte
052c0f276e Add missing LF 2002-10-09 06:36:30 +00:00
Richard Levitte
1e7e392419 Since crypt() isn't defined anywhere, define it locally in destest.c 2002-10-06 00:41:17 +00:00
Richard Levitte
e11b82c337 Do not define crypt(). The supported function is DES_crypt() (an des_crypt()
when backward compatibility is desired).
2002-10-06 00:23:32 +00:00
Dr. Stephen Henson
04ad43af9e Win32 fix (signed/unsigned compare error). 2002-10-05 11:59:51 +00:00
Richard Levitte
227aec9a0f Installed libraries should not be overwritten, especially shared ones.
Use mv to make sure the old copy is unlinked instead of overwritten.
PR: 273, and probably others...
2002-10-04 13:44:00 +00:00
Richard Levitte
b0165ce439 Add random number generation capability to the cswift engine.
Should this be added to 0.9.6-stable as well?
PR: 275
2002-10-04 13:31:06 +00:00
Richard Levitte
3c8756f024 If we're loading libz dynamically, and COMP_zlib() is called more than once,
only the first call would provide the correct result.
PR: 277
2002-10-04 13:04:44 +00:00
Richard Levitte
1801bc0658 Add a small note saying the 'debug' option should come before the platform in
the arguments to mk1mf.pl.
PR: 298
2002-10-04 12:32:38 +00:00
Richard Levitte
ebbad107bf Document should match reality :-).
PR: 255
2002-10-04 00:03:37 +00:00
Richard Levitte
fc0ab2eac2 The OpenBSD project has replaced the first implementation of the /dev/crypto
engine with something they claim is better.  I have nothing to compare to,
and I assume they know what they're talking about.  The interesting part with
this one is that it's loaded by default on OpenBSD systems.
This change was originally introduced in OpenBSD's tracking of OpenSSL.
2002-10-02 00:18:59 +00:00
Bodo Möller
64cb996206 fix more race conditions
Submitted by: "Patrick McCormick" <patrick@tellme.com>
PR: 262
2002-09-26 15:54:15 +00:00
Lutz Jänicke
413f2b2247 Add missing brackets.
Submitted by: "Chris Brook" <cbrook@v-one.com>
Reviewed by:
PR:
2002-09-25 20:17:58 +00:00
Bodo Möller
fbf4c7b4f1 really fix race conditions
Submitted by: "Patrick McCormick" <patrick@tellme.com>

PR: 262
PR: 291
2002-09-25 15:38:17 +00:00
Richard Levitte
99542d8763 Make sure that the signal storage is regarded as volatile.
This correction was originally introduced in OpenBSD's tracking of OpenSSL.
2002-09-25 14:14:16 +00:00
Richard Levitte
b3c1d18d03 It makes more sense to refer to specific function manuals than the concept
manual when the specific function is refered to in the current manual text.
This correction was originally introduced in OpenBSD's tracking of OpenSSL.
2002-09-25 13:34:37 +00:00
Richard Levitte
6c8aec60ca Remove *all* references to RSA_PKCS1_RSAref, since it doesn't exist any more.
This correction was originally introduced in OpenBSD's tracking of OpenSSL.
2002-09-25 13:26:40 +00:00
Richard Levitte
c0ca52952e Remove reference to RSA_PKCS1_RSAref, since it doesn't exist any more.
This correction was originally introduced in OpenBSD's tracking of OpenSSL.
2002-09-25 13:25:48 +00:00
Richard Levitte
39d727d0c3 It makes more sense to refer to specific function manuals than the concept
manual when the specific function is refered to in the current manual text.
This correction was originally introduced in OpenBSD's tracking of OpenSSL.
2002-09-25 13:11:16 +00:00
Richard Levitte
6319853811 Incorrect argument order to memset() 2002-09-25 12:52:23 +00:00
Richard Levitte
6b3a385f85 Missing ; 2002-09-25 12:49:45 +00:00
Richard Levitte
27a80b7906 -elapsed is also useful when using gettimeofday 2002-09-25 12:42:04 +00:00
Bodo Möller
4e33db9a3f really fix race condition
PR: 262
2002-09-23 14:28:12 +00:00
Ulf Möller
ca9a114f7a as in head 2002-09-22 08:51:33 +00:00
Ulf Möller
ce1dc2e9b2 as in main 2002-09-22 08:45:22 +00:00
cvs2svn
b4b62004a6 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-09-22 08:44:06 +00:00
Bodo Möller
f7eb95852c there is no minimum length for session IDs
PR: 274

fix race condition
PR: 262
2002-09-20 08:37:13 +00:00
Dr. Stephen Henson
12a296edfc Really fix PKCS7_set_detached this time... 2002-09-08 16:25:55 +00:00
Dr. Stephen Henson
e696a05791 Fix typos in PKCS#12 ASN1 code.
Make PKCS7_set_detached work again.
2002-09-07 22:59:34 +00:00
Lutz Jänicke
4a13e4b36c Consequently use term URI instead of URL
Submitted by: TJ Saunders <tj@castaglia.org>
Reviewed by:
PR: 268
2002-09-05 07:51:23 +00:00
Dr. Stephen Henson
b7fb041f31 make update 2002-09-03 00:09:45 +00:00
Dr. Stephen Henson
a98beb3a2d Apply -nameopt patches to 0.9.7 2002-08-30 18:26:26 +00:00
Dr. Stephen Henson
f627c159b1 Fix ASN1_STRING_to_UTF8: remove non sensical !*out test. 2002-08-30 17:17:45 +00:00
Bodo Möller
535cedf136 don't memset(data,0,...) if data is NULL
Submitted by: anonymous
PR: 254
2002-08-29 11:35:42 +00:00
Geoff Thorpe
3a00964dd3 Fix a bug to allow the 4758 ENGINE to build as a DSO. 2002-08-28 19:11:59 +00:00
Dr. Stephen Henson
a69d50b02d Reinstate the check for invalid length BIT STRINGS,
which was effectively bypassed in the ASN1 changed.
2002-08-23 00:00:54 +00:00
Dr. Stephen Henson
ed7443661c Fix C++ style comments. 2002-08-22 23:00:05 +00:00
Dr. Stephen Henson
3d2aa62cb6 Fix crahses and leaks in pkcs12 utility -chain option 2002-08-22 21:54:24 +00:00
Richard Levitte
9925249ba5 Typo, I assigned the variable ld instead of my_ld... 2002-08-18 21:33:02 +00:00
Richard Levitte
d7041ea5de So, I discovered that if you have your $PATH set so a ld different from
GNU ld comes first, checking the usage of collect2 gives that instead of
GNU ld, even if GNU ld would be the one that would get used if we link using
gcc.  It's much better, apparently, to ask gcc directly what the path to
GNU ld is (provided it's there at all and gcc knows about it), and ask
the result if it's a GNU or not.  The bonus is that our GNU ld detection
mechanism got shorter and easier to understand...
2002-08-17 13:46:52 +00:00
Lutz Jänicke
68a9ee13e8 Reorder cleanup sequence in SSL_CTX_free() to leave ex_data for remove_cb().
Submitted by:
Reviewed by:
PR: 212
2002-08-16 17:02:30 +00:00
Lutz Jänicke
a64f08f3dd Fix wrong URI.
Submitted by: Mike Castle <dalgoda@ix.netcom.com>
Reviewed by:
PR: 200
2002-08-16 16:44:54 +00:00
Richard Levitte
384897f46b isalist was less trustable than I thought (or rather, one can trust it to
come up with all kinds of names we don't have in our targets).
Besides, our sparcv9 targets currently generate sparcv8 code, I'm told.
2002-08-16 09:41:35 +00:00
Richard Levitte
08e60fc0ff Add -lz to the ld flags when the user has chosen to link in zlib *statically*.
Notified by Doug Kaufman <dkaufman@rahul.net>
2002-08-16 06:15:58 +00:00
Dr. Stephen Henson
ea050a6eb3 Fix block_size field for CFB and OFB modes: it should be 1. 2002-08-16 01:38:34 +00:00
Richard Levitte
bde63f803a q may be used uninitialised 2002-08-15 22:06:14 +00:00
Bodo Möller
e73308638a use correct function code in error message 2002-08-15 16:17:02 +00:00
Richard Levitte
1ac3419ef6 It seems like sun4u doesn't always have a sparcv9 inside. Trust isalist.
PR: 220
2002-08-15 15:21:00 +00:00
Bodo Möller
1e9858a28b fix warnings (CHARSET_EBCDIC)
Submitted by: Lorinczy Zsigmond <lzsiga@mail.ahiv.hu>
2002-08-15 14:52:22 +00:00
Bodo Möller
8f4a09e531 fix manpage 2002-08-15 14:22:49 +00:00
Richard Levitte
3b2f77d88e I think that's the last forgotten compilation module. 2002-08-15 11:48:58 +00:00
Richard Levitte
52ccf9e1c1 Missing =back.
Part of PR 196
2002-08-15 10:59:59 +00:00
Richard Levitte
5e947727a9 Add a FAQ entry for yet another bc failure.
PR: 199
2002-08-15 10:50:42 +00:00
Richard Levitte
d7bd58cf36 Yet a couple of modules forgotten. These weren't important for
OpenSSL itself, since they aren't used there (yet).  It became quite
visible qhen building a shared library, however...
2002-08-15 09:40:08 +00:00
Richard Levitte
b84e473d63 Sometimes, the value of the variable containing the compiler call can
become rather large.  This becomes a problem when the default 1024
character large buffer that WRITE uses isn't enough.  WRITE/SYMBOL
uses a 2048 byte large buffer instead.
2002-08-15 08:29:26 +00:00
Bodo Möller
4aecd67d04 change how pod2man is handled: explicitly invoke '$PERL' only when
needed, call 'pod2man' directly if this works

PR: 217
2002-08-14 14:06:11 +00:00
Richard Levitte
74a25e9cd9 Instead of returning errors when certain flags are unusable, just ignore them.
That will make the test go through even if DH (or in some cases ECDH) aren't
built into OpenSSL.
PR: 216, part 2
2002-08-14 12:18:36 +00:00
Richard Levitte
d020139db7 Make sure that the test input file comes in the same record format as the
typical output from a program in C.
PR: 222
2002-08-14 11:09:03 +00:00
Dr. Stephen Henson
f84acec8ea Fix typo in OBJ_txt2obj which incorrectly passed the content
length, instead of the encoding length to d2i_ASN1_OBJECT.

This wasn't visible before becuse ASN1_get_object() used
to read past the length of the supplied buffer.
2002-08-14 00:50:35 +00:00
Richard Levitte
d3b282e01f Some files deserve to be ignored 2002-08-13 22:41:39 +00:00
cvs2svn
85d9e2f2f0 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-08-13 22:41:21 +00:00
Richard Levitte
04ed3994e2 OK, I've amused myself with making sure the engines that have been
contributed TO WORK WITH 0.9.7 can be built as dynamically loadable
libraries.

For now, they're not included in crypto/engine/ since 0.9.7 is in
feature freeze.  Further discussion might change that, but don't hold
your breath.
2002-08-13 12:26:41 +00:00
Richard Levitte
6100502726 Export text symbols as well (AIX experts might need to correct me
here).
2002-08-13 12:19:55 +00:00
Richard Levitte
a1f09ea8f8 Do not include openssl/ripemd.h when the RIPEMD algorithm has been deselected.
PR: 216, point 1
2002-08-12 21:22:05 +00:00
Richard Levitte
bce625987d Do not use the word 'modulus', which is a class template name in VC++ 6.0/SP5.
PR: 216, point 3
2002-08-12 21:20:30 +00:00
Bodo Möller
3c1a6f441b add 0.9.6g information 2002-08-12 08:43:32 +00:00
Richard Levitte
97d640e1f0 Update with the status for 0.9.6g. 2002-08-12 06:55:02 +00:00
Richard Levitte
ddf7602425 Update with the status for 0.9.6g. 2002-08-12 06:06:27 +00:00
Richard Levitte
d3c32ffbcc When we want to give a -f argument to $(MAKE), we'd better make sure the
variable doesn't already contain a -f argument.
PR: 203, part 4
2002-08-09 08:49:46 +00:00
Richard Levitte
1d2a3fe246 Parse version numbers prefixed with text (egcs does that, even with
-dumpversion).
PR: 203, part 1
2002-08-09 07:32:31 +00:00
Richard Levitte
00c8546d21 0.9.6f is released 2002-08-08 22:56:05 +00:00
Geoff Thorpe
31e441a805 These are updates/fixes to DH/DSA/RAND docs based on the fixes to the RSA
docs. There were a couple of other places where the docs were not
synchronised with the API that are now fixed. One or two still remain to be
fixed though ...
2002-08-05 16:28:59 +00:00
Geoff Thorpe
c4a28caa32 typo fix 2002-08-05 02:55:27 +00:00
Geoff Thorpe
c3eb0c1e7f Various parts of the RSA documentation were inaccurate and out of date and
this fixes those that I'm currently aware of. In particular, the ENGINE
interference in the RSA API has hopefully been clarified. This still needs
to be done for other areas of the API ...
2002-08-04 21:10:05 +00:00
Geoff Thorpe
d18f681310 A single monolithic man page for the ENGINE stuff. This is a rough
first-cut but provides better documentation than having nothing on the
ENGINE API.
2002-08-04 21:03:04 +00:00
cvs2svn
ea5214328b This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-08-04 20:57:20 +00:00
Geoff Thorpe
0833a40d13 Fix "make install_docs" (and thus "make install"). 2002-08-04 20:38:54 +00:00
Bodo Möller
ab1a01e9b2 oops -- must use EVP_MD_size, not EVP_MD_block_size 2002-08-03 18:50:17 +00:00
Dr. Stephen Henson
f1e1d6d6af Fix typo 2002-08-02 19:03:41 +00:00
Dr. Stephen Henson
b012127a99 Fix the ASN1 sanity check: correct header length
calculation and check overflow against LONG_MAX.
2002-08-02 18:42:40 +00:00
Bodo Möller
265a9e2c5d get rid of OpenSSLDie 2002-08-02 11:47:24 +00:00
Richard Levitte
b0b3b11dbf make update 2002-08-02 11:23:27 +00:00
Richard Levitte
c578208d63 Certain flag macros were tested with #if instead if #ifdef... 2002-08-02 11:13:55 +00:00
Richard Levitte
038461a61b We don't need to find out which pod2man to use more than once 2002-08-01 21:53:08 +00:00
Richard Levitte
716c94492a Don't try testing with parallell make, that will just fail.
PR: 175
2002-08-01 21:34:39 +00:00
Richard Levitte
a4f335ba3e Add aix64-cc, and make sure that ar gets proper flags for 64-bit libraries 2002-08-01 20:28:50 +00:00
Richard Levitte
90832c891e make update 2002-08-01 19:44:43 +00:00
Richard Levitte
dc2ab9f4fa Add the CBC flag for cbc ciphers 2002-08-01 19:33:08 +00:00
Richard Levitte
162d858a90 Avoid yet another name clash with libdes, and make the declaration consistent
with the definition.
2002-08-01 19:31:15 +00:00
Richard Levitte
13ac37d01a Make it possible to load keys from stdin, and restore that
functionality in the programs that had that before.
Part fo PR 164
2002-08-01 16:27:47 +00:00
Richard Levitte
c2decc56b0 OCSP and KRB5 Makefil.ssl should be consistent with all the others 2002-08-01 14:19:08 +00:00
Richard Levitte
1649d5fee1 Linux on s390 really knows about loading dynamically.
PR: 183
2002-08-01 13:50:24 +00:00
Richard Levitte
f8279b8ea3 Cut'n'paste error with other reposnder certificates cleared.
PR: 190
2002-08-01 13:39:46 +00:00
Richard Levitte
76b8f839c2 If CRYPTO_realloc() is called with a NULL pointer, have it call
OPENSSL_malloc().
PR: 187
2002-08-01 10:08:45 +00:00
Richard Levitte
8d37f07e09 If the email address is moved from the subject to the subject alternate name,
the subject in the certificate would differ from the subject in the index file,
which has quite bad concequences.
PR: 180
2002-07-31 14:06:09 +00:00
Richard Levitte
450c73d98b Make sure to use $(MAKE) everywhere instead of make.
Part of PR 181
2002-07-31 13:49:58 +00:00
Richard Levitte
2ead4a5df6 ln -f -s doesn't always work, so do a rm -f followed by a ln -s.
Part of PR 181
2002-07-31 13:38:39 +00:00
Lutz Jänicke
addafc08a5 Typo.
Submitted by: Jeffrey Altman <jaltman@columbia.edu>
Reviewed by:
PR: 169
2002-07-30 13:34:44 +00:00
Lutz Jänicke
e970fa0022 Typo.
Submitted by:
Reviewed by:
PR:
2002-07-30 11:30:03 +00:00
Lutz Jänicke
458bb156bf Release 0.9.7-beta3
Submitted by:
Reviewed by:
PR:
2002-07-30 11:27:18 +00:00
Lutz Jänicke
bca9dc2a51 OpenSSL Security Advisory [30 July 2002]
Changes marked "(CHATS)" were sponsored by the Defense Advanced
Research Projects Agency (DARPA) and Air Force Research Laboratory,
Air Force Materiel Command, USAF, under agreement number
F30602-01-2-0537.
Submitted by:
Reviewed by:
PR:
2002-07-30 11:21:19 +00:00
Lutz Jänicke
3720ea24f0 "make update"
Submitted by:
Reviewed by:
PR:
2002-07-30 07:18:03 +00:00
Lutz Jänicke
72a37c03be Only use DSA-functions if available.
Submitted by: "Hellan,Kim KHE" <KHE@kmd.dk>
Reviewed by:
PR: 167
2002-07-29 13:28:57 +00:00
Bodo Möller
93d1969c78 mention SSL_do_handshake() 2002-07-29 12:34:14 +00:00
Bodo Möller
6178bb8fe9 Add bn_dup_expand() comment from the main branch explaining that
bn_dup_expand() is broken.

[No need to fix this in 0.9.7-stable, it is just an unused internal
function.]
2002-07-25 12:14:41 +00:00
Bodo Möller
5b195b5a0e more detailed instructions for export from US 2002-07-25 11:19:36 +00:00
Richard Levitte
4289131ae6 Don't clobber loop variable.
PR: 159
2002-07-24 14:42:38 +00:00
Richard Levitte
b721e1e239 Document the recent DJGPP-related changes 2002-07-23 13:46:05 +00:00
Richard Levitte
6cf2012a4d Make dummy tests to make it easier to physically remove unwanted algorithms.
This should complete PR 75
2002-07-23 13:32:10 +00:00
cvs2svn
e459ebaed1 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-07-23 13:31:07 +00:00
Richard Levitte
e9e3ce40c5 If DH is disabled, don't define the DH functions.
Notified by Kim Hellan <KHE@kmd.dk>
2002-07-22 14:18:00 +00:00
Bodo Möller
56d84db1d4 fix a typo and clarify 2002-07-22 09:05:41 +00:00
Bodo Möller
16758de0a2 add an explanation and fix a typo 2002-07-22 08:38:14 +00:00
Lutz Jänicke
f19b6474fe New cipher selection options COMPLEMENTOFALL and COMPLEMENTOFDEFAULT.
Submitted by:
Reviewed by:
PR: 127
2002-07-19 19:53:02 +00:00
Lutz Jänicke
2f6f2970c4 HP-UX shared libraries must be +x and should be -w. It doesn't hurt on
other platforms.
Submitted by:
Reviewed by:
PR: 134
2002-07-19 16:31:36 +00:00
Bodo Möller
f227a1af7d update 2002-07-19 12:32:52 +00:00
Lutz Jänicke
4408572079 The behaviour is undefined when calling SSL_write() with num=0.
Submitted by:
Reviewed by:
PR: 141
2002-07-19 11:53:11 +00:00
Lutz Jänicke
31b5b999c7 Manual page for SSL_do_handshake().
Submitted by: Martin Sjögren <martin@strakt.com>
PR: 137
2002-07-19 11:06:53 +00:00
cvs2svn
f8bcfb5d5a This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-07-19 11:05:53 +00:00
Geoff Thorpe
44e9c2617a This documentation change was being written at the same time as Richard's
changes. So I'm committing this version to overwrite his changes for now,
and he can always take his turn to overwrite my words if he wants :-)

PR: 86
2002-07-18 20:52:47 +00:00
Richard Levitte
b61739874e Explain why RSA_check_key() doesn't work with hard keys.
PR: 86
2002-07-18 19:11:06 +00:00
Richard Levitte
73957bd323 Add history for documented new functions.
PR: 59
2002-07-18 18:55:06 +00:00
Richard Levitte
81f1338613 Allow subjects with more than 255 characters to be properly printed.
PR: 147
2002-07-18 17:59:38 +00:00
Richard Levitte
90baf2a92d Further enhance assembler support on Cygwin and DJGPP.
Make pod2mantest useable on DOS-based systems.
Part of PR 75, the rest is still under investigation.
2002-07-18 12:38:07 +00:00
Bodo Möller
13793a0ddf Fix bug introduced with revision 1.95 when this filed was modified to
use the new X509_CRL_set_issuer_name() function:
The CRL issuer should be X509_get_subject_name(x509), not
X509_get_issuer_name(x509).

Submitted by: Juergen Lesny <lesnyj@informatik.tu-muenchen.de>

typo
2002-07-18 11:19:05 +00:00
Richard Levitte
b334853d72 Reverse the change with the following log, it needs further investigation:
Make S/MIME output conform with the mail and MIME standards.
PR: 151
2002-07-18 10:39:49 +00:00
Richard Levitte
4b5d50e26b Make S/MIME output conform with the mail and MIME standards.
PR: 151
2002-07-18 08:47:56 +00:00
Richard Levitte
6d454e6ab2 Unixware doesn't have strings.h, so we need to declare strcasecmp()
differently.
Unixware 2 needs to link with libresolv.
PR: 148
2002-07-18 07:47:49 +00:00
Richard Levitte
4f0e09aa67 OPENSSL_SYS_WIN32 is important so util/mkdef.pl can detect it 2002-07-18 06:34:39 +00:00
Richard Levitte
e921bbf9f6 Make mkdir failsafe in case the directories are already present 2002-07-17 13:33:12 +00:00
Richard Levitte
205a4a9571 Add support for shared libraries with OS/2.
PR: 124
2002-07-17 13:28:29 +00:00
Richard Levitte
44279d4638 Add a few FAQ entries for the various ways building OpenSSL on MacOS X
can fail, and point at the text in the PROBLEMS file
2002-07-17 11:29:34 +00:00
Richard Levitte
9f1c3d7392 If OpenSSL is built with shared library support on MacOS X,
everything works fine.  Note: this is only true for 0.9.7 and on
2002-07-17 11:16:26 +00:00
Richard Levitte
362be34a2f On MacOS X, the shared library editor uses DYLD_LIBRARY_PATH 2002-07-17 11:09:59 +00:00
Richard Levitte
ec7f13d375 On MacOS X, you're not allowed to have common objects in shared libraries 2002-07-17 08:20:56 +00:00
Richard Levitte
ec27c2ac97 Add the usually recommended solution to the linking problem entry for MacOS X 2002-07-17 07:48:50 +00:00
Richard Levitte
b97c854e15 We had some experimental options in the Darwin entries. They are no longer needed 2002-07-16 11:07:49 +00:00
Richard Levitte
bdbbf930aa The default C compiler on MacOS X doesn't like empty object files 2002-07-16 10:46:09 +00:00
Richard Levitte
5254b53e97 Add the new PROBLEMS section from HEAD 2002-07-16 10:38:53 +00:00
cvs2svn
8adc3e5db7 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-07-16 10:20:08 +00:00
Richard Levitte
4810644f65 For those wanting to build for several platforms with the same source
directory, making a separate directory tree with lots of symbolic links
seems to be the solution.  Unfortunately, Configure doesn't take appropriate
steps to support this solution (as in removing a file that's going to be
rewritten).  This change corrects that situation.  Now I just have to
find all other places where there's lack of support for this.
2002-07-16 09:18:25 +00:00
Richard Levitte
d24d873e17 For those wanting to build for several platforms with the same source
directory, making a separate directory tree with lots of symbolic links
seems to be the solution.  Unfortunatelt, Configure doesn't take appropriate
steps to support this solution (as in removing a file that's going to be
rewritten).  This change corrects that situation.  Now I just have to
find all other places where there's lack of support for this.
2002-07-16 08:53:14 +00:00
Richard Levitte
7728770623 Let's not forget the second -Wtraditional 2002-07-16 07:06:18 +00:00
Richard Levitte
279c36564f Using -Wtraditional took it a little far. After all, we expect ANSI C, so
we don't need to care about traditional compilers
2002-07-16 06:53:22 +00:00
Richard Levitte
50d1c3fd85 Set up the engine before doing anything random-related, since engine randomness
is only used for seeding and doing it in the wrong order will mean seeding
is done before the engine randomness is hooked in.
Notified by Frederic DONNAT <frederic.donnat@zencod.com>
2002-07-16 06:51:45 +00:00
Lutz Jänicke
ed712101ea Rewording: some algorithms are also patented in Europe, so choose more
defensive phrases...
Submitted by:
Reviewed by:
PR:
2002-07-12 15:27:01 +00:00
Richard Levitte
015eb65963 In UI_UTIL_read_pw(), we should look at the size parameter, not at BUFSIZ.
Submitted by Götz Babin-Ebell <babinebell@trustcenter.de>
2002-07-11 09:12:37 +00:00
Lutz Jänicke
afafa3e15c Discussion about Redhat's specialties for the FAQ.
Submitted by: John.Airey@rnib.org.uk
Reviewed by:
PR: 128
2002-07-10 19:47:55 +00:00
Lutz Jänicke
150f2d8d24 Typos in links between manual pages
Submitted by: Richard.Koenning@fujitsu-siemens.com
Reviewed by:
PR: 129
2002-07-10 19:34:47 +00:00
Lutz Jänicke
a6545f0566 Sun's official statement with respect to /dev/random support.
Submitted by: Garrett Anderson garrett@dirsec.com
Reviewed by:
PR: 120
2002-07-10 17:51:14 +00:00
Lutz Jänicke
5fc041cca0 Minor typos
Submitted by: jufi@nerdnet.de
Reviewed by:
PR: 138
2002-07-10 17:33:55 +00:00
Bodo Möller
089cd046af remove obsolete comment 2002-07-10 08:38:34 +00:00
Lutz Jänicke
7e8852c549 Reorder inclusion of header files:
des_old.h redefines crypt:
#define crypt(b,s)\
	DES_crypt((b),(s))

This scheme leads to failure, if header files with the OS's true definition
of crypt() are processed _after_ des_old.h was processed. This is e.g. the
case on HP-UX with unistd.h.
As evp.h now again includes des.h (which includes des_old.h), this problem
only came up after this modification.
Solution: move header files (indirectly) including e_os.h before the header
files (indirectly) including evp.h.
Submitted by:
Reviewed by:
PR:
2002-07-10 06:57:54 +00:00
Lutz Jänicke
4064a85205 Ciphers with NULL encryption were not properly handled because they were
not covered by the strength bit mask.
Submitted by:
Reviewed by:
PR: 130
2002-07-10 06:40:18 +00:00
Bodo Möller
3a9fef60a1 fix synopsis
Submitted by: Nils Larsch
2002-07-09 10:52:30 +00:00
Bodo Möller
be9419edf4 emtpy fragments are not necessary for SSL_eNULL
(but noone uses it anyway)

fix t1_enc.c: use OPENSSL_NO_RC4, not NO_RC4
2002-07-09 08:48:49 +00:00
Geoff Thorpe
a729d47d41 oops, there were other cases of "ENGINE_ID" to change too. 2002-07-08 15:06:39 +00:00
Geoff Thorpe
6abf827f25 Correct an error in the README.ENGINE file.
Submitted by: Jan Tschirschwitz <Jan.Tschirschwitz@cluster-labs.de>
2002-07-08 14:48:44 +00:00
Bodo Möller
5af9fcaf35 AES cipher suites are now official (RFC3268) 2002-07-04 08:50:33 +00:00
Lutz Jänicke
5736d40dad README and INSTALL should contain information about the request tracker
(noted by Jonathan Louie <jlouie@recourse.com>).
Submitted by:
Reviewed by:
PR:
2002-06-30 19:38:01 +00:00
Richard Levitte
0dfd83b9f4 Do not define crypt() on OpenBSD. Notified by Bob Beck of OpenBSD. 2002-06-29 22:04:16 +00:00
Richard Levitte
8e10dea8ec opensslconf.h doesn't define what we want, e_os2.h does.
PR 123
2002-06-27 17:20:16 +00:00
Richard Levitte
a69e8ea1a1 Try to avoid double declaration of ERR_load_PEM_strings().
PR 71
2002-06-27 17:06:41 +00:00
Richard Levitte
1f656724f6 A few changes to BC-32.pl didn't get properly applied.
This completes PR 123
2002-06-27 16:56:36 +00:00
Richard Levitte
ca55c617e5 Pass CFLAG to dependency makers, so non-standard system include paths are
handled properly.
Part of PR 75
2002-06-27 16:44:52 +00:00
Richard Levitte
9063e375e8 DJGPP has some needed header files that other MSDOS/Windows compilers don't have.
Part of PR 75
2002-06-27 16:32:15 +00:00
Richard Levitte
97c9760f61 Update the information on Cygwin.
Part of PR 75
2002-06-27 16:30:18 +00:00
Richard Levitte
df60710ea8 Forgot to change the second $ENV{DJDIR} to /dev/env/DJDIR.
Part of PR 75
2002-06-27 16:28:28 +00:00
Richard Levitte
5d2edd2659 The new stuff is for Borland Bulider 5, so document it appropriately 2002-06-27 15:11:08 +00:00
Richard Levitte
a558ae9496 Document the new way of building with Borland Builder.
This concludes the changes from PR 123
2002-06-27 15:07:43 +00:00
Richard Levitte
d58a949aae Use underscores instead of dashes in temporary file names.
This is due to weird Borland compilers.
Part of PR 123
2002-06-27 14:58:06 +00:00
Richard Levitte
00e608c89d When compiling for Windows, make sure we have the windows definitions declared.
Part of PR 123
2002-06-27 14:56:02 +00:00
Richard Levitte
b4dfd76a4c Use 32-bit sections instead of the default, 16-bit ones.
Part of PR 123
2002-06-27 14:54:39 +00:00
Richard Levitte
ea9a52d124 have 'openssl pkcs7' exit with code 1 on error instead of 0.
PR: 119
2002-06-27 10:26:52 +00:00
Richard Levitte
75cc5e05ad gcc requires -m64 to link 64-bit shared libraries on Solaris.
PR: 117
2002-06-27 10:19:54 +00:00
Richard Levitte
84ae14d754 Use bg instead of bag as argument to macros, to avoid clashes with
structure field names.
PR: 112
2002-06-27 09:54:14 +00:00
Richard Levitte
a9e897adc3 There is no RSAREF any more, so do not ty to install it.
PR: 106
2002-06-27 09:18:30 +00:00
Richard Levitte
fc0f3ad254 The general debug target must specify that it doesn't use assembler routines.
PR: 105
2002-06-27 09:13:11 +00:00
Richard Levitte
a1fbe27123 A number of includes were removed from evp.h some time ago. The reason
was that they weren't really needed any more for EVP itself.  However,
it seems like soma applications (I know about OpenSSH, but there may
be more) used evp.h as the 'load all' header file, which makes sense
since we try our best to promote the use of EVP instead of the lower
level crypto algorithms.  Therefore, I put the inclusions back so
the application authors don't get too shocked by all the errors they
would otherwise get.

Thanks to Theo de Raadt for making us aware of this.
2002-06-27 05:03:12 +00:00
Bodo Möller
1c45b1fef3 Make sure buffers are large enough even for weird parameters
Submitted by: Nils Larsch
2002-06-26 14:29:10 +00:00
Bodo Möller
e003386793 update an entry on EVP changes 2002-06-26 14:22:39 +00:00
Richard Levitte
a533b89c9f For some reason, we need to return the full path to perl 2002-06-25 11:41:25 +00:00
Geoff Thorpe
a2ffad81c8 Make sure any ENGINE control commands make local copies of string
pointers passed to them whenever necessary. Otherwise it is possible the
caller may have overwritten (or deallocated) the original string data
when a later ENGINE operation tries to use the stored values.

Submitted by: Götz Babin-Ebell <babinebell@trustcenter.de>
Reviewed by: Geoff Thorpe
PR: 98
2002-06-21 02:48:57 +00:00
Lutz Jänicke
081cdf3f63 <sys/select.h> is included for AIX, when USE_SOCKETS is defined.
Submitted by: Bernhard Simon <bs@bsws.zid.tuwien.ac.at>
Reviewed by:
PR:
2002-06-20 20:13:12 +00:00
Lutz Jänicke
dbf5b18a99 HP-UX: shared libraries MUST be +x and SHOULD be -w.
Submitted by:
Reviewed by:
PR:
2002-06-20 19:55:58 +00:00
Lutz Jänicke
0b3f7afaed Fix path to find util/pod2man.pl from the execution directory.
Make sure to use the predefined PERL.
Submitted by: Bernhard Simon <bs@bsws.zid.tuwien.ac.at>
Reviewed by:
PR:
2002-06-20 19:47:59 +00:00
Lutz Jänicke
d6e8f6ae2b AIX (V3) requires <sys/select.h> (included via e_os.h) for fd_set.
Submitted by: Bernhard Simon <bs@bsws.zid.tuwien.ac.at>
Reviewed by:
PR:
2002-06-20 17:31:12 +00:00
Geoff Thorpe
af629a19d7 This apparently fixes compilation on OSX that was failing in 0.9.7 betas.
Submitted by: Pieter Bowman <bowman@math.utah.edu>
2002-06-20 15:17:02 +00:00
Lutz Jänicke
9a3eaa1117 load_netscape_key is static.
Submitted by:
Reviewed by:
PR:
2002-06-18 17:44:01 +00:00
Bodo Möller
7a68e6aad1 always include <string.h> (we do this in various other header files,
so it can't be bad)

PR: 102
2002-06-18 09:35:29 +00:00
Bodo Möller
f27fa54388 typo 2002-06-17 13:59:36 +00:00
Lutz Jänicke
48acb9e08a Roll OpenSSL-0.9.7-beta2
Submitted by:
Reviewed by:
PR:
2002-06-16 11:27:44 +00:00
Lutz Jänicke
e5706ccbde Use -dumpversion to obtain gcc's version.
Submitted by: ross.alexander@uk.neceur.com, allenh@eecs.berkeley.edu
Reviewed by:
PR: 96
2002-06-16 10:29:55 +00:00
Lutz Jänicke
9a82ef5255 OpenSSL_add_all_algorithms has been replaced by configuration dependent
functions and is redirected by macros. Switch it off now, possible removal
later.
Submitted by:
Reviewed by:
PR:
2002-06-16 10:16:42 +00:00
Dr. Stephen Henson
4a1dcb2d03 Make update 2002-06-15 12:29:28 +00:00
Lutz Jänicke
ef92312b41 Initial support for hpux64-parisc-gcc
Submitted by: ross.alexander@uk.neceur.com
Reviewed by:
PR: 96
2002-06-14 20:10:24 +00:00
Lutz Jänicke
4673461789 Some more prototype fixes.
Use DECLARE macros in asn1* instead of direct declaration.
Submitted by: Goetz Babin-Ebell <babinebell@trustcenter.de>
Reviewed by:
PR: 89
2002-06-14 18:59:53 +00:00
Bodo Möller
2f8275c52d New option SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS for disabling CBC
vulnerability workaround (included in SSL_OP_ALL).

PR: #90
2002-06-14 12:20:27 +00:00
Richard Levitte
39ebb51bba make update 2002-06-13 23:38:11 +00:00
Richard Levitte
d7227da9a8 Merge from HEAD. 2002-06-13 23:37:26 +00:00
Richard Levitte
ab805194a6 Tentatively add support for UWIN, a Unix-like environment on top of Windows.
PR: 62
2002-06-13 21:44:01 +00:00
Richard Levitte
4fac53a757 Make sure that any dash in the prefix before the version number is removed.
PR: 96
2002-06-13 21:11:57 +00:00
Richard Levitte
11198b78a2 Add support for DJGPP. 2002-06-13 20:44:38 +00:00
Richard Levitte
573a568dd0 Add support for DJGPP.
PR: 75
2002-06-13 20:40:49 +00:00
Richard Levitte
ff3dd00370 Check for the executable $openssl, not just the file.
Part of PR: 75
2002-06-13 19:59:26 +00:00
Richard Levitte
2028c2800a Parse directory using both slashes and backslashes as separators.
Do file copying in term of perl statements instead of using cp.
Part of PR: 75
2002-06-13 19:50:26 +00:00
Richard Levitte
fd8766b67e Making a softlink from crypto/des/asm/perlasm to crypto/perlasm isn't
strictly necessary, so let's not do that.
2002-06-13 19:42:06 +00:00
Lutz Jänicke
7d210e5194 Add missing prototypes.
Submitted by: Goetz Babin-Ebell <babinebell@trustcenter.de>
Reviewed by:
PR: 89
2002-06-13 17:38:58 +00:00
Dr. Stephen Henson
2e674fc611 Fix ext_dat.h extension ordering.
Reinstate -reqout code.

Avoid coredump in ocsp if setup_verify
fails.

Fix typo in ocsp usage message.
2002-06-13 12:54:52 +00:00
Lutz Jänicke
5cfd3419c6 Add OIDs for Secure Electronic Transactions (SET)
Submitted by: Vadim Fedukovich <vf@unity.net>
Reviewed by: Lutz Jaenicke
PR: 80
2002-06-13 11:51:31 +00:00
Lutz Jänicke
9efd4fb891 Clarify formulation (proposed by Bodo Moeller).
Submitted by:
Reviewed by:
PR:
2002-06-13 08:52:25 +00:00
Dr. Stephen Henson
b2e85f9d93 The new ASN1 code automatically allocates
structures for fields that are not OPTIONAL.

However in the AUTHORITY_INFO_ACCESS case
the 'location' field was set to NULL in
the old code.

So in 0.9.7+ we should free up the field before
overwriting it in v2i_AUTHORITY_INFO_ACCESS.
2002-06-13 00:43:59 +00:00
Lutz Jänicke
f10581829d Make change uniqueIdentifier -> x500UniqueIdentifier clearly visible.
Submitted by:
Reviewed by:
PR: 82
2002-06-12 20:42:04 +00:00
Lutz Jänicke
78af3b274f Correct wrong usage information.
Submitted by:
Reviewed by:
PR: 95
2002-06-12 20:14:04 +00:00
Lutz Jänicke
facd9a2024 Support building the distribution .tar file on platforms with limited
argument list length. This requires Gnu-tar. As we use the non-standard
"tardy" software anyway, it doesn't hurt too much to require Gnu-tar.
"make dist" will probably only be used by team-members anyway.
Submitted by:
Reviewed by:
PR:
2002-06-12 12:25:42 +00:00
Ben Laurie
461f00dd53 Handle read failures better. 2002-06-11 11:41:26 +00:00
Bodo Möller
22f03eaedf fix for 'make update' 2002-06-10 11:45:21 +00:00
Lutz Jänicke
d467c74954 Make sure that flags are passed to "make" subprocesses.
Submitted by:
Reviewed by:
PR:
2002-06-10 08:11:20 +00:00
Lutz Jänicke
c4c745ccb8 For the main directory, Makefile.org is significant :-)
Submitted by:
Reviewed by:
PR:
2002-06-06 10:19:33 +00:00
Lutz Jänicke
3b66e34e74 Make sure that settings are passed back and forth when walking around
in the tree during build.
Reinstall default PERL settings in Makefiles, as the real reason for the
failure was that the settings were not passed.
Submitted by:
Reviewed by:
PR:
2002-06-06 10:14:16 +00:00
Lutz Jänicke
2250f475fc New OID for X509 usage: pseudonym
Submitted by: Michael Bell <michael.bell@rz.hu-berlin.de>
Reviewed by: Lutz Jaenicke
PR: 83
2002-06-06 07:30:45 +00:00
Richard Levitte
ed703912b2 Make perl replacement for dirname, for system that lack the latter.
PR: 81
2002-06-05 14:10:31 +00:00
Richard Levitte
2cddcd1dbb It's not good to have a pointer point at something in an inner block.
PR: 66
2002-06-05 13:47:15 +00:00
Richard Levitte
231360a3b7 Check errors when parsing a PKCS8INF PEM FILE, or there will be a core dump on error.
PR: 77
2002-06-05 11:58:23 +00:00
Richard Levitte
65ac3faff6 Documentation bug corrected.
PR: 70
2002-06-05 09:30:20 +00:00
Richard Levitte
778252741e Since there's no continuation, the ; can go as well :-) 2002-06-05 09:08:49 +00:00
Lutz Jänicke
96e40d97cc There is no continuation at this point.
Submitted by:
Reviewed by:
PR:
2002-06-05 07:56:14 +00:00
Lutz Jänicke
4b3743c85a On some systems the default "perl" may still be perl4, use the correct
version determined by "config" instead.
Submitted by:
Reviewed by:
PR:
2002-06-05 07:27:21 +00:00
Lutz Jänicke
5795665a7d The correct PERL interpreter is passed via commandline.
Submitted by:
Reviewed by:
PR:
2002-06-05 07:01:39 +00:00
Richard Levitte
88f1be140c Correct syntax in ssl-lib.com
maketests.com was missing the TCP/IP options TCPIP and NONE
2002-06-05 06:45:27 +00:00
Richard Levitte
fc16b228fd Update the recognision of GCC version numbers to handle the prefix text
that GCC 3.1 adds to the --version output
2002-06-05 05:00:41 +00:00
Richard Levitte
a5b2ccaaad make update (including adjusting libeay.num in HEAD to the changes in the
0.9.7-stable libeay.num
2002-06-04 22:32:17 +00:00
Lutz Jänicke
5dd352c916 Typo.
Submitted by:
Reviewed by:
PR: 72
2002-06-04 20:44:10 +00:00
Richard Levitte
3c204aaf50 use sstrsep() to get the proper type to aoti().
Remove unneeded cast in ustrsep().
PR: 69
2002-06-03 15:27:52 +00:00
Lutz Jänicke
3ae184d31f Ok, we are rolling 0.9.7-beta1 now.
Submitted by:
Reviewed by:
PR:
2002-06-01 15:21:55 +00:00
Ben Laurie
3e975124f3 Fix a warning. 2002-05-31 14:34:15 +00:00
Ben Laurie
74c467f9f2 Fix warnings. 2002-05-31 14:28:30 +00:00
Richard Levitte
1b97c938e9 Document the AES changes. 2002-05-31 13:16:37 +00:00
Richard Levitte
b3e2acac4e Add the AES test vectors from NIST document SP800-38A. 2002-05-31 13:13:51 +00:00
Richard Levitte
403fa0dc53 Make it possible to give vectors only for decryption or encryption. 2002-05-31 13:12:54 +00:00
Richard Levitte
f918c330a9 For CFB and OFB modes, always create the encryption key. 2002-05-31 13:11:48 +00:00
Richard Levitte
7f52f77efe Declare the CFB and OFB modes for AES, and prepare for a declaration
of CTR mode.
2002-05-31 13:10:24 +00:00
Richard Levitte
90b480f2af In CFB mode, the iv is always encrypted. 2002-05-31 13:07:45 +00:00
Richard Levitte
578c33c010 Reformat the CFLAG string so it can be made part of a C string.
Incidently, this works pretty well on the command line as well.
PR: 52
2002-05-30 18:06:52 +00:00
Richard Levitte
d6a821b9d7 Support the newly release gcc 3.1 on 64-bit Solaris. Not automatic.
PR: 57
2002-05-30 17:28:23 +00:00
Richard Levitte
7d8b5c530f Support shared libraries properly on linux-sparcv[89].
PR: 60
2002-05-30 17:07:55 +00:00
Richard Levitte
2033da0b23 a B< that wasn't properly ended. 2002-05-30 16:55:31 +00:00
Richard Levitte
c4ac954c59 Check the return values where memory allocation failures may happen.
PR: 49
2002-05-30 16:50:38 +00:00
Richard Levitte
2640aec227 CAformat should not be used for CA key format. 2002-05-30 16:24:26 +00:00
Richard Levitte
a1037ce3bc Make sure that MS_STATIC isn't defined to 'static' under Win32.
PR: 51
2002-05-30 15:45:02 +00:00
Richard Levitte
249737e53d pod2man.pl would only remove the first LF from the name. 2002-05-30 15:30:21 +00:00
Richard Levitte
c70573dee1 Apparently, there are still chances we have to deal with buggy pod2man versions.
Deal with that by testing any available pod2man and using it if appropriate,
and falling back to util/pod2man.pl if none was found.
2002-05-30 15:18:07 +00:00
Richard Levitte
6c98ed520d Correct AES counter mode, which incorrectly incremented the counter before
using it.
PR: 56
2002-05-30 14:06:17 +00:00
Richard Levitte
37ceea7333 Correct darwin shared library support.
PR: 39
2002-05-30 12:16:51 +00:00
Richard Levitte
374b227226 Some shlib extensions were in the wrong field 2002-05-30 10:47:52 +00:00
Richard Levitte
8c4a5016ce Our copy of pod2man.pl is old and comparatively broken, so lets remove it.
PR: 30
2002-05-30 10:18:23 +00:00
Richard Levitte
1056275825 Add more warnings for my debug targets. 2002-05-30 09:39:19 +00:00
Richard Levitte
9634acedaf Remove the duplicate description of -out.
PR: 28
2002-05-30 06:24:46 +00:00
Dr. Stephen Henson
3a4b0bed49 Make i2c_ASN1_BIT_STRING return the correct length. 2002-05-29 23:11:55 +00:00
Richard Levitte
84f4e33ea3 Set DLOPEN_FLAG the same way on NetBSD as on OpenBSD.
PR: 58, submitted by andrew@cis.uoguelph.ca
2002-05-29 21:00:33 +00:00
Richard Levitte
b093ef7445 There is a chance that the input string is larger than size, and on VMS,
this wasn't checked and could possibly be exploitable (slim chance, but still)
2002-05-29 08:31:45 +00:00
Lutz Jänicke
405ac901c9 Remove item listed twice <kromJx@crosswinds.net>.
Submitted by:
Reviewed by:
PR:
2002-05-28 17:48:12 +00:00
Ulf Möller
721ccb6cf5 as in main branch 2002-05-27 19:54:41 +00:00
Bodo Möller
ba05727773 Change as in main branch:
Use assembler implementations with Cygwin.
This also fixes the bn_sub_part_word problem.
2002-05-24 20:41:07 +00:00
Richard Levitte
f9332da521 Recover from errors 2002-05-23 23:32:30 +00:00
Richard Levitte
156516ce44 Avoid loops when linking doesn't work 2002-05-23 15:27:21 +00:00
Richard Levitte
157e44a799 Forgot this file. 2002-05-23 15:25:27 +00:00
Richard Levitte
7d2ff3f081 Allow the use of the TCP/IP stack keyword TCPIP and NONE 2002-05-22 11:37:02 +00:00
Richard Levitte
25a87e82d4 Use OPENSSL_SYS_VMS instead of just VMS 2002-05-22 11:35:41 +00:00
Richard Levitte
e400753ed8 Update copyright years.
This has already been applied in the main branch.
2002-05-22 07:58:02 +00:00
Richard Levitte
0984fcf118 Use 0 instead of NULL when casting to function pointers, to avoid
warnings from compilers when NULL is defined as '((void *)0)'.
This has already been applied in the main branch.
2002-05-22 07:56:38 +00:00
Richard Levitte
18cc99ac17 Remove warnings about uninitialised variables.
This has already been applied in the main branch.
2002-05-22 07:55:03 +00:00
Richard Levitte
1522c23470 Remove warnings about unused symbols when configured with no-rsa. 2002-05-22 07:53:53 +00:00
Richard Levitte
2341e303da This file was removed long ago. Why it's still in this branch is a
mystery to me.
2002-05-22 07:49:37 +00:00
Bodo Möller
dca142029c accept NULL in 'free' functions 2002-05-21 09:00:54 +00:00
Dr. Stephen Henson
7448f5e5ed Reorganise -subj option code, fix buffer overrun. 2002-05-19 16:32:21 +00:00
Dr. Stephen Henson
45caf9c50c Fix Mingw32 asm build: use the Unix
bignum assembly method of bn-586.pl
and co-586.pl which (for some reason)
VC++ doesn't use.
2002-05-19 12:00:46 +00:00
Dr. Stephen Henson
ace2ca484b Add missing EVP_CIPHER_CTX_init call. 2002-05-18 23:42:20 +00:00
Lutz Jänicke
7dc584ed91 Fix incorrect =over 4 location.
Submitted by: David Waitzman <djw@bbn.com>
Reviewed by: Lutz Jaenicke
PR: [openssl.org #38]
2002-05-16 17:44:50 +00:00
Bodo Möller
855f0b4f2f fix EVP_dsa_sha macro
Submitted by: Nils Larsch
2002-05-16 12:53:34 +00:00
Lutz Jänicke
2bf30d6b47 Use the indirect way to the actual request tracker, so that people
also are informed about the credentials required for guest access
and the operation instructions.
Submitted by:
Reviewed by:
PR:
2002-05-16 10:00:16 +00:00
Bodo Möller
685e7d7225 update 2002-05-16 09:31:27 +00:00
Dr. Stephen Henson
38dbcb2248 Oops, forgot CHANGES entry and description:
Allow reuse of cipher contexts by removing
automatic cleanup in EVP_*Final().
2002-05-15 18:23:07 +00:00
Dr. Stephen Henson
bb3a69f801 Zero cipher_data in EVP_CIPHER_CTX_cleanup
Add cleanup calls to evp_test.c
2002-05-15 17:52:19 +00:00
Bodo Möller
55db40d3e0 make b_print.c consistent with the rest of OpenSSL:
disable assert() except for debug builds
2002-05-14 19:03:12 +00:00
Bodo Möller
f1fbf15116 apply mingw32 patches from main branch 2002-05-14 17:19:26 +00:00
Lutz Jänicke
9bdbdda261 Add missing '"'
Submitted by: Boyd Gerber <gerberb@zenez.com>
Reviewed by:
PR:
2002-05-12 20:36:49 +00:00
Lutz Jänicke
ad2057500a Recognize PPC64 target.
Submitted by:
Reviewed by:
PR: 26
2002-05-12 19:44:19 +00:00
Dr. Stephen Henson
d0e3726ca4 EVP_SealFinal should return a value. 2002-05-11 17:33:01 +00:00
Dr. Stephen Henson
75a46764e5 closedir is not used on Win32. 2002-05-11 12:42:23 +00:00
Dr. Stephen Henson
4eceda658b Add config entry debug-steve-linux-pseudo64. This sets the
SIXTY_FOUR bignum library option to use 64 bit operations
on the 32 bit linux platform.

This is very inefficient but it can be used to test some
of the 64 bit logic on a 32 bit platform.
2002-05-10 22:57:29 +00:00
Dr. Stephen Henson
1c511bdb7c Fallback to normal multiply if n2 == 8 and dna or dnb is not zero
in bn_mul_recursive.

This is (hopefully) what was triggering bignum errors on 64 bit
platforms and causing the BN_mod_mul test to fail.
2002-05-10 22:22:55 +00:00
Dr. Stephen Henson
f9bd76e4f7 Avoid gcc warning: BN_DEC_CONV when SIXTY_FOUR_BIT is defined is unsigned. 2002-05-10 22:08:22 +00:00
Richard Levitte
e74e0dedcd Updating status for 0.9.6d 2002-05-09 23:53:35 +00:00
Richard Levitte
dcf6eb2a9e Synchronise the FAQ 2002-05-09 23:41:51 +00:00
Richard Levitte
7d2980f09e Make the huge buffer smaller, so the size becomes reasonable for small-stack environments.
Notified by Verdon Walker <VWalker@novell.com>
2002-05-09 20:14:50 +00:00
Richard Levitte
f1fe6fa6e4 One place where VMS wasn't changed to OPENSSL_SYS_VMS... 2002-05-09 18:27:56 +00:00
Richard Levitte
ecb7a9c73a Move an assert() to avoid core dumps when a static buffer hasn't been given.
Notified by Verdon Walker <VWalker@novell.com>
2002-05-09 18:19:45 +00:00
Richard Levitte
aebe0396e9 Small documentation fix for EVP_CipherFinal or EVP_CipherFinal_ex.
Notified by Stella Power <snpower@maths.tcd.ie>.
PR: 24
2002-05-08 15:20:33 +00:00
Ben Laurie
4e9a77cf26 Fix warning. 2002-05-08 15:13:24 +00:00
Richard Levitte
14ef32631c Generate an error if rewinding wasn't possible.
Notified by Ken Hirsch <kenhirsch@myself.com>.
PR: 23
2002-05-08 15:12:49 +00:00
Lutz Jänicke
500f07c8de Add missing ";" after fi
Submitted by: bryanh@giraffe-data.com
Reviewed by:
PR: [openssl.org #18]
2002-05-07 15:35:09 +00:00
Bodo Möller
ae936dae90 Fix ciphersuite list to enforce low priority for RC4. 2002-05-07 08:36:01 +00:00
Bodo Möller
67166dc05c ensure that, for each strength, RC4 ciphers have least preference
in the default ciphersuite list
2002-05-07 07:59:05 +00:00
Bodo Möller
aa9fed8cc2 refer to latest draft for AES ciphersuites 2002-05-07 07:56:09 +00:00
Bodo Möller
442eb8a4c3 fix warning 2002-05-06 10:44:08 +00:00
Bodo Möller
46805f696d update 2002-05-05 23:48:51 +00:00
Bodo Möller
29f6a99432 disable AES ciphersuites unless explicitly requested 2002-05-05 23:47:09 +00:00
Bodo Möller
1f13793b1a fix casts 2002-05-05 23:01:02 +00:00
Richard Levitte
08130eb158 Make sure that date is run under the C locale, so dates are given in the
default format.
PR: 16
2002-05-02 08:05:52 +00:00
Dr. Stephen Henson
b27dfeacc9 Add apps_startup and bio_err init code to smime.c 2002-05-01 20:06:24 +00:00
Lutz Jänicke
fb0f53b2e0 Fix escaping when using the -subj option of "openssl req", document
'hidden' -nameopt support. (Robert Joop <joop@fokus.gmd.de>)
Submitted by:
Reviewed by:
PR: #2
2002-04-30 12:10:10 +00:00
Lutz Jänicke
baa521bef5 Add information about -nameopt option for x509.
Submitted by:
Reviewed by:
PR:
2002-04-29 16:02:38 +00:00
Bodo Möller
7bcf65a125 undo nonsense patch (r *is* signed or we have signedness mismatches elsewhere) 2002-04-29 11:03:38 +00:00
Richard Levitte
306009bb6a Fix unsigned vs. signed clash 2002-04-29 10:30:34 +00:00
Bodo Möller
dfc5336975 Fix crypto/asn1/a_sign.c so that 'parameters' is omitted (not
encoded as NULL) with id-dsa-with-sha1.

Submitted by: Nils Larsch
2002-04-26 08:29:18 +00:00
Lutz Jänicke
4cea95a547 Added generationQualifier OID (proposed by Fiel Cabral).
Submitted by:
Reviewed by:
PR:
2002-04-25 18:00:13 +00:00
Richard Levitte
b23b3272dc Potential memory leak removed. Notified by <threaded@totalise.co.uk> 2002-04-25 10:11:08 +00:00
Bodo Möller
1696aa1891 new items for 0.9.7 2002-04-25 07:51:51 +00:00
Bodo Möller
52407725c9 oops 2002-04-25 07:46:55 +00:00
Bodo Möller
81da3c3319 AlgorithmIdentifier bugs 2002-04-25 06:29:31 +00:00
Bodo Möller
7729bc2634 fix usage (no 'key') 2002-04-23 13:55:56 +00:00
Richard Levitte
69a305d434 Uhmmm, if we use && after having tested for the presence of the certificate,
we just *might* stand a certain chance of actually getting it written
to file...
2002-04-23 13:15:27 +00:00
Lutz Jänicke
ab5b1cf86b ERR_file_name is no longer being used.
Submitted by:
Reviewed by:
PR:
2002-04-22 13:55:37 +00:00
Lutz Jänicke
c33387749b Add cygwin build script (Corinna Vinschen <vinschen@redhat.com>).
Submitted by:
Reviewed by:
PR:
2002-04-21 17:54:53 +00:00
cvs2svn
c9ca65b469 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-04-21 17:54:06 +00:00
Richard Levitte
8e078f45e0 Make sure ec is properly handled in Windows. 2002-04-20 10:25:19 +00:00
Richard Levitte
f84ffd0130 Make sure the opened directory is closed on exit.
Notified by Lorinczy Zsigmond <lzsiga@mail.ahiv.hu>
2002-04-18 16:20:21 +00:00
Lutz Jänicke
300e3d7c73 Missing "Configure" entry (Jean-Marc Desperrier <jean-marc.desperrier@certplus.com>).
Submitted by:
Reviewed by:
PR:
2002-04-18 12:46:41 +00:00
Lutz Jänicke
365c6e4661 Optimize: better shortcut evaluation ("Howard Chu" <hyc@highlandsun.com>).
Submitted by:
Reviewed by:
PR:
2002-04-18 11:53:35 +00:00
Lutz Jänicke
1dc03ef706 Handle headings uniformly to allow automatic processing.
Submitted by:
Reviewed by:
PR:
2002-04-18 08:09:59 +00:00
Bodo Möller
d4a67e3186 check return values
Submitted by: Nils Larsch
2002-04-17 09:31:02 +00:00
Lutz Jänicke
18e10315e5 Document OID changes.
Submitted by:
Reviewed by:
PR:
2002-04-15 14:17:20 +00:00
Lutz Jänicke
e9caaa4ad9 Use the "mail" short name according to RFC2798 (Michael Bell
<michael.bell@rz.hu-berlin.de>).
Submitted by:
Reviewed by:
PR:
2002-04-15 13:28:53 +00:00
Lutz Jänicke
a6198b9ed1 Some more OID enhancements.
Submitted by:
Reviewed by:
PR:
2002-04-15 10:38:37 +00:00
Lutz Jänicke
a7be294ed7 Fix CRLF problem in BASE64 decode.
Submitted by:
Reviewed by:
PR:
2002-04-15 09:53:47 +00:00
Bodo Möller
617f461c9d remove disabled code 2002-04-14 13:28:41 +00:00
Bodo Möller
1dcb6c994f fix length field we create when converting SSL 2.0 format into SSL 3.0/TLS 1.0 format
(the bug was introduced with message callback support)
2002-04-14 13:04:58 +00:00
Bodo Möller
a9ab63c01c Implement known-IV countermeasure.
Fix length checks in ssl3_get_client_hello().

Use s->s3->in_read_app_data differently to fix ssl3_read_internal().
2002-04-13 22:51:26 +00:00
Bodo Möller
f89db4020f error reported by Karsten Braaten 2002-04-13 22:06:25 +00:00
Richard Levitte
393c09659e Avoid emacs backup files when making a snapshot 2002-04-13 12:28:49 +00:00
Bodo Möller
2d96549cd0 looks like a typo 2002-04-12 13:51:42 +00:00
Bodo Möller
b48892d403 synchronize with main branch 2002-04-12 13:46:46 +00:00
Richard Levitte
7b907f0bb5 Check error code from a2d_ASN1_OBJECT(). 2002-04-11 22:14:10 +00:00
Richard Levitte
9dfcad117c Change the date to XX xxx XXXX in development versions. 2002-04-11 21:53:57 +00:00
Lutz Jänicke
7018feed88 Compile NEWS from CHANGES.
Submitted by:
Reviewed by:
PR:
2002-04-11 18:43:01 +00:00
Lutz Jänicke
9be529f12d In preparation of 0.9.7: re-order changelog, so that the changes
are listed as of ... -> 0.9.6c -> 0.9.6d -> 0.9.7
Submitted by:
Reviewed by:
PR:
2002-04-10 19:50:23 +00:00
Lutz Jänicke
f5e5277908 Keep my own specially optimized HP-UX shared library building up to date.
Submitted by:
Reviewed by:
PR:
2002-04-10 12:34:32 +00:00
Bodo Möller
c991c6e710 error reported by Karsten Braaten 2002-04-09 13:04:00 +00:00
Bodo Möller
e1f4319279 harmonize capitalization 2002-04-09 12:42:15 +00:00
Bodo Möller
2826fcc851 add usage examples 2002-04-09 11:53:51 +00:00
Richard Levitte
37562f753a Allow longer program names (VMS allows up to 39 characters).
Submitted by Compaq.
2002-04-06 20:22:40 +00:00
Richard Levitte
248252682c make update 2002-04-06 19:15:27 +00:00
Richard Levitte
cc3586028e Allow longer program names (VMS allows up to 39 characters).
Submitted by Compaq.
2002-04-06 18:59:57 +00:00
Richard Levitte
f60df86c89 Oops, the system macro for VMS is OPENSSL_SYS_VMS, not VMS 2002-04-06 11:57:58 +00:00
Richard Levitte
bc7a3a9e99 Recognise DEC C++ as equivalent to DEC C for the definitions of OPENSSL_EXTERN and OPENSSL_GLOBAL.
Submitted by Compaq.
2002-04-06 11:37:13 +00:00
Richard Levitte
d3cbf7d86a Use recv() and send() for socket communication on VMS instead of read()
and write().  The reason is that read() and write() make additional record
level locking which causes hangs of Compaq Secure Web Server (Apache) with
SSL.
Submitted by Compaq.
2002-04-06 11:35:45 +00:00
Richard Levitte
313bf45e42 Make shared libraries resolve global symbols within themselves first.
Currently only on GNUish linkers...
Submitted by Steven Bade <sbade@austin.ibm.com>
2002-04-06 09:42:25 +00:00
Lutz Jänicke
ce34d0ac09 Fix buggy object definitions (Svenning Sorensen <sss@sss.dnsalias.net>).
Submitted by:
Reviewed by:
PR:
2002-04-04 17:49:39 +00:00
Richard Levitte
4e9dd6b0f5 Forgot one of the casts 2002-04-03 15:02:00 +00:00
Richard Levitte
b6ccbffe2b Cast the pointers to the BIGNUM data to unsigned long *. This would be
harmful if we didn't also pass the exact number of bytes of that data
2002-04-03 14:47:50 +00:00
Richard Levitte
1aecc34e9e Fix of mixup bwtween SOMAXCONN and SO_MAXCONN.
Furthermore, make SO_MAXCONN the first choice, since that's the standard
(as far as I know).
2002-03-29 23:48:43 +00:00
Lutz Jänicke
75b9c0044c Make short names of objects RFC2256-compliant.
Submitted by:
Reviewed by:
PR:
2002-03-26 17:15:32 +00:00
Richard Levitte
600b77a93f Add the possibility to enable olde des support, not just disable it, for future support. Redocument 2002-03-26 14:26:08 +00:00
Richard Levitte
39335c356b Add the mapping of des_random_seed() for 0.9.6 compatibility.
Make sure DES_cblock is defined at all times (meaning one shouldn't include
openssl/des_old.h directly any more).
2002-03-26 13:58:30 +00:00
Richard Levitte
a3c62bb737 Correct the mapping for des_read_pw() 2002-03-26 13:54:04 +00:00
Bodo Möller
2f6263a696 fix memory leak
Submitted by: Nils Larsch
2002-03-25 23:17:35 +00:00
Bodo Möller
35748f40d6 add missing declaration
Submitted by: Nils Larsch
2002-03-25 23:14:50 +00:00
Lutz Jänicke
ed62478192 Fix typo (Craig Davison <cd@securityfocus.com>).
Submitted by:
Reviewed by:
PR:
2002-03-25 17:11:25 +00:00
Bodo Möller
9e7733a743 fix conditational compilation for OPENSSL_NO_... 2002-03-22 11:02:45 +00:00
Richard Levitte
fc0bdd1aa8 Key schedules are given as arguments a bit differently in 0.9.6 and
earlier.  Also, it was an error to define crypt() at all times.
2002-03-22 10:46:13 +00:00
Richard Levitte
e9dad4048f Key schedules are given as arguments a bit differently in 0.9.6 and
earlier.  Also, a few 0.9.6 functions were missing their mappings.
2002-03-22 10:29:56 +00:00
Richard Levitte
ddba94214f Use the more modern DES API in the openssl subcommands. 2002-03-22 02:36:58 +00:00
Richard Levitte
e9f970891d Change des_old.h so OpenSSL 0.9.6 compatibility is default. One must
define OPENSSL_DES_LIBDES_COMPATIBILITY to get libdes compatibility.
At the same time, correct a couple of argument errors for the cfb
encryption routines.

Make destest use as much of the old API as possible, to make sure it
works properly.  Other tests will use the new API...
2002-03-22 02:33:24 +00:00
Lutz Jänicke
a89cf50c59 Fix buggy if-condition (thomas poindessous <poinde_t@epita.fr>).
Submitted by:
Reviewed by:
PR:
2002-03-21 19:17:06 +00:00
Lutz Jänicke
f90c544039 Remove superflous statement <justin.fletcher@ntlworld.com>.
Submitted by:
Reviewed by:
PR:
2002-03-21 19:10:07 +00:00
Bodo Möller
afcf54a5c9 fix DH_generate_parameters for general 'generator' 2002-03-20 16:02:46 +00:00
Lutz Jänicke
3671e38af4 Map new X509 verification errors to alert codes (Tom Wu <tom@arcot.com>).
Submitted by:
Reviewed by:
PR:
2002-03-19 16:44:26 +00:00
Dr. Stephen Henson
4fc3946111 Initialize ciph_ctx in kssl.c 2002-03-19 01:27:10 +00:00
Dr. Stephen Henson
59a941e4a4 Ensure EVP_CipherInit() uses the correct encode/decode parameter if
enc == -1

[Reported by Markus Friedl <markus@openbsd.org>]

Fix typo in dh_lib.c (use of DSAerr instead of DHerr).
2002-03-16 23:19:25 +00:00
Bodo Möller
a7cd5f3f38 Rename 'cray-t90-cc' into 'cray-j90'.
Add to 'config'.
2002-03-15 16:47:51 +00:00
Bodo Möller
0bdbc5a86e fix ssl3_pending 2002-03-15 10:52:03 +00:00
Lutz Jänicke
abecef77cf Add missing strength classification.
Submitted by:
Reviewed by:
PR:
2002-03-14 18:47:51 +00:00
Dr. Stephen Henson
b74dfe6e8e Initialize cipher context in KRB5
("D. Russell" <russelld@aol.net>)

Allow HMAC functions to use an alternative ENGINE.
2002-03-14 18:16:49 +00:00
Bodo Möller
d80f6e0f8c Fixes for 'no-hw' combined with 'no-SOME_CIPHER'.
Fix dsaparam usage output.

Submitted by: Nils Larsch (for 0.9.8-dev; backported to 0.9.7-dev)
2002-03-14 09:53:30 +00:00
Bodo Möller
13962f0b15 use BIO_nwrite() more properly 2002-03-14 09:48:32 +00:00
Bodo Möller
2fc1f3dd48 disable '#ifdef DEBUG' code 2002-03-14 09:35:15 +00:00
Dr. Stephen Henson
f2cbb15468 Undo previous patch: avoid warnings by #undef'ing
duplicate definitions.

Suggested by "Kenneth R. Robinette" <support@securenetterm.com>
2002-03-13 13:58:33 +00:00
Dr. Stephen Henson
e38e8b29f8 Fix Kerberos warnings with VC++. 2002-03-12 19:38:16 +00:00
Dr. Stephen Henson
c03ceadfbd Fix ASN1 additions for KRB5 2002-03-12 13:33:20 +00:00
Dr. Stephen Henson
e50baf58ab Fix various warnings when compiling with KRB5 code. 2002-03-12 03:00:59 +00:00
Bodo Möller
1750ec5c52 asm/mips3.o problems 2002-03-11 09:35:33 +00:00
Dr. Stephen Henson
c77bd28775 Make ciphers and digests obtain an ENGINE functional reference
if impl is explicitly supplied.
2002-03-09 18:56:38 +00:00
Dr. Stephen Henson
1619add90c Make {RSA,DSA,DH}_new_method obtain and release an ENGINE
functional reference.
2002-03-09 18:24:14 +00:00
Dr. Stephen Henson
a1a4e8b6bb typo 2002-03-08 19:12:38 +00:00
Dr. Stephen Henson
25f350a058 Fix the Win32_rename() function so it correctly
returns an error code. Use the same code in Win9X
and NT.

Fix some ca.c options so they work under Win32:
unlink/rename wont work under Win32 unless the file
is closed.
2002-03-08 19:06:36 +00:00
Richard Levitte
121cb9ee38 Synchronise the AEP engine in all branches. For 0.9.6-stable [engine], implement software fallback 2002-03-07 19:39:19 +00:00
Richard Levitte
bc173b9fb0 When closing, do not use close(). Also, if the closing call fails, do
not return immediately since that leaves a locked lock.
2002-03-07 17:13:49 +00:00
Richard Levitte
4fd9c70f06 Change des_old.c to use types prefixed with _ossl_old_des_. 2002-03-07 15:38:40 +00:00
Ben Laurie
91aeab0de3 ADH-DES-CBC-SHA should be LOW. 2002-03-06 16:59:12 +00:00
Dr. Stephen Henson
c913cf446f ENGINE module additions.
Add "init" command to control ENGINE
initialization.

Call ENGINE_finish on initialized ENGINEs on exit.

Reorder shutdown in apps.c: modules should be shut
down first.

Add test private key loader to openssl ENGINE: this
just loads a private key in PEM format.

Fix print format for dh length parameter.
2002-03-06 14:09:46 +00:00
Richard Levitte
a88f39457b OpenSSL currently fails on certain pure 64-bit architectures. This is a showstopper 2002-03-06 06:25:21 +00:00
Bodo Möller
2bbaab4a24 Rephrase statement on the security of two-key 3DES.
[Chosen plaintext attack: R. Merkle, M. Hellman: "On the Security of
  Multiple Encryption", CACM 24 (1981) pp. 465-467, p. 776.

  Known plaintext angriff: P.C. van Oorschot, M. Wiener: "A
  known-plaintext attack on two-key triple encryption", EUROCRYPT '90.]
2002-03-05 15:30:13 +00:00
Bodo Möller
1a8f4b57a9 fix printf call 2002-03-05 15:05:17 +00:00
Bodo Möller
022b31a8c8 typo 2002-03-05 15:03:16 +00:00
Dr. Stephen Henson
dd6b494eb3 Make sure the type accessed by the LONG and ZLONG ASN1 type
is really a long, to avoid problems on platforms where
sizeof(int) != sizeof(long).
2002-03-05 13:49:27 +00:00
Richard Levitte
c9bea5bad3 Provide a pre 0.9.7 compatibility mapping if
OPENSSL_DES_PRE_0_9_7_COMPATIBILITY is defined.  NOT AT ALL TESTED YET!
Add a comment as to the libdes compatibility.
2002-03-05 11:25:46 +00:00
Richard Levitte
296324ea03 New configuration targets for OpenBSD, handed to me by Bob Beck <beck@openbsd.org> 2002-03-05 09:43:09 +00:00
Bodo Möller
fa41e86a28 '#if OPENSSL_VERSION_NUMBER >= ...' to document the recent change 2002-03-05 09:06:57 +00:00
Richard Levitte
9e77b7075a A dash was missing in this branch as well. 2002-03-04 18:09:10 +00:00
Richard Levitte
5c7f9a627f Rename des_SPtrans to DES_SPtrans to differentiate from libdes and avoid certain linkage clashes. 2002-03-04 16:08:53 +00:00
Richard Levitte
bc3e3472c1 Make it so one can select tests from within the test directory 2002-03-04 15:59:05 +00:00
Dr. Stephen Henson
66bd86e2c2 Fix warnings about signed/unsigned mismatch and global
shadowing (random, index) in hw_4758.c
2002-03-03 17:07:27 +00:00
Ben Laurie
487fe20490 OpenBSD variant. 2002-03-01 15:39:29 +00:00
Richard Levitte
80d9b1ccd7 Remove the perl/ subdirectory. It hasn't been worked on for ages, is
very broken, and there are working modules in CPAN, which makes our
module even more moot.
2002-02-28 22:06:26 +00:00
Richard Levitte
69c48301e0 make update 2002-02-28 20:28:23 +00:00
Bodo Möller
2be9b88135 use ERR_peek_last_error() instead of ERR_peek_error() 2002-02-28 14:10:13 +00:00
Bodo Möller
98fa4fce09 use ERR_peek_last_error() instead of ERR_peek_error() to ignore
any other errors that may be left in the error queue

Submitted by: Jeffrey Altman
2002-02-28 14:03:41 +00:00
Richard Levitte
1ec1d17e16 VMS addaptation, including a few more long names that needed hacking. 2002-02-28 13:18:47 +00:00
Richard Levitte
1e11df0dc3 Make sure aep_close_connection() is declared and has a prototype that's
consistent with the rest of the AEP functions
2002-02-28 12:59:03 +00:00
Richard Levitte
421d474332 Increase internal security when using strncpy, by making sure the resulting string is NUL-terminated 2002-02-28 12:44:05 +00:00
Richard Levitte
58060fa11b Updated AEP engine, submitted by Diarmuid O'Neill <Diarmuid.ONeill@aep.ie> 2002-02-28 11:37:35 +00:00
Richard Levitte
cea698f19c Document the added modes for AES 2002-02-28 11:30:42 +00:00
Bodo Möller
48781ef7f7 Add 'void *' argument to app_verify_callback.
Submitted by: D. K. Smetters <smetters@parc.xerox.com>
Reviewed by: Bodo Moeller
2002-02-28 10:55:52 +00:00
Geoff Thorpe
6d1a837df7 This adds a new ENGINE to support IBM 4758 cards, contributed by Maurice
Gittens.
2002-02-27 22:45:48 +00:00
Lutz Jänicke
21f422ca5e Fix the fix (Yoram Zahavi)...
Submitted by:
Reviewed by:
PR:
2002-02-27 11:24:39 +00:00
Lutz Jänicke
291ae60b52 SSL_clear != SSL_free/SSL_new
Submitted by:
Reviewed by:
PR:
2002-02-27 08:10:12 +00:00
Lutz Jänicke
3b79d2789d Make sure that bad sessions are removed in SSL_clear() (found by
Yoram Zahavi).
Submitted by:
Reviewed by:
PR:
2002-02-26 21:44:07 +00:00
Dr. Stephen Henson
bb9dcc99cf Always init ctx_tmp in PKCS7_dataFinal since it is always cleaned up. 2002-02-26 19:32:16 +00:00
Richard Levitte
3d59821134 make update 2002-02-26 14:37:25 +00:00
Dr. Stephen Henson
cae111287b Fix new -aes command argument handling 2002-02-26 13:45:19 +00:00
Dr. Stephen Henson
e36e473859 Make the engine config module always add dynamic ENGINEs
to the list using dynamic_path. This stops ENGINEs which
don't supply any default algorithms being automatically
freed (because they have no references) and allows them
to be accessed by id.

Alternative dynamic loading behaviour can be achieved by
issuing the dynamic ENGINE ctrls separately in the config file.
2002-02-24 16:22:20 +00:00
Dr. Stephen Henson
d7fb66aa82 Remove old comment 2002-02-23 13:43:07 +00:00
Dr. Stephen Henson
344b3b5ce1 OPENSSL_LOAD_CONF define as in main trunk 2002-02-23 02:09:29 +00:00
Dr. Stephen Henson
3f7cf29124 Update from main branch. 2002-02-23 01:47:59 +00:00
cvs2svn
63dc69fef6 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-02-23 01:00:45 +00:00
Dr. Stephen Henson
cfe1c195c4 non-Monolith fixes.
Submitted by Andrew W. Gray <agray@iconsinc.com>
2002-02-22 21:27:47 +00:00
Dr. Stephen Henson
0cd8572b2d Config code updates.
CONF_modules_unload() now calls CONF_modules_finish()
automatically.

Default use of section openssl_conf moved to
CONF_modules_load()

Load config file in several openssl utilities.

Most utilities now load modules from the config file,
though in a few (such as version) this isn't done
because it couldn't be used for anything.

In the case of ca and req the config file used is
the same as the utility itself: that is the -config
command line option can be used to specify an
alternative file.
2002-02-22 13:58:15 +00:00
Richard Levitte
7c2831ac90 We have AES support in openssl speed 2002-02-21 17:23:08 +00:00
Bodo Möller
de603b75fc disable '#ifdef DEBUG' sections 2002-02-21 14:08:47 +00:00
Bodo Möller
1244be2eda disable '#ifdef DEBUG' sections 2002-02-21 13:00:45 +00:00
Richard Levitte
9f0a373b51 Add AES support in the applications that support -des and -des3. 2002-02-20 18:04:17 +00:00
Richard Levitte
b0701709c1 Add comfy aliases for AES in CBC mode. 2002-02-20 18:00:23 +00:00
Richard Levitte
34aa216a65 Stop assuming the IV is 8 bytes long, use the real size instead.
This is especially important for AES that has a 16 bytes IV.
2002-02-20 17:56:01 +00:00
Richard Levitte
a76a29f233 Merge in recent changes from the main trunk. 2002-02-20 17:53:17 +00:00
Richard Levitte
4e06ab75e8 Including openssl/e_os.h in the OpenSSL 0.9.6 branch is legal, since
it's exported.  Changing that is a BIG step, which has been done in
0.9.7-dev.
2002-02-20 17:40:33 +00:00
Richard Levitte
26147fb954 Merge in recent changes from the main trunk. 2002-02-20 13:20:32 +00:00
Richard Levitte
bd53a054b1 Merg in recent changes from the main trunk. 2002-02-20 12:28:32 +00:00
Bodo Möller
211b8685d3 bugfix: allocate sufficiently large buffer
Submitted by: Nils Larsch
2002-02-20 11:58:17 +00:00
Dr. Stephen Henson
9c75b2d931 Use default openssl.cnf if config filename set to NULL and
openssl_conf if appname NULL.
2002-02-19 23:25:18 +00:00
Richard Levitte
54d11e6057 Merge in Cygwin-related changes from main trunk. 2002-02-16 22:44:30 +00:00
Richard Levitte
3d7ba69a05 The AES modes OFB and CFB are defined with 128 feedback bits. This
deviates from the "standard" 64 bits of feedback that all other
algorithms are using.  Therefore, let's redo certain EVP macros to
accept different amounts of feedback bits for these modes.

Also, change e_aes.c to provide all usually available modes for AES.
CTR isn't included yet.
2002-02-16 12:39:58 +00:00
Richard Levitte
58133d22a8 Add the modes OFB128, CFB128 and CTR128 to AES.
Submitted by Stephen Sprunk <stephen@sprunk.org>
2002-02-16 12:21:43 +00:00
cvs2svn
330e5c5460 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-02-16 12:20:35 +00:00
Richard Levitte
ab519c8262 Adjust the NID names for the AES modes OFB and CFB to contain the number
of feedback bits
2002-02-16 12:16:43 +00:00
Richard Levitte
65f29a78b2 Give the linux-sparv9 target shared capability.
Submitted by Ian Marsh <mushypea@dominion.net.uk>
2002-02-15 16:23:50 +00:00
Bodo Möller
c363b5a62f constify 2002-02-15 10:19:22 +00:00
Bodo Möller
60ed0f94ed mention EC library 2002-02-15 10:12:01 +00:00
Lutz Jänicke
f38f8d94a9 Even though it is not really practical people should know about it.
Submitted by:
Reviewed by:
PR:
2002-02-15 07:44:44 +00:00
cvs2svn
679eb352e0 This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-02-15 07:41:46 +00:00
Dr. Stephen Henson
80bbb6578e Add flag to disable config module DSO loading. 2002-02-15 02:43:50 +00:00
Dr. Stephen Henson
19cc0f0ab4 Only initialize cipher ctx if cipher is not NULL. 2002-02-15 01:01:36 +00:00
Dr. Stephen Henson
14e14ea68c Allow a NULL store parameter to X509_STORE_CTX_init(). 2002-02-15 00:58:14 +00:00
Dr. Stephen Henson
834d37ed86 Don't call finish function if it isn't set.
Fix OID module.
2002-02-15 00:33:35 +00:00
Dr. Stephen Henson
adcc235ef6 Update NEWS 2002-02-15 00:12:44 +00:00
Dr. Stephen Henson
86a0d0234d Add argument to OPENSSL_config() and add flag to
tolerate missing config file.
2002-02-14 23:39:36 +00:00
Dr. Stephen Henson
4598be561a typo (?) 2002-02-14 18:52:37 +00:00
Dr. Stephen Henson
af5db47e99 Fix warnings:
#if out some unused function.

"index" is a global function on some platforms.
2002-02-14 18:46:12 +00:00
Richard Levitte
fb67f40f04 Add the configuration target VxWorks. 2002-02-14 16:23:55 +00:00
Bodo Möller
48033c3242 fix: make it possible to disable memory debugging even if it is
enabled by default
2002-02-14 14:47:15 +00:00
Bodo Möller
aa1f5b3581 don't call OPENSSL_config(), this does not make any sense during "make test" 2002-02-14 13:52:11 +00:00
Richard Levitte
d9d3a69595 Make sure memset() is defined by including string.h
Notified by Oscar Jacobsson <oscar@jacobsson.org>
2002-02-14 13:51:13 +00:00
Richard Levitte
f9adfa6d4e For some reason, getting the topmost error was done the same way as
getting the bottommost one.  I hope I understood correctly how this
should be done.  It seems to work when running evp_test in an
environment where it can't find openssl.cnf.
2002-02-14 13:42:33 +00:00
Richard Levitte
85b1fce1ef make update 2002-02-14 13:37:14 +00:00
Richard Levitte
da566db150 The Cygwin shared extension was shifted. 2002-02-14 13:36:13 +00:00
Richard Levitte
be37dc73f6 At Corinna Vinschen's request, change CygWin32 to Cygwin 2002-02-14 12:29:32 +00:00
Richard Levitte
976b2c9c2f Because making the key strong by xoring the last byte with 0xF0
generates different keys than previous versions of OpenSSL and libdes,
let's make Assar's change experimental for now.
2002-02-14 02:43:57 +00:00
Richard Levitte
b74d2cda28 Correct sh, please 2002-02-14 02:20:48 +00:00
Bodo Möller
cc5dd9f14e it's year 2002 now 2002-02-13 18:22:49 +00:00
cvs2svn
fbfcdc4cef This commit was manufactured by cvs2svn to create branch
'OpenSSL_0_9_7-stable'.
2002-02-13 14:44:34 +00:00
278 changed files with 6070 additions and 30827 deletions

View File

@ -1,3 +1,4 @@
openssl.pc
Makefile.ssl
MINFO
makefile.one

315
CHANGES
View File

@ -2,321 +2,6 @@
OpenSSL CHANGES
_______________
Changes between 0.9.7 and 0.9.8 [xx XXX 2002]
*) Make it possible to inhibit symlinking of shared libraries in
Makefile.shared, for Cygwin's sake.
[Richard Levitte]
*) Extend the BIGNUM API by creating new macros that behave like
functions
void BN_set_sign(BIGNUM *a, int neg);
int BN_get_sign(const BIGNUM *a);
and avoid the need to access 'a->neg' directly in applications.
[Nils Larsch <nla@trustcenter.de>]
*) Implement fast modular reduction for pseudo-Mersenne primes
used in NIST curves (crypto/bn/bn_nist.c, crypto/ec/ecp_nist.c).
EC_GROUP_new_curve_GFp() will now automatically use this
if applicable.
[Nils Larsch <nla@trustcenter.de>]
*) Add new lock type (CRYPTO_LOCK_BN).
[Bodo Moeller]
*) Change the ENGINE framework to automatically load engines
dynamically from specific directories unless they could be
found to already be built in or loaded. Move all the
current engines except for the cryptodev one to a new
directory engines/.
The engines in engines/ are built as shared libraries if
the "shared" options was given to ./Configure or ./config.
Otherwise, they are inserted in libcrypto.a.
/usr/local/ssl/engines is the default directory for dynamic
engines, but that can be overriden at configure time through
the usual use of --prefix and/or --openssldir, and at run
time with the environment variable OPENSSL_ENGINES.
[Geoff Thorpe and Richard Levitte]
*) Add Makefile.shared, a helper makefile to build shared
libraries. Addapt Makefile.org.
[Richard Levitte]
*) Add version info to Win32 DLLs.
[Peter 'Luna' Runestig" <peter@runestig.com>]
*) Add new 'medium level' PKCS#12 API. Certificates and keys
can be added using this API to created arbitrary PKCS#12
files while avoiding the low level API.
New options to PKCS12_create(), key or cert can be NULL and
will then be omitted from the output file. The encryption
algorithm NIDs can be set to -1 for no encryption, the mac
iteration count can be set to 0 to omit the mac.
Enhance pkcs12 utility by making the -nokeys and -nocerts
options work when creating a PKCS#12 file. New option -nomac
to omit the mac, NONE can be set for an encryption algorithm.
New code is modified to use the enhanced PKCS12_create()
instead of the low level API.
[Steve Henson]
*) Extend ASN1 encoder to support indefinite length constructed
encoding. This can output sequences tags and octet strings in
this form. Modify pk7_asn1.c to support indefinite length
encoding. This is experimental and needs additional code to
be useful, such as an ASN1 bio and some enhanced streaming
PKCS#7 code.
Extend template encode functionality so that tagging is passed
down to the template encoder.
[Steve Henson]
*) Let 'openssl req' fail if an argument to '-newkey' is not
recognized instead of using RSA as a default.
[Bodo Moeller]
*) Add support for ECC-based ciphersuites from draft-ietf-tls-ecc-01.txt.
As these are not official, they are not included in "ALL";
the "ECCdraft" ciphersuite group alias can be used to select them.
[Vipul Gupta and Sumit Gupta (Sun Microsystems Laboratories)]
*) Add ECDH engine support.
[Nils Gura and Douglas Stebila (Sun Microsystems Laboratories)]
*) Add ECDH in new directory crypto/ecdh/.
TODO: more general interface (return x coordinate, not its hash)
TODO: bug: pad x with leading zeros if necessary
[Douglas Stebila (Sun Microsystems Laboratories)]
*) Let BN_rand_range() abort with an error after 100 iterations
without success (which indicates a broken PRNG).
[Bodo Moeller]
*) Change BN_mod_sqrt() so that it verifies that the input value
is really the square of the return value. (Previously,
BN_mod_sqrt would show GIGO behaviour.)
[Bodo Moeller]
*) Add named elliptic curves over binary fields from X9.62, SECG,
and WAP/WTLS; add OIDs that were still missing.
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) Extend the EC library for elliptic curves over binary fields
(new files ec2_smpl.c, ec2_smpt.c, ec2_mult.c in crypto/ec/).
New EC_METHOD:
EC_GF2m_simple_method
New API functions:
EC_GROUP_new_curve_GF2m
EC_GROUP_set_curve_GF2m
EC_GROUP_get_curve_GF2m
EC_POINT_set_affine_coordinates_GF2m
EC_POINT_get_affine_coordinates_GF2m
EC_POINT_set_compressed_coordinates_GF2m
Point compression for binary fields is disabled by default for
patent reasons (compile with OPENSSL_EC_BIN_PT_COMP defined to
enable it).
As binary polynomials are represented as BIGNUMs, various members
of the EC_GROUP and EC_POINT data structures can be shared
between the implementations for prime fields and binary fields;
the above ..._GF2m functions (except for EX_GROUP_new_curve_GF2m)
are essentially identical to their ..._GFp counterparts.
(For simplicity, the '..._GFp' prefix has been dropped from
various internal method names.)
An internal 'field_div' method (similar to 'field_mul' and
'field_sqr') has been added; this is used only for binary fields.
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) Optionally dispatch EC_POINT_mul(), EC_POINT_precompute_mult()
through methods ('mul', 'precompute_mult').
The generic implementations (now internally called 'ec_wNAF_mul'
and 'ec_wNAF_precomputed_mult') remain the default if these
methods are undefined.
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) New function EC_GROUP_get_degree, which is defined through
EC_METHOD. For curves over prime fields, this returns the bit
length of the modulus.
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) New functions EC_GROUP_dup, EC_POINT_dup.
(These simply call ..._new and ..._copy).
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) Add binary polynomial arithmetic software in crypto/bn/bn_gf2m.c.
Polynomials are represented as BIGNUMs (where the sign bit is not
used) in the following functions [macros]:
BN_GF2m_add
BN_GF2m_sub [= BN_GF2m_add]
BN_GF2m_mod [wrapper for BN_GF2m_mod_arr]
BN_GF2m_mod_mul [wrapper for BN_GF2m_mod_mul_arr]
BN_GF2m_mod_sqr [wrapper for BN_GF2m_mod_sqr_arr]
BN_GF2m_mod_inv
BN_GF2m_mod_exp [wrapper for BN_GF2m_mod_exp_arr]
BN_GF2m_mod_sqrt [wrapper for BN_GF2m_mod_sqrt_arr]
BN_GF2m_mod_solve_quad [wrapper for BN_GF2m_mod_solve_quad_arr]
BN_GF2m_cmp [= BN_ucmp]
(Note that only the 'mod' functions are actually for fields GF(2^m).
BN_GF2m_add() is misnomer, but this is for the sake of consistency.)
For some functions, an the irreducible polynomial defining a
field can be given as an 'unsigned int[]' with strictly
decreasing elements giving the indices of those bits that are set;
i.e., p[] represents the polynomial
f(t) = t^p[0] + t^p[1] + ... + t^p[k]
where
p[0] > p[1] > ... > p[k] = 0.
This applies to the following functions:
BN_GF2m_mod_arr
BN_GF2m_mod_mul_arr
BN_GF2m_mod_sqr_arr
BN_GF2m_mod_inv_arr [wrapper for BN_GF2m_mod_inv]
BN_GF2m_mod_div_arr [wrapper for BN_GF2m_mod_div]
BN_GF2m_mod_exp_arr
BN_GF2m_mod_sqrt_arr
BN_GF2m_mod_solve_quad_arr
BN_GF2m_poly2arr
BN_GF2m_arr2poly
Conversion can be performed by the following functions:
BN_GF2m_poly2arr
BN_GF2m_arr2poly
bntest.c has additional tests for binary polynomial arithmetic.
Two implementations for BN_GF2m_mod_div() are available.
The default algorithm simply uses BN_GF2m_mod_inv() and
BN_GF2m_mod_mul(). The alternative algorithm is compiled in only
if OPENSSL_SUN_GF2M_DIV is defined (patent pending; read the
copyright notice in crypto/bn/bn_gf2m.c before enabling it).
[Sheueling Chang Shantz and Douglas Stebila
(Sun Microsystems Laboratories)]
*) Add new error code 'ERR_R_DISABLED' that can be used when some
functionality is disabled at compile-time.
[Douglas Stebila <douglas.stebila@sun.com>]
*) Change default behaviour of 'openssl asn1parse' so that more
information is visible when viewing, e.g., a certificate:
Modify asn1_parse2 (crypto/asn1/asn1_par.c) so that in non-'dump'
mode the content of non-printable OCTET STRINGs is output in a
style similar to INTEGERs, but with '[HEX DUMP]' prepended to
avoid the appearance of a printable string.
[Nils Larsch <nla@trustcenter.de>]
*) Add 'asn1_flag' and 'asn1_form' member to EC_GROUP with access
functions
EC_GROUP_set_asn1_flag()
EC_GROUP_get_asn1_flag()
EC_GROUP_set_point_conversion_form()
EC_GROUP_get_point_conversion_form()
These control ASN1 encoding details:
- Curves (i.e., groups) are encoded explicitly unless asn1_flag
has been set to OPENSSL_EC_NAMED_CURVE.
- Points are encoded in uncompressed form by default; options for
asn1_for are as for point2oct, namely
POINT_CONVERSION_COMPRESSED
POINT_CONVERSION_UNCOMPRESSED
POINT_CONVERSION_HYBRID
Also add 'seed' and 'seed_len' members to EC_GROUP with access
functions
EC_GROUP_set_seed()
EC_GROUP_get0_seed()
EC_GROUP_get_seed_len()
This is used only for ASN1 purposes (so far).
[Nils Larsch <nla@trustcenter.de>]
*) Add 'field_type' member to EC_METHOD, which holds the NID
of the appropriate field type OID. The new function
EC_METHOD_get_field_type() returns this value.
[Nils Larsch <nla@trustcenter.de>]
*) Add functions
EC_POINT_point2bn()
EC_POINT_bn2point()
EC_POINT_point2hex()
EC_POINT_hex2point()
providing useful interfaces to EC_POINT_point2oct() and
EC_POINT_oct2point().
[Nils Larsch <nla@trustcenter.de>]
*) Change internals of the EC library so that the functions
EC_GROUP_set_generator()
EC_GROUP_get_generator()
EC_GROUP_get_order()
EC_GROUP_get_cofactor()
are implemented directly in crypto/ec/ec_lib.c and not dispatched
to methods, which would lead to unnecessary code duplication when
adding different types of curves.
[Nils Larsch <nla@trustcenter.de> with input by Bodo Moeller]
*) Implement compute_wNAF (crypto/ec/ec_mult.c) without BIGNUM
arithmetic, and such that modified wNAFs are generated
(which avoid length expansion in many cases).
[Bodo Moeller]
*) Add a function EC_GROUP_check_discriminant() (defined via
EC_METHOD) that verifies that the curve discriminant is non-zero.
Add a function EC_GROUP_check() that makes some sanity tests
on a EC_GROUP, its generator and order. This includes
EC_GROUP_check_discriminant().
[Nils Larsch <nla@trustcenter.de>]
*) Add ECDSA in new directory crypto/ecdsa/.
Add applications 'openssl ecparam' and 'openssl ecdsa'
(these are based on 'openssl dsaparam' and 'openssl dsa').
ECDSA support is also included in various other files across the
library. Most notably,
- 'openssl req' now has a '-newkey ecdsa:file' option;
- EVP_PKCS82PKEY (crypto/evp/evp_pkey.c) now can handle ECDSA;
- X509_PUBKEY_get (crypto/asn1/x_pubkey.c) and
d2i_PublicKey (crypto/asn1/d2i_pu.c) have been modified to make
them suitable for ECDSA where domain parameters must be
extracted before the specific public key;
- ECDSA engine support has been added.
[Nils Larsch <nla@trustcenter.de>]
*) Include some named elliptic curves, and add OIDs from X9.62,
SECG, and WAP/WTLS. Each curve can be obtained from the new
function
EC_GROUP_new_by_nid(),
and the list of available named curves can be obtained with
EC_get_builtin_curves().
Also add a 'curve_name' member to EC_GROUP objects, which can be
accessed via
EC_GROUP_set_nid()
EC_GROUP_get_nid()
[Nils Larsch <nla@trustcenter.de, Bodo Moeller]
Changes between 0.9.6h and 0.9.7 [XX xxx 2002]
*) Add the VC-CE target, introduce the WINCE sysname, and add

View File

@ -759,27 +759,6 @@ PROCESS_ARGS:
$depflags .= "-DOPENSSL_NO_MDC2 ";
$openssl_algorithm_defines .= "#define OPENSSL_NO_MDC2\n";
}
if ($algo eq "EC")
{
push @skip, "ecdsa";
push @skip, "ecdh";
$options .= " no-ecdsa";
$options .= " no-ecdh";
$flags .= "-DOPENSSL_NO_ECDSA ";
$flags .= "-DOPENSSL_NO_ECDH ";
$depflags .= "-DOPENSSL_NO_ECDSA ";
$depflags .= "-DOPENSSL_NO_ECDH ";
$openssl_algorithm_defines .= "#define OPENSSL_NO_ECDSA\n";
$openssl_algorithm_defines .= "#define OPENSSL_NO_ECDH\n";
}
if ($algo eq "SHA" || $algo eq "SHA1")
{
push @skip, "ecdsa";
$options .= " no-ecdsa";
$flags .= "-DOPENSSL_NO_ECDSA ";
$depflags .= "-DOPENSSL_NO_ECDSA ";
$openssl_algorithm_defines .= "#define OPENSSL_NO_ECDSA\n";
}
if ($algo eq "MD5")
{
$no_md5 = 1;
@ -1124,17 +1103,6 @@ else
$no_shared = 1;
}
if ($no_shared)
{
$cflags="-DOPENSSL_NO_DYNAMIC_ENGINE $cflags";
$openssl_other_defines.="#define OPENSSL_NO_DYNAMIC_ENGINE\n";
}
else
{
$cflags="-DOPENSSL_NO_STATIC_ENGINE $cflags";
$openssl_other_defines.="#define OPENSSL_NO_STATIC_ENGINE\n";
}
if ($sys_id ne "")
{
$cflags="-DOPENSSL_SYSNAME_$sys_id $cflags";
@ -1179,7 +1147,6 @@ if ($rmd160_obj =~ /\.o$/)
$cflags =~ s/([\\\"])/\\\1/g;
my $version = "unknown";
my $version_num = "unknown";
my $major = "unknown";
my $minor = "unknown";
my $shlib_version_number = "unknown";
@ -1191,7 +1158,6 @@ open(IN,'<crypto/opensslv.h') || die "unable to read opensslv.h:$!\n";
while (<IN>)
{
$version=$1 if /OPENSSL.VERSION.TEXT.*OpenSSL (\S+) /;
$version_num=$1 if /OPENSSL.VERSION.NUMBER.*0x(\S+)/;
$shlib_version_number=$1 if /SHLIB_VERSION_NUMBER *"([^"]+)"/;
$shlib_version_history=$1 if /SHLIB_VERSION_HISTORY *"([^"]*)"/;
}
@ -1524,68 +1490,6 @@ EOF
}
}
# create the ms/version32.rc file if needed
if ($IsWindows) {
my ($v1, $v2, $v3, $v4);
if ($version_num =~ /(^[0-9a-f]{1})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i) {
$v1=hex $1;
$v2=hex $2;
$v3=hex $3;
$v4=hex $4;
}
open (OUT,">ms/version32.rc") || die "Can't open ms/version32.rc";
print OUT <<EOF;
#include <winver.h>
LANGUAGE 0x09,0x01
1 VERSIONINFO
FILEVERSION $v1,$v2,$v3,$v4
PRODUCTVERSION $v1,$v2,$v3,$v4
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x01L
#else
FILEFLAGS 0x00L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
// Required:
VALUE "CompanyName", "The OpenSSL Project, http://www.openssl.org/\\0"
VALUE "FileDescription", "OpenSSL Shared Library\\0"
VALUE "FileVersion", "$version\\0"
#if defined(CRYPTO)
VALUE "InternalName", "libeay32\\0"
VALUE "OriginalFilename", "libeay32.dll\\0"
#elif defined(SSL)
VALUE "InternalName", "ssleay32\\0"
VALUE "OriginalFilename", "ssleay32.dll\\0"
#endif
VALUE "ProductName", "The OpenSSL Toolkit\\0"
VALUE "ProductVersion", "$version\\0"
// Optional:
//VALUE "Comments", "\\0"
VALUE "LegalCopyright", "Copyright © 1998-2002 The OpenSSL Project. Copyright © 1995-1998 Eric A. Young, Tim J. Hudson. All rights reserved.\\0"
//VALUE "LegalTrademarks", "\\0"
//VALUE "PrivateBuild", "\\0"
//VALUE "SpecialBuild", "\\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 0x4b0
END
END
EOF
close(OUT);
}
print <<EOF;
Configured for $target.

View File

@ -8,6 +8,9 @@
* wcecompat compatibility library (www.essemer.com.au)
* Optionally ceutils for running automated tests (www.essemer.com.au)
You also need Perl for Win32. You will need ActiveState Perl, available
from http://www.activestate.com/ActivePerl.
The C Runtime Library implementation for Windows CE that is included with
Microsoft eMbedded Visual C++ 3.0 is incomplete and in some places
incorrect. wcecompat plugs the holes and tries to bring the Windows CE
@ -20,9 +23,6 @@
Building
--------
You need Perl for Win32. Unless you will build on Cygwin, you will need
ActiveState Perl, available from http://www.activestate.com/ActivePerl.
Setup the eMbedded Visual C++ environment. There are batch files for doing
this installed with eVC++. For an ARM processor, for example, execute:
@ -61,3 +61,8 @@
> cd out32
> ..\ms\testce
This will copy each of the test programs to the Windows CE device and execute
them, displaying the output of the tests on this computer. The output should
look similar to the output produced by running the tests for a regular Windows
build.

View File

@ -156,14 +156,18 @@ RMD160_ASM_OBJ= asm/rm86-out.o
KRB5_INCLUDES=
LIBKRB5=
DIRS= crypto ssl engines apps test tools
# When we're prepared to use shared libraries in the programs we link here
# we might set SHLIB_MARK to '$(SHARED_LIBS)'.
SHLIB_MARK=
DIRS= crypto ssl $(SHLIB_MARK) apps test tools
SHLIBDIRS= crypto ssl
# dirs in crypto to build
SDIRS= \
md2 md4 md5 sha mdc2 hmac ripemd \
des rc2 rc4 rc5 idea bf cast \
bn ec rsa dsa ecdsa dh ecdh dso engine aes \
bn ec rsa dsa dh dso engine aes \
buffer bio stack lhash rand err objects \
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5
@ -172,8 +176,7 @@ SDIRS= \
TESTS = alltests
MAKEFILE= Makefile.ssl
NEWMAKE= make
MAKE= $(NEWMAKE) -f Makefile.ssl
MAKE= make -f Makefile.ssl
MANDIR=$(OPENSSLDIR)/man
MAN1=1
@ -199,33 +202,21 @@ WTARFILE= $(NAME)-win.tar
EXHEADER= e_os2.h
HEADER= e_os.h
all: Makefile.ssl build_all openssl.pc
# When we're prepared to use shared libraries in the programs we link here
# we might remove 'clean-shared' from the targets to perform at this stage
BUILD_CMD=if echo " $(DIRS) " | grep " $$i " >/dev/null 2>/dev/null; then \
all: Makefile.ssl sub_all openssl.pc
sub_all:
@for i in $(DIRS); \
do \
if [ -d "$$i" ]; then \
(cd $$i && echo "making all in $$i..." && \
$(MAKE) CC='${CC}' PLATFORM='${PLATFORM}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' KRB5_INCLUDES='${KRB5_INCLUDES}' LIBKRB5='${LIBKRB5}' EXE_EXT='${EXE_EXT}' SHARED_LIBS='${SHARED_LIBS}' SHLIB_EXT='${SHLIB_EXT}' SHLIB_TARGET='${SHLIB_TARGET}' all ) || exit 1; \
else \
$(MAKE) $$i; \
fi; fi
sub_all: build_all
build_all: build_libs build_apps build_tests build_tools
build_libs: build_crypto build_ssl build_engines
build_crypto:
@i=crypto; $(BUILD_CMD)
build_ssl:
@i=ssl; $(BUILD_CMD)
build_engines:
@i=engines; $(BUILD_CMD)
build_apps:
@i=apps; $(BUILD_CMD)
build_tests:
@i=test; $(BUILD_CMD)
build_tools:
@i=tools; $(BUILD_CMD)
fi; \
done;
libcrypto$(SHLIB_EXT): libcrypto.a
@if [ "$(SHLIB_TARGET)" != "" ]; then \
@ -251,31 +242,276 @@ clean-shared:
fi; \
( set -x; rm -f lib$$i$(SHLIB_EXT) ); \
if [ "$(PLATFORM)" = "Cygwin" ]; then \
( set -x; rm -f cyg$$i$(SHLIB_EXT) lib$$i$(SHLIB_EXT).a ); \
( set -x; rm -f cyg$$i-$(SHLIB_VERSION_NUMBER)$(SHLIB_EXT) lib$$i$(SHLIB_EXT).a ); \
fi; \
done
link-shared:
@ for i in ${SHLIBDIRS}; do \
$(NEWMAKE) -f Makefile.shared \
LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
symlink.$(SHLIB_TARGET); \
libs="$$libs -l$$i"; \
@if [ -n "$(SHARED_LIBS_LINK_EXTS)" ]; then \
tmp="$(SHARED_LIBS_LINK_EXTS)"; \
for i in $(SHLIBDIRS); do \
prev=lib$$i$(SHLIB_EXT); \
for j in $${tmp:-x}; do \
( set -x; \
rm -f lib$$i$$j; ln -s $$prev lib$$i$$j ); \
prev=lib$$i$$j; \
done; \
done; \
fi
build-shared: clean-shared do_$(SHLIB_TARGET) link-shared
do_bsd-gcc-shared: do_gnu-shared
do_linux-shared: do_gnu-shared
do_gnu-shared:
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} ${SHARED_LDFLAGS} \
-shared -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-Wl,-soname=lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-Wl,-Bsymbolic \
-Wl,--whole-archive lib$$i.a \
-Wl,--no-whole-archive $$libs ${EX_LIBS} -lc ) || exit 1; \
libs="$$libs -l$$i"; \
done
build-shared: do_$(SHLIB_TARGET) link-shared
DETECT_GNU_LD=${CC} -v 2>&1 | grep '^gcc' >/dev/null 2>&1 && \
my_ld=`${CC} -print-prog-name=ld 2>&1` && \
[ -n "$$my_ld" ] && \
$$my_ld -v 2>&1 | grep 'GNU ld' >/dev/null 2>&1
do_$(SHLIB_TARGET):
@ libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
$(NEWMAKE) -f Makefile.shared \
CC="$(CC)" LDFLAGS="$(LDFLAGS)" \
SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
LIBNAME=$$i LIBVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR} \
LIBCOMPATVERSIONS=";${SHLIB_VERSION_HISTORY}" \
LIBDEPS="$$libs $(EX_LIBS)" \
link_a.$(SHLIB_TARGET); \
# For Darwin AKA Mac OS/X (dyld)
do_darwin-shared:
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x ; ${CC} --verbose -dynamiclib -o lib$$i${SHLIB_EXT} \
lib$$i.a $$libs -all_load -current_version ${SHLIB_MAJOR}.${SHLIB_MINOR} \
-compatibility_version ${SHLIB_MAJOR}.`echo ${SHLIB_MINOR} | cut -d. -f1` \
-install_name ${INSTALLTOP}/lib/lib$$i${SHLIB_EXT} ) || exit 1; \
libs="$$libs -l`basename $$i${SHLIB_EXT} .dylib`"; \
echo "" ; \
done
do_cygwin-shared:
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} -shared -o cyg$$i-$(SHLIB_VERSION_NUMBER).dll \
-Wl,-Bsymbolic \
-Wl,--whole-archive lib$$i.a \
-Wl,--out-implib,lib$$i.dll.a \
-Wl,--no-whole-archive $$libs ) || exit 1; \
libs="$$libs -l$$i"; \
done
# This assumes that GNU utilities are *not* used
do_alpha-osf1-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} ${SHARED_LDFLAGS} \
-shared -o lib$$i.so \
-set_version "${SHLIB_VERSION_HISTORY}${SHLIB_VERSION_NUMBER}" \
-all lib$$i.a -none $$libs ${EX_LIBS} -lc ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# This assumes that GNU utilities are *not* used
# The difference between alpha-osf1-shared and tru64-shared is the `-msym'
# option passed to the linker.
do_tru64-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} ${SHARED_LDFLAGS} \
-shared -msym -o lib$$i.so \
-set_version "${SHLIB_VERSION_HISTORY}${SHLIB_VERSION_NUMBER}" \
-all lib$$i.a -none $$libs ${EX_LIBS} -lc ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# This assumes that GNU utilities are *not* used
# The difference between tru64-shared and tru64-shared-rpath is the
# -rpath ${INSTALLTOP}/lib passed to the linker.
do_tru64-shared-rpath:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} ${SHARED_LDFLAGS} \
-shared -msym -o lib$$i.so \
-rpath ${INSTALLTOP}/lib \
-set_version "${SHLIB_VERSION_HISTORY}${SHLIB_VERSION_NUMBER}" \
-all lib$$i.a -none $$libs ${EX_LIBS} -lc ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# This assumes that GNU utilities are *not* used
do_solaris-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( PATH=/usr/ccs/bin:$$PATH ; export PATH; \
set -x; ${CC} ${SHARED_LDFLAGS} \
-G -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-h lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-z allextract lib$$i.a $$libs ${EX_LIBS} -lc ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# OpenServer 5 native compilers used
do_svr3-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( PATH=/usr/ccs/bin:$$PATH ; export PATH; \
find . -name "*.o" -print > allobjs ; \
OBJS= ; export OBJS ; \
for obj in `ar t lib$$i.a` ; do \
OBJS="$${OBJS} `grep $$obj allobjs`" ; \
done ; \
set -x; ${CC} -G -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-h lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
$${OBJS} $$libs ${EX_LIBS} ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# UnixWare 7 and OpenUNIX 8 native compilers used
do_svr5-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( PATH=/usr/ccs/bin:$$PATH ; export PATH; \
find . -name "*.o" -print > allobjs ; \
OBJS= ; export OBJS ; \
for obj in `ar t lib$$i.a` ; do \
OBJS="$${OBJS} `grep $$obj allobjs`" ; \
done ; \
set -x; ${CC} ${SHARED_LDFLAGS} \
-G -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-h lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
$${OBJS} $$libs ${EX_LIBS} ) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# This assumes that GNU utilities are *not* used
do_irix-shared:
if ${DETECT_GNU_LD}; then \
$(MAKE) do_gnu-shared; \
else \
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; ${CC} ${SHARED_LDFLAGS} \
-shared -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-Wl,-soname,lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-all lib$$i.a $$libs ${EX_LIBS} -lc) || exit 1; \
libs="$$libs -l$$i"; \
done; \
fi
# This assumes that GNU utilities are *not* used
# HP-UX includes the full pathname of libs we depend on, so we would get
# ./libcrypto (with ./ as path information) compiled into libssl, hence
# we omit the SHLIBDEPS. Applications must be linked with -lssl -lcrypto
# anyway.
# The object modules are loaded from lib$i.a using the undocumented -Fl
# option.
#
# WARNING: Until DSO is fixed to support a search path, we support SHLIB_PATH
# by temporarily specifying "+s"!
#
do_hpux-shared:
for i in ${SHLIBDIRS}; do \
( set -x; /usr/ccs/bin/ld ${SHARED_LDFLAGS} \
+vnocompatwarnings \
-b -z +s \
-o lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR} \
+h lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR} \
-Fl lib$$i.a -ldld -lc ) || exit 1; \
chmod a=rx lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR}; \
done
# This assumes that GNU utilities are *not* used
# HP-UX includes the full pathname of libs we depend on, so we would get
# ./libcrypto (with ./ as path information) compiled into libssl, hence
# we omit the SHLIBDEPS. Applications must be linked with -lssl -lcrypto
# anyway.
#
# HP-UX in 64bit mode has "+s" enabled by default; it will search for
# shared libraries along LD_LIBRARY_PATH _and_ SHLIB_PATH.
#
do_hpux64-shared:
for i in ${SHLIBDIRS}; do \
( set -x; /usr/ccs/bin/ld ${SHARED_LDFLAGS} \
-b -z \
-o lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR} \
+h lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR} \
+forceload lib$$i.a -ldl -lc ) || exit 1; \
chmod a=rx lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR}; \
done
# The following method is said to work on all platforms. Tests will
# determine if that's how it's gong to be used.
# This assumes that for all but GNU systems, GNU utilities are *not* used.
# ALLSYMSFLAGS would be:
# GNU systems: --whole-archive
# Tru64 Unix: -all
# Solaris: -z allextract
# Irix: -all
# HP/UX-32bit: -Fl
# HP/UX-64bit: +forceload
# AIX: -bnogc
# SHAREDFLAGS would be:
# GNU systems: -shared -Wl,-soname=lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
# Tru64 Unix: -shared \
# -set_version "${SHLIB_VERSION_HISTORY}${SHLIB_VERSION_NUMBER}"
# Solaris: -G -h lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
# Irix: -shared -Wl,-soname,lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
# HP/UX-32bit: +vnocompatwarnings -b -z +s \
# +h lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR}
# HP/UX-64bit: -b -z +h lib$$i.sl.${SHLIB_MAJOR}.${SHLIB_MINOR}
# AIX: -G -bE:lib$$i.exp -bM:SRE
# SHAREDCMD would be:
# GNU systems: $(CC)
# Tru64 Unix: $(CC)
# Solaris: $(CC)
# Irix: $(CC)
# HP/UX-32bit: /usr/ccs/bin/ld
# HP/UX-64bit: /usr/ccs/bin/ld
# AIX: $(CC)
ALLSYMSFLAG=-bnogc
SHAREDFLAGS=${SHARED_LDFLAGS} -G -bE:lib$$i.exp -bM:SRE
SHAREDCMD=$(CC)
do_aix-shared:
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
( set -x; \
ld -r -o $$i.o $(ALLSYMSFLAG) lib$$i.a && \
( nm -Pg lib$$i.o | grep ' [BD] ' | cut -f1 -d' ' > lib$$i.exp; \
$(SHAREDCMD) $(SHAREDFLAG) -o lib$$i.so lib$$i.o \
$$libs ${EX_LIBS} ) ) \
|| exit 1; \
libs="$$libs -l$$i"; \
done
do_reliantunix-shared:
libs='-L. ${SHLIBDEPS}'; for i in ${SHLIBDIRS}; do \
tmpdir=/tmp/openssl.$$$$ ; rm -rf $$tmpdir ; \
( set -x; \
( Opwd=`pwd` ; mkdir $$tmpdir || exit 1; \
cd $$tmpdir || exit 1 ; ar x $$Opwd/lib$$i.a ; \
${CC} -G -o lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} *.o \
) || exit 1; \
cp $$tmpdir/lib$$i.so.${SHLIB_MAJOR}.${SHLIB_MINOR} . ; \
) || exit 1; \
rm -rf $$tmpdir ; \
libs="$$libs -l$$i"; \
done
openssl.pc:
@ -297,7 +533,7 @@ Makefile.ssl: Makefile.org
@false
libclean:
rm -f *.so *.so.* engines/*.so *.a */lib */*/lib
rm -f *.a */lib */*/lib
clean:
rm -f shlib/*.o *.o core a.out fluff *.map rehash.time testlog make.log cctest cctest.c
@ -408,7 +644,7 @@ tags:
errors:
$(PERL) util/mkerr.pl -recurse -write
(cd engines; $(MAKE) PERL=$(PERL) errors)
(cd crypto/engine; $(MAKE) PERL=$(PERL) errors)
stacks:
$(PERL) util/mkstack.pl -write
@ -470,7 +706,6 @@ install: all install_docs
$(INSTALL_PREFIX)$(INSTALLTOP)/lib \
$(INSTALL_PREFIX)$(INSTALLTOP)/lib/pkginfo \
$(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl \
$(INSTALL_PREFIX)$(OPENSSLDIR)/engines \
$(INSTALL_PREFIX)$(OPENSSLDIR)/misc \
$(INSTALL_PREFIX)$(OPENSSLDIR)/certs \
$(INSTALL_PREFIX)$(OPENSSLDIR)/private \
@ -484,7 +719,7 @@ install: all install_docs
do \
if [ -d "$$i" ]; then \
(cd $$i; echo "installing $$i..."; \
$(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' OPENSSLDIR='${OPENSSLDIR}' EX_LIBS='${EX_LIBS}' SDIRS='${SDIRS}' RANLIB='${RANLIB}' EXE_EXT='${EXE_EXT}' SHARED_LIBS='${SHARED_LIBS}' install ); \
$(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' OPENSSLDIR='${OPENSSLDIR}' EX_LIBS='${EX_LIBS}' SDIRS='${SDIRS}' RANLIB='${RANLIB}' EXE_EXT='${EXE_EXT}' install ); \
fi; \
done
@for i in $(LIBS) ;\
@ -508,7 +743,7 @@ install: all install_docs
chmod 555 $(INSTALL_PREFIX)$(INSTALLTOP)/lib/$$i.new; \
mv $(INSTALL_PREFIX)$(INSTALLTOP)/lib/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/lib/$$i; \
else \
c=`echo $$i | sed 's/^lib/cyg/'`; \
c=`echo $$i | sed 's/^lib\(.*\)/cyg\1-$(SHLIB_VERSION_NUMBER)/'`; \
cp $$c $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$c.new; \
chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$c.new; \
mv $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$c.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$c; \
@ -520,7 +755,8 @@ install: all install_docs
done; \
( here="`pwd`"; \
cd $(INSTALL_PREFIX)$(INSTALLTOP)/lib; \
$(NEWMAKE) -f $$here/Makefile link-shared ); \
set $(MAKE); \
$$1 -f $$here/Makefile link-shared ); \
fi
cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/lib/pkginfo

View File

@ -1,584 +0,0 @@
#
# Helper makefile to link shared libraries in a portable way.
# This is much simpler than libtool, and hopefully not too error-prone.
#
# The following variables need to be set on the command line to build
# properly
# CC contains the current compiler. This one MUST be defined
CC=cc
# LDFLAGS contains flags to be used when the temporary object file is
# created. SHARED_LDFLAGS contains flags to be used when the shared
# library is created.
LDFLAGS=
SHARED_LDFLAGS=
# LIBNAME contains just the name of thhe library, without prefix ("lib"
# on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
# .dll, ...). This one MUST have a value when using this makefile.
# For example, to build libfoo.so, you need to do the following:
#LIBNAME=foo
LIBNAME=
# LIBEXTRAS contains extra modules to link together with the library.
# For example, if a second library, say libbar.a needs to be linked into
# libfoo.so, you need to do the following:
#LIBEXTRAS=libbar.a
# Note that this MUST be used when using the link_o targets, to hold the
# names of all object files that go into the target library.
LIBEXTRAS=
# LIBVERSION contains the current version of the library.
# For example, to build libfoo.so.1.2, you need to do the following:
#LIBVERSION=1.2
LIBVERSION=
# LIBCOMPATVERSIONS contains the compatibility versions (a list) of
# the library. They MUST be in decreasing order.
# For example, if libfoo.so.1.2.1 is backward compatible with libfoo.so.1.2
# and libfoo.so.1, you need to do the following:
#LIBCOMPATVERSIONS=1.2 1
# Note that on systems that use sonames, the last number will appear as
# part of it.
# It's also possible, for systems that support it (Tru64, for example),
# to add extra compatibility info with more precision, by adding a second
# list of versions, separated from the first with a semicolon, like this:
#LIBCOMPATVERSIONS=1.2 1;1.2.0 1.1.2 1.1.1 1.1.0 1.0.0
LIBCOMPATVERSIONS=
# LIBDEPS contains all the flags necessary to cover all necessary
# dependencies to other libraries.
LIBDEPS=
#------------------------------------------------------------------------------
# The rest is private to this makefile.
#DEBUG=:
DEBUG=set -x
top:
echo "Trying to use this makefile interactively? Don't."
CALC_VERSIONS= \
SHLIB_COMPAT=; SHLIB_SOVER=; \
if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \
prev=""; \
for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \
SHLIB_SOVER_NODOT=$$v \
SHLIB_SOVER=.$$v; \
if [ -n "$$prev" ]; then \
SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \
fi; \
prev=$$v; \
done; \
fi
LINK_SO= \
( $(DEBUG); \
nm -Pg $$SHOBJECTS | grep ' [BDT] ' | cut -f1 -d' ' > lib$(LIBNAME).exp; \
$$SHAREDCMD $(SHARED_LDFLAGS) $$SHAREDFLAGS -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
$$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS ) && \
$(SYMLINK_SO); ( $(DEBUG); rm -f lib$(LIBNAME).exp )
SYMLINK_SO= \
if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \
prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
if [ -n "$$SHLIB_COMPAT" ]; then \
for x in $$SHLIB_COMPAT; do \
( $(DEBUG); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
done; \
fi; \
if [ -n "$$SHLIB_SOVER" ]; then \
( $(DEBUG); rm -f $$SHLIB$$SHLIB_SUFFIX; \
ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
fi; \
fi
LINK_SO_A= SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)
LINK_SO_O= SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)
LINK_SO_A_VIA_O= \
SHOBJECTS=lib$(LIBNAME).o ALL=$$ALLSYMSFLAGS ALLSYMSFLAGS= NOALLSYMSFLAGS=; \
( $(DEBUG); \
ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
$(LINK_SO) && rm -f $(LIBNAME).o
LINK_SO_A_UNPACKED= \
UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
(cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && cp $(LIBEXTRAS) $$UNPACKDIR && \
SHOBJECTS=$$UNPACKDIR/*.o; \
$(LINK_SO) && rm -rf $$UNPACKDIR
DETECT_GNU_LD=${CC} -v 2>&1 | grep '^gcc' >/dev/null 2>&1 && \
my_ld=`${CC} -print-prog-name=ld 2>&1` && \
[ -n "$$my_ld" ] && \
$$my_ld -v 2>&1 | grep 'GNU ld' >/dev/null 2>&1
DO_GNU=$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-Wl,--whole-archive' \
NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX" \
SHAREDCMD='$(CC)'
link_o.gnu:
@ $(DO_GNU); $(LINK_SO_O)
link_a.gnu:
@ $(DO_GNU); $(LINK_SO_A)
# For Darwin AKA Mac OS/X (dyld)
link_o.darwin:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME) \
SHLIB_SUFFIX=.dylib \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-all_load' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS="-dynamiclib" \
SHAREDCMD='$(CC)'; \
if [ -n "$(LIBVERSION)" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -current_version $(LIBVERSION)"; \
fi; \
if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
fi; \
$(LINK_SO_O)
link_a.darwin:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME) \
SHLIB_SUFFIX=.dylib \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-all_load' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS="-dynamiclib" \
SHAREDCMD='$(CC)'; \
if [ -n "$(LIBVERSION)" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -current_version $(LIBVERSION)"; \
fi; \
if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
fi; \
$(LINK_SO_A)
link_o.cygwin:
@ $(CALC_VERSIONS); \
INHIBIT_SYMLINKS=yes; \
SHLIB=cyg$(LIBNAME) \
SHLIB_SUFFIX=.dll \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_SOVER=-$(LIBVERSION) \
ALLSYMSFLAGS='-Wl,--whole-archive' \
NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a" \
SHAREDCMD='${CC}'; \
$(LINK_SO_O)
link_a.cygwin:
@ $(CALC_VERSIONS); \
INHIBIT_SYMLINKS=yes; \
SHLIB=cyg$(LIBNAME) \
SHLIB_SUFFIX=.dll \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_SOVER= \
ALLSYMSFLAGS='-Wl,--whole-archive' \
NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a" \
SHAREDCMD='${CC}'; \
$(LINK_SO_A)
link_o.alpha-osf1:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_O)
link_a.alpha-osf1:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_A)
# The difference between alpha-osf1-shared and tru64-shared is the `-msym'
# option passed to the linker.
link_o.tru64:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared -msym" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_O)
link_a.tru64:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared -msym" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_A)
# The difference between tru64-shared and tru64-shared-rpath is the
# -rpath ${LIBRPATH} passed to the linker.
link_o.tru64-rpath:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_O)
link_a.tru64-rpath:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
if [ -n "$$SHLIB_HIST" ]; then \
SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
else \
SHLIB_HIST="$(LIBVERSION)"; \
fi
SHLIB_SOVER= \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='-none' \
SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)" \
SHAREDCMD='$(CC)'; \
if [ -n "$$SHLIB_HIST" ]; then \
SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
fi; \
fi; \
$(LINK_SO_A)
link_o.solaris:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-z allextract' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_O)
link_a.solaris:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-z allextract' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_A)
# OpenServer 5 native compilers used
# UnixWare 7 and OpenUNIX 8 native compilers used
link_o.svr3:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-z allextract' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_O)
link_a.svr3:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-z allextract' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_A_UNPACKED)
link_o.irix:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_O)
link_a.irix:
@ if ${DETECT_GNU_LD}; then \
$(DO_GNU); \
else \
$(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-all' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='$(CC)'; \
fi; \
$(LINK_SO_A)
# HP-UX includes the full pathname of libs we depend on, so we would get
# ./libcrypto (with ./ as path information) compiled into libssl, hence
# we omit the SHLIBDEPS. Applications must be linked with -lssl -lcrypto
# anyway.
# The object modules are loaded from lib$i.a using the undocumented -Fl
# option.
#
# WARNING: Until DSO is fixed to support a search path, we support SHLIB_PATH
# by temporarily specifying "+s"!
#
link_o.hpux32:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).sl \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-Fl' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='+vnocompatwarnings -b -z +s +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='/usr/ccs/bin/ld'; \
$(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
link_a.hpux32:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).sl \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-Fl' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='+vnocompatwarnings -b -z +s +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='/usr/ccs/bin/ld'; \
$(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
# HP-UX includes the full pathname of libs we depend on, so we would get
# ./libcrypto (with ./ as path information) compiled into libssl, hence
# we omit the SHLIBDEPS. Applications must be linked with -lssl -lcrypto
# anyway.
#
# HP-UX in 64bit mode has "+s" enabled by default; it will search for
# shared libraries along LD_LIBRARY_PATH _and_ SHLIB_PATH.
#
link_o.hpux64:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).sl \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='+forceload' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='/usr/ccs/bin/ld'; \
$(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
link_a.hpux64:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).sl \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='+forceload' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
SHAREDCMD='/usr/ccs/bin/ld'; \
$(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
link_o.aix:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-bnogc' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE' \
SHAREDCMD='$(CC)'; \
$(LINK_SO_O)
link_a.aix:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS='-bnogc' \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE' \
SHAREDCMD='$(CC)'; \
$(LINK_SO_A_VIA_O)
link_o.reliantunix:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS= \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G' \
SHAREDCMD='$(CC)'; \
$(LINK_SO_O)
link_a.reliantunix:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so \
SHLIB_SUFFIX= \
LIBDEPS="$(LIBDEPS) -lc" \
ALLSYMSFLAGS= \
NOALLSYMSFLAGS='' \
SHAREDFLAGS='-G' \
SHAREDCMD='$(CC)'; \
$(LINK_SO_A_UNPACKED)
# Targets to build symbolic links when needed
symlink.gnu symlink.solaris symlink.svr3 symlink.irix \
symlink.aix symlink.reliantunix:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).so; \
$(SYMLINK_SO)
symlink.darwin:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME) \
SHLIB_SUFFIX=.dylib; \
$(SYMLINK_SO)
symlink.hpux32 symlink.hpux64:
@ $(CALC_VERSIONS); \
SHLIB=lib$(LIBNAME).sl; \
$(SYMLINK_SO)
# The following lines means those specific architectures do no symlinks
symlink.cygwin symlib.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
# Compatibility targets
link_o.bsd-gcc-shared link_o.linux-shared link_o.gnu-shared: link_o.gnu
link_a.bsd-gcc-shared link_a.linux-shared link_a.gnu-shared: link_a.gnu
symlink.bsd-gcc-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
link_o.darwin-shared: link_o.darwin
link_a.darwin-shared: link_a.darwin
symlink.darwin-shared: symlink.darwin
link_o.cygwin-shared: link_o.cygwin
link_a.cygwin-shared: link_a.cygwin
symlink.cygwin-shared: symlink.cygwin
link_o.alpha-osf1-shared: link_o.alpha-osf1
link_a.alpha-osf1-shared: link_a.alpha-osf1
symlink.alpha-osf1-shared: symlink.alpha-osf1
link_o.tru64-shared: link_o.tru64
link_a.tru64-shared: link_a.tru64
symlink.tru64-shared: symlink.tru64
link_o.tru64-shared-rpath: link_o.tru64-rpath
link_a.tru64-shared-rpath: link_a.tru64-rpath
symlink.tru64-shared-rpath: symlink.tru64-rpath
link_o.solaris-shared: link_o.solaris
link_a.solaris-shared: link_a.solaris
symlink.solaris-shared: symlink.solaris
link_o.svr3-shared: link_o.svr3
link_a.svr3-shared: link_a.svr3
symlink.svr3-shared: symlink.svr3
link_o.svr5-shared: link_o.svr3
link_a.svr5-shared: link_a.svr3
symlink.svr5-shared: symlink.svr3
link_o.irix-shared: link_o.irix
link_a.irix-shared: link_a.irix
symlink.irix-shared: symlink.irix
link_o.hpux-shared: link_o.hpux32
link_a.hpux-shared: link_a.hpux32
symlink.hpux-shared: symlink.hpux32
link_o.hpux64-shared: link_o.hpux64
link_a.hpux64-shared: link_a.hpux64
symlink.hpux64-shared: symlink.hpux64
link_o.aix-shared: link_o.aix
link_a.aix-shared: link_a.aix
symlink.aix-shared: symlink.aix
link_o.reliantunix-shared: link_o.reliantunix
link_a.reliantunix-shared: link_a.reliantunix
symlink.reliantunix-shared: symlink.reliantunix

20
NEWS
View File

@ -17,6 +17,11 @@
a separate distribution.
o New elliptic curve library section.
o New AES (Rijndael) library section.
o Support for new platforms: Windows CE, Tandem OSS, A/UX, AIX 64-bit
o Extended support for some platforms: VxWorks
o Enhanced support for shared libraries.
o Support for pkg-config.
o Lots of new manuals.
o Change DES API to clean up the namespace (some applications link also
against libdes providing similar functions having the same name).
Provide macros for backward compatibility (will be removed in the
@ -30,6 +35,7 @@
o Reworked parts of the BIGNUM code.
o Support for new engines: Broadcom ubsec, Accelerated Encryption
Processing, IBM 4758.
o A few new engines added in the demos area.
o Extended and corrected OID (object identifier) table.
o PRNG: query at more locations for a random device, automatic query for
EGD style random sources at several locations.
@ -40,6 +46,20 @@
o SSL/TLS: add callback to retrieve SSL/TLS messages.
o SSL/TLS: support AES cipher suites (RFC3268).
Major changes between OpenSSL 0.9.6g and OpenSSL 0.9.6h:
o New configuration targets for Tandem OSS and A/UX.
o New OIDs for Microsoft attributes.
o Better handling of SSL session caching.
o Better comparison of distinguished names.
o Better handling of shared libraries in a mixed GNU/non-GNU environment.
o Support assembler code with Borland C.
o Fixes for length problems.
o Fixes for uninitialised variables.
o Fixes for memory leaks, some unusual crashes and some race conditions.
o Fixes for smaller building problems.
o Updates of manuals, FAQ and other instructive documents.
Major changes between OpenSSL 0.9.6f and OpenSSL 0.9.6g:
o Important building fixes on Unix.

4
README
View File

@ -1,5 +1,5 @@
OpenSSL 0.9.8-dev XX xxx XXXX
OpenSSL 0.9.7-beta4 19 Nov 2002
Copyright (c) 1998-2002 The OpenSSL Project
Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
@ -154,7 +154,7 @@
- Stack Traceback (if the application dumps core)
Report the bug to the OpenSSL project via the Request Tracker
(http://www.openssl.org/rt2.html) by mail to:
(http://www.openssl.org/support/rt2.html) by mail to:
openssl-bugs@openssl.org

6
STATUS
View File

@ -1,10 +1,11 @@
OpenSSL STATUS Last modified at
______________ $Date: 2002/08/14 11:07:29 $
______________ $Date: 2002/11/19 09:34:38 $
DEVELOPMENT STATE
o OpenSSL 0.9.8: Under development...
o OpenSSL 0.9.7-beta4: Released on November 19th, 2002
o OpenSSL 0.9.7-beta3: Released on July 30th, 2002
o OpenSSL 0.9.7-beta2: Released on June 16th, 2002
o OpenSSL 0.9.7-beta1: Released on June 1st, 2002
@ -58,9 +59,6 @@
NEEDS PATCH
o 0.9.8-dev: COMPLEMENTOFALL and COMPLEMENTOFDEFAULT do not
handle ECCdraft cipher suites correctly.
o apps/ca.c: "Sign the certificate?" - "n" creates empty certificate file
o "OpenSSL STATUS" is never up-to-date.

25
TABLE
View File

@ -875,6 +875,31 @@ $shared_extension =
$ranlib =
$arflags =
*** VC-CE
$cc = cl
$cflags =
$unistd =
$thread_cflag =
$sys_id = WINCE
$lflags =
$bn_ops = BN_LLONG RC4_INDEX EXPORT_VAR_AS_FN RC4_INDEX MD2_INT
$bn_obj =
$des_obj =
$bf_obj =
$md5_obj =
$sha1_obj =
$cast_obj =
$rc4_obj =
$rmd160_obj =
$rc5_obj =
$dso_scheme = win32
$shared_target=
$shared_cflag =
$shared_ldflag =
$shared_extension =
$ranlib =
$arflags =
*** VC-MSDOS
$cc = cl
$cflags =

View File

@ -285,7 +285,6 @@ $ if alg_entry .eqs. "" then goto loop2
$ if alg_entry .nes. ","
$ then
$ if alg_entry .eqs. "KRB5" then goto loop ! Special for now
$ if alg_entry .eqs. "STATIC_ENGINE" then goto loop ! Special for now
$ if f$trnlnm("OPENSSL_NO_"+alg_entry) .nes. "" then goto loop
$ goto loop2
$ endif

1
VMS/tcpip_shr_decc.opt Normal file
View File

@ -0,0 +1 @@
sys$share:tcpip$ipc_shr.exe/share

File diff suppressed because it is too large Load Diff

View File

@ -82,8 +82,6 @@
int MAIN(int, char **);
static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf);
int MAIN(int argc, char **argv)
{
int i,badops=0,offset=0,ret=1,j;
@ -92,7 +90,6 @@ int MAIN(int argc, char **argv)
BIO *in=NULL,*out=NULL,*b64=NULL, *derout = NULL;
int informat,indent=0, noout = 0, dump = 0;
char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL;
char *genstr=NULL, *genconf=NULL;
unsigned char *tmpbuf;
BUF_MEM *buf=NULL;
STACK *osk=NULL;
@ -170,16 +167,6 @@ int MAIN(int argc, char **argv)
if (--argc < 1) goto bad;
sk_push(osk,*(++argv));
}
else if (strcmp(*argv,"-genstr") == 0)
{
if (--argc < 1) goto bad;
genstr= *(++argv);
}
else if (strcmp(*argv,"-genconf") == 0)
{
if (--argc < 1) goto bad;
genconf= *(++argv);
}
else
{
BIO_printf(bio_err,"unknown option %s\n",*argv);
@ -208,8 +195,6 @@ bad:
BIO_printf(bio_err," -strparse offset\n");
BIO_printf(bio_err," a series of these can be used to 'dig' into multiple\n");
BIO_printf(bio_err," ASN1 blob wrappings\n");
BIO_printf(bio_err," -genstr str string to generate ASN1 structure from\n");
BIO_printf(bio_err," -genconf file file to generate ASN1 structure from\n");
goto end;
}
@ -263,39 +248,25 @@ bad:
if ((buf=BUF_MEM_new()) == NULL) goto end;
if (!BUF_MEM_grow(buf,BUFSIZ*8)) goto end; /* Pre-allocate :-) */
if (genstr || genconf)
if (informat == FORMAT_PEM)
{
num = do_generate(bio_err, genstr, genconf, buf);
if (num < 0)
{
ERR_print_errors(bio_err);
BIO *tmp;
if ((b64=BIO_new(BIO_f_base64())) == NULL)
goto end;
}
BIO_push(b64,in);
tmp=in;
in=b64;
b64=tmp;
}
else
num=0;
for (;;)
{
if (informat == FORMAT_PEM)
{
BIO *tmp;
if ((b64=BIO_new(BIO_f_base64())) == NULL)
goto end;
BIO_push(b64,in);
tmp=in;
in=b64;
b64=tmp;
}
num=0;
for (;;)
{
if (!BUF_MEM_grow(buf,(int)num+BUFSIZ)) goto end;
i=BIO_read(in,&(buf->data[num]),BUFSIZ);
if (i <= 0) break;
num+=i;
}
if (!BUF_MEM_grow(buf,(int)num+BUFSIZ)) goto end;
i=BIO_read(in,&(buf->data[num]),BUFSIZ);
if (i <= 0) break;
num+=i;
}
str=buf->data;
@ -364,61 +335,3 @@ end:
EXIT(ret);
}
static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf)
{
CONF *cnf = NULL;
int len;
long errline;
unsigned char *p;
ASN1_TYPE *atyp = NULL;
if (genconf)
{
cnf = NCONF_new(NULL);
if (!NCONF_load(cnf, genconf, &errline))
goto conferr;
if (!genstr)
genstr = NCONF_get_string(cnf, "default", "asn1");
if (!genstr)
{
BIO_printf(bio, "Can't find 'asn1' in '%s'\n", genconf);
goto err;
}
}
atyp = ASN1_generate_nconf(genstr, cnf);
NCONF_free(cnf);
if (!atyp)
return -1;
len = i2d_ASN1_TYPE(atyp, NULL);
if (len <= 0)
goto err;
if (!BUF_MEM_grow(buf,len))
goto err;
p=(unsigned char *)buf->data;
i2d_ASN1_TYPE(atyp, &p);
ASN1_TYPE_free(atyp);
return len;
conferr:
if (errline > 0)
BIO_printf(bio, "Error on line %ld of config file '%s'\n",
errline, genconf);
else
BIO_printf(bio, "Error loading config file '%s'\n", genconf);
err:
NCONF_free(cnf);
ASN1_TYPE_free(atyp);
return -1;
}

View File

@ -1532,11 +1532,6 @@ bad:
if (pkey->type == EVP_PKEY_DSA)
dgst=EVP_dss1();
else
#endif
#ifndef OPENSSL_NO_ECDSA
if (pkey->type == EVP_PKEY_EC)
dgst=EVP_ecdsa();
else
#endif
dgst=EVP_md5();
}
@ -1601,6 +1596,10 @@ bad:
}
j=TXT_DB_write(out,db);
if (j <= 0) goto err;
BIO_free_all(out);
out = NULL;
BIO_free_all(in);
in = NULL;
strncpy(buf[1],dbfile,BSIZE-4);
buf[1][BSIZE-4]='\0';
#ifndef OPENSSL_SYS_VMS
@ -1608,10 +1607,6 @@ bad:
#else
strcat(buf[1],"-old");
#endif
BIO_free(in);
in = NULL;
BIO_free(out);
out = NULL;
if (rename(dbfile,buf[1]) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n", dbfile, buf[1]);
@ -2321,16 +2316,6 @@ again2:
EVP_PKEY_copy_parameters(pktmp,pkey);
EVP_PKEY_free(pktmp);
#endif
#ifndef OPENSSL_NO_ECDSA
if (pkey->type == EVP_PKEY_EC)
dgst = EVP_ecdsa();
pktmp = X509_get_pubkey(ret);
if (EVP_PKEY_missing_parameters(pktmp) &&
!EVP_PKEY_missing_parameters(pkey))
EVP_PKEY_copy_parameters(pktmp, pkey);
EVP_PKEY_free(pktmp);
#endif
if (!X509_sign(ret,pkey,dgst))
goto err;
@ -3076,16 +3061,16 @@ X509_NAME *do_subject(char *subject, long chtype)
int nid;
if (!buf || !ne_types || !ne_values)
{
{
BIO_printf(bio_err, "malloc error\n");
goto error;
}
}
if (*subject != '/')
{
{
BIO_printf(bio_err, "Subject does not start with '/'.\n");
goto error;
}
}
sp++; /* skip leading / */
while (*sp)
@ -3098,12 +3083,12 @@ X509_NAME *do_subject(char *subject, long chtype)
{
if (*++sp)
*bp++ = *sp++;
else
else
{
BIO_printf(bio_err, "escape character at end of string\n");
goto error;
}
}
}
else if (*sp == '=')
{
sp++;
@ -3141,7 +3126,7 @@ X509_NAME *do_subject(char *subject, long chtype)
}
*bp++ = '\0';
ne_num++;
}
}
if (!(n = X509_NAME_new()))
goto error;

395
apps/ec.c
View File

@ -1,395 +0,0 @@
/* apps/ec.c */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* openssl-core@openssl.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#ifndef OPENSSL_NO_EC
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#undef PROG
#define PROG ec_main
/* -inform arg - input format - default PEM (one of DER, NET or PEM)
* -outform arg - output format - default PEM
* -in arg - input file - default stdin
* -out arg - output file - default stdout
* -des - encrypt output if PEM format with DES in cbc mode
* -text - print a text version
* -param_out - print the elliptic curve parameters
* -conv_form arg - specifies the point encoding form
* -param_enc arg - specifies the parameter encoding
*/
int MAIN(int, char **);
int MAIN(int argc, char **argv)
{
ENGINE *e = NULL;
int ret = 1;
EC_KEY *eckey = NULL;
int i, badops = 0;
const EVP_CIPHER *enc = NULL;
BIO *in = NULL, *out = NULL;
int informat, outformat, text=0, noout=0;
int pubin = 0, pubout = 0, param_out = 0;
char *infile, *outfile, *prog, *engine;
char *passargin = NULL, *passargout = NULL;
char *passin = NULL, *passout = NULL;
point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
int new_form = 0;
int asn1_flag = OPENSSL_EC_NAMED_CURVE;
int new_asn1_flag = 0;
apps_startup();
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
engine = NULL;
infile = NULL;
outfile = NULL;
informat = FORMAT_PEM;
outformat = FORMAT_PEM;
prog = argv[0];
argc--;
argv++;
while (argc >= 1)
{
if (strcmp(*argv,"-inform") == 0)
{
if (--argc < 1) goto bad;
informat=str2fmt(*(++argv));
}
else if (strcmp(*argv,"-outform") == 0)
{
if (--argc < 1) goto bad;
outformat=str2fmt(*(++argv));
}
else if (strcmp(*argv,"-in") == 0)
{
if (--argc < 1) goto bad;
infile= *(++argv);
}
else if (strcmp(*argv,"-out") == 0)
{
if (--argc < 1) goto bad;
outfile= *(++argv);
}
else if (strcmp(*argv,"-passin") == 0)
{
if (--argc < 1) goto bad;
passargin= *(++argv);
}
else if (strcmp(*argv,"-passout") == 0)
{
if (--argc < 1) goto bad;
passargout= *(++argv);
}
else if (strcmp(*argv, "-engine") == 0)
{
if (--argc < 1) goto bad;
engine= *(++argv);
}
else if (strcmp(*argv, "-noout") == 0)
noout = 1;
else if (strcmp(*argv, "-text") == 0)
text = 1;
else if (strcmp(*argv, "-conv_form") == 0)
{
if (--argc < 1)
goto bad;
++argv;
new_form = 1;
if (strcmp(*argv, "compressed") == 0)
form = POINT_CONVERSION_COMPRESSED;
else if (strcmp(*argv, "uncompressed") == 0)
form = POINT_CONVERSION_UNCOMPRESSED;
else if (strcmp(*argv, "hybrid") == 0)
form = POINT_CONVERSION_HYBRID;
else
goto bad;
}
else if (strcmp(*argv, "-param_enc") == 0)
{
if (--argc < 1)
goto bad;
++argv;
new_asn1_flag = 1;
if (strcmp(*argv, "named_curve") == 0)
asn1_flag = OPENSSL_EC_NAMED_CURVE;
else if (strcmp(*argv, "explicit") == 0)
asn1_flag = 0;
else
goto bad;
}
else if (strcmp(*argv, "-param_out") == 0)
param_out = 1;
else if (strcmp(*argv, "-pubin") == 0)
pubin=1;
else if (strcmp(*argv, "-pubout") == 0)
pubout=1;
else if ((enc=EVP_get_cipherbyname(&(argv[0][1]))) == NULL)
{
BIO_printf(bio_err, "unknown option %s\n", *argv);
badops=1;
break;
}
argc--;
argv++;
}
if (badops)
{
bad:
BIO_printf(bio_err, "%s [options] <infile >outfile\n", prog);
BIO_printf(bio_err, "where options are\n");
BIO_printf(bio_err, " -inform arg input format - "
"DER or PEM\n");
BIO_printf(bio_err, " -outform arg output format - "
"DER or PEM\n");
BIO_printf(bio_err, " -in arg input file\n");
BIO_printf(bio_err, " -passin arg input file pass "
"phrase source\n");
BIO_printf(bio_err, " -out arg output file\n");
BIO_printf(bio_err, " -passout arg output file pass "
"phrase source\n");
BIO_printf(bio_err, " -engine e use engine e, "
"possibly a hardware device.\n");
BIO_printf(bio_err, " -des encrypt PEM output, "
"instead of 'des' every other \n"
" cipher "
"supported by OpenSSL can be used\n");
BIO_printf(bio_err, " -text print the key\n");
BIO_printf(bio_err, " -noout don't print key out\n");
BIO_printf(bio_err, " -param_out print the elliptic "
"curve parameters\n");
BIO_printf(bio_err, " -conv_form arg specifies the "
"point conversion form \n");
BIO_printf(bio_err, " possible values:"
" compressed\n");
BIO_printf(bio_err, " "
" uncompressed (default)\n");
BIO_printf(bio_err, " "
" hybrid\n");
BIO_printf(bio_err, " -param_enc arg specifies the way"
" the ec parameters are encoded\n");
BIO_printf(bio_err, " in the asn1 der "
"encoding\n");
BIO_printf(bio_err, " possilbe values:"
" named_curve (default)\n");
BIO_printf(bio_err," "
"explicit\n");
goto end;
}
ERR_load_crypto_strings();
e = setup_engine(bio_err, engine, 0);
if(!app_passwd(bio_err, passargin, passargout, &passin, &passout))
{
BIO_printf(bio_err, "Error getting passwords\n");
goto end;
}
in = BIO_new(BIO_s_file());
out = BIO_new(BIO_s_file());
if ((in == NULL) || (out == NULL))
{
ERR_print_errors(bio_err);
goto end;
}
if (infile == NULL)
BIO_set_fp(in, stdin, BIO_NOCLOSE);
else
{
if (BIO_read_filename(in, infile) <= 0)
{
perror(infile);
goto end;
}
}
BIO_printf(bio_err, "read EC key\n");
if (informat == FORMAT_ASN1)
{
if (pubin)
eckey = d2i_EC_PUBKEY_bio(in, NULL);
else
eckey = d2i_ECPrivateKey_bio(in, NULL);
}
else if (informat == FORMAT_PEM)
{
if (pubin)
eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL,
NULL);
else
eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL,
passin);
}
else
{
BIO_printf(bio_err, "bad input format specified for key\n");
goto end;
}
if (eckey == NULL)
{
BIO_printf(bio_err,"unable to load Key\n");
ERR_print_errors(bio_err);
goto end;
}
if (outfile == NULL)
{
BIO_set_fp(out, stdout, BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
{
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
out = BIO_push(tmpbio, out);
}
#endif
}
else
{
if (BIO_write_filename(out, outfile) <= 0)
{
perror(outfile);
goto end;
}
}
if (new_form)
{
EC_GROUP_set_point_conversion_form(eckey->group, form);
eckey->conv_form = form;
}
if (new_asn1_flag)
EC_GROUP_set_asn1_flag(eckey->group, asn1_flag);
if (text)
if (!EC_KEY_print(out, eckey, 0))
{
perror(outfile);
ERR_print_errors(bio_err);
goto end;
}
if (noout)
goto end;
BIO_printf(bio_err, "writing EC key\n");
if (outformat == FORMAT_ASN1)
{
if (param_out)
i = i2d_ECPKParameters_bio(out, eckey->group);
else if (pubin || pubout)
i = i2d_EC_PUBKEY_bio(out, eckey);
else
i = i2d_ECPrivateKey_bio(out, eckey);
}
else if (outformat == FORMAT_PEM)
{
if (param_out)
i = PEM_write_bio_ECPKParameters(out, eckey->group);
else if (pubin || pubout)
i = PEM_write_bio_EC_PUBKEY(out, eckey);
else
i = PEM_write_bio_ECPrivateKey(out, eckey, enc,
NULL, 0, NULL, passout);
}
else
{
BIO_printf(bio_err, "bad output format specified for "
"outfile\n");
goto end;
}
if (!i)
{
BIO_printf(bio_err, "unable to write private key\n");
ERR_print_errors(bio_err);
}
else
ret=0;
end:
if (in)
BIO_free(in);
if (out)
BIO_free_all(out);
if (eckey)
EC_KEY_free(eckey);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
apps_shutdown();
EXIT(ret);
}
#endif

View File

@ -1,709 +0,0 @@
/* apps/ecparam.c */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The elliptic curve binary polynomial software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#ifndef OPENSSL_NO_EC
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "apps.h"
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#undef PROG
#define PROG ecparam_main
/* -inform arg - input format - default PEM (DER or PEM)
* -outform arg - output format - default PEM
* -in arg - input file - default stdin
* -out arg - output file - default stdout
* -noout - do not print the ec parameter
* -text - print the ec parameters in text form
* -check - validate the ec parameters
* -C - print a 'C' function creating the parameters
* -name arg - use the ec parameters with 'short name' name
* -list_curves - prints a list of all currently available curve 'short names'
* -conv_form arg - specifies the point conversion form
* - possible values: compressed
* uncompressed (default)
* hybrid
* -param_enc arg - specifies the way the ec parameters are encoded
* in the asn1 der encoding
* possible values: named_curve (default)
* explicit
* -no_seed - if 'explicit' parameters are choosen do not use the seed
* -genkey - generate ec key
* -rand file - files to use for random number input
* -engine e - use engine e, possibly a hardware device
*/
static int ecparam_print_var(BIO *,BIGNUM *,const char *,int,unsigned char *);
int MAIN(int, char **);
int MAIN(int argc, char **argv)
{
EC_GROUP *group = NULL;
point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;
int new_form = 0;
int asn1_flag = OPENSSL_EC_NAMED_CURVE;
int new_asn1_flag = 0;
char *curve_name = NULL, *inrand = NULL;
int list_curves = 0, no_seed = 0, check = 0,
badops = 0, text = 0, i, need_rand = 0, genkey = 0;
char *infile = NULL, *outfile = NULL, *prog;
BIO *in = NULL, *out = NULL;
int informat, outformat, noout = 0, C = 0, ret = 1;
ENGINE *e = NULL;
char *engine = NULL;
BIGNUM *ec_p = NULL, *ec_a = NULL, *ec_b = NULL,
*ec_gen = NULL, *ec_order = NULL, *ec_cofactor = NULL;
unsigned char *buffer = NULL;
apps_startup();
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
informat=FORMAT_PEM;
outformat=FORMAT_PEM;
prog=argv[0];
argc--;
argv++;
while (argc >= 1)
{
if (strcmp(*argv,"-inform") == 0)
{
if (--argc < 1) goto bad;
informat=str2fmt(*(++argv));
}
else if (strcmp(*argv,"-outform") == 0)
{
if (--argc < 1) goto bad;
outformat=str2fmt(*(++argv));
}
else if (strcmp(*argv,"-in") == 0)
{
if (--argc < 1) goto bad;
infile= *(++argv);
}
else if (strcmp(*argv,"-out") == 0)
{
if (--argc < 1) goto bad;
outfile= *(++argv);
}
else if (strcmp(*argv,"-text") == 0)
text = 1;
else if (strcmp(*argv,"-C") == 0)
C = 1;
else if (strcmp(*argv,"-check") == 0)
check = 1;
else if (strcmp (*argv, "-name") == 0)
{
if (--argc < 1)
goto bad;
curve_name = *(++argv);
}
else if (strcmp(*argv, "-list_curves") == 0)
list_curves = 1;
else if (strcmp(*argv, "-conv_form") == 0)
{
if (--argc < 1)
goto bad;
++argv;
new_form = 1;
if (strcmp(*argv, "compressed") == 0)
form = POINT_CONVERSION_COMPRESSED;
else if (strcmp(*argv, "uncompressed") == 0)
form = POINT_CONVERSION_UNCOMPRESSED;
else if (strcmp(*argv, "hybrid") == 0)
form = POINT_CONVERSION_HYBRID;
else
goto bad;
}
else if (strcmp(*argv, "-param_enc") == 0)
{
if (--argc < 1)
goto bad;
++argv;
new_asn1_flag = 1;
if (strcmp(*argv, "named_curve") == 0)
asn1_flag = OPENSSL_EC_NAMED_CURVE;
else if (strcmp(*argv, "explicit") == 0)
asn1_flag = 0;
else
goto bad;
}
else if (strcmp(*argv, "-no_seed") == 0)
no_seed = 1;
else if (strcmp(*argv, "-noout") == 0)
noout=1;
else if (strcmp(*argv,"-genkey") == 0)
{
genkey=1;
need_rand=1;
}
else if (strcmp(*argv, "-rand") == 0)
{
if (--argc < 1) goto bad;
inrand= *(++argv);
need_rand=1;
}
else if(strcmp(*argv, "-engine") == 0)
{
if (--argc < 1) goto bad;
engine = *(++argv);
}
else
{
BIO_printf(bio_err,"unknown option %s\n",*argv);
badops=1;
break;
}
argc--;
argv++;
}
if (badops)
{
bad:
BIO_printf(bio_err, "%s [options] <infile >outfile\n",prog);
BIO_printf(bio_err, "where options are\n");
BIO_printf(bio_err, " -inform arg input format - "
"default PEM (DER or PEM)\n");
BIO_printf(bio_err, " -outform arg output format - "
"default PEM\n");
BIO_printf(bio_err, " -in arg input file - "
"default stdin\n");
BIO_printf(bio_err, " -out arg output file - "
"default stdout\n");
BIO_printf(bio_err, " -noout do not print the "
"ec parameter\n");
BIO_printf(bio_err, " -text print the ec "
"parameters in text form\n");
BIO_printf(bio_err, " -check validate the ec "
"parameters\n");
BIO_printf(bio_err, " -C print a 'C' "
"function creating the parameters\n");
BIO_printf(bio_err, " -name arg use the "
"ec parameters with 'short name' name\n");
BIO_printf(bio_err, " -list_curves prints a list of "
"all currently available curve 'short names'\n");
BIO_printf(bio_err, " -conv_form arg specifies the "
"point conversion form \n");
BIO_printf(bio_err, " possible values:"
" compressed\n");
BIO_printf(bio_err, " "
" uncompressed (default)\n");
BIO_printf(bio_err, " "
" hybrid\n");
BIO_printf(bio_err, " -param_enc arg specifies the way"
" the ec parameters are encoded\n");
BIO_printf(bio_err, " in the asn1 der "
"encoding\n");
BIO_printf(bio_err, " possible values:"
" named_curve (default)\n");
BIO_printf(bio_err, " "
" explicit\n");
BIO_printf(bio_err, " -no_seed if 'explicit'"
" parameters are choosen do not"
" use the seed\n");
BIO_printf(bio_err, " -genkey generate ec"
" key\n");
BIO_printf(bio_err, " -rand file files to use for"
" random number input\n");
BIO_printf(bio_err, " -engine e use engine e, "
"possibly a hardware device\n");
goto end;
}
ERR_load_crypto_strings();
in=BIO_new(BIO_s_file());
out=BIO_new(BIO_s_file());
if ((in == NULL) || (out == NULL))
{
ERR_print_errors(bio_err);
goto end;
}
if (infile == NULL)
BIO_set_fp(in,stdin,BIO_NOCLOSE);
else
{
if (BIO_read_filename(in,infile) <= 0)
{
perror(infile);
goto end;
}
}
if (outfile == NULL)
{
BIO_set_fp(out,stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
{
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
out = BIO_push(tmpbio, out);
}
#endif
}
else
{
if (BIO_write_filename(out,outfile) <= 0)
{
perror(outfile);
goto end;
}
}
e = setup_engine(bio_err, engine, 0);
if (list_curves)
{
EC_builtin_curve *curves = NULL;
size_t crv_len = 0;
size_t n = 0;
size_t len;
crv_len = EC_get_builtin_curves(NULL, 0);
curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
if (curves == NULL)
goto end;
if (!EC_get_builtin_curves(curves, crv_len))
{
OPENSSL_free(curves);
goto end;
}
for (n = 0; n < crv_len; n++)
{
const char *comment;
const char *sname;
comment = curves[n].comment;
sname = OBJ_nid2sn(curves[n].nid);
if (comment == NULL)
comment = "CURVE DESCRIPTION NOT AVAILABLE";
if (sname == NULL)
sname = "";
len = BIO_printf(out, " %-10s: ", sname);
if (len + strlen(comment) > 80)
BIO_printf(out, "\n%80s\n", comment);
else
BIO_printf(out, "%s\n", comment);
}
OPENSSL_free(curves);
ret = 0;
goto end;
}
if (curve_name != NULL)
{
int nid = OBJ_sn2nid(curve_name);
if (nid == 0)
{
BIO_printf(bio_err, "unknown curve name (%s)\n",
curve_name);
goto end;
}
group = EC_GROUP_new_by_nid(nid);
if (group == NULL)
{
BIO_printf(bio_err, "unable to create curve (%s)\n",
curve_name);
goto end;
}
EC_GROUP_set_asn1_flag(group, asn1_flag);
EC_GROUP_set_point_conversion_form(group, form);
}
else if (informat == FORMAT_ASN1)
{
group = d2i_ECPKParameters_bio(in, NULL);
}
else if (informat == FORMAT_PEM)
{
group = PEM_read_bio_ECPKParameters(in,NULL,NULL,NULL);
}
else
{
BIO_printf(bio_err, "bad input format specified\n");
goto end;
}
if (group == NULL)
{
BIO_printf(bio_err,
"unable to load elliptic curve parameters\n");
ERR_print_errors(bio_err);
goto end;
}
if (new_form)
EC_GROUP_set_point_conversion_form(group, form);
if (new_asn1_flag)
EC_GROUP_set_asn1_flag(group, asn1_flag);
if (no_seed)
{
EC_GROUP_set_seed(group, NULL, 0);
}
if (text)
{
if (!ECPKParameters_print(out, group, 0))
goto end;
}
if (check)
{
if (group == NULL)
BIO_printf(bio_err, "no elliptic curve parameters\n");
BIO_printf(bio_err, "checking elliptic curve parameters: ");
if (!EC_GROUP_check(group, NULL))
{
BIO_printf(bio_err, "failed\n");
ERR_print_errors(bio_err);
}
else
BIO_printf(bio_err, "ok\n");
}
if (C)
{
size_t buf_len = 0, tmp_len = 0;
const EC_POINT *point;
int is_prime, len = 0;
const EC_METHOD *meth = EC_GROUP_method_of(group);
if ((ec_p = BN_new()) == NULL || (ec_a = BN_new()) == NULL ||
(ec_b = BN_new()) == NULL || (ec_gen = BN_new()) == NULL ||
(ec_order = BN_new()) == NULL ||
(ec_cofactor = BN_new()) == NULL )
{
perror("OPENSSL_malloc");
goto end;
}
is_prime = (EC_METHOD_get_field_type(meth) ==
NID_X9_62_prime_field);
if (is_prime)
{
if (!EC_GROUP_get_curve_GFp(group, ec_p, ec_a,
ec_b, NULL))
goto end;
}
else
{
/* TODO */
goto end;
}
if ((point = EC_GROUP_get0_generator(group)) == NULL)
goto end;
if (!EC_POINT_point2bn(group, point,
EC_GROUP_get_point_conversion_form(group), ec_gen,
NULL))
goto end;
if (!EC_GROUP_get_order(group, ec_order, NULL))
goto end;
if (!EC_GROUP_get_cofactor(group, ec_cofactor, NULL))
goto end;
if (!ec_p || !ec_a || !ec_b || !ec_gen ||
!ec_order || !ec_cofactor)
goto end;
len = BN_num_bits(ec_order);
if ((tmp_len = (size_t)BN_num_bytes(ec_p)) > buf_len)
buf_len = tmp_len;
if ((tmp_len = (size_t)BN_num_bytes(ec_a)) > buf_len)
buf_len = tmp_len;
if ((tmp_len = (size_t)BN_num_bytes(ec_b)) > buf_len)
buf_len = tmp_len;
if ((tmp_len = (size_t)BN_num_bytes(ec_gen)) > buf_len)
buf_len = tmp_len;
if ((tmp_len = (size_t)BN_num_bytes(ec_order)) > buf_len)
buf_len = tmp_len;
if ((tmp_len = (size_t)BN_num_bytes(ec_cofactor)) > buf_len)
buf_len = tmp_len;
buffer = (unsigned char *)OPENSSL_malloc(buf_len);
if (buffer == NULL)
{
perror("OPENSSL_malloc");
goto end;
}
ecparam_print_var(out, ec_p, "ec_p", len, buffer);
ecparam_print_var(out, ec_a, "ec_a", len, buffer);
ecparam_print_var(out, ec_b, "ec_b", len, buffer);
ecparam_print_var(out, ec_gen, "ec_gen", len, buffer);
ecparam_print_var(out, ec_order, "ec_order", len, buffer);
ecparam_print_var(out, ec_cofactor, "ec_cofactor", len,
buffer);
BIO_printf(out, "\n\n");
BIO_printf(out, "EC_GROUP *get_ec_group_%d(void)\n\t{\n", len);
BIO_printf(out, "\tint ok=0;\n");
BIO_printf(out, "\tEC_GROUP *group = NULL;\n");
BIO_printf(out, "\tEC_POINT *point = NULL;\n");
BIO_printf(out, "\tBIGNUM *tmp_1 = NULL, *tmp_2 = NULL, "
"*tmp_3 = NULL;\n\n");
BIO_printf(out, "\tif ((tmp_1 = BN_bin2bn(ec_p_%d, "
"sizeof(ec_p_%d), NULL)) == NULL)\n\t\t"
"goto err;\n", len, len);
BIO_printf(out, "\tif ((tmp_2 = BN_bin2bn(ec_a_%d, "
"sizeof(ec_a_%d), NULL)) == NULL)\n\t\t"
"goto err;\n", len, len);
BIO_printf(out, "\tif ((tmp_3 = BN_bin2bn(ec_b_%d, "
"sizeof(ec_b_%d), NULL)) == NULL)\n\t\t"
"goto err;\n", len, len);
if (is_prime)
{
BIO_printf(out, "\tif ((group = EC_GROUP_new_curve_"
"GFp(tmp_1, tmp_2, tmp_3, NULL)) == NULL)"
"\n\t\tgoto err;\n\n");
}
else
{
/* TODO */
goto end;
}
BIO_printf(out, "\t/* build generator */\n");
BIO_printf(out, "\tif ((tmp_1 = BN_bin2bn(ec_gen_%d, "
"sizeof(ec_gen_%d), tmp_1)) == NULL)"
"\n\t\tgoto err;\n", len, len);
BIO_printf(out, "\tpoint = EC_POINT_bn2point(group, tmp_1, "
"NULL, NULL);\n");
BIO_printf(out, "\tif (point == NULL)\n\t\tgoto err;\n");
BIO_printf(out, "\tif ((tmp_2 = BN_bin2bn(ec_order_%d, "
"sizeof(ec_order_%d), tmp_2)) == NULL)"
"\n\t\tgoto err;\n", len, len);
BIO_printf(out, "\tif ((tmp_3 = BN_bin2bn(ec_cofactor_%d, "
"sizeof(ec_cofactor_%d), tmp_3)) == NULL)"
"\n\t\tgoto err;\n", len, len);
BIO_printf(out, "\tif (!EC_GROUP_set_generator(group, point,"
" tmp_2, tmp_3))\n\t\tgoto err;\n");
BIO_printf(out, "\n\tok=1;\n");
BIO_printf(out, "err:\n");
BIO_printf(out, "\tif (tmp_1)\n\t\tBN_free(tmp_1);\n");
BIO_printf(out, "\tif (tmp_2)\n\t\tBN_free(tmp_2);\n");
BIO_printf(out, "\tif (tmp_3)\n\t\tBN_free(tmp_3);\n");
BIO_printf(out, "\tif (point)\n\t\tEC_POINT_free(point);\n");
BIO_printf(out, "\tif (!ok)\n");
BIO_printf(out, "\t\t{\n");
BIO_printf(out, "\t\tEC_GROUP_free(group);\n");
BIO_printf(out, "\t\tgroup = NULL;\n");
BIO_printf(out, "\t\t}\n");
BIO_printf(out, "\treturn(group);\n\t}\n");
}
if (!noout)
{
if (outformat == FORMAT_ASN1)
i = i2d_ECPKParameters_bio(out, group);
else if (outformat == FORMAT_PEM)
i = PEM_write_bio_ECPKParameters(out, group);
else
{
BIO_printf(bio_err,"bad output format specified for"
" outfile\n");
goto end;
}
if (!i)
{
BIO_printf(bio_err, "unable to write elliptic "
"curve parameters\n");
ERR_print_errors(bio_err);
goto end;
}
}
if (need_rand)
{
app_RAND_load_file(NULL, bio_err, (inrand != NULL));
if (inrand != NULL)
BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
app_RAND_load_files(inrand));
}
if (genkey)
{
EC_KEY *eckey = EC_KEY_new();
if (eckey == NULL)
goto end;
assert(need_rand);
eckey->group = group;
if (!EC_KEY_generate_key(eckey))
{
eckey->group = NULL;
EC_KEY_free(eckey);
goto end;
}
if (outformat == FORMAT_ASN1)
i = i2d_ECPrivateKey_bio(out, eckey);
else if (outformat == FORMAT_PEM)
i = PEM_write_bio_ECPrivateKey(out, eckey, NULL,
NULL, 0, NULL, NULL);
else
{
BIO_printf(bio_err, "bad output format specified "
"for outfile\n");
eckey->group = NULL;
EC_KEY_free(eckey);
goto end;
}
eckey->group = NULL;
EC_KEY_free(eckey);
}
if (need_rand)
app_RAND_write_file(NULL, bio_err);
ret=0;
end:
if (ec_p)
BN_free(ec_p);
if (ec_a)
BN_free(ec_a);
if (ec_b)
BN_free(ec_b);
if (ec_gen)
BN_free(ec_gen);
if (ec_order)
BN_free(ec_order);
if (ec_cofactor)
BN_free(ec_cofactor);
if (buffer)
OPENSSL_free(buffer);
if (in != NULL)
BIO_free(in);
if (out != NULL)
BIO_free_all(out);
if (group != NULL)
EC_GROUP_free(group);
apps_shutdown();
EXIT(ret);
}
int ecparam_print_var(BIO *out, BIGNUM *in, const char *var,
int len, unsigned char *buffer)
{
BIO_printf(out, "static unsigned char %s_%d[] = {", var, len);
if (BN_is_zero(in))
BIO_printf(out, "\n\t0x00");
else
{
int i, l;
l = BN_bn2bin(in, buffer);
for (i=0; i<l-1; i++)
{
if ((i%12) == 0)
BIO_printf(out, "\n\t");
BIO_printf(out, "0x%02X,", buffer[i]);
}
if ((i%12) == 0)
BIO_printf(out, "\n\t");
BIO_printf(out, "0x%02X", buffer[i]);
}
BIO_printf(out, "\n\t};\n\n");
return 1;
}
#endif

View File

@ -139,13 +139,13 @@ $! Define The Application Files.
$!
$ LIB_FILES = "VERIFY;ASN1PARS;REQ;DGST;DH;DHPARAM;ENC;PASSWD;GENDH;ERRSTR;"+-
"CA;PKCS7;CRL2P7;CRL;"+-
"RSA;RSAUTL;DSA;DSAPARAM;EC;ECPARAM;"+-
"RSA;RSAUTL;DSA;DSAPARAM;"+-
"X509;GENRSA;GENDSA;S_SERVER;S_CLIENT;SPEED;"+-
"S_TIME;APPS;S_CB;S_SOCKET;APP_RAND;VERSION;SESS_ID;"+-
"CIPHERS;NSEQ;PKCS12;PKCS8;SPKAC;SMIME;RAND;ENGINE;OCSP"
$ APP_FILES := OPENSSL,'OBJ_DIR'VERIFY.OBJ,ASN1PARS.OBJ,REQ.OBJ,DGST.OBJ,DH.OBJ,DHPARAM.OBJ,ENC.OBJ,PASSWD.OBJ,GENDH.OBJ,ERRSTR.OBJ,-
CA.OBJ,PKCS7.OBJ,CRL2P7.OBJ,CRL.OBJ,-
RSA.OBJ,RSAUTL.OBJ,DSA.OBJ,DSAPARAM.OBJ,EC.OBJ,ECPARAM.OBJ,-
RSA.OBJ,RSAUTL.OBJ,DSA.OBJ,DSAPARAM.OBJ,-
X509.OBJ,GENRSA.OBJ,GENDSA.OBJ,S_SERVER.OBJ,S_CLIENT.OBJ,SPEED.OBJ,-
S_TIME.OBJ,APPS.OBJ,S_CB.OBJ,S_SOCKET.OBJ,APP_RAND.OBJ,VERSION.OBJ,SESS_ID.OBJ,-
CIPHERS.OBJ,NSEQ.OBJ,PKCS12.OBJ,PKCS8.OBJ,SPKAC.OBJ,SMIME.OBJ,RAND.OBJ,ENGINE.OBJ,OCSP.OBJ

View File

@ -229,6 +229,10 @@ int main(int Argc, char *Argv[])
arg.data=NULL;
arg.count=0;
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
if (getenv("OPENSSL_DEBUG_MEMORY") != NULL) /* if not defined, use compiled-in library defaults */
{
if (!(0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off")))
@ -253,10 +257,6 @@ int main(int Argc, char *Argv[])
apps_startup();
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
/* Lets load up our environment a little */
p=getenv("OPENSSL_CONF");
if (p == NULL)

View File

@ -2,10 +2,10 @@
#if !defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_SHA1)
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
* project.
* project 1999.
*/
/* ====================================================================
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
* 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
@ -164,14 +164,10 @@ int MAIN(int argc, char **argv)
maciter = PKCS12_DEFAULT_ITER;
else if (!strcmp (*args, "-nomaciter"))
maciter = 1;
else if (!strcmp (*args, "-nomac"))
maciter = -1;
else if (!strcmp (*args, "-nodes")) enc=NULL;
else if (!strcmp (*args, "-certpbe")) {
if (args[1]) {
args++;
if (!strcmp(*args, "NONE"))
cert_pbe = -1;
cert_pbe=OBJ_txt2nid(*args);
if(cert_pbe == NID_undef) {
BIO_printf(bio_err,
@ -182,10 +178,7 @@ int MAIN(int argc, char **argv)
} else if (!strcmp (*args, "-keypbe")) {
if (args[1]) {
args++;
if (!strcmp(*args, "NONE"))
key_pbe = -1;
else
key_pbe=OBJ_txt2nid(*args);
key_pbe=OBJ_txt2nid(*args);
if(key_pbe == NID_undef) {
BIO_printf(bio_err,
"Unknown PBE algorithm %s\n", *args);
@ -364,6 +357,24 @@ int MAIN(int argc, char **argv)
goto end;
}
#if 0
if (certfile) {
if(!(certsin = BIO_new_file(certfile, "r"))) {
BIO_printf(bio_err, "Can't open certificate file %s\n", certfile);
perror (certfile);
goto end;
}
}
if (keyname) {
if(!(inkey = BIO_new_file(keyname, "r"))) {
BIO_printf(bio_err, "Can't key certificate file %s\n", keyname);
perror (keyname);
goto end;
}
}
#endif
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("write files");
@ -400,31 +411,27 @@ int MAIN(int argc, char **argv)
if (export_cert) {
EVP_PKEY *key = NULL;
X509 *ucert = NULL, *x = NULL;
STACK_OF(PKCS12_SAFEBAG) *bags = NULL;
STACK_OF(PKCS7) *safes = NULL;
PKCS12_SAFEBAG *bag = NULL;
PKCS8_PRIV_KEY_INFO *p8 = NULL;
PKCS7 *authsafe = NULL;
X509 *ucert = NULL;
STACK_OF(X509) *certs=NULL;
unsigned char *catmp = NULL;
char *catmp = NULL;
int i;
if ((options & (NOCERTS|NOKEYS)) == (NOCERTS|NOKEYS))
{
BIO_printf(bio_err, "Nothing to do!\n");
goto export_end;
}
if (options & NOCERTS)
chain = 0;
unsigned char keyid[EVP_MAX_MD_SIZE];
unsigned int keyidlen = 0;
#ifdef CRYPTO_MDEBUG
CRYPTO_push_info("process -export_cert");
CRYPTO_push_info("reading private key");
#endif
if (!(options & NOKEYS))
{
key = load_key(bio_err, keyname ? keyname : infile,
FORMAT_PEM, 1, passin, e, "private key");
if (!key)
goto export_end;
}
key = load_key(bio_err, keyname ? keyname : infile, FORMAT_PEM, 1,
passin, e, "private key");
if (!key) {
goto export_end;
}
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
@ -432,62 +439,50 @@ int MAIN(int argc, char **argv)
#endif
/* Load in all certs in input file */
if(!(options & NOCERTS))
{
certs = load_certs(bio_err, infile, FORMAT_PEM, NULL, e,
"certificates");
if (!certs)
goto export_end;
if (key)
{
/* Look for matching private key */
for(i = 0; i < sk_X509_num(certs); i++)
{
x = sk_X509_value(certs, i);
if(X509_check_private_key(x, key))
{
ucert = x;
/* Zero keyid and alias */
X509_keyid_set1(ucert, NULL, 0);
X509_alias_set1(ucert, NULL, 0);
/* Remove from list */
sk_X509_delete(certs, i);
break;
}
}
if (!ucert)
{
BIO_printf(bio_err, "No certificate matches private key\n");
goto export_end;
}
}
}
if(!(certs = load_certs(bio_err, infile, FORMAT_PEM, NULL, e,
"certificates"))) {
goto export_end;
}
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("reading certs from input 2");
#endif
/* Add any more certificates asked for */
if(certfile)
{
STACK_OF(X509) *morecerts=NULL;
if(!(morecerts = load_certs(bio_err, certfile, FORMAT_PEM,
NULL, e,
"certificates from certfile")))
goto export_end;
while(sk_X509_num(morecerts) > 0)
sk_X509_push(certs, sk_X509_shift(morecerts));
sk_X509_free(morecerts);
}
for(i = 0; i < sk_X509_num(certs); i++) {
ucert = sk_X509_value(certs, i);
if(X509_check_private_key(ucert, key)) {
X509_digest(ucert, EVP_sha1(), keyid, &keyidlen);
break;
}
}
if(!keyidlen) {
ucert = NULL;
BIO_printf(bio_err, "No certificate matches private key\n");
goto export_end;
}
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("reading certs from certfile");
#endif
bags = sk_PKCS12_SAFEBAG_new_null ();
/* Add any more certificates asked for */
if (certfile) {
STACK_OF(X509) *morecerts=NULL;
if(!(morecerts = load_certs(bio_err, certfile, FORMAT_PEM,
NULL, e,
"certificates from certfile"))) {
goto export_end;
}
while(sk_X509_num(morecerts) > 0) {
sk_X509_push(certs, sk_X509_shift(morecerts));
}
sk_X509_free(morecerts);
}
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("building chain");
@ -523,51 +518,100 @@ int MAIN(int argc, char **argv)
}
}
/* Add any CA names */
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("building bags");
#endif
for (i = 0; i < sk_num(canames); i++)
{
catmp = (unsigned char *)sk_value(canames, i);
X509_alias_set1(sk_X509_value(certs, i), catmp, -1);
}
/* We now have loads of certificates: include them all */
for(i = 0; i < sk_X509_num(certs); i++) {
X509 *cert = NULL;
cert = sk_X509_value(certs, i);
bag = PKCS12_x5092certbag(cert);
/* If it matches private key set id */
if(cert == ucert) {
if(name) PKCS12_add_friendlyname(bag, name, -1);
PKCS12_add_localkeyid(bag, keyid, keyidlen);
} else if((catmp = sk_shift(canames)))
PKCS12_add_friendlyname(bag, catmp, -1);
sk_PKCS12_SAFEBAG_push(bags, bag);
}
sk_X509_pop_free(certs, X509_free);
certs = NULL;
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("reading password");
CRYPTO_push_info("encrypting bags");
#endif
if(!noprompt &&
EVP_read_pw_string(pass, sizeof pass, "Enter Export Password:", 1))
{
BIO_printf (bio_err, "Can't read Password\n");
goto export_end;
}
EVP_read_pw_string(pass, sizeof pass, "Enter Export Password:", 1)) {
BIO_printf (bio_err, "Can't read Password\n");
goto export_end;
}
if (!twopass) strcpy(macpass, pass);
/* Turn certbags into encrypted authsafe */
authsafe = PKCS12_pack_p7encdata(cert_pbe, cpass, -1, NULL, 0,
iter, bags);
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
bags = NULL;
if (!authsafe) {
ERR_print_errors (bio_err);
goto export_end;
}
safes = sk_PKCS7_new_null ();
sk_PKCS7_push (safes, authsafe);
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("creating PKCS#12 structure");
CRYPTO_push_info("building shrouded key bag");
#endif
p12 = PKCS12_create(pass, name, key, ucert, certs,
key_pbe, cert_pbe, iter, -1, keytype);
/* Make a shrouded key bag */
p8 = EVP_PKEY2PKCS8 (key);
if(keytype) PKCS8_add_keyusage(p8, keytype);
bag = PKCS12_MAKE_SHKEYBAG(key_pbe, cpass, -1, NULL, 0, iter, p8);
PKCS8_PRIV_KEY_INFO_free(p8);
p8 = NULL;
if (name) PKCS12_add_friendlyname (bag, name, -1);
if(csp_name) PKCS12_add_CSPName_asc(bag, csp_name, -1);
PKCS12_add_localkeyid (bag, keyid, keyidlen);
bags = sk_PKCS12_SAFEBAG_new_null();
sk_PKCS12_SAFEBAG_push (bags, bag);
if (!p12)
{
ERR_print_errors (bio_err);
goto export_end;
}
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("encrypting shrouded key bag");
#endif
if (maciter != -1)
PKCS12_set_mac(p12, mpass, -1, NULL, 0, maciter, NULL);
/* Turn it into unencrypted safe bag */
authsafe = PKCS12_pack_p7data (bags);
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
bags = NULL;
sk_PKCS7_push (safes, authsafe);
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("building pkcs12");
#endif
p12 = PKCS12_init(NID_pkcs7_data);
PKCS12_pack_authsafes(p12, safes);
sk_PKCS7_pop_free(safes, PKCS7_free);
safes = NULL;
PKCS12_set_mac (p12, mpass, -1, NULL, 0, maciter, NULL);
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();
CRYPTO_push_info("writing pkcs12");
#endif
i2d_PKCS12_bio(out, p12);
i2d_PKCS12_bio (out, p12);
ret = 0;
@ -580,7 +624,8 @@ int MAIN(int argc, char **argv)
if (key) EVP_PKEY_free(key);
if (certs) sk_X509_pop_free(certs, X509_free);
if (ucert) X509_free(ucert);
if (safes) sk_PKCS7_pop_free(safes, PKCS7_free);
if (bags) sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
#ifdef CRYPTO_MDEBUG
CRYPTO_pop_info();

View File

@ -17,8 +17,6 @@ extern int rsa_main(int argc,char *argv[]);
extern int rsautl_main(int argc,char *argv[]);
extern int dsa_main(int argc,char *argv[]);
extern int dsaparam_main(int argc,char *argv[]);
extern int ec_main(int argc,char *argv[]);
extern int ecparam_main(int argc,char *argv[]);
extern int x509_main(int argc,char *argv[]);
extern int genrsa_main(int argc,char *argv[]);
extern int gendsa_main(int argc,char *argv[]);
@ -80,12 +78,6 @@ FUNCTION functions[] = {
#endif
#ifndef OPENSSL_NO_DSA
{FUNC_TYPE_GENERAL,"dsaparam",dsaparam_main},
#endif
#ifndef OPENSSL_NO_EC
{FUNC_TYPE_GENERAL,"ec",ec_main},
#endif
#ifndef OPENSSL_NO_EC
{FUNC_TYPE_GENERAL,"ecparam",ecparam_main},
#endif
{FUNC_TYPE_GENERAL,"x509",x509_main},
#ifndef OPENSSL_NO_RSA

View File

@ -33,8 +33,6 @@ foreach (@ARGV)
{ print "#ifndef OPENSSL_NO_RSA\n${str}#endif\n"; }
elsif ( ($_ =~ /^dsa$/) || ($_ =~ /^gendsa$/) || ($_ =~ /^dsaparam$/))
{ print "#ifndef OPENSSL_NO_DSA\n${str}#endif\n"; }
elsif ( ($_ =~ /^ec$/) || ($_ =~ /^ecparam$/))
{ print "#ifndef OPENSSL_NO_EC\n${str}#endif\n";}
elsif ( ($_ =~ /^dh$/) || ($_ =~ /^gendh$/) || ($_ =~ /^dhparam$/))
{ print "#ifndef OPENSSL_NO_DH\n${str}#endif\n"; }
elsif ( ($_ =~ /^pkcs12$/))

View File

@ -143,7 +143,6 @@ static int batch=0;
#define TYPE_RSA 1
#define TYPE_DSA 2
#define TYPE_DH 3
#define TYPE_EC 4
int MAIN(int, char **);
@ -152,9 +151,6 @@ int MAIN(int argc, char **argv)
ENGINE *e = NULL;
#ifndef OPENSSL_NO_DSA
DSA *dsa_params=NULL;
#endif
#ifndef OPENSSL_NO_ECDSA
EC_KEY *ec_params = NULL;
#endif
unsigned long nmflag = 0, reqflag = 0;
int ex=1,x509=0,days=30;
@ -323,59 +319,11 @@ int MAIN(int argc, char **argv)
}
}
BIO_free(in);
in=NULL;
newkey=BN_num_bits(dsa_params->p);
in=NULL;
}
else
#endif
#ifndef OPENSSL_NO_ECDSA
if (strncmp("ec:",p,3) == 0)
{
X509 *xtmp=NULL;
EVP_PKEY *dtmp;
pkey_type=TYPE_EC;
p+=3;
if ((in=BIO_new_file(p,"r")) == NULL)
{
perror(p);
goto end;
}
if ((ec_params = EC_KEY_new()) == NULL)
goto end;
if ((ec_params->group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL)) == NULL)
{
if (ec_params)
EC_KEY_free(ec_params);
ERR_clear_error();
(void)BIO_reset(in);
if ((xtmp=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL)
{
BIO_printf(bio_err,"unable to load EC parameters from file\n");
goto end;
}
if ((dtmp=X509_get_pubkey(xtmp))==NULL)
goto end;
if (dtmp->type == EVP_PKEY_EC)
ec_params = ECParameters_dup(dtmp->pkey.eckey);
EVP_PKEY_free(dtmp);
X509_free(xtmp);
if (ec_params == NULL)
{
BIO_printf(bio_err,"Certificate does not contain EC parameters\n");
goto end;
}
}
BIO_free(in);
in=NULL;
newkey = EC_GROUP_get_degree(ec_params->group);
}
else
#endif
#ifndef OPENSSL_NO_DH
if (strncmp("dh:",p,4) == 0)
{
@ -384,9 +332,7 @@ int MAIN(int argc, char **argv)
}
else
#endif
{
goto bad;
}
pkey_type=TYPE_RSA;
newreq=1;
}
@ -494,9 +440,6 @@ bad:
BIO_printf(bio_err," the random number generator\n");
BIO_printf(bio_err," -newkey rsa:bits generate a new RSA key of 'bits' in size\n");
BIO_printf(bio_err," -newkey dsa:file generate a new DSA key, parameters taken from CA in 'file'\n");
#ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err," -newkey ec:file generate a new EC key, parameters taken from CA in 'file'\n");
#endif
BIO_printf(bio_err," -[digest] Digest to sign with (md5, sha1, md2, mdc2, md4)\n");
BIO_printf(bio_err," -config file request template file.\n");
BIO_printf(bio_err," -subj arg set or modify request subject\n");
@ -687,8 +630,7 @@ bad:
message */
goto end;
}
if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA ||
EVP_PKEY_type(pkey->type) == EVP_PKEY_EC)
if (EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA)
{
char *randfile = NCONF_get_string(req_conf,SECTION,"RANDFILE");
if (randfile == NULL)
@ -712,15 +654,14 @@ bad:
newkey=DEFAULT_KEY_LENGTH;
}
if (newkey < MIN_KEY_LENGTH && (pkey_type == TYPE_RSA || pkey_type == TYPE_DSA))
if (newkey < MIN_KEY_LENGTH)
{
BIO_printf(bio_err,"private key length is too short,\n");
BIO_printf(bio_err,"it needs to be at least %d bits, not %d\n",MIN_KEY_LENGTH,newkey);
goto end;
}
BIO_printf(bio_err,"Generating a %d bit %s private key\n",
newkey,(pkey_type == TYPE_RSA)?"RSA":
(pkey_type == TYPE_DSA)?"DSA":"EC");
newkey,(pkey_type == TYPE_RSA)?"RSA":"DSA");
if ((pkey=EVP_PKEY_new()) == NULL) goto end;
@ -742,15 +683,6 @@ bad:
dsa_params=NULL;
}
#endif
#ifndef OPENSSL_NO_ECDSA
if (pkey_type == TYPE_EC)
{
if (!EC_KEY_generate_key(ec_params)) goto end;
if (!EVP_PKEY_assign_EC_KEY(pkey, ec_params))
goto end;
ec_params = NULL;
}
#endif
app_RAND_write_file(randfile, bio_err);
@ -856,10 +788,6 @@ loop:
#ifndef OPENSSL_NO_DSA
if (pkey->type == EVP_PKEY_DSA)
digest=EVP_dss1();
#endif
#ifndef OPENSSL_NO_ECDSA
if (pkey->type == EVP_PKEY_EC)
digest=EVP_ecdsa();
#endif
if (req == NULL)
{
@ -1145,9 +1073,6 @@ end:
OBJ_cleanup();
#ifndef OPENSSL_NO_DSA
if (dsa_params != NULL) DSA_free(dsa_params);
#endif
#ifndef OPENSSL_NO_ECDSA
if (ec_params != NULL) EC_KEY_free(ec_params);
#endif
apps_shutdown();
EXIT(ex);

View File

@ -108,11 +108,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* ECC cipher suite support in OpenSSL originally developed by
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#include <assert.h>
#include <stdio.h>
@ -177,7 +172,6 @@ static int generate_session_id(const SSL *ssl, unsigned char *id,
static DH *load_dh_param(char *dhfile);
static DH *get_dh512(void);
#endif
#ifdef MONOLITH
static void s_server_init(void);
#endif
@ -216,7 +210,6 @@ static DH *get_dh512(void)
}
#endif
/* static int load_CA(SSL_CTX *ctx, char *file);*/
#undef BUFSIZZ
@ -294,11 +287,6 @@ static void sv_usage(void)
BIO_printf(bio_err," -dkey arg - second private key file to use (usually for DSA)\n");
BIO_printf(bio_err," -dhparam arg - DH parameter file to use, in cert file if not specified\n");
BIO_printf(bio_err," or a default set of parameters is used\n");
#ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err," -named_curve arg - Elliptic curve name to use for ephemeral ECDH keys.\n" \
" Use \"openssl ecparam -list_curves\" for all names\n" \
" (default is sect163r2).\n");
#endif
#ifdef FIONBIO
BIO_printf(bio_err," -nbio - Run with non-blocking IO\n");
#endif
@ -322,9 +310,6 @@ static void sv_usage(void)
BIO_printf(bio_err," -no_tls1 - Just disable TLSv1\n");
#ifndef OPENSSL_NO_DH
BIO_printf(bio_err," -no_dhe - Disable ephemeral DH\n");
#endif
#ifndef OPENSSL_NO_ECDH
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," -www - Respond to a 'GET /' with a status page\n");
@ -499,11 +484,10 @@ int MAIN(int argc, char *argv[])
char *CApath=NULL,*CAfile=NULL;
char *context = NULL;
char *dhfile = NULL;
char *named_curve = NULL;
int badop=0,bugs=0;
int ret=1;
int off=0;
int no_tmp_rsa=0,no_dhe=0,no_ecdhe=0,nocert=0;
int no_tmp_rsa=0,no_dhe=0,nocert=0;
int state=0;
SSL_METHOD *meth=NULL;
ENGINE *e=NULL;
@ -584,13 +568,6 @@ int MAIN(int argc, char *argv[])
if (--argc < 1) goto bad;
dhfile = *(++argv);
}
#ifndef OPENSSL_NO_ECDH
else if (strcmp(*argv,"-named_curve") == 0)
{
if (--argc < 1) goto bad;
named_curve = *(++argv);
}
#endif
else if (strcmp(*argv,"-dcert") == 0)
{
if (--argc < 1) goto bad;
@ -659,8 +636,6 @@ int MAIN(int argc, char *argv[])
{ no_tmp_rsa=1; }
else if (strcmp(*argv,"-no_dhe") == 0)
{ no_dhe=1; }
else if (strcmp(*argv,"-no_ecdhe") == 0)
{ no_ecdhe=1; }
else if (strcmp(*argv,"-www") == 0)
{ www=1; }
else if (strcmp(*argv,"-WWW") == 0)
@ -743,7 +718,7 @@ bad:
}
}
#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
if (nocert)
#endif
{
@ -831,59 +806,6 @@ bad:
DH_free(dh);
}
#endif
#ifndef OPENSSL_NO_ECDH
if (!no_ecdhe)
{
EC_KEY *ecdh=NULL;
ecdh = EC_KEY_new();
if (ecdh == NULL)
{
BIO_printf(bio_err,"Could not create ECDH struct.\n");
goto end;
}
if (named_curve)
{
int nid = OBJ_sn2nid(named_curve);
if (nid == 0)
{
BIO_printf(bio_err, "unknown curve name (%s)\n",
named_curve);
goto end;
}
ecdh->group = EC_GROUP_new_by_nid(nid);
if (ecdh->group == NULL)
{
BIO_printf(bio_err, "unable to create curve (%s)\n",
named_curve);
goto end;
}
}
if (ecdh->group != NULL)
{
BIO_printf(bio_s_out,"Setting temp ECDH parameters\n");
}
else
{
BIO_printf(bio_s_out,"Using default temp ECDH parameters\n");
ecdh->group=EC_GROUP_new_by_nid(NID_sect163r2);
if (ecdh->group == NULL)
{
BIO_printf(bio_err, "unable to create curve (sect163r2)\n");
goto end;
}
}
(void)BIO_flush(bio_s_out);
SSL_CTX_set_tmp_ecdh(ctx,ecdh);
EC_KEY_free(ecdh);
}
#endif
if (!set_cert_stuff(ctx,s_cert_file,s_key_file))
goto end;

View File

@ -55,19 +55,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The ECDH and ECDSA speed test software is originally written by
* Sumit Gupta of Sun Microsystems Laboratories.
*
*/
/* most of this code has been pilfered from my libdes speed.c program */
@ -75,8 +62,6 @@
#define SECONDS 3
#define RSA_SECONDS 10
#define DSA_SECONDS 10
#define ECDSA_SECONDS 10
#define ECDH_SECONDS 10
/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
@ -199,16 +184,11 @@
#ifndef OPENSSL_NO_DSA
#include "./testdsa.h"
#endif
#ifndef OPENSSL_NO_ECDSA
#include <openssl/ecdsa.h>
#endif
#ifndef OPENSSL_NO_ECDH
#include <openssl/ecdh.h>
#endif
/* The following if from times(3) man page. It may need to be changed */
#ifndef HZ
# ifdef _SC_CLK_TCK
# if defined(_SC_CLK_TCK) \
&& (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
# define HZ ((double)sysconf(_SC_CLK_TCK))
# else
# ifndef CLK_TCK
@ -247,10 +227,6 @@ static int do_multi(int multi);
#define SIZE_NUM 5
#define RSA_NUM 4
#define DSA_NUM 3
#define EC_NUM 16
#define MAX_ECDH_SIZE 256
static const char *names[ALGOR_NUM]={
"md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
"des cbc","des ede3","idea cbc",
@ -260,9 +236,6 @@ static double results[ALGOR_NUM][SIZE_NUM];
static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
static double rsa_results[RSA_NUM][2];
static double dsa_results[DSA_NUM][2];
static double ecdsa_results[EC_NUM][2];
static double ecdh_results[EC_NUM][1];
#ifdef SIGALRM
#if defined(__STDC__) || defined(sgi) || defined(_AIX)
@ -505,24 +478,6 @@ int MAIN(int argc, char **argv)
#define R_RSA_1024 1
#define R_RSA_2048 2
#define R_RSA_4096 3
#define R_EC_P160 0
#define R_EC_P192 1
#define R_EC_P224 2
#define R_EC_P256 3
#define R_EC_P384 4
#define R_EC_P521 5
#define R_EC_K163 6
#define R_EC_K233 7
#define R_EC_K283 8
#define R_EC_K409 9
#define R_EC_K571 10
#define R_EC_B163 11
#define R_EC_B233 12
#define R_EC_B283 13
#define R_EC_B409 14
#define R_EC_B571 15
#ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
long rsa_c[RSA_NUM][2];
@ -538,83 +493,8 @@ int MAIN(int argc, char **argv)
long dsa_c[DSA_NUM][2];
static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
#endif
#ifndef OPENSSL_NO_EC
/* We only test over the following curves as they are representative,
* To add tests over more curves, simply add the curve NID
* and curve name to the following arrays and increase the
* EC_NUM value accordingly.
*/
static unsigned int test_curves[EC_NUM] =
{
/* Prime Curves */
NID_secp160r1,
NID_X9_62_prime192v1,
NID_secp224r1,
NID_X9_62_prime256v1,
NID_secp384r1,
NID_secp521r1,
/* Binary Curves */
NID_sect163k1,
NID_sect233k1,
NID_sect283k1,
NID_sect409k1,
NID_sect571k1,
NID_sect163r2,
NID_sect233r1,
NID_sect283r1,
NID_sect409r1,
NID_sect571r1
};
static char * test_curves_names[EC_NUM] =
{
/* Prime Curves */
"secp160r1",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
/* Binary Curves */
"nistk163",
"nistk233",
"nistk283",
"nistk409",
"nistk571",
"nistb163",
"nistb233",
"nistb283",
"nistb409",
"nistb571"
};
static int test_curves_bits[EC_NUM] =
{
160, 192, 224, 256, 384, 521,
163, 233, 283, 409, 571,
163, 233, 283, 409, 571
};
#endif
#ifndef OPENSSL_NO_ECDSA
unsigned char ecdsasig[256];
unsigned int ecdsasiglen;
EC_KEY *ecdsa[EC_NUM];
long ecdsa_c[EC_NUM][2];
#endif
#ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
int secret_size_a, secret_size_b;
int ecdh_checks = 0;
int secret_idx = 0;
long ecdh_c[EC_NUM][2];
#endif
int rsa_doit[RSA_NUM];
int dsa_doit[DSA_NUM];
int ecdsa_doit[EC_NUM];
int ecdh_doit[EC_NUM];
int doit[ALGOR_NUM];
int pr_header=0;
const EVP_CIPHER *evp_cipher=NULL;
@ -633,17 +513,6 @@ int MAIN(int argc, char **argv)
#ifndef OPENSSL_NO_DSA
memset(dsa_key,0,sizeof(dsa_key));
#endif
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
{
ecdh_a[i] = NULL;
ecdh_b[i] = NULL;
}
#endif
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
@ -682,15 +551,6 @@ int MAIN(int argc, char **argv)
rsa_doit[i]=0;
for (i=0; i<DSA_NUM; i++)
dsa_doit[i]=0;
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++)
ecdsa_doit[i]=0;
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
ecdh_doit[i]=0;
#endif
j=0;
argc--;
@ -909,52 +769,6 @@ int MAIN(int argc, char **argv)
dsa_doit[R_DSA_1024]=1;
}
else
#endif
#ifndef OPENSSL_NO_ECDSA
if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
else if (strcmp(*argv,"ecdsa") == 0)
{
for (i=0; i < EC_NUM; i++)
ecdsa_doit[i]=1;
}
else
#endif
#ifndef OPENSSL_NO_ECDH
if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
else if (strcmp(*argv,"ecdh") == 0)
{
for (i=0; i < EC_NUM; i++)
ecdh_doit[i]=1;
}
else
#endif
{
BIO_printf(bio_err,"Error: bad option or value\n");
@ -1021,18 +835,6 @@ int MAIN(int argc, char **argv)
#ifndef OPENSSL_NO_DSA
BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
#endif
#ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err,"ecdsap160 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
BIO_printf(bio_err,"ecdsa\n");
#endif
#ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err,"ecdhp160 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
BIO_printf(bio_err,"ecdh\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err,"idea ");
@ -1262,114 +1064,6 @@ int MAIN(int argc, char **argv)
}
#endif
#ifndef OPENSSL_NO_ECDSA
ecdsa_c[R_EC_P160][0]=count/1000;
ecdsa_c[R_EC_P160][1]=count/1000/2;
for (i=R_EC_P224; i<=R_EC_P521; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
ecdsa_c[R_EC_K163][0]=count/1000;
ecdsa_c[R_EC_K163][1]=count/1000/2;
for (i=R_EC_K233; i<=R_EC_K571; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
ecdsa_c[R_EC_B163][0]=count/1000;
ecdsa_c[R_EC_B163][1]=count/1000/2;
for (i=R_EC_B233; i<=R_EC_B571; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
#endif
#ifndef OPENSSL_NO_ECDH
ecdh_c[R_EC_P160][0]=count/1000;
ecdh_c[R_EC_P160][1]=count/1000;
for (i=R_EC_P224; i<=R_EC_P521; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
ecdh_c[R_EC_K163][0]=count/1000;
ecdh_c[R_EC_K163][1]=count/1000;
for (i=R_EC_K233; i<=R_EC_K571; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
ecdh_c[R_EC_B163][0]=count/1000;
ecdh_c[R_EC_B163][1]=count/1000;
for (i=R_EC_B233; i<=R_EC_B571; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
#endif
#define COND(d) (count < (d))
#define COUNT(d) (d)
#else
@ -1894,220 +1588,6 @@ int MAIN(int argc, char **argv)
}
if (rnd_fake) RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDSA
if (RAND_status() != 1)
{
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j=0; j<EC_NUM; j++)
{
int ret;
if (!ecdsa_doit[j]) continue; /* Ignore Curve */
ecdsa[j] = EC_KEY_new();
if (ecdsa[j] == NULL)
{
BIO_printf(bio_err,"ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
ecdsa[j]->group = EC_GROUP_new_by_nid(test_curves[j]);
/* Could not obtain group information */
if (ecdsa[j]->group == NULL)
{
BIO_printf(bio_err,"ECDSA failure.Could not obtain group information\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
/* Perform ECDSA signature test */
EC_KEY_generate_key(ecdsa[j]);
ret = ECDSA_sign(0, buf, 20, ecdsasig,
&ecdsasiglen, ecdsa[j]);
if (ret == 0)
{
BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
pkey_print_message("sign","ecdsa",
ecdsa_c[j][0],
test_curves_bits[j],
ECDSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdsa_c[j][0]);
count++)
{
ret=ECDSA_sign(0, buf, 20,
ecdsasig, &ecdsasiglen,
ecdsa[j]);
if (ret == 0)
{
BIO_printf(bio_err, "ECDSA sign failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
"%ld %d bit ECDSA signs in %.2fs \n",
count, test_curves_bits[j], d);
ecdsa_results[j][0]=d/(double)count;
rsa_count=count;
}
/* Perform ECDSA verification test */
ret=ECDSA_verify(0, buf, 20, ecdsasig,
ecdsasiglen, ecdsa[j]);
if (ret != 1)
{
BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
ERR_print_errors(bio_err);
ecdsa_doit[j] = 0;
}
else
{
pkey_print_message("verify","ecdsa",
ecdsa_c[j][1],
test_curves_bits[j],
ECDSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
{
ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
if (ret != 1)
{
BIO_printf(bio_err, "ECDSA verify failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
: "%ld %d bit ECDSA verify in %.2fs\n",
count, test_curves_bits[j], d);
ecdsa_results[j][1]=d/(double)count;
}
if (rsa_count <= 1)
{
/* if longer than 10s, don't do any more */
for (j++; j<EC_NUM; j++)
ecdsa_doit[j]=0;
}
}
}
}
if (rnd_fake) RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDH
if (RAND_status() != 1)
{
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j=0; j<EC_NUM; j++)
{
if (!ecdh_doit[j]) continue;
ecdh_a[j] = EC_KEY_new();
ecdh_b[j] = EC_KEY_new();
if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
{
BIO_printf(bio_err,"ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
ecdh_a[j]->group = EC_GROUP_new_by_nid(test_curves[j]);
if (ecdh_a[j]->group == NULL)
{
BIO_printf(bio_err,"ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
ecdh_b[j]->group = ecdh_a[j]->group;
/* generate two ECDH key pairs */
if (!EC_KEY_generate_key(ecdh_a[j]) ||
!EC_KEY_generate_key(ecdh_b[j]))
{
BIO_printf(bio_err,"ECDH key generation failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
secret_size_a = ECDH_compute_key(secret_a,
ecdh_b[j]->pub_key,
ecdh_a[j]);
secret_size_b = ECDH_compute_key(secret_b,
ecdh_a[j]->pub_key,
ecdh_b[j]);
if (secret_size_a != secret_size_b)
ecdh_checks = 0;
else
ecdh_checks = 1;
for (secret_idx = 0;
(secret_idx < secret_size_a)
&& (ecdh_checks == 1);
secret_idx++)
{
if (secret_a[secret_idx] != secret_b[secret_idx])
ecdh_checks = 0;
}
if (ecdh_checks == 0)
{
BIO_printf(bio_err,"ECDH computations don't match.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
pkey_print_message("","ecdh",
ecdh_c[j][0],
test_curves_bits[j],
ECDH_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdh_c[j][0]); count++)
{
ECDH_compute_key(secret_a,
ecdh_b[j]->pub_key,
ecdh_a[j]);
}
d=Time_F(STOP);
BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
count, test_curves_bits[j], d);
ecdh_results[j][0]=d/(double)count;
rsa_count=count;
}
}
}
if (rsa_count <= 1)
{
/* if longer than 10s, don't do any more */
for (j++; j<EC_NUM; j++)
ecdh_doit[j]=0;
}
}
if (rnd_fake) RAND_cleanup();
#endif
#ifdef HAVE_FORK
show_res:
#endif
@ -2233,57 +1713,7 @@ show_res:
1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDSA
j=1;
for (k=0; k<EC_NUM; k++)
{
if (!ecdsa_doit[k]) continue;
if (j && !mr)
{
printf("%30ssign verify sign/s verify/s\n"," ");
j=0;
}
if (mr)
fprintf(stdout,"+F4:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdsa_results[k][0],ecdsa_results[k][1]);
else
fprintf(stdout,
"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdsa_results[k][0],ecdsa_results[k][1],
1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDH
j=1;
for (k=0; k<EC_NUM; k++)
{
if (!ecdh_doit[k]) continue;
if (j && !mr)
{
printf("%30sop op/s\n"," ");
j=0;
}
if (mr)
fprintf(stdout,"+F5:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdh_results[k][0], 1.0/ecdh_results[k][0]);
else
fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdh_results[k][0], 1.0/ecdh_results[k][0]);
}
#endif
mret=0;
end:
ERR_print_errors(bio_err);
if (buf != NULL) OPENSSL_free(buf);
@ -2298,22 +1728,6 @@ end:
if (dsa_key[i] != NULL)
DSA_free(dsa_key[i]);
#endif
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++)
if (ecdsa[i] != NULL)
EC_KEY_free(ecdsa[i]);
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
{
if (ecdh_a[i] != NULL)
EC_KEY_free(ecdh_a[i]);
if (ecdh_b[i] != NULL)
EC_KEY_free(ecdh_b[i]);
}
#endif
apps_shutdown();
EXIT(mret);
}
@ -2515,49 +1929,6 @@ static int do_multi(int multi)
else
dsa_results[k][1]=d;
}
#ifndef OPENSSL_NO_ECDSA
else if(!strncmp(buf,"+F4:",4))
{
int k;
double d;
p=buf+4;
k=atoi(sstrsep(&p,sep));
sstrsep(&p,sep);
d=atof(sstrsep(&p,sep));
if(n)
ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
else
ecdsa_results[k][0]=d;
d=atof(sstrsep(&p,sep));
if(n)
ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
else
ecdsa_results[k][1]=d;
}
#endif
#ifndef OPENSSL_NO_ECDH
else if(!strncmp(buf,"+F5:",4))
{
int k;
double d;
p=buf+4;
k=atoi(sstrsep(&p,sep));
sstrsep(&p,sep);
d=atof(sstrsep(&p,sep));
if(n)
ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
else
ecdh_results[k][0]=d;
}
#endif
else if(!strncmp(buf,"+H:",3))
{
}

View File

@ -172,19 +172,7 @@ int MAIN(int argc, char **argv)
}
}
if (version)
{
if (SSLeay() == SSLEAY_VERSION_NUMBER)
{
printf("%s\n",SSLeay_version(SSLEAY_VERSION));
}
else
{
printf("%s (Library: %s)\n",
OPENSSL_VERSION_TEXT,
SSLeay_version(SSLEAY_VERSION));
}
}
if (version) printf("%s\n",SSLeay_version(SSLEAY_VERSION));
if (date) printf("%s\n",SSLeay_version(SSLEAY_BUILT_ON));
if (platform) printf("%s\n",SSLeay_version(SSLEAY_PLATFORM));
if (options)

View File

@ -870,10 +870,6 @@ bad:
if (Upkey->type == EVP_PKEY_DSA)
digest=EVP_dss1();
#endif
#ifndef OPENSSL_NO_ECDSA
if (Upkey->type == EVP_PKEY_EC)
digest=EVP_ecdsa();
#endif
assert(need_rand);
if (!sign(x,Upkey,days,clrext,digest,
@ -894,10 +890,6 @@ bad:
if (CApkey->type == EVP_PKEY_DSA)
digest=EVP_dss1();
#endif
#ifndef OPENSSL_NO_ECDSA
if (CApkey->type == EVP_PKEY_EC)
digest = EVP_ecdsa();
#endif
assert(need_rand);
if (!x509_certify(ctx,CAfile,digest,x,xca,
@ -929,10 +921,6 @@ bad:
if (pk->type == EVP_PKEY_DSA)
digest=EVP_dss1();
#endif
#ifndef OPENSSL_NO_ECDSA
if (pk->type == EVP_PKEY_EC)
digest=EVP_ecdsa();
#endif
rq=X509_to_X509_REQ(x,pk,digest);
EVP_PKEY_free(pk);

View File

@ -28,7 +28,7 @@ LIBS=
SDIRS= md2 md5 sha mdc2 hmac ripemd \
des rc2 rc4 rc5 idea bf cast \
bn ec rsa dsa ecdsa ecdh dh dso engine aes \
bn ec rsa dsa dh dso engine aes \
buffer bio stack lhash rand err objects \
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5

View File

@ -72,7 +72,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
if (AES_ENCRYPT == enc) {
while (len >= AES_BLOCK_SIZE) {
for(n=0; n < AES_BLOCK_SIZE; ++n)
for(n=0; n < sizeof tmp; ++n)
tmp[n] = in[n] ^ ivec[n];
AES_encrypt(tmp, out, key);
memcpy(ivec, out, AES_BLOCK_SIZE);
@ -87,11 +87,11 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
tmp[n] = ivec[n];
AES_encrypt(tmp, tmp, key);
memcpy(out, tmp, len);
memcpy(ivec, tmp, AES_BLOCK_SIZE);
memcpy(ivec, tmp, sizeof tmp);
}
} else {
while (len >= AES_BLOCK_SIZE) {
memcpy(tmp, in, AES_BLOCK_SIZE);
memcpy(tmp, in, sizeof tmp);
AES_decrypt(in, out, key);
for(n=0; n < AES_BLOCK_SIZE; ++n)
out[n] ^= ivec[n];
@ -101,11 +101,11 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
out += AES_BLOCK_SIZE;
}
if (len) {
memcpy(tmp, in, AES_BLOCK_SIZE);
memcpy(tmp, in, sizeof tmp);
AES_decrypt(tmp, tmp, key);
for(n=0; n < len; ++n)
out[n] ^= ivec[n];
memcpy(ivec, tmp, AES_BLOCK_SIZE);
memcpy(ivec, tmp, sizeof tmp);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -147,7 +147,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if(BN_get_sign(bn)) ret->type = V_ASN1_NEG_ENUMERATED;
if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
else ret->type=V_ASN1_ENUMERATED;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
@ -175,6 +175,6 @@ BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_sign(ret,1);
else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
return(ret);
}

View File

@ -393,8 +393,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
goto err;
}
if (BN_get_sign(bn))
ret->type = V_ASN1_NEG_INTEGER;
if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
else ret->type=V_ASN1_INTEGER;
j=BN_num_bits(bn);
len=((j == 0)?0:((j/8)+1));
@ -427,8 +426,7 @@ BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
else if(ai->type == V_ASN1_NEG_INTEGER)
BN_set_sign(ret, 1);
else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
return(ret);
}

View File

@ -191,11 +191,6 @@ typedef struct asn1_object_st
} ASN1_OBJECT;
#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
/* This indicates that the ASN1_STRING is not a real value but just a place
* holder for the location where indefinite length constructed data should
* be inserted in the memory buffer
*/
#define ASN1_STRING_FLAG_NDEF 0x010
/* This is the base type that holds just about everything :-) */
typedef struct asn1_string_st
{
@ -284,9 +279,6 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
int i2d_##name(const type *a, unsigned char **out); \
DECLARE_ASN1_ITEM(name)
#define DECLARE_ASN1_NDEF_FUNCTION(name) \
int i2d_##name##_NDEF(name *a, unsigned char **out);
#define DECLARE_ASN1_FUNCTIONS_const(name) \
name *name##_new(void); \
void name##_free(name *a);
@ -800,8 +792,6 @@ DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
int ASN1_TIME_check(ASN1_TIME *t);
ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
@ -858,7 +848,6 @@ int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
int ASN1_check_infinite_end(unsigned char **p,long len);
void ASN1_put_object(unsigned char **pp, int constructed, int length,
int tag, int xclass);
int ASN1_put_eoc(unsigned char **pp);
int ASN1_object_size(int constructed, int length, int tag);
/* Used to implement other functions */
@ -945,13 +934,9 @@ ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
void ASN1_add_oid_module(void);
ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
@ -965,8 +950,6 @@ void ERR_load_ASN1_strings(void);
#define ASN1_F_A2I_ASN1_ENUMERATED 101
#define ASN1_F_A2I_ASN1_INTEGER 102
#define ASN1_F_A2I_ASN1_STRING 103
#define ASN1_F_APPEND_TAG 177
#define ASN1_F_ASN1_CB 178
#define ASN1_F_ASN1_CHECK_TLEN 104
#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
#define ASN1_F_ASN1_COLLECT 106
@ -977,7 +960,6 @@ void ERR_load_ASN1_strings(void);
#define ASN1_F_ASN1_DUP 111
#define ASN1_F_ASN1_ENUMERATED_SET 112
#define ASN1_F_ASN1_ENUMERATED_TO_BN 113
#define ASN1_F_ASN1_GENERATE_V3 182
#define ASN1_F_ASN1_GET_OBJECT 114
#define ASN1_F_ASN1_HEADER_NEW 115
#define ASN1_F_ASN1_I2D_BIO 116
@ -993,7 +975,6 @@ void ERR_load_ASN1_strings(void);
#define ASN1_F_ASN1_SEQ_PACK 126
#define ASN1_F_ASN1_SEQ_UNPACK 127
#define ASN1_F_ASN1_SIGN 128
#define ASN1_F_ASN1_STR2TYPE 179
#define ASN1_F_ASN1_STRING_TABLE_ADD 129
#define ASN1_F_ASN1_STRING_TYPE_NEW 130
#define ASN1_F_ASN1_TEMPLATE_D2I 131
@ -1003,7 +984,6 @@ void ERR_load_ASN1_strings(void);
#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
#define ASN1_F_ASN1_UNPACK_STRING 136
#define ASN1_F_ASN1_VERIFY 137
#define ASN1_F_BITSTR_CB 180
#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
#define ASN1_F_BN_TO_ASN1_INTEGER 139
#define ASN1_F_COLLECT_DATA 140
@ -1028,15 +1008,12 @@ void ERR_load_ASN1_strings(void);
#define ASN1_F_D2I_X509_PKEY 159
#define ASN1_F_I2D_ASN1_TIME 160
#define ASN1_F_I2D_DSA_PUBKEY 161
#define ASN1_F_I2D_ECDSA_PUBKEY 174
#define ASN1_F_I2D_EC_PUBKEY 176
#define ASN1_F_I2D_NETSCAPE_RSA 162
#define ASN1_F_I2D_PRIVATEKEY 163
#define ASN1_F_I2D_PUBLICKEY 164
#define ASN1_F_I2D_RSA_PUBKEY 165
#define ASN1_F_LONG_C2I 166
#define ASN1_F_OID_MODULE_INIT 175
#define ASN1_F_PARSE_TAGGING 181
#define ASN1_F_OID_MODULE_INIT 174
#define ASN1_F_PKCS5_PBE2_SET 167
#define ASN1_F_X509_CINF_NEW 168
#define ASN1_F_X509_CRL_ADD0_REVOKED 169
@ -1059,7 +1036,6 @@ void ERR_load_ASN1_strings(void);
#define ASN1_R_DATA_IS_WRONG 109
#define ASN1_R_DECODE_ERROR 110
#define ASN1_R_DECODING_ERROR 111
#define ASN1_R_DEPTH_EXCEEDED 173
#define ASN1_R_ENCODE_ERROR 112
#define ASN1_R_ERROR_LOADING_SECTION 172
#define ASN1_R_ERROR_PARSING_SET_ELEMENT 113
@ -1073,57 +1049,38 @@ void ERR_load_ASN1_strings(void);
#define ASN1_R_FIELD_MISSING 121
#define ASN1_R_FIRST_NUM_TOO_LARGE 122
#define ASN1_R_HEADER_TOO_LONG 123
#define ASN1_R_ILLEGAL_BITSTRING_FORMAT 174
#define ASN1_R_ILLEGAL_BOOLEAN 175
#define ASN1_R_ILLEGAL_CHARACTERS 124
#define ASN1_R_ILLEGAL_FORMAT 176
#define ASN1_R_ILLEGAL_HEX 177
#define ASN1_R_ILLEGAL_IMPLICIT_TAG 178
#define ASN1_R_ILLEGAL_INTEGER 179
#define ASN1_R_ILLEGAL_NESTED_TAGGING 180
#define ASN1_R_ILLEGAL_NULL 125
#define ASN1_R_ILLEGAL_NULL_VALUE 181
#define ASN1_R_ILLEGAL_OBJECT 182
#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
#define ASN1_R_ILLEGAL_TAGGED_ANY 127
#define ASN1_R_ILLEGAL_TIME_VALUE 183
#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 184
#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
#define ASN1_R_INVALID_DIGIT 130
#define ASN1_R_INVALID_MODIFIER 185
#define ASN1_R_INVALID_NUMBER 186
#define ASN1_R_INVALID_SEPARATOR 131
#define ASN1_R_INVALID_TIME_FORMAT 132
#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
#define ASN1_R_INVALID_UTF8STRING 134
#define ASN1_R_IV_TOO_LARGE 135
#define ASN1_R_LENGTH_ERROR 136
#define ASN1_R_LIST_ERROR 187
#define ASN1_R_MISSING_EOC 137
#define ASN1_R_MISSING_SECOND_NUMBER 138
#define ASN1_R_MISSING_VALUE 188
#define ASN1_R_MSTRING_NOT_UNIVERSAL 139
#define ASN1_R_MSTRING_WRONG_TAG 140
#define ASN1_R_NON_HEX_CHARACTERS 141
#define ASN1_R_NOT_ASCII_FORMAT 189
#define ASN1_R_NOT_ENOUGH_DATA 142
#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
#define ASN1_R_NULL_IS_WRONG_LENGTH 144
#define ASN1_R_OBJECT_NOT_ASCII_FORMAT 190
#define ASN1_R_ODD_NUMBER_OF_CHARS 145
#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 195
#define ASN1_R_SHORT_LINE 150
#define ASN1_R_STRING_TOO_LONG 151
#define ASN1_R_STRING_TOO_SHORT 152
#define ASN1_R_TAG_VALUE_TOO_HIGH 153
#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
#define ASN1_R_TIME_NOT_ASCII_FORMAT 191
#define ASN1_R_TOO_LONG 155
#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
@ -1133,13 +1090,10 @@ void ERR_load_ASN1_strings(void);
#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
#define ASN1_R_UNKNOWN_OBJECT_TYPE 162
#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
#define ASN1_R_UNKNOWN_TAG 192
#define ASN1_R_UNKOWN_FORMAT 193
#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
#define ASN1_R_UNSUPPORTED_CIPHER 165
#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
#define ASN1_R_UNSUPPORTED_TYPE 194
#define ASN1_R_WRONG_TAG 168
#define ASN1_R_WRONG_TYPE 169

View File

@ -1,6 +1,6 @@
/* crypto/asn1/asn1_err.c */
/* ====================================================================
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
* 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
@ -70,8 +70,6 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
{ERR_PACK(0,ASN1_F_APPEND_TAG,0), "APPEND_TAG"},
{ERR_PACK(0,ASN1_F_ASN1_CB,0), "ASN1_CB"},
{ERR_PACK(0,ASN1_F_ASN1_CHECK_TLEN,0), "ASN1_CHECK_TLEN"},
{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
{ERR_PACK(0,ASN1_F_ASN1_COLLECT,0), "ASN1_COLLECT"},
@ -82,7 +80,6 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
{ERR_PACK(0,ASN1_F_ASN1_GENERATE_V3,0), "ASN1_generate_v3"},
{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
@ -98,7 +95,6 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
{ERR_PACK(0,ASN1_F_ASN1_STR2TYPE,0), "ASN1_STR2TYPE"},
{ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"},
{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
{ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"},
@ -108,7 +104,6 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
{ERR_PACK(0,ASN1_F_BITSTR_CB,0), "BITSTR_CB"},
{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
{ERR_PACK(0,ASN1_F_COLLECT_DATA,0), "COLLECT_DATA"},
@ -133,15 +128,12 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "I2D_ASN1_TIME"},
{ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"},
{ERR_PACK(0,ASN1_F_I2D_ECDSA_PUBKEY,0), "I2D_ECDSA_PUBKEY"},
{ERR_PACK(0,ASN1_F_I2D_EC_PUBKEY,0), "i2d_EC_PUBKEY"},
{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
{ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"},
{ERR_PACK(0,ASN1_F_LONG_C2I,0), "LONG_C2I"},
{ERR_PACK(0,ASN1_F_OID_MODULE_INIT,0), "OID_MODULE_INIT"},
{ERR_PACK(0,ASN1_F_PARSE_TAGGING,0), "PARSE_TAGGING"},
{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"},
{ERR_PACK(0,ASN1_F_X509_CRL_ADD0_REVOKED,0), "X509_CRL_add0_revoked"},
@ -167,7 +159,6 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
{ASN1_R_DECODE_ERROR ,"decode error"},
{ASN1_R_DECODING_ERROR ,"decoding error"},
{ASN1_R_DEPTH_EXCEEDED ,"depth exceeded"},
{ASN1_R_ENCODE_ERROR ,"encode error"},
{ASN1_R_ERROR_LOADING_SECTION ,"error loading section"},
{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
@ -181,57 +172,38 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
{ASN1_R_FIELD_MISSING ,"field missing"},
{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
{ASN1_R_HEADER_TOO_LONG ,"header too long"},
{ASN1_R_ILLEGAL_BITSTRING_FORMAT ,"illegal bitstring format"},
{ASN1_R_ILLEGAL_BOOLEAN ,"illegal boolean"},
{ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"},
{ASN1_R_ILLEGAL_FORMAT ,"illegal format"},
{ASN1_R_ILLEGAL_HEX ,"illegal hex"},
{ASN1_R_ILLEGAL_IMPLICIT_TAG ,"illegal implicit tag"},
{ASN1_R_ILLEGAL_INTEGER ,"illegal integer"},
{ASN1_R_ILLEGAL_NESTED_TAGGING ,"illegal nested tagging"},
{ASN1_R_ILLEGAL_NULL ,"illegal null"},
{ASN1_R_ILLEGAL_NULL_VALUE ,"illegal null value"},
{ASN1_R_ILLEGAL_OBJECT ,"illegal object"},
{ASN1_R_ILLEGAL_OPTIONAL_ANY ,"illegal optional any"},
{ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE ,"illegal options on item template"},
{ASN1_R_ILLEGAL_TAGGED_ANY ,"illegal tagged any"},
{ASN1_R_ILLEGAL_TIME_VALUE ,"illegal time value"},
{ASN1_R_INTEGER_NOT_ASCII_FORMAT ,"integer not ascii format"},
{ASN1_R_INTEGER_TOO_LARGE_FOR_LONG ,"integer too large for long"},
{ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"},
{ASN1_R_INVALID_DIGIT ,"invalid digit"},
{ASN1_R_INVALID_MODIFIER ,"invalid modifier"},
{ASN1_R_INVALID_NUMBER ,"invalid number"},
{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
{ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"},
{ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"},
{ASN1_R_IV_TOO_LARGE ,"iv too large"},
{ASN1_R_LENGTH_ERROR ,"length error"},
{ASN1_R_LIST_ERROR ,"list error"},
{ASN1_R_MISSING_EOC ,"missing eoc"},
{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
{ASN1_R_MISSING_VALUE ,"missing value"},
{ASN1_R_MSTRING_NOT_UNIVERSAL ,"mstring not universal"},
{ASN1_R_MSTRING_WRONG_TAG ,"mstring wrong tag"},
{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
{ASN1_R_NOT_ASCII_FORMAT ,"not ascii format"},
{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
{ASN1_R_NO_MATCHING_CHOICE_TYPE ,"no matching choice type"},
{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
{ASN1_R_OBJECT_NOT_ASCII_FORMAT ,"object not ascii format"},
{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},
{ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"},
{ASN1_R_SEQUENCE_LENGTH_MISMATCH ,"sequence length mismatch"},
{ASN1_R_SEQUENCE_NOT_CONSTRUCTED ,"sequence not constructed"},
{ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG ,"sequence or set needs config"},
{ASN1_R_SHORT_LINE ,"short line"},
{ASN1_R_STRING_TOO_LONG ,"string too long"},
{ASN1_R_STRING_TOO_SHORT ,"string too short"},
{ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"},
{ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
{ASN1_R_TIME_NOT_ASCII_FORMAT ,"time not ascii format"},
{ASN1_R_TOO_LONG ,"too long"},
{ASN1_R_TYPE_NOT_CONSTRUCTED ,"type not constructed"},
{ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"},
@ -241,13 +213,10 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
{ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"},
{ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"},
{ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"},
{ASN1_R_UNKNOWN_TAG ,"unknown tag"},
{ASN1_R_UNKOWN_FORMAT ,"unkown format"},
{ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE ,"unsupported any defined by type"},
{ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
{ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"},
{ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"},
{ASN1_R_UNSUPPORTED_TYPE ,"unsupported type"},
{ASN1_R_WRONG_TAG ,"wrong tag"},
{ASN1_R_WRONG_TYPE ,"wrong type"},
{0,NULL}

View File

@ -1,839 +0,0 @@
/* asn1_gen.c */
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
* project 2002.
*/
/* ====================================================================
* Copyright (c) 2002 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include "cryptlib.h"
#include <openssl/asn1.h>
#include <openssl/x509v3.h>
#define ASN1_GEN_FLAG 0x10000
#define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
#define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
#define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3)
#define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4)
#define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5)
#define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6)
#define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7)
#define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8)
#define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val}
#define ASN1_FLAG_EXP_MAX 20
/* Input formats */
/* ASCII: default */
#define ASN1_GEN_FORMAT_ASCII 1
/* UTF8 */
#define ASN1_GEN_FORMAT_UTF8 2
/* Hex */
#define ASN1_GEN_FORMAT_HEX 3
/* List of bits */
#define ASN1_GEN_FORMAT_BITLIST 4
struct tag_name_st
{
char *strnam;
int len;
int tag;
};
typedef struct
{
int exp_tag;
int exp_class;
int exp_constructed;
int exp_pad;
long exp_len;
} tag_exp_type;
typedef struct
{
int imp_tag;
int imp_class;
int utype;
int format;
const char *str;
tag_exp_type exp_list[ASN1_FLAG_EXP_MAX];
int exp_count;
} tag_exp_arg;
static int bitstr_cb(const char *elem, int len, void *bitstr);
static int asn1_cb(const char *elem, int len, void *bitstr);
static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok);
static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass);
static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf);
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
static int asn1_str2tag(const char *tagstr, int len);
ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
{
X509V3_CTX cnf;
if (!nconf)
return ASN1_generate_v3(str, NULL);
X509V3_set_nconf(&cnf, nconf);
return ASN1_generate_v3(str, &cnf);
}
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
{
ASN1_TYPE *ret;
tag_exp_arg asn1_tags;
tag_exp_type *etmp;
int i, len;
unsigned char *orig_der = NULL, *new_der = NULL;
unsigned char *cpy_start, *p;
int cpy_len;
long hdr_len;
int hdr_constructed = 0, hdr_tag, hdr_class;
int r;
asn1_tags.imp_tag = -1;
asn1_tags.imp_class = -1;
asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
asn1_tags.exp_count = 0;
if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
return NULL;
if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET))
{
if (!cnf)
{
ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
return NULL;
}
ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf);
}
else
ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);
if (!ret)
return NULL;
/* If no tagging return base type */
if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))
return ret;
/* Generate the encoding */
cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
ASN1_TYPE_free(ret);
ret = NULL;
/* Set point to start copying for modified encoding */
cpy_start = orig_der;
/* Do we need IMPLICIT tagging? */
if (asn1_tags.imp_tag != -1)
{
/* If IMPLICIT we will replace the underlying tag */
/* Skip existing tag+len */
r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
if (r & 0x80)
goto err;
/* Update copy length */
cpy_len -= cpy_start - orig_der;
/* For IMPLICIT tagging the length should match the
* original length and constructed flag should be
* consistent.
*/
if (r & 0x1)
{
/* Indefinite length constructed */
hdr_constructed = 2;
hdr_len = 0;
}
else
/* Just retain constructed flag */
hdr_constructed = r & V_ASN1_CONSTRUCTED;
/* Work out new length with IMPLICIT tag: ignore constructed
* because it will mess up if indefinite length
*/
len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);
}
else
len = cpy_len;
/* Work out length in any EXPLICIT, starting from end */
for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--)
{
/* Content length: number of content octets + any padding */
len += etmp->exp_pad;
etmp->exp_len = len;
/* Total object length: length including new header */
len = ASN1_object_size(0, len, etmp->exp_tag);
}
/* Allocate buffer for new encoding */
new_der = OPENSSL_malloc(len);
/* Generate tagged encoding */
p = new_der;
/* Output explicit tags first */
for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++)
{
ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
etmp->exp_tag, etmp->exp_class);
if (etmp->exp_pad)
*p++ = 0;
}
/* If IMPLICIT, output tag */
if (asn1_tags.imp_tag != -1)
ASN1_put_object(&p, hdr_constructed, hdr_len,
asn1_tags.imp_tag, asn1_tags.imp_class);
/* Copy across original encoding */
memcpy(p, cpy_start, cpy_len);
p = new_der;
/* Obtain new ASN1_TYPE structure */
ret = d2i_ASN1_TYPE(NULL, &p, len);
err:
if (orig_der)
OPENSSL_free(orig_der);
if (new_der)
OPENSSL_free(new_der);
return ret;
}
static int asn1_cb(const char *elem, int len, void *bitstr)
{
tag_exp_arg *arg = bitstr;
int i;
int utype;
int vlen = 0;
const char *p, *vstart = NULL;
int tmp_tag, tmp_class;
for(i = 0, p = elem; i < len; p++, i++)
{
/* Look for the ':' in name value pairs */
if (*p == ':')
{
vstart = p + 1;
vlen = len - (vstart - elem);
len = p - elem;
break;
}
}
utype = asn1_str2tag(elem, len);
if (utype == -1)
{
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
ERR_add_error_data(2, "tag=", elem);
return -1;
}
/* If this is not a modifier mark end of string and exit */
if (!(utype & ASN1_GEN_FLAG))
{
arg->utype = utype;
arg->str = vstart;
/* If no value and not end of string, error */
if (!vstart && elem[len])
{
ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
return -1;
}
return 0;
}
switch(utype)
{
case ASN1_GEN_FLAG_IMP:
/* Check for illegal multiple IMPLICIT tagging */
if (arg->imp_tag != -1)
{
ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
return -1;
}
if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class))
return -1;
break;
case ASN1_GEN_FLAG_EXP:
if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
return -1;
if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
return -1;
break;
case ASN1_GEN_FLAG_SEQWRAP:
if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
case ASN1_GEN_FLAG_SETWRAP:
if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
return -1;
break;
case ASN1_GEN_FLAG_BITWRAP:
if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
return -1;
break;
case ASN1_GEN_FLAG_OCTWRAP:
if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
return -1;
break;
case ASN1_GEN_FLAG_FORMAT:
if (!strncmp(vstart, "ASCII", 5))
arg->format = ASN1_GEN_FORMAT_ASCII;
else if (!strncmp(vstart, "UTF8", 4))
arg->format = ASN1_GEN_FORMAT_UTF8;
else if (!strncmp(vstart, "HEX", 3))
arg->format = ASN1_GEN_FORMAT_HEX;
else if (!strncmp(vstart, "BITLIST", 3))
arg->format = ASN1_GEN_FORMAT_BITLIST;
else
{
ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT);
return -1;
}
break;
}
return 1;
}
static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
{
char erch[2];
long tag_num;
char *eptr;
if (!vstart)
return 0;
tag_num = strtoul(vstart, &eptr, 10);
/* Check we haven't gone past max length: should be impossible */
if (eptr && *eptr && (eptr > vstart + vlen))
return 0;
if (tag_num < 0)
{
ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
return 0;
}
*ptag = tag_num;
/* If we have non numeric characters, parse them */
if (eptr)
vlen -= eptr - vstart;
else
vlen = 0;
if (vlen)
{
switch (*eptr)
{
case 'U':
*pclass = V_ASN1_UNIVERSAL;
break;
case 'A':
*pclass = V_ASN1_APPLICATION;
break;
case 'P':
*pclass = V_ASN1_PRIVATE;
break;
case 'C':
*pclass = V_ASN1_CONTEXT_SPECIFIC;
break;
default:
erch[0] = *eptr;
erch[1] = 0;
ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_MODIFIER);
ERR_add_error_data(2, "Char=", erch);
return 0;
break;
}
}
else
*pclass = V_ASN1_CONTEXT_SPECIFIC;
return 1;
}
/* Handle multiple types: SET and SEQUENCE */
static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
{
ASN1_TYPE *ret = NULL, *typ = NULL;
STACK_OF(ASN1_TYPE) *sk = NULL;
STACK_OF(CONF_VALUE) *sect = NULL;
unsigned char *der = NULL, *p;
int derlen;
int i, is_set;
sk = sk_ASN1_TYPE_new_null();
if (section)
{
if (!cnf)
goto bad;
sect = X509V3_get_section(cnf, (char *)section);
if (!sect)
goto bad;
for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
{
typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
if (!typ)
goto bad;
sk_ASN1_TYPE_push(sk, typ);
typ = NULL;
}
}
/* Now we has a STACK of the components, convert to the correct form */
if (utype == V_ASN1_SET)
is_set = 1;
else
is_set = 0;
derlen = i2d_ASN1_SET((STACK *)sk, NULL, i2d_ASN1_TYPE, utype, V_ASN1_UNIVERSAL, is_set);
der = OPENSSL_malloc(derlen);
p = der;
i2d_ASN1_SET((STACK *)sk, &p, i2d_ASN1_TYPE, utype, V_ASN1_UNIVERSAL, is_set);
if (!(ret = ASN1_TYPE_new()))
goto bad;
if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype)))
goto bad;
ret->type = utype;
ret->value.asn1_string->data = der;
ret->value.asn1_string->length = derlen;
der = NULL;
bad:
if (der)
OPENSSL_free(der);
if (sk)
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
if (typ)
ASN1_TYPE_free(typ);
if (sect)
X509V3_section_free(cnf, sect);
return ret;
}
static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok)
{
tag_exp_type *exp_tmp;
/* Can only have IMPLICIT if permitted */
if ((arg->imp_tag != -1) && !imp_ok)
{
ASN1err(ASN1_F_APPEND_TAG, ASN1_R_ILLEGAL_IMPLICIT_TAG);
return 0;
}
if (arg->exp_count == ASN1_FLAG_EXP_MAX)
{
ASN1err(ASN1_F_APPEND_TAG, ASN1_R_DEPTH_EXCEEDED);
return 0;
}
exp_tmp = &arg->exp_list[arg->exp_count++];
/* If IMPLICIT set tag to implicit value then
* reset implicit tag since it has been used.
*/
if (arg->imp_tag != -1)
{
exp_tmp->exp_tag = arg->imp_tag;
exp_tmp->exp_class = arg->imp_class;
arg->imp_tag = -1;
arg->imp_class = -1;
}
else
{
exp_tmp->exp_tag = exp_tag;
exp_tmp->exp_class = exp_class;
}
exp_tmp->exp_constructed = exp_constructed;
exp_tmp->exp_pad = exp_pad;
return 1;
}
static int asn1_str2tag(const char *tagstr, int len)
{
int i;
static struct tag_name_st *tntmp, tnst [] = {
ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
ASN1_GEN_STR("NULL", V_ASN1_NULL),
ASN1_GEN_STR("INT", V_ASN1_INTEGER),
ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER),
ASN1_GEN_STR("ENUM", V_ASN1_ENUMERATED),
ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED),
ASN1_GEN_STR("OID", V_ASN1_OBJECT),
ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT),
ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME),
ASN1_GEN_STR("UTC", V_ASN1_UTCTIME),
ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME),
ASN1_GEN_STR("GENTIME", V_ASN1_GENERALIZEDTIME),
ASN1_GEN_STR("OCT", V_ASN1_OCTET_STRING),
ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING),
ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING),
ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING),
ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING),
ASN1_GEN_STR("UNIV", V_ASN1_UNIVERSALSTRING),
ASN1_GEN_STR("IA5", V_ASN1_IA5STRING),
ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING),
ASN1_GEN_STR("UTF8", V_ASN1_UTF8STRING),
ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING),
ASN1_GEN_STR("BMP", V_ASN1_BMPSTRING),
ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING),
ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING),
ASN1_GEN_STR("VISIBLE", V_ASN1_VISIBLESTRING),
ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING),
ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING),
ASN1_GEN_STR("T61", V_ASN1_T61STRING),
ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING),
ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
/* Special cases */
ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
ASN1_GEN_STR("SEQ", V_ASN1_SEQUENCE),
ASN1_GEN_STR("SET", V_ASN1_SET),
/* type modifiers */
/* Explicit tag */
ASN1_GEN_STR("EXP", ASN1_GEN_FLAG_EXP),
ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP),
/* Implicit tag */
ASN1_GEN_STR("IMP", ASN1_GEN_FLAG_IMP),
ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP),
/* OCTET STRING wrapper */
ASN1_GEN_STR("OCTWRAP", ASN1_GEN_FLAG_OCTWRAP),
/* SEQUENCE wrapper */
ASN1_GEN_STR("SEQWRAP", ASN1_GEN_FLAG_SEQWRAP),
/* SET wrapper */
ASN1_GEN_STR("SETWRAP", ASN1_GEN_FLAG_SEQWRAP),
/* BIT STRING wrapper */
ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP),
ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT),
ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT),
};
if (len == -1)
len = strlen(tagstr);
tntmp = tnst;
for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++)
{
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
return tntmp->tag;
}
return -1;
}
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
{
ASN1_TYPE *atmp = NULL;
CONF_VALUE vtmp;
unsigned char *rdata;
long rdlen;
int no_unused = 1;
if (!(atmp = ASN1_TYPE_new()))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (!str)
str = "";
switch(utype)
{
case V_ASN1_NULL:
if (str && *str)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
goto bad_form;
}
break;
case V_ASN1_BOOLEAN:
if (format != ASN1_GEN_FORMAT_ASCII)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
goto bad_form;
}
vtmp.value = (char *)str;
if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
goto bad_str;
}
break;
case V_ASN1_INTEGER:
case V_ASN1_ENUMERATED:
if (format != ASN1_GEN_FORMAT_ASCII)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
goto bad_str;
}
break;
case V_ASN1_OBJECT:
if (format != ASN1_GEN_FORMAT_ASCII)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.object = OBJ_txt2obj(str, 0)))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
goto bad_str;
}
break;
case V_ASN1_UTCTIME:
case V_ASN1_GENERALIZEDTIME:
if (format != ASN1_GEN_FORMAT_ASCII)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
goto bad_form;
}
if (!(atmp->value.asn1_string = ASN1_STRING_new()))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
atmp->value.asn1_string->type = utype;
if (!ASN1_TIME_check(atmp->value.asn1_string))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
goto bad_str;
}
break;
case V_ASN1_BMPSTRING:
case V_ASN1_PRINTABLESTRING:
case V_ASN1_IA5STRING:
case V_ASN1_T61STRING:
case V_ASN1_UTF8STRING:
case V_ASN1_VISIBLESTRING:
case V_ASN1_UNIVERSALSTRING:
if (format == ASN1_GEN_FORMAT_ASCII)
format = MBSTRING_ASC;
else if (format == ASN1_GEN_FORMAT_UTF8)
format = MBSTRING_UTF8;
else
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
goto bad_form;
}
if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
-1, format, ASN1_tag2bit(utype)) <= 0)
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_str;
}
break;
case V_ASN1_BIT_STRING:
case V_ASN1_OCTET_STRING:
if (!(atmp->value.asn1_string = ASN1_STRING_new()))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
goto bad_form;
}
if (format == ASN1_GEN_FORMAT_HEX)
{
if (!(rdata = string_to_hex((char *)str, &rdlen)))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
goto bad_str;
}
atmp->value.asn1_string->data = rdata;
atmp->value.asn1_string->length = rdlen;
atmp->value.asn1_string->type = utype;
}
else if (format == ASN1_GEN_FORMAT_ASCII)
ASN1_STRING_set(atmp->value.asn1_string, str, -1);
else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING))
{
if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string))
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
goto bad_str;
}
no_unused = 0;
}
else
{
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
goto bad_form;
}
if ((utype == V_ASN1_BIT_STRING) && no_unused)
{
atmp->value.asn1_string->flags
&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
atmp->value.asn1_string->flags
|= ASN1_STRING_FLAG_BITS_LEFT;
}
break;
default:
ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
goto bad_str;
break;
}
atmp->type = utype;
return atmp;
bad_str:
ERR_add_error_data(2, "string=", str);
bad_form:
ASN1_TYPE_free(atmp);
return NULL;
}
static int bitstr_cb(const char *elem, int len, void *bitstr)
{
long bitnum;
char *eptr;
if (!elem)
return 0;
bitnum = strtoul(elem, &eptr, 10);
if (eptr && *eptr && (eptr != elem + len))
return 0;
if (bitnum < 0)
{
ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
return 0;
}
if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1))
{
ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
return 0;
}
return 1;
}

View File

@ -203,22 +203,13 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
}
p += ttag;
}
if (constructed == 2)
*(p++)=0x80;
if ((constructed == 2) && (length == 0))
*(p++)=0x80; /* der_put_length would output 0 instead */
else
asn1_put_length(&p,length);
*pp=p;
}
int ASN1_put_eoc(unsigned char **pp)
{
unsigned char *p = *pp;
*p++ = 0;
*p++ = 0;
*pp = p;
return 2;
}
static void asn1_put_length(unsigned char **pp, int length)
{
unsigned char *p= *pp;
@ -256,8 +247,8 @@ int ASN1_object_size(int constructed, int length, int tag)
ret++;
}
}
if (constructed == 2)
return ret + 3;
if ((length == 0) && (constructed == 2))
ret+=2;
ret++;
if (length > 127)
{

View File

@ -256,11 +256,9 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
opp=op;
os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
if (os != NULL && os->length > 0)
if (os != NULL)
{
opp = os->data;
/* testing whether the octet string is
* printable */
opp=os->data;
for (i=0; i<os->length; i++)
{
if (( (opp[i] < ' ') &&
@ -273,8 +271,7 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
break;
}
}
if (printable)
/* printable string */
if (printable && (os->length > 0))
{
if (BIO_write(bp,":",1) <= 0)
goto end;
@ -282,21 +279,8 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
os->length) <= 0)
goto end;
}
else if (!dump)
/* not printable => print octet string
* as hex dump */
{
if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
goto end;
for (i=0; i<os->length; i++)
{
if (BIO_printf(bp,"%02X"
, opp[i]) <= 0)
goto end;
}
}
else
/* print the normal dump */
if (!printable && (os->length > 0)
&& dump)
{
if (!nl)
{
@ -304,15 +288,11 @@ static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
goto end;
}
if (BIO_dump_indent(bp,(char *)opp,
((dump == -1 || dump >
os->length)?os->length:dump),
((dump == -1 || dump > os->length)?os->length:dump),
dump_indent) <= 0)
goto end;
nl=1;
}
}
if (os != NULL)
{
M_ASN1_OCTET_STRING_free(os);
os=NULL;
}

View File

@ -112,7 +112,7 @@ extern "C" {
/* Macros to aid ASN1 template writing */
#define ASN1_ITEM_TEMPLATE(tname) \
static const ASN1_TEMPLATE tname##_item_tt
const static ASN1_TEMPLATE tname##_item_tt
#define ASN1_ITEM_TEMPLATE_END(tname) \
;\
@ -150,7 +150,7 @@ extern "C" {
*/
#define ASN1_SEQUENCE(tname) \
static const ASN1_TEMPLATE tname##_seq_tt[]
const static ASN1_TEMPLATE tname##_seq_tt[]
#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
@ -166,37 +166,22 @@ extern "C" {
#stname \
ASN1_ITEM_end(tname)
#define ASN1_NDEF_SEQUENCE(tname) \
ASN1_SEQUENCE(tname)
#define ASN1_SEQUENCE_cb(tname, cb) \
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
ASN1_SEQUENCE(tname)
#define ASN1_BROKEN_SEQUENCE(tname) \
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
ASN1_SEQUENCE(tname)
#define ASN1_SEQUENCE_ref(tname, cb, lck) \
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
ASN1_SEQUENCE(tname)
#define ASN1_SEQUENCE_enc(tname, enc, cb) \
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
ASN1_SEQUENCE(tname)
#define ASN1_NDEF_SEQUENCE_END(tname) \
;\
ASN1_ITEM_start(tname) \
ASN1_ITYPE_NDEF_SEQUENCE,\
V_ASN1_SEQUENCE,\
tname##_seq_tt,\
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
NULL,\
sizeof(tname),\
#tname \
ASN1_ITEM_end(tname)
#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
@ -239,10 +224,10 @@ extern "C" {
*/
#define ASN1_CHOICE(tname) \
static const ASN1_TEMPLATE tname##_ch_tt[]
const static ASN1_TEMPLATE tname##_ch_tt[]
#define ASN1_CHOICE_cb(tname, cb) \
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
ASN1_CHOICE(tname)
#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
@ -368,20 +353,16 @@ extern "C" {
#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
/* EXPLICIT OPTIONAL using indefinite length constructed form */
#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
/* Macros for the ASN1_ADB structure */
#define ASN1_ADB(name) \
static const ASN1_ADB_TABLE name##_adbtbl[]
const static ASN1_ADB_TABLE name##_adbtbl[]
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
;\
static const ASN1_ADB name##_adb = {\
const static ASN1_ADB name##_adb = {\
flags,\
offsetof(name, field),\
app_table,\
@ -395,9 +376,9 @@ extern "C" {
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
;\
static const ASN1_ITEM *name##_adb(void) \
const static ASN1_ITEM *name##_adb(void) \
{ \
static const ASN1_ADB internal_adb = \
const static ASN1_ADB internal_adb = \
{\
flags,\
offsetof(name, field),\
@ -416,7 +397,7 @@ extern "C" {
#define ADB_ENTRY(val, template) {val, template}
#define ASN1_ADB_TEMPLATE(name) \
static const ASN1_TEMPLATE name##_tt
const static ASN1_TEMPLATE name##_tt
/* This is the ASN1 template structure that defines
* a wrapper round the actual type. It determines the
@ -537,13 +518,6 @@ struct ASN1_ADB_TABLE_st {
#define ASN1_TFLG_COMBINE (0x1<<10)
/* This flag when present in a SEQUENCE OF, SET OF
* or EXPLICIT causes indefinite length constructed
* encoding to be used if required.
*/
#define ASN1_TFLG_NDEF (0x1<<11)
/* This is the actual ASN1 item itself */
struct ASN1_ITEM_st {
@ -596,25 +570,19 @@ const char *sname; /* Structure name */
* has a special meaning, it is used as a mask
* of acceptable types using the B_ASN1 constants.
*
* NDEF_SEQUENCE is the same as SEQUENCE except
* that it will use indefinite length constructed
* encoding if requested.
*
*/
#define ASN1_ITYPE_PRIMITIVE 0x0
#define ASN1_ITYPE_PRIMITIVE 0x0
#define ASN1_ITYPE_SEQUENCE 0x1
#define ASN1_ITYPE_SEQUENCE 0x1
#define ASN1_ITYPE_CHOICE 0x2
#define ASN1_ITYPE_CHOICE 0x2
#define ASN1_ITYPE_COMPAT 0x3
#define ASN1_ITYPE_COMPAT 0x3
#define ASN1_ITYPE_EXTERN 0x4
#define ASN1_ITYPE_EXTERN 0x4
#define ASN1_ITYPE_MSTRING 0x5
#define ASN1_ITYPE_NDEF_SEQUENCE 0x6
#define ASN1_ITYPE_MSTRING 0x5
/* Cache for ASN1 tag and length, so we
* don't keep re-reading it for things
@ -799,12 +767,6 @@ typedef struct ASN1_AUX_st {
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
}
#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
{ \
return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
}
/* This includes evil casts to remove const: they will go away when full
* ASN1 constification is done.
*/

View File

@ -68,9 +68,6 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
long length)
@ -110,16 +107,6 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
goto err;
}
break;
#endif
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
if ((ret->pkey.eckey = d2i_ECPrivateKey(NULL,
(const unsigned char **)pp, length)) == NULL)
{
ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB);
goto err;
}
break;
#endif
default:
ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
@ -151,10 +138,7 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
/* Since we only need to discern "traditional format" RSA and DSA
* keys we can just count the elements.
*/
if(sk_ASN1_TYPE_num(inkey) == 6)
keytype = EVP_PKEY_DSA;
else if (sk_ASN1_TYPE_num(inkey) == 4)
keytype = EVP_PKEY_EC;
if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
else keytype = EVP_PKEY_RSA;
sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
return d2i_PrivateKey(keytype, a, pp, length);

View File

@ -68,9 +68,6 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
long length)
@ -103,24 +100,13 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
#endif
#ifndef OPENSSL_NO_DSA
case EVP_PKEY_DSA:
if ((ret->pkey.dsa=d2i_DSAPublicKey(&(ret->pkey.dsa),
if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,
(const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
{
ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
goto err;
}
break;
#endif
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
if ((ret->pkey.eckey = ECPublicKey_set_octet_string(
&(ret->pkey.eckey), (const unsigned char **)pp,
length)) == NULL)
{
ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
goto err;
}
break;
#endif
default:
ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);

View File

@ -67,9 +67,6 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
{
@ -86,12 +83,6 @@ int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
}
#endif
#ifndef OPENSSL_NO_EC
if (a->type == EVP_PKEY_EC)
{
return(i2d_ECPrivateKey(a->pkey.eckey, pp));
}
#endif
ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return(-1);

View File

@ -67,9 +67,6 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
{
@ -82,10 +79,6 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
#ifndef OPENSSL_NO_DSA
case EVP_PKEY_DSA:
return(i2d_DSAPublicKey(a->pkey.dsa,pp));
#endif
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
return(ECPublicKey_get_octet_string(a->pkey.eckey, pp));
#endif
default:
ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);

View File

@ -55,15 +55,9 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Binary polynomial ECC support in OpenSSL originally developed by
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/objects.h>
#include <openssl/buffer.h>
#include <openssl/bn.h>
#ifndef OPENSSL_NO_RSA
@ -75,31 +69,26 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
static int print(BIO *fp,const char *str,BIGNUM *num,
unsigned char *buf,int off);
static int print_bin(BIO *fp, const char *str, const unsigned char *num,
size_t len, int off);
#ifndef OPENSSL_NO_RSA
#ifndef OPENSSL_NO_FP_API
int RSA_print_fp(FILE *fp, const RSA *x, int off)
{
BIO *b;
int ret;
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
if ((b=BIO_new(BIO_s_file())) == NULL)
{
RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
return(0);
return(0);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=RSA_print(b,x,off);
BIO_free(b);
return(ret);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=RSA_print(b,x,off);
BIO_free(b);
return(ret);
}
#endif
int RSA_print(BIO *bp, const RSA *x, int off)
@ -238,307 +227,6 @@ err:
}
#endif /* !OPENSSL_NO_DSA */
#ifndef OPENSSL_NO_EC
#ifndef OPENSSL_NO_FP_API
int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off)
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
{
ECerr(EC_F_ECPKPARAMETERS_PRINT_FP,ERR_R_BUF_LIB);
return(0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = ECPKParameters_print(b, x, off);
BIO_free(b);
return(ret);
}
int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off)
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
{
ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB);
return(0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = EC_KEY_print(b, x, off);
BIO_free(b);
return(ret);
}
#endif
int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
{
unsigned char *buffer=NULL;
size_t buf_len=0, i;
int ret=0, reason=ERR_R_BIO_LIB;
BN_CTX *ctx=NULL;
EC_POINT *point=NULL;
BIGNUM *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
*order=NULL, *cofactor=NULL;
const unsigned char *seed;
size_t seed_len=0;
static const char *gen_compressed = "Generator (compressed):";
static const char *gen_uncompressed = "Generator (uncompressed):";
static const char *gen_hybrid = "Generator (hybrid):";
if (!x)
{
reason = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
if (EC_GROUP_get_asn1_flag(x))
{
/* the curve parameter are given by an asn1 OID */
int nid;
if (!BIO_indent(bp, off, 128))
goto err;
nid = EC_GROUP_get_nid(x);
if (nid == 0)
goto err;
if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0)
goto err;
if (BIO_printf(bp, "\n") <= 0)
goto err;
}
else
{
/* explicit parameters */
int is_char_two = 0;
point_conversion_form_t form;
int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x));
if (tmp_nid == NID_X9_62_characteristic_two_field)
is_char_two = 1;
if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
(b = BN_new()) == NULL || (order = BN_new()) == NULL ||
(cofactor = BN_new()) == NULL)
{
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
if (is_char_two)
{
if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
{
reason = ERR_R_EC_LIB;
goto err;
}
}
else /* prime field */
{
if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
{
reason = ERR_R_EC_LIB;
goto err;
}
}
if ((point = EC_GROUP_get0_generator(x)) == NULL)
{
reason = ERR_R_EC_LIB;
goto err;
}
if (!EC_GROUP_get_order(x, order, NULL) ||
!EC_GROUP_get_cofactor(x, cofactor, NULL))
{
reason = ERR_R_EC_LIB;
goto err;
}
form = EC_GROUP_get_point_conversion_form(x);
if ((gen = EC_POINT_point2bn(x, point,
form, NULL, ctx)) == NULL)
{
reason = ERR_R_EC_LIB;
goto err;
}
buf_len = (size_t)BN_num_bytes(p);
if (buf_len < (i = (size_t)BN_num_bytes(a)))
buf_len = i;
if (buf_len < (i = (size_t)BN_num_bytes(b)))
buf_len = i;
if (buf_len < (i = (size_t)BN_num_bytes(gen)))
buf_len = i;
if (buf_len < (i = (size_t)BN_num_bytes(order)))
buf_len = i;
if (buf_len < (i = (size_t)BN_num_bytes(cofactor)))
buf_len = i;
if ((seed = EC_GROUP_get0_seed(x)) != NULL)
seed_len = EC_GROUP_get_seed_len(x);
buf_len += 10;
if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
{
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
if (!BIO_indent(bp, off, 128))
goto err;
/* print the 'short name' of the field type */
if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
<= 0)
goto err;
if (is_char_two)
{
/* print the 'short name' of the base type OID */
int basis_type = EC_GROUP_get_basis_type(x);
if (basis_type == 0)
goto err;
if (!BIO_indent(bp, off, 128))
goto err;
if (BIO_printf(bp, "Basis Type: %s\n",
OBJ_nid2sn(basis_type)) <= 0)
goto err;
/* print the polynomial */
if ((p != NULL) && !print(bp, "Polynomial:", p, buffer,
off))
goto err;
}
else
{
if ((p != NULL) && !print(bp, "Prime:", p, buffer,off))
goto err;
}
if ((a != NULL) && !print(bp, "A: ", a, buffer, off))
goto err;
if ((b != NULL) && !print(bp, "B: ", b, buffer, off))
goto err;
if (form == POINT_CONVERSION_COMPRESSED)
{
if ((gen != NULL) && !print(bp, gen_compressed, gen,
buffer, off))
goto err;
}
else if (form == POINT_CONVERSION_UNCOMPRESSED)
{
if ((gen != NULL) && !print(bp, gen_uncompressed, gen,
buffer, off))
goto err;
}
else /* form == POINT_CONVERSION_HYBRID */
{
if ((gen != NULL) && !print(bp, gen_hybrid, gen,
buffer, off))
goto err;
}
if ((order != NULL) && !print(bp, "Order: ", order,
buffer, off)) goto err;
if ((cofactor != NULL) && !print(bp, "Cofactor: ", cofactor,
buffer, off)) goto err;
if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
goto err;
}
ret=1;
err:
if (!ret)
ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
if (p)
BN_free(p);
if (a)
BN_free(a);
if (b)
BN_free(b);
if (gen)
BN_free(gen);
if (order)
BN_free(order);
if (cofactor)
BN_free(cofactor);
if (ctx)
BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return(ret);
}
int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
{
unsigned char *buffer=NULL;
size_t buf_len=0, i;
int ret=0, reason=ERR_R_BIO_LIB;
BIGNUM *pub_key=NULL;
BN_CTX *ctx=NULL;
if (!x || !x->group)
{
reason = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
if ((pub_key = EC_POINT_point2bn(x->group, x->pub_key,
x->conv_form, NULL, ctx)) == NULL)
{
reason = ERR_R_EC_LIB;
goto err;
}
buf_len = (size_t)BN_num_bytes(pub_key);
if (x->priv_key)
{
if ((i = (size_t)BN_num_bytes(x->priv_key)) > buf_len)
buf_len = i;
}
buf_len += 10;
if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
{
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
if (x->priv_key != NULL)
{
if (!BIO_indent(bp, off, 128))
goto err;
if (BIO_printf(bp, "Private-Key: (%d bit)\n",
BN_num_bits(x->priv_key)) <= 0) goto err;
}
if ((x->priv_key != NULL) && !print(bp, "priv:", x->priv_key,
buffer, off))
goto err;
if ((pub_key != NULL) && !print(bp, "pub: ", pub_key,
buffer, off))
goto err;
if (!ECPKParameters_print(bp, x->group, off))
goto err;
ret=1;
err:
if (!ret)
ECerr(EC_F_EC_KEY_PRINT, reason);
if (pub_key)
BN_free(pub_key);
if (ctx)
BN_CTX_free(ctx);
if (buffer != NULL)
OPENSSL_free(buffer);
return(ret);
}
#endif /* OPENSSL_NO_EC */
static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
int off)
{
@ -546,15 +234,9 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
const char *neg;
if (num == NULL) return(1);
neg = (BN_get_sign(num))?"-":"";
neg=(num->neg)?"-":"";
if(!BIO_indent(bp,off,128))
return 0;
if (BN_is_zero(num))
{
if (BIO_printf(bp, "%s 0\n", number) <= 0)
return 0;
return 1;
}
if (BN_num_bytes(num) <= BN_BYTES)
{
@ -590,61 +272,23 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
return(1);
}
static int print_bin(BIO *fp, const char *name, const unsigned char *buf,
size_t len, int off)
{
size_t i;
char str[128];
if (buf == NULL)
return 1;
if (off)
{
if (off > 128)
off=128;
memset(str,' ',off);
if (BIO_write(fp, str, off) <= 0)
return 0;
}
if (BIO_printf(fp,"%s", name) <= 0)
return 0;
for (i=0; i<len; i++)
{
if ((i%15) == 0)
{
str[0]='\n';
memset(&(str[1]),' ',off+4);
if (BIO_write(fp, str, off+1+4) <= 0)
return 0;
}
if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0)
return 0;
}
if (BIO_write(fp,"\n",1) <= 0)
return 0;
return 1;
}
#ifndef OPENSSL_NO_DH
#ifndef OPENSSL_NO_FP_API
int DHparams_print_fp(FILE *fp, const DH *x)
{
BIO *b;
int ret;
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
if ((b=BIO_new(BIO_s_file())) == NULL)
{
DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
return(0);
return(0);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=DHparams_print(b, x);
BIO_free(b);
return(ret);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=DHparams_print(b, x);
BIO_free(b);
return(ret);
}
#endif
int DHparams_print(BIO *bp, const DH *x)
@ -689,20 +333,20 @@ err:
#ifndef OPENSSL_NO_DSA
#ifndef OPENSSL_NO_FP_API
int DSAparams_print_fp(FILE *fp, const DSA *x)
{
BIO *b;
int ret;
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
if ((b=BIO_new(BIO_s_file())) == NULL)
{
DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
return(0);
return(0);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=DSAparams_print(b, x);
BIO_free(b);
return(ret);
}
BIO_set_fp(b,fp,BIO_NOCLOSE);
ret=DSAparams_print(b, x);
BIO_free(b);
return(ret);
}
#endif
int DSAparams_print(BIO *bp, const DSA *x)
@ -741,59 +385,3 @@ err:
#endif /* !OPENSSL_NO_DSA */
#ifndef OPENSSL_NO_EC
#ifndef OPENSSL_NO_FP_API
int ECParameters_print_fp(FILE *fp, const EC_KEY *x)
{
BIO *b;
int ret;
if ((b=BIO_new(BIO_s_file())) == NULL)
{
ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB);
return(0);
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = ECParameters_print(b, x);
BIO_free(b);
return(ret);
}
#endif
int ECParameters_print(BIO *bp, const EC_KEY *x)
{
int reason=ERR_R_EC_LIB, ret=0;
BIGNUM *order=NULL;
if (!x || !x->group)
{
reason = ERR_R_PASSED_NULL_PARAMETER;;
goto err;
}
if ((order = BN_new()) == NULL)
{
reason = ERR_R_MALLOC_FAILURE;
goto err;
}
if (!EC_GROUP_get_order(x->group, order, NULL))
{
reason = ERR_R_EC_LIB;
goto err;
}
if (BIO_printf(bp, "ECDSA-Parameters: (%d bit)\n",
BN_num_bits(order)) <= 0)
goto err;
if (!ECPKParameters_print(bp, x->group, 4))
goto err;
ret=1;
err:
if (order)
BN_free(order);
ECerr(EC_F_ECPARAMETERS_PRINT, reason);
return(ret);
}
#endif

View File

@ -159,14 +159,6 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long
DSA_print(bp,pkey->pkey.dsa,16);
}
else
#endif
#ifndef OPENSSL_NO_EC
if (pkey->type == EVP_PKEY_EC)
{
BIO_printf(bp, "%12sEC Public Key: \n","");
EC_KEY_print(bp, pkey->pkey.eckey, 16);
}
else
#endif
BIO_printf(bp,"%12sUnknown Public Key:\n","");

View File

@ -93,15 +93,6 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
}
else
#endif
#ifndef OPENSSL_NO_EC
if (pkey->type == EVP_PKEY_EC)
{
BIO_printf(out, " EC Public Key:\n");
EC_KEY_print(out, pkey->pkey.eckey,2);
}
else
#endif
BIO_printf(out," Unknown Public Key:\n");
EVP_PKEY_free(pkey);
}

View File

@ -66,9 +66,6 @@
#ifndef OPENSSL_NO_DSA
#include <openssl/dsa.h>
#endif
#ifndef OPENSSL_NO_EC
#include <openssl/ec.h>
#endif
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
@ -231,14 +228,6 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
DSA_print(bp,pkey->pkey.dsa,16);
}
else
#endif
#ifndef OPENSSL_NO_EC
if (pkey->type == EVP_PKEY_EC)
{
BIO_printf(bp, "%12sEC Public Key:\n","");
EC_KEY_print(bp, pkey->pkey.eckey, 16);
}
else
#endif
BIO_printf(bp,"%12sUnknown Public Key:\n","");

View File

@ -289,7 +289,6 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1
goto auxerr;
return 1;
case ASN1_ITYPE_NDEF_SEQUENCE:
case ASN1_ITYPE_SEQUENCE:
p = *in;
tmplen = len;

View File

@ -3,7 +3,7 @@
* project 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -63,57 +63,38 @@
#include <openssl/asn1t.h>
#include <openssl/objects.h>
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it,
int tag, int aclass);
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
int skcontlen, const ASN1_ITEM *item,
int do_sort, int iclass);
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *tt,
int tag, int aclass);
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
const ASN1_ITEM *it, int flags);
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
/* Top level i2d equivalents: the 'ndef' variant instructs the encoder
* to use indefinite length constructed encoding, where appropriate
*/
int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
{
return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
}
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
{
return asn1_item_flags_i2d(val, out, it, 0);
}
/* Encode an ASN1 item, this is use by the
/* Encode an ASN1 item, this is compatible with the
* standard 'i2d' function. 'out' points to
* a buffer to output the data to.
* a buffer to output the data to, in future we will
* have more advanced versions that can output data
* a piece at a time and this will simply be a special
* case.
*
* The new i2d has one additional feature. If the output
* buffer is NULL (i.e. *out == NULL) then a buffer is
* allocated and populated with the encoding.
*/
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it, int flags)
int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
{
if(out && !*out) {
unsigned char *p, *buf;
int len;
len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
if(len <= 0) return len;
buf = OPENSSL_malloc(len);
if(!buf) return -1;
p = buf;
ASN1_item_ex_i2d(&val, &p, it, -1, flags);
ASN1_item_ex_i2d(&val, &p, it, -1, 0);
*out = buf;
return len;
}
return ASN1_item_ex_i2d(&val, out, it, -1, flags);
return ASN1_item_ex_i2d(&val, out, it, -1, 0);
}
/* Encode an item, taking care of IMPLICIT tagging (if any).
@ -121,34 +102,31 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_
* used in external types.
*/
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass)
int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
{
const ASN1_TEMPLATE *tt = NULL;
unsigned char *p = NULL;
int i, seqcontlen, seqlen, ndef = 1;
int i, seqcontlen, seqlen;
ASN1_STRING *strtmp;
const ASN1_COMPAT_FUNCS *cf;
const ASN1_EXTERN_FUNCS *ef;
const ASN1_AUX *aux = it->funcs;
ASN1_aux_cb *asn1_cb = 0;
if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
return 0;
if(aux && aux->asn1_cb)
asn1_cb = aux->asn1_cb;
ASN1_aux_cb *asn1_cb;
if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
else asn1_cb = 0;
switch(it->itype) {
case ASN1_ITYPE_PRIMITIVE:
if(it->templates)
return asn1_template_ex_i2d(pval, out, it->templates,
tag, aclass);
return ASN1_template_i2d(pval, out, it->templates);
return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
break;
case ASN1_ITYPE_MSTRING:
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
strtmp = (ASN1_STRING *)*pval;
return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
case ASN1_ITYPE_CHOICE:
if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
@ -159,8 +137,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
const ASN1_TEMPLATE *chtt;
chtt = it->templates + i;
pchval = asn1_get_field_ptr(pval, chtt);
return asn1_template_ex_i2d(pchval, out, chtt,
-1, aclass);
return ASN1_template_i2d(pchval, out, chtt);
}
/* Fixme: error condition if selector out of range */
if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
@ -184,11 +161,6 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
*p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
return i;
case ASN1_ITYPE_NDEF_SEQUENCE:
/* Use indefinite length constructed if requested */
if (aclass & ASN1_TFLG_NDEF) ndef = 2;
/* fall through */
case ASN1_ITYPE_SEQUENCE:
i = asn1_enc_restore(&seqcontlen, out, pval, it);
/* An error occurred */
@ -200,9 +172,7 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
/* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
if(tag == -1) {
tag = V_ASN1_SEQUENCE;
/* Retain any other flags in aclass */
aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
| V_ASN1_UNIVERSAL;
aclass = V_ASN1_UNIVERSAL;
}
if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
return 0;
@ -214,13 +184,13 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
if(!seqtt) return 0;
pseqval = asn1_get_field_ptr(pval, seqtt);
/* FIXME: check for errors in enhanced version */
seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
-1, aclass);
/* FIXME: special handling of indefinite length encoding */
seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
}
seqlen = ASN1_object_size(ndef, seqcontlen, tag);
seqlen = ASN1_object_size(1, seqcontlen, tag);
if(!out) return seqlen;
/* Output SEQUENCE header */
ASN1_put_object(out, ndef, seqcontlen, tag, aclass);
ASN1_put_object(out, 1, seqcontlen, tag, aclass);
for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
@ -228,9 +198,8 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
if(!seqtt) return 0;
pseqval = asn1_get_field_ptr(pval, seqtt);
/* FIXME: check for errors in enhanced version */
asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);
ASN1_template_i2d(pseqval, out, seqtt);
}
if (ndef == 2) ASN1_put_eoc(out);
if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
return 0;
return seqlen;
@ -242,95 +211,41 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
}
int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
{
return asn1_template_ex_i2d(pval, out, tt, -1, 0);
}
static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt, int tag, int iclass)
{
int i, ret, flags, ttag, tclass, ndef;
int i, ret, flags, aclass;
flags = tt->flags;
/* Work out tag and class to use: tagging may come
* either from the template or the arguments, not both
* because this would create ambiguity. Additionally
* the iclass argument may contain some additional flags
* which should be noted and passed down to other levels.
*/
if (flags & ASN1_TFLG_TAG_MASK)
{
/* Error if argument and template tagging */
if (tag != -1)
/* FIXME: error code here */
return -1;
/* Get tagging from template */
ttag = tt->tag;
tclass = flags & ASN1_TFLG_TAG_CLASS;
}
else if (tag != -1)
{
/* No template tagging, get from arguments */
ttag = tag;
tclass = iclass & ASN1_TFLG_TAG_CLASS;
}
else
{
ttag = -1;
tclass = 0;
}
/*
* Remove any class mask from iflag.
*/
iclass &= ~ASN1_TFLG_TAG_CLASS;
/* At this point 'ttag' contains the outer tag to use,
* 'tclass' is the class and iclass is any flags passed
* to this function.
*/
/* if template and arguments require ndef, use it */
if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
ndef = 2;
else ndef = 1;
aclass = flags & ASN1_TFLG_TAG_CLASS;
if(flags & ASN1_TFLG_SK_MASK) {
/* SET OF, SEQUENCE OF */
STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
int isset, sktag, skaclass;
int skcontlen, sklen;
ASN1_VALUE *skitem;
if(!*pval) return 0;
if(flags & ASN1_TFLG_SET_OF) {
isset = 1;
/* 2 means we reorder */
if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
} else isset = 0;
/* Work out inner tag value: if EXPLICIT
* or no tagging use underlying type.
*/
if((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG)) {
sktag = ttag;
skaclass = tclass;
/* First work out inner tag value */
if(flags & ASN1_TFLG_IMPTAG) {
sktag = tt->tag;
skaclass = aclass;
} else {
skaclass = V_ASN1_UNIVERSAL;
if(isset) sktag = V_ASN1_SET;
else sktag = V_ASN1_SEQUENCE;
}
/* Determine total length of items */
/* Now work out length of items */
skcontlen = 0;
for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
skcontlen += ASN1_item_ex_i2d(&skitem, NULL,
ASN1_ITEM_ptr(tt->item),
-1, iclass);
skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
}
sklen = ASN1_object_size(ndef, skcontlen, sktag);
sklen = ASN1_object_size(1, skcontlen, sktag);
/* If EXPLICIT need length of surrounding tag */
if(flags & ASN1_TFLG_EXPTAG)
ret = ASN1_object_size(ndef, sklen, ttag);
ret = ASN1_object_size(1, sklen, tt->tag);
else ret = sklen;
if(!out) return ret;
@ -338,43 +253,35 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const AS
/* Now encode this lot... */
/* EXPLICIT tag */
if(flags & ASN1_TFLG_EXPTAG)
ASN1_put_object(out, ndef, sklen, ttag, tclass);
ASN1_put_object(out, 1, sklen, tt->tag, aclass);
/* SET or SEQUENCE and IMPLICIT tag */
ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);
/* And the stuff itself */
asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),
isset, iclass);
if (ndef == 2) {
ASN1_put_eoc(out);
if(flags & ASN1_TFLG_EXPTAG)
ASN1_put_eoc(out);
}
ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
/* And finally the stuff itself */
asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
return ret;
}
if(flags & ASN1_TFLG_EXPTAG) {
/* EXPLICIT tagging */
/* Find length of tagged item */
i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),
-1, iclass);
i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
if(!i) return 0;
/* Find length of EXPLICIT tag */
ret = ASN1_object_size(ndef, i, ttag);
ret = ASN1_object_size(1, i, tt->tag);
if(out) {
/* Output tag and item */
ASN1_put_object(out, ndef, i, ttag, tclass);
ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
-1, iclass);
if (ndef == 2) ASN1_put_eoc(out);
ASN1_put_object(out, 1, i, tt->tag, aclass);
ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
}
return ret;
}
/* Either normal or IMPLICIT tagging: combine class and flags */
return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
ttag, tclass | iclass);
if(flags & ASN1_TFLG_IMPTAG) {
/* IMPLICIT tagging */
return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
}
/* Nothing special: treat as normal */
return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
}
/* Temporary structure used to hold DER encoding of items for SET OF */
@ -397,9 +304,7 @@ static int der_cmp(const void *a, const void *b)
/* Output the content octets of SET OF or SEQUENCE OF */
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
int skcontlen, const ASN1_ITEM *item,
int do_sort, int iclass)
static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
{
int i;
ASN1_VALUE *skitem;
@ -418,7 +323,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
if(!do_sort) {
for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
skitem = sk_ASN1_VALUE_value(sk, i);
ASN1_item_ex_i2d(&skitem, out, item, -1, iclass);
ASN1_item_i2d(skitem, out, item);
}
return 1;
}
@ -427,7 +332,7 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
skitem = sk_ASN1_VALUE_value(sk, i);
tder->data = p;
tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass);
tder->length = ASN1_item_i2d(skitem, &p, item);
tder->field = skitem;
}
/* Now sort them */
@ -454,7 +359,6 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const A
int len;
int utype;
int usetag;
int ndef = 0;
utype = it->utype;
@ -477,27 +381,19 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const A
/* -1 means omit type */
if(len == -1)
return 0;
/* -2 return is special meaning use ndef */
if (len == -2)
{
ndef = 2;
len = 0;
}
if(len == -1) return 0;
/* If not implicitly tagged get tag from underlying type */
if(tag == -1) tag = utype;
/* Output tag+length followed by content octets */
if(out) {
if(usetag) ASN1_put_object(out, ndef, len, tag, aclass);
if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
asn1_ex_i2c(pval, *out, &utype, it);
*out += len;
}
if(usetag) return ASN1_object_size(ndef, len, tag);
if(usetag) return ASN1_object_size(0, len, tag);
return len;
}
@ -590,19 +486,6 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_
default:
/* All based on ASN1_STRING and handled the same */
strtmp = (ASN1_STRING *)*pval;
/* Special handling for NDEF */
if ((it->size == ASN1_TFLG_NDEF)
&& (strtmp->flags & ASN1_STRING_FLAG_NDEF))
{
if (cout)
{
strtmp->data = cout;
strtmp->length = 0;
ASN1_put_eoc(&cout);
}
/* Special return code */
return -2;
}
cont = strtmp->data;
len = strtmp->length;

View File

@ -130,7 +130,6 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
break;
case ASN1_ITYPE_NDEF_SEQUENCE:
case ASN1_ITYPE_SEQUENCE:
if(asn1_do_lock(pval, -1, it) > 0) return;
if(asn1_cb) {

View File

@ -155,7 +155,6 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int
goto auxerr;
break;
case ASN1_ITYPE_NDEF_SEQUENCE:
case ASN1_ITYPE_SEQUENCE:
if(asn1_cb) {
i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
@ -232,7 +231,6 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
case ASN1_ITYPE_COMPAT:
case ASN1_ITYPE_CHOICE:
case ASN1_ITYPE_SEQUENCE:
case ASN1_ITYPE_NDEF_SEQUENCE:
*pval = NULL;
break;
}

View File

@ -131,7 +131,3 @@ IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
/* Special, OCTET STRING with indefinite length constructed support */
IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)

View File

@ -102,8 +102,7 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
{
const ASN1_AUX *aux;
int *lck, ret;
if((it->itype != ASN1_ITYPE_SEQUENCE)
&& (it->itype != ASN1_ITYPE_NDEF_SEQUENCE)) return 0;
if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
aux = it->funcs;
if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
lck = offset2ptr(*pval, aux->ref_offset);

View File

@ -63,14 +63,13 @@
/* Minor tweak to operation: free up EVP_PKEY */
static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
{
if (operation == ASN1_OP_FREE_POST)
{
{
if(operation == ASN1_OP_FREE_POST) {
X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
EVP_PKEY_free(pubkey->pkey);
}
return 1;
}
return 1;
}
ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR),
@ -109,12 +108,13 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
a->parameter->type=V_ASN1_NULL;
}
}
else
#ifndef OPENSSL_NO_DSA
else if (pkey->type == EVP_PKEY_DSA)
if (pkey->type == EVP_PKEY_DSA)
{
unsigned char *pp;
DSA *dsa;
dsa=pkey->pkey.dsa;
dsa->write_params=0;
ASN1_TYPE_free(a->parameter);
@ -128,62 +128,8 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
ASN1_STRING_set(a->parameter->value.sequence,p,i);
OPENSSL_free(p);
}
else
#endif
#ifndef OPENSSL_NO_EC
else if (pkey->type == EVP_PKEY_EC)
{
int nid=0;
unsigned char *pp;
EC_KEY *eckey;
eckey = pkey->pkey.eckey;
ASN1_TYPE_free(a->parameter);
if ((a->parameter = ASN1_TYPE_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
goto err;
}
if (EC_GROUP_get_asn1_flag(eckey->group)
&& (nid = EC_GROUP_get_nid(eckey->group)))
{
/* just set the OID */
a->parameter->type = V_ASN1_OBJECT;
a->parameter->value.object = OBJ_nid2obj(nid);
}
else /* explicit parameters */
{
if ((i = i2d_ECParameters(eckey, NULL)) == 0)
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
goto err;
}
if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE);
goto err;
}
pp = p;
if (!i2d_ECParameters(eckey, &pp))
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
OPENSSL_free(p);
goto err;
}
a->parameter->type = V_ASN1_SEQUENCE;
if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
OPENSSL_free(p);
goto err;
}
ASN1_STRING_set(a->parameter->value.sequence, p, i);
OPENSSL_free(p);
}
}
#endif
else if (1)
{
X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
goto err;
@ -227,7 +173,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
long j;
int type;
unsigned char *p;
#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
#ifndef OPENSSL_NO_DSA
const unsigned char *cp;
X509_ALGOR *a;
#endif
@ -235,102 +181,40 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
if (key == NULL) goto err;
if (key->pkey != NULL)
{
CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
return(key->pkey);
}
{
CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
return(key->pkey);
}
if (key->public_key == NULL) goto err;
type=OBJ_obj2nid(key->algor->algorithm);
if ((ret = EVP_PKEY_new()) == NULL)
p=key->public_key->data;
j=key->public_key->length;
if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
{
X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
goto err;
}
ret->type = EVP_PKEY_type(type);
ret->save_parameters=0;
/* the parameters must be extracted before the public key (ECDSA!) */
#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
a=key->algor;
#endif
if (0)
;
#ifndef OPENSSL_NO_DSA
else if (ret->type == EVP_PKEY_DSA)
a=key->algor;
if (ret->type == EVP_PKEY_DSA)
{
if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
{
if ((ret->pkey.dsa = DSA_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
goto err;
}
ret->pkey.dsa->write_params=0;
cp=p=a->parameter->value.sequence->data;
j=a->parameter->value.sequence->length;
if (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j))
if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))
goto err;
}
ret->save_parameters=1;
}
#endif
#ifndef OPENSSL_NO_EC
else if (ret->type == EVP_PKEY_EC)
{
if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
{
/* type == V_ASN1_SEQUENCE => we have explicit parameters
* (e.g. parameters in the X9_62_EC_PARAMETERS-structure )
*/
if ((ret->pkey.eckey= EC_KEY_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_GET,
ERR_R_MALLOC_FAILURE);
goto err;
}
cp = p = a->parameter->value.sequence->data;
j = a->parameter->value.sequence->length;
if (!d2i_ECParameters(&ret->pkey.eckey, &cp, (long)j))
{
X509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);
goto err;
}
}
else if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))
{
/* type == V_ASN1_OBJECT => the parameters are given
* by an asn1 OID
*/
EC_KEY *eckey;
if (ret->pkey.eckey == NULL)
ret->pkey.eckey = EC_KEY_new();
eckey = ret->pkey.eckey;
if (eckey->group)
EC_GROUP_free(eckey->group);
if ((eckey->group = EC_GROUP_new_by_nid(
OBJ_obj2nid(a->parameter->value.object))) == NULL)
goto err;
EC_GROUP_set_asn1_flag(eckey->group,
OPENSSL_EC_NAMED_CURVE);
}
/* the case implicitlyCA is currently not implemented */
ret->save_parameters = 1;
}
#endif
p=key->public_key->data;
j=key->public_key->length;
if ((ret = d2i_PublicKey(type, &ret, &p, (long)j)) == NULL)
{
X509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB);
goto err;
}
key->pkey = ret;
CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
key->pkey=ret;
CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
return(ret);
err:
if (ret != NULL)
@ -344,7 +228,7 @@ err:
EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
long length)
{
{
X509_PUBKEY *xpk;
EVP_PKEY *pktmp;
xpk = d2i_X509_PUBKEY(NULL, pp, length);
@ -352,16 +236,15 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
pktmp = X509_PUBKEY_get(xpk);
X509_PUBKEY_free(xpk);
if(!pktmp) return NULL;
if(a)
{
if(a) {
EVP_PKEY_free(*a);
*a = pktmp;
}
return pktmp;
}
return pktmp;
}
int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
{
{
X509_PUBKEY *xpk=NULL;
int ret;
if(!a) return 0;
@ -369,7 +252,7 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
ret = i2d_X509_PUBKEY(xpk, pp);
X509_PUBKEY_free(xpk);
return ret;
}
}
/* The following are equivalents but which return RSA and DSA
* keys
@ -377,117 +260,75 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
#ifndef OPENSSL_NO_RSA
RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
long length)
{
{
EVP_PKEY *pkey;
RSA *key;
unsigned char *q;
q = *pp;
pkey = d2i_PUBKEY(NULL, &q, length);
if (!pkey) return NULL;
if(!pkey) return NULL;
key = EVP_PKEY_get1_RSA(pkey);
EVP_PKEY_free(pkey);
if (!key) return NULL;
if(!key) return NULL;
*pp = q;
if (a)
{
if(a) {
RSA_free(*a);
*a = key;
}
return key;
}
return key;
}
int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
{
{
EVP_PKEY *pktmp;
int ret;
if (!a) return 0;
if(!a) return 0;
pktmp = EVP_PKEY_new();
if (!pktmp)
{
if(!pktmp) {
ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
}
EVP_PKEY_set1_RSA(pktmp, a);
ret = i2d_PUBKEY(pktmp, pp);
EVP_PKEY_free(pktmp);
return ret;
}
}
#endif
#ifndef OPENSSL_NO_DSA
DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
long length)
{
{
EVP_PKEY *pkey;
DSA *key;
unsigned char *q;
q = *pp;
pkey = d2i_PUBKEY(NULL, &q, length);
if (!pkey) return NULL;
if(!pkey) return NULL;
key = EVP_PKEY_get1_DSA(pkey);
EVP_PKEY_free(pkey);
if (!key) return NULL;
if(!key) return NULL;
*pp = q;
if (a)
{
if(a) {
DSA_free(*a);
*a = key;
}
return key;
}
return key;
}
int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
{
{
EVP_PKEY *pktmp;
int ret;
if(!a) return 0;
pktmp = EVP_PKEY_new();
if(!pktmp)
{
if(!pktmp) {
ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
}
EVP_PKEY_set1_DSA(pktmp, a);
ret = i2d_PUBKEY(pktmp, pp);
EVP_PKEY_free(pktmp);
return ret;
}
#endif
#ifndef OPENSSL_NO_EC
EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, unsigned char **pp, long length)
{
EVP_PKEY *pkey;
EC_KEY *key;
unsigned char *q;
q = *pp;
pkey = d2i_PUBKEY(NULL, &q, length);
if (!pkey) return(NULL);
key = EVP_PKEY_get1_EC_KEY(pkey);
EVP_PKEY_free(pkey);
if (!key) return(NULL);
*pp = q;
if (a)
{
EC_KEY_free(*a);
*a = key;
}
return(key);
}
int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
{
EVP_PKEY *pktmp;
int ret;
if (!a) return(0);
if ((pktmp = EVP_PKEY_new()) == NULL)
{
ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
return(0);
}
EVP_PKEY_set1_EC_KEY(pktmp, a);
ret = i2d_PUBKEY(pktmp, pp);
EVP_PKEY_free(pktmp);
return(ret);
}
}
#endif

View File

@ -91,14 +91,6 @@ static X509_CERT_AUX *aux_get(X509 *x)
int X509_alias_set1(X509 *x, unsigned char *name, int len)
{
X509_CERT_AUX *aux;
if (!name)
{
if (!x || !x->aux || !x->aux->alias)
return 1;
ASN1_UTF8STRING_free(x->aux->alias);
x->aux->alias = NULL;
return 1;
}
if(!(aux = aux_get(x))) return 0;
if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
return ASN1_STRING_set(aux->alias, name, len);
@ -107,14 +99,6 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len)
int X509_keyid_set1(X509 *x, unsigned char *id, int len)
{
X509_CERT_AUX *aux;
if (!id)
{
if (!x || !x->aux || !x->aux->keyid)
return 1;
ASN1_OCTET_STRING_free(x->aux->keyid);
x->aux->keyid = NULL;
return 1;
}
if(!(aux = aux_get(x))) return 0;
if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
return ASN1_STRING_set(aux->keyid, id, len);
@ -127,13 +111,6 @@ unsigned char *X509_alias_get0(X509 *x, int *len)
return x->aux->alias->data;
}
unsigned char *X509_keyid_get0(X509 *x, int *len)
{
if(!x->aux || !x->aux->keyid) return NULL;
if(len) *len = x->aux->keyid->length;
return x->aux->keyid->data;
}
int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
{
X509_CERT_AUX *aux;

View File

@ -39,12 +39,12 @@ LIB=$(TOP)/libcrypto.a
LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c
bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c
LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o
bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o
SRC= $(LIBSRC)
@ -242,13 +242,6 @@ bn_gcd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
bn_gcd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bn_gcd.o: ../cryptlib.h bn_gcd.c bn_lcl.h
bn_gf2m.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
bn_gf2m.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
bn_gf2m.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
bn_gf2m.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bn_gf2m.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
bn_gf2m.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bn_gf2m.o: ../cryptlib.h bn_gf2m.c bn_lcl.h
bn_kron.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
bn_kron.o: ../../include/openssl/opensslconf.h bn_kron.c bn_lcl.h
bn_lib.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
@ -286,13 +279,6 @@ bn_mul.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
bn_mul.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bn_mul.o: ../cryptlib.h bn_lcl.h bn_mul.c
bn_nist.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
bn_nist.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
bn_nist.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
bn_nist.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
bn_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
bn_nist.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
bn_nist.o: ../cryptlib.h bn_lcl.h bn_nist.c
bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h

View File

@ -55,19 +55,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the Eric Young open source
* license provided above.
*
* The binary polynomial arithmetic software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#ifndef HEADER_BN_H
#define HEADER_BN_H
@ -320,11 +307,6 @@ typedef struct bn_recp_ctx_st
#define BN_one(a) (BN_set_word((a),1))
#define BN_zero(a) (BN_set_word((a),0))
/* BN_set_sign(BIGNUM *, int) sets the sign of a BIGNUM
* (0 for a non-negative value, 1 for negative) */
#define BN_set_sign(a,b) ((a)->neg = (b))
/* BN_get_sign(BIGNUM *) returns the sign of the BIGNUM */
#define BN_get_sign(a) ((a)->neg)
/*#define BN_ascii2bn(a) BN_hex2bn(a) */
/*#define BN_bn2ascii(a) BN_bn2hex(a) */
@ -347,8 +329,6 @@ BIGNUM *BN_new(void);
void BN_init(BIGNUM *);
void BN_clear_free(BIGNUM *a);
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
/* BN_ncopy(): like BN_copy() but copies at most the first n BN_ULONGs */
BIGNUM *BN_ncopy(BIGNUM *a, const BIGNUM *b, size_t n);
void BN_swap(BIGNUM *a, BIGNUM *b);
BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
int BN_bn2bin(const BIGNUM *a, unsigned char *to);
@ -473,71 +453,6 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
BN_RECP_CTX *recp, BN_CTX *ctx);
/* Functions for arithmetic over binary polynomials represented by BIGNUMs.
*
* The BIGNUM::neg property of BIGNUMs representing binary polynomials is
* ignored.
*
* Note that input arguments are not const so that their bit arrays can
* be expanded to the appropriate size if needed.
*/
int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/
#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/
int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */
int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
BN_CTX *ctx); /* r = (a * a) mod p */
int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,
BN_CTX *ctx); /* r = (1 / b) mod p */
int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */
int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */
int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
BN_CTX *ctx); /* r = sqrt(a) mod p */
int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
BN_CTX *ctx); /* r^2 + r = a mod p */
#define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))
/* Some functions allow for representation of the irreducible polynomials
* as an unsigned int[], say p. The irreducible f(t) is then of the form:
* t^p[0] + t^p[1] + ... + t^p[k]
* where m = p[0] > p[1] > ... > p[k] = 0.
*/
int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]);
/* r = a mod p */
int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const unsigned int p[], BN_CTX *ctx); /* r = (a * b) mod p */
int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[],
BN_CTX *ctx); /* r = (a * a) mod p */
int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const unsigned int p[],
BN_CTX *ctx); /* r = (1 / b) mod p */
int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const unsigned int p[], BN_CTX *ctx); /* r = (a / b) mod p */
int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
const unsigned int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */
int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
const unsigned int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */
int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
const unsigned int p[], BN_CTX *ctx); /* r^2 + r = a mod p */
int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max);
int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a);
/* faster mod functions for the 'NIST primes'
* 0 <= a < p^2 */
int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
const BIGNUM *BN_get0_nist_prime_192(void);
const BIGNUM *BN_get0_nist_prime_224(void);
const BIGNUM *BN_get0_nist_prime_256(void);
const BIGNUM *BN_get0_nist_prime_384(void);
const BIGNUM *BN_get0_nist_prime_521(void);
/* library internal functions */
#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
@ -595,13 +510,6 @@ void ERR_load_BN_strings(void);
#define BN_F_BN_DIV 107
#define BN_F_BN_EXPAND2 108
#define BN_F_BN_EXPAND_INTERNAL 120
#define BN_F_BN_GF2M_MOD 126
#define BN_F_BN_GF2M_MOD_DIV 123
#define BN_F_BN_GF2M_MOD_EXP 127
#define BN_F_BN_GF2M_MOD_MUL 124
#define BN_F_BN_GF2M_MOD_SOLVE_QUAD 128
#define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 129
#define BN_F_BN_GF2M_MOD_SQR 125
#define BN_F_BN_MOD_EXP2_MONT 118
#define BN_F_BN_MOD_EXP_MONT 109
#define BN_F_BN_MOD_EXP_MONT_WORD 117
@ -627,7 +535,6 @@ void ERR_load_BN_strings(void);
#define BN_R_INVALID_LENGTH 106
#define BN_R_INVALID_RANGE 115
#define BN_R_NOT_A_SQUARE 111
#define BN_R_NOT_IMPLEMENTED 116
#define BN_R_NOT_INITIALIZED 107
#define BN_R_NO_INVERSE 108
#define BN_R_P_IS_NOT_PRIME 112

View File

@ -1,6 +1,6 @@
/* crypto/bn/bn_err.c */
/* ====================================================================
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
* 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
@ -77,13 +77,6 @@ static ERR_STRING_DATA BN_str_functs[]=
{ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"},
{ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"},
{ERR_PACK(0,BN_F_BN_EXPAND_INTERNAL,0), "BN_EXPAND_INTERNAL"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD,0), "BN_GF2m_mod"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_DIV,0), "BN_GF2m_mod_div"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_EXP,0), "BN_GF2m_mod_exp"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_MUL,0), "BN_GF2m_mod_mul"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_SOLVE_QUAD,0), "BN_GF2m_mod_solve_quad"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR,0), "BN_GF2m_mod_solve_quad_arr"},
{ERR_PACK(0,BN_F_BN_GF2M_MOD_SQR,0), "BN_GF2m_mod_sqr"},
{ERR_PACK(0,BN_F_BN_MOD_EXP2_MONT,0), "BN_mod_exp2_mont"},
{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"},
{ERR_PACK(0,BN_F_BN_MOD_EXP_MONT_WORD,0), "BN_mod_exp_mont_word"},
@ -112,7 +105,6 @@ static ERR_STRING_DATA BN_str_reasons[]=
{BN_R_INVALID_LENGTH ,"invalid length"},
{BN_R_INVALID_RANGE ,"invalid range"},
{BN_R_NOT_A_SQUARE ,"not a square"},
{BN_R_NOT_IMPLEMENTED ,"not implemented"},
{BN_R_NOT_INITIALIZED ,"not initialized"},
{BN_R_NO_INVERSE ,"no inverse"},
{BN_R_P_IS_NOT_PRIME ,"p is not prime"},

View File

@ -1,995 +0,0 @@
/* crypto/bn/bn_gf2m.c */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* The Elliptic Curve Public-Key Crypto Library (ECC Code) included
* herein is developed by SUN MICROSYSTEMS, INC., and is contributed
* to the OpenSSL project.
*
* The ECC Code is licensed pursuant to the OpenSSL open source
* license provided below.
*
* In addition, Sun covenants to all licensees who provide a reciprocal
* covenant with respect to their own patents if any, not to sue under
* current and future patent claims necessarily infringed by the making,
* using, practicing, selling, offering for sale and/or otherwise
* disposing of the ECC Code as delivered hereunder (or portions thereof),
* provided that such covenant shall not apply:
* 1) for code that a licensee deletes from the ECC Code;
* 2) separates from the ECC Code; or
* 3) for infringements caused by:
* i) the modification of the ECC Code or
* ii) the combination of the ECC Code with other software or
* devices where such combination causes the infringement.
*
* The software is originally written by Sheueling Chang Shantz and
* Douglas Stebila of Sun Microsystems Laboratories.
*
*/
/* NOTE: This file is licensed pursuant to the OpenSSL license below
* and may be modified; but after modifications, the above covenant
* may no longer apply! In such cases, the corresponding paragraph
* ["In addition, Sun covenants ... causes the infringement."] and
* this note can be edited out; but please keep the Sun copyright
* notice and attribution. */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include "cryptlib.h"
#include "bn_lcl.h"
/* Maximum number of iterations before BN_GF2m_mod_solve_quad_arr should fail. */
#define MAX_ITERATIONS 50
static const BN_ULONG SQR_tb[16] =
{ 0, 1, 4, 5, 16, 17, 20, 21,
64, 65, 68, 69, 80, 81, 84, 85 };
/* Platform-specific macros to accelerate squaring. */
#if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
#define SQR1(w) \
SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \
SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \
SQR_tb[(w) >> 44 & 0xF] << 24 | SQR_tb[(w) >> 40 & 0xF] << 16 | \
SQR_tb[(w) >> 36 & 0xF] << 8 | SQR_tb[(w) >> 32 & 0xF]
#define SQR0(w) \
SQR_tb[(w) >> 28 & 0xF] << 56 | SQR_tb[(w) >> 24 & 0xF] << 48 | \
SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \
SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \
SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF]
#endif
#ifdef THIRTY_TWO_BIT
#define SQR1(w) \
SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \
SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF]
#define SQR0(w) \
SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \
SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF]
#endif
#ifdef SIXTEEN_BIT
#define SQR1(w) \
SQR_tb[(w) >> 12 & 0xF] << 8 | SQR_tb[(w) >> 8 & 0xF]
#define SQR0(w) \
SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF]
#endif
#ifdef EIGHT_BIT
#define SQR1(w) \
SQR_tb[(w) >> 4 & 0xF]
#define SQR0(w) \
SQR_tb[(w) & 15]
#endif
/* Product of two polynomials a, b each with degree < BN_BITS2 - 1,
* result is a polynomial r with degree < 2 * BN_BITS - 1
* The caller MUST ensure that the variables have the right amount
* of space allocated.
*/
#ifdef EIGHT_BIT
static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
{
register BN_ULONG h, l, s;
BN_ULONG tab[4], top1b = a >> 7;
register BN_ULONG a1, a2;
a1 = a & (0x7F); a2 = a1 << 1;
tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2;
s = tab[b & 0x3]; l = s;
s = tab[b >> 2 & 0x3]; l ^= s << 2; h = s >> 6;
s = tab[b >> 4 & 0x3]; l ^= s << 4; h ^= s >> 4;
s = tab[b >> 6 ]; l ^= s << 6; h ^= s >> 2;
/* compensate for the top bit of a */
if (top1b & 01) { l ^= b << 7; h ^= b >> 1; }
*r1 = h; *r0 = l;
}
#endif
#ifdef SIXTEEN_BIT
static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
{
register BN_ULONG h, l, s;
BN_ULONG tab[4], top1b = a >> 15;
register BN_ULONG a1, a2;
a1 = a & (0x7FFF); a2 = a1 << 1;
tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2;
s = tab[b & 0x3]; l = s;
s = tab[b >> 2 & 0x3]; l ^= s << 2; h = s >> 14;
s = tab[b >> 4 & 0x3]; l ^= s << 4; h ^= s >> 12;
s = tab[b >> 6 & 0x3]; l ^= s << 6; h ^= s >> 10;
s = tab[b >> 8 & 0x3]; l ^= s << 8; h ^= s >> 8;
s = tab[b >>10 & 0x3]; l ^= s << 10; h ^= s >> 6;
s = tab[b >>12 & 0x3]; l ^= s << 12; h ^= s >> 4;
s = tab[b >>14 ]; l ^= s << 14; h ^= s >> 2;
/* compensate for the top bit of a */
if (top1b & 01) { l ^= b << 15; h ^= b >> 1; }
*r1 = h; *r0 = l;
}
#endif
#ifdef THIRTY_TWO_BIT
static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
{
register BN_ULONG h, l, s;
BN_ULONG tab[8], top2b = a >> 30;
register BN_ULONG a1, a2, a4;
a1 = a & (0x3FFFFFFF); a2 = a1 << 1; a4 = a2 << 1;
tab[0] = 0; tab[1] = a1; tab[2] = a2; tab[3] = a1^a2;
tab[4] = a4; tab[5] = a1^a4; tab[6] = a2^a4; tab[7] = a1^a2^a4;
s = tab[b & 0x7]; l = s;
s = tab[b >> 3 & 0x7]; l ^= s << 3; h = s >> 29;
s = tab[b >> 6 & 0x7]; l ^= s << 6; h ^= s >> 26;
s = tab[b >> 9 & 0x7]; l ^= s << 9; h ^= s >> 23;
s = tab[b >> 12 & 0x7]; l ^= s << 12; h ^= s >> 20;
s = tab[b >> 15 & 0x7]; l ^= s << 15; h ^= s >> 17;
s = tab[b >> 18 & 0x7]; l ^= s << 18; h ^= s >> 14;
s = tab[b >> 21 & 0x7]; l ^= s << 21; h ^= s >> 11;
s = tab[b >> 24 & 0x7]; l ^= s << 24; h ^= s >> 8;
s = tab[b >> 27 & 0x7]; l ^= s << 27; h ^= s >> 5;
s = tab[b >> 30 ]; l ^= s << 30; h ^= s >> 2;
/* compensate for the top two bits of a */
if (top2b & 01) { l ^= b << 30; h ^= b >> 2; }
if (top2b & 02) { l ^= b << 31; h ^= b >> 1; }
*r1 = h; *r0 = l;
}
#endif
#if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b)
{
register BN_ULONG h, l, s;
BN_ULONG tab[16], top3b = a >> 61;
register BN_ULONG a1, a2, a4, a8;
a1 = a & (0x1FFFFFFFFFFFFFFF); a2 = a1 << 1; a4 = a2 << 1; a8 = a4 << 1;
tab[ 0] = 0; tab[ 1] = a1; tab[ 2] = a2; tab[ 3] = a1^a2;
tab[ 4] = a4; tab[ 5] = a1^a4; tab[ 6] = a2^a4; tab[ 7] = a1^a2^a4;
tab[ 8] = a8; tab[ 9] = a1^a8; tab[10] = a2^a8; tab[11] = a1^a2^a8;
tab[12] = a4^a8; tab[13] = a1^a4^a8; tab[14] = a2^a4^a8; tab[15] = a1^a2^a4^a8;
s = tab[b & 0xF]; l = s;
s = tab[b >> 4 & 0xF]; l ^= s << 4; h = s >> 60;
s = tab[b >> 8 & 0xF]; l ^= s << 8; h ^= s >> 56;
s = tab[b >> 12 & 0xF]; l ^= s << 12; h ^= s >> 52;
s = tab[b >> 16 & 0xF]; l ^= s << 16; h ^= s >> 48;
s = tab[b >> 20 & 0xF]; l ^= s << 20; h ^= s >> 44;
s = tab[b >> 24 & 0xF]; l ^= s << 24; h ^= s >> 40;
s = tab[b >> 28 & 0xF]; l ^= s << 28; h ^= s >> 36;
s = tab[b >> 32 & 0xF]; l ^= s << 32; h ^= s >> 32;
s = tab[b >> 36 & 0xF]; l ^= s << 36; h ^= s >> 28;
s = tab[b >> 40 & 0xF]; l ^= s << 40; h ^= s >> 24;
s = tab[b >> 44 & 0xF]; l ^= s << 44; h ^= s >> 20;
s = tab[b >> 48 & 0xF]; l ^= s << 48; h ^= s >> 16;
s = tab[b >> 52 & 0xF]; l ^= s << 52; h ^= s >> 12;
s = tab[b >> 56 & 0xF]; l ^= s << 56; h ^= s >> 8;
s = tab[b >> 60 ]; l ^= s << 60; h ^= s >> 4;
/* compensate for the top three bits of a */
if (top3b & 01) { l ^= b << 61; h ^= b >> 3; }
if (top3b & 02) { l ^= b << 62; h ^= b >> 2; }
if (top3b & 04) { l ^= b << 63; h ^= b >> 1; }
*r1 = h; *r0 = l;
}
#endif
/* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1,
* result is a polynomial r with degree < 4 * BN_BITS2 - 1
* The caller MUST ensure that the variables have the right amount
* of space allocated.
*/
static void bn_GF2m_mul_2x2(BN_ULONG *r, const BN_ULONG a1, const BN_ULONG a0, const BN_ULONG b1, const BN_ULONG b0)
{
BN_ULONG m1, m0;
/* r[3] = h1, r[2] = h0; r[1] = l1; r[0] = l0 */
bn_GF2m_mul_1x1(r+3, r+2, a1, b1);
bn_GF2m_mul_1x1(r+1, r, a0, b0);
bn_GF2m_mul_1x1(&m1, &m0, a0 ^ a1, b0 ^ b1);
/* Correction on m1 ^= l1 ^ h1; m0 ^= l0 ^ h0; */
r[2] ^= m1 ^ r[1] ^ r[3]; /* h0 ^= m1 ^ l1 ^ h1; */
r[1] = r[3] ^ r[2] ^ r[0] ^ m1 ^ m0; /* l1 ^= l0 ^ h0 ^ m0; */
}
/* Add polynomials a and b and store result in r; r could be a or b, a and b
* could be equal; r is the bitwise XOR of a and b.
*/
int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int i;
const BIGNUM *at, *bt;
if (a->top < b->top) { at = b; bt = a; }
else { at = a; bt = b; }
bn_wexpand(r, at->top);
for (i = 0; i < bt->top; i++)
{
r->d[i] = at->d[i] ^ bt->d[i];
}
for (; i < at->top; i++)
{
r->d[i] = at->d[i];
}
r->top = at->top;
bn_fix_top(r);
return 1;
}
/* Some functions allow for representation of the irreducible polynomials
* as an int[], say p. The irreducible f(t) is then of the form:
* t^p[0] + t^p[1] + ... + t^p[k]
* where m = p[0] > p[1] > ... > p[k] = 0.
*/
/* Performs modular reduction of a and store result in r. r could be a. */
int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[])
{
int j, k;
int n, dN, d0, d1;
BN_ULONG zz, *z;
/* Since the algorithm does reduction in the r value, if a != r, copy the
* contents of a into r so we can do reduction in r.
*/
if (a != r)
{
if (!bn_wexpand(r, a->top)) return 0;
for (j = 0; j < a->top; j++)
{
r->d[j] = a->d[j];
}
r->top = a->top;
}
z = r->d;
/* start reduction */
dN = p[0] / BN_BITS2;
for (j = r->top - 1; j > dN;)
{
zz = z[j];
if (z[j] == 0) { j--; continue; }
z[j] = 0;
for (k = 1; p[k] > 0; k++)
{
/* reducing component t^p[k] */
n = p[0] - p[k];
d0 = n % BN_BITS2; d1 = BN_BITS2 - d0;
n /= BN_BITS2;
z[j-n] ^= (zz>>d0);
if (d0) z[j-n-1] ^= (zz<<d1);
}
/* reducing component t^0 */
n = dN;
d0 = p[0] % BN_BITS2;
d1 = BN_BITS2 - d0;
z[j-n] ^= (zz >> d0);
if (d0) z[j-n-1] ^= (zz << d1);
}
/* final round of reduction */
while (j == dN)
{
d0 = p[0] % BN_BITS2;
zz = z[dN] >> d0;
if (zz == 0) break;
d1 = BN_BITS2 - d0;
if (d0) z[dN] = (z[dN] << d1) >> d1; /* clear up the top d1 bits */
z[0] ^= zz; /* reduction t^0 component */
for (k = 1; p[k] > 0; k++)
{
BN_ULONG tmp_ulong;
/* reducing component t^p[k]*/
n = p[k] / BN_BITS2;
d0 = p[k] % BN_BITS2;
d1 = BN_BITS2 - d0;
z[n] ^= (zz << d0);
tmp_ulong = zz >> d1;
if (d0 && tmp_ulong)
z[n+1] ^= tmp_ulong;
}
}
bn_fix_top(r);
return 1;
}
/* Performs modular reduction of a by p and store result in r. r could be a.
*
* This function calls down to the BN_GF2m_mod_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_arr function.
*/
int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_arr(r, a, arr);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Compute the product of two polynomials a and b, reduce modulo p, and store
* the result in r. r could be a or b; a could be b.
*/
int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsigned int p[], BN_CTX *ctx)
{
int zlen, i, j, k, ret = 0;
BIGNUM *s;
BN_ULONG x1, x0, y1, y0, zz[4];
if (a == b)
{
return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
}
BN_CTX_start(ctx);
if ((s = BN_CTX_get(ctx)) == NULL) goto err;
zlen = a->top + b->top + 4;
if (!bn_wexpand(s, zlen)) goto err;
s->top = zlen;
for (i = 0; i < zlen; i++) s->d[i] = 0;
for (j = 0; j < b->top; j += 2)
{
y0 = b->d[j];
y1 = ((j+1) == b->top) ? 0 : b->d[j+1];
for (i = 0; i < a->top; i += 2)
{
x0 = a->d[i];
x1 = ((i+1) == a->top) ? 0 : a->d[i+1];
bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
for (k = 0; k < 4; k++) s->d[i+j+k] ^= zz[k];
}
}
bn_fix_top(s);
BN_GF2m_mod_arr(r, s, p);
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the product of two polynomials a and b, reduce modulo p, and store
* the result in r. r could be a or b; a could equal b.
*
* This function calls down to the BN_GF2m_mod_mul_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_mul_arr function.
*/
int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD_MUL,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Square a, reduce the result mod p, and store it in a. r could be a. */
int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)
{
int i, ret = 0;
BIGNUM *s;
BN_CTX_start(ctx);
if ((s = BN_CTX_get(ctx)) == NULL) return 0;
if (!bn_wexpand(s, 2 * a->top)) goto err;
for (i = a->top - 1; i >= 0; i--)
{
s->d[2*i+1] = SQR1(a->d[i]);
s->d[2*i ] = SQR0(a->d[i]);
}
s->top = 2 * a->top;
bn_fix_top(s);
if (!BN_GF2m_mod_arr(r, s, p)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Square a, reduce the result mod p, and store it in a. r could be a.
*
* This function calls down to the BN_GF2m_mod_sqr_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_sqr_arr function.
*/
int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD_SQR,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Invert a, reduce modulo p, and store the result in r. r could be a.
* Uses Modified Almost Inverse Algorithm (Algorithm 10) from
* Hankerson, D., Hernandez, J.L., and Menezes, A. "Software Implementation
* of Elliptic Curve Cryptography Over Binary Fields".
*/
int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
{
BIGNUM *b, *c, *u, *v, *tmp;
int ret = 0;
BN_CTX_start(ctx);
b = BN_CTX_get(ctx);
c = BN_CTX_get(ctx);
u = BN_CTX_get(ctx);
v = BN_CTX_get(ctx);
if (v == NULL) goto err;
if (!BN_one(b)) goto err;
if (!BN_zero(c)) goto err;
if (!BN_GF2m_mod(u, a, p)) goto err;
if (!BN_copy(v, p)) goto err;
u->neg = 0; /* Need to set u->neg = 0 because BN_is_one(u) checks
* the neg flag of the bignum.
*/
if (BN_is_zero(u)) goto err;
while (1)
{
while (!BN_is_odd(u))
{
if (!BN_rshift1(u, u)) goto err;
if (BN_is_odd(b))
{
if (!BN_GF2m_add(b, b, p)) goto err;
}
if (!BN_rshift1(b, b)) goto err;
}
if (BN_is_one(u)) break;
if (BN_num_bits(u) < BN_num_bits(v))
{
tmp = u; u = v; v = tmp;
tmp = b; b = c; c = tmp;
}
if (!BN_GF2m_add(u, u, v)) goto err;
if (!BN_GF2m_add(b, b, c)) goto err;
}
if (!BN_copy(r, b)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Invert xx, reduce modulo p, and store the result in r. r could be xx.
*
* This function calls down to the BN_GF2m_mod_inv implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_inv function.
*/
int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const unsigned int p[], BN_CTX *ctx)
{
BIGNUM *field;
int ret = 0;
BN_CTX_start(ctx);
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
if (!BN_GF2m_arr2poly(p, field)) goto err;
ret = BN_GF2m_mod_inv(r, xx, field, ctx);
err:
BN_CTX_end(ctx);
return ret;
}
#ifndef OPENSSL_SUN_GF2M_DIV
/* Divide y by x, reduce modulo p, and store the result in r. r could be x
* or y, x could equal y.
*/
int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, BN_CTX *ctx)
{
BIGNUM *xinv = NULL;
int ret = 0;
BN_CTX_start(ctx);
xinv = BN_CTX_get(ctx);
if (xinv == NULL) goto err;
if (!BN_GF2m_mod_inv(xinv, x, p, ctx)) goto err;
if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
#else
/* Divide y by x, reduce modulo p, and store the result in r. r could be x
* or y, x could equal y.
* Uses algorithm Modular_Division_GF(2^m) from
* Chang-Shantz, S. "From Euclid's GCD to Montgomery Multiplication to
* the Great Divide".
*/
int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x, const BIGNUM *p, BN_CTX *ctx)
{
BIGNUM *a, *b, *u, *v;
int ret = 0;
BN_CTX_start(ctx);
a = BN_CTX_get(ctx);
b = BN_CTX_get(ctx);
u = BN_CTX_get(ctx);
v = BN_CTX_get(ctx);
if (v == NULL) goto err;
/* reduce x and y mod p */
if (!BN_GF2m_mod(u, y, p)) goto err;
if (!BN_GF2m_mod(a, x, p)) goto err;
if (!BN_copy(b, p)) goto err;
if (!BN_zero(v)) goto err;
a->neg = 0; /* Need to set a->neg = 0 because BN_is_one(a) checks
* the neg flag of the bignum.
*/
while (!BN_is_odd(a))
{
if (!BN_rshift1(a, a)) goto err;
if (BN_is_odd(u)) if (!BN_GF2m_add(u, u, p)) goto err;
if (!BN_rshift1(u, u)) goto err;
}
do
{
if (BN_GF2m_cmp(b, a) > 0)
{
if (!BN_GF2m_add(b, b, a)) goto err;
if (!BN_GF2m_add(v, v, u)) goto err;
do
{
if (!BN_rshift1(b, b)) goto err;
if (BN_is_odd(v)) if (!BN_GF2m_add(v, v, p)) goto err;
if (!BN_rshift1(v, v)) goto err;
} while (!BN_is_odd(b));
}
else if (BN_is_one(a))
break;
else
{
if (!BN_GF2m_add(a, a, b)) goto err;
if (!BN_GF2m_add(u, u, v)) goto err;
do
{
if (!BN_rshift1(a, a)) goto err;
if (BN_is_odd(u)) if (!BN_GF2m_add(u, u, p)) goto err;
if (!BN_rshift1(u, u)) goto err;
} while (!BN_is_odd(a));
}
} while (1);
if (!BN_copy(r, u)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
#endif
/* Divide yy by xx, reduce modulo p, and store the result in r. r could be xx
* or yy, xx could equal yy.
*
* This function calls down to the BN_GF2m_mod_div implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_div function.
*/
int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx, const unsigned int p[], BN_CTX *ctx)
{
BIGNUM *field;
int ret = 0;
BN_CTX_start(ctx);
if ((field = BN_CTX_get(ctx)) == NULL) goto err;
if (!BN_GF2m_arr2poly(p, field)) goto err;
ret = BN_GF2m_mod_div(r, yy, xx, field, ctx);
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the bth power of a, reduce modulo p, and store
* the result in r. r could be a.
* Uses simple square-and-multiply algorithm A.5.1 from IEEE P1363.
*/
int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const unsigned int p[], BN_CTX *ctx)
{
int ret = 0, i, n;
BIGNUM *u;
if (BN_is_zero(b))
{
return(BN_one(r));
}
BN_CTX_start(ctx);
if ((u = BN_CTX_get(ctx)) == NULL) goto err;
if (!BN_GF2m_mod_arr(u, a, p)) goto err;
n = BN_num_bits(b) - 1;
for (i = n - 1; i >= 0; i--)
{
if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx)) goto err;
if (BN_is_bit_set(b, i))
{
if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx)) goto err;
}
}
if (!BN_copy(r, u)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the bth power of a, reduce modulo p, and store
* the result in r. r could be a.
*
* This function calls down to the BN_GF2m_mod_exp_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_exp_arr function.
*/
int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p, BN_CTX *ctx)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD_EXP,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Compute the square root of a, reduce modulo p, and store
* the result in r. r could be a.
* Uses exponentiation as in algorithm A.4.1 from IEEE P1363.
*/
int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[], BN_CTX *ctx)
{
int ret = 0;
BIGNUM *u;
BN_CTX_start(ctx);
if ((u = BN_CTX_get(ctx)) == NULL) goto err;
if (!BN_zero(u)) goto err;
if (!BN_set_bit(u, p[0] - 1)) goto err;
ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the square root of a, reduce modulo p, and store
* the result in r. r could be a.
*
* This function calls down to the BN_GF2m_mod_sqrt_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_sqrt_arr function.
*/
int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD_EXP,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Find r such that r^2 + r = a mod p. r could be a. If no r exists returns 0.
* Uses algorithms A.4.7 and A.4.6 from IEEE P1363.
*/
int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const unsigned int p[], BN_CTX *ctx)
{
int ret = 0, i, count = 0;
BIGNUM *a, *z, *rho, *w, *w2, *tmp;
BN_CTX_start(ctx);
a = BN_CTX_get(ctx);
z = BN_CTX_get(ctx);
w = BN_CTX_get(ctx);
if (w == NULL) goto err;
if (!BN_GF2m_mod_arr(a, a_, p)) goto err;
if (BN_is_zero(a))
{
ret = BN_zero(r);
goto err;
}
if (p[0] & 0x1) /* m is odd */
{
/* compute half-trace of a */
if (!BN_copy(z, a)) goto err;
for (i = 1; i <= (p[0] - 1) / 2; i++)
{
if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)) goto err;
if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)) goto err;
if (!BN_GF2m_add(z, z, a)) goto err;
}
}
else /* m is even */
{
rho = BN_CTX_get(ctx);
w2 = BN_CTX_get(ctx);
tmp = BN_CTX_get(ctx);
if (tmp == NULL) goto err;
do
{
if (!BN_rand(rho, p[0], 0, 0)) goto err;
if (!BN_GF2m_mod_arr(rho, rho, p)) goto err;
if (!BN_zero(z)) goto err;
if (!BN_copy(w, rho)) goto err;
for (i = 1; i <= p[0] - 1; i++)
{
if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx)) goto err;
if (!BN_GF2m_mod_sqr_arr(w2, w, p, ctx)) goto err;
if (!BN_GF2m_mod_mul_arr(tmp, w2, a, p, ctx)) goto err;
if (!BN_GF2m_add(z, z, tmp)) goto err;
if (!BN_GF2m_add(w, w2, rho)) goto err;
}
count++;
} while (BN_is_zero(w) && (count < MAX_ITERATIONS));
if (BN_is_zero(w))
{
BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR,BN_R_TOO_MANY_ITERATIONS);
goto err;
}
}
if (!BN_GF2m_mod_sqr_arr(w, z, p, ctx)) goto err;
if (!BN_GF2m_add(w, z, w)) goto err;
if (BN_GF2m_cmp(w, a)) goto err;
if (!BN_copy(r, z)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Find r such that r^2 + r = a mod p. r could be a. If no r exists returns 0.
*
* This function calls down to the BN_GF2m_mod_solve_quad_arr implementation; this wrapper
* function is only provided for convenience; for best performance, use the
* BN_GF2m_mod_solve_quad_arr function.
*/
int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
{
const int max = BN_num_bits(p);
unsigned int *arr=NULL, ret = 0;
if ((arr = (unsigned int *)OPENSSL_malloc(sizeof(unsigned int) * max)) == NULL) goto err;
if (BN_GF2m_poly2arr(p, arr, max) > max)
{
BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD,BN_R_INVALID_LENGTH);
goto err;
}
ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx);
err:
if (arr) OPENSSL_free(arr);
return ret;
}
/* Convert the bit-string representation of a polynomial a into an array
* of integers corresponding to the bits with non-zero coefficient.
* Up to max elements of the array will be filled. Return value is total
* number of coefficients that would be extracted if array was large enough.
*/
int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max)
{
int i, j, k;
BN_ULONG mask;
for (k = 0; k < max; k++) p[k] = 0;
k = 0;
for (i = a->top - 1; i >= 0; i--)
{
mask = BN_TBIT;
for (j = BN_BITS2 - 1; j >= 0; j--)
{
if (a->d[i] & mask)
{
if (k < max) p[k] = BN_BITS2 * i + j;
k++;
}
mask >>= 1;
}
}
return k;
}
/* Convert the coefficient array representation of a polynomial to a
* bit-string. The array must be terminated by 0.
*/
int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a)
{
int i;
BN_zero(a);
for (i = 0; p[i] > 0; i++)
{
BN_set_bit(a, p[i]);
}
BN_set_bit(a, 0);
return 1;
}

View File

@ -239,16 +239,6 @@ struct bignum_ctx
#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
#define bn_clear_top2max(a) \
{ \
int ind = (a)->dmax - (a)->top; \
BN_ULONG *ftl = &(a)->d[(a)->top-1]; \
for (; ind != 0; ind--) \
*(++ftl) = 0x0; \
}
/* This is used for internal error checking and is not normally used */
#ifdef BN_DEBUG
# include <assert.h>

View File

@ -363,6 +363,17 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
}
}
/* Now need to zero any data between b->top and b->max */
/* XXX Why? */
A= &(a[b->top]);
for (i=(words - b->top)>>3; i>0; i--,A+=8)
{
A[0]=0; A[1]=0; A[2]=0; A[3]=0;
A[4]=0; A[5]=0; A[6]=0; A[7]=0;
}
for (i=(words - b->top)&7; i>0; i--,A++)
A[0]=0;
#else
memset(A,0,sizeof(BN_ULONG)*(words+1));
memcpy(A,b->d,sizeof(b->d[0])*b->top);
@ -424,16 +435,12 @@ BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
}
/* This is an internal function that should not be used in applications.
* It ensures that 'b' has enough room for a 'words' word number
* and initialises any unused part of b->d with leading zeros.
* It ensures that 'b' has enough room for a 'words' word number number.
* It is mostly used by the various BIGNUM routines. If there is an error,
* NULL is returned. If not, 'b' is returned. */
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A;
int i;
if (words > b->dmax)
{
BN_ULONG *a = bn_expand_internal(b, words);
@ -448,21 +455,6 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
else
b = NULL;
}
/* NB: bn_wexpand() calls this only if the BIGNUM really has to grow */
if ((b != NULL) && (b->top < b->dmax))
{
A = &(b->d[b->top]);
for (i=(b->dmax - b->top)>>3; i>0; i--,A+=8)
{
A[0]=0; A[1]=0; A[2]=0; A[3]=0;
A[4]=0; A[5]=0; A[6]=0; A[7]=0;
}
for (i=(b->dmax - b->top)&7; i>0; i--,A++)
A[0]=0;
assert(A == &(b->d[b->dmax]));
}
return b;
}
@ -522,51 +514,6 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
return(a);
}
BIGNUM *BN_ncopy(BIGNUM *a, const BIGNUM *b, size_t n)
{
int i, min;
BN_ULONG *A;
const BN_ULONG *B;
bn_check_top(b);
if (a == b)
return a;
min = (b->top < (int)n)? b->top: (int)n;
if (!min)
{
BN_zero(a);
return a;
}
if (bn_wexpand(a, min) == NULL)
return NULL;
A=a->d;
B=b->d;
for (i=min>>2; i>0; i--, A+=4, B+=4)
{
BN_ULONG a0,a1,a2,a3;
a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
}
switch (min&3)
{
case 3: A[2]=B[2];
case 2: A[1]=B[1];
case 1: A[0]=B[0];
case 0: ;
}
a->top = min;
a->neg = b->neg;
bn_fix_top(a);
return(a);
}
void BN_swap(BIGNUM *a, BIGNUM *b)
{
int flags_old_a, flags_old_b;

View File

@ -1,843 +0,0 @@
/* crypto/bn/bn_nist.p */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include "bn_lcl.h"
#include "cryptlib.h"
#define BN_NIST_192_TOP (192+BN_BITS2-1)/BN_BITS2
#define BN_NIST_224_TOP (224+BN_BITS2-1)/BN_BITS2
#define BN_NIST_256_TOP (256+BN_BITS2-1)/BN_BITS2
#define BN_NIST_384_TOP (384+BN_BITS2-1)/BN_BITS2
#define BN_NIST_521_TOP (521+BN_BITS2-1)/BN_BITS2
#if BN_BITS2 == 64
const static BN_ULONG _nist_p_192[] = {0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFE,
0xFFFFFFFFFFFFFFFF};
const static BN_ULONG _nist_p_224[] = {0x0000000000000001,0xFFFFFFFF00000000,
0xFFFFFFFFFFFFFFFF,0x00000000FFFFFFFF};
const static BN_ULONG _nist_p_256[] = {0xFFFFFFFFFFFFFFFF,0x00000000FFFFFFFF,
0x0000000000000000,0xFFFFFFFF00000001};
const static BN_ULONG _nist_p_384[] = {0x00000000FFFFFFFF,0xFFFFFFFF00000000,
0xFFFFFFFFFFFFFFFE,0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF};
const static BN_ULONG _nist_p_521[] = {0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,
0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,0xFFFFFFFFFFFFFFFF,
0x00000000000001FF};
#elif BN_BITS2 == 32
const static BN_ULONG _nist_p_192[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFE,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
const static BN_ULONG _nist_p_224[] = {0x00000001,0x00000000,0x00000000,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
const static BN_ULONG _nist_p_256[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0x00000000,0x00000000,0x00000000,0x00000001,0xFFFFFFFF};
const static BN_ULONG _nist_p_384[] = {0xFFFFFFFF,0x00000000,0x00000000,
0xFFFFFFFF,0xFFFFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
const static BN_ULONG _nist_p_521[] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
0xFFFFFFFF,0x000001FF};
#elif BN_BITS2 == 16
const static BN_ULONG _nist_p_192[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFE,
0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
const static BN_ULONG _nist_p_224[] = {0x0001,0x0000,0x0000,0x0000,0x0000,
0x0000,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
const static BN_ULONG _nist_p_256[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0000,0xFFFF,
0xFFFF};
const static BN_ULONG _nist_p_384[] = {0xFFFF,0xFFFF,0x0000,0x0000,0x0000,
0x0000,0xFFFF,0xFFFF,0xFFFE,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
const static BN_ULONG _nist_p_521[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x01FF};
#elif BN_BITS2 == 8
const static BN_ULONG _nist_p_192[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF};
const static BN_ULONG _nist_p_224[] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
const static BN_ULONG _nist_p_256[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF};
const static BN_ULONG _nist_p_384[] = {0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
const static BN_ULONG _nist_p_521[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x01};
#endif
const BIGNUM *BN_get0_nist_prime_192(void)
{
static BIGNUM const_nist_192={(BN_ULONG *)_nist_p_192,BN_NIST_192_TOP,
BN_NIST_192_TOP, 0, BN_FLG_STATIC_DATA};
return &const_nist_192;
}
const BIGNUM *BN_get0_nist_prime_224(void)
{
static BIGNUM const_nist_224={(BN_ULONG *)_nist_p_224,BN_NIST_224_TOP,
BN_NIST_224_TOP, 0, BN_FLG_STATIC_DATA};
return &const_nist_224;
}
const BIGNUM *BN_get0_nist_prime_256(void)
{
static BIGNUM const_nist_256={(BN_ULONG *)_nist_p_256,BN_NIST_256_TOP,
BN_NIST_256_TOP, 0, BN_FLG_STATIC_DATA};
return &const_nist_256;
}
const BIGNUM *BN_get0_nist_prime_384(void)
{
static BIGNUM const_nist_384={(BN_ULONG *)_nist_p_384,BN_NIST_384_TOP,
BN_NIST_384_TOP, 0, BN_FLG_STATIC_DATA};
return &const_nist_384;
}
const BIGNUM *BN_get0_nist_prime_521(void)
{
static BIGNUM const_nist_521={(BN_ULONG *)_nist_p_521,BN_NIST_521_TOP,
BN_NIST_521_TOP, 0, BN_FLG_STATIC_DATA};
return &const_nist_521;
}
/* some misc internal functions */
static BN_ULONG _256_data[BN_NIST_256_TOP*6];
static int _is_set_256_data = 0;
static void _init_256_data(void);
static BN_ULONG _384_data[BN_NIST_384_TOP*8];
static int _is_set_384_data = 0;
static void _init_384_data(void);
#define BN_NIST_ADD_ONE(a) while (!(++(*(a)))) ++(a);
#define __buf_0 (BN_ULONG)0
#define __buf_0_1 (BN_ULONG)0
#define __buf_0_2 (BN_ULONG)0
#if BN_BITS2 == 64
#define BN_64_BIT_BUF(n) BN_ULONG __buf_##n = (BN_ULONG)0;
#define BN_CP_64_TO_BUF(n) __buf_##n = (a)[(n)];
#define BN_CP_64_FROM_BUF(a,n) *(a)++ = __buf_##n;
#define BN_CASE_64_BIT(n,a) case (n): __buf_##n = (a)[(n)];
#if UINT_MAX == 4294967295UL
#define nist32 unsigned int
#define BN_32_BIT_BUF(n) nist32 __buf_##n = (nist32)0;
#define BN_CP_32_TO_BUF(n) __buf_##n = ((nist32 *)(a))[(n)];
#define BN_CP_32_FROM_BUF(a,n) *((nist32)(a))++ = __buf_##n;
#define BN_CASE_32_BIT(n,a) case (n): __buf_##n = ((nist32)(a))[(n)];
#elif ULONG_MAX == 4294967295UL
#define nist32 unsigned long
#define BN_32_BIT_BUF(n) nist32 __buf_##n = (nist32)0;
#define BN_CP_32_TO_BUF(n) __buf_##n = ((nist32 *)(a))[(n)];
#define BN_CP_32_FROM_BUF(a,n) *((nist32)(a))++ = __buf_##n;
#define BN_CASE_32_BIT(n,a) case (n): __buf_##n = ((nist32)(a))[(n)];
#else
#define NO_32_BIT_TYPE
#endif
#elif BN_BITS2 == 32
#define BN_64_BIT_BUF(n) BN_ULONG __buf_##n##_1 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_2 = (BN_ULONG)0;
#define BN_CP_64_TO_BUF(n) __buf_##n##_2 = (a)[2*(n)+1];\
__buf_##n##_1 = (a)[2*(n)];
#define BN_CP_64_FROM_BUF(a,n) *(a)++ = __buf_##n##_1;\
*(a)++ = __buf_##n##_2;
#define BN_CASE_64_BIT(n,a) case 2*(n)+1: __buf_##n##_2 = (a)[2*(n)+1];\
case 2*(n): __buf_##n##_1 = (a)[2*(n)];
#define BN_32_BIT_BUF(n) BN_ULONG __buf_##n = (BN_ULONG)0;
#define BN_CP_32_TO_BUF(n) __buf_##n = (a)[(n)];
#define BN_CP_32_FROM_BUF(a,n) *(a)++ = __buf_##n;
#define BN_CASE_32_BIT(n,a) case (n): __buf_##n = (a)[(n)];
#elif BN_BITS2 == 16
#define __buf_0_3 (BN_ULONG)0
#define __buf_0_4 (BN_ULONG)0
#define BN_64_BIT_BUF(n) BN_ULONG __buf_##n##_1 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_2 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_3 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_4 = (BN_ULONG)0;
#define BN_CP_64_TO_BUF(n) __buf_##n##_4 = (a)[4*(n)+3];\
__buf_##n##_3 = (a)[4*(n)+2];\
__buf_##n##_2 = (a)[4*(n)+1];\
__buf_##n##_1 = (a)[4*(n)];
#define BN_CP_64_FROM_BUF(a,n) *(a)++ = __buf_##n##_1;\
*(a)++ = __buf_##n##_2;\
*(a)++ = __buf_##n##_3;\
*(a)++ = __buf_##n##_4;
#define BN_CASE_64_BIT(n,a) case 4*(n)+3: __buf_##n##_4 = (a)[4*(n)+3];\
case 4*(n)+2: __buf_##n##_3 = (a)[4*(n)+2];\
case 4*(n)+1: __buf_##n##_2 = (a)[4*(n)+1];\
case 4*(n): __buf_##n##_1 = (a)[4*(n)];
#define BN_32_BIT_BUF(n) BN_ULONG __buf_##n##_1 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_2 = (BN_ULONG)0;
#define BN_CP_32_TO_BUF(n) __buf_##n##_1 = (a)[2*(n)];\
__buf_##n##_2 = (a)[2*(n)+1];
#define BN_CP_32_FROM_BUF(a,n) *(a)++ = __buf_##n##_1;\
*(a)++ = __buf_##n##_2;
#define BN_CASE_32_BIT(n,a) case 2*(n)+1: __buf_##n##_2 = (a)[2*(n)+1];\
case 2*(n): __buf_##n##_1 = (a)[2*(n)];
#elif BN_BITS2 == 8
#define __buf_0_3 (BN_ULONG)0
#define __buf_0_4 (BN_ULONG)0
#define __buf_0_5 (BN_ULONG)0
#define __buf_0_6 (BN_ULONG)0
#define __buf_0_7 (BN_ULONG)0
#define __buf_0_8 (BN_ULONG)0
#define BN_64_BIT_BUF(n) BN_ULONG __buf_##n##_1 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_2 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_3 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_4 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_5 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_6 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_7 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_8 = (BN_ULONG)0;
#define BN_CP_64_TO_BUF(n) __buf_##n##_8 = (a)[8*(n)+7];\
__buf_##n##_7 = (a)[8*(n)+6];\
__buf_##n##_6 = (a)[8*(n)+5];\
__buf_##n##_5 = (a)[8*(n)+4];\
__buf_##n##_4 = (a)[8*(n)+3];\
__buf_##n##_3 = (a)[8*(n)+2];\
__buf_##n##_2 = (a)[8*(n)+1];\
__buf_##n##_1 = (a)[8*(n)];
#define BN_CP_64_FROM_BUF(a,n) *(a)++ = __buf_##n##_1;\
*(a)++ = __buf_##n##_2;\
*(a)++ = __buf_##n##_3;\
*(a)++ = __buf_##n##_4;\
*(a)++ = __buf_##n##_5;\
*(a)++ = __buf_##n##_6;\
*(a)++ = __buf_##n##_7;\
*(a)++ = __buf_##n##_8;
#define BN_CASE_64_BIT(n,a) case 8*(n)+7: __buf_##n##_8 = (a)[8*(n)+7];\
case 8*(n)+6: __buf_##n##_7 = (a)[8*(n)+6];\
case 8*(n)+5: __buf_##n##_6 = (a)[8*(n)+5];\
case 8*(n)+4: __buf_##n##_5 = (a)[8*(n)+4];\
case 8*(n)+3: __buf_##n##_4 = (a)[8*(n)+3];\
case 8*(n)+2: __buf_##n##_3 = (a)[8*(n)+2];\
case 8*(n)+1: __buf_##n##_2 = (a)[8*(n)+1];\
case 8*(n): __buf_##n##_1 = (a)[8*(n)];
#define BN_32_BIT_BUF(n) BN_ULONG __buf_##n##_1 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_2 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_3 = (BN_ULONG)0;\
BN_ULONG __buf_##n##_4 = (BN_ULONG)0;
#define BN_CP_32_TO_BUF(n) __buf_##n##_1 = (a)[4*(n)];\
__buf_##n##_2 = (a)[4*(n)+1];\
__buf_##n##_3 = (a)[4*(n)+2];\
__buf_##n##_4 = (a)[4*(n)+3];
#define BN_CP_32_FROM_BUF(a,n) *(a)++ = __buf_##n##_1;\
*(a)++ = __buf_##n##_2;\
*(a)++ = __buf_##n##_3;\
*(a)++ = __buf_##n##_4;
#define BN_CASE_32_BIT(n,a) case 4*(n)+3: __buf_##n##_4 = (a)[4*(n)+3];\
case 4*(n)+2: __buf_##n##_3 = (a)[4*(n)+2];\
case 4*(n)+1: __buf_##n##_2 = (a)[4*(n)+1];\
case 4*(n): __buf_##n##_1 = (a)[4*(n)];
#endif
#define BN_192_SET(d,a1,a2,a3) \
{\
register BN_ULONG *td = (d);\
BN_CP_64_FROM_BUF(td,a3); BN_CP_64_FROM_BUF(td,a2);\
BN_CP_64_FROM_BUF(td,a1);\
}
int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
BN_CTX *ctx)
{
int top;
BN_ULONG carry = 0;
register BN_ULONG *r_d, *a_d;
BN_ULONG t_d[BN_NIST_192_TOP];
BN_64_BIT_BUF(3) BN_64_BIT_BUF(4)
BN_64_BIT_BUF(5)
top = BN_ucmp(field, a);
if (top == 0)
return BN_zero(r);
else if (top > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
if (r != a)
if (!BN_ncopy(r, a, BN_NIST_192_TOP))
return 0;
r_d = r->d;
a_d = a->d;
top = a->top-1;
switch (top)
{
BN_CASE_64_BIT(5, a_d)
BN_CASE_64_BIT(4, a_d)
BN_CASE_64_BIT(3, a_d)
break;
default: /* a->top == field->top */
return BN_usub(r, a, field);
}
BN_192_SET(t_d,0,3,3)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP))
++carry;
BN_192_SET(t_d,4,4,0)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP))
++carry;
BN_192_SET(t_d,5,5,5)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_192_TOP))
++carry;
while (carry)
{
if (bn_sub_words(r_d, r_d, _nist_p_192, BN_NIST_192_TOP))
--carry;
}
r->top = BN_NIST_192_TOP;
#if 1
bn_clear_top2max(r);
#endif
bn_fix_top(r);
if (BN_ucmp(r, field) >= 0)
{
bn_sub_words(r_d, r_d, _nist_p_192, BN_NIST_192_TOP);
bn_fix_top(r);
}
return 1;
}
#define BN_224_SET(d,a1,a2,a3,a4,a5,a6,a7) \
{\
register BN_ULONG *td = (d);\
BN_CP_32_FROM_BUF(td,a7); BN_CP_32_FROM_BUF(td,a6);\
BN_CP_32_FROM_BUF(td,a5); BN_CP_32_FROM_BUF(td,a4);\
BN_CP_32_FROM_BUF(td,a3); BN_CP_32_FROM_BUF(td,a2);\
BN_CP_32_FROM_BUF(td,a1);\
}
int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
BN_CTX *ctx)
{
#ifndef NO_32_BIT_TYPE
int tmp_int;
int carry = 0;
BN_ULONG *r_d, *a_d;
BN_ULONG t_d[BN_NIST_224_TOP];
BN_32_BIT_BUF(7) BN_32_BIT_BUF(8)
BN_32_BIT_BUF(9) BN_32_BIT_BUF(10)
BN_32_BIT_BUF(11) BN_32_BIT_BUF(12)
BN_32_BIT_BUF(13)
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
return BN_zero(r);
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
if (r != a)
if (!BN_ncopy(r, a, BN_NIST_224_TOP))
return 0;
r_d = r->d;
a_d = a->d;
tmp_int = a->top-1;
switch (tmp_int)
{
BN_CASE_32_BIT(13, a_d)
BN_CASE_32_BIT(12, a_d)
BN_CASE_32_BIT(11, a_d)
BN_CASE_32_BIT(10, a_d)
BN_CASE_32_BIT(9, a_d)
BN_CASE_32_BIT(8, a_d)
BN_CASE_32_BIT(7, a_d)
break;
default: /* a->top == field->top */
return BN_usub(r, a, field);
}
BN_224_SET(t_d,10,9,8,7,0,0,0)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP))
++carry;
BN_224_SET(t_d,0,13,12,11,0,0,0)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_224_TOP))
++carry;
BN_224_SET(t_d,13,12,11,10,9,8,7)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP))
--carry;
BN_224_SET(t_d,0,0,0,0,13,12,11)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_224_TOP))
--carry;
if (carry > 0)
while (carry)
{
if (bn_sub_words(r_d,r_d,_nist_p_224,BN_NIST_224_TOP))
--carry;
}
else if (carry < 0)
while (carry)
{
if (bn_add_words(r_d,r_d,_nist_p_224,BN_NIST_224_TOP))
++carry;
}
r->top = BN_NIST_224_TOP;
#if 1
bn_clear_top2max(r);
#endif
bn_fix_top(r);
if (BN_ucmp(r, field) >= 0)
{
bn_sub_words(r_d, r_d, _nist_p_224, BN_NIST_224_TOP);
bn_fix_top(r);
}
return 1;
#else
return 0;
#endif
}
static void _init_256_data(void)
{
int i;
BN_ULONG *tmp1 = _256_data;
const BN_ULONG *tmp2 = tmp1;
memcpy(tmp1, _nist_p_256, BN_NIST_256_TOP * sizeof(BN_ULONG));
tmp1 += BN_NIST_256_TOP;
for (i=0; i<5; i++)
{
bn_add_words(tmp1, _nist_p_256, tmp2, BN_NIST_256_TOP);
tmp2 = tmp1;
tmp1 += BN_NIST_256_TOP;
}
_is_set_256_data = 1;
}
#define BN_256_SET(d,a1,a2,a3,a4,a5,a6,a7,a8) \
{\
register BN_ULONG *td = (d);\
BN_CP_32_FROM_BUF(td,a8); BN_CP_32_FROM_BUF(td,a7);\
BN_CP_32_FROM_BUF(td,a6); BN_CP_32_FROM_BUF(td,a5);\
BN_CP_32_FROM_BUF(td,a4); BN_CP_32_FROM_BUF(td,a3);\
BN_CP_32_FROM_BUF(td,a2); BN_CP_32_FROM_BUF(td,a1);\
}
int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
BN_CTX *ctx)
{
#ifndef NO_32_BIT_TYPE
int tmp_int;
int carry = 0;
register BN_ULONG *a_d, *r_d;
BN_ULONG t_d[BN_NIST_256_TOP];
BN_ULONG t_d2[BN_NIST_256_TOP];
BN_32_BIT_BUF(8) BN_32_BIT_BUF(9)
BN_32_BIT_BUF(10) BN_32_BIT_BUF(11)
BN_32_BIT_BUF(12) BN_32_BIT_BUF(13)
BN_32_BIT_BUF(14) BN_32_BIT_BUF(15)
if (!_is_set_256_data)
{
CRYPTO_w_lock(CRYPTO_LOCK_BN);
if (!_is_set_256_data)
_init_256_data();
CRYPTO_w_unlock(CRYPTO_LOCK_BN);
}
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
return BN_zero(r);
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
if (r != a)
if (!BN_ncopy(r, a, BN_NIST_256_TOP))
return 0;
tmp_int = a->top-1;
a_d = a->d;
r_d = r->d;
switch (tmp_int)
{
BN_CASE_32_BIT(15, a_d)
BN_CASE_32_BIT(14, a_d)
BN_CASE_32_BIT(13, a_d)
BN_CASE_32_BIT(12, a_d)
BN_CASE_32_BIT(11, a_d)
BN_CASE_32_BIT(10, a_d)
BN_CASE_32_BIT(9, a_d)
BN_CASE_32_BIT(8, a_d)
break;
default: /* a->top == field->top */
return BN_usub(r, a, field);
}
/*S1*/
BN_256_SET(t_d,15,14,13,12,11,0,0,0)
/*S2*/
BN_256_SET(t_d2,0,15,14,13,12,0,0,0)
if (bn_add_words(t_d, t_d, t_d2, BN_NIST_256_TOP))
carry = 2;
/* left shift */
{
register BN_ULONG *ap,t,c;
ap = t_d;
c=0;
for (tmp_int=BN_NIST_256_TOP; tmp_int != 0; --tmp_int)
{
t= *ap;
*(ap++)=((t<<1)|c)&BN_MASK2;
c=(t & BN_TBIT)?1:0;
}
if (c)
++carry;
}
if (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))
++carry;
/*S3*/
BN_256_SET(t_d,15,14,0,0,0,10,9,8)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))
++carry;
/*S4*/
BN_256_SET(t_d,8,13,15,14,13,11,10,9)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))
++carry;
/*D1*/
BN_256_SET(t_d,10,8,0,0,0,13,12,11)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))
--carry;
/*D2*/
BN_256_SET(t_d,11,9,0,0,15,14,13,12)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))
--carry;
/*D3*/
BN_256_SET(t_d,12,0,10,9,8,15,14,13)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))
--carry;
/*D4*/
BN_256_SET(t_d,13,0,11,10,9,0,15,14)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))
--carry;
if (carry)
{
if (carry > 0)
bn_sub_words(r_d, r_d, _256_data + BN_NIST_256_TOP *
--carry, BN_NIST_256_TOP);
else
{
carry = -carry;
bn_add_words(r_d, r_d, _256_data + BN_NIST_256_TOP *
--carry, BN_NIST_256_TOP);
}
}
r->top = BN_NIST_256_TOP;
#if 1
bn_clear_top2max(r);
#endif
bn_fix_top(r);
if (BN_ucmp(r, field) >= 0)
{
bn_sub_words(r_d, r_d, _nist_p_256, BN_NIST_256_TOP);
bn_fix_top(r);
}
return 1;
#else
return 0;
#endif
}
static void _init_384_data(void)
{
int i;
BN_ULONG *tmp1 = _384_data;
const BN_ULONG *tmp2 = tmp1;
memcpy(tmp1, _nist_p_384, BN_NIST_384_TOP * sizeof(BN_ULONG));
tmp1 += BN_NIST_384_TOP;
for (i=0; i<7; i++)
{
bn_add_words(tmp1, _nist_p_384, tmp2, BN_NIST_384_TOP);
tmp2 = tmp1;
tmp1 += BN_NIST_384_TOP;
}
_is_set_384_data = 1;
}
#define BN_384_SET(d,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) \
{\
register BN_ULONG *td = (d);\
BN_CP_32_FROM_BUF(td,a12); BN_CP_32_FROM_BUF(td,a11);\
BN_CP_32_FROM_BUF(td,a10); BN_CP_32_FROM_BUF(td,a9);\
BN_CP_32_FROM_BUF(td,a8); BN_CP_32_FROM_BUF(td,a7);\
BN_CP_32_FROM_BUF(td,a6); BN_CP_32_FROM_BUF(td,a5);\
BN_CP_32_FROM_BUF(td,a4); BN_CP_32_FROM_BUF(td,a3);\
BN_CP_32_FROM_BUF(td,a2); BN_CP_32_FROM_BUF(td,a1);\
}
int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
BN_CTX *ctx)
{
#ifndef NO_32_BIT_TYPE
int tmp_int;
int carry = 0;
register BN_ULONG *r_d, *a_d;
BN_ULONG t_d[BN_NIST_384_TOP];
BN_32_BIT_BUF(12) BN_32_BIT_BUF(13)
BN_32_BIT_BUF(14) BN_32_BIT_BUF(15)
BN_32_BIT_BUF(16) BN_32_BIT_BUF(17)
BN_32_BIT_BUF(18) BN_32_BIT_BUF(19)
BN_32_BIT_BUF(20) BN_32_BIT_BUF(21)
BN_32_BIT_BUF(22) BN_32_BIT_BUF(23)
if (!_is_set_384_data)
{
CRYPTO_w_lock(CRYPTO_LOCK_BN);
if (!_is_set_384_data)
_init_384_data();
CRYPTO_w_unlock(CRYPTO_LOCK_BN);
}
tmp_int = BN_ucmp(field, a);
if (tmp_int == 0)
return BN_zero(r);
else if (tmp_int > 0)
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
if (r != a)
if (!BN_ncopy(r, a, BN_NIST_384_TOP))
return 0;
r_d = r->d;
a_d = a->d;
tmp_int = a->top-1;
switch (tmp_int)
{
BN_CASE_32_BIT(23, a_d)
BN_CASE_32_BIT(22, a_d)
BN_CASE_32_BIT(21, a_d)
BN_CASE_32_BIT(20, a_d)
BN_CASE_32_BIT(19, a_d)
BN_CASE_32_BIT(18, a_d)
BN_CASE_32_BIT(17, a_d)
BN_CASE_32_BIT(16, a_d)
BN_CASE_32_BIT(15, a_d)
BN_CASE_32_BIT(14, a_d)
BN_CASE_32_BIT(13, a_d)
BN_CASE_32_BIT(12, a_d)
break;
default: /* a->top == field->top */
return BN_usub(r, a, field);
}
/*S1*/
BN_256_SET(t_d,0,0,0,0,0,23,22,21)
/* left shift */
{
register BN_ULONG *ap,t,c;
ap = t_d;
c=0;
for (tmp_int=BN_NIST_256_TOP; tmp_int != 0; --tmp_int)
{
t= *ap;
*(ap++)=((t<<1)|c)&BN_MASK2;
c=(t & BN_TBIT)?1:0;
}
}
if (bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2),
t_d, BN_NIST_256_TOP))
++carry;
/*S2*/
BN_384_SET(t_d,23,22,21,20,19,18,17,16,15,14,13,12)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP))
++carry;
/*S3*/
BN_384_SET(t_d,20,19,18,17,16,15,14,13,12,23,22,21)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP))
++carry;
/*S4*/
BN_384_SET(t_d,19,18,17,16,15,14,13,12,20,0,23,0)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP))
++carry;
/*S5*/
BN_256_SET(t_d,0,0,0,0,23,22,21,20)
if (bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2),
t_d, BN_NIST_256_TOP))
++carry;
/*S6*/
BN_384_SET(t_d,0,0,0,0,0,0,23,22,21,0,0,20)
if (bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP))
++carry;
/*D1*/
BN_384_SET(t_d,22,21,20,19,18,17,16,15,14,13,12,23)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP))
--carry;
/*D2*/
BN_384_SET(t_d,0,0,0,0,0,0,0,23,22,21,20,0)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP))
--carry;
/*D3*/
BN_384_SET(t_d,0,0,0,0,0,0,0,23,23,0,0,0)
if (bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP))
--carry;
if (carry)
{
if (carry > 0)
bn_sub_words(r_d, r_d, _384_data + BN_NIST_384_TOP *
--carry, BN_NIST_384_TOP);
else
{
carry = -carry;
bn_add_words(r_d, r_d, _384_data + BN_NIST_384_TOP *
--carry, BN_NIST_384_TOP);
}
}
r->top = BN_NIST_384_TOP;
#if 1
bn_clear_top2max(r);
#endif
bn_fix_top(r);
if (BN_ucmp(r, field) >= 0)
{
bn_sub_words(r_d, r_d, _nist_p_384, BN_NIST_384_TOP);
bn_fix_top(r);
}
return 1;
#else
return 0;
#endif
}
int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
BN_CTX *ctx)
{
#if BN_BITS2 == 64
#define BN_NIST_521_TOP_MASK (BN_ULONG)0x1FF
#elif BN_BITS2 == 32
#define BN_NIST_521_TOP_MASK (BN_ULONG)0x1FF
#elif BN_BITS2 == 16
#define BN_NIST_521_TOP_MASK (BN_ULONG)0x1FF
#elif BN_BITS2 == 8
#define BN_NIST_521_TOP_MASK (BN_ULONG)0x1
#endif
int top, ret = 0;
BN_ULONG *r_d;
BIGNUM *tmp;
/* check whether a reduction is necessary */
top = a->top;
if (top < BN_NIST_521_TOP || ( top == BN_NIST_521_TOP &&
(!(a->d[BN_NIST_521_TOP-1] & ~(BN_NIST_521_TOP_MASK)))))
return (r == a)? 1 : (BN_copy(r ,a) != NULL);
BN_CTX_start(ctx);
tmp = BN_CTX_get(ctx);
if (!tmp)
goto err;
if (!BN_ncopy(tmp, a, BN_NIST_521_TOP))
return 0;
if (!BN_rshift(r, a, 521))
return 0;
if (tmp->top == BN_NIST_521_TOP)
tmp->d[BN_NIST_521_TOP-1] &= BN_NIST_521_TOP_MASK;
if (!BN_uadd(r, tmp, r))
return 0;
top = r->top;
r_d = r->d;
if (top == BN_NIST_521_TOP &&
(r_d[BN_NIST_521_TOP-1] & ~(BN_NIST_521_TOP_MASK)))
{
BN_NIST_ADD_ONE(r_d)
r_d[BN_NIST_521_TOP-1] &= BN_NIST_521_TOP_MASK;
}
bn_fix_top(r);
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}

View File

@ -230,7 +230,6 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
{
int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand;
int n;
int count = 100;
if (range->neg || BN_is_zero(range))
{
@ -264,13 +263,6 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
if (BN_cmp(r, range) >= 0)
if (!BN_sub(r, r, range)) return 0;
}
if (!--count)
{
BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);
return 0;
}
}
while (BN_cmp(r, range) >= 0);
}
@ -280,12 +272,6 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
{
/* range = 11..._2 or range = 101..._2 */
if (!bn_rand(r, n, -1, 0)) return 0;
if (!--count)
{
BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);
return 0;
}
}
while (BN_cmp(r, range) >= 0);
}

View File

@ -65,12 +65,14 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
* using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course
* in Algebraic Computational Number Theory", algorithm 1.5.1).
* 'p' must be prime!
* If 'a' is not a square, this is not necessarily detected by
* the algorithms; a bogus result must be expected in this case.
*/
{
BIGNUM *ret = in;
int err = 1;
int r;
BIGNUM *A, *b, *q, *t, *x, *y;
BIGNUM *b, *q, *t, *x, *y;
int e, i, j;
if (!BN_is_odd(p) || BN_abs_is_word(p, 1))
@ -107,8 +109,17 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
return ret;
}
#if 0 /* if BN_mod_sqrt is used with correct input, this just wastes time */
r = BN_kronecker(a, p, ctx);
if (r < -1) return NULL;
if (r == -1)
{
BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
return(NULL);
}
#endif
BN_CTX_start(ctx);
A = BN_CTX_get(ctx);
b = BN_CTX_get(ctx);
q = BN_CTX_get(ctx);
t = BN_CTX_get(ctx);
@ -120,9 +131,6 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
ret = BN_new();
if (ret == NULL) goto end;
/* A = a mod p */
if (!BN_nnmod(A, a, p, ctx)) goto end;
/* now write |p| - 1 as 2^e*q where q is odd */
e = 1;
while (!BN_is_bit_set(p, e))
@ -141,9 +149,9 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
if (!BN_rshift(q, p, 2)) goto end;
q->neg = 0;
if (!BN_add_word(q, 1)) goto end;
if (!BN_mod_exp(ret, A, q, p, ctx)) goto end;
if (!BN_mod_exp(ret, a, q, p, ctx)) goto end;
err = 0;
goto vrfy;
goto end;
}
if (e == 2)
@ -174,8 +182,15 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
* November 1992.)
*/
/* make sure that a is reduced modulo p */
if (a->neg || BN_ucmp(a, p) >= 0)
{
if (!BN_nnmod(x, a, p, ctx)) goto end;
a = x; /* use x as temporary variable */
}
/* t := 2*a */
if (!BN_mod_lshift1_quick(t, A, p)) goto end;
if (!BN_mod_lshift1_quick(t, a, p)) goto end;
/* b := (2*a)^((|p|-5)/8) */
if (!BN_rshift(q, p, 3)) goto end;
@ -190,12 +205,12 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
if (!BN_sub_word(t, 1)) goto end;
/* x = a*b*t */
if (!BN_mod_mul(x, A, b, p, ctx)) goto end;
if (!BN_mod_mul(x, a, b, p, ctx)) goto end;
if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
if (!BN_copy(ret, x)) goto end;
err = 0;
goto vrfy;
goto end;
}
/* e > 2, so we really have to use the Tonelli/Shanks algorithm.
@ -282,7 +297,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
/* x := a^((q-1)/2) */
if (BN_is_zero(t)) /* special case: p = 2^e + 1 */
{
if (!BN_nnmod(t, A, p, ctx)) goto end;
if (!BN_nnmod(t, a, p, ctx)) goto end;
if (BN_is_zero(t))
{
/* special case: a == 0 (mod p) */
@ -295,7 +310,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
}
else
{
if (!BN_mod_exp(x, A, t, p, ctx)) goto end;
if (!BN_mod_exp(x, a, t, p, ctx)) goto end;
if (BN_is_zero(x))
{
/* special case: a == 0 (mod p) */
@ -307,10 +322,10 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
/* b := a*x^2 (= a^q) */
if (!BN_mod_sqr(b, x, p, ctx)) goto end;
if (!BN_mod_mul(b, b, A, p, ctx)) goto end;
if (!BN_mod_mul(b, b, a, p, ctx)) goto end;
/* x := a*x (= a^((q+1)/2)) */
if (!BN_mod_mul(x, x, A, p, ctx)) goto end;
if (!BN_mod_mul(x, x, a, p, ctx)) goto end;
while (1)
{
@ -327,7 +342,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
{
if (!BN_copy(ret, x)) goto end;
err = 0;
goto vrfy;
goto end;
}
@ -358,22 +373,6 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
e = i;
}
vrfy:
if (!err)
{
/* verify the result -- the input might have been not a square
* (test added in 0.9.8) */
if (!BN_mod_sqr(x, ret, p, ctx))
err = 1;
if (!err && 0 != BN_cmp(x, A))
{
BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
err = 1;
}
}
end:
if (err)
{

View File

@ -55,19 +55,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the Eric Young open source
* license provided above.
*
* The binary polynomial arithmetic software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#include <stdio.h>
#include <stdlib.h>
@ -104,15 +91,6 @@ int test_mod(BIO *bp,BN_CTX *ctx);
int test_mod_mul(BIO *bp,BN_CTX *ctx);
int test_mod_exp(BIO *bp,BN_CTX *ctx);
int test_exp(BIO *bp,BN_CTX *ctx);
int test_gf2m_add(BIO *bp);
int test_gf2m_mod(BIO *bp);
int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx);
int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx);
int test_kron(BIO *bp,BN_CTX *ctx);
int test_sqrt(BIO *bp,BN_CTX *ctx);
int rand_neg(void);
@ -256,42 +234,6 @@ int main(int argc, char *argv[])
if (!test_sqrt(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_add");
if (!test_gf2m_add(out)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod");
if (!test_gf2m_mod(out)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_mul");
if (!test_gf2m_mod_mul(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_sqr");
if (!test_gf2m_mod_sqr(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_inv");
if (!test_gf2m_mod_inv(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_div");
if (!test_gf2m_mod_div(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_exp");
if (!test_gf2m_mod_exp(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_sqrt");
if (!test_gf2m_mod_sqrt(out,ctx)) goto err;
BIO_flush(out);
message(out,"BN_GF2m_mod_solve_quad");
if (!test_gf2m_mod_solve_quad(out,ctx)) goto err;
BIO_flush(out);
BN_CTX_free(ctx);
BIO_free(out);
@ -930,581 +872,6 @@ int test_exp(BIO *bp, BN_CTX *ctx)
return(1);
}
int test_gf2m_add(BIO *bp)
{
BIGNUM a,b,c;
int i, ret = 0;
BN_init(&a);
BN_init(&b);
BN_init(&c);
for (i=0; i<num0; i++)
{
BN_rand(&a,512,0,0);
BN_copy(&b, BN_value_one());
a.neg=rand_neg();
b.neg=rand_neg();
BN_GF2m_add(&c,&a,&b);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,&a);
BIO_puts(bp," ^ ");
BN_print(bp,&b);
BIO_puts(bp," = ");
}
BN_print(bp,&c);
BIO_puts(bp,"\n");
}
#endif
/* Test that two added values have the correct parity. */
if((BN_is_odd(&a) && BN_is_odd(&c)) || (!BN_is_odd(&a) && !BN_is_odd(&c)))
{
fprintf(stderr,"GF(2^m) addition test (a) failed!\n");
goto err;
}
BN_GF2m_add(&c,&c,&c);
/* Test that c + c = 0. */
if(!BN_is_zero(&c))
{
fprintf(stderr,"GF(2^m) addition test (b) failed!\n");
goto err;
}
}
ret = 1;
err:
BN_free(&a);
BN_free(&b);
BN_free(&c);
return ret;
}
int test_gf2m_mod(BIO *bp)
{
BIGNUM *a,*b[2],*c,*d,*e;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 1024, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod(c, a, b[j]);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp," % ");
BN_print(bp,b[j]);
BIO_puts(bp," - ");
BN_print(bp,c);
BIO_puts(bp,"\n");
}
}
#endif
BN_GF2m_add(d, a, c);
BN_GF2m_mod(e, d, b[j]);
/* Test that a + (a mod p) mod p == 0. */
if(!BN_is_zero(e))
{
fprintf(stderr,"GF(2^m) modulo test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
return ret;
}
int test_gf2m_mod_mul(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d,*e,*f,*g,*h;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
f=BN_new();
g=BN_new();
h=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 1024, 0, 0);
BN_bntest_rand(c, 1024, 0, 0);
BN_bntest_rand(d, 1024, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod_mul(e, a, c, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp," * ");
BN_print(bp,c);
BIO_puts(bp," % ");
BN_print(bp,b[j]);
BIO_puts(bp," - ");
BN_print(bp,e);
BIO_puts(bp,"\n");
}
}
#endif
BN_GF2m_add(f, a, d);
BN_GF2m_mod_mul(g, f, c, b[j], ctx);
BN_GF2m_mod_mul(h, d, c, b[j], ctx);
BN_GF2m_add(f, e, g);
BN_GF2m_add(f, f, h);
/* Test that (a+d)*c = a*c + d*c. */
if(!BN_is_zero(f))
{
fprintf(stderr,"GF(2^m) modular multiplication test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
BN_free(f);
BN_free(g);
BN_free(h);
return ret;
}
int test_gf2m_mod_sqr(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 1024, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod_sqr(c, a, b[j], ctx);
BN_copy(d, a);
BN_GF2m_mod_mul(d, a, d, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp," ^ 2 % ");
BN_print(bp,b[j]);
BIO_puts(bp, " = ");
BN_print(bp,c);
BIO_puts(bp,"; a * a = ");
BN_print(bp,d);
BIO_puts(bp,"\n");
}
}
#endif
BN_GF2m_add(d, c, d);
/* Test that a*a = a^2. */
if(!BN_is_zero(d))
{
fprintf(stderr,"GF(2^m) modular squaring test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
return ret;
}
int test_gf2m_mod_inv(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 512, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod_inv(c, a, b[j], ctx);
BN_GF2m_mod_mul(d, a, c, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp, " * ");
BN_print(bp,c);
BIO_puts(bp," - 1 % ");
BN_print(bp,b[j]);
BIO_puts(bp,"\n");
}
}
#endif
/* Test that ((1/a)*a) = 1. */
if(!BN_is_one(d))
{
fprintf(stderr,"GF(2^m) modular inversion test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
return ret;
}
int test_gf2m_mod_div(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d,*e,*f;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
f=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 512, 0, 0);
BN_bntest_rand(c, 512, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod_div(d, a, c, b[j], ctx);
BN_GF2m_mod_mul(e, d, c, b[j], ctx);
BN_GF2m_mod_div(f, a, e, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp, " = ");
BN_print(bp,c);
BIO_puts(bp," * ");
BN_print(bp,d);
BIO_puts(bp, " % ");
BN_print(bp,b[j]);
BIO_puts(bp,"\n");
}
}
#endif
/* Test that ((a/c)*c)/a = 1. */
if(!BN_is_one(f))
{
fprintf(stderr,"GF(2^m) modular division test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
BN_free(f);
return ret;
}
int test_gf2m_mod_exp(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d,*e,*f;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
f=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 512, 0, 0);
BN_bntest_rand(c, 512, 0, 0);
BN_bntest_rand(d, 512, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod_exp(e, a, c, b[j], ctx);
BN_GF2m_mod_exp(f, a, d, b[j], ctx);
BN_GF2m_mod_mul(e, e, f, b[j], ctx);
BN_add(f, c, d);
BN_GF2m_mod_exp(f, a, f, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp, " ^ (");
BN_print(bp,c);
BIO_puts(bp," + ");
BN_print(bp,d);
BIO_puts(bp, ") = ");
BN_print(bp,e);
BIO_puts(bp, "; - ");
BN_print(bp,f);
BIO_puts(bp, " % ");
BN_print(bp,b[j]);
BIO_puts(bp,"\n");
}
}
#endif
BN_GF2m_add(f, e, f);
/* Test that a^(c+d)=a^c*a^d. */
if(!BN_is_zero(f))
{
fprintf(stderr,"GF(2^m) modular exponentiation test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
BN_free(f);
return ret;
}
int test_gf2m_mod_sqrt(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d,*e,*f;
int i, j, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
f=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 512, 0, 0);
for (j=0; j < 2; j++)
{
BN_GF2m_mod(c, a, b[j]);
BN_GF2m_mod_sqrt(d, a, b[j], ctx);
BN_GF2m_mod_sqr(e, d, b[j], ctx);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,d);
BIO_puts(bp, " ^ 2 - ");
BN_print(bp,a);
BIO_puts(bp,"\n");
}
}
#endif
BN_GF2m_add(f, c, e);
/* Test that d^2 = a, where d = sqrt(a). */
if(!BN_is_zero(f))
{
fprintf(stderr,"GF(2^m) modular square root test failed!\n");
goto err;
}
}
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
BN_free(f);
return ret;
}
int test_gf2m_mod_solve_quad(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b[2],*c,*d,*e;
int i, j, s = 0, t, ret = 0;
unsigned int p0[] = {163,7,6,3,0};
unsigned int p1[] = {193,15,0};
a=BN_new();
b[0]=BN_new();
b[1]=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
BN_GF2m_arr2poly(p0, b[0]);
BN_GF2m_arr2poly(p1, b[1]);
for (i=0; i<num0; i++)
{
BN_bntest_rand(a, 512, 0, 0);
for (j=0; j < 2; j++)
{
t = BN_GF2m_mod_solve_quad(c, a, b[j], ctx);
if (t)
{
s++;
BN_GF2m_mod_sqr(d, c, b[j], ctx);
BN_GF2m_add(d, c, d);
BN_GF2m_mod(e, a, b[j]);
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BN_print(bp,c);
BIO_puts(bp, " is root of z^2 + z = ");
BN_print(bp,a);
BIO_puts(bp, " % ");
BN_print(bp,b[j]);
BIO_puts(bp, "\n");
}
}
#endif
BN_GF2m_add(e, e, d);
/* Test that solution of quadratic c satisfies c^2 + c = a. */
if(!BN_is_zero(e))
{
fprintf(stderr,"GF(2^m) modular solve quadratic test failed!\n");
goto err;
}
}
else
{
#if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */
if (bp != NULL)
{
if (!results)
{
BIO_puts(bp, "There are no roots of z^2 + z = ");
BN_print(bp,a);
BIO_puts(bp, " % ");
BN_print(bp,b[j]);
BIO_puts(bp, "\n");
}
}
#endif
}
}
}
if (s == 0)
{
fprintf(stderr,"All %i tests of GF(2^m) modular solve quadratic resulted in no roots;\n", num0);
fprintf(stderr,"this is very unlikely and probably indicates an error.\n");
goto err;
}
ret = 1;
err:
BN_free(a);
BN_free(b[0]);
BN_free(b[1]);
BN_free(c);
BN_free(d);
BN_free(e);
return ret;
}
static void genprime_cb(int p, int n, void *arg)
{
char c='*';

View File

@ -86,32 +86,31 @@ conf_api.o: ../../e_os.h ../../include/openssl/bio.h
conf_api.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
conf_api.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_api.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
conf_api.o: ../../include/openssl/symhacks.h conf_api.c
conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
conf_api.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
conf_api.o: conf_api.c
conf_def.o: ../../e_os.h ../../include/openssl/bio.h
conf_def.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
conf_def.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
conf_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
conf_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_def.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
conf_def.o: ../../include/openssl/symhacks.h ../cryptlib.h conf_def.c
conf_def.o: conf_def.h
conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
conf_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
conf_def.o: ../cryptlib.h conf_def.c conf_def.h
conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
conf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
conf_err.o: ../../include/openssl/opensslconf.h
conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
conf_err.o: ../../include/openssl/symhacks.h conf_err.c
conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
conf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
conf_err.o: conf_err.c
conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
conf_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
conf_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
conf_lib.o: ../../include/openssl/symhacks.h conf_lib.c
conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
conf_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
conf_lib.o: conf_lib.c
conf_mall.o: ../../e_os.h ../../include/openssl/aes.h
conf_mall.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
conf_mall.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
@ -120,13 +119,12 @@ conf_mall.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
conf_mall.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
conf_mall.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
conf_mall.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
conf_mall.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
conf_mall.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
conf_mall.o: ../../include/openssl/err.h ../../include/openssl/evp.h
conf_mall.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
conf_mall.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
conf_mall.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
conf_mall.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
conf_mall.o: ../../include/openssl/engine.h ../../include/openssl/err.h
conf_mall.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
conf_mall.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
conf_mall.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
conf_mall.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
conf_mall.o: ../../include/openssl/objects.h
conf_mall.o: ../../include/openssl/opensslconf.h
conf_mall.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_mall.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
@ -145,13 +143,12 @@ conf_mod.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
conf_mod.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
conf_mod.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
conf_mod.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
conf_mod.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
conf_mod.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
conf_mod.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
conf_mod.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
conf_mod.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
conf_mod.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
conf_mod.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
conf_mod.o: ../../include/openssl/err.h ../../include/openssl/evp.h
conf_mod.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
conf_mod.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
conf_mod.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
conf_mod.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
conf_mod.o: ../../include/openssl/opensslconf.h
conf_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_mod.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
conf_mod.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
@ -169,14 +166,12 @@ conf_sap.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
conf_sap.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
conf_sap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
conf_sap.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
conf_sap.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
conf_sap.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
conf_sap.o: ../../include/openssl/err.h ../../include/openssl/evp.h
conf_sap.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
conf_sap.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
conf_sap.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
conf_sap.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
conf_sap.o: ../../include/openssl/opensslconf.h
conf_sap.o: ../../include/openssl/engine.h ../../include/openssl/err.h
conf_sap.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
conf_sap.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
conf_sap.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
conf_sap.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
conf_sap.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
conf_sap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
conf_sap.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
conf_sap.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h

View File

@ -65,8 +65,6 @@
#include <openssl/safestack.h>
#include <openssl/e_os2.h>
#include <openssl/ossl_typ.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -83,6 +81,7 @@ DECLARE_STACK_OF(CONF_MODULE)
DECLARE_STACK_OF(CONF_IMODULE)
struct conf_st;
typedef struct conf_st CONF;
struct conf_method_st;
typedef struct conf_method_st CONF_METHOD;

View File

@ -1,57 +1,4 @@
/* crypto/cryptlib.c */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -108,11 +55,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* ECDH support in OpenSSL originally developed by
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#include <stdio.h>
#include <string.h>
@ -162,11 +104,7 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] =
"dynlock",
"engine",
"ui",
"ecdsa",
"ec",
"ecdh",
"bn",
#if CRYPTO_NUM_LOCKS != 36
#if CRYPTO_NUM_LOCKS != 32
# error "Inconsistency between crypto.h and cryptlib.c"
#endif
};

View File

@ -77,7 +77,7 @@ $! Define The Different Encryption Types.
$!
$ ENCRYPT_TYPES = "Basic,MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
"DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
"BN,EC,RSA,DSA,ECDSA,DH,ECDH,DSO,ENGINE,AES,"+ -
"BN,EC,RSA,DSA,DH,DSO,ENGINE,AES,"+ -
"BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
"EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
"CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,UI,KRB5"
@ -184,23 +184,22 @@ $ IF F$TRNLNM("OPENSSL_NO_ASM").OR.ARCH.EQS."AXP" THEN LIB_BN_ASM = "bn_asm"
$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_ctx,bn_mul,bn_mod,"+ -
"bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
"bn_kron,bn_sqrt,bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+","+ -
"bn_recp,bn_mont,bn_mpi,bn_exp2,bn_gf2m,bn_nist"
$ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_recp,ecp_nist,ec_cvt,ec_mult,"+ -
"ec_err,ec_curve,ec_check,ec_print,ec_asn1,ec_key,"+ -
"ec2_smpl,ec2_mult"
"bn_recp,bn_mont,bn_mpi,bn_exp2"
$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
"rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk,rsa_null,"+ -
"rsa_asn1"
$ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_recp,ecp_nist,ec_cvt,ec_mult,"+ -
"ec_err"
$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err,dsa_ossl"
$ LIB_ECDSA = "ecs_lib,ecs_asn1,ecs_ossl,ecs_sign,ecs_vrf,ecs_err"
$ LIB_DH = "dh_asn1,dh_gen,dh_key,dh_lib,dh_check,dh_err"
$ LIB_ECDH = "ech_lib,ech_ossl,ech_key,ech_err"
$ LIB_DSO = "dso_dl,dso_dlfcn,dso_err,dso_lib,dso_null,"+ -
"dso_openssl,dso_win32,dso_vms"
$ LIB_ENGINE = "eng_err,eng_lib,eng_list,eng_init,eng_ctrl,"+ -
"eng_table,eng_pkey,eng_fat,eng_all,"+ -
"tb_rsa,tb_dsa,tb_ecdsa,tb_dh,tb_rand,tb_cipher,tb_digest,tb_ecdh,"+ -
"eng_openssl,eng_dyn,eng_cnf,eng_cryptodev"
"tb_rsa,tb_dsa,tb_dh,tb_rand,tb_cipher,tb_digest,"+ -
"eng_openssl,eng_dyn,eng_cnf,"+ -
"hw_atalla,hw_cswift,hw_ncipher,hw_nuron,hw_ubsec,"+ -
"hw_cryptodev,hw_aep,hw_sureware,hw_4758_cca"
$ LIB_AES = "aes_core,aes_misc,aes_ecb,aes_cbc,aes_cfb,aes_ofb,aes_ctr"
$ LIB_BUFFER = "buffer,buf_err"
$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
@ -220,7 +219,7 @@ $ LIB_EVP = "encode,digest,evp_enc,evp_key,evp_acnf,"+ -
"e_rc4,e_aes,names,"+ -
"e_xcbc_d,e_rc2,e_cast,e_rc5"
$ LIB_EVP_2 = "m_null,m_md2,m_md4,m_md5,m_sha,m_sha1," + -
"m_dss,m_dss1,m_mdc2,m_ripemd,m_ecdsa,"+ -
"m_dss,m_dss1,m_mdc2,m_ripemd,"+ -
"p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
"bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
"c_all,c_allc,c_alld,evp_lib,bio_ok,"+-
@ -235,7 +234,7 @@ $ LIB_ASN1_2 = "t_req,t_x509,t_x509a,t_crl,t_pkey,t_spki,t_bitst,"+ -
"tasn_new,tasn_fre,tasn_enc,tasn_dec,tasn_utl,tasn_typ,"+ -
"f_int,f_string,n_pkey,"+ -
"f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
"asn1_gen,asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,a_strnid,"+ -
"asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,a_strnid,"+ -
"evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey,asn_moid"
$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err,"+ -
"pem_x509,pem_xaux,pem_oth,pem_pk8,pem_pkey"

View File

@ -1,57 +1,4 @@
/* crypto/crypto.h */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -108,11 +55,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* ECDH support in OpenSSL originally developed by
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#ifndef HEADER_CRYPTO_H
#define HEADER_CRYPTO_H
@ -157,11 +99,11 @@ extern "C" {
* names in cryptlib.c
*/
#define CRYPTO_LOCK_ERR 1
#define CRYPTO_LOCK_EX_DATA 2
#define CRYPTO_LOCK_X509 3
#define CRYPTO_LOCK_X509_INFO 4
#define CRYPTO_LOCK_X509_PKEY 5
#define CRYPTO_LOCK_ERR 1
#define CRYPTO_LOCK_EX_DATA 2
#define CRYPTO_LOCK_X509 3
#define CRYPTO_LOCK_X509_INFO 4
#define CRYPTO_LOCK_X509_PKEY 5
#define CRYPTO_LOCK_X509_CRL 6
#define CRYPTO_LOCK_X509_REQ 7
#define CRYPTO_LOCK_DSA 8
@ -188,11 +130,7 @@ extern "C" {
#define CRYPTO_LOCK_DYNLOCK 29
#define CRYPTO_LOCK_ENGINE 30
#define CRYPTO_LOCK_UI 31
#define CRYPTO_LOCK_ECDSA 32
#define CRYPTO_LOCK_EC 33
#define CRYPTO_LOCK_ECDH 34
#define CRYPTO_LOCK_BN 35
#define CRYPTO_NUM_LOCKS 36
#define CRYPTO_NUM_LOCKS 32
#define CRYPTO_LOCK 1
#define CRYPTO_UNLOCK 2
@ -299,8 +237,6 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
#define CRYPTO_EX_INDEX_ENGINE 9
#define CRYPTO_EX_INDEX_X509 10
#define CRYPTO_EX_INDEX_UI 11
#define CRYPTO_EX_INDEX_ECDSA 12
#define CRYPTO_EX_INDEX_ECDH 13
/* Dynamically assigned indexes start from this value (don't use directly, use
* via CRYPTO_ex_data_new_class). */

View File

@ -69,7 +69,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef OPENSSL_SYS_MSDOS
#if !defined(OPENSSL_SYS_VMS) || defined(__DECC)
@ -90,6 +89,10 @@
#include <io.h>
#endif
#if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS)
#include <string.h>
#endif
#ifdef OPENSSL_BUILD_SHLIBCRYPTO
# undef OPENSSL_EXTERN
# define OPENSSL_EXTERN OPENSSL_EXPORT

View File

@ -116,23 +116,21 @@ dh_key.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
dh_key.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
dh_key.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
dh_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
dh_key.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
dh_key.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
dh_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
dh_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
dh_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
dh_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
dh_key.o: ../../include/openssl/ui.h ../cryptlib.h dh_key.c
dh_key.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dh_key.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dh_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dh_key.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dh_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
dh_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
dh_key.o: ../cryptlib.h dh_key.c
dh_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
dh_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
dh_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
dh_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
dh_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
dh_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
dh_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
dh_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
dh_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
dh_lib.o: ../../include/openssl/ui.h ../cryptlib.h dh_lib.c
dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dh_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
dh_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
dh_lib.o: ../cryptlib.h dh_lib.c

View File

@ -132,23 +132,20 @@ dsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
dsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
dsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
dsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
dsa_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
dsa_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dsa_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dsa_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dsa_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
dsa_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
dsa_lib.o: ../cryptlib.h dsa_lib.c
dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
dsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
dsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
dsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
dsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
dsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h dsa_lib.c
dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
dsa_ossl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
dsa_ossl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
dsa_ossl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dsa_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
dsa_ossl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dsa_ossl.o: ../../include/openssl/opensslconf.h
dsa_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dsa_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
@ -158,10 +155,9 @@ dsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
dsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
dsa_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
dsa_sign.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dsa_sign.o: ../../include/openssl/opensslconf.h
dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
@ -172,11 +168,10 @@ dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
dsa_vrf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
dsa_vrf.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
dsa_vrf.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
dsa_vrf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
dsa_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
dsa_vrf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
dsa_vrf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
dsa_vrf.o: ../../include/openssl/ui.h ../cryptlib.h dsa_vrf.c
dsa_vrf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
dsa_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
dsa_vrf.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
dsa_vrf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
dsa_vrf.o: ../cryptlib.h dsa_vrf.c

View File

@ -246,14 +246,12 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
BN_init(&u2);
BN_init(&t1);
if (BN_is_zero(sig->r) || BN_get_sign(sig->r) ||
BN_ucmp(sig->r, dsa->q) >= 0)
if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
{
ret = 0;
goto err;
}
if (BN_is_zero(sig->s) || BN_get_sign(sig->s) ||
BN_ucmp(sig->s, dsa->q) >= 0)
if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
{
ret = 0;
goto err;

View File

@ -1,4 +1,4 @@
/* dso.h -*- mode:C; c-file-style: "eay" -*- */
/* dso.h */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@ -107,22 +107,6 @@ typedef struct dso_st DSO;
* condition) or a newly allocated string containing the transformed form that
* the caller will need to free with OPENSSL_free() when done. */
typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
/* The function prototype used for method functions (or caller-provided
* callbacks) that merge two file specifications. They are passed a
* DSO structure pointer (or NULL if they are to be used independantly of
* a DSO object) and two file specifications to merge. They should
* either return NULL (if there is an error condition) or a newly allocated
* string containing the result of merging that the caller will need
* to free with OPENSSL_free() when done.
* Here, merging means that bits and pieces are taken from each of the
* file specifications and added together in whatever fashion that is
* sensible for the DSO method in question. The only rule that really
* applies is that if the two specification contain pieces of the same
* type, the copy from the string string takes priority. One could see
* it as the first specification is the one given by the user and the
* second being a bunch of defaults to add on if they're missing in the
* first. */
typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *);
typedef struct dso_meth_st
{
@ -156,9 +140,6 @@ typedef struct dso_meth_st
/* The default DSO_METHOD-specific function for converting filenames to
* a canonical native form. */
DSO_NAME_CONVERTER_FUNC dso_name_converter;
/* The default DSO_METHOD-specific function for converting filenames to
* a canonical native form. */
DSO_MERGER_FUNC dso_merger;
/* [De]Initialisation handlers. */
int (*init)(DSO *dso);
@ -183,13 +164,9 @@ struct dso_st
* don't touch meth_data! */
CRYPTO_EX_DATA ex_data;
/* If this callback function pointer is set to non-NULL, then it will
* be used in DSO_load() in place of meth->dso_name_converter. NB: This
* be used on DSO_load() in place of meth->dso_name_converter. NB: This
* should normally set using DSO_set_name_converter(). */
DSO_NAME_CONVERTER_FUNC name_converter;
/* If this callback function pointer is set to non-NULL, then it will
* be used in DSO_load() in place of meth->dso_merger. NB: This
* should normally set using DSO_set_merger(). */
DSO_MERGER_FUNC merger;
/* This is populated with (a copy of) the platform-independant
* filename used for this DSO. */
char *filename;
@ -232,11 +209,6 @@ int DSO_set_filename(DSO *dso, const char *filename);
* caller-created DSO_METHODs can do the same thing. A non-NULL return value
* will need to be OPENSSL_free()'d. */
char *DSO_convert_filename(DSO *dso, const char *filename);
/* This function will invoke the DSO's merger callback to merge two file
* specifications, or if the callback isn't set it will instead use the
* DSO_METHOD's merger. A non-NULL return value will need to be
* OPENSSL_free()'d. */
char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2);
/* If the DSO is currently loaded, this returns the filename that it was loaded
* under, otherwise it returns NULL. So it is also useful as a test as to
* whether the DSO is currently loaded. NB: This will not necessarily return
@ -301,13 +273,11 @@ void ERR_load_DSO_strings(void);
#define DSO_F_DLFCN_BIND_FUNC 100
#define DSO_F_DLFCN_BIND_VAR 101
#define DSO_F_DLFCN_LOAD 102
#define DSO_F_DLFCN_MERGER 130
#define DSO_F_DLFCN_NAME_CONVERTER 123
#define DSO_F_DLFCN_UNLOAD 103
#define DSO_F_DL_BIND_FUNC 104
#define DSO_F_DL_BIND_VAR 105
#define DSO_F_DL_LOAD 106
#define DSO_F_DL_MERGER 131
#define DSO_F_DL_NAME_CONVERTER 124
#define DSO_F_DL_UNLOAD 107
#define DSO_F_DSO_BIND_FUNC 108
@ -318,34 +288,27 @@ void ERR_load_DSO_strings(void);
#define DSO_F_DSO_GET_FILENAME 127
#define DSO_F_DSO_GET_LOADED_FILENAME 128
#define DSO_F_DSO_LOAD 112
#define DSO_F_DSO_MERGE 132
#define DSO_F_DSO_NEW_METHOD 113
#define DSO_F_DSO_SET_FILENAME 129
#define DSO_F_DSO_SET_NAME_CONVERTER 122
#define DSO_F_DSO_UP_REF 114
#define DSO_F_VMS_BIND_VAR 115
#define DSO_F_VMS_LOAD 116
#define DSO_F_VMS_MERGER 133
#define DSO_F_VMS_UNLOAD 117
#define DSO_F_WIN32_BIND_FUNC 118
#define DSO_F_WIN32_BIND_VAR 119
#define DSO_F_WIN32_LOAD 120
#define DSO_F_WIN32_MERGER 134
#define DSO_F_WIN32_NAME_CONVERTER 125
#define DSO_F_WIN32_UNLOAD 121
/* Reason codes. */
#define DSO_R_CTRL_FAILED 100
#define DSO_R_DSO_ALREADY_LOADED 110
#define DSO_R_EMPTY_FILE_STRUCTURE 113
#define DSO_R_FAILURE 114
#define DSO_R_FILENAME_TOO_BIG 101
#define DSO_R_FINISH_FAILED 102
#define DSO_R_INCORRECT_FILE_SYNTAX 115
#define DSO_R_LOAD_FAILED 103
#define DSO_R_NAME_TRANSLATION_FAILED 109
#define DSO_R_NO_FILENAME 111
#define DSO_R_NO_FILE_SPECIFICATION 116
#define DSO_R_NULL_HANDLE 104
#define DSO_R_SET_FILENAME_FAILED 112
#define DSO_R_STACK_ERROR 105

View File

@ -1,4 +1,4 @@
/* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */
/* dso_dl.c */
/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
* project 2000.
*/
@ -84,7 +84,6 @@ static int dl_finish(DSO *dso);
static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
#endif
static char *dl_name_converter(DSO *dso, const char *filename);
static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2);
static DSO_METHOD dso_meth_dl = {
"OpenSSL 'dl' shared library method",
@ -99,7 +98,6 @@ static DSO_METHOD dso_meth_dl = {
#endif
NULL, /* ctrl */
dl_name_converter,
dl_merger,
NULL, /* init */
NULL /* finish */
};
@ -240,72 +238,6 @@ static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
return((DSO_FUNC_TYPE)sym);
}
static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2)
{
char *merged;
if(!filespec1 && !filespec2)
{
DSOerr(DSO_F_DL_MERGER,
ERR_R_PASSED_NULL_PARAMETER);
return(NULL);
}
/* If the first file specification is a rooted path, it rules.
same goes if the second file specification is missing. */
if (!filespec2 || filespec1[0] == '/')
{
merged = OPENSSL_malloc(strlen(filespec1) + 1);
if(!merged)
{
DSOerr(DSO_F_DL_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec1);
}
/* If the first file specification is missing, the second one rules. */
else if (!filespec1)
{
merged = OPENSSL_malloc(strlen(filespec2) + 1);
if(!merged)
{
DSOerr(DSO_F_DL_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec2);
}
else
/* This part isn't as trivial as it looks. It assumes that
the second file specification really is a directory, and
makes no checks whatsoever. Therefore, the result becomes
the concatenation of filespec2 followed by a slash followed
by filespec1. */
{
int spec2len, len;
spec2len = (filespec2 ? strlen(filespec2) : 0);
len = spec2len + (filespec1 ? strlen(filespec1) : 0);
if(filespec2 && filespec2[spec2len - 1] == '/')
{
spec2len--;
len--;
}
merged = OPENSSL_malloc(len + 2);
if(!merged)
{
DSOerr(DSO_F_DL_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec2);
merged[spec2len] = '/';
strcpy(&merged[spec2len + 1], filespec1);
}
return(merged);
}
/* This function is identical to the one in dso_dlfcn.c, but as it is highly
* unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the
* same time, there's no great duplicating the code. Figuring out an elegant

View File

@ -1,4 +1,4 @@
/* dso_dlfcn.c -*- mode:C; c-file-style: "eay" -*- */
/* dso_dlfcn.c */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@ -85,8 +85,6 @@ static int dlfcn_finish(DSO *dso);
static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
#endif
static char *dlfcn_name_converter(DSO *dso, const char *filename);
static char *dlfcn_merger(DSO *dso, const char *filespec1,
const char *filespec2);
static DSO_METHOD dso_meth_dlfcn = {
"OpenSSL 'dlfcn' shared library method",
@ -101,7 +99,6 @@ static DSO_METHOD dso_meth_dlfcn = {
#endif
NULL, /* ctrl */
dlfcn_name_converter,
dlfcn_merger,
NULL, /* init */
NULL /* finish */
};
@ -255,73 +252,6 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
return(sym);
}
static char *dlfcn_merger(DSO *dso, const char *filespec1,
const char *filespec2)
{
char *merged;
if(!filespec1 && !filespec2)
{
DSOerr(DSO_F_DLFCN_MERGER,
ERR_R_PASSED_NULL_PARAMETER);
return(NULL);
}
/* If the first file specification is a rooted path, it rules.
same goes if the second file specification is missing. */
if (!filespec2 || filespec1[0] == '/')
{
merged = OPENSSL_malloc(strlen(filespec1) + 1);
if(!merged)
{
DSOerr(DSO_F_DLFCN_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec1);
}
/* If the first file specification is missing, the second one rules. */
else if (!filespec1)
{
merged = OPENSSL_malloc(strlen(filespec2) + 1);
if(!merged)
{
DSOerr(DSO_F_DLFCN_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec2);
}
else
/* This part isn't as trivial as it looks. It assumes that
the second file specification really is a directory, and
makes no checks whatsoever. Therefore, the result becomes
the concatenation of filespec2 followed by a slash followed
by filespec1. */
{
int spec2len, len;
spec2len = (filespec2 ? strlen(filespec2) : 0);
len = spec2len + (filespec1 ? strlen(filespec1) : 0);
if(filespec2 && filespec2[spec2len - 1] == '/')
{
spec2len--;
len--;
}
merged = OPENSSL_malloc(len + 2);
if(!merged)
{
DSOerr(DSO_F_DLFCN_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec2);
merged[spec2len] = '/';
strcpy(&merged[spec2len + 1], filespec1);
}
return(merged);
}
static char *dlfcn_name_converter(DSO *dso, const char *filename)
{
char *translated;

View File

@ -1,6 +1,6 @@
/* crypto/dso/dso_err.c */
/* ====================================================================
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
* 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
@ -69,13 +69,11 @@ static ERR_STRING_DATA DSO_str_functs[]=
{ERR_PACK(0,DSO_F_DLFCN_BIND_FUNC,0), "DLFCN_BIND_FUNC"},
{ERR_PACK(0,DSO_F_DLFCN_BIND_VAR,0), "DLFCN_BIND_VAR"},
{ERR_PACK(0,DSO_F_DLFCN_LOAD,0), "DLFCN_LOAD"},
{ERR_PACK(0,DSO_F_DLFCN_MERGER,0), "DLFCN_MERGER"},
{ERR_PACK(0,DSO_F_DLFCN_NAME_CONVERTER,0), "DLFCN_NAME_CONVERTER"},
{ERR_PACK(0,DSO_F_DLFCN_UNLOAD,0), "DLFCN_UNLOAD"},
{ERR_PACK(0,DSO_F_DL_BIND_FUNC,0), "DL_BIND_FUNC"},
{ERR_PACK(0,DSO_F_DL_BIND_VAR,0), "DL_BIND_VAR"},
{ERR_PACK(0,DSO_F_DL_LOAD,0), "DL_LOAD"},
{ERR_PACK(0,DSO_F_DL_MERGER,0), "DL_MERGER"},
{ERR_PACK(0,DSO_F_DL_NAME_CONVERTER,0), "DL_NAME_CONVERTER"},
{ERR_PACK(0,DSO_F_DL_UNLOAD,0), "DL_UNLOAD"},
{ERR_PACK(0,DSO_F_DSO_BIND_FUNC,0), "DSO_bind_func"},
@ -86,19 +84,16 @@ static ERR_STRING_DATA DSO_str_functs[]=
{ERR_PACK(0,DSO_F_DSO_GET_FILENAME,0), "DSO_get_filename"},
{ERR_PACK(0,DSO_F_DSO_GET_LOADED_FILENAME,0), "DSO_get_loaded_filename"},
{ERR_PACK(0,DSO_F_DSO_LOAD,0), "DSO_load"},
{ERR_PACK(0,DSO_F_DSO_MERGE,0), "DSO_merge"},
{ERR_PACK(0,DSO_F_DSO_NEW_METHOD,0), "DSO_new_method"},
{ERR_PACK(0,DSO_F_DSO_SET_FILENAME,0), "DSO_set_filename"},
{ERR_PACK(0,DSO_F_DSO_SET_NAME_CONVERTER,0), "DSO_set_name_converter"},
{ERR_PACK(0,DSO_F_DSO_UP_REF,0), "DSO_up_ref"},
{ERR_PACK(0,DSO_F_VMS_BIND_VAR,0), "VMS_BIND_VAR"},
{ERR_PACK(0,DSO_F_VMS_LOAD,0), "VMS_LOAD"},
{ERR_PACK(0,DSO_F_VMS_MERGER,0), "VMS_MERGER"},
{ERR_PACK(0,DSO_F_VMS_UNLOAD,0), "VMS_UNLOAD"},
{ERR_PACK(0,DSO_F_WIN32_BIND_FUNC,0), "WIN32_BIND_FUNC"},
{ERR_PACK(0,DSO_F_WIN32_BIND_VAR,0), "WIN32_BIND_VAR"},
{ERR_PACK(0,DSO_F_WIN32_LOAD,0), "WIN32_LOAD"},
{ERR_PACK(0,DSO_F_WIN32_MERGER,0), "WIN32_MERGER"},
{ERR_PACK(0,DSO_F_WIN32_NAME_CONVERTER,0), "WIN32_NAME_CONVERTER"},
{ERR_PACK(0,DSO_F_WIN32_UNLOAD,0), "WIN32_UNLOAD"},
{0,NULL}
@ -108,15 +103,11 @@ static ERR_STRING_DATA DSO_str_reasons[]=
{
{DSO_R_CTRL_FAILED ,"control command failed"},
{DSO_R_DSO_ALREADY_LOADED ,"dso already loaded"},
{DSO_R_EMPTY_FILE_STRUCTURE ,"empty file structure"},
{DSO_R_FAILURE ,"failure"},
{DSO_R_FILENAME_TOO_BIG ,"filename too big"},
{DSO_R_FINISH_FAILED ,"cleanup method function failed"},
{DSO_R_INCORRECT_FILE_SYNTAX ,"incorrect file syntax"},
{DSO_R_LOAD_FAILED ,"could not load the shared library"},
{DSO_R_NAME_TRANSLATION_FAILED ,"name translation failed"},
{DSO_R_NO_FILENAME ,"no filename"},
{DSO_R_NO_FILE_SPECIFICATION ,"no file specification"},
{DSO_R_NULL_HANDLE ,"a null shared library handle was used"},
{DSO_R_SET_FILENAME_FAILED ,"set filename failed"},
{DSO_R_STACK_ERROR ,"the meth_data stack is corrupt"},

View File

@ -1,4 +1,4 @@
/* dso_lib.c -*- mode:C; c-file-style: "eay" -*- */
/* dso_lib.c */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@ -390,33 +390,6 @@ int DSO_set_filename(DSO *dso, const char *filename)
return(1);
}
char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
{
char *result = NULL;
if(dso == NULL || filespec1 == NULL)
{
DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
return(NULL);
}
if(filespec1 == NULL)
filespec1 = dso->filename;
if(filespec1 == NULL)
{
DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
return(NULL);
}
if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
{
if(dso->merger != NULL)
result = dso->merger(dso, filespec1, filespec2);
else if(dso->meth->dso_merger != NULL)
result = dso->meth->dso_merger(dso,
filespec1, filespec2);
}
return(result);
}
char *DSO_convert_filename(DSO *dso, const char *filename)
{
char *result = NULL;

View File

@ -1,4 +1,4 @@
/* dso_vms.c -*- mode:C; c-file-style: "eay" -*- */
/* dso_vms.c */
/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
* project 2000.
*/
@ -63,7 +63,6 @@
#include <openssl/dso.h>
#ifdef OPENSSL_SYS_VMS
#pragma message disable DOLLARID
#include <rms.h>
#include <lib$routines.h>
#include <stsdef.h>
#include <descrip.h>
@ -90,8 +89,6 @@ static int vms_finish(DSO *dso);
static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
#endif
static char *vms_name_converter(DSO *dso, const char *filename);
static char *vms_merger(DSO *dso, const char *filespec1,
const char *filespec2);
static DSO_METHOD dso_meth_vms = {
"OpenSSL 'VMS' shared library method",
@ -106,7 +103,6 @@ static DSO_METHOD dso_meth_vms = {
#endif
NULL, /* ctrl */
vms_name_converter,
vms_merger,
NULL, /* init */
NULL /* finish */
};
@ -372,127 +368,6 @@ static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
return sym;
}
static char *vms_merger(DSO *dso, const char *filespec1, const char *filespec2)
{
int status;
int filespec1len, filespec2len;
struct FAB fab;
#ifdef NAML$C_MAXRSS
struct NAML nam;
char esa[NAML$C_MAXRSS];
#else
struct NAM nam;
char esa[NAM$C_MAXRSS];
#endif
char *merged;
if (!filespec1) filespec1 = "";
if (!filespec2) filespec2 = "";
filespec1len = strlen(filespec1);
filespec2len = strlen(filespec2);
fab = cc$rms_fab;
#ifdef NAML$C_MAXRSS
nam = cc$rms_naml;
#else
nam = cc$rms_nam;
#endif
fab.fab$l_fna = (char *)filespec1;
fab.fab$b_fns = filespec1len;
fab.fab$l_dna = (char *)filespec2;
fab.fab$b_dns = filespec2len;
#ifdef NAML$C_MAXRSS
if (filespec1len > NAM$C_MAXRSS)
{
fab.fab$l_fna = 0;
fab.fab$b_fns = 0;
nam.naml$l_long_filename = (char *)filespec1;
nam.naml$l_long_filename_size = filespec1len;
}
if (filespec2len > NAM$C_MAXRSS)
{
fab.fab$l_dna = 0;
fab.fab$b_dns = 0;
nam.naml$l_long_defname = (char *)filespec2;
nam.naml$l_long_defname_size = filespec2len;
}
nam.naml$l_esa = esa;
nam.naml$b_ess = NAM$C_MAXRSS;
nam.naml$l_long_expand = esa;
nam.naml$l_long_expand_alloc = sizeof(esa);
nam.naml$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
nam.naml$v_no_short_upcase = 1;
fab.fab$l_naml = &nam;
#else
nam.nam$l_esa = esa;
nam.nam$b_ess = NAM$C_MAXRSS;
nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
fab.fab$l_nam = &nam;
#endif
status = sys$parse(&fab, 0, 0);
if(!$VMS_STATUS_SUCCESS(status))
{
unsigned short length;
char errstring[257];
struct dsc$descriptor_s errstring_dsc;
errstring_dsc.dsc$w_length = sizeof(errstring);
errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
errstring_dsc.dsc$a_pointer = errstring;
status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
if (!$VMS_STATUS_SUCCESS(status))
lib$signal(status); /* This is really bad. Abort! */
else
{
errstring[length] = '\0';
DSOerr(DSO_F_VMS_MERGER,DSO_R_FAILURE);
ERR_add_error_data(7,
"filespec \"", filespec1, "\", ",
"defaults \"", filespec2, "\": ",
errstring);
}
return(NULL);
}
#ifdef NAML$C_MAXRSS
if (nam.naml$l_long_expand_size)
{
merged = OPENSSL_malloc(nam.naml$l_long_expand_size + 1);
if(!merged)
goto malloc_err;
strncpy(merged, nam.naml$l_long_expand,
nam.naml$l_long_expand_size);
merged[nam.naml$l_long_expand_size] = '\0';
}
else
{
merged = OPENSSL_malloc(nam.naml$b_esl + 1);
if(!merged)
goto malloc_err;
strncpy(merged, nam.naml$l_esa,
nam.naml$b_esl);
merged[nam.naml$b_esl] = '\0';
}
#else
merged = OPENSSL_malloc(nam.nam$b_esl + 1);
if(!merged)
goto malloc_err;
strncpy(merged, nam.nam$l_esa,
nam.nam$b_esl);
merged[nam.nam$b_esl] = '\0';
#endif
return(merged);
malloc_err:
DSOerr(DSO_F_VMS_MERGER,
ERR_R_MALLOC_FAILURE);
}
static char *vms_name_converter(DSO *dso, const char *filename)
{
int len = strlen(filename);

View File

@ -1,4 +1,4 @@
/* dso_win32.c -*- mode:C; c-file-style: "eay" -*- */
/* dso_win32.c */
/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
* project 2000.
*/
@ -83,10 +83,6 @@ static int win32_finish(DSO *dso);
static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
#endif
static char *win32_name_converter(DSO *dso, const char *filename);
static char *win32_merger(DSO *dso, const char *filespec1,
const char *filespec2);
static const char *openssl_strnchr(const char *string, int c, size_t len);
static DSO_METHOD dso_meth_win32 = {
"OpenSSL 'win32' shared library method",
@ -101,7 +97,6 @@ static DSO_METHOD dso_meth_win32 = {
#endif
NULL, /* ctrl */
win32_name_converter,
win32_merger,
NULL, /* init */
NULL /* finish */
};
@ -253,306 +248,6 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
return((DSO_FUNC_TYPE)sym);
}
struct file_st
{
const char *node; int nodelen;
const char *device; int devicelen;
const char *predir; int predirlen;
const char *dir; int dirlen;
const char *file; int filelen;
};
static struct file_st *win32_splitter(DSO *dso, const char *filename,
int assume_last_is_dir)
{
struct file_st *result = NULL;
enum { IN_NODE, IN_DEVICE, IN_FILE } position;
const char *start = filename;
if (!filename)
{
DSOerr(DSO_F_WIN32_MERGER,DSO_R_NO_FILENAME);
/*goto err;*/
return(NULL);
}
result = OPENSSL_malloc(sizeof(struct file_st));
if(result == NULL)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
memset(result, 0, sizeof(struct file_st));
position = IN_DEVICE;
if(filename[0] == '\\' && filename[1] == '\\'
|| filename[0] == '/' && filename[1] == '/')
{
position = IN_NODE;
filename += 2;
start = filename;
result->node = start;
}
do
{
switch(filename[0])
{
case ':':
if(position != IN_DEVICE)
{
DSOerr(DSO_F_WIN32_MERGER,
DSO_R_INCORRECT_FILE_SYNTAX);
/*goto err;*/
return(NULL);
}
result->device = start;
result->devicelen = filename - start;
position = IN_FILE;
start = ++filename;
result->dir = start;
break;
case '\\':
case '/':
if(position == IN_NODE)
{
result->nodelen = filename - start;
position = IN_FILE;
start = ++filename;
result->dir = start;
}
else
{
filename++;
result->dirlen += filename - start;
}
break;
case '\0':
if(position == IN_NODE)
{
result->nodelen = filename - start;
}
else
{
if(filename - start > 0)
{
if (assume_last_is_dir)
{
result->devicelen += filename - start;
}
else
{
result->file = start;
result->filelen = filename - start;
}
}
}
break;
default:
filename++;
break;
}
}
while(*filename);
if(!result->nodelen) result->node = NULL;
if(!result->devicelen) result->device = NULL;
if(!result->dirlen) result->dir = NULL;
if(!result->filelen) result->file = NULL;
return(result);
}
static char *win32_joiner(DSO *dso, const struct file_st *file_split)
{
int len = 0, offset = 0;
char *result = NULL;
const char *start;
if(!file_split)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_PASSED_NULL_PARAMETER);
return(NULL);
}
if(file_split->node)
{
len += 2 + file_split->nodelen; /* 2 for starting \\ */
if(file_split->predir || file_split->dir || file_split->file)
len++; /* 1 for ending \ */
}
else if(file_split->device)
{
len += file_split->devicelen + 1; /* 1 for ending : */
}
len += file_split->predirlen;
if(file_split->predir && (file_split->dir || file_split->file))
{
len++; /* 1 for ending \ */
}
len += file_split->dirlen;
if(file_split->dir && file_split->file)
{
len++; /* 1 for ending \ */
}
len += file_split->filelen;
if(!len)
{
DSOerr(DSO_F_WIN32_MERGER, DSO_R_EMPTY_FILE_STRUCTURE);
return(NULL);
}
result = OPENSSL_malloc(len + 1);
if (!result)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
if(file_split->node)
{
strcpy(&result[offset], "\\\\"); offset += 2;
strncpy(&result[offset], file_split->node,
file_split->nodelen); offset += file_split->nodelen;
if(file_split->predir || file_split->dir || file_split->file)
{
result[offset] = '\\'; offset++;
}
}
else if(file_split->device)
{
strncpy(&result[offset], file_split->device,
file_split->devicelen); offset += file_split->devicelen;
result[offset] = ':'; offset++;
}
start = file_split->predir;
while(file_split->predirlen > (start - file_split->predir))
{
const char *end = openssl_strnchr(start, '/',
file_split->predirlen - (start - file_split->predir));
if(!end)
end = start
+ file_split->predirlen
- (start - file_split->predir);
strncpy(&result[offset], start,
end - start); offset += end - start;
result[offset] = '\\'; offset++;
start = end + 1;
}
if(file_split->predir && (file_split->dir || file_split->file))
{
result[offset] = '\\'; offset++;
}
start = file_split->dir;
while(file_split->dirlen > (start - file_split->dir))
{
const char *end = openssl_strnchr(start, '/',
file_split->dirlen - (start - file_split->dir));
if(!end)
end = start
+ file_split->dirlen
- (start - file_split->dir);
strncpy(&result[offset], start,
end - start); offset += end - start;
result[offset] = '\\'; offset++;
start = end + 1;
}
if(file_split->dir && file_split->file)
{
result[offset] = '\\'; offset++;
}
strncpy(&result[offset], file_split->file,
file_split->filelen); offset += file_split->filelen;
result[offset] = '\0';
return(result);
}
static char *win32_merger(DSO *dso, const char *filespec1, const char *filespec2)
{
char *merged = NULL;
struct file_st *filespec1_split = NULL;
struct file_st *filespec2_split = NULL;
if(!filespec1 && !filespec2)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_PASSED_NULL_PARAMETER);
return(NULL);
}
if (!filespec2)
{
merged = OPENSSL_malloc(strlen(filespec1) + 1);
if(!merged)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec1);
}
else if (!filespec1)
{
merged = OPENSSL_malloc(strlen(filespec2) + 1);
if(!merged)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
strcpy(merged, filespec2);
}
else
{
filespec1_split = win32_splitter(dso, filespec1, 1);
if (!filespec1_split)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
return(NULL);
}
filespec2_split = win32_splitter(dso, filespec2, 0);
if (!filespec1_split)
{
DSOerr(DSO_F_WIN32_MERGER,
ERR_R_MALLOC_FAILURE);
OPENSSL_free(filespec1_split);
return(NULL);
}
/* Fill in into filespec1_split */
if (!filespec1_split->node && !filespec1_split->device)
{
filespec1_split->node = filespec2_split->node;
filespec1_split->nodelen = filespec2_split->nodelen;
filespec1_split->device = filespec2_split->device;
filespec1_split->devicelen = filespec2_split->devicelen;
}
if (!filespec1_split->dir)
{
filespec1_split->dir = filespec2_split->dir;
filespec1_split->dirlen = filespec2_split->dirlen;
}
else if (filespec1_split->dir[0] != '\\'
&& filespec1_split->dir[0] != '/')
{
filespec1_split->predir = filespec2_split->dir;
filespec1_split->predirlen = filespec2_split->dirlen;
}
if (!filespec1_split->file)
{
filespec1_split->file = filespec2_split->file;
filespec1_split->filelen = filespec2_split->filelen;
}
merged = win32_joiner(dso, filespec1_split);
}
return(merged);
}
static char *win32_name_converter(DSO *dso, const char *filename)
{
char *translated;
@ -581,17 +276,4 @@ static char *win32_name_converter(DSO *dso, const char *filename)
return(translated);
}
static const char *openssl_strnchr(const char *string, int c, size_t len)
{
size_t i;
const char *p;
for (i = 0, p = string; i < len && *p; i++, p++)
{
if (*p == c)
return p;
}
return NULL;
}
#endif /* OPENSSL_SYS_WIN32 */

View File

@ -23,13 +23,11 @@ TEST=ectest.c
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC= ec_lib.c ecp_smpl.c ecp_mont.c ecp_recp.c ecp_nist.c ec_cvt.c ec_mult.c\
ec_err.c ec_curve.c ec_check.c ec_print.c ec_asn1.c ec_key.c\
ec2_smpl.c ec2_smpt.c ec2_mult.c
LIBSRC= ec_lib.c ecp_smpl.c ecp_mont.c ecp_recp.c ecp_nist.c ec_cvt.c ec_mult.c \
ec_err.c
LIBOBJ= ec_lib.o ecp_smpl.o ecp_mont.o ecp_recp.o ecp_nist.o ec_cvt.o ec_mult.o\
ec_err.o ec_curve.o ec_check.o ec_print.o ec_asn1.o ec_key.o\
ec2_smpl.o ec2_mult.o
LIBOBJ= ec_lib.o ecp_smpl.o ecp_mont.o ecp_recp.o ecp_nist.o ec_cvt.o ec_mult.o \
ec_err.o
SRC= $(LIBSRC)
@ -84,123 +82,47 @@ clean:
# DO NOT DELETE THIS LINE -- make depend depends on it.
ec2_mult.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec2_mult.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec2_mult.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec2_mult.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec2_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec2_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec2_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec2_mult.o: ../../include/openssl/symhacks.h ec2_mult.c ec_lcl.h
ec2_smpl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec2_smpl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec2_smpl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec2_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec2_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec2_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec2_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec2_smpl.o: ../../include/openssl/symhacks.h ec2_smpl.c ec2_smpt.c ec_lcl.h
ec2_smpt.o: ec2_smpt.c
ec_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
ec_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ec_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ec_asn1.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ec_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ec_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
ec_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_asn1.o: ../../include/openssl/symhacks.h ec_asn1.c ec_lcl.h
ec_check.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_check.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_check.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_check.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_check.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_check.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_check.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_check.o: ../../include/openssl/symhacks.h ec_check.c ec_lcl.h
ec_curve.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_curve.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_curve.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_curve.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_curve.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_curve.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_curve.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_curve.o: ../../include/openssl/symhacks.h ec_curve.c ec_lcl.h
ec_cvt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_cvt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_cvt.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_cvt.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_cvt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_cvt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
ec_cvt.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h
ec_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
ec_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
ec_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ec_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ec_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ec_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ec_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
ec_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ec_err.o: ec_err.c
ec_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_key.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_key.o: ../../include/openssl/symhacks.h ec_key.c ec_lcl.h
ec_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_lib.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_lib.o: ../../include/openssl/symhacks.h ec_lcl.h ec_lib.c
ec_mult.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_mult.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_mult.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_mult.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ec_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_mult.o: ../../include/openssl/symhacks.h ec_lcl.h ec_mult.c
ec_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ec_print.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ec_print.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ec_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ec_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ec_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_print.o: ../../include/openssl/symhacks.h ec_lcl.h ec_print.c
ecp_mont.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecp_mont.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ecp_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecp_mont.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ecp_mont.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecp_mont.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ecp_mont.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_mont.c
ecp_nist.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ecp_nist.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecp_nist.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ecp_nist.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ecp_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecp_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ec_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ec_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ec_lib.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ec_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
ec_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ec_lib.o: ec_lcl.h ec_lib.c
ec_mult.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ec_mult.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ec_mult.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ec_mult.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
ec_mult.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ec_mult.o: ec_lcl.h ec_mult.c
ecp_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ecp_mont.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ecp_mont.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ecp_mont.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
ecp_mont.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ecp_mont.o: ec_lcl.h ecp_mont.c
ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
ecp_nist.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
ecp_nist.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_nist.c
ecp_recp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecp_recp.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ecp_recp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecp_recp.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ecp_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecp_recp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ecp_recp.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
ecp_recp.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
ecp_recp.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_recp.c
ecp_smpl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecp_smpl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ecp_smpl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecp_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ecp_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecp_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ecp_smpl.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_smpl.c
ecp_smpl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
ecp_smpl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ecp_smpl.o: ../../include/openssl/ec.h ../../include/openssl/err.h
ecp_smpl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
ecp_smpl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ecp_smpl.o: ec_lcl.h ecp_smpl.c

View File

@ -1,9 +1,6 @@
/* crypto/ec/ec.h */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -55,19 +52,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The elliptic curve binary polynomial software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#ifndef HEADER_EC_H
#define HEADER_EC_H
@ -77,7 +61,6 @@
#endif
#include <openssl/bn.h>
#include <openssl/asn1.h>
#include <openssl/symhacks.h>
#ifdef __cplusplus
@ -102,7 +85,6 @@ typedef struct ec_group_st
-- curve coefficients
-- optional generator with associated information (order, cofactor)
-- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
-- ASN1 stuff
*/
EC_GROUP;
@ -114,82 +96,40 @@ typedef struct ec_point_st EC_POINT;
*/
const EC_METHOD *EC_GFp_simple_method(void);
const EC_METHOD *EC_GFp_mont_method(void);
const EC_METHOD *EC_GFp_nist_method(void);
#if 0
const EC_METHOD *EC_GFp_recp_method(void); /* TODO */
const EC_METHOD *EC_GFp_nist_method(void); /* TODO */
#endif
/* EC_METHOD for curves over GF(2^m).
*/
const EC_METHOD *EC_GF2m_simple_method(void);
EC_GROUP *EC_GROUP_new(const EC_METHOD *);
void EC_GROUP_free(EC_GROUP *);
void EC_GROUP_clear_free(EC_GROUP *);
int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
EC_GROUP *EC_GROUP_dup(const EC_GROUP *);
const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
int EC_METHOD_get_field_type(const EC_METHOD *);
/* We don't have types for field specifications and field elements in general.
* Otherwise we could declare
* int EC_GROUP_set_curve(EC_GROUP *, .....);
*/
int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp()
* after choosing an appropriate EC_METHOD */
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
void EC_GROUP_set_nid(EC_GROUP *, int); /* curve name */
int EC_GROUP_get_nid(const EC_GROUP *);
void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
int EC_GROUP_get_asn1_flag(const EC_GROUP *);
void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
size_t EC_GROUP_get_seed_len(const EC_GROUP *);
size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
int EC_GROUP_get_degree(const EC_GROUP *);
/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the
* elliptic curve is not zero, 0 otherwise */
int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
* after choosing an appropriate EC_METHOD */
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
/* EC_GROUP_new_by_nid() creates a EC_GROUP structure specified by a NID */
EC_GROUP *EC_GROUP_new_by_nid(int nid);
/* handling of internal curves */
typedef struct {
int nid;
const char *comment;
} EC_builtin_curve;
/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
* of all available curves or zero if a error occurred.
* In case r ist not zero nitems EC_builtin_curve structures
* are filled with the data of the first nitems internal groups */
size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
/* EC_POINT functions */
EC_POINT *EC_POINT_new(const EC_GROUP *);
void EC_POINT_free(EC_POINT *);
void EC_POINT_clear_free(EC_POINT *);
int EC_POINT_copy(EC_POINT *, const EC_POINT *);
EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
@ -205,28 +145,11 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, int y_bit, BN_CTX *);
int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BN_CTX *);
int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, int y_bit, BN_CTX *);
size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
unsigned char *buf, size_t len, BN_CTX *);
int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
const unsigned char *buf, size_t len, BN_CTX *);
/* other interfaces to point2oct/oct2point: */
BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
point_conversion_form_t form, BIGNUM *, BN_CTX *);
EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
EC_POINT *, BN_CTX *);
char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
point_conversion_form_t form, BN_CTX *);
EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
EC_POINT *, BN_CTX *);
int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
@ -245,99 +168,6 @@ int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
/* ASN1 stuff */
/* EC_GROUP_get_basis_type() returns the NID of the basis type
* used to represent the field elements */
int EC_GROUP_get_basis_type(const EC_GROUP *);
int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
unsigned int *k2, unsigned int *k3);
#define OPENSSL_EC_NAMED_CURVE 0x001
typedef struct ecpk_parameters_st ECPKPARAMETERS;
EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
#define d2i_ECPKParameters_bio(bp,x) (EC_GROUP *)ASN1_d2i_bio(NULL, \
(char *(*)())d2i_ECPKParameters,(bp),(unsigned char **)(x))
#define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio(i2d_ECPKParameters,(bp), \
(unsigned char *)(x))
#define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
(char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
#define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
(unsigned char *)(x))
#ifndef OPENSSL_NO_BIO
int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
#endif
#ifndef OPENSSL_NO_FP_API
int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
#endif
/* the EC_KEY stuff */
typedef struct ec_key_st EC_KEY;
typedef struct ec_key_meth_data_st {
int (*init)(EC_KEY *);
void (*finish)(EC_KEY *);
} EC_KEY_METH_DATA;
struct ec_key_st {
int version;
EC_GROUP *group;
EC_POINT *pub_key;
BIGNUM *priv_key;
unsigned int enc_flag;
point_conversion_form_t conv_form;
int references;
EC_KEY_METH_DATA *meth_data;
}/* EC_KEY */;
/* some values for the encoding_flag */
#define EC_PKEY_NO_PARAMETERS 0x001
#define EC_PKEY_NO_PUBKEY 0x002
EC_KEY *EC_KEY_new(void);
void EC_KEY_free(EC_KEY *);
EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
EC_KEY *EC_KEY_dup(const EC_KEY *);
int EC_KEY_up_ref(EC_KEY *);
/* EC_KEY_generate_key() creates a ec private (public) key */
int EC_KEY_generate_key(EC_KEY *);
/* EC_KEY_check_key() */
int EC_KEY_check_key(const EC_KEY *);
/* de- and encode functions for the SEC1 ECPrivateKey */
EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
/* de- and encode functions for the elliptic curve parameters */
EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
int i2d_ECParameters(EC_KEY *a, unsigned char **out);
EC_KEY *ECPublicKey_set_octet_string(EC_KEY **a, const unsigned char **in,
long len);
int ECPublicKey_get_octet_string(EC_KEY *a, unsigned char **out);
#ifndef OPENSSL_NO_BIO
int ECParameters_print(BIO *bp, const EC_KEY *x);
int EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
#endif
#ifndef OPENSSL_NO_FP_API
int ECParameters_print_fp(FILE *fp, const EC_KEY *x);
int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
#endif
#define ECParameters_dup(x) (EC_KEY *)ASN1_dup((int (*)())i2d_ECParameters,\
(char *(*)())d2i_ECParameters,(char *)(x))
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
@ -348,148 +178,66 @@ void ERR_load_EC_strings(void);
/* Function codes. */
#define EC_F_COMPUTE_WNAF 143
#define EC_F_D2I_ECPARAMETERS 144
#define EC_F_D2I_ECPKPARAMETERS 145
#define EC_F_D2I_ECPRIVATEKEY 146
#define EC_F_ECPARAMETERS_PRINT 147
#define EC_F_ECPARAMETERS_PRINT_FP 148
#define EC_F_ECPKPARAMETERS_PRINT 149
#define EC_F_ECPKPARAMETERS_PRINT_FP 150
#define EC_F_ECPUBLICKEY_GET_OCTET 151
#define EC_F_ECPUBLICKEY_SET_OCTET 152
#define EC_F_ECP_NIST_MOD_192 203
#define EC_F_ECP_NIST_MOD_224 204
#define EC_F_ECP_NIST_MOD_256 205
#define EC_F_ECP_NIST_MOD_521 206
#define EC_F_EC_ASN1_GROUP2CURVE 153
#define EC_F_EC_ASN1_GROUP2FIELDID 154
#define EC_F_EC_ASN1_GROUP2PARAMETERS 155
#define EC_F_EC_ASN1_GROUP2PKPARAMETERS 156
#define EC_F_EC_ASN1_PARAMETERS2GROUP 157
#define EC_F_EC_ASN1_PKPARAMETERS2GROUP 158
#define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159
#define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195
#define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160
#define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161
#define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
#define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
#define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164
#define EC_F_EC_GFP_MONT_FIELD_DECODE 133
#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
#define EC_F_EC_GFP_MONT_FIELD_MUL 131
#define EC_F_EC_GFP_MONT_FIELD_SQR 132
#define EC_F_EC_GFP_NIST_FIELD_MUL 200
#define EC_F_EC_GFP_NIST_FIELD_SQR 201
#define EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP 202
#define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165
#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166
#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167
#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168
#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169
#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
#define EC_F_EC_GROUP_CHECK 170
#define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171
#define EC_F_EC_GROUP_COPY 106
#define EC_F_EC_GROUP_GET0_GENERATOR 139
#define EC_F_EC_GROUP_GET_COFACTOR 140
#define EC_F_EC_GROUP_GET_CURVE_GF2M 172
#define EC_F_EC_GROUP_GET_CURVE_GFP 130
#define EC_F_EC_GROUP_GET_DEGREE 173
#define EC_F_EC_GROUP_GET_EXTRA_DATA 107
#define EC_F_EC_GROUP_GET_ORDER 141
#define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193
#define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194
#define EC_F_EC_GROUP_GROUP2NID 147
#define EC_F_EC_GROUP_NEW 108
#define EC_F_EC_GROUP_NEW_BY_NID 174
#define EC_F_EC_GROUP_NEW_FROM_DATA 175
#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
#define EC_F_EC_GROUP_SET_CURVE_GF2M 176
#define EC_F_EC_GROUP_SET_CURVE_GFP 109
#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
#define EC_F_EC_GROUP_SET_GENERATOR 111
#define EC_F_EC_KEY_CHECK_KEY 177
#define EC_F_EC_KEY_COPY 178
#define EC_F_EC_KEY_GENERATE_KEY 179
#define EC_F_EC_KEY_PRINT 180
#define EC_F_EC_KEY_PRINT_FP 181
#define EC_F_EC_NEW 182
#define EC_F_EC_POINTS_MAKE_AFFINE 136
#define EC_F_EC_POINTS_MUL 138
#define EC_F_EC_POINT_ADD 112
#define EC_F_EC_POINT_CMP 113
#define EC_F_EC_POINT_COPY 114
#define EC_F_EC_POINT_DBL 115
#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183
#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
#define EC_F_EC_POINT_IS_AT_INFINITY 118
#define EC_F_EC_POINT_IS_ON_CURVE 119
#define EC_F_EC_POINT_MAKE_AFFINE 120
#define EC_F_EC_POINT_MUL 184
#define EC_F_EC_POINT_NEW 121
#define EC_F_EC_POINT_OCT2POINT 122
#define EC_F_EC_POINT_POINT2OCT 123
#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185
#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186
#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
#define EC_F_EC_POINT_SET_TO_INFINITY 127
#define EC_F_EC_WNAF_MUL 187
#define EC_F_EC_WNAF_PRECOMPUTE_MULT 188
#define EC_F_GFP_MONT_GROUP_SET_CURVE 189
#define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135
#define EC_F_I2D_ECPARAMETERS 190
#define EC_F_I2D_ECPKPARAMETERS 191
#define EC_F_I2D_ECPRIVATEKEY 192
/* Reason codes. */
#define EC_R_ASN1_ERROR 115
#define EC_R_ASN1_UNKNOWN_FIELD 116
#define EC_R_BUFFER_TOO_SMALL 100
#define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
#define EC_R_DISCRIMINANT_IS_ZERO 118
#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
#define EC_R_GROUP2PKPARAMETERS_FAILURE 120
#define EC_R_I2D_ECPKPARAMETERS_FAILURE 121
#define EC_R_INCOMPATIBLE_OBJECTS 101
#define EC_R_INTERNAL_ERROR 132
#define EC_R_INVALID_ARGUMENT 112
#define EC_R_INVALID_COMPRESSED_POINT 110
#define EC_R_INVALID_COMPRESSION_BIT 109
#define EC_R_INVALID_ENCODING 102
#define EC_R_INVALID_FIELD 103
#define EC_R_INVALID_FORM 104
#define EC_R_INVALID_GROUP_ORDER 122
#define EC_R_INVALID_PRIVATE_KEY 123
#define EC_R_MISSING_PARAMETERS 124
#define EC_R_MISSING_PRIVATE_KEY 125
#define EC_R_NOT_A_NIST_PRIME 135
#define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136
#define EC_R_NOT_IMPLEMENTED 126
#define EC_R_NOT_INITIALIZED 111
#define EC_R_NO_FIELD_MOD 133
#define EC_R_NO_SUCH_EXTRA_DATA 105
#define EC_R_PASSED_NULL_PARAMETER 134
#define EC_R_PKPARAMETERS2GROUP_FAILURE 127
#define EC_R_POINT_AT_INFINITY 106
#define EC_R_POINT_IS_NOT_ON_CURVE 107
#define EC_R_SLOT_FULL 108
#define EC_R_UNDEFINED_GENERATOR 113
#define EC_R_UNDEFINED_ORDER 128
#define EC_R_UNKNOWN_GROUP 129
#define EC_R_UNKNOWN_ORDER 114
#define EC_R_UNSUPPORTED_FIELD 131
#define EC_R_WRONG_ORDER 130
#ifdef __cplusplus
}

View File

@ -1,376 +0,0 @@
/* crypto/ec/ec2_mult.c */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* The Elliptic Curve Public-Key Crypto Library (ECC Code) included
* herein is developed by SUN MICROSYSTEMS, INC., and is contributed
* to the OpenSSL project.
*
* The ECC Code is licensed pursuant to the OpenSSL open source
* license provided below.
*
* The software is originally written by Sheueling Chang Shantz and
* Douglas Stebila of Sun Microsystems Laboratories.
*
*/
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include <openssl/err.h>
#include "ec_lcl.h"
/* Compute the x-coordinate x/z for the point 2*(x/z) in Montgomery projective
* coordinates.
* Uses algorithm Mdouble in appendix of
* Lopez, J. and Dahab, R. "Fast multiplication on elliptic curves over
* GF(2^m) without precomputation".
* modified to not require precomputation of c=b^{2^{m-1}}.
*/
static int Mdouble(const EC_GROUP *group, BIGNUM *x, BIGNUM *z, BN_CTX *ctx)
{
BIGNUM *t1;
int ret = 0;
/* Since Mdouble is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx);
if (t1 == NULL) goto err;
if (!group->meth->field_sqr(group, x, x, ctx)) goto err;
if (!group->meth->field_sqr(group, t1, z, ctx)) goto err;
if (!group->meth->field_mul(group, z, x, t1, ctx)) goto err;
if (!group->meth->field_sqr(group, x, x, ctx)) goto err;
if (!group->meth->field_sqr(group, t1, t1, ctx)) goto err;
if (!group->meth->field_mul(group, t1, &group->b, t1, ctx)) goto err;
if (!BN_GF2m_add(x, x, t1)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the x-coordinate x1/z1 for the point (x1/z1)+(x2/x2) in Montgomery
* projective coordinates.
* Uses algorithm Madd in appendix of
* Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over
* GF(2^m) without precomputation".
*/
static int Madd(const EC_GROUP *group, const BIGNUM *x, BIGNUM *x1, BIGNUM *z1,
const BIGNUM *x2, const BIGNUM *z2, BN_CTX *ctx)
{
BIGNUM *t1, *t2;
int ret = 0;
/* Since Madd is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
t1 = BN_CTX_get(ctx);
t2 = BN_CTX_get(ctx);
if (t2 == NULL) goto err;
if (!BN_copy(t1, x)) goto err;
if (!group->meth->field_mul(group, x1, x1, z2, ctx)) goto err;
if (!group->meth->field_mul(group, z1, z1, x2, ctx)) goto err;
if (!group->meth->field_mul(group, t2, x1, z1, ctx)) goto err;
if (!BN_GF2m_add(z1, z1, x1)) goto err;
if (!group->meth->field_sqr(group, z1, z1, ctx)) goto err;
if (!group->meth->field_mul(group, x1, z1, t1, ctx)) goto err;
if (!BN_GF2m_add(x1, x1, t2)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Compute the affine coordinates x2, y2=z2 for the point (x1/z1) and (x2/x2) in
* Montgomery projective coordinates.
* Uses algorithm Mxy in appendix of
* Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over
* GF(2^m) without precomputation".
* Returns:
* 0 on error
* 1 if return value should be the point at infinity
* 2 otherwise
*/
static int Mxy(const EC_GROUP *group, const BIGNUM *x, const BIGNUM *y, BIGNUM *x1,
BIGNUM *z1, BIGNUM *x2, BIGNUM *z2, BN_CTX *ctx)
{
BIGNUM *t3, *t4, *t5;
int ret = 0;
if (BN_is_zero(z1))
{
if (!BN_zero(x2)) return 0;
if (!BN_zero(z2)) return 0;
return 1;
}
if (BN_is_zero(z2))
{
if (!BN_copy(x2, x)) return 0;
if (!BN_GF2m_add(z2, x, y)) return 0;
return 2;
}
/* Since Mxy is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
t3 = BN_CTX_get(ctx);
t4 = BN_CTX_get(ctx);
t5 = BN_CTX_get(ctx);
if (t5 == NULL) goto err;
if (!BN_one(t5)) goto err;
if (!group->meth->field_mul(group, t3, z1, z2, ctx)) goto err;
if (!group->meth->field_mul(group, z1, z1, x, ctx)) goto err;
if (!BN_GF2m_add(z1, z1, x1)) goto err;
if (!group->meth->field_mul(group, z2, z2, x, ctx)) goto err;
if (!group->meth->field_mul(group, x1, z2, x1, ctx)) goto err;
if (!BN_GF2m_add(z2, z2, x2)) goto err;
if (!group->meth->field_mul(group, z2, z2, z1, ctx)) goto err;
if (!group->meth->field_sqr(group, t4, x, ctx)) goto err;
if (!BN_GF2m_add(t4, t4, y)) goto err;
if (!group->meth->field_mul(group, t4, t4, t3, ctx)) goto err;
if (!BN_GF2m_add(t4, t4, z2)) goto err;
if (!group->meth->field_mul(group, t3, t3, x, ctx)) goto err;
if (!group->meth->field_div(group, t3, t5, t3, ctx)) goto err;
if (!group->meth->field_mul(group, t4, t3, t4, ctx)) goto err;
if (!group->meth->field_mul(group, x2, x1, t3, ctx)) goto err;
if (!BN_GF2m_add(z2, x2, x)) goto err;
if (!group->meth->field_mul(group, z2, z2, t4, ctx)) goto err;
if (!BN_GF2m_add(z2, z2, y)) goto err;
ret = 2;
err:
BN_CTX_end(ctx);
return ret;
}
/* Computes scalar*point and stores the result in r.
* point can not equal r.
* Uses algorithm 2P of
* Lopex, J. and Dahab, R. "Fast multiplication on elliptic curves over
* GF(2^m) without precomputation".
*/
static int point_multiply(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
const EC_POINT *point, BN_CTX *ctx)
{
BIGNUM *x1, *x2, *z1, *z2;
int ret = 0, i, j;
BN_ULONG mask;
if (r == point)
{
ECerr(EC_F_EC_POINT_MUL, EC_R_INVALID_ARGUMENT);
return 0;
}
/* if result should be point at infinity */
if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) ||
EC_POINT_is_at_infinity(group, point))
{
return EC_POINT_set_to_infinity(group, r);
}
/* only support affine coordinates */
if (!point->Z_is_one) return 0;
/* Since point_multiply is static we can guarantee that ctx != NULL. */
BN_CTX_start(ctx);
x1 = BN_CTX_get(ctx);
z1 = BN_CTX_get(ctx);
if (z1 == NULL) goto err;
x2 = &r->X;
z2 = &r->Y;
if (!BN_GF2m_mod_arr(x1, &point->X, group->poly)) goto err; /* x1 = x */
if (!BN_one(z1)) goto err; /* z1 = 1 */
if (!group->meth->field_sqr(group, z2, x1, ctx)) goto err; /* z2 = x1^2 = x^2 */
if (!group->meth->field_sqr(group, x2, z2, ctx)) goto err;
if (!BN_GF2m_add(x2, x2, &group->b)) goto err; /* x2 = x^4 + b */
/* find top most bit and go one past it */
i = scalar->top - 1; j = BN_BITS2 - 1;
mask = BN_TBIT;
while (!(scalar->d[i] & mask)) { mask >>= 1; j--; }
mask >>= 1; j--;
/* if top most bit was at word break, go to next word */
if (!mask)
{
i--; j = BN_BITS2 - 1;
mask = BN_TBIT;
}
for (; i >= 0; i--)
{
for (; j >= 0; j--)
{
if (scalar->d[i] & mask)
{
if (!Madd(group, &point->X, x1, z1, x2, z2, ctx)) goto err;
if (!Mdouble(group, x2, z2, ctx)) goto err;
}
else
{
if (!Madd(group, &point->X, x2, z2, x1, z1, ctx)) goto err;
if (!Mdouble(group, x1, z1, ctx)) goto err;
}
mask >>= 1;
}
j = BN_BITS2 - 1;
mask = BN_TBIT;
}
/* convert out of "projective" coordinates */
i = Mxy(group, &point->X, &point->Y, x1, z1, x2, z2, ctx);
if (i == 0) goto err;
else if (i == 1)
{
if (!EC_POINT_set_to_infinity(group, r)) goto err;
}
else
{
if (!BN_one(&r->Z)) goto err;
r->Z_is_one = 1;
}
/* GF(2^m) field elements should always have BIGNUM::neg = 0 */
BN_set_sign(&r->X, 0);
BN_set_sign(&r->Y, 0);
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
/* Computes the sum
* scalar*group->generator + scalars[0]*points[0] + ... + scalars[num-1]*points[num-1]
* gracefully ignoring NULL scalar values.
*/
int ec_GF2m_mont_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
int ret = 0, i;
EC_POINT *p=NULL;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
/* This implementation is more efficient than the wNAF implementation for 2
* or fewer points. Use the ec_wNAF_mul implementation for 3 or more points.
*/
if ((scalar && (num > 1)) || (num > 2))
{
ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
goto err;
}
if ((p = EC_POINT_new(group)) == NULL) goto err;
if (!EC_POINT_set_to_infinity(group, r)) goto err;
if (scalar)
{
if (!point_multiply(group, p, scalar, group->generator, ctx)) goto err;
if (BN_get_sign(scalar))
if (!group->meth->invert(group, p, ctx)) goto err;
if (!group->meth->add(group, r, r, p, ctx)) goto err;
}
for (i = 0; i < num; i++)
{
if (!point_multiply(group, p, scalars[i], points[i], ctx)) goto err;
if (BN_get_sign(scalars[i]))
if (!group->meth->invert(group, p, ctx)) goto err;
if (!group->meth->add(group, r, r, p, ctx)) goto err;
}
ret = 1;
err:
if (p) EC_POINT_free(p);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
}
/* Precomputation for point multiplication. */
int ec_GF2m_mont_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
{
/* There is no precomputation to do for Montgomery scalar multiplication but
* since this implementation falls back to the wNAF multiplication for more than
* two points, call the wNAF implementation's precompute.
*/
return ec_wNAF_precompute_mult(group, ctx);
}

View File

@ -1,974 +0,0 @@
/* crypto/ec/ec2_smpl.c */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* The Elliptic Curve Public-Key Crypto Library (ECC Code) included
* herein is developed by SUN MICROSYSTEMS, INC., and is contributed
* to the OpenSSL project.
*
* The ECC Code is licensed pursuant to the OpenSSL open source
* license provided below.
*
* The software is originally written by Sheueling Chang Shantz and
* Douglas Stebila of Sun Microsystems Laboratories.
*
*/
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include <openssl/err.h>
#include "ec_lcl.h"
const EC_METHOD *EC_GF2m_simple_method(void)
{
static const EC_METHOD ret = {
NID_X9_62_characteristic_two_field,
ec_GF2m_simple_group_init,
ec_GF2m_simple_group_finish,
ec_GF2m_simple_group_clear_finish,
ec_GF2m_simple_group_copy,
ec_GF2m_simple_group_set_curve,
ec_GF2m_simple_group_get_curve,
ec_GF2m_simple_group_get_degree,
ec_GF2m_simple_group_check_discriminant,
ec_GF2m_simple_point_init,
ec_GF2m_simple_point_finish,
ec_GF2m_simple_point_clear_finish,
ec_GF2m_simple_point_copy,
ec_GF2m_simple_point_set_to_infinity,
0 /* set_Jprojective_coordinates_GFp */,
0 /* get_Jprojective_coordinates_GFp */,
ec_GF2m_simple_point_set_affine_coordinates,
ec_GF2m_simple_point_get_affine_coordinates,
ec_GF2m_simple_set_compressed_coordinates,
ec_GF2m_simple_point2oct,
ec_GF2m_simple_oct2point,
ec_GF2m_simple_add,
ec_GF2m_simple_dbl,
ec_GF2m_simple_invert,
ec_GF2m_mont_mul,
ec_GF2m_mont_precompute_mult,
ec_GF2m_simple_is_at_infinity,
ec_GF2m_simple_is_on_curve,
ec_GF2m_simple_cmp,
ec_GF2m_simple_make_affine,
ec_GF2m_simple_points_make_affine,
ec_GF2m_simple_field_mul,
ec_GF2m_simple_field_sqr,
ec_GF2m_simple_field_div,
0 /* field_encode */,
0 /* field_decode */,
0 /* field_set_to_one */ };
return &ret;
}
/* Initialize a GF(2^m)-based EC_GROUP structure.
* Note that all other members are handled by EC_GROUP_new.
*/
int ec_GF2m_simple_group_init(EC_GROUP *group)
{
BN_init(&group->field);
BN_init(&group->a);
BN_init(&group->b);
return 1;
}
/* Free a GF(2^m)-based EC_GROUP structure.
* Note that all other members are handled by EC_GROUP_free.
*/
void ec_GF2m_simple_group_finish(EC_GROUP *group)
{
BN_free(&group->field);
BN_free(&group->a);
BN_free(&group->b);
}
/* Clear and free a GF(2^m)-based EC_GROUP structure.
* Note that all other members are handled by EC_GROUP_clear_free.
*/
void ec_GF2m_simple_group_clear_finish(EC_GROUP *group)
{
BN_clear_free(&group->field);
BN_clear_free(&group->a);
BN_clear_free(&group->b);
group->poly[0] = 0;
group->poly[1] = 0;
group->poly[2] = 0;
group->poly[3] = 0;
group->poly[4] = 0;
}
/* Copy a GF(2^m)-based EC_GROUP structure.
* Note that all other members are handled by EC_GROUP_copy.
*/
int ec_GF2m_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
int i;
if (!BN_copy(&dest->field, &src->field)) return 0;
if (!BN_copy(&dest->a, &src->a)) return 0;
if (!BN_copy(&dest->b, &src->b)) return 0;
dest->poly[0] = src->poly[0];
dest->poly[1] = src->poly[1];
dest->poly[2] = src->poly[2];
dest->poly[3] = src->poly[3];
dest->poly[4] = src->poly[4];
bn_wexpand(&dest->a, (dest->poly[0] + BN_BITS2 - 1) / BN_BITS2);
bn_wexpand(&dest->b, (dest->poly[0] + BN_BITS2 - 1) / BN_BITS2);
for (i = dest->a.top; i < dest->a.dmax; i++) dest->a.d[i] = 0;
for (i = dest->b.top; i < dest->b.dmax; i++) dest->b.d[i] = 0;
return 1;
}
/* Set the curve parameters of an EC_GROUP structure. */
int ec_GF2m_simple_group_set_curve(EC_GROUP *group,
const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
int ret = 0, i;
/* group->field */
if (!BN_copy(&group->field, p)) goto err;
i = BN_GF2m_poly2arr(&group->field, group->poly, 5);
if ((i != 5) && (i != 3))
{
ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE, EC_R_UNSUPPORTED_FIELD);
goto err;
}
/* group->a */
if (!BN_GF2m_mod_arr(&group->a, a, group->poly)) goto err;
bn_wexpand(&group->a, (group->poly[0] + BN_BITS2 - 1) / BN_BITS2);
for (i = group->a.top; i < group->a.dmax; i++) group->a.d[i] = 0;
/* group->b */
if (!BN_GF2m_mod_arr(&group->b, b, group->poly)) goto err;
bn_wexpand(&group->b, (group->poly[0] + BN_BITS2 - 1) / BN_BITS2);
for (i = group->b.top; i < group->b.dmax; i++) group->b.d[i] = 0;
ret = 1;
err:
return ret;
}
/* Get the curve parameters of an EC_GROUP structure.
* If p, a, or b are NULL then there values will not be set but the method will return with success.
*/
int ec_GF2m_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
{
int ret = 0;
if (p != NULL)
{
if (!BN_copy(p, &group->field)) return 0;
}
if (a != NULL)
{
if (!BN_copy(a, &group->a)) goto err;
}
if (b != NULL)
{
if (!BN_copy(b, &group->b)) goto err;
}
ret = 1;
err:
return ret;
}
/* Gets the degree of the field. For a curve over GF(2^m) this is the value m. */
int ec_GF2m_simple_group_get_degree(const EC_GROUP *group)
{
return BN_num_bits(&group->field)-1;
}
/* Checks the discriminant of the curve.
* y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p)
*/
int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
{
int ret = 0;
BIGNUM *b;
BN_CTX *new_ctx = NULL;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
{
ECerr(EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE);
goto err;
}
}
BN_CTX_start(ctx);
b = BN_CTX_get(ctx);
if (b == NULL) goto err;
if (!BN_GF2m_mod_arr(b, &group->b, group->poly)) goto err;
/* check the discriminant:
* y^2 + x*y = x^3 + a*x^2 + b is an elliptic curve <=> b != 0 (mod p)
*/
if (BN_is_zero(b)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
}
/* Initializes an EC_POINT. */
int ec_GF2m_simple_point_init(EC_POINT *point)
{
BN_init(&point->X);
BN_init(&point->Y);
BN_init(&point->Z);
return 1;
}
/* Frees an EC_POINT. */
void ec_GF2m_simple_point_finish(EC_POINT *point)
{
BN_free(&point->X);
BN_free(&point->Y);
BN_free(&point->Z);
}
/* Clears and frees an EC_POINT. */
void ec_GF2m_simple_point_clear_finish(EC_POINT *point)
{
BN_clear_free(&point->X);
BN_clear_free(&point->Y);
BN_clear_free(&point->Z);
point->Z_is_one = 0;
}
/* Copy the contents of one EC_POINT into another. Assumes dest is initialized. */
int ec_GF2m_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
{
if (!BN_copy(&dest->X, &src->X)) return 0;
if (!BN_copy(&dest->Y, &src->Y)) return 0;
if (!BN_copy(&dest->Z, &src->Z)) return 0;
dest->Z_is_one = src->Z_is_one;
return 1;
}
/* Set an EC_POINT to the point at infinity.
* A point at infinity is represented by having Z=0.
*/
int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
{
point->Z_is_one = 0;
return (BN_zero(&point->Z));
}
/* Set the coordinates of an EC_POINT using affine coordinates.
* Note that the simple implementation only uses affine coordinates.
*/
int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
{
int ret = 0;
if (x == NULL || y == NULL)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if (!BN_copy(&point->X, x)) goto err;
BN_set_sign(&point->X, 0);
if (!BN_copy(&point->Y, y)) goto err;
BN_set_sign(&point->Y, 0);
if (!BN_copy(&point->Z, BN_value_one())) goto err;
BN_set_sign(&point->Z, 0);
point->Z_is_one = 1;
ret = 1;
err:
return ret;
}
/* Gets the affine coordinates of an EC_POINT.
* Note that the simple implementation only uses affine coordinates.
*/
int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
int ret = 0;
if (EC_POINT_is_at_infinity(group, point))
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY);
return 0;
}
if (BN_cmp(&point->Z, BN_value_one()))
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (x != NULL)
{
if (!BN_copy(x, &point->X)) goto err;
BN_set_sign(x, 0);
}
if (y != NULL)
{
if (!BN_copy(y, &point->Y)) goto err;
BN_set_sign(y, 0);
}
ret = 1;
err:
return ret;
}
/* Include patented algorithms. */
#include "ec2_smpt.c"
/* Converts an EC_POINT to an octet string.
* If buf is NULL, the encoded length will be returned.
* If the length len of buf is smaller than required an error will be returned.
*
* The point compression section of this function is patented by Certicom Corp.
* under US Patent 6,141,420. Point compression is disabled by default and can
* be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at
* Configure-time.
*/
size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point, point_conversion_form_t form,
unsigned char *buf, size_t len, BN_CTX *ctx)
{
size_t ret;
BN_CTX *new_ctx = NULL;
int used_ctx = 0;
BIGNUM *x, *y, *yxi;
size_t field_len, i, skip;
#ifndef OPENSSL_EC_BIN_PT_COMP
if ((form == POINT_CONVERSION_COMPRESSED) || (form == POINT_CONVERSION_HYBRID))
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_DISABLED);
goto err;
}
#endif
if ((form != POINT_CONVERSION_COMPRESSED)
&& (form != POINT_CONVERSION_UNCOMPRESSED)
&& (form != POINT_CONVERSION_HYBRID))
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_INVALID_FORM);
goto err;
}
if (EC_POINT_is_at_infinity(group, point))
{
/* encodes to a single 0 octet */
if (buf != NULL)
{
if (len < 1)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
return 0;
}
buf[0] = 0;
}
return 1;
}
/* ret := required output buffer length */
field_len = (EC_GROUP_get_degree(group) + 7) / 8;
ret = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
/* if 'buf' is NULL, just return required length */
if (buf != NULL)
{
if (len < ret)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);
goto err;
}
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
BN_CTX_start(ctx);
used_ctx = 1;
x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
yxi = BN_CTX_get(ctx);
if (yxi == NULL) goto err;
if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
buf[0] = form;
#ifdef OPENSSL_EC_BIN_PT_COMP
if ((form != POINT_CONVERSION_UNCOMPRESSED) && !BN_is_zero(x))
{
if (!group->meth->field_div(group, yxi, y, x, ctx)) goto err;
if (BN_is_odd(yxi)) buf[0]++;
}
#endif
i = 1;
skip = field_len - BN_num_bytes(x);
if (skip > field_len)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
goto err;
}
while (skip > 0)
{
buf[i++] = 0;
skip--;
}
skip = BN_bn2bin(x, buf + i);
i += skip;
if (i != 1 + field_len)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
goto err;
}
if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID)
{
skip = field_len - BN_num_bytes(y);
if (skip > field_len)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
goto err;
}
while (skip > 0)
{
buf[i++] = 0;
skip--;
}
skip = BN_bn2bin(y, buf + i);
i += skip;
}
if (i != ret)
{
ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);
goto err;
}
}
if (used_ctx)
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
err:
if (used_ctx)
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return 0;
}
/* Converts an octet string representation to an EC_POINT.
* Note that the simple implementation only uses affine coordinates.
*/
int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
const unsigned char *buf, size_t len, BN_CTX *ctx)
{
point_conversion_form_t form;
int y_bit;
BN_CTX *new_ctx = NULL;
BIGNUM *x, *y, *yxi;
size_t field_len, enc_len;
int ret = 0;
if (len == 0)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);
return 0;
}
form = buf[0];
y_bit = form & 1;
form = form & ~1;
if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
&& (form != POINT_CONVERSION_UNCOMPRESSED)
&& (form != POINT_CONVERSION_HYBRID))
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
return 0;
}
if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
return 0;
}
if (form == 0)
{
if (len != 1)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
return 0;
}
return EC_POINT_set_to_infinity(group, point);
}
field_len = (EC_GROUP_get_degree(group) + 7) / 8;
enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2*field_len;
if (len != enc_len)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
return 0;
}
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
BN_CTX_start(ctx);
x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
yxi = BN_CTX_get(ctx);
if (yxi == NULL) goto err;
if (!BN_bin2bn(buf + 1, field_len, x)) goto err;
if (BN_ucmp(x, &group->field) >= 0)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
goto err;
}
if (form == POINT_CONVERSION_COMPRESSED)
{
if (!EC_POINT_set_compressed_coordinates_GF2m(group, point, x, y_bit, ctx)) goto err;
}
else
{
if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err;
if (BN_ucmp(y, &group->field) >= 0)
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
goto err;
}
if (form == POINT_CONVERSION_HYBRID)
{
if (!group->meth->field_div(group, yxi, y, x, ctx)) goto err;
if (y_bit != BN_is_odd(yxi))
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);
goto err;
}
}
if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
}
if (!EC_POINT_is_on_curve(group, point, ctx)) /* test required by X9.62 */
{
ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);
goto err;
}
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
}
/* Computes a + b and stores the result in r. r could be a or b, a could be b.
* Uses algorithm A.10.2 of IEEE P1363.
*/
int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;
int ret = 0;
if (EC_POINT_is_at_infinity(group, a))
{
if (!EC_POINT_copy(r, b)) return 0;
return 1;
}
if (EC_POINT_is_at_infinity(group, b))
{
if (!EC_POINT_copy(r, a)) return 0;
return 1;
}
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
BN_CTX_start(ctx);
x0 = BN_CTX_get(ctx);
y0 = BN_CTX_get(ctx);
x1 = BN_CTX_get(ctx);
y1 = BN_CTX_get(ctx);
x2 = BN_CTX_get(ctx);
y2 = BN_CTX_get(ctx);
s = BN_CTX_get(ctx);
t = BN_CTX_get(ctx);
if (t == NULL) goto err;
if (a->Z_is_one)
{
if (!BN_copy(x0, &a->X)) goto err;
if (!BN_copy(y0, &a->Y)) goto err;
}
else
{
if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx)) goto err;
}
if (b->Z_is_one)
{
if (!BN_copy(x1, &b->X)) goto err;
if (!BN_copy(y1, &b->Y)) goto err;
}
else
{
if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx)) goto err;
}
if (BN_GF2m_cmp(x0, x1))
{
if (!BN_GF2m_add(t, x0, x1)) goto err;
if (!BN_GF2m_add(s, y0, y1)) goto err;
if (!group->meth->field_div(group, s, s, t, ctx)) goto err;
if (!group->meth->field_sqr(group, x2, s, ctx)) goto err;
if (!BN_GF2m_add(x2, x2, &group->a)) goto err;
if (!BN_GF2m_add(x2, x2, s)) goto err;
if (!BN_GF2m_add(x2, x2, t)) goto err;
}
else
{
if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1))
{
if (!EC_POINT_set_to_infinity(group, r)) goto err;
ret = 1;
goto err;
}
if (!group->meth->field_div(group, s, y1, x1, ctx)) goto err;
if (!BN_GF2m_add(s, s, x1)) goto err;
if (!group->meth->field_sqr(group, x2, s, ctx)) goto err;
if (!BN_GF2m_add(x2, x2, s)) goto err;
if (!BN_GF2m_add(x2, x2, &group->a)) goto err;
}
if (!BN_GF2m_add(y2, x1, x2)) goto err;
if (!group->meth->field_mul(group, y2, y2, s, ctx)) goto err;
if (!BN_GF2m_add(y2, y2, x2)) goto err;
if (!BN_GF2m_add(y2, y2, y1)) goto err;
if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
}
/* Computes 2 * a and stores the result in r. r could be a.
* Uses algorithm A.10.2 of IEEE P1363.
*/
int ec_GF2m_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
{
return ec_GF2m_simple_add(group, r, a, a, ctx);
}
int ec_GF2m_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
{
if (EC_POINT_is_at_infinity(group, point) || BN_is_zero(&point->Y))
/* point is its own inverse */
return 1;
if (!EC_POINT_make_affine(group, point, ctx)) return 0;
return BN_GF2m_add(&point->Y, &point->X, &point->Y);
}
/* Indicates whether the given point is the point at infinity. */
int ec_GF2m_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
{
return BN_is_zero(&point->Z);
}
/* Determines whether the given EC_POINT is an actual point on the curve defined
* in the EC_GROUP. A point is valid if it satisfies the Weierstrass equation:
* y^2 + x*y = x^3 + a*x^2 + b.
*/
int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
BIGNUM *rh, *lh, *tmp1;
int ret = -1;
if (EC_POINT_is_at_infinity(group, point))
return 1;
/* only support affine coordinates */
if (!point->Z_is_one) goto err;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return -1;
}
BN_CTX_start(ctx);
rh = BN_CTX_get(ctx);
lh = BN_CTX_get(ctx);
tmp1 = BN_CTX_get(ctx);
if (tmp1 == NULL) goto err;
/* We have a curve defined by a Weierstrass equation
* y^2 + x*y = x^3 + a*x^2 + b.
* To test this, we add up the right-hand side in 'rh'
* and the left-hand side in 'lh'.
*/
/* rh := X^3 */
if (!group->meth->field_sqr(group, tmp1, &point->X, ctx)) goto err;
if (!group->meth->field_mul(group, rh, tmp1, &point->X, ctx)) goto err;
/* rh := rh + a*X^2 */
if (!group->meth->field_mul(group, tmp1, tmp1, &group->a, ctx)) goto err;
if (!BN_GF2m_add(rh, rh, tmp1)) goto err;
/* rh := rh + b */
if (!BN_GF2m_add(rh, rh, &group->b)) goto err;
/* lh := Y^2 */
if (!group->meth->field_sqr(group, lh, &point->Y, ctx)) goto err;
/* lh := lh + x*y */
if (!group->meth->field_mul(group, tmp1, &point->X, &point->Y, ctx)) goto err;
if (!BN_GF2m_add(lh, lh, tmp1)) goto err;
ret = (0 == BN_GF2m_cmp(lh, rh));
err:
if (ctx) BN_CTX_end(ctx);
if (new_ctx) BN_CTX_free(new_ctx);
return ret;
}
/* Indicates whether two points are equal.
* Return values:
* -1 error
* 0 equal (in affine coordinates)
* 1 not equal
*/
int ec_GF2m_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
{
BIGNUM *aX, *aY, *bX, *bY;
BN_CTX *new_ctx = NULL;
int ret = -1;
if (EC_POINT_is_at_infinity(group, a))
{
return EC_POINT_is_at_infinity(group, b) ? 0 : 1;
}
if (a->Z_is_one && b->Z_is_one)
{
return ((BN_cmp(&a->X, &b->X) == 0) && BN_cmp(&a->Y, &b->Y) == 0) ? 0 : 1;
}
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return -1;
}
BN_CTX_start(ctx);
aX = BN_CTX_get(ctx);
aY = BN_CTX_get(ctx);
bX = BN_CTX_get(ctx);
bY = BN_CTX_get(ctx);
if (bY == NULL) goto err;
if (!EC_POINT_get_affine_coordinates_GF2m(group, a, aX, aY, ctx)) goto err;
if (!EC_POINT_get_affine_coordinates_GF2m(group, b, bX, bY, ctx)) goto err;
ret = ((BN_cmp(aX, bX) == 0) && BN_cmp(aY, bY) == 0) ? 0 : 1;
err:
if (ctx) BN_CTX_end(ctx);
if (new_ctx) BN_CTX_free(new_ctx);
return ret;
}
/* Forces the given EC_POINT to internally use affine coordinates. */
int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
BIGNUM *x, *y;
int ret = 0;
if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))
return 1;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
BN_CTX_start(ctx);
x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
if (y == NULL) goto err;
if (!EC_POINT_get_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
if (!BN_copy(&point->X, x)) goto err;
if (!BN_copy(&point->Y, y)) goto err;
if (!BN_one(&point->Z)) goto err;
ret = 1;
err:
if (ctx) BN_CTX_end(ctx);
if (new_ctx) BN_CTX_free(new_ctx);
return ret;
}
/* Forces each of the EC_POINTs in the given array to use affine coordinates. */
int ec_GF2m_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
{
size_t i;
for (i = 0; i < num; i++)
{
if (!group->meth->make_affine(group, points[i], ctx)) return 0;
}
return 1;
}
/* Wrapper to simple binary polynomial field multiplication implementation. */
int ec_GF2m_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
return BN_GF2m_mod_mul_arr(r, a, b, group->poly, ctx);
}
/* Wrapper to simple binary polynomial field squaring implementation. */
int ec_GF2m_simple_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
{
return BN_GF2m_mod_sqr_arr(r, a, group->poly, ctx);
}
/* Wrapper to simple binary polynomial field division implementation. */
int ec_GF2m_simple_field_div(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
return BN_GF2m_mod_div(r, a, b, &group->field, ctx);
}

View File

@ -1,125 +0,0 @@
/* crypto/ec/ec2_smpt.c */
/* This code was originally written by Douglas Stebila
* <dstebila@student.math.uwaterloo.ca> for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
/* Calaculates and sets the affine coordinates of an EC_POINT from the given
* compressed coordinates. Uses algorithm 2.3.4 of SEC 1.
* Note that the simple implementation only uses affine coordinates.
*
* This algorithm is patented by Certicom Corp. under US Patent 6,141,420.
* This function is disabled by default and can be enabled by defining the
* preprocessor macro OPENSSL_EC_BIN_PT_COMP at Configure-time.
*/
int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x_, int y_bit, BN_CTX *ctx)
{
#ifndef OPENSSL_EC_BIN_PT_COMP
ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_DISABLED);
return 0;
#else
BN_CTX *new_ctx = NULL;
BIGNUM *tmp, *x, *y, *z;
int ret = 0, z0;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
return 0;
}
y_bit = (y_bit != 0) ? 1 : 0;
BN_CTX_start(ctx);
tmp = BN_CTX_get(ctx);
x = BN_CTX_get(ctx);
y = BN_CTX_get(ctx);
z = BN_CTX_get(ctx);
if (z == NULL) goto err;
if (!BN_GF2m_mod_arr(x, x_, group->poly)) goto err;
if (BN_is_zero(x))
{
if (!BN_GF2m_mod_sqrt_arr(y, &group->b, group->poly, ctx)) goto err;
}
else
{
if (!group->meth->field_sqr(group, tmp, x, ctx)) goto err;
if (!group->meth->field_div(group, tmp, &group->b, tmp, ctx)) goto err;
if (!BN_GF2m_add(tmp, &group->a, tmp)) goto err;
if (!BN_GF2m_add(tmp, x, tmp)) goto err;
if (!BN_GF2m_mod_solve_quad_arr(z, tmp, group->poly, ctx)) goto err;
z0 = (BN_is_odd(z)) ? 1 : 0;
if (!group->meth->field_mul(group, y, x, z, ctx)) goto err;
if (z0 != y_bit)
{
if (!BN_GF2m_add(y, y, x)) goto err;
}
}
if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx)) goto err;
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -1,122 +0,0 @@
/* crypto/ec/ec_check.c */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include "ec_lcl.h"
#include <openssl/err.h>
int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
{
int ret = 0;
BIGNUM *order;
BN_CTX *new_ctx = NULL;
EC_POINT *point = NULL;
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
{
ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);
goto err;
}
}
BN_CTX_start(ctx);
if ((order = BN_CTX_get(ctx)) == NULL) goto err;
/* check the discriminant */
if (!EC_GROUP_check_discriminant(group, ctx))
{
ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);
goto err;
}
/* check the generator */
if (group->generator == NULL)
{
ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);
goto err;
}
if (!EC_POINT_is_on_curve(group, group->generator, ctx))
{
ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);
goto err;
}
/* check the order of the generator */
if ((point = EC_POINT_new(group)) == NULL) goto err;
if (!EC_GROUP_get_order(group, order, ctx)) goto err;
if (BN_is_zero(order))
{
ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);
goto err;
}
if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err;
if (!EC_POINT_is_at_infinity(group, point))
{
ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);
goto err;
}
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
if (point)
EC_POINT_free(point);
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,6 @@
/* crypto/ec/ec_cvt.c */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -55,21 +52,7 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The elliptic curve binary polynomial software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#include <openssl/err.h>
#include "ec_lcl.h"
@ -77,64 +60,17 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM
{
const EC_METHOD *meth;
EC_GROUP *ret;
meth = EC_GFp_nist_method();
/* Finally, this will use EC_GFp_nist_method if 'p' is a special
* prime with optimized modular arithmetics (for NIST curves)
*/
meth = EC_GFp_mont_method();
ret = EC_GROUP_new(meth);
if (ret == NULL)
return NULL;
if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
{
unsigned long err;
err = ERR_peek_last_error();
if (!(ERR_GET_LIB(err) == ERR_LIB_EC &&
((ERR_GET_REASON(err) == EC_R_NOT_A_NIST_PRIME) ||
(ERR_GET_REASON(err) == EC_R_NOT_A_SUPPORTED_NIST_PRIME))))
{
/* real error */
EC_GROUP_clear_free(ret);
return NULL;
}
/* not an actual error, we just cannot use EC_GFp_nist_method */
ERR_clear_error();
EC_GROUP_clear_free(ret);
meth = EC_GFp_mont_method();
ret = EC_GROUP_new(meth);
if (ret == NULL)
return NULL;
if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
{
EC_GROUP_clear_free(ret);
return NULL;
}
}
return ret;
}
EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
const EC_METHOD *meth;
EC_GROUP *ret;
meth = EC_GF2m_simple_method();
ret = EC_GROUP_new(meth);
if (ret == NULL)
return NULL;
if (!EC_GROUP_set_curve_GF2m(ret, p, a, b, ctx))
{
EC_GROUP_clear_free(ret);
return NULL;

View File

@ -1,6 +1,6 @@
/* crypto/ec/ec_err.c */
/* ====================================================================
* Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
* 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
@ -67,151 +67,69 @@
static ERR_STRING_DATA EC_str_functs[]=
{
{ERR_PACK(0,EC_F_COMPUTE_WNAF,0), "COMPUTE_WNAF"},
{ERR_PACK(0,EC_F_D2I_ECPARAMETERS,0), "d2i_ECParameters"},
{ERR_PACK(0,EC_F_D2I_ECPKPARAMETERS,0), "d2i_ECPKParameters"},
{ERR_PACK(0,EC_F_D2I_ECPRIVATEKEY,0), "d2i_ECPrivateKey"},
{ERR_PACK(0,EC_F_ECPARAMETERS_PRINT,0), "ECParameters_print"},
{ERR_PACK(0,EC_F_ECPARAMETERS_PRINT_FP,0), "ECParameters_print_fp"},
{ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT,0), "ECPKParameters_print"},
{ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT_FP,0), "ECPKParameters_print_fp"},
{ERR_PACK(0,EC_F_ECPUBLICKEY_GET_OCTET,0), "ECPUBLICKEY_GET_OCTET"},
{ERR_PACK(0,EC_F_ECPUBLICKEY_SET_OCTET,0), "ECPUBLICKEY_SET_OCTET"},
{ERR_PACK(0,EC_F_ECP_NIST_MOD_192,0), "ECP_NIST_MOD_192"},
{ERR_PACK(0,EC_F_ECP_NIST_MOD_224,0), "ECP_NIST_MOD_224"},
{ERR_PACK(0,EC_F_ECP_NIST_MOD_256,0), "ECP_NIST_MOD_256"},
{ERR_PACK(0,EC_F_ECP_NIST_MOD_521,0), "ECP_NIST_MOD_521"},
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2CURVE,0), "EC_ASN1_GROUP2CURVE"},
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2FIELDID,0), "EC_ASN1_GROUP2FIELDID"},
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PARAMETERS,0), "EC_ASN1_GROUP2PARAMETERS"},
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PKPARAMETERS,0), "EC_ASN1_GROUP2PKPARAMETERS"},
{ERR_PACK(0,EC_F_EC_ASN1_PARAMETERS2GROUP,0), "EC_ASN1_PARAMETERS2GROUP"},
{ERR_PACK(0,EC_F_EC_ASN1_PKPARAMETERS2GROUP,0), "EC_ASN1_PKPARAMETERS2GROUP"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT,0), "ec_GF2m_simple_group_check_discriminant"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE,0), "ec_GF2m_simple_group_set_curve"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_OCT2POINT,0), "ec_GF2m_simple_oct2point"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_POINT2OCT,0), "ec_GF2m_simple_point2oct"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES,0), "ec_GF2m_simple_point_get_affine_coordinates"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES,0), "ec_GF2m_simple_point_set_affine_coordinates"},
{ERR_PACK(0,EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES,0), "ec_GF2m_simple_set_compressed_coordinates"},
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_DECODE,0), "ec_GFp_mont_field_decode"},
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_ENCODE,0), "ec_GFp_mont_field_encode"},
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_MUL,0), "ec_GFp_mont_field_mul"},
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_SQR,0), "ec_GFp_mont_field_sqr"},
{ERR_PACK(0,EC_F_EC_GFP_NIST_FIELD_MUL,0), "ec_GFp_nist_field_mul"},
{ERR_PACK(0,EC_F_EC_GFP_NIST_FIELD_SQR,0), "ec_GFp_nist_field_sqr"},
{ERR_PACK(0,EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP,0), "EC_GFP_NIST_GROUP_SET_CURVE_GFP"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT,0), "ec_GFp_simple_group_check_discriminant"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE,0), "ec_GFp_simple_group_set_curve"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP,0), "EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "EC_GFP_SIMPLE_GROUP_SET_GENERATOR"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP,0), "ec_GFp_simple_group_set_curve_GFp"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR,0), "ec_GFp_simple_group_set_generator"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_MAKE_AFFINE,0), "ec_GFp_simple_make_affine"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_OCT2POINT,0), "ec_GFp_simple_oct2point"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT2OCT,0), "ec_GFp_simple_point2oct"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE,0), "ec_GFp_simple_points_make_affine"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,0), "ec_GFp_simple_point_get_affine_coordinates"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP,0), "EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES,0), "ec_GFp_simple_point_set_affine_coordinates"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP,0), "EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,0), "ec_GFp_simple_set_compressed_coordinates"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP,0), "EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP"},
{ERR_PACK(0,EC_F_EC_GROUP_CHECK,0), "EC_GROUP_check"},
{ERR_PACK(0,EC_F_EC_GROUP_CHECK_DISCRIMINANT,0), "EC_GROUP_check_discriminant"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_get_affine_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP,0), "ec_GFp_simple_point_set_affine_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP,0), "ec_GFp_simple_set_compressed_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_GROUP_COPY,0), "EC_GROUP_copy"},
{ERR_PACK(0,EC_F_EC_GROUP_GET0_GENERATOR,0), "EC_GROUP_get0_generator"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GF2M,0), "EC_GROUP_get_curve_GF2m"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_DEGREE,0), "EC_GROUP_get_degree"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_EXTRA_DATA,0), "EC_GROUP_get_extra_data"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS,0), "EC_GROUP_get_pentanomial_basis"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_TRINOMIAL_BASIS,0), "EC_GROUP_get_trinomial_basis"},
{ERR_PACK(0,EC_F_EC_GROUP_GROUP2NID,0), "EC_GROUP_GROUP2NID"},
{ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"},
{ERR_PACK(0,EC_F_EC_GROUP_NEW_BY_NID,0), "EC_GROUP_new_by_nid"},
{ERR_PACK(0,EC_F_EC_GROUP_NEW_FROM_DATA,0), "EC_GROUP_NEW_FROM_DATA"},
{ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GF2M,0), "EC_GROUP_set_curve_GF2m"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GFP,0), "EC_GROUP_set_curve_GFp"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_EXTRA_DATA,0), "EC_GROUP_set_extra_data"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_GENERATOR,0), "EC_GROUP_set_generator"},
{ERR_PACK(0,EC_F_EC_KEY_CHECK_KEY,0), "EC_KEY_check_key"},
{ERR_PACK(0,EC_F_EC_KEY_COPY,0), "EC_KEY_copy"},
{ERR_PACK(0,EC_F_EC_KEY_GENERATE_KEY,0), "EC_KEY_generate_key"},
{ERR_PACK(0,EC_F_EC_KEY_PRINT,0), "EC_KEY_print"},
{ERR_PACK(0,EC_F_EC_KEY_PRINT_FP,0), "EC_KEY_print_fp"},
{ERR_PACK(0,EC_F_EC_NEW,0), "EC_NEW"},
{ERR_PACK(0,EC_F_EC_POINTS_MAKE_AFFINE,0), "EC_POINTs_make_affine"},
{ERR_PACK(0,EC_F_EC_POINTS_MUL,0), "EC_POINTs_mul"},
{ERR_PACK(0,EC_F_EC_POINT_ADD,0), "EC_POINT_add"},
{ERR_PACK(0,EC_F_EC_POINT_CMP,0), "EC_POINT_cmp"},
{ERR_PACK(0,EC_F_EC_POINT_COPY,0), "EC_POINT_copy"},
{ERR_PACK(0,EC_F_EC_POINT_DBL,0), "EC_POINT_dbl"},
{ERR_PACK(0,EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M,0), "EC_POINT_get_affine_coordinates_GF2m"},
{ERR_PACK(0,EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP,0), "EC_POINT_get_affine_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_get_Jprojective_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_POINT_IS_AT_INFINITY,0), "EC_POINT_is_at_infinity"},
{ERR_PACK(0,EC_F_EC_POINT_IS_ON_CURVE,0), "EC_POINT_is_on_curve"},
{ERR_PACK(0,EC_F_EC_POINT_MAKE_AFFINE,0), "EC_POINT_make_affine"},
{ERR_PACK(0,EC_F_EC_POINT_MUL,0), "EC_POINT_mul"},
{ERR_PACK(0,EC_F_EC_POINT_NEW,0), "EC_POINT_new"},
{ERR_PACK(0,EC_F_EC_POINT_OCT2POINT,0), "EC_POINT_oct2point"},
{ERR_PACK(0,EC_F_EC_POINT_POINT2OCT,0), "EC_POINT_point2oct"},
{ERR_PACK(0,EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M,0), "EC_POINT_set_affine_coordinates_GF2m"},
{ERR_PACK(0,EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP,0), "EC_POINT_set_affine_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,0), "EC_POINT_set_compressed_coordinates_GF2m"},
{ERR_PACK(0,EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP,0), "EC_POINT_set_compressed_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP,0), "EC_POINT_set_Jprojective_coordinates_GFp"},
{ERR_PACK(0,EC_F_EC_POINT_SET_TO_INFINITY,0), "EC_POINT_set_to_infinity"},
{ERR_PACK(0,EC_F_EC_WNAF_MUL,0), "ec_wNAF_mul"},
{ERR_PACK(0,EC_F_EC_WNAF_PRECOMPUTE_MULT,0), "ec_wNAF_precompute_mult"},
{ERR_PACK(0,EC_F_GFP_MONT_GROUP_SET_CURVE,0), "GFP_MONT_GROUP_SET_CURVE"},
{ERR_PACK(0,EC_F_GFP_MONT_GROUP_SET_CURVE_GFP,0), "GFP_MONT_GROUP_SET_CURVE_GFP"},
{ERR_PACK(0,EC_F_I2D_ECPARAMETERS,0), "i2d_ECParameters"},
{ERR_PACK(0,EC_F_I2D_ECPKPARAMETERS,0), "i2d_ECPKParameters"},
{ERR_PACK(0,EC_F_I2D_ECPRIVATEKEY,0), "i2d_ECPrivateKey"},
{0,NULL}
};
static ERR_STRING_DATA EC_str_reasons[]=
{
{EC_R_ASN1_ERROR ,"asn1 error"},
{EC_R_ASN1_UNKNOWN_FIELD ,"asn1 unknown field"},
{EC_R_BUFFER_TOO_SMALL ,"buffer too small"},
{EC_R_D2I_ECPKPARAMETERS_FAILURE ,"d2i ecpkparameters failure"},
{EC_R_DISCRIMINANT_IS_ZERO ,"discriminant is zero"},
{EC_R_EC_GROUP_NEW_BY_NAME_FAILURE ,"ec group new by name failure"},
{EC_R_GROUP2PKPARAMETERS_FAILURE ,"group2pkparameters failure"},
{EC_R_I2D_ECPKPARAMETERS_FAILURE ,"i2d ecpkparameters failure"},
{EC_R_INCOMPATIBLE_OBJECTS ,"incompatible objects"},
{EC_R_INTERNAL_ERROR ,"internal error"},
{EC_R_INVALID_ARGUMENT ,"invalid argument"},
{EC_R_INVALID_COMPRESSED_POINT ,"invalid compressed point"},
{EC_R_INVALID_COMPRESSION_BIT ,"invalid compression bit"},
{EC_R_INVALID_ENCODING ,"invalid encoding"},
{EC_R_INVALID_FIELD ,"invalid field"},
{EC_R_INVALID_FORM ,"invalid form"},
{EC_R_INVALID_GROUP_ORDER ,"invalid group order"},
{EC_R_INVALID_PRIVATE_KEY ,"invalid private key"},
{EC_R_MISSING_PARAMETERS ,"missing parameters"},
{EC_R_MISSING_PRIVATE_KEY ,"missing private key"},
{EC_R_NOT_A_NIST_PRIME ,"not a NIST prime"},
{EC_R_NOT_A_SUPPORTED_NIST_PRIME ,"not a supported NIST prime"},
{EC_R_NOT_IMPLEMENTED ,"not implemented"},
{EC_R_NOT_INITIALIZED ,"not initialized"},
{EC_R_NO_FIELD_MOD ,"no field mod"},
{EC_R_NO_SUCH_EXTRA_DATA ,"no such extra data"},
{EC_R_PASSED_NULL_PARAMETER ,"passed null parameter"},
{EC_R_PKPARAMETERS2GROUP_FAILURE ,"pkparameters2group failure"},
{EC_R_POINT_AT_INFINITY ,"point at infinity"},
{EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"},
{EC_R_SLOT_FULL ,"slot full"},
{EC_R_UNDEFINED_GENERATOR ,"undefined generator"},
{EC_R_UNDEFINED_ORDER ,"undefined order"},
{EC_R_UNKNOWN_GROUP ,"unknown group"},
{EC_R_UNKNOWN_ORDER ,"unknown order"},
{EC_R_UNSUPPORTED_FIELD ,"unsupported field"},
{EC_R_WRONG_ORDER ,"wrong order"},
{0,NULL}
};

View File

@ -1,377 +0,0 @@
/* crypto/ec/ec_key.c */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions originally developed by SUN MICROSYSTEMS, INC., and
* contributed to the OpenSSL project.
*/
#include <string.h>
#include "ec_lcl.h"
#include <openssl/err.h>
#include <string.h>
EC_KEY *EC_KEY_new(void)
{
EC_KEY *ret;
ret=(EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));
if (ret == NULL)
{
ECerr(EC_F_EC_NEW, ERR_R_MALLOC_FAILURE);
return(NULL);
}
ret->version = 1;
ret->group = NULL;
ret->pub_key = NULL;
ret->priv_key= NULL;
ret->enc_flag= 0;
ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;
ret->references= 1;
ret->meth_data = NULL;
return(ret);
}
void EC_KEY_free(EC_KEY *r)
{
int i;
if (r == NULL) return;
i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_EC);
#ifdef REF_PRINT
REF_PRINT("EC_KEY",r);
#endif
if (i > 0) return;
#ifdef REF_CHECK
if (i < 0)
{
fprintf(stderr,"EC_KEY_free, bad reference count\n");
abort();
}
#endif
if (r->group != NULL)
EC_GROUP_free(r->group);
if (r->pub_key != NULL)
EC_POINT_free(r->pub_key);
if (r->priv_key != NULL)
BN_clear_free(r->priv_key);
if (r->meth_data && r->meth_data->finish)
r->meth_data->finish(r);
memset((void *)r, 0x0, sizeof(EC_KEY));
OPENSSL_free(r);
}
EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
{
if (dest == NULL || src == NULL)
{
ECerr(EC_F_EC_KEY_COPY, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
/* copy the parameters */
if (src->group)
{
const EC_METHOD *meth = EC_GROUP_method_of(src->group);
/* clear the old group */
if (dest->group)
EC_GROUP_free(dest->group);
dest->group = EC_GROUP_new(meth);
if (dest->group == NULL)
return NULL;
if (!EC_GROUP_copy(dest->group, src->group))
return NULL;
}
/* copy the public key */
if (src->pub_key && src->group)
{
if (dest->pub_key)
EC_POINT_free(dest->pub_key);
dest->pub_key = EC_POINT_new(src->group);
if (dest->pub_key == NULL)
return NULL;
if (!EC_POINT_copy(dest->pub_key, src->pub_key))
return NULL;
}
/* copy the private key */
if (src->priv_key)
{
if (dest->priv_key == NULL)
{
dest->priv_key = BN_new();
if (dest->priv_key == NULL)
return NULL;
}
if (!BN_copy(dest->priv_key, src->priv_key))
return NULL;
}
/* copy the rest */
dest->enc_flag = src->enc_flag;
dest->conv_form = src->conv_form;
dest->version = src->version;
return dest;
}
EC_KEY *EC_KEY_dup(const EC_KEY *eckey)
{
EC_KEY *ret = NULL;
int ok = 1;
ret = EC_KEY_new();
if (ret == NULL)
return NULL;
/* copy the parameters */
if (eckey->group)
{
ret->group = EC_GROUP_dup(eckey->group);
if (ret->group == NULL)
ok = 0;
}
/* copy the public key */
if (eckey->pub_key && eckey->group)
{
ret->pub_key = EC_POINT_dup(eckey->pub_key, eckey->group);
if (ret->pub_key == NULL)
ok = 0;
}
/* copy the private key */
if (eckey->priv_key)
{
ret->priv_key = BN_dup(ret->priv_key);
if (ret->priv_key == NULL)
ok = 0;
}
/* copy the rest */
ret->enc_flag = eckey->enc_flag;
ret->conv_form = eckey->conv_form;
ret->version = eckey->version;
if (!ok)
{
EC_KEY_free(ret);
ret = NULL;
}
return ret;
}
int EC_KEY_up_ref(EC_KEY *r)
{
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
#ifdef REF_PRINT
REF_PRINT("EC_KEY",r);
#endif
#ifdef REF_CHECK
if (i < 2)
{
fprintf(stderr, "EC_KEY_up, bad reference count\n");
abort();
}
#endif
return ((i > 1) ? 1 : 0);
}
int EC_KEY_generate_key(EC_KEY *eckey)
{
int ok = 0;
BN_CTX *ctx = NULL;
BIGNUM *priv_key = NULL, *order = NULL;
EC_POINT *pub_key = NULL;
if (!eckey || !eckey->group)
{
ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if ((order = BN_new()) == NULL) goto err;
if ((ctx = BN_CTX_new()) == NULL) goto err;
if (eckey->priv_key == NULL)
{
priv_key = BN_new();
if (priv_key == NULL)
goto err;
}
else
priv_key = eckey->priv_key;
if (!EC_GROUP_get_order(eckey->group, order, ctx))
goto err;
do
if (!BN_rand_range(priv_key, order))
goto err;
while (BN_is_zero(priv_key));
if (eckey->pub_key == NULL)
{
pub_key = EC_POINT_new(eckey->group);
if (pub_key == NULL)
goto err;
}
else
pub_key = eckey->pub_key;
if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
goto err;
eckey->priv_key = priv_key;
eckey->pub_key = pub_key;
ok=1;
err:
if (order)
BN_free(order);
if (pub_key != NULL && eckey->pub_key == NULL)
EC_POINT_free(pub_key);
if (priv_key != NULL && eckey->priv_key == NULL)
BN_free(priv_key);
if (ctx != NULL)
BN_CTX_free(ctx);
return(ok);
}
int EC_KEY_check_key(const EC_KEY *eckey)
{
int ok = 0;
BN_CTX *ctx = NULL;
BIGNUM *order = NULL;
EC_POINT *point = NULL;
if (!eckey || !eckey->group || !eckey->pub_key)
{
ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if ((ctx = BN_CTX_new()) == NULL)
goto err;
if ((order = BN_new()) == NULL)
goto err;
if ((point = EC_POINT_new(eckey->group)) == NULL)
goto err;
/* testing whether the pub_key is on the elliptic curve */
if (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);
goto err;
}
/* testing whether pub_key * order is the point at infinity */
if (!EC_GROUP_get_order(eckey->group, order, ctx))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
goto err;
}
if (!EC_POINT_copy(point, eckey->pub_key))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
goto err;
}
if (!EC_POINT_mul(eckey->group, point, order, NULL, NULL, ctx))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
goto err;
}
if (!EC_POINT_is_at_infinity(eckey->group, point))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
goto err;
}
/* in case the priv_key is present :
* check if generator * priv_key == pub_key
*/
if (eckey->priv_key)
{
if (BN_cmp(eckey->priv_key, order) >= 0)
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);
goto err;
}
if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
NULL, NULL, ctx))
{
ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);
goto err;
}
if (EC_POINT_cmp(eckey->group, point, eckey->pub_key,
ctx) != 0)
{
ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY);
goto err;
}
}
ok = 1;
err:
if (ctx != NULL)
BN_CTX_free(ctx);
if (order != NULL)
BN_free(order);
if (point != NULL)
EC_POINT_free(point);
return(ok);
}

View File

@ -1,7 +1,4 @@
/* crypto/ec/ec_lcl.h */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
*
@ -55,24 +52,10 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The elliptic curve binary polynomial software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#include <stdlib.h>
#include <openssl/obj_mac.h>
#include <openssl/ec.h>
@ -80,25 +63,24 @@
* so all this may change in future versions. */
struct ec_method_st {
/* used by EC_METHOD_get_field_type: */
int field_type; /* a NID */
/* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
int (*group_init)(EC_GROUP *);
void (*group_finish)(EC_GROUP *);
void (*group_clear_finish)(EC_GROUP *);
int (*group_copy)(EC_GROUP *, const EC_GROUP *);
/* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */
/* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */
int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
/* used by EC_GROUP_set_curve_GFp and EC_GROUP_get_curve_GFp: */
int (*group_set_curve_GFp)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int (*group_get_curve_GFp)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
/* used by EC_GROUP_get_degree: */
int (*group_get_degree)(const EC_GROUP *);
/* used by EC_GROUP_check: */
int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *);
/* used by EC_GROUP_set_generator, EC_GROUP_get0_generator,
* EC_GROUP_get_order, EC_GROUP_get_cofactor:
*/
int (*group_set_generator)(EC_GROUP *, const EC_POINT *generator,
const BIGNUM *order, const BIGNUM *cofactor);
EC_POINT *(*group_get0_generator)(const EC_GROUP *);
int (*group_get_order)(const EC_GROUP *, BIGNUM *order, BN_CTX *);
int (*group_get_cofactor)(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
/* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
int (*point_init)(EC_POINT *);
@ -107,22 +89,20 @@ struct ec_method_st {
int (*point_copy)(EC_POINT *, const EC_POINT *);
/* used by EC_POINT_set_to_infinity,
* EC_POINT_set_Jprojective_coordinates_GFp,
* EC_POINT_get_Jprojective_coordinates_GFp,
* EC_POINT_set_affine_coordinates_GFp, ..._GF2m,
* EC_POINT_get_affine_coordinates_GFp, ..._GF2m,
* EC_POINT_set_compressed_coordinates_GFp, ..._GF2m:
* EC_POINT_set_Jprojective_coordinates_GFp, EC_POINT_get_Jprojective_coordinates_GFp,
* EC_POINT_set_affine_coordinates_GFp, EC_POINT_get_affine_coordinates_GFp,
* EC_POINT_set_compressed_coordinates_GFp:
*/
int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *,
int (*point_set_affine_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *,
int (*point_get_affine_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BN_CTX *);
int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *,
int (*point_set_compressed_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, int y_bit, BN_CTX *);
/* used by EC_POINT_point2oct, EC_POINT_oct2point: */
@ -136,11 +116,6 @@ struct ec_method_st {
int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *);
/* used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult: */
int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
int (*precompute_mult)(EC_GROUP *group, BN_CTX *);
/* used by EC_POINT_is_at_infinity, EC_POINT_is_on_curve, EC_POINT_cmp: */
int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *);
int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *);
@ -153,12 +128,11 @@ struct ec_method_st {
/* internal functions */
/* 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 'dbl' so that
/* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
* the same implementations of point operations can be used with different
* optimized implementations of expensive field operations: */
int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
@ -169,35 +143,16 @@ struct ec_method_st {
struct ec_group_st {
const EC_METHOD *meth;
EC_POINT *generator; /* optional */
BIGNUM order, cofactor;
int curve_name;/* optional NID for named curve */
int asn1_flag; /* flag to control the asn1 encoding */
point_conversion_form_t asn1_form;
unsigned char *seed; /* optional seed for parameters (appears in ASN1) */
size_t seed_len;
void *extra_data;
void *(*extra_data_dup_func)(void *);
void (*extra_data_free_func)(void *);
void (*extra_data_clear_free_func)(void *);
/* The following members are handled by the method functions,
* even if they appear generic */
/* All members except 'meth' and 'extra_data...' are handled by
* the method functions, even if they appear generic */
BIGNUM field; /* Field specification.
* For curves over GF(p), this is the modulus;
* for curves over GF(2^m), this is the
* irreducible polynomial defining the field.
*/
unsigned int poly[5]; /* Field specification for curves over GF(2^m).
* The irreducible f(t) is then of the form:
* t^poly[0] + t^poly[1] + ... + t^poly[k]
* where m = poly[0] > poly[1] > ... > poly[k] = 0.
*/
* For curves over GF(p), this is the modulus. */
BIGNUM a, b; /* Curve coefficients.
* (Here the assumption is that BIGNUMs can be used
@ -205,16 +160,14 @@ struct ec_group_st {
* For characteristic > 3, the curve is defined
* by a Weierstrass equation of the form
* y^2 = x^3 + a*x + b.
* For characteristic 2, the curve is defined by
* an equation of the form
* y^2 + x*y = x^3 + a*x^2 + b.
*/
int a_is_minus3; /* enable optimized point arithmetics for special case */
EC_POINT *generator; /* optional */
BIGNUM order, cofactor;
void *field_data1; /* method-specific (e.g., Montgomery structure) */
void *field_data2; /* method-specific */
int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); /* method-specific */
} /* EC_GROUP */;
@ -248,20 +201,18 @@ struct ec_point_st {
/* method functions in ec_mult.c */
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *);
/* method functions in ecp_smpl.c */
int ec_GFp_simple_group_init(EC_GROUP *);
void ec_GFp_simple_group_finish(EC_GROUP *);
void ec_GFp_simple_group_clear_finish(EC_GROUP *);
int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
int ec_GFp_simple_group_get_degree(const EC_GROUP *);
int ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
int ec_GFp_simple_group_set_generator(EC_GROUP *, const EC_POINT *generator,
const BIGNUM *order, const BIGNUM *cofactor);
EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *);
int ec_GFp_simple_group_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
int ec_GFp_simple_group_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
int ec_GFp_simple_point_init(EC_POINT *);
void ec_GFp_simple_point_finish(EC_POINT *);
void ec_GFp_simple_point_clear_finish(EC_POINT *);
@ -271,11 +222,11 @@ int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *,
int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BN_CTX *);
int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, int y_bit, BN_CTX *);
size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
unsigned char *buf, size_t len, BN_CTX *);
@ -295,7 +246,7 @@ int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX
/* method functions in ecp_mont.c */
int ec_GFp_mont_group_init(EC_GROUP *);
int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_mont_group_finish(EC_GROUP *);
void ec_GFp_mont_group_clear_finish(EC_GROUP *);
int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
@ -308,7 +259,7 @@ int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
/* method functions in ecp_recp.c */
int ec_GFp_recp_group_init(EC_GROUP *);
int ec_GFp_recp_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_recp_group_finish(EC_GROUP *);
void ec_GFp_recp_group_clear_finish(EC_GROUP *);
int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
@ -318,52 +269,9 @@ int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *
/* method functions in ecp_nist.c */
int ec_GFp_nist_group_init(EC_GROUP *);
int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
void ec_GFp_nist_group_finish(EC_GROUP *);
void ec_GFp_nist_group_clear_finish(EC_GROUP *);
int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
/* method functions in ec2_smpl.c */
int ec_GF2m_simple_group_init(EC_GROUP *);
void ec_GF2m_simple_group_finish(EC_GROUP *);
void ec_GF2m_simple_group_clear_finish(EC_GROUP *);
int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *);
int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
int ec_GF2m_simple_group_get_degree(const EC_GROUP *);
int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
int ec_GF2m_simple_point_init(EC_POINT *);
void ec_GF2m_simple_point_finish(EC_POINT *);
void ec_GF2m_simple_point_clear_finish(EC_POINT *);
int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *);
int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, const BIGNUM *y, BN_CTX *);
int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *,
BIGNUM *x, BIGNUM *y, BN_CTX *);
int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
const BIGNUM *x, int y_bit, BN_CTX *);
size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
unsigned char *buf, size_t len, BN_CTX *);
int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *,
const unsigned char *buf, size_t len, BN_CTX *);
int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
/* method functions in ec2_mult.c */
int ec_GF2m_mont_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
int ec_GF2m_mont_precompute_mult(EC_GROUP *group, BN_CTX *ctx);

View File

@ -1,9 +1,6 @@
/* crypto/ec/ec_lib.c */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -55,11 +52,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Binary polynomial ECC support in OpenSSL originally developed by
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#include <string.h>
@ -101,18 +93,7 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
ret->extra_data_dup_func = 0;
ret->extra_data_free_func = 0;
ret->extra_data_clear_free_func = 0;
ret->generator = NULL;
BN_init(&ret->order);
BN_init(&ret->cofactor);
ret->curve_name = 0;
ret->asn1_flag = 0;
ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
ret->seed = NULL;
ret->seed_len = 0;
if (!meth->group_init(ret))
{
OPENSSL_free(ret);
@ -132,14 +113,6 @@ void EC_GROUP_free(EC_GROUP *group)
EC_GROUP_free_extra_data(group);
if (group->generator != NULL)
EC_POINT_free(group->generator);
BN_free(&group->order);
BN_free(&group->cofactor);
if (group->seed)
OPENSSL_free(group->seed);
OPENSSL_free(group);
}
@ -155,17 +128,6 @@ void EC_GROUP_clear_free(EC_GROUP *group)
EC_GROUP_clear_free_extra_data(group);
if (group->generator != NULL)
EC_POINT_clear_free(group->generator);
BN_clear_free(&group->order);
BN_clear_free(&group->cofactor);
if (group->seed)
{
memset(group->seed, 0, group->seed_len);
OPENSSL_free(group->seed);
}
memset(group, 0, sizeof *group);
OPENSSL_free(group);
}
@ -201,276 +163,79 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
}
if (src->generator != NULL)
{
if (dest->generator == NULL)
{
dest->generator = EC_POINT_new(dest);
if (dest->generator == NULL) return 0;
}
if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
}
else
{
/* src->generator == NULL */
if (dest->generator != NULL)
{
EC_POINT_clear_free(dest->generator);
dest->generator = NULL;
}
}
if (!BN_copy(&dest->order, &src->order)) return 0;
if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
dest->curve_name = src->curve_name;
dest->asn1_flag = src->asn1_flag;
dest->asn1_form = src->asn1_form;
if (src->seed)
{
if (dest->seed)
OPENSSL_free(dest->seed);
dest->seed = OPENSSL_malloc(src->seed_len);
if (dest->seed == NULL)
return 0;
if (!memcpy(dest->seed, src->seed, src->seed_len))
return 0;
dest->seed_len = src->seed_len;
}
else
{
if (dest->seed)
OPENSSL_free(dest->seed);
dest->seed = NULL;
dest->seed_len = 0;
}
return dest->meth->group_copy(dest, src);
}
EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)
{
EC_GROUP *t = NULL;
int ok = 0;
if (a == NULL) return NULL;
if ((t = EC_GROUP_new(a->meth)) == NULL) return(NULL);
if (!EC_GROUP_copy(t, a)) goto err;
ok = 1;
err:
if (!ok)
{
if (t) EC_GROUP_free(t);
return NULL;
}
else return t;
}
const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
{
return group->meth;
}
int EC_METHOD_get_field_type(const EC_METHOD *meth)
{
return meth->field_type;
}
int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
{
if (generator == NULL)
{
ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
return 0 ;
}
if (group->generator == NULL)
{
group->generator = EC_POINT_new(group);
if (group->generator == NULL) return 0;
}
if (!EC_POINT_copy(group->generator, generator)) return 0;
if (order != NULL)
{ if (!BN_copy(&group->order, order)) return 0; }
else
{ if (!BN_zero(&group->order)) return 0; }
if (cofactor != NULL)
{ if (!BN_copy(&group->cofactor, cofactor)) return 0; }
else
{ if (!BN_zero(&group->cofactor)) return 0; }
return 1;
}
EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
{
return group->generator;
}
int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
{
if (!BN_copy(order, &group->order))
return 0;
return !BN_is_zero(order);
}
int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
{
if (!BN_copy(cofactor, &group->cofactor))
return 0;
return !BN_is_zero(&group->cofactor);
}
void EC_GROUP_set_nid(EC_GROUP *group, int nid)
{
group->curve_name = nid;
}
int EC_GROUP_get_nid(const EC_GROUP *group)
{
return group->curve_name;
}
void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag)
{
group->asn1_flag = flag;
}
int EC_GROUP_get_asn1_flag(const EC_GROUP *group)
{
return group->asn1_flag;
}
void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
point_conversion_form_t form)
{
group->asn1_form = form;
}
point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *group)
{
return group->asn1_form;
}
size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
{
if (group->seed)
{
OPENSSL_free(group->seed);
group->seed = NULL;
group->seed_len = 0;
}
if (!len || !p)
return 1;
if ((group->seed = OPENSSL_malloc(len)) == NULL)
return 0;
memcpy(group->seed, p, len);
group->seed_len = len;
return len;
}
unsigned char *EC_GROUP_get0_seed(const EC_GROUP *group)
{
return group->seed;
}
size_t EC_GROUP_get_seed_len(const EC_GROUP *group)
{
return group->seed_len;
}
int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
if (group->meth->group_set_curve == 0)
if (group->meth->group_set_curve_GFp == 0)
{
ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_set_curve(group, p, a, b, ctx);
return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
}
int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
{
if (group->meth->group_get_curve == 0)
if (group->meth->group_get_curve_GFp == 0)
{
ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_get_curve(group, p, a, b, ctx);
return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
}
int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
{
if (group->meth->group_set_curve == 0)
if (group->meth->group_set_generator == 0)
{
ECerr(EC_F_EC_GROUP_SET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_set_curve(group, p, a, b, ctx);
return group->meth->group_set_generator(group, generator, order, cofactor);
}
int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
{
if (group->meth->group_get_curve == 0)
if (group->meth->group_get0_generator == 0)
{
ECerr(EC_F_EC_GROUP_GET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_get_curve(group, p, a, b, ctx);
return group->meth->group_get0_generator(group);
}
int EC_GROUP_get_degree(const EC_GROUP *group)
int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
{
if (group->meth->group_get_degree == 0)
if (group->meth->group_get_order == 0)
{
ECerr(EC_F_EC_GROUP_GET_DEGREE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_get_degree(group);
return group->meth->group_get_order(group, order, ctx);
}
int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
{
if (group->meth->group_check_discriminant == 0)
if (group->meth->group_get_cofactor == 0)
{
ECerr(EC_F_EC_GROUP_CHECK_DISCRIMINANT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
return group->meth->group_check_discriminant(group, ctx);
return group->meth->group_get_cofactor(group, cofactor, ctx);
}
@ -537,6 +302,7 @@ void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
}
/* functions for EC_POINT objects */
EC_POINT *EC_POINT_new(const EC_GROUP *group)
@ -614,25 +380,6 @@ int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
}
EC_POINT *EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group)
{
EC_POINT *t;
int r;
if (a == NULL) return NULL;
t = EC_POINT_new(group);
if (t == NULL) return(NULL);
r = EC_POINT_copy(t, a);
if (!r)
{
EC_POINT_free(t);
return NULL;
}
else return t;
}
const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
{
return point->meth;
@ -692,7 +439,7 @@ int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POI
int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
{
if (group->meth->point_set_affine_coordinates == 0)
if (group->meth->point_set_affine_coordinates_GFp == 0)
{
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
@ -702,31 +449,14 @@ int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
}
int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
{
if (group->meth->point_set_affine_coordinates == 0)
{
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (group->meth != point->meth)
{
ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
}
int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
if (group->meth->point_get_affine_coordinates == 0)
if (group->meth->point_get_affine_coordinates_GFp == 0)
{
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
@ -736,31 +466,14 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *p
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
}
int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
if (group->meth->point_get_affine_coordinates == 0)
{
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (group->meth != point->meth)
{
ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
}
int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, int y_bit, BN_CTX *ctx)
{
if (group->meth->point_set_compressed_coordinates == 0)
if (group->meth->point_set_compressed_coordinates_GFp == 0)
{
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
@ -770,24 +483,7 @@ int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *poi
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx);
}
int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, int y_bit, BN_CTX *ctx)
{
if (group->meth->point_set_compressed_coordinates == 0)
{
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (group->meth != point->meth)
{
ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx);
return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
}

View File

@ -1,9 +1,6 @@
/* crypto/ec/ec_mult.c */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -55,11 +52,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions of this software developed by SUN MICROSYSTEMS, INC.,
* and contributed to the OpenSSL project.
*/
#include <openssl/err.h>
@ -76,23 +68,25 @@
*/
/* Determine the modified width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
/* Determine the width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
* This is an array r[] of values that are either zero or odd with an
* absolute value less than 2^w satisfying
* scalar = \sum_j r[j]*2^j
* where at most one of any w+1 consecutive digits is non-zero
* with the exception that the most significant digit may be only
* w-1 zeros away from that next non-zero digit.
* where at most one of any w+1 consecutive digits is non-zero.
*/
static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len, BN_CTX *ctx)
{
int window_val;
BIGNUM *c;
int ok = 0;
signed char *r = NULL;
int sign = 1;
int bit, next_bit, mask;
size_t len = 0, j;
BN_CTX_start(ctx);
c = BN_CTX_get(ctx);
if (c == NULL) goto err;
if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
@ -102,84 +96,60 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
next_bit = bit << 1; /* at most 256 */
mask = next_bit - 1; /* at most 255 */
if (BN_get_sign(scalar))
if (!BN_copy(c, scalar)) goto err;
if (c->neg)
{
sign = -1;
c->neg = 0;
}
len = BN_num_bits(scalar);
r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation */
len = BN_num_bits(c) + 1; /* wNAF may be one digit longer than binary representation */
r = OPENSSL_malloc(len);
if (r == NULL) goto err;
if (scalar->d == NULL || scalar->top == 0)
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
goto err;
}
window_val = scalar->d[0] & mask;
j = 0;
while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */
while (!BN_is_zero(c))
{
int digit = 0;
int u = 0;
/* 0 <= window_val <= 2^(w+1) */
if (window_val & 1)
if (BN_is_odd(c))
{
/* 0 < window_val < 2^(w+1) */
if (window_val & bit)
{
digit = window_val - next_bit; /* -2^w < digit < 0 */
#if 1 /* modified wNAF */
if (j + w + 1 >= len)
{
/* special case for generating modified wNAFs:
* no new bits will be added into window_val,
* so using a positive digit here will decrease
* the total length of the representation */
digit = window_val & (mask >> 1); /* 0 < digit < 2^w */
}
#endif
}
else
{
digit = window_val; /* 0 < digit < 2^w */
}
if (digit <= -bit || digit >= bit || !(digit & 1))
if (c->d == NULL || c->top == 0)
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
goto err;
}
u = c->d[0] & mask;
if (u & bit)
{
u -= next_bit;
/* u < 0 */
if (!BN_add_word(c, -u)) goto err;
}
else
{
/* u > 0 */
if (!BN_sub_word(c, u)) goto err;
}
window_val -= digit;
/* now window_val is 0 or 2^(w+1) in standard wNAF generation;
* for modified window NAFs, it may also be 2^w
*/
if (window_val != 0 && window_val != next_bit && window_val != bit)
if (u <= -bit || u >= bit || !(u & 1) || c->neg)
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
goto err;
}
}
r[j++] = sign * digit;
window_val >>= 1;
window_val += bit * BN_is_bit_set(scalar, j + w);
if (window_val > next_bit)
r[j++] = sign * u;
if (BN_is_odd(c))
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
goto err;
}
if (!BN_rshift1(c, c)) goto err;
}
if (j > len + 1)
if (j > len)
{
ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
goto err;
@ -188,6 +158,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
ok = 1;
err:
BN_CTX_end(ctx);
if (!ok)
{
OPENSSL_free(r);
@ -217,7 +188,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
* scalar*generator
* in the addition if scalar != NULL
*/
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
@ -243,7 +214,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
generator = EC_GROUP_get0_generator(group);
if (generator == NULL)
{
ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);
ECerr(EC_F_EC_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
return 0;
}
}
@ -252,7 +223,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
{
if (group->meth != points[i]->meth)
{
ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);
ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
return 0;
}
}
@ -302,7 +273,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
}
if (!(v == val + num_val))
{
ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);
goto err;
}
@ -343,7 +314,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
}
wNAF[i + 1] = NULL; /* make sure we always have a pivot */
wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]);
wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i], ctx);
if (wNAF[i] == NULL) goto err;
if (wNAF_len[i] > max_len)
max_len = wNAF_len[i];
@ -446,20 +417,6 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
}
/* Generic multiplication method.
* If group->meth does not provide a multiplication method, default to ec_wNAF_mul;
* otherwise use the group->meth's multiplication.
*/
int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
{
if (group->meth->mul == 0)
return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
else
return group->meth->mul(group, r, scalar, num, points, scalars, ctx);
}
int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
{
const EC_POINT *points[1];
@ -472,7 +429,7 @@ int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, con
}
int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
{
const EC_POINT *generator;
BN_CTX *new_ctx = NULL;
@ -482,7 +439,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
generator = EC_GROUP_get0_generator(group);
if (generator == NULL)
{
ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
return 0;
}
@ -500,7 +457,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
if (!EC_GROUP_get_order(group, order, ctx)) return 0;
if (BN_is_zero(order))
{
ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
goto err;
}
@ -514,18 +471,3 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
BN_CTX_free(new_ctx);
return ret;
}
/* Generic multiplicaiton precomputation method.
* If group->meth does not provide a multiplication method, default to ec_wNAF_mul and do its
* precomputation; otherwise use the group->meth's precomputation if it exists.
*/
int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
{
if (group->meth->mul == 0)
return ec_wNAF_precompute_mult(group, ctx);
else if (group->meth->precompute_mult != 0)
return group->meth->precompute_mult(group, ctx);
else
return 1;
}

View File

@ -1,195 +0,0 @@
/* crypto/ec/ec_print.c */
/* ====================================================================
* Copyright (c) 1998-2002 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).
*
*/
#include <openssl/crypto.h>
#include "ec_lcl.h"
BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
const EC_POINT *point,
point_conversion_form_t form,
BIGNUM *ret,
BN_CTX *ctx)
{
size_t buf_len=0;
unsigned char *buf;
buf_len = EC_POINT_point2oct(group, point, form,
NULL, 0, ctx);
if (buf_len == 0)
return NULL;
if ((buf = OPENSSL_malloc(buf_len)) == NULL)
return NULL;
if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx))
{
OPENSSL_free(buf);
return NULL;
}
ret = BN_bin2bn(buf, buf_len, ret);
OPENSSL_free(buf);
return ret;
}
EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
const BIGNUM *bn,
EC_POINT *point,
BN_CTX *ctx)
{
size_t buf_len=0;
unsigned char *buf;
EC_POINT *ret;
if ((buf_len = BN_num_bytes(bn)) == 0) return NULL;
buf = OPENSSL_malloc(buf_len);
if (buf == NULL)
return NULL;
if (!BN_bn2bin(bn, buf))
{
OPENSSL_free(buf);
return NULL;
}
if (point == NULL)
{
if ((ret = EC_POINT_new(group)) == NULL)
{
OPENSSL_free(buf);
return NULL;
}
}
else
ret = point;
if (!EC_POINT_oct2point(group, ret, buf, buf_len, ctx))
{
if (point == NULL)
EC_POINT_clear_free(ret);
OPENSSL_free(buf);
return NULL;
}
OPENSSL_free(buf);
return ret;
}
static const char *HEX_DIGITS = "0123456789ABCDEF";
/* the return value must be freed (using OPENSSL_free()) */
char *EC_POINT_point2hex(const EC_GROUP *group,
const EC_POINT *point,
point_conversion_form_t form,
BN_CTX *ctx)
{
char *ret, *p;
size_t buf_len=0,i;
unsigned char *buf, *pbuf;
buf_len = EC_POINT_point2oct(group, point, form,
NULL, 0, ctx);
if (buf_len == 0)
return NULL;
if ((buf = OPENSSL_malloc(buf_len)) == NULL)
return NULL;
if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx))
{
OPENSSL_free(buf);
return NULL;
}
ret = (char *)OPENSSL_malloc(buf_len*2+2);
if (ret == NULL)
{
OPENSSL_free(buf);
return NULL;
}
p = ret;
pbuf = buf;
for (i=buf_len; i > 0; i--)
{
int v = (int) *(pbuf++);
*(p++)=HEX_DIGITS[v>>4];
*(p++)=HEX_DIGITS[v&0x0F];
}
*p='\0';
OPENSSL_free(buf);
return ret;
}
EC_POINT *EC_POINT_hex2point(const EC_GROUP *group,
const char *buf,
EC_POINT *point,
BN_CTX *ctx)
{
EC_POINT *ret=NULL;
BIGNUM *tmp_bn=NULL;
if (!BN_hex2bn(&tmp_bn, buf))
return NULL;
ret = EC_POINT_bn2point(group, tmp_bn, point, ctx);
BN_clear_free(tmp_bn);
return ret;
}

View File

@ -1,7 +1,4 @@
/* crypto/ec/ecp_mont.c */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
*
@ -55,11 +52,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions of this software developed by SUN MICROSYSTEMS, INC.,
* and contributed to the OpenSSL project.
*/
#include <openssl/err.h>
@ -69,15 +61,16 @@
const EC_METHOD *EC_GFp_mont_method(void)
{
static const EC_METHOD ret = {
NID_X9_62_prime_field,
ec_GFp_mont_group_init,
ec_GFp_mont_group_finish,
ec_GFp_mont_group_clear_finish,
ec_GFp_mont_group_copy,
ec_GFp_mont_group_set_curve,
ec_GFp_simple_group_get_curve,
ec_GFp_simple_group_get_degree,
ec_GFp_simple_group_check_discriminant,
ec_GFp_mont_group_set_curve_GFp,
ec_GFp_simple_group_get_curve_GFp,
ec_GFp_simple_group_set_generator,
ec_GFp_simple_group_get0_generator,
ec_GFp_simple_group_get_order,
ec_GFp_simple_group_get_cofactor,
ec_GFp_simple_point_init,
ec_GFp_simple_point_finish,
ec_GFp_simple_point_clear_finish,
@ -85,16 +78,14 @@ const EC_METHOD *EC_GFp_mont_method(void)
ec_GFp_simple_point_set_to_infinity,
ec_GFp_simple_set_Jprojective_coordinates_GFp,
ec_GFp_simple_get_Jprojective_coordinates_GFp,
ec_GFp_simple_point_set_affine_coordinates,
ec_GFp_simple_point_get_affine_coordinates,
ec_GFp_simple_set_compressed_coordinates,
ec_GFp_simple_point_set_affine_coordinates_GFp,
ec_GFp_simple_point_get_affine_coordinates_GFp,
ec_GFp_simple_set_compressed_coordinates_GFp,
ec_GFp_simple_point2oct,
ec_GFp_simple_oct2point,
ec_GFp_simple_add,
ec_GFp_simple_dbl,
ec_GFp_simple_invert,
0 /* mul */,
0 /* precompute_mult */,
ec_GFp_simple_is_at_infinity,
ec_GFp_simple_is_on_curve,
ec_GFp_simple_cmp,
@ -102,7 +93,6 @@ const EC_METHOD *EC_GFp_mont_method(void)
ec_GFp_simple_points_make_affine,
ec_GFp_mont_field_mul,
ec_GFp_mont_field_sqr,
0 /* field_div */,
ec_GFp_mont_field_encode,
ec_GFp_mont_field_decode,
ec_GFp_mont_field_set_to_one };
@ -122,7 +112,7 @@ int ec_GFp_mont_group_init(EC_GROUP *group)
}
int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
BN_MONT_CTX *mont = NULL;
@ -151,7 +141,7 @@ int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *
if (mont == NULL) goto err;
if (!BN_MONT_CTX_set(mont, p, ctx))
{
ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE, ERR_R_BN_LIB);
ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP, ERR_R_BN_LIB);
goto err;
}
one = BN_new();
@ -163,7 +153,7 @@ int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *
group->field_data2 = one;
one = NULL;
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
ret = ec_GFp_simple_group_set_curve_GFp(group, p, a, b, ctx);
if (!ret)
{

View File

@ -1,9 +1,6 @@
/* crypto/ec/ecp_nist.c */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -55,28 +52,23 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions of this software developed by SUN MICROSYSTEMS, INC.,
* and contributed to the OpenSSL project.
*/
#include <openssl/err.h>
#include <openssl/obj_mac.h>
#include "ec_lcl.h"
#if 0
const EC_METHOD *EC_GFp_nist_method(void)
{
static const EC_METHOD ret = {
NID_X9_62_prime_field,
ec_GFp_nist_group_init,
ec_GFp_nist_group_finish,
ec_GFp_nist_group_clear_finish,
ec_GFp_nist_group_copy,
ec_GFp_nist_group_set_curve,
ec_GFp_simple_group_get_curve,
ec_GFp_simple_group_get_degree,
ec_GFp_simple_group_check_discriminant,
ec_GFp_nist_group_set_curve_GFp,
ec_GFp_simple_group_get_curve_GFp,
ec_GFp_simple_group_set_generator,
ec_GFp_simple_group_get0_generator,
ec_GFp_simple_group_get_order,
ec_GFp_simple_group_get_cofactor,
ec_GFp_simple_point_init,
ec_GFp_simple_point_finish,
ec_GFp_simple_point_clear_finish,
@ -84,16 +76,14 @@ const EC_METHOD *EC_GFp_nist_method(void)
ec_GFp_simple_point_set_to_infinity,
ec_GFp_simple_set_Jprojective_coordinates_GFp,
ec_GFp_simple_get_Jprojective_coordinates_GFp,
ec_GFp_simple_point_set_affine_coordinates,
ec_GFp_simple_point_get_affine_coordinates,
ec_GFp_simple_set_compressed_coordinates,
ec_GFp_simple_point_set_affine_coordinates_GFp,
ec_GFp_simple_point_get_affine_coordinates_GFp,
ec_GFp_simple_set_compressed_coordinates_GFp,
ec_GFp_simple_point2oct,
ec_GFp_simple_oct2point,
ec_GFp_simple_add,
ec_GFp_simple_dbl,
ec_GFp_simple_invert,
0 /* mul */,
0 /* precompute_mult */,
ec_GFp_simple_is_at_infinity,
ec_GFp_simple_is_on_curve,
ec_GFp_simple_cmp,
@ -101,181 +91,44 @@ const EC_METHOD *EC_GFp_nist_method(void)
ec_GFp_simple_points_make_affine,
ec_GFp_nist_field_mul,
ec_GFp_nist_field_sqr,
0 /* field_div */,
0 /* field_encode */,
0 /* field_decode */,
0 /* field_set_to_one */ };
return &ret;
}
#if BN_BITS2 == 64 && UINT_MAX != 4294967295UL && ULONG_MAX != 4294967295UL
#define NO_32_BIT_TYPE
#endif
int ec_GFp_nist_group_init(EC_GROUP *group)
{
int ok;
ok = ec_GFp_simple_group_init(group);
group->field_data1 = NULL;
return ok;
}
void ec_GFp_nist_group_finish(EC_GROUP *group)
{
BN_free(&group->field);
BN_free(&group->a);
BN_free(&group->b);
}
int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */
void ec_GFp_nist_group_clear_finish(EC_GROUP *group)
{
BN_clear_free(&group->field);
BN_clear_free(&group->a);
BN_clear_free(&group->b);
}
void ec_GFp_nist_group_finish(EC_GROUP *group);
/* TODO */
int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
int ret = 0;
BN_CTX *new_ctx = NULL;
BIGNUM *tmp_bn;
if (ctx == NULL)
if ((ctx = new_ctx = BN_CTX_new()) == NULL) return 0;
void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
/* TODO */
BN_CTX_start(ctx);
if ((tmp_bn = BN_CTX_get(ctx)) == NULL) goto err;
if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0)
group->field_mod_func = BN_nist_mod_192;
else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0)
{
#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
group->field_mod_func = BN_nist_mod_224;
#else
ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
goto err;
#endif
}
else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0)
{
#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
group->field_mod_func = BN_nist_mod_256;
#else
ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
goto err;
#endif
}
else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0)
{
#if !defined(NO_32_BIT_TYPE) || defined(OPENSSL_NO_ASM)
group->field_mod_func = BN_nist_mod_384;
#else
ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
goto err;
#endif
}
else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0)
/* this one works in the NO_32_BIT_TYPE case */
group->field_mod_func = BN_nist_mod_521;
else
{
ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE_GFP, EC_R_NOT_A_NIST_PRIME);
goto err;
}
int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
/* TODO */
/* group->field */
if (!BN_copy(&group->field, p)) goto err;
BN_set_sign(&group->field, 0);
/* group->a */
if (!group->field_mod_func(&group->a, a, p, ctx)) goto err;
int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */
/* group->b */
if (!group->field_mod_func(&group->b, b, p, ctx)) goto err;
/* group->a_is_minus3 */
if (!BN_add_word(tmp_bn, 3)) goto err;
group->a_is_minus3 = (0 == BN_cmp(tmp_bn, &group->field));
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
}
int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
if (dest == NULL || src == NULL)
return 0;
if (!BN_copy(&dest->field, &src->field))
return 0;
if (!BN_copy(&dest->a, &src->a))
return 0;
if (!BN_copy(&dest->b, &src->b))
return 0;
dest->curve_name = src->curve_name;
dest->a_is_minus3 = src->a_is_minus3;
return 1;
}
int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
const BIGNUM *b, BN_CTX *ctx)
{
int ret=0;
BN_CTX *ctx_new=NULL;
if (!group || !r || !a || !b)
{
ECerr(EC_F_EC_GFP_NIST_FIELD_MUL, ERR_R_PASSED_NULL_PARAMETER);
goto err;
}
if (!ctx)
if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err;
if (!BN_mul(r, a, b, ctx)) goto err;
if (!group->field_mod_func(r, r, &group->field, ctx))
goto err;
ret=1;
err:
if (ctx_new)
BN_CTX_free(ctx_new);
return ret;
}
int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
BN_CTX *ctx)
{
int ret=0;
BN_CTX *ctx_new=NULL;
if (!group || !r || !a)
{
ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER);
goto err;
}
if (!ctx)
if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err;
if (!BN_sqr(r, a, ctx)) goto err;
if (!group->field_mod_func(r, r, &group->field, ctx))
goto err;
ret=1;
err:
if (ctx_new)
BN_CTX_free(ctx_new);
return ret;
}
int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
/* TODO */

View File

@ -52,11 +52,6 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions of this software developed by SUN MICROSYSTEMS, INC.,
* and contributed to the OpenSSL project.
*/
#include "ec_lcl.h"
@ -68,14 +63,12 @@ const EC_METHOD *EC_GFp_recp_method(void)
ec_GFp_recp_group_finish,
ec_GFp_recp_group_clear_finish,
ec_GFp_recp_group_copy,
ec_GFp_recp_group_set_curve,
ec_GFp_simple_group_get_curve,
ec_GFp_simple_group_get_degree,
ec_GFp_recp_group_set_curve_GFp,
ec_GFp_simple_group_get_curve_GFp,
ec_GFp_simple_group_set_generator,
ec_GFp_simple_group_get0_generator,
ec_GFp_simple_group_get_order,
ec_GFp_simple_group_get_cofactor,
ec_GFp_simple_group_check_discriminant,
ec_GFp_simple_point_init,
ec_GFp_simple_point_finish,
ec_GFp_simple_point_clear_finish,
@ -83,16 +76,14 @@ const EC_METHOD *EC_GFp_recp_method(void)
ec_GFp_simple_point_set_to_infinity,
ec_GFp_simple_set_Jprojective_coordinates_GFp,
ec_GFp_simple_get_Jprojective_coordinates_GFp,
ec_GFp_simple_point_set_affine_coordinates,
ec_GFp_simple_point_get_affine_coordinates,
ec_GFp_simple_set_compressed_coordinates,
ec_GFp_simple_point_set_affine_coordinates_GFp,
ec_GFp_simple_point_get_affine_coordinates_GFp,
ec_GFp_simple_set_compressed_coordinates_GFp,
ec_GFp_simple_point2oct,
ec_GFp_simple_oct2point,
ec_GFp_simple_add,
ec_GFp_simple_dbl,
ec_GFp_simple_invert,
0 /* mul */,
0 /* precompute_mult */,
ec_GFp_simple_is_at_infinity,
ec_GFp_simple_is_on_curve,
ec_GFp_simple_cmp,
@ -100,7 +91,6 @@ const EC_METHOD *EC_GFp_recp_method(void)
ec_GFp_simple_points_make_affine,
ec_GFp_recp_field_mul,
ec_GFp_recp_field_sqr,
0 /* field_div */,
0 /* field_encode */,
0 /* field_decode */,
0 /* field_set_to_one */ };
@ -119,7 +109,7 @@ int ec_GFp_recp_group_init(EC_GROUP *group)
}
int ec_GFp_recp_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
/* TODO */

View File

@ -1,10 +1,8 @@
/* crypto/ec/ecp_smpl.c */
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
* for the OpenSSL project.
* Includes code written by Bodo Moeller for the OpenSSL project.
*/
* for the OpenSSL project. */
/* ====================================================================
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
* Copyright (c) 1998-2001 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
@ -56,29 +54,25 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
* Portions of this software developed by SUN MICROSYSTEMS, INC.,
* and contributed to the OpenSSL project.
*/
#include <openssl/err.h>
#include <openssl/symhacks.h>
#include "ec_lcl.h"
const EC_METHOD *EC_GFp_simple_method(void)
{
static const EC_METHOD ret = {
NID_X9_62_prime_field,
ec_GFp_simple_group_init,
ec_GFp_simple_group_finish,
ec_GFp_simple_group_clear_finish,
ec_GFp_simple_group_copy,
ec_GFp_simple_group_set_curve,
ec_GFp_simple_group_get_curve,
ec_GFp_simple_group_get_degree,
ec_GFp_simple_group_check_discriminant,
ec_GFp_simple_group_set_curve_GFp,
ec_GFp_simple_group_get_curve_GFp,
ec_GFp_simple_group_set_generator,
ec_GFp_simple_group_get0_generator,
ec_GFp_simple_group_get_order,
ec_GFp_simple_group_get_cofactor,
ec_GFp_simple_point_init,
ec_GFp_simple_point_finish,
ec_GFp_simple_point_clear_finish,
@ -86,16 +80,14 @@ const EC_METHOD *EC_GFp_simple_method(void)
ec_GFp_simple_point_set_to_infinity,
ec_GFp_simple_set_Jprojective_coordinates_GFp,
ec_GFp_simple_get_Jprojective_coordinates_GFp,
ec_GFp_simple_point_set_affine_coordinates,
ec_GFp_simple_point_get_affine_coordinates,
ec_GFp_simple_set_compressed_coordinates,
ec_GFp_simple_point_set_affine_coordinates_GFp,
ec_GFp_simple_point_get_affine_coordinates_GFp,
ec_GFp_simple_set_compressed_coordinates_GFp,
ec_GFp_simple_point2oct,
ec_GFp_simple_oct2point,
ec_GFp_simple_add,
ec_GFp_simple_dbl,
ec_GFp_simple_invert,
0 /* mul */,
0 /* precompute_mult */,
ec_GFp_simple_is_at_infinity,
ec_GFp_simple_is_on_curve,
ec_GFp_simple_cmp,
@ -103,7 +95,6 @@ const EC_METHOD *EC_GFp_simple_method(void)
ec_GFp_simple_points_make_affine,
ec_GFp_simple_field_mul,
ec_GFp_simple_field_sqr,
0 /* field_div */,
0 /* field_encode */,
0 /* field_decode */,
0 /* field_set_to_one */ };
@ -118,6 +109,9 @@ int ec_GFp_simple_group_init(EC_GROUP *group)
BN_init(&group->a);
BN_init(&group->b);
group->a_is_minus3 = 0;
group->generator = NULL;
BN_init(&group->order);
BN_init(&group->cofactor);
return 1;
}
@ -127,6 +121,10 @@ void ec_GFp_simple_group_finish(EC_GROUP *group)
BN_free(&group->field);
BN_free(&group->a);
BN_free(&group->b);
if (group->generator != NULL)
EC_POINT_free(group->generator);
BN_free(&group->order);
BN_free(&group->cofactor);
}
@ -135,6 +133,13 @@ void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
BN_clear_free(&group->field);
BN_clear_free(&group->a);
BN_clear_free(&group->b);
if (group->generator != NULL)
{
EC_POINT_clear_free(group->generator);
group->generator = NULL;
}
BN_clear_free(&group->order);
BN_clear_free(&group->cofactor);
}
@ -146,11 +151,33 @@ int ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
dest->a_is_minus3 = src->a_is_minus3;
if (src->generator != NULL)
{
if (dest->generator == NULL)
{
dest->generator = EC_POINT_new(dest);
if (dest->generator == NULL) return 0;
}
if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
}
else
{
/* src->generator == NULL */
if (dest->generator != NULL)
{
EC_POINT_clear_free(dest->generator);
dest->generator = NULL;
}
}
if (!BN_copy(&dest->order, &src->order)) return 0;
if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
return 1;
}
int ec_GFp_simple_group_set_curve(EC_GROUP *group,
int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *group,
const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
int ret = 0;
@ -160,7 +187,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
/* p must be a prime > 3 */
if (BN_num_bits(p) <= 2 || !BN_is_odd(p))
{
ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, EC_R_INVALID_FIELD);
ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP, EC_R_INVALID_FIELD);
return 0;
}
@ -177,7 +204,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
/* group->field */
if (!BN_copy(&group->field, p)) goto err;
BN_set_sign(&group->field, 0);
group->field.neg = 0;
/* group->a */
if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
@ -205,7 +232,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
}
int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
{
int ret = 0;
BN_CTX *new_ctx = NULL;
@ -256,75 +283,58 @@ int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, B
}
int ec_GFp_simple_group_get_degree(const EC_GROUP *group)
int ec_GFp_simple_group_set_generator(EC_GROUP *group, const EC_POINT *generator,
const BIGNUM *order, const BIGNUM *cofactor)
{
return BN_num_bits(&group->field);
if (generator == NULL)
{
ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
return 0 ;
}
if (group->generator == NULL)
{
group->generator = EC_POINT_new(group);
if (group->generator == NULL) return 0;
}
if (!EC_POINT_copy(group->generator, generator)) return 0;
if (order != NULL)
{ if (!BN_copy(&group->order, order)) return 0; }
else
{ if (!BN_zero(&group->order)) return 0; }
if (cofactor != NULL)
{ if (!BN_copy(&group->cofactor, cofactor)) return 0; }
else
{ if (!BN_zero(&group->cofactor)) return 0; }
return 1;
}
int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *group)
{
int ret = 0;
BIGNUM *a,*b,*order,*tmp_1,*tmp_2;
const BIGNUM *p = &group->field;
BN_CTX *new_ctx = NULL;
return group->generator;
}
if (ctx == NULL)
{
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
{
ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE);
goto err;
}
}
BN_CTX_start(ctx);
a = BN_CTX_get(ctx);
b = BN_CTX_get(ctx);
tmp_1 = BN_CTX_get(ctx);
tmp_2 = BN_CTX_get(ctx);
order = BN_CTX_get(ctx);
if (order == NULL) goto err;
if (group->meth->field_decode)
{
if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err;
if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err;
}
else
{
if (!BN_copy(a, &group->a)) goto err;
if (!BN_copy(b, &group->b)) goto err;
}
/* check the discriminant:
* y^2 = x^3 + a*x + b is an elliptic curve <=> 4*a^3 + 27*b^2 != 0 (mod p)
* 0 =< a, b < p */
if (BN_is_zero(a))
{
if (BN_is_zero(b)) goto err;
}
else if (!BN_is_zero(b))
{
if (!BN_mod_sqr(tmp_1, a, p, ctx)) goto err;
if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx)) goto err;
if (!BN_lshift(tmp_1, tmp_2, 2)) goto err;
/* tmp_1 = 4*a^3 */
int ec_GFp_simple_group_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
{
if (!BN_copy(order, &group->order))
return 0;
if (!BN_mod_sqr(tmp_2, b, p, ctx)) goto err;
if (!BN_mul_word(tmp_2, 27)) goto err;
/* tmp_2 = 27*b^2 */
return !BN_is_zero(&group->order);
}
if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx)) goto err;
if (BN_is_zero(a)) goto err;
}
ret = 1;
err:
BN_CTX_end(ctx);
if (new_ctx != NULL)
BN_CTX_free(new_ctx);
return ret;
int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
{
if (!BN_copy(cofactor, &group->cofactor))
return 0;
return !BN_is_zero(&group->cofactor);
}
@ -487,13 +497,13 @@ int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const E
}
int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point,
int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
{
if (x == NULL || y == NULL)
{
/* unlike for projective coordinates, we do not tolerate this */
ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES, ERR_R_PASSED_NULL_PARAMETER);
ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
@ -501,7 +511,7 @@ int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *
}
int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,
int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
@ -511,7 +521,7 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
if (EC_POINT_is_at_infinity(group, point))
{
ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY);
ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_POINT_AT_INFINITY);
return 0;
}
@ -562,7 +572,7 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
{
if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
{
ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB);
ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_BN_LIB);
goto err;
}
@ -616,7 +626,7 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
}
int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
const BIGNUM *x_, int y_bit, BN_CTX *ctx)
{
BN_CTX *new_ctx = NULL;
@ -699,12 +709,14 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *po
if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)
{
(void)ERR_get_error();
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
}
else
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB);
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_BN_LIB);
goto err;
}
/* If tmp1 is not a square (i.e. there is no point on the curve with
* our x), then y now is a nonsense value too */
if (y_bit != BN_is_odd(y))
{
@ -716,17 +728,16 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *po
if (kron == -2) goto err;
if (kron == 1)
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSION_BIT);
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSION_BIT);
else
/* BN_mod_sqrt() should have cought this error (not a square) */
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
goto err;
}
if (!BN_usub(y, &group->field, y)) goto err;
}
if (y_bit != BN_is_odd(y))
{
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_INTERNAL_ERROR);
ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_INTERNAL_ERROR);
goto err;
}

View File

@ -1,7 +1,4 @@
/* crypto/ec/ectest.c */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
/* ====================================================================
* Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
*
@ -55,26 +52,13 @@
* Hudson (tjh@cryptsoft.com).
*
*/
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
* Portions of the attached software ("Contribution") are developed by
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
*
* The Contribution is licensed pursuant to the OpenSSL open source
* license provided above.
*
* The elliptic curve binary polynomial software is originally written by
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
*
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef FLAT_INC
#include "e_os.h"
#else
#include "../../e_os.h"
#include "../e_os.h"
#endif
#include <string.h>
#include <time.h>
@ -88,8 +72,6 @@ int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); retur
#include <openssl/ec.h>
#include <openssl/engine.h>
#include <openssl/err.h>
#include <openssl/obj_mac.h>
#include <openssl/objects.h>
#define ABORT do { \
fflush(stdout); \
@ -98,49 +80,42 @@ int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); retur
exit(1); \
} while (0)
void prime_field_tests(void);
void char2_field_tests(void);
void internal_curve_test(void);
#if 0
static void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
{
clock_t clck;
int i, j;
BIGNUM *s;
BIGNUM *r[10], *r0[10];
BIGNUM *s, *s0;
EC_POINT *P;
s = BN_new();
if (s == NULL) ABORT;
s0 = BN_new();
if (s == NULL || s0 == NULL) ABORT;
fprintf(stdout, "Timings for %d-bit field, ", EC_GROUP_get_degree(group));
if (!EC_GROUP_get_curve_GFp(group, s, NULL, NULL, ctx)) ABORT;
fprintf(stdout, "Timings for %d bit prime, ", (int)BN_num_bits(s));
if (!EC_GROUP_get_order(group, s, ctx)) ABORT;
fprintf(stdout, "%d-bit scalars ", (int)BN_num_bits(s));
fprintf(stdout, "%d bit scalars ", (int)BN_num_bits(s));
fflush(stdout);
P = EC_POINT_new(group);
if (P == NULL) ABORT;
EC_POINT_copy(P, EC_GROUP_get0_generator(group));
for (i = 0; i < 10; i++)
{
if ((r[i] = BN_new()) == NULL) ABORT;
if (!BN_pseudo_rand(r[i], BN_num_bits(s), 0, 0)) ABORT;
if (multi)
{
if ((r0[i] = BN_new()) == NULL) ABORT;
if (!BN_pseudo_rand(r0[i], BN_num_bits(s), 0, 0)) ABORT;
}
}
clck = clock();
for (i = 0; i < 10; i++)
{
if (!BN_pseudo_rand(s, BN_num_bits(s), 0, 0)) ABORT;
if (multi)
{
if (!BN_pseudo_rand(s0, BN_num_bits(s), 0, 0)) ABORT;
}
for (j = 0; j < 10; j++)
{
if (!EC_POINT_mul(group, P, r[i], multi ? P : NULL, multi ? r0[i] : NULL, ctx)) ABORT;
if (!EC_POINT_mul(group, P, s, multi ? P : NULL, multi ? s0 : NULL, ctx)) ABORT;
}
fprintf(stdout, ".");
fflush(stdout);
}
fprintf(stdout, "\n");
@ -166,15 +141,11 @@ static void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
EC_POINT_free(P);
BN_free(s);
for (i = 0; i < 10; i++)
{
BN_free(r[i]);
if (multi) BN_free(r0[i]);
}
BN_free(s0);
}
#endif
void prime_field_tests()
int main(int argc, char *argv[])
{
BN_CTX *ctx = NULL;
BIGNUM *p, *a, *b;
@ -186,6 +157,20 @@ void prime_field_tests()
size_t i, len;
int k;
/* enable memory leak checking unless explicitly disabled */
if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
{
CRYPTO_malloc_debug_init();
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
}
else
{
/* OPENSSL_DEBUG_MEMORY=off */
CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
ERR_load_crypto_strings();
#if 1 /* optional */
ctx = BN_CTX_new();
if (!ctx) ABORT;
@ -353,10 +338,6 @@ void prime_field_tests()
/* G_y value taken from the standard: */
if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT;
if (0 != BN_cmp(y, z)) ABORT;
fprintf(stdout, "verify degree ...");
if (EC_GROUP_get_degree(group) != 192) ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "verify group order ...");
fflush(stdout);
@ -398,10 +379,6 @@ void prime_field_tests()
if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT;
if (0 != BN_cmp(y, z)) ABORT;
fprintf(stdout, "verify degree ...");
if (EC_GROUP_get_degree(group) != 224) ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "verify group order ...");
fflush(stdout);
if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
@ -443,10 +420,6 @@ void prime_field_tests()
if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT;
if (0 != BN_cmp(y, z)) ABORT;
fprintf(stdout, "verify degree ...");
if (EC_GROUP_get_degree(group) != 256) ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "verify group order ...");
fflush(stdout);
if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
@ -493,10 +466,6 @@ void prime_field_tests()
"7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT;
if (0 != BN_cmp(y, z)) ABORT;
fprintf(stdout, "verify degree ...");
if (EC_GROUP_get_degree(group) != 384) ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "verify group order ...");
fflush(stdout);
if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
@ -549,10 +518,6 @@ void prime_field_tests()
"7086A272C24088BE94769FD16650")) ABORT;
if (0 != BN_cmp(y, z)) ABORT;
fprintf(stdout, "verify degree ...");
if (EC_GROUP_get_degree(group) != 521) ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "verify group order ...");
fflush(stdout);
if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
@ -610,7 +575,7 @@ void prime_field_tests()
if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
if (!BN_add(z, z, y)) ABORT;
BN_set_sign(z, 1);
z->neg = 1;
scalars[0] = y;
scalars[1] = z; /* z = -(order + y) */
@ -622,7 +587,7 @@ void prime_field_tests()
if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT;
if (!BN_add(z, x, y)) ABORT;
BN_set_sign(z, 1);
z->neg = 1;
scalars[0] = x;
scalars[1] = y;
scalars[2] = z; /* z = -(x+y) */
@ -663,570 +628,6 @@ void prime_field_tests()
if (P_384) EC_GROUP_free(P_384);
if (P_521) EC_GROUP_free(P_521);
}
/* Change test based on whether binary point compression is enabled or not. */
#ifdef OPENSSL_EC_BIN_PT_COMP
#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \
if (!BN_hex2bn(&x, _x)) ABORT; \
if (!EC_POINT_set_compressed_coordinates_GF2m(group, P, x, _y_bit, ctx)) ABORT; \
if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \
if (!BN_hex2bn(&z, _order)) ABORT; \
if (!BN_hex2bn(&cof, _cof)) ABORT; \
if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \
if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \
fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \
BN_print_fp(stdout, x); \
fprintf(stdout, "\n y = 0x"); \
BN_print_fp(stdout, y); \
fprintf(stdout, "\n"); \
/* G_y value taken from the standard: */ \
if (!BN_hex2bn(&z, _y)) ABORT; \
if (0 != BN_cmp(y, z)) ABORT;
#else
#define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \
if (!BN_hex2bn(&x, _x)) ABORT; \
if (!BN_hex2bn(&y, _y)) ABORT; \
if (!EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \
if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \
if (!BN_hex2bn(&z, _order)) ABORT; \
if (!BN_hex2bn(&cof, _cof)) ABORT; \
if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \
fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \
BN_print_fp(stdout, x); \
fprintf(stdout, "\n y = 0x"); \
BN_print_fp(stdout, y); \
fprintf(stdout, "\n");
#endif
#define CHAR2_CURVE_TEST(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \
if (!BN_hex2bn(&p, _p)) ABORT; \
if (!BN_hex2bn(&a, _a)) ABORT; \
if (!BN_hex2bn(&b, _b)) ABORT; \
if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; \
CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \
fprintf(stdout, "verify degree ..."); \
if (EC_GROUP_get_degree(group) != _degree) ABORT; \
fprintf(stdout, " ok\n"); \
fprintf(stdout, "verify group order ..."); \
fflush(stdout); \
if (!EC_GROUP_get_order(group, z, ctx)) ABORT; \
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT; \
if (!EC_POINT_is_at_infinity(group, Q)) ABORT; \
fprintf(stdout, "."); \
fflush(stdout); \
if (!EC_GROUP_precompute_mult(group, ctx)) ABORT; \
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT; \
if (!EC_POINT_is_at_infinity(group, Q)) ABORT; \
fprintf(stdout, " ok\n"); \
if (!(_variable = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; \
if (!EC_GROUP_copy(_variable, group)) ABORT;
void char2_field_tests()
{
BN_CTX *ctx = NULL;
BIGNUM *p, *a, *b;
EC_GROUP *group;
EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 = NULL, *C2_K571 = NULL;
EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 = NULL, *C2_B571 = NULL;
EC_POINT *P, *Q, *R;
BIGNUM *x, *y, *z, *cof;
unsigned char buf[100];
size_t i, len;
int k;
#if 1 /* optional */
ctx = BN_CTX_new();
if (!ctx) ABORT;
#endif
p = BN_new();
a = BN_new();
b = BN_new();
if (!p || !a || !b) ABORT;
if (!BN_hex2bn(&p, "13")) ABORT;
if (!BN_hex2bn(&a, "3")) ABORT;
if (!BN_hex2bn(&b, "1")) ABORT;
group = EC_GROUP_new(EC_GF2m_simple_method()); /* applications should use EC_GROUP_new_curve_GF2m
* so that the library gets to choose the EC_METHOD */
if (!group) ABORT;
if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT;
{
EC_GROUP *tmp;
tmp = EC_GROUP_new(EC_GROUP_method_of(group));
if (!tmp) ABORT;
if (!EC_GROUP_copy(tmp, group));
EC_GROUP_free(group);
group = tmp;
}
if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) ABORT;
fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x");
BN_print_fp(stdout, p);
fprintf(stdout, ")\n a = 0x");
BN_print_fp(stdout, a);
fprintf(stdout, "\n b = 0x");
BN_print_fp(stdout, b);
fprintf(stdout, "\n(0x... means binary polynomial)\n");
P = EC_POINT_new(group);
Q = EC_POINT_new(group);
R = EC_POINT_new(group);
if (!P || !Q || !R) ABORT;
if (!EC_POINT_set_to_infinity(group, P)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
buf[0] = 0;
if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT;
if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
x = BN_new();
y = BN_new();
z = BN_new();
cof = BN_new();
if (!x || !y || !z || !cof) ABORT;
if (!BN_hex2bn(&x, "6")) ABORT;
/* Change test based on whether binary point compression is enabled or not. */
#ifdef OPENSSL_EC_BIN_PT_COMP
if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx)) ABORT;
#else
if (!BN_hex2bn(&y, "8")) ABORT;
if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT;
#endif
if (!EC_POINT_is_on_curve(group, Q, ctx))
{
/* Change test based on whether binary point compression is enabled or not. */
#ifdef OPENSSL_EC_BIN_PT_COMP
if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx)) ABORT;
#endif
fprintf(stderr, "Point is not on curve: x = 0x");
BN_print_fp(stderr, x);
fprintf(stderr, ", y = 0x");
BN_print_fp(stderr, y);
fprintf(stderr, "\n");
ABORT;
}
fprintf(stdout, "A cyclic subgroup:\n");
k = 100;
do
{
if (k-- == 0) ABORT;
if (EC_POINT_is_at_infinity(group, P))
fprintf(stdout, " point at infinity\n");
else
{
if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT;
fprintf(stdout, " x = 0x");
BN_print_fp(stdout, x);
fprintf(stdout, ", y = 0x");
BN_print_fp(stdout, y);
fprintf(stdout, "\n");
}
if (!EC_POINT_copy(R, P)) ABORT;
if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
}
while (!EC_POINT_is_at_infinity(group, P));
if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
/* Change test based on whether binary point compression is enabled or not. */
#ifdef OPENSSL_EC_BIN_PT_COMP
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx);
if (len == 0) ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
fprintf(stdout, "Generator as octet string, compressed form:\n ");
for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
#endif
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
if (len == 0) ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n ");
for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
/* Change test based on whether binary point compression is enabled or not. */
#ifdef OPENSSL_EC_BIN_PT_COMP
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
if (len == 0) ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
fprintf(stdout, "\nGenerator as octet string, hybrid form:\n ");
for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
#endif
fprintf(stdout, "\n");
if (!EC_POINT_invert(group, P, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
/* Curve K-163 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve K-163",
"0800000000000000000000000000000000000000C9",
"1",
"1",
"02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",
"0289070FB05D38FF58321F2E800536D538CCDAA3D9",
1,
"04000000000000000000020108A2E0CC0D99F8A5EF",
"2",
163,
C2_K163
);
/* Curve B-163 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve B-163",
"0800000000000000000000000000000000000000C9",
"1",
"020A601907B8C953CA1481EB10512F78744A3205FD",
"03F0EBA16286A2D57EA0991168D4994637E8343E36",
"00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",
1,
"040000000000000000000292FE77E70C12A4234C33",
"2",
163,
C2_B163
);
/* Curve K-233 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve K-233",
"020000000000000000000000000000000000000004000000000000000001",
"0",
"1",
"017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",
"01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",
0,
"008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF",
"4",
233,
C2_K233
);
/* Curve B-233 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve B-233",
"020000000000000000000000000000000000000004000000000000000001",
"000000000000000000000000000000000000000000000000000000000001",
"0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",
"00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",
"01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",
1,
"01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7",
"2",
233,
C2_B233
);
/* Curve K-283 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve K-283",
"0800000000000000000000000000000000000000000000000000000000000000000010A1",
"0",
"1",
"0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836",
"01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259",
0,
"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61",
"4",
283,
C2_K283
);
/* Curve B-283 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve B-283",
"0800000000000000000000000000000000000000000000000000000000000000000010A1",
"000000000000000000000000000000000000000000000000000000000000000000000001",
"027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5",
"05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053",
"03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4",
1,
"03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307",
"2",
283,
C2_B283
);
/* Curve K-409 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve K-409",
"02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
"0",
"1",
"0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746",
"01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B",
1,
"007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF",
"4",
409,
C2_K409
);
/* Curve B-409 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve B-409",
"02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",
"015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",
"0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",
1,
"010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173",
"2",
409,
C2_B409
);
/* Curve K-571 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve K-571",
"80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
"0",
"1",
"026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",
"0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",
0,
"020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001",
"4",
571,
C2_K571
);
/* Curve B-571 (FIPS PUB 186-2, App. 6) */
CHAR2_CURVE_TEST
(
"NIST curve B-571",
"80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",
"0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",
"037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",
1,
"03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47",
"2",
571,
C2_B571
);
/* more tests using the last curve */
if (!EC_POINT_copy(Q, P)) ABORT;
if (EC_POINT_is_at_infinity(group, Q)) ABORT;
if (!EC_POINT_dbl(group, P, P, ctx)) ABORT;
if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */
if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT;
if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */
{
const EC_POINT *points[3];
const BIGNUM *scalars[3];
if (EC_POINT_is_at_infinity(group, Q)) ABORT;
points[0] = Q;
points[1] = Q;
points[2] = Q;
if (!BN_add(y, z, BN_value_one())) ABORT;
if (BN_is_odd(y)) ABORT;
if (!BN_rshift1(y, y)) ABORT;
scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */
scalars[1] = y;
fprintf(stdout, "combined multiplication ...");
fflush(stdout);
/* z is still the group order */
if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
if (!BN_add(z, z, y)) ABORT;
BN_set_sign(z, 1);
scalars[0] = y;
scalars[1] = z; /* z = -(order + y) */
if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT;
if (!BN_add(z, x, y)) ABORT;
BN_set_sign(z, 1);
scalars[0] = x;
scalars[1] = y;
scalars[2] = z; /* z = -(x+y) */
if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
fprintf(stdout, " ok\n\n");
}
#if 0
timings(C2_K163, 0, ctx);
timings(C2_K163, 1, ctx);
timings(C2_B163, 0, ctx);
timings(C2_B163, 1, ctx);
timings(C2_K233, 0, ctx);
timings(C2_K233, 1, ctx);
timings(C2_B233, 0, ctx);
timings(C2_B233, 1, ctx);
timings(C2_K283, 0, ctx);
timings(C2_K283, 1, ctx);
timings(C2_B283, 0, ctx);
timings(C2_B283, 1, ctx);
timings(C2_K409, 0, ctx);
timings(C2_K409, 1, ctx);
timings(C2_B409, 0, ctx);
timings(C2_B409, 1, ctx);
timings(C2_K571, 0, ctx);
timings(C2_K571, 1, ctx);
timings(C2_B571, 0, ctx);
timings(C2_B571, 1, ctx);
#endif
if (ctx)
BN_CTX_free(ctx);
BN_free(p); BN_free(a); BN_free(b);
EC_GROUP_free(group);
EC_POINT_free(P);
EC_POINT_free(Q);
EC_POINT_free(R);
BN_free(x); BN_free(y); BN_free(z); BN_free(cof);
if (C2_K163) EC_GROUP_free(C2_K163);
if (C2_B163) EC_GROUP_free(C2_B163);
if (C2_K233) EC_GROUP_free(C2_K233);
if (C2_B233) EC_GROUP_free(C2_B233);
if (C2_K283) EC_GROUP_free(C2_K283);
if (C2_B283) EC_GROUP_free(C2_B283);
if (C2_K409) EC_GROUP_free(C2_K409);
if (C2_B409) EC_GROUP_free(C2_B409);
if (C2_K571) EC_GROUP_free(C2_K571);
if (C2_B571) EC_GROUP_free(C2_B571);
}
void internal_curve_test(void)
{
EC_builtin_curve *curves = NULL;
size_t crv_len = 0, n = 0;
int ok = 1;
crv_len = EC_get_builtin_curves(NULL, 0);
curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
if (curves == NULL)
return;
if (!EC_get_builtin_curves(curves, crv_len))
{
OPENSSL_free(curves);
return;
}
fprintf(stdout, "testing internal curves: ");
for (n = 0; n < crv_len; n++)
{
EC_GROUP *group = NULL;
int nid = curves[n].nid;
if ((group = EC_GROUP_new_by_nid(nid)) == NULL)
{
ok = 0;
fprintf(stdout, "\nEC_GROUP_new_by_nid() failed with"
" curve %s\n", OBJ_nid2sn(nid));
/* try next curve */
continue;
}
if (!EC_GROUP_check(group, NULL))
{
ok = 0;
fprintf(stdout, "\nEC_GROUP_check() failed with"
" curve %s\n", OBJ_nid2sn(nid));
EC_GROUP_free(group);
/* try the next curve */
continue;
}
fprintf(stdout, ".");
fflush(stdout);
EC_GROUP_free(group);
}
if (ok)
fprintf(stdout, " ok\n");
else
fprintf(stdout, " failed\n");
OPENSSL_free(curves);
return;
}
static const char rnd_seed[] = "string to make the random number generator think it has entropy";
int main(int argc, char *argv[])
{
/* enable memory leak checking unless explicitly disabled */
if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
{
CRYPTO_malloc_debug_init();
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
}
else
{
/* OPENSSL_DEBUG_MEMORY=off */
CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
ERR_load_crypto_strings();
RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */
prime_field_tests();
puts("");
char2_field_tests();
/* test the internal curves */
internal_curve_test();
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
ERR_free_strings();

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