Compare commits

...

160 Commits

Author SHA1 Message Date
David Benjamin f78fa1ea33 Always enable ecdh_auto.
This is a really dumb API wart. Now that we have a limited set of curves that
are all reasonable, the automatic logic should just always kick in. This makes
set_ecdh_auto a no-op and, instead of making it the first choice, uses it as
the fallback behavior should none of the older curve selection APIs be used.

Currently, by default, server sockets can only use the plain RSA key exchange.

BUG=481139

(cherry picked from commit dd978784d7)

Change-Id: I2ef653236c55df0d990c01cfdcaedbd757062e46
2015-05-04 17:43:00 -04:00
David Benjamin 40acdaeb86 Rename p_thread_callback_base to p_thread_callback_boringssl.
This fixes the Windows build. Otherwise this collides with the symbol in
Chromium's //base. (The 'base' suffix is the name of the library, not some
Windows-ism.)

Change-Id: I65d755f08991978bd2040d53c401082b2fee65fa
Reviewed-on: https://boringssl-review.googlesource.com/4217
Reviewed-by: Adam Langley <agl@google.com>
2015-04-03 17:17:32 +00:00
David Benjamin 72f5911a16 Fix the standalone shared library build.
BUG=473360

Change-Id: I6dc06eb425dd10c8d6a40d17f94405ea6f2f3905
Reviewed-on: https://boringssl-review.googlesource.com/4210
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 21:07:17 +00:00
David Benjamin 4d78718cde OPENSSL_EXPORT the threading functions.
Otherwise thread_test doesn't build in a components build.

Change-Id: I05d88bd2abc6fcbc43097a50cea0c064beafdb74
Reviewed-on: https://boringssl-review.googlesource.com/4209
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 20:36:58 +00:00
David Benjamin 89baa72ed8 Define __STDC_FORMAT_MACROS before inttypes.h.
It seems Android's inttypes.h refuses to define those macros on C++ unless
__STDC_FORMAT_MACROS is set. This unbreaks the roll on Android.

Change-Id: Iad6c971b4789f0302534d9e5022534c6124e0ff0
Reviewed-on: https://boringssl-review.googlesource.com/4202
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 18:39:18 +00:00
David Benjamin 0e434b9470 Define NOMINMAX across the entire project.
This fixes the standalone build on Windows and matches Chromium.

Change-Id: I194f53e0a610c5ae9cef53c826b22f7bded5f357
Reviewed-on: https://boringssl-review.googlesource.com/4201
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 18:38:56 +00:00
David Benjamin c0f763b080 Simplify server-side ECDH curve selection.
There's multiple sets of APIs for selecting the curve. Fold away
SSL_OP_SINGLE_ECDH_USE as failing to set it is either a no-op or a bug. With
that gone, the consumer only needs to control the selection of a curve, with
key generation from then on being uniform. Also clean up the interaction
between the three API modes in s3_srvr.c; they were already mutually exclusive
due to tls1_check_ec_tmp_key.

This also removes all callers of EC_KEY_dup (and thus CRYPTO_dup_ex_data)
within the library.

Change-Id: I477b13bd9e77eb03d944ef631dd521639968dc8c
Reviewed-on: https://boringssl-review.googlesource.com/4200
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 18:37:06 +00:00
Adam Langley e631d9679e Don't False Start with DHE.
BUG=460271

Change-Id: I271a270067605ec629944633c3e22c2069ba9a24
Reviewed-on: https://boringssl-review.googlesource.com/4192
Reviewed-by: Adam Langley <agl@google.com>
2015-04-02 00:34:17 +00:00
David Benjamin be55790652 Disable the malloc test interceptor on ASan.
ASan's own malloc interceptor isn't compatible with this mechanism; it doesn't
see calls to __libc_malloc.

Change-Id: Ibac5aa05c6e40f1c72dcee3a2597e96deffca62c
Reviewed-on: https://boringssl-review.googlesource.com/4191
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 20:08:18 +00:00
David Benjamin f8c2c9e9f0 Convert bytestring_test to C++.
Change-Id: Id3e6183da3ae328b562ec5413151256cf6071ffc
Reviewed-on: https://boringssl-review.googlesource.com/4140
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 20:07:43 +00:00
David Benjamin a1283f75f1 Convert err_test to C++.
Another easy one. Doesn't actually buy us much.

Change-Id: I166ae08e61c69bedea4de0a74ddd4dfc4699577d
Reviewed-on: https://boringssl-review.googlesource.com/4129
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 19:59:44 +00:00
David Benjamin 3db1ded2e7 Convert bio_test to C++.
Change-Id: I6416eb6b2474e4fbb974a7da8a9bc6d2b4c44adb
Reviewed-on: https://boringssl-review.googlesource.com/4128
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 19:59:03 +00:00
David Benjamin e8261a0100 Convert base64_test to C++.
Not actually much of a change, but consistency.

Change-Id: If2ef7a8b698a229f5c494822d870767e1a61476e
Reviewed-on: https://boringssl-review.googlesource.com/4127
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 19:54:13 +00:00
David Benjamin a5974bfae7 Convert bn_test to C++.
Along the way, fix a host of missing failure checks. This will save some
headache when it comes time to run these under the malloc failure tests.

Change-Id: I3fd589bd094178723398e793d6bc578884e99b67
Reviewed-on: https://boringssl-review.googlesource.com/4126
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 19:53:51 +00:00
David Benjamin e12c4378e9 Fix leak in ssl_test.
SSL_CIPHER_get_rfc_name still returns an allocated string.

Change-Id: Ie2f14626c1ff22d0ea613b22439b7de5c04c9062
Reviewed-on: https://boringssl-review.googlesource.com/4190
Reviewed-by: Adam Langley <agl@google.com>
2015-04-01 18:22:23 +00:00
David Benjamin 5a3162a521 Convert hmac_test to C++.
Change-Id: I50db70385634c51ed692ac0ebf9732f46130ca41
Reviewed-on: https://boringssl-review.googlesource.com/4125
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:13:49 +00:00
David Benjamin f93d737c86 Convert pbkdf_test to C++11.
We don't really gain much from this one, but consistency.

Change-Id: I3f830c6d1ad65263bd1cc09372a5b810a8f690c0
Reviewed-on: https://boringssl-review.googlesource.com/4124
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:12:11 +00:00
David Benjamin 94e597a51c Convert digest_test to C++.
Change-Id: Ibc8c3d8740cbd03dfb0d1ff9834fed66601dd479
Reviewed-on: https://boringssl-review.googlesource.com/4123
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:10:24 +00:00
David Benjamin c2b45a164a Convert evp_test to C++.
Change-Id: I6e51815db2f600f4d9fb4d8b01cc92e128b31bbb
Reviewed-on: https://boringssl-review.googlesource.com/4122
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:08:53 +00:00
David Benjamin 1d77e56b29 Convert ssl_test to C++.
Change-Id: Ic8f3cd5c6a89e07bbae43b1599a01fedf119b081
Reviewed-on: https://boringssl-review.googlesource.com/4121
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:03:54 +00:00
David Benjamin 45fb1be33e Remove std::unique_ptr dependency on bssl_shim's scoped types.
This is in preparation for using RAII in the unit tests. Those tests are built
in Chromium as well, but Chromium does not have C++11 library support across
all its toolchains. Compiler support is available, so add a partial
reimplementation of std::unique_ptr and std::move under crypto/test/. The
scopers for the crypto/ library are also moved there while the ones for ssl/
stay in ssl/test/.

Change-Id: I38f769acbc16a870db34649928575c7314b6e9f6
Reviewed-on: https://boringssl-review.googlesource.com/4120
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 23:03:06 +00:00
Adam Langley d7c5dfb233 Add native support for onces and thread-local storage.
Historically, OpenSSL has used callbacks for anything thread related,
but we don't actually have that many threading libraries to worry about:
just pthreads and Windows (I hope).

That suggests that it's quite reasonable to handle threading ourselves,
and eliminate the need for users to remember to install the thread
callbacks.

The first user of this would be ERR, which currently simulates
thread-local storage using a lock around a hash table keyed by the TID.
(Although I suspect that change will need some CMake work in order that
libpthread is automatically included with libcrypto when linking tests
etc, but not on Windows and without lots of ifs.)

Change-Id: I4dd088e3794506747f875c1f3e92b9bc6700fad2
Reviewed-on: https://boringssl-review.googlesource.com/4010
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 22:37:12 +00:00
Adam Langley c11e13a78b Support MIPS64.
MIPS64 confusingly sets __mips__, but it's not a 32-bit platform. This
change updates the defines in base.h to recognise MIPS64 based on both
__mips__ and __LP64__ being defined.

Change-Id: I220f5d9c8f1cd7d3089cc013348e6f95cdee76d9
Reviewed-on: https://boringssl-review.googlesource.com/4093
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 22:27:10 +00:00
Adam Langley 20b64fd19d Export the PSS padding functions.
(system/keymaster is using them now.)

Change-Id: I8fba501005b9318b7d3a76bf1715fb772b23c49d
Reviewed-on: https://boringssl-review.googlesource.com/4092
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 22:26:57 +00:00
Adam Langley 32ab7b0e74 Use libmingwex for gmtime_s.
gmtime_s first appeared in MSVCR80, but libmingwex has a helper function
that tries to find the symbol or falls back to an internal
implementation.

(Patch by Kenny Root.)

Change-Id: I96ef9cd7459d7e8202831a4e687dfbc055c9f50b
Reviewed-on: https://boringssl-review.googlesource.com/4091
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 22:21:57 +00:00
Adam Langley 3e719319be Lowercase some Windows headers.
MinGW on Linux needs lowercase include files. On Windows this doesn't
matter since the filesystems are case-insensitive, but building
BoringSSL on Linux with MinGW has case-sensitive filesystems.

Change-Id: Id9c120d819071b041341fbb978352812d6d073bc
Reviewed-on: https://boringssl-review.googlesource.com/4090
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 22:21:42 +00:00
Adam Langley e2e13265ff Don't set NEON_FUNCTIONAL in the getauxval path.
NEON_FUNCTIONAL is set by default in crypto.c. Chromium calls
|CRYPTO_set_NEON_functional| before |SSL_library_init| and thus the
getauxval path for CPU-feature detection was resetting the functional
flag, even on broken processors.

This change means that, apart from the default, only
|CRYPTO_set_NEON_functional| will change the NEON_FUNCTIONAL flag.

BUG=469511

Change-Id: I3d4dbbd9f4a5e33539f8559f90289e706ad17451
Reviewed-on: https://boringssl-review.googlesource.com/4170
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-31 00:26:25 +00:00
David Benjamin 4616bb1e6e Build 32-bit assembly with SSE2 enabled.
This affects bignum and sha. Also now that we're passing the SSE2 flag, revert
the change to ghash-x86.pl which unconditionally sets $sse2, just to minimize
upstream divergence. Chromium assumes SSE2 support, so relying on it is okay.
See https://crbug.com/349320.

Note: this change needs to be mirrored in Chromium to take.

bssl speed numbers:

SSE2:
Did 552 RSA 2048 signing operations in 3007814us (183.5 ops/sec)
Did 19003 RSA 2048 verify operations in 3070779us (6188.3 ops/sec)
Did 72 RSA 4096 signing operations in 3055885us (23.6 ops/sec)
Did 4650 RSA 4096 verify operations in 3024926us (1537.2 ops/sec)

Without SSE2:
Did 350 RSA 2048 signing operations in 3042021us (115.1 ops/sec)
Did 11760 RSA 2048 verify operations in 3003197us (3915.8 ops/sec)
Did 46 RSA 4096 signing operations in 3042692us (15.1 ops/sec)
Did 3400 RSA 4096 verify operations in 3083035us (1102.8 ops/sec)

SSE2:
Did 16407000 SHA-1 (16 bytes) operations in 3000141us (5468743.0 ops/sec): 87.5 MB/s
Did 4367000 SHA-1 (256 bytes) operations in 3000436us (1455455.1 ops/sec): 372.6 MB/s
Did 185000 SHA-1 (8192 bytes) operations in 3002666us (61611.9 ops/sec): 504.7 MB/s
Did 9444000 SHA-256 (16 bytes) operations in 3000052us (3147945.4 ops/sec): 50.4 MB/s
Did 2283000 SHA-256 (256 bytes) operations in 3000457us (760884.1 ops/sec): 194.8 MB/s
Did 89000 SHA-256 (8192 bytes) operations in 3016024us (29509.0 ops/sec): 241.7 MB/s
Did 5550000 SHA-512 (16 bytes) operations in 3000350us (1849784.2 ops/sec): 29.6 MB/s
Did 1820000 SHA-512 (256 bytes) operations in 3001039us (606456.6 ops/sec): 155.3 MB/s
Did 93000 SHA-512 (8192 bytes) operations in 3007874us (30918.8 ops/sec): 253.3 MB/s

Without SSE2:
Did 10573000 SHA-1 (16 bytes) operations in 3000261us (3524026.7 ops/sec): 56.4 MB/s
Did 2937000 SHA-1 (256 bytes) operations in 3000621us (978797.4 ops/sec): 250.6 MB/s
Did 123000 SHA-1 (8192 bytes) operations in 3033202us (40551.2 ops/sec): 332.2 MB/s
Did 5846000 SHA-256 (16 bytes) operations in 3000294us (1948475.7 ops/sec): 31.2 MB/s
Did 1377000 SHA-256 (256 bytes) operations in 3000335us (458948.8 ops/sec): 117.5 MB/s
Did 54000 SHA-256 (8192 bytes) operations in 3027962us (17833.8 ops/sec): 146.1 MB/s
Did 2075000 SHA-512 (16 bytes) operations in 3000967us (691443.8 ops/sec): 11.1 MB/s
Did 638000 SHA-512 (256 bytes) operations in 3000576us (212625.8 ops/sec): 54.4 MB/s
Did 30000 SHA-512 (8192 bytes) operations in 3042797us (9859.3 ops/sec): 80.8 MB/s

BUG=430237

Change-Id: I47d1c1ffcd71afe4f4a192272f8cb92af9505ee1
Reviewed-on: https://boringssl-review.googlesource.com/4130
Reviewed-by: Adam Langley <agl@google.com>
2015-03-26 23:35:56 +00:00
David Benjamin 87ac295d5d Remove unused fields from EVP_PKEY.
None of these are ever set.

Change-Id: If92554a4c560bf8fa2d630c419a946711db30839
Reviewed-on: https://boringssl-review.googlesource.com/4114
Reviewed-by: Adam Langley <agl@google.com>
2015-03-25 15:32:33 +00:00
David Benjamin 05a5beb35c Add support for finding depot_tools' MSVC toolchain on the bots.
- Pull in a trimmed down version of vs_toolchain.py from Chromium.

- Drop in toolchain_vs2013.hash from Chromium to use Chromium's
  current toolchain.

- Add a very hacky vs_env.py to pull in Visual Studio. This is
  loosely based off a handful of lines of Chromium's
  tools/clang/scripts/update.py. This (and vs_toolchain.py) depends
  on gyp which is now pulled in via DEPS.

BUG=430237

Change-Id: Ic29cbb15e19a99616cfe778d0778b9a71c45338a
Reviewed-on: https://boringssl-review.googlesource.com/3900
Reviewed-by: Adam Langley <agl@google.com>
2015-03-25 15:31:55 +00:00
David Benjamin 340d5ed295 Test that warning alerts are ignored.
Partly inspired by the new state exposed in
dc3da93899, stress this codepath by spamming our
poor shim with warning alerts.

Change-Id: I876c6e52911b6eb57493cf3e1782b37ea96d01f8
Reviewed-on: https://boringssl-review.googlesource.com/4112
Reviewed-by: Adam Langley <agl@google.com>
2015-03-25 15:25:28 +00:00
David Benjamin 0570923ed2 Add additional features to bssl client.
This exposes the features needed to mimic Chrome's ClientHello, which is useful
in testing. Also use bssl_shim's scopers for SSL objects.

Change-Id: Icb88bb00c0a05c27610134d618f466a24f7f757a
Reviewed-on: https://boringssl-review.googlesource.com/4113
Reviewed-by: Adam Langley <agl@google.com>
2015-03-23 23:16:30 +00:00
David Benjamin 0d4db50a54 Use C++11 inline initialization.
Google C++ style allows these. It's also considerably less tedious and
error-prone than defining an out-of-line constructor.

Change-Id: Ib76ccf6079be383722433046ac5c5d796dd1f525
Reviewed-on: https://boringssl-review.googlesource.com/4111
Reviewed-by: Adam Langley <agl@google.com>
2015-03-23 23:09:11 +00:00
David Benjamin e5a3ac2cac Fix fail_second_ddos_callback flag.
It was failing only on 32-bit for some reason. Part of TestConfig wasn't
getting initialized.

Change-Id: I2a3747a347a47b47e2357f34d32f8db86d6cc629
Reviewed-on: https://boringssl-review.googlesource.com/4110
Reviewed-by: Adam Langley <agl@google.com>
2015-03-23 23:08:48 +00:00
David Benjamin 8056343a58 Fix CRYPTO_add_lock documentation.
It's not actually CRYPTO_add_locked, despite the name. I guess they just needed
a name that didn't clash with CRYPTO_add.

Change-Id: I3fdee08bf75e9a4e1b5e75630707c0be5792599b
Reviewed-on: https://boringssl-review.googlesource.com/4102
Reviewed-by: Adam Langley <agl@google.com>
2015-03-23 23:08:20 +00:00
David Benjamin b6d0c6db5e Remove the stats block in SSL_CTX.
Within the library, only ssl_update_cache read them, so add a dedicated field
to replace that use.

The APIs have a handful of uninteresting callers so I've left them in for now,
but they now always return zero.

Change-Id: Ie4e36fd4ab18f9bff544541d042bf3c098a46933
Reviewed-on: https://boringssl-review.googlesource.com/4101
Reviewed-by: Adam Langley <agl@google.com>
2015-03-23 23:07:56 +00:00
David Benjamin 90fa69aaae Remove unnecessary -ldl and clean up includes for malloc tests.
I'm guessing a previous iteration used dlsym to look up the real malloc.

Change-Id: I18be9ef4db4ed059400074c8507d4e2fea882fbc
Reviewed-on: https://boringssl-review.googlesource.com/4100
Reviewed-by: Adam Langley <agl@google.com>
2015-03-21 00:07:42 +00:00
Håvard Molland ab2479a08a Clean up error reporting.
Quite a few functions reported wrong function names when pushing
to the error stack.

Change-Id: I84d89dbefd2ecdc89ffb09799e673bae17be0e0f
Reviewed-on: https://boringssl-review.googlesource.com/4080
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-20 22:12:59 +00:00
Adam Langley 32156b974d Add some more Android compatibility declarations.
Change-Id: Ia1de2b746dec680eb59dc614295a1da289c5741a
2015-03-20 11:50:29 -07:00
David Benjamin 72dc7834af Test that signature_algorithm preferences are enforced.
Both on the client and the server.

Change-Id: I9892c6dbbb29938154aba4f53b10e8b5231f9c47
Reviewed-on: https://boringssl-review.googlesource.com/4071
Reviewed-by: Adam Langley <agl@google.com>
2015-03-20 18:23:54 +00:00
David Benjamin 67d1fb59ad Test that client cipher preferences are enforced.
Change-Id: I6e760cfd785c0c5688da6f7d3d3092a8add40409
Reviewed-on: https://boringssl-review.googlesource.com/4070
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 22:44:49 +00:00
David Benjamin 642f1498d0 evp: prevent underflow in base64 decoding
This patch resolves RT ticket #2608.

(Imported from upstream's d0666f289ac013094bbbf547bfbcd616199b7d2d.)

Change-Id: If0c8f583f3f643f3db6b6158cbc9ad7541bab8ec
Reviewed-on: https://boringssl-review.googlesource.com/4060
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 21:59:28 +00:00
David Benjamin 7061e28dc2 Rename EECDH and EDH to ECDHE and DHE.
Align with upstream's renames from a while ago. These names are considerably
more standard. This also aligns with upstream in that both "ECDHE" and "EECDH"
are now accepted in the various cipher string parsing bits.

Change-Id: I84c3daeacf806f79f12bc661c314941828656b04
Reviewed-on: https://boringssl-review.googlesource.com/4053
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:54:58 +00:00
David Benjamin 3c9746a6d7 Regression test for CVE-2015-0291.
This is really just scar tissue with https://crbug.com/468889 being the real
underlying problem. But the test is pretty easy.

Change-Id: I5eca18fdcbde8665c0e6c3ac419a28152647d66f
Reviewed-on: https://boringssl-review.googlesource.com/4052
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:52:59 +00:00
David Benjamin b85a4c2923 Remove unnecessary NULL initializations in ssl_cert_dup.
A casual grep would suggest this function has the same problems as
CVE-2015-0291, but the structure is memset to 0, so the calls are unnecessary.
Also use BUF_memdup rather than an OPENSSL_malloc + mempcy pair.

Change-Id: Id605374d99cff32e2dccb7f9b8a9da226faf7715
Reviewed-on: https://boringssl-review.googlesource.com/4051
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:52:57 +00:00
David Benjamin cdea40c3e2 Add tests for full handshakes under renegotiation.
In verifying the fix for CVE-2015-0291, I noticed we don't actually have any
test coverage for full handshakes on renegotiation. All our tests always do
resumptions.

Change-Id: Ia9b701e8a50ba9353fefb8cc4fb86e78065d0b40
Reviewed-on: https://boringssl-review.googlesource.com/4050
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:51:16 +00:00
David Benjamin 4b1510c71e Fix a failure to NULL a pointer freed on error.
Reported by the LibreSSL project as a follow on to CVE-2015-0209

(Imported from upstream's 5e5d53d341fd9a9b9cc0a58eb3690832ca7a511f.)

Change-Id: Ic2e5dc5c96e316c55f76bedc6ea55b416be3287a
Reviewed-on: https://boringssl-review.googlesource.com/4049
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:50:32 +00:00
David Benjamin 7a8e62dbd9 Fix ASN1_TYPE_cmp
Fix segmentation violation when ASN1_TYPE_cmp is passed a boolean type. This
can be triggered during certificate verification so could be a DoS attack
against a client or a server enabling client authentication.

CVE-2015-0286

(Imported from upstream's e677e8d13595f7b3287f8feef7676feb301b0e8a.)

Change-Id: I5faefc190568504bb5895ed9816a6d80432cfa45
Reviewed-on: https://boringssl-review.googlesource.com/4048
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:48:41 +00:00
David Benjamin 61c0d4e8b2 Always reset sigalgslen when NULLing sigalgs.
See also upstream's 34e3edbf3a10953cb407288101fd56a629af22f9. This fixes
CVE-2015-0291. Also bubble up malloc failures in tls1_set_shared_sigalgs. Tidy
up style a bit and remove unnecessary check (it actually is unnecessary; see
https://boringssl-review.googlesource.com/4042).

Change-Id: Idfb31a90fb3e56ef6fe7701464748a5c1603f064
Reviewed-on: https://boringssl-review.googlesource.com/4047
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:46:28 +00:00
David Benjamin c12d377e24 Free up ADB and CHOICE if already initialised.
CVE-2015-0287

(Imported from upstream's b485d976340d3ca080060c3c7dee9102e2200762.)

Change-Id: Ie8dac46ccc95a4eee9ef535d8620217202f13ca1
Reviewed-on: https://boringssl-review.googlesource.com/4046
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:42:27 +00:00
David Benjamin 7e3b5840c2 Fix more missing error checks in v3_cpols.c
I only imported half of upstream's c5f2b5336ab72e40ab91e2ca85639f51fa3178c6 on
accident.

Change-Id: Ice8185ca6770f915eb859e918f5db7d5ccdc7cc7
Reviewed-on: https://boringssl-review.googlesource.com/4045
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 19:41:28 +00:00
Adam Langley 078abceb29 Don't install SIGILL handler until after sigsetjmp.
Previously, if SIGILL was received between the signal handler being
installed and before the sigsetjmp, the process would longjmp to a
random location.

Change-Id: I9e6143a17ff3db0e1b00ece68fce161801461010
Reviewed-on: https://boringssl-review.googlesource.com/3950
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:53:07 +00:00
David Benjamin 8b368412d3 Minor formatting fixes.
Noticed these as I was poking around.

Change-Id: I93833a152583feced374c9febf7485bec7abc1c7
Reviewed-on: https://boringssl-review.googlesource.com/3973
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:52:44 +00:00
David Benjamin 9e13e1a31d Move the is_dtls bit from SSL3_ENC_METHOD to SSL_PROTOCOL_METHOD.
This too isn't version-specific. This removes the final difference between TLS
and DTLS SSL3_ENC_METHODs and we can fold them together. (We should be able to
fold away the version-specific differences too, but all in due time.)

Change-Id: I6652d3942a0970273d46d28d7052629c81f848b5
Reviewed-on: https://boringssl-review.googlesource.com/3771
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:51:49 +00:00
David Benjamin cfdd6b1aef Account for partial reads in PacketedBio.
This fixes test flakiness on Windows.

BUG=467767

Change-Id: Ie69b5b43ddd524aadb15c53705f6ec860e928786
Reviewed-on: https://boringssl-review.googlesource.com/4001
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:49:37 +00:00
David Benjamin 506fa4f770 Allocate string types directly.
Allocate and free ASN.1 string types directly instead of going through
the ASN.1 item code.

(Imported from upstream's 3d6aa6d441fe8124d247dffee5c68c2e5efd8258.)

Change-Id: I617283e67071a792f219ed08f19078afc223e2f5
Reviewed-on: https://boringssl-review.googlesource.com/4041
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:47:52 +00:00
David Benjamin 42574efaff Avoid undefined behavior in probable_prime.
(Imported from upstream's e4676e900f165f5272991443225813002300b09b.)

Change-Id: I678e158c223daf2f7f9114f4e743d531fe2e2a93
Reviewed-on: https://boringssl-review.googlesource.com/4044
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:36:49 +00:00
David Benjamin cdcecf546b Fix regression in ASN1_UTCTIME_cmp_time_t
Previously, ASN1_UTCTIME_cmp_time_t would return 1 if s > t, -1 if
s < t, and 0 if s == t.

This behavior was broken in upstream's
904348a4922333106b613754136305db229475ea, resulting in the opposite time
comparison behavior.

PR#3706

(Imported from upstream's da27006df06853a33b132133699a7aa9d4277920.)

Change-Id: I9c1c28ba21d82ff4b587e33b262f46be4e846ff9
Reviewed-on: https://boringssl-review.googlesource.com/4043
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:36:10 +00:00
David Benjamin a5a3eeb9cc Remove ssl_cert_inst()
It created the cert structure in SSL_CTX or SSL if it was NULL, but they can
never be NULL as the comments already said.

(Imported from upstream's 2c3823491d8812560922a58677e3ad2db4b2ec8d.)

Change-Id: I97c7bb306d6f3c18597850db9f08023b2ef74839
Reviewed-on: https://boringssl-review.googlesource.com/4042
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:35:46 +00:00
David Benjamin ced555394f Fix undefined behavior in shifts.
Td4 is an array of u8. A u8 << int promotes the u8 to an int first then shifts.
If the mathematical result of a shift (as modelled by lhs * 2^{rhs}) is not
representable in an integer, behaviour is undefined. In other words, you can't
shift into the sign bit of a signed integer. Fix this by casting to u32
whenever we're shifting left by 24.

(For consistency, cast other shifts, too.)

Caught by -fsanitize=shift

Submitted by Nick Lewycky (Google)

(Imported from upstream's 8b37e5c14f0eddb10c7f91ef91004622d90ef361.)

Change-Id: Id0f98d1d65738533c6ddcc3c21bc38b569d74793
Reviewed-on: https://boringssl-review.googlesource.com/4040
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:33:46 +00:00
David Benjamin 34860739de ASN.1 print fix.
When printing out an ASN.1 structure, if the type is an item template don't
fall through and attempt to interpret as a primitive type.

(Imported from upstream's 5dc1247a7494f50c88ce7492518bbe0ce6f124fa.)

Change-Id: Ica39757792cbf3f83879953b67838927ddbdb809
Reviewed-on: https://boringssl-review.googlesource.com/4009
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:32:45 +00:00
David Benjamin 859a04b7ff Fix missing return checks in v3_cpols.c
Fixed assorted missing return value checks in v3_cpols.c

(Imported from upstream's c5f2b5336ab72e40ab91e2ca85639f51fa3178c6.)

Change-Id: I95e4157fc689201ca32e1c8e51d04801ba478685
Reviewed-on: https://boringssl-review.googlesource.com/4008
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:31:03 +00:00
David Benjamin a9c6667cab Fix asn1_item_print_ctx
The call to asn1_do_adb can return NULL on error, so we should check the
return value before attempting to use it.

(Imported from upstream's 34a7ed0c39aa3ab67eea1e106577525eaf0d7a00.)

Change-Id: Ia43cdc73b5f1d16e6fc907b5aaf13c9df5a9958c
Reviewed-on: https://boringssl-review.googlesource.com/4007
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:28:48 +00:00
David Benjamin e30f3fb080 ASN1_primitive_new NULL param handling
ASN1_primitive_new takes an ASN1_ITEM * param |it|. There are a couple
of conditional code paths that check whether |it| is NULL or not - but
later |it| is deref'd unconditionally. If |it| was ever really NULL then
this would seg fault. In practice ASN1_primitive_new is marked as an
internal function in the public header file. The only places it is ever
used internally always pass a non NULL parameter for |it|. Therefore, change
the code to sanity check that |it| is not NULL, and remove the conditional
checking.

(Imported from upstream's 9e488fd6ab2c295941e91a47ab7bcd346b7540c7)

Change-Id: Icbb13cd00d0ec5529871b678b0bcc465956a7572
Reviewed-on: https://boringssl-review.googlesource.com/4006
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:11:04 +00:00
David Benjamin c02f148fa8 Fix error handling in bn_exp
In the event of an error |rr| could be NULL. Therefore don't assume you can
use |rr| in the error handling code.

(Imported from upstream's 8c5a7b33c6269c3bd6bc0df6b4c22e4fba03b485.)

Change-Id: I0b392991ce8170dc418e93003af256d535d1e2e8
Reviewed-on: https://boringssl-review.googlesource.com/4005
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:10:27 +00:00
David Benjamin 87b2a13a86 Fix seg fault in ASN1_generate_v3/ASN1_generate_nconf
(Imported from upstream's ac5a110621ca48f0bebd5b4d76d081de403da29e)

Change-Id: I1a0518447716a93038bd95d40abef1d9fb4e5f72
Reviewed-on: https://boringssl-review.googlesource.com/4004
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:08:50 +00:00
David Benjamin 2ddba8cd48 Check for RAND_bytes failures in the ClientHello.
(Imported from upstream's e1b568dd2462f7cacf98f3d117936c34e2849a6b.)

Our RAND_bytes secretly can't actually fail, but we should propagate the check
upwards.

Change-Id: Ieaaea98dad00bf73b1c0a42c039507d76b10ac78
Reviewed-on: https://boringssl-review.googlesource.com/4003
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:08:25 +00:00
David Benjamin 3305858342 Fix wrong numbers being passed as string lengths
(Imported from upstream's 0b142f022e2c5072295e00ebc11c5b707a726d74.)

Modified further because these ought to just be BIO_puts.

Change-Id: I8b70d70d0f626bb19b455adb4f0e08bacf453c1d
Reviewed-on: https://boringssl-review.googlesource.com/4002
Reviewed-by: Adam Langley <agl@google.com>
2015-03-19 11:07:45 +00:00
Adam Langley f21645f4e3 Typo fix in comment.
(Thanks to William Hesse.)

Change-Id: I8479663250546a5ec0a024f80e50541f91d833bc
Reviewed-on: https://boringssl-review.googlesource.com/4020
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 22:01:26 +00:00
David Benjamin 067321502d Explicitly document EVP_PKEY_size vs EVP_PKEY_bits.
They do not quite measure the same value for EC keys. "size" is a really weird
notion to generalize on so we should document what it means for each key type.
EVP_PKEY_size's meaning is most tied to signatures, thanks to EVP_SignFinal
implicitly using it as output bounds.

Change-Id: I7504c142818f8f90f8bcf6891c97a6adaf2d574e
Reviewed-on: https://boringssl-review.googlesource.com/4000
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 21:45:42 +00:00
Adam Langley 1df63e93f9 Fix a couple of issues with building with strict C99.
C99 doesn't, technically, allow empty statements. Thus if a #define'ed
function ends in a semicolon, and the use of it also ends in a
semicolon, then the compiler sees “;;” at the end.

Since a choice has to be made, I prefer that the semicolon exist at the
“callsite” of a #define'ed fuction. But I haven't gone and changed
everything to follow that in this patch.

Change-Id: I1343e52a5ac6255db49aa053048d0df3225bcf43
Reviewed-on: https://boringssl-review.googlesource.com/3890
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 21:17:40 +00:00
Adam Langley 0e782a9eb3 Add AEADs for AES-CTR with HMAC-SHA256.
Change-Id: Id035d2c6ab9c6ae034326c313ffe35e0d035dec1
Reviewed-on: https://boringssl-review.googlesource.com/3911
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 21:16:55 +00:00
Adam Langley 52f9f62283 Change aes_set_gcm_key to be more flexible.
Firstly, it was odd that AES-NI was a special case. Secondly, I have a
need coming up for being able to get the block function and not create a
GCM context.

Change-Id: Ie87de5e7ea42dc042d302c5eafecbc6af03c714b
Reviewed-on: https://boringssl-review.googlesource.com/3910
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 21:16:39 +00:00
Adam Langley 5edc4e2a9b Correct three incorrect function names in errors.
Thanks to Sean Burford.

Change-Id: I4efa352f3e830c4c3761660508a1a8aa927eedf1
Reviewed-on: https://boringssl-review.googlesource.com/3841
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 21:15:04 +00:00
Adam Langley ca8feeb301 Add support for 3DES ECB.
At least the linker can discard this function in the cases where nobody
is calling it.

Change-Id: I30050e918e6bc1dd9c97cc70f3a56408701abebc
Reviewed-on: https://boringssl-review.googlesource.com/3724
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 19:55:14 +00:00
Adam Langley 7282738bad Add DES_set_odd_parity.
Because NTLM authentication is still a thing.

Change-Id: I3308a8431c82f0b614e09ce3e5efac1526881f1e
Reviewed-on: https://boringssl-review.googlesource.com/3723
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 19:54:53 +00:00
Adam Langley 3f92d21094 Add SSL_get_rc4_state.
This allows the current RC4 state of an SSL* to be extracted. We have
internal uses for this functionality.

Change-Id: Ic124c4b253c8325751f49e7a4c021768620ea4b7
Reviewed-on: https://boringssl-review.googlesource.com/3722
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 19:54:34 +00:00
Adam Langley 524e717b87 Add a callback for DDoS protection.
This callback receives information about the ClientHello and can decide
whether or not to allow the handshake to continue.

Change-Id: I21be28335fa74fedb5b73a310ee24310670fc923
Reviewed-on: https://boringssl-review.googlesource.com/3721
Reviewed-by: Adam Langley <agl@google.com>
2015-03-18 19:53:29 +00:00
Brian Smith ab2a8e03d9 Fix duplicate lock IDs & simplify lock ID maintenance.
* Eliminate the possibility of multiple lock IDs having the same
  value (CRYPTO_LOCK_FIPS2 and CRYPTO_LOCK_OBJ were both 40 prior to
  this commit).
* Remove unused lock IDs.
* Automatically guarantee that lock IDs and lock names stay in sync.

Change-Id: If20e462db1285fa891595a7e52404ad011ff16f6
Reviewed-on: https://boringssl-review.googlesource.com/3923
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 23:58:20 +00:00
David Benjamin d434f28ef2 Fix bssl speed.
The TLS AEADs require EVP_AEAD_CTX_init_with_direction now. The speed command
was never updated to account for this.

BUG=467762

Change-Id: I8c7d4566b51d54d91d17318b8f4813ad8f19c777
Reviewed-on: https://boringssl-review.googlesource.com/3971
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 23:57:02 +00:00
David Benjamin 1b3a95122d Document exactly how the stateful AEADs are weird.
Probably worth spelling that out.

Change-Id: Ie8815fc645e2836f4fb5bf7d09df1e5326751544
Reviewed-on: https://boringssl-review.googlesource.com/3970
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 23:55:56 +00:00
Brian Smith 1d1562d9b5 Free new[]'d array using delete[] instead of free in speed.cc.
Change-Id: Ic3d5e8de0b6800c0852c2057427836302c1f1aaa
Reviewed-on: https://boringssl-review.googlesource.com/3962
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 21:04:15 +00:00
Brian Smith a42b4163f8 Remove remaining remnants of RIPEMD-160 support.
Change-Id: I59d06bcb9245ba93d3c3b63afbc24d6cef7c5af4
Reviewed-on: https://boringssl-review.googlesource.com/3925
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 21:03:42 +00:00
Brian Smith d53b2c3c88 Fix out-of-bounds memory write in speed.cc.
Windows x64 uses the IL32P64 data model, which means that unsigned int
is 32 bits and size_t is 64 bits. Previously, the expression
|~(alignment - 1)| resulted in the 32-bit value 0xFFFFFFF0, which was
then extended to the 64-bit value 0x00000000FFFFFFF0 when promoted to
size_t. When the input pointer was masked with this value, the result
was a pointer that was usually way outside the boundaries of the array.

The new code casts |alignment| to size_t first prior to the bitwise
negation, resulting in the correct mask value of 0xFFFFFFFFFFFFFFF0.

Change-Id: I04754aa9e1ce7a615c2b4c74051cfcca38dbb52f
Reviewed-on: https://boringssl-review.googlesource.com/3961
Reviewed-by: Adam Langley <agl@google.com>
2015-03-17 19:12:54 +00:00
Brian Smith 4df48dd30f Define more OPENSSL_NO_xxx flags in opensslfeatures.h.
Change-Id: I464159dd03a2ea9a5e01452888fda86a5af51024
Reviewed-on: https://boringssl-review.googlesource.com/3924
Reviewed-by: Adam Langley <agl@google.com>
2015-03-14 00:21:01 +00:00
Brian Smith 949b26827a Remove Unused SPARC & PowerPC perlasm scripts.
Change-Id: I6139a3e9a2780c5a52169c72afc95665d453da8c
Reviewed-on: https://boringssl-review.googlesource.com/3922
Reviewed-by: Adam Langley <agl@google.com>
2015-03-14 00:16:55 +00:00
Brian Smith 28120a18f6 Fix mistaken use of CRYPTO_EX_INDEX_DSA in rsa.c.
Change-Id: I4a81fcbdd79f96b34cafcbd33279906b55dafbac
Reviewed-on: https://boringssl-review.googlesource.com/3920
Reviewed-by: Adam Langley <agl@google.com>
2015-03-14 00:14:40 +00:00
David Benjamin dc3da93899 Process alerts between ChangeCipherSpec and Finished.
This mostly[*] doesn't matter for TLS since the message would have been
rejected anyway, but, in DTLS, if the peer rejects our Finished, it will send
an encrypted alert. This will then cause it to hang, which isn't very helpful.

I've made the change on both TLS and DTLS so the two protocols don't diverge on
this point. It is true that we're accepting nominally encrypted and
authenticated alerts before Finished, but, prior to ChangeCipherSpec, the
alerts are sent in the clear anyway so an attacker could already inject alerts.
A consumer could only be sensitive to it being post-CCS if it was watching
msg_callback. The only non-debug consumer of msg_callback I've found anywhere
is some hostapd code to detect Heartbeat.

See https://code.google.com/p/webrtc/issues/detail?id=4403 for an instance
where the equivalent behavior in OpenSSL masks an alert.

[*] This does change behavior slightly if the peer sends a warning alert
between CCS and Finished. I believe this is benign as warning alerts are
usually ignored apart from info_callback and msg_callback. The one exception is
a close_notify which is a slightly new state (accepting close_notify during a
handshake seems questionable...), but they're processed pre-CCS too.

Change-Id: Idd0d49b9f9aa9d35374a9f5e2f815cdb931f5254
Reviewed-on: https://boringssl-review.googlesource.com/3883
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 20:19:11 +00:00
David Benjamin 4f7783eaea Use EC_KEY_new_by_curve_name.
May as well use this convenience function when we can. A little tidier. Even
fixes a leak on malloc failure in eckey_type2param.

Change-Id: Ie48dd98f2fe03fa9911bd78db4423ab9faefc63d
Reviewed-on: https://boringssl-review.googlesource.com/3772
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:49:39 +00:00
David Benjamin 7cb0f44d9d Remove EVP_MAXCHUNK from DES EVP code.
Upstream needs this to deal with size_t, but our low-level DES APIs take
size_t, so this is not a concern.

Change-Id: I9dc4c7248c5dd9515246a4b224147b932328a400
Reviewed-on: https://boringssl-review.googlesource.com/3882
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:46:49 +00:00
David Benjamin 165de16c2e Import additional AES-GCM test vector from upstream.
Upstream added another test vector in 4e049c52599d4a3fd918ba8570f49d88159e551b.

Change-Id: I17855dd479214657f0698b78f93e183cd6cb912e
Reviewed-on: https://boringssl-review.googlesource.com/3880
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:41:49 +00:00
David Benjamin 1a5c50f3a8 Error codes are uint32_t, not unsigned long.
Fix a few remnants of them being unsigned long. Also rename extremely unhelpful
variable names in SSL_get_error. i is now ret_code to match the header.

Change-Id: Ic31d6626bfe09c9e21c03691dfc716c5573833ea
Reviewed-on: https://boringssl-review.googlesource.com/3881
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:41:42 +00:00
David Benjamin 7cc29ab833 Take advantage of normalized return values.
Now that much of EVP has been normalized to 0/1, a lot of code can just use
boolean operators. (As can some code which was already using them...)

Change-Id: I6bb17edfd6f67050bf1706d59d8f37df57535faa
Reviewed-on: https://boringssl-review.googlesource.com/3875
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:40:42 +00:00
David Benjamin e0ba4dddf6 Normalize all EVP_PKEY_CTX_ctrl return values.
No code within BoringSSL or Google (grep for EVP_PKEY_CTX_(ctrl|get|set)) is
sensitive to the various failure cases. Normalize it all to 0/1 for simplicity.

This does carry a slight risk: any new ctrl hooks we import from upstream that,
like EVP_PKEY_CTX_get_rsa_oaep_md, return something other than success/failure
cannot be called directly via EVP_PKEY_CTX_ctrl. They instead need to
internally be routed through a struct like CBS and only called through the
wrappers. To that end, unexport EVP_PKEY_CTX_ctrl and require that callers use
the wrappers. No code in Google uses it directly and, if need be, switching to
the wrapper would be an incredibly upstreamable patch.

Change-Id: I3fd4e5a1a0f3d4d1c4122c52d4c74a5105b99cd5
Reviewed-on: https://boringssl-review.googlesource.com/3874
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:39:42 +00:00
David Benjamin bc5d8ee0d4 Route EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL through a CBS.
This is the only EVP_PKEY ctrl hook which returns something other than a
boolean.

Change-Id: Ic226aef168abdf72e5d30e8264a559ed5039a055
Reviewed-on: https://boringssl-review.googlesource.com/3873
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:19:59 +00:00
David Benjamin e60202797d Move EVP_R_COMMAND_NOT_SUPPORTED into individual EVP_PKEY ctrl hooks.
This removes another place where we're internally sensitive to the
success/failure conditions.

Change-Id: I18fecf6457e841ba0afb718397b9b5fd3bbdfe4c
Reviewed-on: https://boringssl-review.googlesource.com/3872
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:18:39 +00:00
David Benjamin 33c8d60a1f Remove EVP_PKEY_CTRL_DIGESTINIT -2 special-case in md_begin_digest.
All EVP_PKEY types return 1 on that. (It can go away entirely when
EVP_PKEY_HMAC is gone.) This removes a place internally where we're sensitive
to the failure code.

Change-Id: Ic6cda2da9337ba7ef1c66a18e40c5dcc44fcf840
Reviewed-on: https://boringssl-review.googlesource.com/3871
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:17:59 +00:00
David Benjamin b18f024816 Minor formatting tweaks.
Some things were misindented in the reformatting.

Change-Id: I97642000452ce4d5b4c8a39b794cec13097d8760
Reviewed-on: https://boringssl-review.googlesource.com/3870
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:17:23 +00:00
David Benjamin bcd374570c Fix some missing return value checks in ssl3_send_new_session_ticket.
See also upstream's 687eaf27a7e4bdfc58dd455e2566b915a7a25c20. I don't think any
of the *Update functions can actually fail (we should verify this and, if
accurate, document it), but HMAC_Final can. It internally copies an EVP_MD_CTX.

Change-Id: I318cb9d0771d536249a26b61d34fe0413a4d3a10
Reviewed-on: https://boringssl-review.googlesource.com/3830
Reviewed-by: Adam Langley <agl@google.com>
2015-03-13 19:17:01 +00:00
David Benjamin bf0df92964 Fix Windows build.
signed/unsigned comparison. Just add a cast for now as in s3_both.c. Later
we'll properly size_t it alongside other tightening of this interface.

Change-Id: Idc8441d65e8ca65e39ab7172a8ec87d9ad710ed6
Reviewed-on: https://boringssl-review.googlesource.com/3860
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 05:28:56 +00:00
David Benjamin 389939422a ARMv4 assembly pack: add Cortex-A15 performance data.
(Imported from upstream's e390ae50e0bc41676994c6fa23f7b65a8afc4d7f)

Change-Id: Ifee85b0936c06c42cc7c09f8327d15fec51da48a
Reviewed-on: https://boringssl-review.googlesource.com/3832
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 02:32:05 +00:00
David Benjamin 5a93342fab Fix two unchecked mallocs in crypto/asn1.
Imported from upstream's 918bb8652969fd53f0c390c1cd909265ed502c7e. (The
remainder is in code we've since deleted.)

Change-Id: Ie878272114086ba60a0fd5eae059b641b00ec0c4
Reviewed-on: https://boringssl-review.googlesource.com/3831
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 02:31:29 +00:00
Adam Langley c4482d65dc Switch an assert back to a check.
The assert was supposed to be *added* in fcf25833 but instead replaced
the check.

BUG=465557

Change-Id: I0d3db5038515021e5bdd1ccb9ff08d4f78552621
Reviewed-on: https://boringssl-review.googlesource.com/3850
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 02:15:50 +00:00
David Benjamin f298019547 Remove ssl_version hook.
It's never called or implemented.

Change-Id: Id41c2fbd23d27cc440e8a23ac1b2d590e50ff20f
Reviewed-on: https://boringssl-review.googlesource.com/3770
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:16:54 +00:00
David Benjamin 2fa83de3f2 Move handshake method hooks to SSL_PROTOCOL_METHOD.
None of these are version-specific. SSL_PROTOCOL_METHOD's interface will change
later, but this gets us closer to folding away SSL3_ENC_METHOD.

Change-Id: Ib427cdff32d0701a18fe42a52cdbf798f82ba956
Reviewed-on: https://boringssl-review.googlesource.com/3769
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:16:38 +00:00
David Benjamin 4c31123bfc Remove finish_mac_length from SSL3_ENC_METHOD.
It's unused.

Change-Id: I234c19990758ad761a72d5b0abe404a8583705a7
Reviewed-on: https://boringssl-review.googlesource.com/3768
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:16:17 +00:00
David Benjamin f7f0f3a74b Remove ccs_header_st.
It doesn't do anything.

Change-Id: I0bba4e22a0b2053aae491d0ad695c892803cafca
Reviewed-on: https://boringssl-review.googlesource.com/3767
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:13:01 +00:00
David Benjamin ee562b987e Get rid of the RSMBLY macros.
Turn them into static functions that take in an hm_fragment. It's not
immediately obvious that the frag_off/frag_len bounds checks and the msg_len
consistency check are critical to avoiding an out-of-bounds write. Better to
have dtls1_hm_fragment_mark also check internally.

Also rework the bitmask logic to be clearer and avoid a table.

Change-Id: Ica54e98f66295efb323e033cb6c67ab21e7d6cbc
Reviewed-on: https://boringssl-review.googlesource.com/3765
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:11:21 +00:00
David Benjamin 8cb7a7c0d5 Fix types of hm_header_st.
Replace unsigned long with the appropriate sized integer type.

Change-Id: I7b4641d84568f6c11efa25350a9e488a556fc92e
Reviewed-on: https://boringssl-review.googlesource.com/3766
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 01:10:09 +00:00
David Benjamin 7538122ca6 Rework DTLS handshake message reassembly logic.
Notably, drop all special cases around receiving a message in order and
receiving a full message. It makes things more complicated and was the source
of bugs (the MixCompleteMessageWithFragments tests added in this CL did not
pass before). Instead, every message goes through an hm_fragment, and
dtls1_get_message always checks buffered_messages to see if the next is
complete.

The downside is that we pay one more copy of the message data in the common
case. This is only during connection setup, so I think it's worth the
simplicity. (If we want to optimize later, we could either tighten
ssl3_get_message's interface to allow the handshake data being in the
hm_fragment's backing store rather than s->init_buf or swap out s->init_buf
with the hm_fragment's backing store when a mesasge completes.

This CL does not address ssl_read_bytes being an inappropriate API for DTLS.
Future work will revise the handshake/transport boundary to align better with
DTLS's needs. Also other problems that I've left as TODOs.

Change-Id: Ib4570d45634b5181ecf192894d735e8699b1c86b
Reviewed-on: https://boringssl-review.googlesource.com/3764
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 00:56:45 +00:00
David Benjamin d03b5eddb9 Fix some stray tabs that snuck into e_tls.c.
Change-Id: Iee44636a3f80d86f94b0c34bb708d4d723964159
Reviewed-on: https://boringssl-review.googlesource.com/3820
Reviewed-by: Adam Langley <agl@google.com>
2015-03-10 00:55:22 +00:00
Adam Langley 8a4ab4fc1d Don't include .extern and .hidden on OS X.
Change-Id: I582eaa2ff922bbf1baf298a5c6857543524a8d4e
Reviewed-on: https://boringssl-review.googlesource.com/3810
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 21:44:19 +00:00
Adam Langley d216b71f90 Include .extern and .hidden in x86-64 asm.
It's unclear why .extern was being suppressed, it's also a little
unclear how the Chromium build was working without this. None the less,
it's causing problems with Android and it's more obviously correct to
make these symbols as hidden.

Change-Id: Id13ec238b80b8bd08d8ae923ac659835450e77f8
Reviewed-on: https://boringssl-review.googlesource.com/3800
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 19:08:11 +00:00
David Benjamin d27eda00a4 Generate error data at build time.
This avoids cluttering up the diff and making merge conflicts a pain.  It does,
however, mean we need to generate err_data.c ahead of time in Chromium and
likely other downstream builds. It also adds a build dependency on Go.

Change-Id: I6e0513ed9f50cfb030f7a523ea28519590977104
Reviewed-on: https://boringssl-review.googlesource.com/3790
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 18:59:25 +00:00
David Benjamin f46cea8cd8 Fix the derivation of SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD.
It happens to give the same value anyway (64 + 16), but only on accident.

Change-Id: I1415f4015e3de472dbeb9ada0d92607c9d1bcd40
Reviewed-on: https://boringssl-review.googlesource.com/3780
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 18:56:57 +00:00
David Benjamin a4e6d48749 runner: Move Finished special-case into dtlsWriteRecord.
We actually don't really care about this special-case since we only test client
full handshakes where the runner sends the second Finished not the shim
(otherwise the overlap logic and retransmitting on every fragment would
probably break us), but it should probably live next to the fragmentation
logic.

Change-Id: I54097d84ad8294bc6c42a84d6f22f496e63eb2a8
Reviewed-on: https://boringssl-review.googlesource.com/3763
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 18:55:58 +00:00
David Benjamin 7eaab4cd57 Only retransmit on Finished if frag_off == 0.
If the peer fragments Finished into multiple pieces, there is no need to
retransmit multiple times.

Change-Id: Ibf708ad079e1633afd420ff1c9be88a80020cba9
Reviewed-on: https://boringssl-review.googlesource.com/3762
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 18:55:47 +00:00
David Benjamin 9d102ddbc0 Check public key is not NULL.
CVE-2015-0288
PR#3708

(Imported from upstream's 28a00bcd8e318da18031b2ac8778c64147cd54f9.)

Change-Id: I6d60691da4c6860f87c753c065e93e9d0704aba9
Reviewed-on: https://boringssl-review.googlesource.com/3750
Reviewed-by: Adam Langley <agl@google.com>
2015-03-06 18:55:32 +00:00
Adam Langley e023ad2d83 Fix SHA-384 and -512 in NO_ASM mode.
This transcription bug comes from the start of BoringSSL and, as you can
imagine, was a complete delight to track down.

Change-Id: I3051934195098a1d3bf893b154389ec7f14d3609
Reviewed-on: https://boringssl-review.googlesource.com/3740
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-05 22:44:00 +00:00
Adam Langley 5f5bf6f210 Don't add another error to the queue when RSA_private_transform fails.
Some code, sadly, tests the error and the extra error is breaking it.

Change-Id: I89eabadf5d2c5f7dd761030da33dd4c3f2ac8382
Reviewed-on: https://boringssl-review.googlesource.com/3720
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-03-05 22:43:43 +00:00
David Benjamin 0685b68216 Remove HelloRequest special-case in DTLS message parsing.
We don't support DTLS renego. Removing this separately from the rewrite to call
out intentionally dropping this logic.

Change-Id: Ie4428eea0d2dbbb8b4b8b6474df4821de62558cc
Reviewed-on: https://boringssl-review.googlesource.com/3761
Reviewed-by: Adam Langley <agl@google.com>
2015-03-05 21:26:55 +00:00
David Benjamin 5ca39fb50c Switch SSL_GET_MESSAGE_HASH_MESSAGE to an enum.
Matches the others.

Change-Id: If8a5164ed25f9e0bc495585bd705862a61a39fd6
Reviewed-on: https://boringssl-review.googlesource.com/3760
Reviewed-by: Adam Langley <agl@google.com>
2015-03-05 21:26:28 +00:00
David Benjamin b34f510b3b Don't delay-initialize legacy AEADs.
Instead, add a separate init_with_direction hook. Normal AEADs ignore the
direction, while legacy AEADs must be initialized with it. This avoids
maintaining extra state to support the delayed initialization.

Change-Id: I25271f0e56ee2783a2fd4d4026434154d58dc0a8
Reviewed-on: https://boringssl-review.googlesource.com/3731
Reviewed-by: Adam Langley <agl@google.com>
2015-03-05 21:25:05 +00:00
David Benjamin fb68d6c901 No-op commit to trigger a build on the bots.
The bot should be on trusty now.

Change-Id: I35776831004152ba280757b531ac24cbdec25cbf
2015-03-03 14:09:04 -08:00
David Benjamin 23721e3705 Forbid reusing HMAC key without reusing the hash function.
There's no good reason to do this, and it doesn't work; HMAC checks the length
of the key and runs it through the hash function if too long. The reuse occurs
after this check.

This allows us to shave 132 bytes off HMAC_CTX as this was the only reason it
ever stored the original key. It also slightly simplifies HMAC_Init_ex's
logic.

Change-Id: Ib56aabc3630b7178f1ee7c38ef6370c9638efbab
Reviewed-on: https://boringssl-review.googlesource.com/3733
Reviewed-by: Adam Langley <agl@google.com>
2015-03-02 23:16:12 +00:00
David Benjamin cc239d3903 Use HMAC_Init_ex, not HMAC_Init, in HMAC.
We've already initialized the context, HMAC_Init has questionable behavior
around NULL keys, and this avoids a size_t truncation.

Change-Id: Iab6bfc24fe22d46ca4c01be6129efe0630d553e6
Reviewed-on: https://boringssl-review.googlesource.com/3732
Reviewed-by: Adam Langley <agl@google.com>
2015-03-02 23:15:20 +00:00
David Benjamin 0d5e080ab9 Drop in prebuilt versions of Windows files.
These are upstream's prebuilt binaries of:
e9493171de0edd8879755aa7229a701010a19561  cmake-3.1.3-win32-x86.zip
ab6e7aee6a915c4d820b86f5227094763b649fce  strawberry-perl-5.20.2.1-32bit-portable.zip
4c4d1951181a610923523cb10d83d9ae9952fbf3  yasm-1.2.0-win32.exe

This is intentionally using yasm 1.2.0 rather than the latest 1.3.0 to match
Chromium's current bundled version. Chromium has additional patches, but they
all seem to be either in 1.2.0 or not relevant for us.

Also update extract.py a little to account for these.

BUG=430237

Change-Id: Iad6687e493900b25390d99882c7ceea62fff8b9b
Reviewed-on: https://boringssl-review.googlesource.com/3710
Reviewed-by: Adam Langley <agl@google.com>
2015-03-02 23:03:38 +00:00
David Benjamin b826c0d670 Bump the -Wshadow cutoff to 4.8 rather than 4.6.
Per https://gcc.gnu.org/gcc-4.8/changes.html, -Wshadow was made less
trigger-happy starting 4.8.

Change-Id: I023919dea3497e2dd27679a6f0c4a114c0b30337
Reviewed-on: https://boringssl-review.googlesource.com/3730
Reviewed-by: Adam Langley <agl@google.com>
2015-02-28 15:15:01 +00:00
David Benjamin b3323704bc No-op change to trigger the bot building things.
Let's see if this works.

Change-Id: I9e652baaf91c94a5f2c97b256ffb91cbd36c556e
2015-02-27 23:41:36 -05:00
Adam Langley 4e581b5378 Add support for reading PKCS#7 data from PEM files.
(There are times when I actually miss C++ templates.)

Change-Id: I3db56e4946ae4fb919105fa33e2cfce3c7542d37
Reviewed-on: https://boringssl-review.googlesource.com/3700
Reviewed-by: Adam Langley <agl@google.com>
2015-02-27 21:02:38 +00:00
Adam Langley 50073e8c5e Add functions to parse and generate PKCS#7 files with CRLs.
Change-Id: I7b6acc9004beb7b7090de1837814ccdff2e9930e
Reviewed-on: https://boringssl-review.googlesource.com/3680
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-27 19:48:19 +00:00
David Benjamin 5ae21bc02b Remove pointless free, and use preferred way of calling d2i_* functions
(Imported from upstream's 535bc8faf69dc4ff39e2ee99195b268cf99b9569)

Change-Id: Ia5abf4dce9dc8cdf5a9b77a3e360a40b5f815adf
Reviewed-on: https://boringssl-review.googlesource.com/3672
Reviewed-by: Adam Langley <agl@google.com>
2015-02-27 19:47:36 +00:00
David Benjamin 29b50eab6c Align d2i_ECPrivateKey error-handling with upstream.
Upstream decided to make the caller free the scratch space rather than the
callee. May as well match. (Existing code is pretty inconsistent. This API
pattern needs to go.)

See upstream's 9e442d485008046933cdc7da65080f436a4af089.

Change-Id: I7c9fcae5778a74d6ae8e9f546e03fb2cf6e48426
Reviewed-on: https://boringssl-review.googlesource.com/3671
Reviewed-by: Adam Langley <agl@google.com>
2015-02-27 19:45:42 +00:00
David Benjamin 114ddebbf6 Unexport EC_GROUP_copy.
EC_GROUP_copy is an rather unfriendly function; it doesn't work if the groups
have different[*] underlying EC_METHODs, but this notion is not exposed through
the API. I found no callers of EC_GROUP_copy in external code.

This leaves the precompute_mult functions as the remaining mutable API exposed
through EC_GROUP.

[*] Though, of the two EC_METHODs right now, simple.c is entirely unused.

Change-Id: Iabb52518005250fb970e12b3b0ea78b4f6eff4a0
Reviewed-on: https://boringssl-review.googlesource.com/3631
Reviewed-by: Adam Langley <agl@google.com>
2015-02-27 19:43:02 +00:00
David Benjamin 9a7233cda8 Add a prebuilt CMake for OS X for the bots.
Built from:
45f4d3fa8a2f61cc092ae461aac4cac1bab4ac6706f98274ea7f314dd315c6d0  cmake-3.1.3.tar.gz

We're still waiting on infra before the buildbot master is up, but let's get
this ready for when we do; it should be fairly easy.

BUG=430237

Change-Id: I3a414743d44052e1aa48759fa5f125db4d4913b5
Reviewed-on: https://boringssl-review.googlesource.com/3670
Reviewed-by: Adam Langley <agl@google.com>
2015-02-26 23:49:03 +00:00
David Benjamin a3e894921e Test that we reject RSA ServerKeyExchange more thoroughly.
The old test just sent an empty ServerKeyExchange which is sufficient as we
reject the message early. But be more thorough and implement the actual
ephemeral key logic in the test server.

Change-Id: I016658762e4502c928c051e14d69eea67b5a495f
Reviewed-on: https://boringssl-review.googlesource.com/3650
Reviewed-by: Adam Langley <agl@google.com>
2015-02-26 21:26:37 +00:00
David Benjamin 03741f61d9 Use EC_GROUP_dup and EC_POINT_dup in EC_KEY_copy.
They do the same thing. This removes all callers of EC_GROUP_copy outside
EC_GROUP_dup.

Change-Id: I65433ee36040de79e56483dfece774e01e2e2743
Reviewed-on: https://boringssl-review.googlesource.com/3630
Reviewed-by: Adam Langley <agl@google.com>
2015-02-25 21:44:24 +00:00
David Benjamin 09bdb2a2c3 Remove explicit .hiddens from x86_64 perlasm files.
This reverts the non-ARM portions of 97999919bb.
x86_64 perlasm already makes .globl imply .hidden. (Confusingly, ARM does not.)
Since we don't need it, revert those to minimize divergence with upstream.

Change-Id: I2d205cfb1183e65d4f18a62bde187d206b1a96de
Reviewed-on: https://boringssl-review.googlesource.com/3610
Reviewed-by: Adam Langley <agl@google.com>
2015-02-25 21:26:16 +00:00
David Benjamin bcb2d91e10 Actually check that the message has the expected type in DTLS.
That might be a reasonable check to make, maybe.

DTLS handshake message reading has a ton of other bugs and needs a complete
rewrite. But let's fix this and get a test in now.

Change-Id: I4981fc302feb9125908bb6161ed1a18288c39e2b
Reviewed-on: https://boringssl-review.googlesource.com/3600
Reviewed-by: Adam Langley <agl@google.com>
2015-02-25 21:23:48 +00:00
David Benjamin 6f5c0f4471 Add tests for installing the certificate on the early callback.
Test both asynchronous and synchronous versions. This callback is somewhat
different from others. It's NOT called a second time when the handshake is
resumed. This appears to be intentional and not a mismerge from the internal
patch. The caller is expected to set up any state before resuming the handshake
state machine.

Also test the early callback returning an error.

Change-Id: If5e6eddd7007ea5cdd7533b4238e456106b95cbd
Reviewed-on: https://boringssl-review.googlesource.com/3590
Reviewed-by: Adam Langley <agl@google.com>
2015-02-25 21:22:35 +00:00
Adam Langley 7c21925a10 EC_GROUP_cmp should return zero if the groups match.
(I got this wrong when reading the OpenSSL code.)

Change-Id: Ib289ef41d0ab5a3157ad8b9454d2de96d1f86c22
Reviewed-on: https://boringssl-review.googlesource.com/3620
Reviewed-by: Adam Langley <agl@google.com>
2015-02-25 21:13:02 +00:00
David Benjamin 3ce3c369cb Find perl using the CMake's standard FindPerl module.
This gives a standard PERL_EXECUTABLE configuration knob which is useful for
specifying a perl to use without having it in PATH.

Change-Id: I4b196b77e0b4666081a3f291fee3654c47925844
Reviewed-on: https://boringssl-review.googlesource.com/3570
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:59:48 +00:00
David Benjamin 87c8a643e1 Use TCP sockets rather than socketpairs in the SSL tests.
This involves more synchronization with child exits as the kernel no longer
closes the pre-created pipes for free, but it works on Windows. As long as
TCP_NODELAY is set, the performance seems comparable. Though it does involve
dealing with graceful socket shutdown. I couldn't get that to work on Windows
without draining the socket; not even SO_LINGER worked. Current (untested)
theory is that Windows refuses to gracefully shutdown a socket if the peer
sends data after we've stopped reading.

cmd.ExtraFiles doesn't work on Windows; it doesn't use fds natively, so you
can't pass fds 4 and 5. (stdin/stdout/stderr are special slots in
CreateProcess.) We can instead use the syscall module directly and mark handles
as inheritable (and then pass the numerical values out-of-band), but that
requires synchronizing all of our shim.Start() calls and assuming no other
thread is spawning a process.

PROC_THREAD_ATTRIBUTE_HANDLE_LIST fixes threading problems, but requires
wrapping more syscalls.  exec.Cmd also doesn't let us launch the process
ourselves. Plus it still requires every handle in the list be marked
inheritable, so it doesn't help if some other thread is launching a process
with bInheritHandles TRUE but NOT using PROC_THREAD_ATTRIBUTE_HANDLE_LIST.
(Like Go, though we can take syscall.ForkLock there.)

http://blogs.msdn.com/b/oldnewthing/archive/2011/12/16/10248328.aspx

The more natively Windows option seems to be named pipes, but that too requires
wrapping more system calls. (To be fair, that isn't too painful.) They also
involve a listening server, so we'd still have to synchronize with shim.Wait()
a la net.TCPListener.

Then there's DuplicateHandle, but then we need an out-of-band signal.

All in all, one cross-platform implementation with a TCP sockets seems
simplest.

Change-Id: I38233e309a0fa6814baf61e806732138902347c0
Reviewed-on: https://boringssl-review.googlesource.com/3563
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:59:06 +00:00
David Benjamin 6204eba91e perlasm/x86masm.pl: make it work.
Though this doesn't mean that masm becomes supported, the script is
still provided on don't-ask-in-case-of-doubt-use-nasm basis.
See RT#3650 for background.

(Imported from upstream's 2f8d82d6418c4de8330e2870c1ca6386dc9e1b34)

The data_word changes were already fixed with our
3e700bb3e8, but best to avoid diverging there.

Change-Id: Iab5455534e8bd632fb2b247ff792d411b105f17a
Reviewed-on: https://boringssl-review.googlesource.com/3581
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:45:30 +00:00
David Benjamin 2b48d6b7dd sha/asm/sha1-586.pl: fix typo.
The typo doesn't affect supported configuration, only unsupported masm.

(Imported from upstream's 3372c4fffa0556a688f8f1f550b095051398f596)

Change-Id: Ib6a2f1d9f6fc244a33da1e079188acdf69d5e2f3
Reviewed-on: https://boringssl-review.googlesource.com/3580
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:44:50 +00:00
David Benjamin 3f5917f320 EVP_CIPHER_CTX_cleanup cannot fail.
There is exactly one implementation and it doesn't fail. Plus a cleanup
function that can fail is very bad manners; the caller has no choice but to
leak at that point.

Change-Id: I5b524617ef37bc7d92273472fa742416ea7dfd43
Reviewed-on: https://boringssl-review.googlesource.com/3564
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:44:02 +00:00
David Benjamin 86058a256b Tidy up the alert-parsing code.
Align the DTLS and TLS implementations more. s3_pkt.c's version still has
remnants of fragmentable alerts and only one side marks some variables as
const. Also use warning/fatal constants rather than the numbers with comments.

Change-Id: Ie62d3af1747b6fe4336496c047dfccc9d71fde3f
Reviewed-on: https://boringssl-review.googlesource.com/3562
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:34:52 +00:00
David Benjamin 2bdb35ccbb Use SSL_get_cipher_by_value in cipher_get_rfc_name tests.
Saves making a temporary SSL_CTX and looking at its insides.

Change-Id: Ia351b9b91aec8b813ad7b6e373773396f0975f9a
Reviewed-on: https://boringssl-review.googlesource.com/3561
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:33:02 +00:00
David Benjamin ce9f0177f8 Remove BIO_should_retry checks in DTLS state machines.
These were added in upstream's 7e159e0133d28bec9148446e8f4dd86c0216d819 for
SCTP. As far as I can tell, they were a no-op there too. The corresponding RT
ticket makes no mention of them.

SSL_get_error checks the retry flags of the BIO already. Specifically it checks
BIO_should_read and BIO_should_write, but those two automatically set
BIO_should_retry.

(Minor, but I noticed them idly. One less thing to think about when the state
machines finally unify.)

Change-Id: I17a956a51895fba383063dee574e0fbe3209f9b0
Reviewed-on: https://boringssl-review.googlesource.com/3560
Reviewed-by: Adam Langley <agl@google.com>
2015-02-23 19:32:27 +00:00
Adam Langley 04c36b5062 Never set RC4_CHAR.
RC4_CHAR is a bit in the x86(-64) CPUID information that switches the
RC4 asm code from using an array of 256 uint32_t's to 256 uint8_t's. It
was originally written for the P4, where the uint8_t style was faster.

(On modern chips, setting RC4_CHAR took RC4-MD5 from 458 to 304 MB/s.
Although I wonder whether, on a server with many connections, using less
cache wouldn't be better.)

However, I'm not too worried about a slowdown of RC4 on P4 systems these
days (the last new P4 chip was released nine years ago) and I want the
code to be simplier.

Also, RC4_CHAR was set when the CPUID family was 15, but Intel actually
lists 15 as a special code meaning "also check the extended family
bits", which the asm didn't do.

The RC4_CHAR support remains in the RC4 asm code to avoid drift with
upstream.

Change-Id: If3febc925a83a76f453b9e9f8de5ee43759927c6
Reviewed-on: https://boringssl-review.googlesource.com/3550
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:59:59 +00:00
Adam Langley 3f309aef45 Tidy up RC4 a little.
RC4_CHUNK is always defined, RC4_INT is always uint32_t and the
"register" keyword is an anachronism.

Change-Id: Ia752af30ba6bac0ee6216ce189fcf3888de73c6e
Reviewed-on: https://boringssl-review.googlesource.com/3544
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:44:33 +00:00
Adam Langley 44972944fd Add SSL_get_cipher_by_value.
(Which is just an exported wrapper around ssl3_get_cipher_by_value.)

Change-Id: Ibba166015ce59e337ff50963ba20237ac4949aaf
Reviewed-on: https://boringssl-review.googlesource.com/3543
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:44:17 +00:00
Adam Langley 5f0efe06e1 Use SSL_MODE_SEND_FALLBACK_SCSV.
Upstream settled in this API, and it's also the one that we expect
internally and that third_party code will expect.

Change-Id: Id7af68cf0af1f2e4d9defd37bda2218d70e2aa7b
Reviewed-on: https://boringssl-review.googlesource.com/3542
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:44:09 +00:00
Adam Langley 93531bd70f Add the CTX parameter back to EC_GROUP_cmp.
It was a mistake to remove this in the first place.

Change-Id: Icd97b4db01e49151daa41dd892f9da573ddc2842
Reviewed-on: https://boringssl-review.googlesource.com/3541
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:33:55 +00:00
Adam Langley d3a73360fa Rename safe_stack.h to safestack.h.
This empty header file exists only to make older code compile. But I
named it incorrectly! Upstream doesn't have the underscore in the name.

Change-Id: I96654b7e17d84a5f2810e6eb20fe7bfb22f855fd
Reviewed-on: https://boringssl-review.googlesource.com/3540
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 23:33:48 +00:00
Adam Langley 97999919bb Hide all asm symbols.
We are leaking asm symbols in Android builds because the asm code isn't
affected by -fvisibility=hidden. This change hides all asm symbols.

This assumes that no asm symbols are public API and that should be true.
Some points to note:

In crypto/rc4/asm/rc4-md5-x86_64.pl there are |RC4_set_key| and
|RC4_options| functions which aren't getting marked as hidden. That's
because those functions aren't actually ever generated. (I'm just trying
to minimise drift with upstream here.)

In crypto/rc4/asm/rc4-x86_64.pl there's |RC4_options| which is "public"
API, except that we've never had it in the header files. So I've just
deleted it. Since we have an internal caller, we'll probably have to put
it back in the future, but it can just be done in rc4.c to save
problems.

BUG=448386

Change-Id: I3846617a0e3d73ec9e5ec3638a53364adbbc6260
Reviewed-on: https://boringssl-review.googlesource.com/3520
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 21:24:01 +00:00
Adam Langley bcc4e23041 Pass fragment to dtls1_retransmit_message.
We can pass the fragment pointer to dtls1_retransmit_message rather than
having it look it up again.

Change-Id: If6957428418a44e7ceac91a93f7c6032d331d9d8
Reviewed-on: https://boringssl-review.googlesource.com/3510
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 19:58:14 +00:00
David Benjamin 40f101b78b Return bool from C++ functions in bssl_shim.
Also move BIO_print_errors_fp up a level so it's less repetitive. There's
enough exit points now that it doesn't seem like adding a separate return exit
code for each has held up. (Maybe there should be a macro that samples
__LINE__...)

Change-Id: I120e59caaa96185e80cf51ea801a5e1f149b1b39
Reviewed-on: https://boringssl-review.googlesource.com/3530
Reviewed-by: Adam Langley <agl@google.com>
2015-02-20 19:29:43 +00:00
Adam Langley 16e38b2b8f Mark OPENSSL_armcap_P as hidden in ARM asm.
This is an import from ARM. Without this, one of the Android builds of
BoringSSL was failing with:
  (sha512-armv4.o): requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC

This is (I believe) a very misleading error message. The R_ARM_REL32
relocation type is the correct type for position independent code. But
unless the target symbol is hidden then the linker doesn't know that
it's not going to be overridden by a different ELF module.

Chromium probably gets away with this because of different default
compiler flags than Android.

Change-Id: I967eabc4d6b33d1e6635caaf6e7a306e4e77c101
Reviewed-on: https://boringssl-review.googlesource.com/3471
Reviewed-by: Adam Langley <agl@google.com>
2015-02-19 19:58:17 +00:00
Adam Langley d3459fb2f9 Don't randomly print stuff to stderr.
Change-Id: I821c546612bdd7fca2c3d6a043a4f888f928ee61
Reviewed-on: https://boringssl-review.googlesource.com/3470
Reviewed-by: Adam Langley <agl@google.com>
2015-02-19 19:58:10 +00:00
198 changed files with 8080 additions and 9678 deletions
+6 -9
View File
@@ -3,7 +3,8 @@ Build Prerequisites:
* CMake[1] 2.8.8 or later is required.
* Perl 5.6.1 or later is required. On Windows, Strawberry Perl and MSYS Perl
have both been reported to work.
have both been reported to work. If not found by CMake, it may be configured
explicitly by setting PERL_EXECUTABLE.
* On Windows you currently must use Ninja[2] to build; on other platforms,
it is not required, but recommended, because it makes builds faster.
@@ -11,14 +12,15 @@ Build Prerequisites:
* If you need to build Ninja from source, then a recent version of
Python[3] is required (Python 2.7.5 works).
* On Windows only, Yasm[4] is required.
* On Windows only, Yasm[4] is required. If not found by CMake, it may be
configured explicitly by setting CMAKE_ASM_NASM_COMPILER.
* A C compiler is required. On Windows, MSVC 12 (Visual Studio 2013) or later
with Platform SDK 8.1 or later are supported. Recent versions of GCC and
Clang should work on non-Windows platforms, and maybe on Windows too.
* Go[5] is required for running tests, but not for building. Note that the
runner.go tests do not work on Windows.
* Go[5] is required. If not found by CMake, the go executable may be
configured explicitly by setting GO_EXECUTABLE.
Using Ninja (note the 'N' is capitalized in the cmake invocation):
@@ -63,8 +65,6 @@ Known Limitations on Windows:
don't have steps for assembling the assembly language source files, so they
currently cannot be used to build BoringSSL.
* The tests written in Go do not work.
[1] http://www.cmake.org/download/
[2] https://martine.github.io/ninja/
@@ -73,7 +73,4 @@ Known Limitations on Windows:
[4] http://yasm.tortall.net/
Either ensure yasm.exe is in %PATH% or configure CMAKE_ASM_NASM_COMPILER
appropriately.
[5] https://golang.org/dl/
+9 -1
View File
@@ -2,6 +2,13 @@ cmake_minimum_required (VERSION 2.8.10)
project (BoringSSL)
find_package(Perl REQUIRED)
find_program(GO_EXECUTABLE go)
if (NOT GO_EXECUTABLE)
message(FATAL_ERROR "Could not find Go")
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")
@@ -56,9 +63,10 @@ elseif(MSVC)
set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
add_definitions(-D_HAS_EXCEPTIONS=0)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)
endif()
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.5.99") OR
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
+18 -3
View File
@@ -2,7 +2,7 @@ include_directories(. ../include)
if(APPLE)
if (${ARCH} STREQUAL "x86")
set(PERLASM_FLAGS "-fPIC")
set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
endif()
set(PERLASM_STYLE macosx)
set(ASM_EXT S)
@@ -13,7 +13,7 @@ elseif(UNIX)
# in order to decide whether to generate 32- or 64-bit asm.
set(PERLASM_STYLE linux64)
elseif (${ARCH} STREQUAL "x86")
set(PERLASM_FLAGS "-fPIC")
set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
set(PERLASM_STYLE elf)
else()
set(PERLASM_STYLE elf)
@@ -27,6 +27,7 @@ else()
else()
message("Using win32n")
set(PERLASM_STYLE win32n)
set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
endif()
# On Windows, we use the NASM output, specifically built with Yasm.
@@ -37,7 +38,7 @@ endif()
function(perlasm dest src)
add_custom_command(
OUTPUT ${dest}
COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} > ${dest}
DEPENDS
${src}
${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
@@ -139,6 +140,8 @@ add_library(
crypto.c
mem.c
thread.c
thread_pthread.c
thread_win.c
ex_data.c
ex_data_impl.c
time_support.c
@@ -186,6 +189,10 @@ add_library(
$<TARGET_OBJECTS:pkcs8>
)
if(NOT MSVC)
target_link_libraries(crypto pthread)
endif()
add_executable(
constant_time_test
@@ -194,5 +201,13 @@ add_executable(
target_link_libraries(constant_time_test crypto)
add_executable(
thread_test
thread_test.c
)
target_link_libraries(thread_test crypto)
perlasm(cpu-x86_64-asm.${ASM_EXT} cpu-x86_64-asm.pl)
perlasm(cpu-x86-asm.${ASM_EXT} cpu-x86-asm.pl)
+16 -8
View File
@@ -1033,17 +1033,25 @@ void AES_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key) {
#endif /* ?FULL_UNROLL */
/* apply last round and
* map cipher state to byte array block: */
s0 = (Td4[(t0 >> 24)] << 24) ^ (Td4[(t3 >> 16) & 0xff] << 16) ^
(Td4[(t2 >> 8) & 0xff] << 8) ^ (Td4[(t1) & 0xff]) ^ rk[0];
s0 = ((uint32_t)Td4[(t0 >> 24)] << 24) ^
((uint32_t)Td4[(t3 >> 16) & 0xff] << 16) ^
((uint32_t)Td4[(t2 >> 8) & 0xff] << 8) ^
((uint32_t)Td4[(t1) & 0xff]) ^ rk[0];
PUTU32(out, s0);
s1 = (Td4[(t1 >> 24)] << 24) ^ (Td4[(t0 >> 16) & 0xff] << 16) ^
(Td4[(t3 >> 8) & 0xff] << 8) ^ (Td4[(t2) & 0xff]) ^ rk[1];
s1 = ((uint32_t)Td4[(t1 >> 24)] << 24) ^
((uint32_t)Td4[(t0 >> 16) & 0xff] << 16) ^
((uint32_t)Td4[(t3 >> 8) & 0xff] << 8) ^
((uint32_t)Td4[(t2) & 0xff]) ^ rk[1];
PUTU32(out + 4, s1);
s2 = (Td4[(t2 >> 24)] << 24) ^ (Td4[(t1 >> 16) & 0xff] << 16) ^
(Td4[(t0 >> 8) & 0xff] << 8) ^ (Td4[(t3) & 0xff]) ^ rk[2];
s2 = ((uint32_t)Td4[(t2 >> 24)] << 24) ^
((uint32_t)Td4[(t1 >> 16) & 0xff] << 16) ^
((uint32_t)Td4[(t0 >> 8) & 0xff] << 8) ^
((uint32_t)Td4[(t3) & 0xff]) ^ rk[2];
PUTU32(out + 8, s2);
s3 = (Td4[(t3 >> 24)] << 24) ^ (Td4[(t2 >> 16) & 0xff] << 16) ^
(Td4[(t1 >> 8) & 0xff] << 8) ^ (Td4[(t0) & 0xff]) ^ rk[3];
s3 = ((uint32_t)Td4[(t3 >> 24)] << 24) ^
((uint32_t)Td4[(t2 >> 16) & 0xff] << 16) ^
((uint32_t)Td4[(t1 >> 8) & 0xff] << 8) ^
((uint32_t)Td4[(t0) & 0xff]) ^ rk[3];
PUTU32(out + 12, s3);
}
+1 -1
View File
@@ -194,7 +194,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
len-off);
if (c.inf & 0x80)
{
unsigned long e;
uint32_t e;
e=ERR_GET_REASON(ERR_peek_error());
if (e != ASN1_R_TOO_LONG)
+3
View File
@@ -125,6 +125,9 @@ int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b)
case V_ASN1_NULL:
result = 0; /* They do not have content. */
break;
case V_ASN1_BOOLEAN:
result = a->value.boolean - b->value.boolean;
break;
case V_ASN1_INTEGER:
case V_ASN1_NEG_INTEGER:
case V_ASN1_ENUMERATED:
+1 -1
View File
@@ -287,7 +287,7 @@ int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
if (!OPENSSL_gmtime(&t, &ttm))
return -2;
if (!OPENSSL_gmtime_diff(&day, &sec, &stm, &ttm))
if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
return -2;
if (day > 0)
+20 -20
View File
@@ -137,7 +137,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
#endif
if (j & 0x80)
{
if (BIO_write(bp,"Error in encoding\n",18) <= 0)
if (BIO_puts(bp, "Error in encoding\n") <= 0)
goto end;
ret=0;
goto end;
@@ -165,7 +165,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
if (j & V_ASN1_CONSTRUCTED)
{
ep=p+len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
if (BIO_puts(bp, "\n") <= 0) goto end;
if (len > length)
{
BIO_printf(bp,
@@ -196,7 +196,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
else if (xclass != 0)
{
p+=len;
if (BIO_write(bp,"\n",1) <= 0) goto end;
if (BIO_puts(bp, "\n") <= 0) goto end;
}
else
{
@@ -210,7 +210,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
(tag == V_ASN1_UTCTIME) ||
(tag == V_ASN1_GENERALIZEDTIME))
{
if (BIO_write(bp,":",1) <= 0) goto end;
if (BIO_puts(bp, ":") <= 0) goto end;
if ((len > 0) &&
BIO_write(bp,(const char *)p,(int)len)
!= (int)len)
@@ -221,12 +221,12 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
opp=op;
if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL)
{
if (BIO_write(bp,":",1) <= 0) goto end;
if (BIO_puts(bp, ":") <= 0) goto end;
i2a_ASN1_OBJECT(bp,o);
}
else
{
if (BIO_write(bp,":BAD OBJECT",11) <= 0)
if (BIO_puts(bp, ":BAD OBJECT") <= 0)
goto end;
}
}
@@ -238,7 +238,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl);
if (ii < 0)
{
if (BIO_write(bp,"Bad boolean\n",12) <= 0)
if (BIO_puts(bp, "Bad boolean\n") <= 0)
goto end;
}
BIO_printf(bp,":%d",ii);
@@ -273,7 +273,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
if (printable)
/* printable string */
{
if (BIO_write(bp,":",1) <= 0)
if (BIO_puts(bp, ":") <= 0)
goto end;
if (BIO_write(bp,(const char *)opp,
os->length) <= 0)
@@ -283,7 +283,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
/* not printable => print octet string
* as hex dump */
{
if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
if (BIO_puts(bp, "[HEX DUMP]:") <= 0)
goto end;
for (i=0; i<os->length; i++)
{
@@ -297,7 +297,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
{
if (!nl)
{
if (BIO_write(bp,"\n",1) <= 0)
if (BIO_puts(bp, "\n") <= 0)
goto end;
}
if (!BIO_hexdump(bp, opp,
@@ -323,9 +323,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl);
if (bs != NULL)
{
if (BIO_write(bp,":",1) <= 0) goto end;
if (BIO_puts(bp, ":") <= 0) goto end;
if (bs->type == V_ASN1_NEG_INTEGER)
if (BIO_write(bp,"-",1) <= 0)
if (BIO_puts(bp, "-") <= 0)
goto end;
for (i=0; i<bs->length; i++)
{
@@ -335,13 +335,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
}
if (bs->length == 0)
{
if (BIO_write(bp,"00",2) <= 0)
if (BIO_puts(bp, "00") <= 0)
goto end;
}
}
else
{
if (BIO_write(bp,"BAD INTEGER",11) <= 0)
if (BIO_puts(bp, "BAD INTEGER") <= 0)
goto end;
}
M_ASN1_INTEGER_free(bs);
@@ -355,9 +355,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
if (bs != NULL)
{
if (BIO_write(bp,":",1) <= 0) goto end;
if (BIO_puts(bp, ":") <= 0) goto end;
if (bs->type == V_ASN1_NEG_ENUMERATED)
if (BIO_write(bp,"-",1) <= 0)
if (BIO_puts(bp, "-") <= 0)
goto end;
for (i=0; i<bs->length; i++)
{
@@ -367,13 +367,13 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
}
if (bs->length == 0)
{
if (BIO_write(bp,"00",2) <= 0)
if (BIO_puts(bp, "00") <= 0)
goto end;
}
}
else
{
if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
if (BIO_puts(bp, "BAD ENUMERATED") <= 0)
goto end;
}
M_ASN1_ENUMERATED_free(bs);
@@ -382,7 +382,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
{
if (!nl)
{
if (BIO_write(bp,"\n",1) <= 0)
if (BIO_puts(bp, "\n") <= 0)
goto end;
}
if (!BIO_hexdump(bp,p,
@@ -394,7 +394,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
if (!nl)
{
if (BIO_write(bp,"\n",1) <= 0) goto end;
if (BIO_puts(bp, "\n") <= 0) goto end;
}
p+=len;
if ((tag == V_ASN1_EOC) && (xclass == 0))
+6
View File
@@ -170,6 +170,9 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
p = OPENSSL_malloc(derlen);
if (p == NULL)
return 0;
ndef_aux->derbuf = p;
*pbuf = p;
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
@@ -235,6 +238,9 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
p = OPENSSL_malloc(derlen);
if (p == NULL)
return 0;
ndef_aux->derbuf = p;
*pbuf = p;
derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
+27 -3
View File
@@ -304,8 +304,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
goto auxerr;
/* Allocate structure */
if (!*pval && !ASN1_item_ex_new(pval, it))
if (*pval)
{
/* Free up and zero CHOICE value if initialised */
i = asn1_get_choice_selector(pval, it);
if ((i >= 0) && (i < it->tcount))
{
tt = it->templates + i;
pchptr = asn1_get_field_ptr(pval, tt);
ASN1_template_free(pchptr, tt);
asn1_set_choice_selector(pval, -1, it);
}
}
else if (!ASN1_item_ex_new(pval, it))
{
OPENSSL_PUT_ERROR(ASN1, ASN1_item_ex_d2i, ASN1_R_NESTED_ASN1_ERROR);
goto err;
@@ -394,6 +405,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
goto auxerr;
/* Free up and zero any ADB found */
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
{
if (tt->flags & ASN1_TFLG_ADB_MASK)
{
const ASN1_TEMPLATE *seqtt;
ASN1_VALUE **pseqval;
seqtt = asn1_do_adb(pval, tt, 1);
pseqval = asn1_get_field_ptr(pval, seqtt);
ASN1_template_free(pseqval, seqtt);
}
}
/* Get each field entry */
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
{
@@ -1193,7 +1217,7 @@ static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
len = buf->length;
if (!BUF_MEM_grow_clean(buf, len + plen))
{
OPENSSL_PUT_ERROR(ASN1, asn1_collect, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(ASN1, collect_data, ERR_R_MALLOC_FAILURE);
return 0;
}
memcpy(buf->data + len, *p, plen);
+5 -2
View File
@@ -329,14 +329,17 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
ASN1_STRING *str;
int utype;
if (it && it->funcs)
if (!it)
return 0;
if (it->funcs)
{
const ASN1_PRIMITIVE_FUNCS *pf = it->funcs;
if (pf->prim_new)
return pf->prim_new(pval, it);
}
if (!it || (it->itype == ASN1_ITYPE_MSTRING))
if (it->itype == ASN1_ITYPE_MSTRING)
utype = -1;
else
utype = it->utype;
+3
View File
@@ -229,6 +229,7 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
if (!asn1_template_print_ctx(out, fld, indent,
it->templates, pctx))
return 0;
break;
}
/* fall thru */
case ASN1_ITYPE_MSTRING:
@@ -309,6 +310,8 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
{
const ASN1_TEMPLATE *seqtt;
seqtt = asn1_do_adb(fld, tt, 1);
if (!seqtt)
return 0;
tmpfld = asn1_get_field_ptr(fld, seqtt);
if (!asn1_template_print_ctx(out, tmpfld,
indent + 2, seqtt, pctx))
+25 -40
View File
@@ -61,53 +61,38 @@
/* Declarations for string types */
IMPLEMENT_ASN1_TYPE(ASN1_INTEGER);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER);
#define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
IMPLEMENT_ASN1_TYPE(sname) \
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
sname *sname##_new(void) \
{ \
return ASN1_STRING_type_new(V_##sname); \
} \
void sname##_free(sname *x) \
{ \
ASN1_STRING_free(x); \
}
IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED);
IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING);
IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING);
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
IMPLEMENT_ASN1_TYPE(ASN1_NULL);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL);
IMPLEMENT_ASN1_TYPE(ASN1_OBJECT);
IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING);
IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING);
IMPLEMENT_ASN1_TYPE(ASN1_T61STRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING);
IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING);
IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING);
IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME);
IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME);
IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING);
IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING);
IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING);
IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING);
IMPLEMENT_ASN1_TYPE(ASN1_ANY);
/* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */;
+1 -1
View File
@@ -11,7 +11,7 @@ add_library(
add_executable(
base64_test
base64_test.c
base64_test.cc
)
target_link_libraries(base64_test crypto)
+4
View File
@@ -373,6 +373,10 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
rv = 0;
goto end;
}
if (eof > v) {
rv = -1;
goto end;
}
ret += (v - eof);
} else {
eof = 1;
@@ -20,13 +20,13 @@
#include <openssl/err.h>
typedef struct {
struct TestVector {
const char *decoded;
const char *encoded;
} TEST_VECTOR;
};
/* Test vectors from RFC 4648. */
static const TEST_VECTOR test_vectors[] = {
// Test vectors from RFC 4648.
static const TestVector kTestVectors[] = {
{ "", "" },
{ "f" , "Zg==" },
{ "fo", "Zm8=" },
@@ -36,95 +36,90 @@ static const TEST_VECTOR test_vectors[] = {
{ "foobar", "Zm9vYmFy" },
};
static const size_t kNumTests = sizeof(test_vectors) / sizeof(test_vectors[0]);
static const size_t kNumTests = sizeof(kTestVectors) / sizeof(kTestVectors[0]);
static int test_encode(void) {
uint8_t out[9];
size_t i, len;
for (i = 0; i < kNumTests; i++) {
const TEST_VECTOR *t = &test_vectors[i];
len = EVP_EncodeBlock(out, (const uint8_t*)t->decoded, strlen(t->decoded));
static bool TestEncode() {
for (size_t i = 0; i < kNumTests; i++) {
const TestVector *t = &kTestVectors[i];
uint8_t out[9];
size_t len = EVP_EncodeBlock(out, (const uint8_t*)t->decoded,
strlen(t->decoded));
if (len != strlen(t->encoded) ||
memcmp(out, t->encoded, len) != 0) {
fprintf(stderr, "encode(\"%s\") = \"%.*s\", want \"%s\"\n",
t->decoded, (int)len, (const char*)out, t->encoded);
return 0;
return false;
}
}
return 1;
return true;
}
static int test_decode(void) {
static bool TestDecode() {
uint8_t out[6];
size_t i, len;
int ret;
size_t len;
for (i = 0; i < kNumTests; i++) {
/* Test the normal API. */
const TEST_VECTOR *t = &test_vectors[i];
for (size_t i = 0; i < kNumTests; i++) {
// Test the normal API.
const TestVector *t = &kTestVectors[i];
size_t expected_len = strlen(t->decoded);
if (!EVP_DecodeBase64(out, &len, sizeof(out),
(const uint8_t*)t->encoded, strlen(t->encoded))) {
fprintf(stderr, "decode(\"%s\") failed\n", t->encoded);
return 0;
return false;
}
if (len != strlen(t->decoded) ||
memcmp(out, t->decoded, len) != 0) {
fprintf(stderr, "decode(\"%s\") = \"%.*s\", want \"%s\"\n",
t->encoded, (int)len, (const char*)out, t->decoded);
return 0;
return false;
}
/* Test that the padding behavior of the deprecated API is
* preserved. */
ret = EVP_DecodeBlock(out, (const uint8_t*)t->encoded, strlen(t->encoded));
// Test that the padding behavior of the deprecated API is preserved.
int ret = EVP_DecodeBlock(out, (const uint8_t*)t->encoded,
strlen(t->encoded));
if (ret < 0) {
fprintf(stderr, "decode(\"%s\") failed\n", t->encoded);
return 0;
return false;
}
if (ret % 3 != 0) {
fprintf(stderr, "EVP_DecodeBlock did not ignore padding\n");
return 0;
return false;
}
if (expected_len % 3 != 0) {
ret -= 3 - (expected_len % 3);
}
if (ret != strlen(t->decoded) ||
if (static_cast<size_t>(ret) != strlen(t->decoded) ||
memcmp(out, t->decoded, ret) != 0) {
fprintf(stderr, "decode(\"%s\") = \"%.*s\", want \"%s\"\n",
t->encoded, ret, (const char*)out, t->decoded);
return 0;
return false;
}
}
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"a!bc", 4)) {
fprintf(stderr, "Failed to reject invalid characters in the middle.\n");
return 0;
return false;
}
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"a=bc", 4)) {
fprintf(stderr, "Failed to reject invalid characters in the middle.\n");
return 0;
return false;
}
if (EVP_DecodeBase64(out, &len, sizeof(out), (const uint8_t*)"abc", 4)) {
fprintf(stderr, "Failed to reject invalid input length.\n");
return 0;
return false;
}
return 1;
return true;
}
int main(void) {
CRYPTO_library_init();
ERR_load_crypto_strings();
if (!test_encode()) {
return 1;
}
if (!test_decode()) {
if (!TestEncode() ||
!TestDecode()) {
return 1;
}
+1 -1
View File
@@ -21,7 +21,7 @@ add_library(
add_executable(
bio_test
bio_test.c
bio_test.cc
)
target_link_libraries(bio_test crypto)
+129 -133
View File
@@ -28,8 +28,8 @@
#else
#include <io.h>
#pragma warning(push, 3)
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma warning(pop)
#endif
@@ -37,95 +37,107 @@
#include <openssl/crypto.h>
#include <openssl/err.h>
#define MIN(a, b) ((a < b) ? a : b)
#include <algorithm>
#include "../test/scoped_types.h"
#if !defined(OPENSSL_WINDOWS)
static int closesocket(int sock) {
return close(sock);
}
static void print_socket_error(const char *func) {
static void PrintSocketError(const char *func) {
perror(func);
}
#else
static void print_socket_error(const char *func) {
static void PrintSocketError(const char *func) {
fprintf(stderr, "%s: %d\n", func, WSAGetLastError());
}
#endif
static int test_socket_connect(void) {
int listening_sock = socket(AF_INET, SOCK_STREAM, 0);
int sock;
struct sockaddr_in sin;
socklen_t sockaddr_len = sizeof(sin);
static const char kTestMessage[] = "test";
char hostname[80], buf[5];
BIO *bio;
class ScopedSocket {
public:
ScopedSocket(int sock) : sock_(sock) {}
~ScopedSocket() {
closesocket(sock_);
}
private:
const int sock_;
};
static bool TestSocketConnect() {
static const char kTestMessage[] = "test";
int listening_sock = socket(AF_INET, SOCK_STREAM, 0);
if (listening_sock == -1) {
PrintSocketError("socket");
return false;
}
ScopedSocket listening_sock_closer(listening_sock);
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
if (!inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr)) {
print_socket_error("inet_pton");
return 0;
PrintSocketError("inet_pton");
return false;
}
if (bind(listening_sock, (struct sockaddr *)&sin, sizeof(sin)) != 0) {
print_socket_error("bind");
return 0;
PrintSocketError("bind");
return false;
}
if (listen(listening_sock, 1)) {
print_socket_error("listen");
return 0;
PrintSocketError("listen");
return false;
}
socklen_t sockaddr_len = sizeof(sin);
if (getsockname(listening_sock, (struct sockaddr *)&sin, &sockaddr_len) ||
sockaddr_len != sizeof(sin)) {
print_socket_error("getsockname");
return 0;
PrintSocketError("getsockname");
return false;
}
char hostname[80];
BIO_snprintf(hostname, sizeof(hostname), "%s:%d", "127.0.0.1",
ntohs(sin.sin_port));
bio = BIO_new_connect(hostname);
ScopedBIO bio(BIO_new_connect(hostname));
if (!bio) {
fprintf(stderr, "BIO_new_connect failed.\n");
return 0;
return false;
}
if (BIO_write(bio, kTestMessage, sizeof(kTestMessage)) !=
if (BIO_write(bio.get(), kTestMessage, sizeof(kTestMessage)) !=
sizeof(kTestMessage)) {
fprintf(stderr, "BIO_write failed.\n");
BIO_print_errors_fp(stderr);
return 0;
return false;
}
sock = accept(listening_sock, (struct sockaddr *) &sin, &sockaddr_len);
if (sock < 0) {
print_socket_error("accept");
return 0;
int sock = accept(listening_sock, (struct sockaddr *) &sin, &sockaddr_len);
if (sock == -1) {
PrintSocketError("accept");
return false;
}
ScopedSocket sock_closer(sock);
char buf[5];
if (recv(sock, buf, sizeof(buf), 0) != sizeof(kTestMessage)) {
print_socket_error("read");
return 0;
PrintSocketError("read");
return false;
}
if (memcmp(buf, kTestMessage, sizeof(kTestMessage))) {
return 0;
return false;
}
closesocket(sock);
closesocket(listening_sock);
BIO_free(bio);
return 1;
return true;
}
/* bio_read_zero_copy_wrapper is a wrapper around the zero-copy APIs to make
* testing easier. */
static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
// BioReadZeroCopyWrapper is a wrapper around the zero-copy APIs to make
// testing easier.
static size_t BioReadZeroCopyWrapper(BIO *bio, uint8_t *data, size_t len) {
uint8_t *read_buf;
size_t read_buf_offset;
size_t available_bytes;
@@ -137,7 +149,7 @@ static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
return 0;
}
available_bytes = MIN(available_bytes, len - len_read);
available_bytes = std::min(available_bytes, len - len_read);
memmove(data + len_read, read_buf + read_buf_offset, available_bytes);
BIO_zero_copy_get_read_buf_done(bio, available_bytes);
@@ -148,10 +160,10 @@ static size_t bio_read_zero_copy_wrapper(BIO *bio, uint8_t *data, size_t len) {
return len_read;
}
/* bio_write_zero_copy_wrapper is a wrapper around the zero-copy APIs to make
* testing easier. */
static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
size_t len) {
// BioWriteZeroCopyWrapper is a wrapper around the zero-copy APIs to make
// testing easier.
static size_t BioWriteZeroCopyWrapper(BIO *bio, const uint8_t *data,
size_t len) {
uint8_t *write_buf;
size_t write_buf_offset;
size_t available_bytes;
@@ -163,7 +175,7 @@ static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
return 0;
}
available_bytes = MIN(available_bytes, len - len_written);
available_bytes = std::min(available_bytes, len - len_written);
memmove(write_buf + write_buf_offset, data + len_written, available_bytes);
BIO_zero_copy_get_write_buf_done(bio, available_bytes);
@@ -174,167 +186,157 @@ static size_t bio_write_zero_copy_wrapper(BIO *bio, const uint8_t *data,
return len_written;
}
static int test_zero_copy_bio_pairs(void) {
/* Test read and write, especially triggering the ring buffer wrap-around.*/
BIO* bio1;
BIO* bio2;
size_t i, j;
static bool TestZeroCopyBioPairs() {
// Test read and write, especially triggering the ring buffer wrap-around.
uint8_t bio1_application_send_buffer[1024];
uint8_t bio2_application_recv_buffer[1024];
size_t total_read = 0;
size_t total_write = 0;
uint8_t* write_buf;
size_t write_buf_offset;
size_t available_bytes;
size_t bytes_left;
const size_t kLengths[] = {254, 255, 256, 257, 510, 511, 512, 513};
/* These trigger ring buffer wrap around. */
// These trigger ring buffer wrap around.
const size_t kPartialLengths[] = {0, 1, 2, 3, 128, 255, 256, 257, 511, 512};
static const size_t kBufferSize = 512;
srand(1);
for (i = 0; i < sizeof(bio1_application_send_buffer); i++) {
for (size_t i = 0; i < sizeof(bio1_application_send_buffer); i++) {
bio1_application_send_buffer[i] = rand() & 255;
}
/* Transfer bytes from bio1_application_send_buffer to
* bio2_application_recv_buffer in various ways. */
for (i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
for (j = 0; j < sizeof(kPartialLengths) / sizeof(kPartialLengths[0]); j++) {
total_write = 0;
total_read = 0;
// Transfer bytes from bio1_application_send_buffer to
// bio2_application_recv_buffer in various ways.
for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
for (size_t j = 0; j < sizeof(kPartialLengths) / sizeof(kPartialLengths[0]);
j++) {
size_t total_write = 0;
size_t total_read = 0;
BIO_new_bio_pair(&bio1, kBufferSize, &bio2, kBufferSize);
BIO *bio1, *bio2;
if (!BIO_new_bio_pair(&bio1, kBufferSize, &bio2, kBufferSize)) {
return false;
}
ScopedBIO bio1_scoper(bio1);
ScopedBIO bio2_scoper(bio2);
total_write += bio_write_zero_copy_wrapper(
total_write += BioWriteZeroCopyWrapper(
bio1, bio1_application_send_buffer, kLengths[i]);
/* This tests interleaved read/write calls. Do a read between zero copy
* write calls. */
// This tests interleaved read/write calls. Do a read between zero copy
// write calls.
uint8_t *write_buf;
size_t write_buf_offset;
size_t available_bytes;
if (!BIO_zero_copy_get_write_buf(bio1, &write_buf, &write_buf_offset,
&available_bytes)) {
return 0;
return false;
}
/* Free kPartialLengths[j] bytes in the beginning of bio1 write buffer.
* This enables ring buffer wrap around for the next write. */
// Free kPartialLengths[j] bytes in the beginning of bio1 write buffer.
// This enables ring buffer wrap around for the next write.
total_read += BIO_read(bio2, bio2_application_recv_buffer + total_read,
kPartialLengths[j]);
size_t interleaved_write_len = MIN(kPartialLengths[j], available_bytes);
size_t interleaved_write_len = std::min(kPartialLengths[j],
available_bytes);
/* Write the data for the interleaved write call. If the buffer becomes
* empty after a read, the write offset is normally set to 0. Check that
* this does not happen for interleaved read/write and that
* |write_buf_offset| is still valid. */
// Write the data for the interleaved write call. If the buffer becomes
// empty after a read, the write offset is normally set to 0. Check that
// this does not happen for interleaved read/write and that
// |write_buf_offset| is still valid.
memcpy(write_buf + write_buf_offset,
bio1_application_send_buffer + total_write, interleaved_write_len);
if (BIO_zero_copy_get_write_buf_done(bio1, interleaved_write_len)) {
total_write += interleaved_write_len;
}
/* Do another write in case |write_buf_offset| was wrapped */
total_write += bio_write_zero_copy_wrapper(
// Do another write in case |write_buf_offset| was wrapped.
total_write += BioWriteZeroCopyWrapper(
bio1, bio1_application_send_buffer + total_write,
kPartialLengths[j] - interleaved_write_len);
/* Drain the rest. */
bytes_left = BIO_pending(bio2);
total_read += bio_read_zero_copy_wrapper(
// Drain the rest.
size_t bytes_left = BIO_pending(bio2);
total_read += BioReadZeroCopyWrapper(
bio2, bio2_application_recv_buffer + total_read, bytes_left);
BIO_free(bio1);
BIO_free(bio2);
if (total_read != total_write) {
fprintf(stderr, "Lengths not equal in round (%u, %u)\n", (unsigned)i,
(unsigned)j);
return 0;
return false;
}
if (total_read > kLengths[i] + kPartialLengths[j]) {
fprintf(stderr, "Bad lengths in round (%u, %u)\n", (unsigned)i,
(unsigned)j);
return 0;
return false;
}
if (memcmp(bio1_application_send_buffer, bio2_application_recv_buffer,
total_read) != 0) {
fprintf(stderr, "Buffers not equal in round (%u, %u)\n", (unsigned)i,
(unsigned)j);
return 0;
return false;
}
}
}
return 1;
return true;
}
static int test_printf(void) {
/* Test a short output, a very long one, and various sizes around
* 256 (the size of the buffer) to ensure edge cases are correct. */
static bool TestPrintf() {
// Test a short output, a very long one, and various sizes around
// 256 (the size of the buffer) to ensure edge cases are correct.
static const size_t kLengths[] = { 5, 250, 251, 252, 253, 254, 1023 };
BIO *bio;
char string[1024];
int ret;
const uint8_t *contents;
size_t i, len;
bio = BIO_new(BIO_s_mem());
ScopedBIO bio(BIO_new(BIO_s_mem()));
if (!bio) {
fprintf(stderr, "BIO_new failed\n");
return 0;
return false;
}
for (i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
for (size_t i = 0; i < sizeof(kLengths) / sizeof(kLengths[0]); i++) {
char string[1024];
if (kLengths[i] >= sizeof(string)) {
fprintf(stderr, "Bad test string length\n");
return 0;
return false;
}
memset(string, 'a', sizeof(string));
string[kLengths[i]] = '\0';
ret = BIO_printf(bio, "test %s", string);
if (ret != 5 + kLengths[i]) {
int ret = BIO_printf(bio.get(), "test %s", string);
if (ret < 0 || static_cast<size_t>(ret) != 5 + kLengths[i]) {
fprintf(stderr, "BIO_printf failed: %d\n", ret);
return 0;
return false;
}
if (!BIO_mem_contents(bio, &contents, &len)) {
const uint8_t *contents;
size_t len;
if (!BIO_mem_contents(bio.get(), &contents, &len)) {
fprintf(stderr, "BIO_mem_contents failed\n");
return 0;
return false;
}
if (len != 5 + kLengths[i] ||
strncmp((const char *)contents, "test ", 5) != 0 ||
strncmp((const char *)contents + 5, string, kLengths[i]) != 0) {
fprintf(stderr, "Contents did not match: %.*s\n", (int)len, contents);
return 0;
return false;
}
if (!BIO_reset(bio)) {
if (!BIO_reset(bio.get())) {
fprintf(stderr, "BIO_reset failed\n");
return 0;
return false;
}
}
BIO_free(bio);
return 1;
return true;
}
int main(void) {
#if defined(OPENSSL_WINDOWS)
WSADATA wsa_data;
WORD wsa_version;
int wsa_err;
#endif
CRYPTO_library_init();
ERR_load_crypto_strings();
#if defined(OPENSSL_WINDOWS)
/* Initialize Winsock. */
wsa_version = MAKEWORD(2, 2);
wsa_err = WSAStartup(wsa_version, &wsa_data);
// Initialize Winsock.
WORD wsa_version = MAKEWORD(2, 2);
WSADATA wsa_data;
int wsa_err = WSAStartup(wsa_version, &wsa_data);
if (wsa_err != 0) {
fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
return 1;
@@ -345,15 +347,9 @@ int main(void) {
}
#endif
if (!test_socket_connect()) {
return 1;
}
if (!test_printf()) {
return 1;
}
if (!test_zero_copy_bio_pairs()) {
if (!TestSocketConnect() ||
!TestPrintf() ||
!TestZeroCopyBioPairs()) {
return 1;
}
+2 -2
View File
@@ -68,8 +68,8 @@
#include <unistd.h>
#else
#pragma warning(push, 3)
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma warning(pop)
#endif
+1 -1
View File
@@ -64,7 +64,7 @@
#else
#include <io.h>
#pragma warning(push, 3)
#include <Windows.h>
#include <windows.h>
#pragma warning(pop)
#endif
+3 -1
View File
@@ -64,8 +64,10 @@
#include <unistd.h>
#else
#pragma warning(push, 3)
#include <WinSock2.h>
#include <winsock2.h>
#pragma warning(pop)
#pragma comment(lib, "Ws2_32.lib")
#endif
#include "internal.h"
+2 -2
View File
@@ -26,8 +26,8 @@
#include <unistd.h>
#else
#pragma warning(push, 3)
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma warning(pop)
#endif
+1 -1
View File
@@ -69,7 +69,7 @@ perlasm(armv4-mont.${ASM_EXT} asm/armv4-mont.pl)
add_executable(
bn_test
bn_test.c
bn_test.cc
)
target_link_libraries(bn_test crypto)
+1
View File
@@ -661,6 +661,7 @@ $code.=<<___;
.align 2
#if __ARM_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___
-1506
View File
File diff suppressed because it is too large Load Diff
+1424
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -172,12 +172,13 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
}
}
}
ret = 1;
err:
if (r != rr) {
BN_copy(r, rr);
}
ret = 1;
err:
BN_CTX_end(ctx);
return ret;
}
+6
View File
@@ -125,6 +125,12 @@
#include <openssl/base.h>
/* Some versions of inttypes.h will not define print macros in C++ unless
* __STDC_FORMAT_MACROS is set. */
#if !defined(__STDC_FORMAT_MACROS)
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#if defined(OPENSSL_X86_64) && defined(_MSC_VER) && _MSC_VER >= 1400
+7 -1
View File
@@ -659,7 +659,13 @@ again:
/* If bits is so small that it fits into a single word then we
* additionally don't want to exceed that many bits. */
if (is_single_word) {
BN_ULONG size_limit = (((BN_ULONG)1) << bits) - get_word(rnd) - 1;
BN_ULONG size_limit;
if (bits == BN_BITS2) {
/* Avoid undefined behavior. */
size_limit = ~((BN_ULONG)0) - get_word(rnd);
} else {
size_limit = (((BN_ULONG)1) << bits) - get_word(rnd) - 1;
}
if (size_limit < maxdelta) {
maxdelta = size_limit;
}
+1 -1
View File
@@ -13,7 +13,7 @@ add_library(
add_executable(
bytestring_test
bytestring_test.c
bytestring_test.cc
)
target_link_libraries(bytestring_test crypto)
@@ -16,14 +16,17 @@
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <openssl/crypto.h>
#include <openssl/bytestring.h>
#include "internal.h"
#include "../internal.h"
#include "../test/scoped_types.h"
static int test_skip(void) {
static bool TestSkip() {
static const uint8_t kData[] = {1, 2, 3};
CBS data;
@@ -36,7 +39,7 @@ static int test_skip(void) {
!CBS_skip(&data, 1);
}
static int test_get_u(void) {
static bool TestGetUint() {
static const uint8_t kData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
uint8_t u8;
uint16_t u16;
@@ -55,7 +58,7 @@ static int test_get_u(void) {
!CBS_get_u8(&data, &u8);
}
static int test_get_prefixed(void) {
static bool TestGetPrefixed() {
static const uint8_t kData[] = {1, 2, 0, 2, 3, 4, 0, 0, 3, 3, 2, 1};
uint8_t u8;
uint16_t u16;
@@ -77,7 +80,7 @@ static int test_get_prefixed(void) {
u32 == 0x30201;
}
static int test_get_prefixed_bad(void) {
static bool TestGetPrefixedBad() {
static const uint8_t kData1[] = {2, 1};
static const uint8_t kData2[] = {0, 2, 1};
static const uint8_t kData3[] = {0, 0, 2, 1};
@@ -85,23 +88,23 @@ static int test_get_prefixed_bad(void) {
CBS_init(&data, kData1, sizeof(kData1));
if (CBS_get_u8_length_prefixed(&data, &prefixed)) {
return 0;
return false;
}
CBS_init(&data, kData2, sizeof(kData2));
if (CBS_get_u16_length_prefixed(&data, &prefixed)) {
return 0;
return false;
}
CBS_init(&data, kData3, sizeof(kData3));
if (CBS_get_u24_length_prefixed(&data, &prefixed)) {
return 0;
return false;
}
return 1;
return true;
}
static int test_get_asn1(void) {
static bool TestGetASN1() {
static const uint8_t kData1[] = {0x30, 2, 1, 2};
static const uint8_t kData2[] = {0x30, 3, 1, 2};
static const uint8_t kData3[] = {0x30, 0x80};
@@ -119,52 +122,52 @@ static int test_get_asn1(void) {
CBS_init(&data, kData1, sizeof(kData1));
if (CBS_peek_asn1_tag(&data, 0x1) ||
!CBS_peek_asn1_tag(&data, 0x30)) {
return 0;
return false;
}
if (!CBS_get_asn1(&data, &contents, 0x30) ||
CBS_len(&contents) != 2 ||
memcmp(CBS_data(&contents), "\x01\x02", 2) != 0) {
return 0;
return false;
}
CBS_init(&data, kData2, sizeof(kData2));
/* data is truncated */
// data is truncated
if (CBS_get_asn1(&data, &contents, 0x30)) {
return 0;
return false;
}
CBS_init(&data, kData3, sizeof(kData3));
/* zero byte length of length */
// zero byte length of length
if (CBS_get_asn1(&data, &contents, 0x30)) {
return 0;
return false;
}
CBS_init(&data, kData4, sizeof(kData4));
/* long form mistakenly used. */
// long form mistakenly used.
if (CBS_get_asn1(&data, &contents, 0x30)) {
return 0;
return false;
}
CBS_init(&data, kData5, sizeof(kData5));
/* length takes too many bytes. */
// length takes too many bytes.
if (CBS_get_asn1(&data, &contents, 0x30)) {
return 0;
return false;
}
CBS_init(&data, kData1, sizeof(kData1));
/* wrong tag. */
// wrong tag.
if (CBS_get_asn1(&data, &contents, 0x31)) {
return 0;
return false;
}
CBS_init(&data, NULL, 0);
/* peek at empty data. */
// peek at empty data.
if (CBS_peek_asn1_tag(&data, 0x30)) {
return 0;
return false;
}
CBS_init(&data, NULL, 0);
/* optional elements at empty data. */
// optional elements at empty data.
if (!CBS_get_optional_asn1(&data, &contents, &present, 0xa0) ||
present ||
!CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa0) ||
@@ -174,22 +177,22 @@ static int test_get_asn1(void) {
CBS_len(&contents) != 0 ||
!CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42) ||
value != 42) {
return 0;
return false;
}
CBS_init(&data, kData6, sizeof(kData6));
/* optional element. */
// optional element.
if (!CBS_get_optional_asn1(&data, &contents, &present, 0xa0) ||
present ||
!CBS_get_optional_asn1(&data, &contents, &present, 0xa1) ||
!present ||
CBS_len(&contents) != 3 ||
memcmp(CBS_data(&contents), "\x04\x01\x01", 3) != 0) {
return 0;
return false;
}
CBS_init(&data, kData6, sizeof(kData6));
/* optional octet string. */
// optional octet string.
if (!CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa0) ||
present ||
CBS_len(&contents) != 0 ||
@@ -197,97 +200,96 @@ static int test_get_asn1(void) {
!present ||
CBS_len(&contents) != 1 ||
CBS_data(&contents)[0] != 1) {
return 0;
return false;
}
CBS_init(&data, kData7, sizeof(kData7));
/* invalid optional octet string. */
// invalid optional octet string.
if (CBS_get_optional_asn1_octet_string(&data, &contents, &present, 0xa1)) {
return 0;
return false;
}
CBS_init(&data, kData8, sizeof(kData8));
/* optional octet string. */
// optional octet string.
if (!CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42) ||
value != 42 ||
!CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42) ||
value != 1) {
return 0;
return false;
}
CBS_init(&data, kData9, sizeof(kData9));
/* invalid optional integer. */
// invalid optional integer.
if (CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42)) {
return 0;
return false;
}
return 1;
return true;
}
static int test_get_optional_asn1_bool(void) {
CBS data;
int val;
static bool TestGetOptionalASN1Bool() {
static const uint8_t kTrue[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0xff};
static const uint8_t kFalse[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x00};
static const uint8_t kInvalid[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x01};
CBS data;
CBS_init(&data, NULL, 0);
val = 2;
int val = 2;
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0) ||
val != 0) {
return 0;
return false;
}
CBS_init(&data, kTrue, sizeof(kTrue));
val = 2;
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0) ||
val != 1) {
return 0;
return false;
}
CBS_init(&data, kFalse, sizeof(kFalse));
val = 2;
if (!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1) ||
val != 0) {
return 0;
return false;
}
CBS_init(&data, kInvalid, sizeof(kInvalid));
if (CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1)) {
return 0;
return false;
}
return 1;
return true;
}
static int test_cbb_basic(void) {
static bool TestCBBBasic() {
static const uint8_t kExpected[] = {1, 2, 3, 4, 5, 6, 7, 8};
uint8_t *buf;
size_t buf_len;
int ok;
CBB cbb;
if (!CBB_init(&cbb, 100)) {
return 0;
return false;
}
CBB_cleanup(&cbb);
if (!CBB_init(&cbb, 0) ||
!CBB_add_u8(&cbb, 1) ||
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_u8(&cbb, 1) ||
!CBB_add_u16(&cbb, 0x203) ||
!CBB_add_u24(&cbb, 0x40506) ||
!CBB_add_bytes(&cbb, (const uint8_t*) "\x07\x08", 2) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
CBB_cleanup(&cbb);
return false;
}
ok = buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
free(buf);
return ok;
ScopedOpenSSLBytes scoper(buf);
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
}
static int test_cbb_fixed(void) {
static bool TestCBBFixed() {
CBB cbb;
uint8_t buf[1];
uint8_t *out_buf;
@@ -298,7 +300,7 @@ static int test_cbb_fixed(void) {
!CBB_finish(&cbb, &out_buf, &out_size) ||
out_buf != NULL ||
out_size != 0) {
return 0;
return false;
}
if (!CBB_init_fixed(&cbb, buf, 1) ||
@@ -308,40 +310,41 @@ static int test_cbb_fixed(void) {
out_buf != buf ||
out_size != 1 ||
buf[0] != 1) {
return 0;
return false;
}
return 1;
return true;
}
static int test_cbb_finish_child(void) {
static bool TestCBBFinishChild() {
CBB cbb, child;
uint8_t *out_buf;
size_t out_size;
if (!CBB_init(&cbb, 16) ||
!CBB_add_u8_length_prefixed(&cbb, &child) ||
CBB_finish(&child, &out_buf, &out_size) ||
!CBB_finish(&cbb, &out_buf, &out_size) ||
out_size != 1 ||
out_buf[0] != 0) {
return 0;
if (!CBB_init(&cbb, 16)) {
return false;
}
free(out_buf);
return 1;
if (!CBB_add_u8_length_prefixed(&cbb, &child) ||
CBB_finish(&child, &out_buf, &out_size) ||
!CBB_finish(&cbb, &out_buf, &out_size)) {
CBB_cleanup(&cbb);
return false;
}
ScopedOpenSSLBytes scoper(out_buf);
return out_size == 1 && out_buf[0] == 0;
}
static int test_cbb_prefixed(void) {
static bool TestCBBPrefixed() {
static const uint8_t kExpected[] = {0, 1, 1, 0, 2, 2, 3, 0, 0, 3,
4, 5, 6, 5, 4, 1, 0, 1, 2};
uint8_t *buf;
size_t buf_len;
CBB cbb, contents, inner_contents, inner_inner_contents;
int ok;
if (!CBB_init(&cbb, 0) ||
!CBB_add_u8_length_prefixed(&cbb, &contents) ||
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_u8_length_prefixed(&cbb, &contents) ||
!CBB_add_u8_length_prefixed(&cbb, &contents) ||
!CBB_add_u8(&contents, 1) ||
!CBB_add_u16_length_prefixed(&cbb, &contents) ||
@@ -354,28 +357,31 @@ static int test_cbb_prefixed(void) {
!CBB_add_u16_length_prefixed(&inner_contents, &inner_inner_contents) ||
!CBB_add_u8(&inner_inner_contents, 2) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
CBB_cleanup(&cbb);
return false;
}
ok = buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
free(buf);
return ok;
ScopedOpenSSLBytes scoper(buf);
return buf_len == sizeof(kExpected) && memcmp(buf, kExpected, buf_len) == 0;
}
static int test_cbb_misuse(void) {
static bool TestCBBMisuse() {
CBB cbb, child, contents;
uint8_t *buf;
size_t buf_len;
if (!CBB_init(&cbb, 0) ||
!CBB_add_u8_length_prefixed(&cbb, &child) ||
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_u8_length_prefixed(&cbb, &child) ||
!CBB_add_u8(&child, 1) ||
!CBB_add_u8(&cbb, 2)) {
return 0;
CBB_cleanup(&cbb);
return false;
}
/* Since we wrote to |cbb|, |child| is now invalid and attempts to write to
* it should fail. */
// Since we wrote to |cbb|, |child| is now invalid and attempts to write to
// it should fail.
if (CBB_add_u8(&child, 1) ||
CBB_add_u16(&child, 1) ||
CBB_add_u24(&child, 1) ||
@@ -384,91 +390,104 @@ static int test_cbb_misuse(void) {
CBB_add_asn1(&child, &contents, 1) ||
CBB_add_bytes(&child, (const uint8_t*) "a", 1)) {
fprintf(stderr, "CBB operation on invalid CBB did not fail.\n");
return 0;
CBB_cleanup(&cbb);
return false;
}
if (!CBB_finish(&cbb, &buf, &buf_len) ||
buf_len != 3 ||
if (!CBB_finish(&cbb, &buf, &buf_len)) {
CBB_cleanup(&cbb);
return false;
}
ScopedOpenSSLBytes scoper(buf);
if (buf_len != 3 ||
memcmp(buf, "\x01\x01\x02", 3) != 0) {
return 0;
return false;
}
free(buf);
return 1;
return true;
}
static int test_cbb_asn1(void) {
static bool TestCBBASN1() {
static const uint8_t kExpected[] = {0x30, 3, 1, 2, 3};
uint8_t *buf, *test_data;
uint8_t *buf;
size_t buf_len;
CBB cbb, contents, inner_contents;
if (!CBB_init(&cbb, 0) ||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_bytes(&contents, (const uint8_t*) "\x01\x02\x03", 3) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
CBB_cleanup(&cbb);
return false;
}
ScopedOpenSSLBytes scoper(buf);
if (buf_len != sizeof(kExpected) || memcmp(buf, kExpected, buf_len) != 0) {
return 0;
return false;
}
free(buf);
test_data = malloc(100000);
memset(test_data, 0x42, 100000);
std::vector<uint8_t> test_data(100000, 0x42);
if (!CBB_init(&cbb, 0) ||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_bytes(&contents, test_data, 130) ||
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_bytes(&contents, bssl::vector_data(&test_data), 130) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
CBB_cleanup(&cbb);
return false;
}
scoper.reset(buf);
if (buf_len != 3 + 130 ||
memcmp(buf, "\x30\x81\x82", 3) != 0 ||
memcmp(buf + 3, test_data, 130) != 0) {
return 0;
memcmp(buf + 3, bssl::vector_data(&test_data), 130) != 0) {
return false;
}
free(buf);
if (!CBB_init(&cbb, 0) ||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_bytes(&contents, test_data, 1000) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_bytes(&contents, bssl::vector_data(&test_data), 1000) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
CBB_cleanup(&cbb);
return false;
}
scoper.reset(buf);
if (buf_len != 4 + 1000 ||
memcmp(buf, "\x30\x82\x03\xe8", 4) != 0 ||
memcmp(buf + 4, test_data, 1000)) {
return 0;
memcmp(buf + 4, bssl::vector_data(&test_data), 1000)) {
return false;
}
free(buf);
if (!CBB_init(&cbb, 0) ||
!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_asn1(&contents, &inner_contents, 0x30) ||
!CBB_add_bytes(&inner_contents, test_data, 100000) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
return 0;
if (!CBB_init(&cbb, 0)) {
return false;
}
if (!CBB_add_asn1(&cbb, &contents, 0x30) ||
!CBB_add_asn1(&contents, &inner_contents, 0x30) ||
!CBB_add_bytes(&inner_contents, bssl::vector_data(&test_data), 100000) ||
!CBB_finish(&cbb, &buf, &buf_len)) {
CBB_cleanup(&cbb);
return false;
}
scoper.reset(buf);
if (buf_len != 5 + 5 + 100000 ||
memcmp(buf, "\x30\x83\x01\x86\xa5\x30\x83\x01\x86\xa0", 10) != 0 ||
memcmp(buf + 10, test_data, 100000)) {
return 0;
memcmp(buf + 10, bssl::vector_data(&test_data), 100000)) {
return false;
}
free(buf);
free(test_data);
return 1;
return true;
}
static int do_ber_convert(const char *name,
const uint8_t *der_expected, size_t der_len,
const uint8_t *ber, size_t ber_len) {
static bool DoBerConvert(const char *name,
const uint8_t *der_expected, size_t der_len,
const uint8_t *ber, size_t ber_len) {
CBS in;
uint8_t *out;
size_t out_len;
@@ -476,44 +495,44 @@ static int do_ber_convert(const char *name,
CBS_init(&in, ber, ber_len);
if (!CBS_asn1_ber_to_der(&in, &out, &out_len)) {
fprintf(stderr, "%s: CBS_asn1_ber_to_der failed.\n", name);
return 0;
return false;
}
ScopedOpenSSLBytes scoper(out);
if (out == NULL) {
if (ber_len != der_len ||
memcmp(der_expected, ber, ber_len) != 0) {
fprintf(stderr, "%s: incorrect unconverted result.\n", name);
return 0;
return false;
}
return 1;
return true;
}
if (out_len != der_len ||
memcmp(out, der_expected, der_len) != 0) {
fprintf(stderr, "%s: incorrect converted result.\n", name);
return 0;
return false;
}
free(out);
return 1;
return true;
}
static int test_ber_convert(void) {
static bool TestBerConvert() {
static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00};
/* kIndefBER contains a SEQUENCE with an indefinite length. */
// kIndefBER contains a SEQUENCE with an indefinite length.
static const uint8_t kIndefBER[] = {0x30, 0x80, 0x01, 0x01, 0x02, 0x00, 0x00};
static const uint8_t kIndefDER[] = {0x30, 0x03, 0x01, 0x01, 0x02};
/* kOctetStringBER contains an indefinite length OCTETSTRING with two parts.
* These parts need to be concatenated in DER form. */
// kOctetStringBER contains an indefinite length OCTETSTRING with two parts.
// These parts need to be concatenated in DER form.
static const uint8_t kOctetStringBER[] = {0x24, 0x80, 0x04, 0x02, 0, 1,
0x04, 0x02, 2, 3, 0x00, 0x00};
static const uint8_t kOctetStringDER[] = {0x04, 0x04, 0, 1, 2, 3};
/* kNSSBER is part of a PKCS#12 message generated by NSS that uses indefinite
* length elements extensively. */
// kNSSBER is part of a PKCS#12 message generated by NSS that uses indefinite
// length elements extensively.
static const uint8_t kNSSBER[] = {
0x30, 0x80, 0x02, 0x01, 0x03, 0x30, 0x80, 0x06, 0x09, 0x2a, 0x86, 0x48,
0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x80, 0x24, 0x80, 0x04, 0x04,
@@ -536,56 +555,55 @@ static int test_ber_convert(void) {
0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0,
};
return do_ber_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
kSimpleBER, sizeof(kSimpleBER)) &&
do_ber_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
sizeof(kIndefBER)) &&
do_ber_convert("kOctetStringBER", kOctetStringDER,
sizeof(kOctetStringDER), kOctetStringBER,
sizeof(kOctetStringBER)) &&
do_ber_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
sizeof(kNSSBER));
return DoBerConvert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER),
kSimpleBER, sizeof(kSimpleBER)) &&
DoBerConvert("kIndefBER", kIndefDER, sizeof(kIndefDER), kIndefBER,
sizeof(kIndefBER)) &&
DoBerConvert("kOctetStringBER", kOctetStringDER,
sizeof(kOctetStringDER), kOctetStringBER,
sizeof(kOctetStringBER)) &&
DoBerConvert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER,
sizeof(kNSSBER));
}
typedef struct {
struct ASN1Uint64Test {
uint64_t value;
const char *encoding;
size_t encoding_len;
} ASN1_UINT64_TEST;
static const ASN1_UINT64_TEST kAsn1Uint64Tests[] = {
{0, "\x02\x01\x00", 3},
{1, "\x02\x01\x01", 3},
{127, "\x02\x01\x7f", 3},
{128, "\x02\x02\x00\x80", 4},
{0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7},
{OPENSSL_U64(0x0102030405060708),
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
{OPENSSL_U64(0xffffffffffffffff),
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
};
typedef struct {
static const ASN1Uint64Test kASN1Uint64Tests[] = {
{0, "\x02\x01\x00", 3},
{1, "\x02\x01\x01", 3},
{127, "\x02\x01\x7f", 3},
{128, "\x02\x02\x00\x80", 4},
{0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7},
{OPENSSL_U64(0x0102030405060708),
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
{OPENSSL_U64(0xffffffffffffffff),
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
};
struct ASN1InvalidUint64Test {
const char *encoding;
size_t encoding_len;
} ASN1_INVALID_UINT64_TEST;
static const ASN1_INVALID_UINT64_TEST kAsn1InvalidUint64Tests[] = {
/* Bad tag. */
{"\x03\x01\x00", 3},
/* Empty contents. */
{"\x02\x00", 2},
/* Negative number. */
{"\x02\x01\x80", 3},
/* Overflow */
{"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11},
};
static int test_asn1_uint64(void) {
size_t i;
static const ASN1InvalidUint64Test kASN1InvalidUint64Tests[] = {
// Bad tag.
{"\x03\x01\x00", 3},
// Empty contents.
{"\x02\x00", 2},
// Negative number.
{"\x02\x01\x80", 3},
// Overflow
{"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11},
};
for (i = 0; i < sizeof(kAsn1Uint64Tests) / sizeof(kAsn1Uint64Tests[0]); i++) {
const ASN1_UINT64_TEST *test = &kAsn1Uint64Tests[i];
static bool TestASN1Uint64() {
for (size_t i = 0; i < sizeof(kASN1Uint64Tests) / sizeof(kASN1Uint64Tests[0]);
i++) {
const ASN1Uint64Test *test = &kASN1Uint64Tests[i];
CBS cbs;
uint64_t value;
CBB cbb;
@@ -596,57 +614,56 @@ static int test_asn1_uint64(void) {
if (!CBS_get_asn1_uint64(&cbs, &value) ||
CBS_len(&cbs) != 0 ||
value != test->value) {
return 0;
return false;
}
if (!CBB_init(&cbb, 0)) {
return 0;
return false;
}
if (!CBB_add_asn1_uint64(&cbb, test->value) ||
!CBB_finish(&cbb, &out, &len)) {
CBB_cleanup(&cbb);
return 0;
return false;
}
ScopedOpenSSLBytes scoper(out);
if (len != test->encoding_len || memcmp(out, test->encoding, len) != 0) {
free(out);
return 0;
return false;
}
free(out);
}
for (i = 0;
i < sizeof(kAsn1InvalidUint64Tests) / sizeof(kAsn1InvalidUint64Tests[0]);
for (size_t i = 0;
i < sizeof(kASN1InvalidUint64Tests) / sizeof(kASN1InvalidUint64Tests[0]);
i++) {
const ASN1_INVALID_UINT64_TEST *test = &kAsn1InvalidUint64Tests[i];
const ASN1InvalidUint64Test *test = &kASN1InvalidUint64Tests[i];
CBS cbs;
uint64_t value;
CBS_init(&cbs, (const uint8_t *)test->encoding, test->encoding_len);
if (CBS_get_asn1_uint64(&cbs, &value)) {
return 0;
return false;
}
}
return 1;
return true;
}
int main(void) {
CRYPTO_library_init();
if (!test_skip() ||
!test_get_u() ||
!test_get_prefixed() ||
!test_get_prefixed_bad() ||
!test_get_asn1() ||
!test_cbb_basic() ||
!test_cbb_fixed() ||
!test_cbb_finish_child() ||
!test_cbb_misuse() ||
!test_cbb_prefixed() ||
!test_cbb_asn1() ||
!test_ber_convert() ||
!test_asn1_uint64() ||
!test_get_optional_asn1_bool()) {
if (!TestSkip() ||
!TestGetUint() ||
!TestGetPrefixed() ||
!TestGetPrefixedBad() ||
!TestGetASN1() ||
!TestCBBBasic() ||
!TestCBBFixed() ||
!TestCBBFinishChild() ||
!TestCBBMisuse() ||
!TestCBBPrefixed() ||
!TestCBBASN1() ||
!TestBerConvert() ||
!TestASN1Uint64() ||
!TestGetOptionalASN1Bool()) {
return 1;
}
+29 -4
View File
@@ -33,12 +33,29 @@ size_t EVP_AEAD_max_tag_len(const EVP_AEAD *aead) { return aead->max_tag_len; }
int EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
const uint8_t *key, size_t key_len, size_t tag_len,
ENGINE *impl) {
ctx->aead = aead;
if (key_len != aead->key_len) {
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init, CIPHER_R_UNSUPPORTED_KEY_SIZE);
if (!aead->init) {
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init, CIPHER_R_NO_DIRECTION_SET);
return 0;
}
return aead->init(ctx, key, key_len, tag_len);
return EVP_AEAD_CTX_init_with_direction(ctx, aead, key, key_len, tag_len,
evp_aead_open);
}
int EVP_AEAD_CTX_init_with_direction(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead,
const uint8_t *key, size_t key_len,
size_t tag_len,
enum evp_aead_direction_t dir) {
ctx->aead = aead;
if (key_len != aead->key_len) {
OPENSSL_PUT_ERROR(CIPHER, EVP_AEAD_CTX_init_with_direction,
CIPHER_R_UNSUPPORTED_KEY_SIZE);
return 0;
}
if (aead->init) {
return aead->init(ctx, key, key_len, tag_len);
} else {
return aead->init_with_direction(ctx, key, key_len, tag_len, dir);
}
}
void EVP_AEAD_CTX_cleanup(EVP_AEAD_CTX *ctx) {
@@ -117,3 +134,11 @@ error:
*out_len = 0;
return 0;
}
int EVP_AEAD_CTX_get_rc4_state(const EVP_AEAD_CTX *ctx, const RC4_KEY **out_key) {
if (ctx->aead->get_rc4_state == NULL) {
return 0;
}
return ctx->aead->get_rc4_state(ctx, out_key);
}
+12 -8
View File
@@ -85,8 +85,8 @@ static int run_test_case(const EVP_AEAD *aead,
* smaller by at least tag length. */
uint8_t out2[sizeof(out)];
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
NULL)) {
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
lengths[TAG], evp_aead_seal)) {
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
return 0;
}
@@ -123,8 +123,8 @@ static int run_test_case(const EVP_AEAD *aead,
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
* reset after each operation. */
EVP_AEAD_CTX_cleanup(&ctx);
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
NULL)) {
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
lengths[TAG], evp_aead_open)) {
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
return 0;
}
@@ -153,8 +153,8 @@ static int run_test_case(const EVP_AEAD *aead,
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
* reset after each operation. */
EVP_AEAD_CTX_cleanup(&ctx);
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
NULL)) {
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
lengths[TAG], evp_aead_open)) {
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
return 0;
}
@@ -172,8 +172,8 @@ static int run_test_case(const EVP_AEAD *aead,
/* The "stateful" AEADs for implementing pre-AEAD cipher suites need to be
* reset after each operation. */
EVP_AEAD_CTX_cleanup(&ctx);
if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], lengths[TAG],
NULL)) {
if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bufs[KEY], lengths[KEY],
lengths[TAG], evp_aead_open)) {
fprintf(stderr, "Failed to init AEAD on line %u\n", line_no);
return 0;
}
@@ -251,6 +251,10 @@ int main(int argc, char **argv) {
aead = EVP_aead_aes_128_key_wrap();
} else if (strcmp(argv[1], "aes-256-key-wrap") == 0) {
aead = EVP_aead_aes_256_key_wrap();
} else if (strcmp(argv[1], "aes-128-ctr-hmac-sha256") == 0) {
aead = EVP_aead_aes_128_ctr_hmac_sha256();
} else if (strcmp(argv[1], "aes-256-ctr-hmac-sha256") == 0) {
aead = EVP_aead_aes_256_ctr_hmac_sha256();
} else {
fprintf(stderr, "Unknown AEAD: %s\n", argv[1]);
return 2;
+2 -2
View File
@@ -94,8 +94,8 @@ EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) {
}
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) {
if (c->cipher != NULL && c->cipher->cleanup && !c->cipher->cleanup(c)) {
return 0;
if (c->cipher != NULL && c->cipher->cleanup) {
c->cipher->cleanup(c);
}
if (c->cipher_data) {
+350 -28
View File
@@ -57,8 +57,10 @@
#include <openssl/modes.h>
#include <openssl/obj.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include "internal.h"
#include "../internal.h"
#include "../modes/internal.h"
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
@@ -390,28 +392,62 @@ static int aes_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
return 1;
}
static ctr128_f aes_gcm_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
const uint8_t *key, size_t key_len) {
static char aesni_capable(void);
static ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_CONTEXT *gcm_ctx,
block128_f *out_block, const uint8_t *key,
size_t key_len) {
if (aesni_capable()) {
aesni_set_encrypt_key(key, key_len * 8, aes_key);
if (gcm_ctx != NULL) {
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aesni_encrypt);
}
if (out_block) {
*out_block = (block128_f) aesni_encrypt;
}
return (ctr128_f)aesni_ctr32_encrypt_blocks;
}
if (hwaes_capable()) {
aes_v8_set_encrypt_key(key, key_len * 8, aes_key);
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aes_v8_encrypt);
if (gcm_ctx != NULL) {
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)aes_v8_encrypt);
}
if (out_block) {
*out_block = (block128_f) aes_v8_encrypt;
}
return (ctr128_f)aes_v8_ctr32_encrypt_blocks;
}
if (bsaes_capable()) {
AES_set_encrypt_key(key, key_len * 8, aes_key);
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
if (gcm_ctx != NULL) {
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
}
if (out_block) {
*out_block = (block128_f) AES_encrypt;
}
return (ctr128_f)bsaes_ctr32_encrypt_blocks;
}
if (vpaes_capable()) {
vpaes_set_encrypt_key(key, key_len * 8, aes_key);
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
if (out_block) {
*out_block = (block128_f) vpaes_encrypt;
}
if (gcm_ctx != NULL) {
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)vpaes_encrypt);
}
return NULL;
}
AES_set_encrypt_key(key, key_len * 8, aes_key);
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
if (gcm_ctx != NULL) {
CRYPTO_gcm128_init(gcm_ctx, aes_key, (block128_f)AES_encrypt);
}
if (out_block) {
*out_block = (block128_f) AES_encrypt;
}
return NULL;
}
@@ -422,7 +458,8 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
return 1;
}
if (key) {
gctx->ctr = aes_gcm_set_key(&gctx->ks.ks, &gctx->gcm, key, ctx->key_len);
gctx->ctr =
aes_ctr_set_key(&gctx->ks.ks, &gctx->gcm, NULL, key, ctx->key_len);
/* If we have an iv can set it directly, otherwise use saved IV. */
if (iv == NULL && gctx->iv_set) {
iv = gctx->iv;
@@ -445,13 +482,12 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
return 1;
}
static int aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
static void aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
EVP_AES_GCM_CTX *gctx = c->cipher_data;
OPENSSL_cleanse(&gctx->gcm, sizeof(gctx->gcm));
if (gctx->iv != c->iv) {
OPENSSL_free(gctx->iv);
}
return 1;
}
/* increment counter (64-bit int) by 1 */
@@ -951,15 +987,8 @@ static int aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
return 0;
}
if (aesni_capable()) {
aesni_set_encrypt_key(key, key_len * 8, &gcm_ctx->ks.ks);
CRYPTO_gcm128_init(&gcm_ctx->gcm, &gcm_ctx->ks.ks,
(block128_f)aesni_encrypt);
gcm_ctx->ctr = (ctr128_f)aesni_ctr32_encrypt_blocks;
} else {
gcm_ctx->ctr =
aes_gcm_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm, key, key_len);
}
gcm_ctx->ctr =
aes_ctr_set_key(&gcm_ctx->ks.ks, &gcm_ctx->gcm, NULL, key, key_len);
gcm_ctx->tag_len = tag_len;
ctx->aead_state = gcm_ctx;
@@ -1072,8 +1101,12 @@ static const EVP_AEAD aead_aes_128_gcm = {
12, /* nonce len */
EVP_AEAD_AES_GCM_TAG_LEN, /* overhead */
EVP_AEAD_AES_GCM_TAG_LEN, /* max tag length */
aead_aes_gcm_init, aead_aes_gcm_cleanup,
aead_aes_gcm_seal, aead_aes_gcm_open,
aead_aes_gcm_init,
NULL, /* init_with_direction */
aead_aes_gcm_cleanup,
aead_aes_gcm_seal,
aead_aes_gcm_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_gcm = {
@@ -1081,8 +1114,12 @@ static const EVP_AEAD aead_aes_256_gcm = {
12, /* nonce len */
EVP_AEAD_AES_GCM_TAG_LEN, /* overhead */
EVP_AEAD_AES_GCM_TAG_LEN, /* max tag length */
aead_aes_gcm_init, aead_aes_gcm_cleanup,
aead_aes_gcm_seal, aead_aes_gcm_open,
aead_aes_gcm_init,
NULL, /* init_with_direction */
aead_aes_gcm_cleanup,
aead_aes_gcm_seal,
aead_aes_gcm_open,
NULL, /* get_rc4_state */
};
const EVP_AEAD *EVP_aead_aes_128_gcm(void) { return &aead_aes_128_gcm; }
@@ -1286,7 +1323,7 @@ static int aead_aes_key_wrap_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
}
if (in_len < 24) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_gcm_open, CIPHER_R_BAD_DECRYPT);
OPENSSL_PUT_ERROR(CIPHER, aead_aes_key_wrap_open, CIPHER_R_BAD_DECRYPT);
return 0;
}
@@ -1323,7 +1360,7 @@ static int aead_aes_key_wrap_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
}
if (CRYPTO_memcmp(A, nonce, 8) != 0) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_gcm_open, CIPHER_R_BAD_DECRYPT);
OPENSSL_PUT_ERROR(CIPHER, aead_aes_key_wrap_open, CIPHER_R_BAD_DECRYPT);
return 0;
}
@@ -1336,8 +1373,12 @@ static const EVP_AEAD aead_aes_128_key_wrap = {
8, /* nonce len */
8, /* overhead */
8, /* max tag length */
aead_aes_key_wrap_init, aead_aes_key_wrap_cleanup,
aead_aes_key_wrap_seal, aead_aes_key_wrap_open,
aead_aes_key_wrap_init,
NULL, /* init_with_direction */
aead_aes_key_wrap_cleanup,
aead_aes_key_wrap_seal,
aead_aes_key_wrap_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_key_wrap = {
@@ -1345,14 +1386,295 @@ static const EVP_AEAD aead_aes_256_key_wrap = {
8, /* nonce len */
8, /* overhead */
8, /* max tag length */
aead_aes_key_wrap_init, aead_aes_key_wrap_cleanup,
aead_aes_key_wrap_seal, aead_aes_key_wrap_open,
aead_aes_key_wrap_init,
NULL, /* init_with_direction */
aead_aes_key_wrap_cleanup,
aead_aes_key_wrap_seal,
aead_aes_key_wrap_open,
NULL, /* get_rc4_state */
};
const EVP_AEAD *EVP_aead_aes_128_key_wrap(void) { return &aead_aes_128_key_wrap; }
const EVP_AEAD *EVP_aead_aes_256_key_wrap(void) { return &aead_aes_256_key_wrap; }
#define EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN SHA256_DIGEST_LENGTH
#define EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN 12
struct aead_aes_ctr_hmac_sha256_ctx {
union {
double align;
AES_KEY ks;
} ks;
ctr128_f ctr;
block128_f block;
SHA256_CTX inner_init_state;
SHA256_CTX outer_init_state;
uint8_t tag_len;
};
static void hmac_init(SHA256_CTX *out_inner, SHA256_CTX *out_outer,
const uint8_t hmac_key[32]) {
static const size_t hmac_key_len = 32;
uint8_t block[SHA256_CBLOCK];
memcpy(block, hmac_key, hmac_key_len);
memset(block + hmac_key_len, 0x36, sizeof(block) - hmac_key_len);
unsigned i;
for (i = 0; i < hmac_key_len; i++) {
block[i] ^= 0x36;
}
SHA256_Init(out_inner);
SHA256_Update(out_inner, block, sizeof(block));
memset(block + hmac_key_len, 0x5c, sizeof(block) - hmac_key_len);
for (i = 0; i < hmac_key_len; i++) {
block[i] ^= (0x36 ^ 0x5c);
}
SHA256_Init(out_outer);
SHA256_Update(out_outer, block, sizeof(block));
}
static int aead_aes_ctr_hmac_sha256_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx;
static const size_t hmac_key_len = 32;
if (key_len < hmac_key_len) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
CIPHER_R_BAD_KEY_LENGTH);
return 0; /* EVP_AEAD_CTX_init should catch this. */
}
const size_t aes_key_len = key_len - hmac_key_len;
if (aes_key_len != 16 && aes_key_len != 32) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
CIPHER_R_BAD_KEY_LENGTH);
return 0; /* EVP_AEAD_CTX_init should catch this. */
}
if (tag_len == EVP_AEAD_DEFAULT_TAG_LENGTH) {
tag_len = EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN;
}
if (tag_len > EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
CIPHER_R_TAG_TOO_LARGE);
return 0;
}
aes_ctx = OPENSSL_malloc(sizeof(struct aead_aes_ctr_hmac_sha256_ctx));
if (aes_ctx == NULL) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_init,
ERR_R_MALLOC_FAILURE);
return 0;
}
aes_ctx->ctr =
aes_ctr_set_key(&aes_ctx->ks.ks, NULL, &aes_ctx->block, key, aes_key_len);
aes_ctx->tag_len = tag_len;
hmac_init(&aes_ctx->inner_init_state, &aes_ctx->outer_init_state,
key + aes_key_len);
ctx->aead_state = aes_ctx;
return 1;
}
static void aead_aes_ctr_hmac_sha256_cleanup(EVP_AEAD_CTX *ctx) {
struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
OPENSSL_cleanse(aes_ctx, sizeof(struct aead_aes_ctr_hmac_sha256_ctx));
OPENSSL_free(aes_ctx);
}
static void hmac_update_uint64(SHA256_CTX *sha256, uint64_t value) {
unsigned i;
uint8_t bytes[8];
for (i = 0; i < sizeof(bytes); i++) {
bytes[i] = value & 0xff;
value >>= 8;
}
SHA256_Update(sha256, bytes, sizeof(bytes));
}
static void hmac_calculate(uint8_t out[SHA256_DIGEST_LENGTH],
const SHA256_CTX *inner_init_state,
const SHA256_CTX *outer_init_state,
const uint8_t *ad, size_t ad_len,
const uint8_t *nonce, const uint8_t *ciphertext,
size_t ciphertext_len) {
SHA256_CTX sha256;
memcpy(&sha256, inner_init_state, sizeof(sha256));
hmac_update_uint64(&sha256, ad_len);
hmac_update_uint64(&sha256, ciphertext_len);
SHA256_Update(&sha256, nonce, EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN);
SHA256_Update(&sha256, ad, ad_len);
/* Pad with zeros to the end of the SHA-256 block. */
const unsigned num_padding =
(SHA256_CBLOCK - ((sizeof(uint64_t)*2 +
EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN + ad_len) %
SHA256_CBLOCK)) %
SHA256_CBLOCK;
uint8_t padding[SHA256_CBLOCK];
memset(padding, 0, num_padding);
SHA256_Update(&sha256, padding, num_padding);
SHA256_Update(&sha256, ciphertext, ciphertext_len);
uint8_t inner_digest[SHA256_DIGEST_LENGTH];
SHA256_Final(inner_digest, &sha256);
memcpy(&sha256, outer_init_state, sizeof(sha256));
SHA256_Update(&sha256, inner_digest, sizeof(inner_digest));
SHA256_Final(out, &sha256);
}
static void aead_aes_ctr_hmac_sha256_crypt(
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx, uint8_t *out,
const uint8_t *in, size_t len, const uint8_t *nonce) {
/* Since the AEAD operation is one-shot, keeping a buffer of unused keystream
* bytes is pointless. However, |CRYPTO_ctr128_encrypt| requires it. */
uint8_t partial_block_buffer[AES_BLOCK_SIZE];
unsigned partial_block_offset = 0;
memset(partial_block_buffer, 0, sizeof(partial_block_buffer));
uint8_t counter[AES_BLOCK_SIZE];
memcpy(counter, nonce, EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN);
memset(counter + EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN, 0, 4);
if (aes_ctx->ctr) {
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &aes_ctx->ks.ks, counter,
partial_block_buffer, &partial_block_offset,
aes_ctx->ctr);
} else {
CRYPTO_ctr128_encrypt(in, out, len, &aes_ctx->ks.ks, counter,
partial_block_buffer, &partial_block_offset,
aes_ctx->block);
}
}
static int aead_aes_ctr_hmac_sha256_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
size_t *out_len, size_t max_out_len,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *in, size_t in_len,
const uint8_t *ad, size_t ad_len) {
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
const uint64_t in_len_64 = in_len;
if (in_len + aes_ctx->tag_len < in_len ||
/* This input is so large it would overflow the 32-bit block counter. */
in_len_64 >= (OPENSSL_U64(1) << 32) * AES_BLOCK_SIZE) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
CIPHER_R_TOO_LARGE);
return 0;
}
if (max_out_len < in_len + aes_ctx->tag_len) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
CIPHER_R_BUFFER_TOO_SMALL);
return 0;
}
if (nonce_len != EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_seal,
CIPHER_R_UNSUPPORTED_NONCE_SIZE);
return 0;
}
aead_aes_ctr_hmac_sha256_crypt(aes_ctx, out, in, in_len, nonce);
uint8_t hmac_result[SHA256_DIGEST_LENGTH];
hmac_calculate(hmac_result, &aes_ctx->inner_init_state,
&aes_ctx->outer_init_state, ad, ad_len, nonce, out, in_len);
memcpy(out + in_len, hmac_result, aes_ctx->tag_len);
*out_len = in_len + aes_ctx->tag_len;
return 1;
}
static int aead_aes_ctr_hmac_sha256_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
size_t *out_len, size_t max_out_len,
const uint8_t *nonce, size_t nonce_len,
const uint8_t *in, size_t in_len,
const uint8_t *ad, size_t ad_len) {
const struct aead_aes_ctr_hmac_sha256_ctx *aes_ctx = ctx->aead_state;
size_t plaintext_len;
if (in_len < aes_ctx->tag_len) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
CIPHER_R_BAD_DECRYPT);
return 0;
}
plaintext_len = in_len - aes_ctx->tag_len;
if (max_out_len < plaintext_len) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
CIPHER_R_BUFFER_TOO_SMALL);
return 0;
}
if (nonce_len != EVP_AEAD_AES_CTR_HMAC_SHA256_NONCE_LEN) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
CIPHER_R_UNSUPPORTED_NONCE_SIZE);
return 0;
}
uint8_t hmac_result[SHA256_DIGEST_LENGTH];
hmac_calculate(hmac_result, &aes_ctx->inner_init_state,
&aes_ctx->outer_init_state, ad, ad_len, nonce, in,
plaintext_len);
if (CRYPTO_memcmp(hmac_result, in + plaintext_len, aes_ctx->tag_len) != 0) {
OPENSSL_PUT_ERROR(CIPHER, aead_aes_ctr_hmac_sha256_open,
CIPHER_R_BAD_DECRYPT);
return 0;
}
aead_aes_ctr_hmac_sha256_crypt(aes_ctx, out, in, plaintext_len, nonce);
*out_len = plaintext_len;
return 1;
}
static const EVP_AEAD aead_aes_128_ctr_hmac_sha256 = {
16 /* AES key */ + 32 /* HMAC key */,
12, /* nonce length */
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* overhead */
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* max tag length */
aead_aes_ctr_hmac_sha256_init,
NULL /* init_with_direction */,
aead_aes_ctr_hmac_sha256_cleanup,
aead_aes_ctr_hmac_sha256_seal,
aead_aes_ctr_hmac_sha256_open,
};
static const EVP_AEAD aead_aes_256_ctr_hmac_sha256 = {
32 /* AES key */ + 32 /* HMAC key */,
12, /* nonce length */
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* overhead */
EVP_AEAD_AES_CTR_HMAC_SHA256_TAG_LEN, /* max tag length */
aead_aes_ctr_hmac_sha256_init,
NULL /* init_with_direction */,
aead_aes_ctr_hmac_sha256_cleanup,
aead_aes_ctr_hmac_sha256_seal,
aead_aes_ctr_hmac_sha256_open,
};
const EVP_AEAD *EVP_aead_aes_128_ctr_hmac_sha256(void) {
return &aead_aes_128_ctr_hmac_sha256;
}
const EVP_AEAD *EVP_aead_aes_256_ctr_hmac_sha256(void) {
return &aead_aes_256_ctr_hmac_sha256;
}
int EVP_has_aes_hardware(void) {
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
return aesni_capable() && crypto_gcm_clmul_enabled();
+6 -2
View File
@@ -209,8 +209,12 @@ static const EVP_AEAD aead_chacha20_poly1305 = {
CHACHA20_NONCE_LEN, /* nonce len */
POLY1305_TAG_LEN, /* overhead */
POLY1305_TAG_LEN, /* max tag length */
aead_chacha20_poly1305_init, aead_chacha20_poly1305_cleanup,
aead_chacha20_poly1305_seal, aead_chacha20_poly1305_open,
aead_chacha20_poly1305_init,
NULL, /* init_with_direction */
aead_chacha20_poly1305_cleanup,
aead_chacha20_poly1305_seal,
aead_chacha20_poly1305_open,
NULL, /* get_rc4_state */
};
const EVP_AEAD *EVP_aead_chacha20_poly1305(void) {
+4 -26
View File
@@ -61,8 +61,6 @@
#include "internal.h"
#define EVP_MAXCHUNK (1<<30)
typedef struct {
union {
double align;
@@ -83,18 +81,8 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
size_t in_len) {
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
while (in_len >= EVP_MAXCHUNK) {
DES_ncbc_encrypt(in, out, EVP_MAXCHUNK, &dat->ks.ks, (DES_cblock *)ctx->iv,
ctx->encrypt);
in_len -= EVP_MAXCHUNK;
in += EVP_MAXCHUNK;
out += EVP_MAXCHUNK;
}
if (in_len) {
DES_ncbc_encrypt(in, out, (long)in_len, &dat->ks.ks,
(DES_cblock *)ctx->iv, ctx->encrypt);
}
DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv,
ctx->encrypt);
return 1;
}
@@ -132,18 +120,8 @@ static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
const uint8_t *in, size_t in_len) {
DES_EDE_KEY *dat = (DES_EDE_KEY*) ctx->cipher_data;
while (in_len >= EVP_MAXCHUNK) {
DES_ede3_cbc_encrypt(in, out, EVP_MAXCHUNK, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
in_len -= EVP_MAXCHUNK;
in += EVP_MAXCHUNK;
out += EVP_MAXCHUNK;
}
if (in_len) {
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
}
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
return 1;
}
+13 -2
View File
@@ -372,13 +372,24 @@ static int aead_rc4_md5_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 1;
}
static int aead_rc4_md5_tls_get_rc4_state(const EVP_AEAD_CTX *ctx,
const RC4_KEY **out_key) {
struct aead_rc4_md5_tls_ctx *rc4_ctx = ctx->aead_state;
*out_key = &rc4_ctx->rc4;
return 1;
}
static const EVP_AEAD aead_rc4_md5_tls = {
16 + MD5_DIGEST_LENGTH, /* key len (RC4 + MD5) */
0, /* nonce len */
MD5_DIGEST_LENGTH, /* overhead */
MD5_DIGEST_LENGTH, /* max tag length */
aead_rc4_md5_tls_init, aead_rc4_md5_tls_cleanup,
aead_rc4_md5_tls_seal, aead_rc4_md5_tls_open,
aead_rc4_md5_tls_init,
NULL, /* init_with_direction */
aead_rc4_md5_tls_cleanup,
aead_rc4_md5_tls_seal,
aead_rc4_md5_tls_open,
aead_rc4_md5_tls_get_rc4_state,
};
const EVP_AEAD *EVP_aead_rc4_md5_tls(void) { return &aead_rc4_md5_tls; }
+54 -70
View File
@@ -30,17 +30,6 @@
typedef struct {
EVP_CIPHER_CTX cipher_ctx;
EVP_MD_CTX md_ctx;
/* enc_key is the portion of the key used for the stream or block cipher. It
* is retained separately to allow the EVP_CIPHER_CTX to be initialized once
* the direction is known. */
uint8_t enc_key[EVP_MAX_KEY_LENGTH];
uint8_t enc_key_len;
/* iv is the portion of the key used for the fixed IV. It is retained
* separately to allow the EVP_CIPHER_CTX to be initialized once the direction
* is known. */
uint8_t iv[EVP_MAX_IV_LENGTH];
uint8_t iv_len;
char initialized;
} AEAD_SSL3_CTX;
static int ssl3_mac(AEAD_SSL3_CTX *ssl3_ctx, uint8_t *out, unsigned *out_len,
@@ -87,15 +76,13 @@ static void aead_ssl3_cleanup(EVP_AEAD_CTX *ctx) {
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
EVP_CIPHER_CTX_cleanup(&ssl3_ctx->cipher_ctx);
EVP_MD_CTX_cleanup(&ssl3_ctx->md_ctx);
OPENSSL_cleanse(&ssl3_ctx->enc_key, sizeof(ssl3_ctx->enc_key));
OPENSSL_cleanse(&ssl3_ctx->iv, sizeof(ssl3_ctx->iv));
OPENSSL_free(ssl3_ctx);
ctx->aead_state = NULL;
}
static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
size_t tag_len, const EVP_CIPHER *cipher,
const EVP_MD *md) {
size_t tag_len, enum evp_aead_direction_t dir,
const EVP_CIPHER *cipher, const EVP_MD *md) {
if (tag_len != EVP_AEAD_DEFAULT_TAG_LENGTH &&
tag_len != EVP_MD_size(md)) {
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_init, CIPHER_R_UNSUPPORTED_TAG_SIZE);
@@ -109,11 +96,7 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
size_t mac_key_len = EVP_MD_size(md);
size_t enc_key_len = EVP_CIPHER_key_length(cipher);
size_t iv_len = EVP_CIPHER_iv_length(cipher);
assert(mac_key_len + enc_key_len + iv_len == key_len);
assert(mac_key_len < 256);
assert(enc_key_len < 256);
assert(iv_len < 256);
assert(mac_key_len + enc_key_len + EVP_CIPHER_iv_length(cipher) == key_len);
/* Although EVP_rc4() is a variable-length cipher, the default key size is
* correct for SSL3. */
@@ -124,14 +107,11 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
}
EVP_CIPHER_CTX_init(&ssl3_ctx->cipher_ctx);
EVP_MD_CTX_init(&ssl3_ctx->md_ctx);
memcpy(ssl3_ctx->enc_key, &key[mac_key_len], enc_key_len);
ssl3_ctx->enc_key_len = (uint8_t)enc_key_len;
memcpy(ssl3_ctx->iv, &key[mac_key_len + enc_key_len], iv_len);
ssl3_ctx->iv_len = (uint8_t)iv_len;
ssl3_ctx->initialized = 0;
ctx->aead_state = ssl3_ctx;
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, cipher, NULL, NULL, NULL, 0) ||
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, cipher, NULL, &key[mac_key_len],
&key[mac_key_len + enc_key_len],
dir == evp_aead_seal) ||
!EVP_DigestInit_ex(&ssl3_ctx->md_ctx, md, NULL) ||
!EVP_DigestUpdate(&ssl3_ctx->md_ctx, key, mac_key_len)) {
aead_ssl3_cleanup(ctx);
@@ -142,31 +122,6 @@ static int aead_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
return 1;
}
/* aead_ssl3_ensure_cipher_init initializes |ssl3_ctx| for encryption (or
* decryption, if |encrypt| is zero). If it has already been initialized, it
* ensures the direction matches and fails otherwise. It returns one on success
* and zero on failure.
*
* Note that, unlike normal AEADs, legacy SSL3 AEADs may not be used concurrently
* due to this (and bulk-cipher-internal) statefulness. */
static int aead_ssl3_ensure_cipher_init(AEAD_SSL3_CTX *ssl3_ctx, int encrypt) {
if (!ssl3_ctx->initialized) {
/* Finish initializing the EVP_CIPHER_CTX now that the direction is
* known. */
if (!EVP_CipherInit_ex(&ssl3_ctx->cipher_ctx, NULL, NULL, ssl3_ctx->enc_key,
ssl3_ctx->iv, encrypt)) {
return 0;
}
ssl3_ctx->initialized = 1;
} else if (ssl3_ctx->cipher_ctx.encrypt != encrypt) {
/* Unlike a normal AEAD, using an SSL3 AEAD once freezes the direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_ensure_cipher_init,
CIPHER_R_INVALID_OPERATION);
return 0;
}
return 1;
}
static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
size_t *out_len, size_t max_out_len,
const uint8_t *nonce, size_t nonce_len,
@@ -175,6 +130,12 @@ static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
size_t total = 0;
if (!ssl3_ctx->cipher_ctx.encrypt) {
/* Unlike a normal AEAD, an SSL3 AEAD may only be used in one direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_seal, CIPHER_R_INVALID_OPERATION);
return 0;
}
if (in_len + EVP_AEAD_max_overhead(ctx->aead) < in_len ||
in_len > INT_MAX) {
/* EVP_CIPHER takes int as input. */
@@ -197,10 +158,6 @@ static int aead_ssl3_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 0;
}
if (!aead_ssl3_ensure_cipher_init(ssl3_ctx, 1)) {
return 0;
}
/* Compute the MAC. This must be first in case the operation is being done
* in-place. */
uint8_t mac[EVP_MAX_MD_SIZE];
@@ -257,6 +214,12 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
const uint8_t *ad, size_t ad_len) {
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
if (ssl3_ctx->cipher_ctx.encrypt) {
/* Unlike a normal AEAD, an SSL3 AEAD may only be used in one direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_open, CIPHER_R_INVALID_OPERATION);
return 0;
}
size_t mac_len = EVP_MD_CTX_size(&ssl3_ctx->md_ctx);
if (in_len < mac_len) {
OPENSSL_PUT_ERROR(CIPHER, aead_ssl3_open, CIPHER_R_BAD_DECRYPT);
@@ -286,10 +249,6 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 0;
}
if (!aead_ssl3_ensure_cipher_init(ssl3_ctx, 0)) {
return 0;
}
/* Decrypt to get the plaintext + MAC + padding. */
size_t total = 0;
int len;
@@ -337,31 +296,46 @@ static int aead_ssl3_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 1;
}
static int aead_ssl3_get_rc4_state(const EVP_AEAD_CTX *ctx, const RC4_KEY **out_key) {
AEAD_SSL3_CTX *ssl3_ctx = (AEAD_SSL3_CTX *)ctx->aead_state;
if (EVP_CIPHER_CTX_cipher(&ssl3_ctx->cipher_ctx) != EVP_rc4()) {
return 0;
}
*out_key = (RC4_KEY*) ssl3_ctx->cipher_ctx.cipher_data;
return 1;
}
static int aead_rc4_md5_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_md5());
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_md5());
}
static int aead_rc4_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_sha1());
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_sha1());
}
static int aead_aes_128_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
EVP_sha1());
}
static int aead_aes_256_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
EVP_sha1());
}
static int aead_des_ede3_cbc_sha1_ssl3_init(EVP_AEAD_CTX *ctx,
const uint8_t *key, size_t key_len,
size_t tag_len) {
return aead_ssl3_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
const uint8_t *key, size_t key_len,
size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_ssl3_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
EVP_sha1());
}
@@ -370,10 +344,12 @@ static const EVP_AEAD aead_rc4_md5_ssl3 = {
0, /* nonce len */
MD5_DIGEST_LENGTH, /* overhead */
MD5_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_rc4_md5_ssl3_init,
aead_ssl3_cleanup,
aead_ssl3_seal,
aead_ssl3_open,
aead_ssl3_get_rc4_state,
};
static const EVP_AEAD aead_rc4_sha1_ssl3 = {
@@ -381,10 +357,12 @@ static const EVP_AEAD aead_rc4_sha1_ssl3 = {
0, /* nonce len */
SHA_DIGEST_LENGTH, /* overhead */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_rc4_sha1_ssl3_init,
aead_ssl3_cleanup,
aead_ssl3_seal,
aead_ssl3_open,
aead_ssl3_get_rc4_state,
};
static const EVP_AEAD aead_aes_128_cbc_sha1_ssl3 = {
@@ -392,10 +370,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_ssl3 = {
0, /* nonce len */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_128_cbc_sha1_ssl3_init,
aead_ssl3_cleanup,
aead_ssl3_seal,
aead_ssl3_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_cbc_sha1_ssl3 = {
@@ -403,10 +383,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_ssl3 = {
0, /* nonce len */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_256_cbc_sha1_ssl3_init,
aead_ssl3_cleanup,
aead_ssl3_seal,
aead_ssl3_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_des_ede3_cbc_sha1_ssl3 = {
@@ -414,10 +396,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_ssl3 = {
0, /* nonce len */
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_des_ede3_cbc_sha1_ssl3_init,
aead_ssl3_cleanup,
aead_ssl3_seal,
aead_ssl3_open,
NULL, /* get_rc4_state */
};
const EVP_AEAD *EVP_aead_rc4_md5_ssl3(void) { return &aead_rc4_md5_ssl3; }
+90 -89
View File
@@ -22,6 +22,7 @@
#include <openssl/hmac.h>
#include <openssl/mem.h>
#include <openssl/sha.h>
#include <openssl/type_check.h>
#include "../crypto/internal.h"
#include "internal.h"
@@ -34,37 +35,26 @@ typedef struct {
* separately for the constant-time CBC code. */
uint8_t mac_key[EVP_MAX_MD_SIZE];
uint8_t mac_key_len;
/* enc_key is the portion of the key used for the stream or block
* cipher. It is retained separately to allow the EVP_CIPHER_CTX to be
* initialized once the direction is known. */
uint8_t enc_key[EVP_MAX_KEY_LENGTH];
uint8_t enc_key_len;
/* iv is the portion of the key used for the fixed IV. It is retained
* separately to allow the EVP_CIPHER_CTX to be initialized once the direction
* is known. */
uint8_t iv[EVP_MAX_IV_LENGTH];
uint8_t iv_len;
/* implicit_iv is one iff this is a pre-TLS-1.1 CBC cipher without an explicit
* IV. */
char implicit_iv;
char initialized;
} AEAD_TLS_CTX;
OPENSSL_COMPILE_ASSERT(EVP_MAX_MD_SIZE < 256, mac_key_len_fits_in_uint8_t);
static void aead_tls_cleanup(EVP_AEAD_CTX *ctx) {
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
EVP_CIPHER_CTX_cleanup(&tls_ctx->cipher_ctx);
HMAC_CTX_cleanup(&tls_ctx->hmac_ctx);
OPENSSL_cleanse(&tls_ctx->mac_key, sizeof(tls_ctx->mac_key));
OPENSSL_cleanse(&tls_ctx->enc_key, sizeof(tls_ctx->enc_key));
OPENSSL_cleanse(&tls_ctx->iv, sizeof(tls_ctx->iv));
OPENSSL_free(tls_ctx);
ctx->aead_state = NULL;
}
static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
size_t tag_len, const EVP_CIPHER *cipher,
const EVP_MD *md, char implicit_iv) {
size_t tag_len, enum evp_aead_direction_t dir,
const EVP_CIPHER *cipher, const EVP_MD *md,
char implicit_iv) {
if (tag_len != EVP_AEAD_DEFAULT_TAG_LENGTH &&
tag_len != EVP_MD_size(md)) {
OPENSSL_PUT_ERROR(CIPHER, aead_tls_init, CIPHER_R_UNSUPPORTED_TAG_SIZE);
@@ -78,11 +68,8 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
size_t mac_key_len = EVP_MD_size(md);
size_t enc_key_len = EVP_CIPHER_key_length(cipher);
size_t iv_len = implicit_iv ? EVP_CIPHER_iv_length(cipher) : 0;
assert(mac_key_len + enc_key_len + iv_len == key_len);
assert(mac_key_len < 256);
assert(enc_key_len < 256);
assert(iv_len < 256);
assert(mac_key_len + enc_key_len +
(implicit_iv ? EVP_CIPHER_iv_length(cipher) : 0) == key_len);
/* Although EVP_rc4() is a variable-length cipher, the default key size is
* correct for TLS. */
@@ -93,17 +80,15 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
}
EVP_CIPHER_CTX_init(&tls_ctx->cipher_ctx);
HMAC_CTX_init(&tls_ctx->hmac_ctx);
assert(mac_key_len <= EVP_MAX_MD_SIZE);
memcpy(tls_ctx->mac_key, key, mac_key_len);
tls_ctx->mac_key_len = (uint8_t)mac_key_len;
memcpy(tls_ctx->enc_key, &key[mac_key_len], enc_key_len);
tls_ctx->enc_key_len = (uint8_t)enc_key_len;
memcpy(tls_ctx->iv, &key[mac_key_len + enc_key_len], iv_len);
tls_ctx->iv_len = (uint8_t)iv_len;
tls_ctx->implicit_iv = implicit_iv;
tls_ctx->initialized = 0;
ctx->aead_state = tls_ctx;
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, cipher, NULL, NULL, NULL, 0) ||
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, cipher, NULL, &key[mac_key_len],
implicit_iv ? &key[mac_key_len + enc_key_len] : NULL,
dir == evp_aead_seal) ||
!HMAC_Init_ex(&tls_ctx->hmac_ctx, key, mac_key_len, md, NULL)) {
aead_tls_cleanup(ctx);
return 0;
@@ -113,32 +98,6 @@ static int aead_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len,
return 1;
}
/* aead_tls_ensure_cipher_init initializes |tls_ctx| for encryption (or
* decryption, if |encrypt| is zero). If it has already been initialized, it
* ensures the direction matches and fails otherwise. It returns one on success
* and zero on failure.
*
* Note that, unlike normal AEADs, legacy TLS AEADs may not be used concurrently
* due to this (and bulk-cipher-internal) statefulness. */
static int aead_tls_ensure_cipher_init(AEAD_TLS_CTX *tls_ctx, int encrypt) {
if (!tls_ctx->initialized) {
/* Finish initializing the EVP_CIPHER_CTX now that the direction is
* known. */
if (!EVP_CipherInit_ex(&tls_ctx->cipher_ctx, NULL, NULL, tls_ctx->enc_key,
tls_ctx->implicit_iv ? tls_ctx->iv : NULL,
encrypt)) {
return 0;
}
tls_ctx->initialized = 1;
} else if (tls_ctx->cipher_ctx.encrypt != encrypt) {
/* Unlike a normal AEAD, using a TLS AEAD once freezes the direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_tls_ensure_cipher_init,
CIPHER_R_INVALID_OPERATION);
return 0;
}
return 1;
}
static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
size_t *out_len, size_t max_out_len,
const uint8_t *nonce, size_t nonce_len,
@@ -147,6 +106,13 @@ static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
size_t total = 0;
if (!tls_ctx->cipher_ctx.encrypt) {
/* Unlike a normal AEAD, a TLS AEAD may only be used in one direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_tls_seal, CIPHER_R_INVALID_OPERATION);
return 0;
}
if (in_len + EVP_AEAD_max_overhead(ctx->aead) < in_len ||
in_len > INT_MAX) {
/* EVP_CIPHER takes int as input. */
@@ -169,10 +135,6 @@ static int aead_tls_seal(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 0;
}
if (!aead_tls_ensure_cipher_init(tls_ctx, 1)) {
return 0;
}
/* To allow for CBC mode which changes cipher length, |ad| doesn't include the
* length for legacy ciphers. */
uint8_t ad_extra[2];
@@ -249,6 +211,13 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
const uint8_t *ad, size_t ad_len) {
AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)ctx->aead_state;
if (tls_ctx->cipher_ctx.encrypt) {
/* Unlike a normal AEAD, a TLS AEAD may only be used in one direction. */
OPENSSL_PUT_ERROR(CIPHER, aead_tls_open, CIPHER_R_INVALID_OPERATION);
return 0;
}
if (in_len < HMAC_size(&tls_ctx->hmac_ctx)) {
OPENSSL_PUT_ERROR(CIPHER, aead_tls_open, CIPHER_R_BAD_DECRYPT);
return 0;
@@ -277,10 +246,6 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
return 0;
}
if (!aead_tls_ensure_cipher_init(tls_ctx, 0)) {
return 0;
}
/* Configure the explicit IV. */
if (EVP_CIPHER_CTX_mode(&tls_ctx->cipher_ctx) == EVP_CIPH_CBC_MODE &&
!tls_ctx->implicit_iv &&
@@ -394,83 +359,101 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
}
static int aead_rc4_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_rc4(), EVP_sha1(), 0);
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_rc4(), EVP_sha1(),
0);
}
static int aead_aes_128_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
EVP_sha1(), 0);
}
static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
const uint8_t *key,
size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
EVP_sha1(), 1);
}
static int aead_aes_128_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
const uint8_t *key, size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_128_cbc(),
size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
EVP_sha256(), 0);
}
static int aead_aes_256_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
size_t key_len, size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
EVP_sha1(), 0);
}
static int aead_aes_256_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
const uint8_t *key,
size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
static int aead_aes_256_cbc_sha1_tls_implicit_iv_init(
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
EVP_sha1(), 1);
}
static int aead_aes_256_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
const uint8_t *key, size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
EVP_sha256(), 0);
}
static int aead_aes_256_cbc_sha384_tls_init(EVP_AEAD_CTX *ctx,
const uint8_t *key, size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_aes_256_cbc(),
size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
EVP_sha384(), 0);
}
static int aead_des_ede3_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx,
const uint8_t *key, size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
EVP_sha1(), 0);
}
static int aead_des_ede3_cbc_sha1_tls_implicit_iv_init(EVP_AEAD_CTX *ctx,
const uint8_t *key,
size_t key_len,
size_t tag_len) {
return aead_tls_init(ctx, key, key_len, tag_len, EVP_des_ede3_cbc(),
static int aead_des_ede3_cbc_sha1_tls_implicit_iv_init(
EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir) {
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_des_ede3_cbc(),
EVP_sha1(), 1);
}
static int aead_rc4_sha1_tls_get_rc4_state(const EVP_AEAD_CTX *ctx,
const RC4_KEY **out_key) {
const AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX*) ctx->aead_state;
if (EVP_CIPHER_CTX_cipher(&tls_ctx->cipher_ctx) != EVP_rc4()) {
return 0;
}
*out_key = (const RC4_KEY*) tls_ctx->cipher_ctx.cipher_data;
return 1;
}
static const EVP_AEAD aead_rc4_sha1_tls = {
SHA_DIGEST_LENGTH + 16, /* key len (SHA1 + RC4) */
0, /* nonce len */
SHA_DIGEST_LENGTH, /* overhead */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_rc4_sha1_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
aead_rc4_sha1_tls_get_rc4_state, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_128_cbc_sha1_tls = {
@@ -478,10 +461,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls = {
16, /* nonce len (IV) */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_128_cbc_sha1_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
@@ -489,10 +474,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
0, /* nonce len */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_128_cbc_sha1_tls_implicit_iv_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
@@ -500,10 +487,12 @@ static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
16, /* nonce len (IV) */
16 + SHA256_DIGEST_LENGTH, /* overhead (padding + SHA256) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_128_cbc_sha256_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
@@ -511,10 +500,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
16, /* nonce len (IV) */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_256_cbc_sha1_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_cbc_sha1_tls_implicit_iv = {
@@ -522,10 +513,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_tls_implicit_iv = {
0, /* nonce len */
16 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_256_cbc_sha1_tls_implicit_iv_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_cbc_sha256_tls = {
@@ -533,10 +526,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha256_tls = {
16, /* nonce len (IV) */
16 + SHA256_DIGEST_LENGTH, /* overhead (padding + SHA256) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_256_cbc_sha256_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_aes_256_cbc_sha384_tls = {
@@ -544,10 +539,12 @@ static const EVP_AEAD aead_aes_256_cbc_sha384_tls = {
16, /* nonce len (IV) */
16 + SHA384_DIGEST_LENGTH, /* overhead (padding + SHA384) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_aes_256_cbc_sha384_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_des_ede3_cbc_sha1_tls = {
@@ -555,10 +552,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_tls = {
8, /* nonce len (IV) */
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_des_ede3_cbc_sha1_tls_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
static const EVP_AEAD aead_des_ede3_cbc_sha1_tls_implicit_iv = {
@@ -566,10 +565,12 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_tls_implicit_iv = {
0, /* nonce len */
8 + SHA_DIGEST_LENGTH, /* overhead (padding + SHA1) */
SHA_DIGEST_LENGTH, /* max tag length */
NULL, /* init */
aead_des_ede3_cbc_sha1_tls_implicit_iv_init,
aead_tls_cleanup,
aead_tls_seal,
aead_tls_open,
NULL, /* get_rc4_state */
};
const EVP_AEAD *EVP_aead_rc4_sha1_tls(void) { return &aead_rc4_sha1_tls; }
+8 -1
View File
@@ -59,6 +59,7 @@
#include <openssl/base.h>
#include <openssl/aead.h>
#include <openssl/asn1t.h>
#if defined(__cplusplus)
@@ -97,7 +98,7 @@ struct evp_cipher_st {
int (*cipher)(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
size_t inl);
int (*cleanup)(EVP_CIPHER_CTX *);
void (*cleanup)(EVP_CIPHER_CTX *);
int (*ctrl)(EVP_CIPHER_CTX *, int type, int arg, void *ptr);
};
@@ -117,6 +118,9 @@ struct evp_aead_st {
int (*init)(struct evp_aead_ctx_st *, const uint8_t *key,
size_t key_len, size_t tag_len);
int (*init_with_direction)(struct evp_aead_ctx_st *, const uint8_t *key,
size_t key_len, size_t tag_len,
enum evp_aead_direction_t dir);
void (*cleanup)(struct evp_aead_ctx_st *);
int (*seal)(const struct evp_aead_ctx_st *ctx, uint8_t *out,
@@ -128,6 +132,9 @@ struct evp_aead_st {
size_t *out_len, size_t max_out_len, const uint8_t *nonce,
size_t nonce_len, const uint8_t *in, size_t in_len,
const uint8_t *ad, size_t ad_len);
int (*get_rc4_state)(const struct evp_aead_ctx_st *ctx,
const RC4_KEY **out_key);
};
@@ -0,0 +1,336 @@
KEY: 067b841a2540cb467b75f2188f5da4b5aeb7e0e44582a2b668b5b1ff39e21c4e65745470fb1be1aa909c62fabcf0e6ac
NONCE: 10e0ecb00da5345127407150
IN:
AD:
CT:
TAG: a82a891565e466957ad5a499d45b579d31acaf582f54d518f8f9c128936dac4c
KEY: c9d9ef2c808c3f8b22f659c12147104b08cec2390a84f0c4b887ca4c247c8c9dd45e72f48b30b67a8545750387232344
NONCE: 58bddf96158a3a588bf3ec05
IN:
AD: 5d
CT:
TAG: 3580c1601d1c9a5b1595d3dee35b0cd9e1b115d8b0abee557b2c207b8d0df5ee
KEY: f755dc6786e21f39b595389a51d36673e1ffb94ffc066c03873eb31839be6fa319fd31c8bea29f03ff28831861e60b6e
NONCE: bd6c80797f1f4c563b06fd3b
IN:
AD: 78d88005136e312639572343a2d0daf7483d8235291ee3ac002469456b075243dc03380c387030d546c2b1
CT:
TAG: dede80d810fc449a769c79a5ecd2c0d68e9e0fae567781e623ab2098c88d8a86
KEY: 43a0a28fef8b89b8fb0f76de01d802935ad561e27ca9c9fa629347be676a6af758501b6a652f369045da5fef751b56bb
NONCE: 0f6472f1e589c16ca5ad45b2
IN:
AD: 78e4eafccfc87631f0314c442ba4c07bca36f996a5b3408f9e445d6009a87ded16b33a4af9537a4619cab70d
CT:
TAG: 11fa62dd8374aabe728ebf7e9aa1c02cf8f2dbc29f9aaf1940313f0b7c3e0301
KEY: acf8e5f1bd64e6289370650b5b3fd773320025c8b229fd335d9461768cd0a17b4bcc946919932efdc9fc84a7f50768bf
NONCE: 1aecfc90d28bcdcc5a8e3578
IN:
AD: 6daedbdc69133b56f6a8f098f9f70cdb7e129e51115df385a6d86204a53412cd999cf2e69f45e168efed4742b6
CT:
TAG: fbe0511ba0ec5709def9966a9b05facf171cddd81ee2cd56e7afc867af465f31
KEY: 2773c92e6cddc9a5e5dcaf3893080fd2153f009d807df0b175c76615645f2087539e299d8411b27badb749a9845c5e29
NONCE: 6d04ed129299651aec0465f8
IN:
AD: 44219577e361a7a4681172d120a2d653a53ec74bc487ccde4954835943bca413d55c65dc665310148654d8c1e2e6bc2f06ec344473120ad1f95739b993a57f9ec0b3299cc088f385894fff876fc2ce8ce6b77ca253f177ba615101e84e17ad0e60704cff195dcd50eb48c77de409797e0b1c8c4c5b9215a4a0399954a008267b
CT:
TAG: 6ab61ac4493e58e48d071d994a000f1c1f498d22f83c8d2af56b03c155afc57e
KEY: 23189bf23bc4b734410d1c7ae321c42e144a25347a8029bb925e3d8ac1b92f4eb97227c1dece86ae9dea7d127eb33f9b
NONCE: 30681944cd5d78f46d36ed8a
IN: 59
AD:
CT: 92
TAG: 986aa8438da3cf4a98f478f90d24908c6a4e848f299873e649b256f5499d89d9
KEY: 463d1148325c5f57af670877068a78203571b8b19f40e9f0373156b7448ab315df86c77d7c85ba6e54b9bc329399f687
NONCE: cc9d015a4b5a888b36b14d05
IN: 28
AD: 6a
CT: 05
TAG: f66e8dc794b142944fa46d5c04a3e3fe00291668374846d763f2beeffd4ca4a0
KEY: 937eaab44e7c7d2cd5bbb053c12e6255e0aaa42cbe7d83025b7a2887eff8f098d019c80af849b0ed7da54a5ba5b39200
NONCE: 2b160d24df579836e1572ea2
IN: 9a
AD: 35841a33ba3a6ed3d89a1f76d06c61613d09834847e5a41f8616748e30c14335e5baa43d49fceaf85aeb22
CT: 80
TAG: 5e5799c147be0329dbcabf7ecdba6ac595ebc2d06b9d757426fbb31e8b39f62a
KEY: 68a746f382fcc11c02af7b352b9d710c137a9f59bc5886dc374ca88cdc01b86fe5678fde16cfa846846539f67a429276
NONCE: b94346c033ac1a3d709c4f09
IN: ad
AD: ad61c9168debf9974e19759088944e888346aff99f3e2e4522549c8ae332a0f41922972fb7c1d5ff24e7ae4b
CT: 46
TAG: 62ae92ff64710a9f260da2562e246356e9d749c3584fb9f40d9572307ccbbd31
KEY: 6622579d1d6350fd5dff432b69d172cc51f99bdaff50b0a1c0f4cda8d5904581ba8657ba61c6936407243d7fb64b00da
NONCE: a880caa7157a13540d2b724f
IN: 2a
AD: 95a23eafcff892deecaf093109d30290d819851ad5c91061510e54baa2b039b114c815da20f0e3ba2ba4875bdd
CT: ce
TAG: 33f09666f9fd1d92f137d9f3f7092b47b2bd71a7e3139dcd19a803a6b17f2a3a
KEY: 91ce9dd87c7d11d2c4da41863b6851c40fba786a612e0fbf0d1956a71286dfc61fa10bf7d148cecd72b6ceeb82b68d3f
NONCE: a50dc3d8fd63d3076cc70ff6
IN: da
AD: 9ce8e1a777c159ec775abbd67d85e84f3550c3296e848dec18b61bbd713a98a033805bfe6e2f2a011dd7fd754708e524168142aeee579cae19c7eab78fa7c42fa335f0c725baf556160beef9e4afd1050a2c8813be6bd14cc6982116d0229d53e9b4de923abf6ba99bdffe1d5f21748ae74caddb077d9f7488b394436222beca
CT: 2b
TAG: 1541cd745bc0259dd72a212474f5c7b8c121dd0289d674e5ba8d56a220d1f1d0
KEY: 1ad577d3b47e3fff8528e336a43a7ffef72f811e05b5c69ccfe777b10f29061e289178e394a1c87ba483c7f98ea5431d
NONCE: 1fcaa4757a9e48ed2cb3be62
IN: 46d30dac550103006c292a9ac05d31
AD:
CT: 37616eba30c55595fa0ad5d50f91ca
TAG: 5c3ac4010f75adf90f81e775b07ab939e7551a9b8e0486ba33766728ed498245
KEY: 6df310dc1847b42c68e50b03d154b73d7f3823354b32759c5369bce1a1b4cd63ccdb911c2dc792acf84b8b8f3fdfb89d
NONCE: 92e6759a31dd556ff9124d73
IN: 6daba76658db642209e276ff7c8d46
AD: 32
CT: ce1814c03037078b6be3252460af48
TAG: 46e61913f2a1ff6e77faade9a7cd37a82eff3ebec4276fbddff9266b9c9bd873
KEY: f848c2300995f5c98dcd0db24574d7c61459ca64c084421c6ad156e80e398904417ee745245ddae91be20fb07e66bdb6
NONCE: 3b177e11063445717f417d14
IN: bbf225131c821a6a60817cc65bf699
AD: 4c5ab4fdbe0018344629349feed5d8c3ae0c5b64f2b093576a2aaa1225e7a50eca01a9962c9b4f8fc5c12a
CT: 1538957e78f3ab0fed77906153d715
TAG: 2c7760d47407ad7b0d5b85fa4967eaa7b6c0bb6eb16619adde7a191abfdf3da3
KEY: d406cac07630ce2c071732a0ec95f55123486d2677465768dc7db13f90902cf172f92e19f57f5cf7c68cd7bde7ee4b4b
NONCE: 766aede0120b634a4be6fa12
IN: 3804d40090a38d4c97a5fff631068c
AD: 7707b7d0f266284e84c2ecdd5a18832650c3e27d66697616c9e9bb2f8a09a3295de0119582ca3614b9608548
CT: 91e96462a5dfbe8b7af201158a36dc
TAG: 56623e5813070a0e2f5184aed83b9863301ca02e3108f7afc478d48305e397f8
KEY: 42bb22a317ed9f9df8119746e9a1257217e5b0144051ca56f39587021d969bc0acc02795f3bd201031e8c05af08ad079
NONCE: 0a9f6bace71a1ab21f4917df
IN: 013f7b8c75307158f4f300450e7a78
AD: cd95a649ae215fe73442a6991e157232cbcabecff6042b87d41557e35b97606d606c3ded54f5d3db7aa2773f67
CT: e588dbcecbdb7667dccf7fe34f8387
TAG: b04461748109ed9068c7e9c0446528ef09b01613c3b3aa1ffeed6685ebb550f5
KEY: e1cfcbaba3a04b5108ce2a87099a6aae936ee38acd92b7e6b7df0e3bcb9ad18fc579b5d470ef3e04c23459f509852458
NONCE: 112dd267174bcd81e6fbd924
IN: 288a1e44b406aebec7b418674f81e7
AD: 7809d8011c5a963df14fb8981e874119c60b7a9d897d13a05651759db5835deffdd991fbf98b9aa71c79e48bd701b228ba248b6bed874b02da7fcf28a04c38b81c0ff628846015258af30dbf28ea4f3283f664f888fca545f5fc57dccc4ad1dd476c52fba341182ecf783706c5c458bf0ee5ec83454afba78eb8b5ca17af88ec
CT: 80f4e1012d76f6180ca00fd32c8fec
TAG: 6de00bf2fd3c88ab34ca9390f7e559875e43e0f938303816a3a75a35729bc453
KEY: 84172547d8608bd9e788a7bb60df2982963716e45f8e63f0c5033327d85c920c5e3776e314246b1694b739c39abfa29f
NONCE: a3f1643bb504b7ce9e5b43c2
IN: 7e76323eb13e64da9b240a57c95c855b
AD:
CT: 966487c18f025d67b42a04c30d3ff4c3
TAG: 8bb03d893f0ce8ea4a6a47245bc7f20c72acf8caa466edd01365d0f74c929463
KEY: 02dee8f2e63b37fe3cbae9101fed0946e05e5090510bef3324a82e3f27456a45ab1b6cdeddb1fe515ad07aefeee6ccbc
NONCE: 64723d21365d62926d5c2262
IN: 4f1f132c50a01ad48882ce88655b33f7
AD: d8
CT: b102082e14cd9ecc0895f7a6f08ab522
TAG: 2c09651c1a51cb8a375746236fe258a36e725936ccedbc4dfafee6c3084a4716
KEY: 5db57cf6301bab815d38879b35c9db72fd40ac576d259ad5074d0828364050554e9fc08335b5f2bf066b09e50fbe6ba4
NONCE: 36e5340d844de213c312177a
IN: 41a6e910b14388740ea351eb1df980c9
AD: 8316a6b9b155b2de5e724f7593ecdcee442eaef7b9ad204eda4744a5e648c2dd84f48ee81397e485953465
CT: ee21d4d47042415ca27d2ecb11b13d79
TAG: 5015da5a3339389d39d0fcafb56ef4005b342e69ba47930e84408d33aadf5f2a
KEY: a493dd6de6fd6584599096442dd9345f6f2d8fc2d426c78eee2b992b4071aba4ce463f3ca293c84b2faf3e8644b6ec25
NONCE: 4f9be6f788ee960adc650d86
IN: 4de6e244251091cf13762d20685e9085
AD: d15da312b7522c18384acdbf6348b5e105557f1790a6a203a65acd73397524681666743f3145048775ad84e3
CT: bb1296457daa39d889c8f986938d6a39
TAG: b93548cea90c34d03d6f5683ae2cc78814531b803d42cfe57623fd4bdc8f084c
KEY: 8cc59ebe2c7375a70915c48d2978a1f720bc0aa2775ce9189ae7b3d5dda9a81e56cde0e0a29939599409b71f0b65f346
NONCE: b0ab041f37ea1e594f1eddb3
IN: cd0aeaf6806cb99e6bc1c8c5d830de8c
AD: 8f4b5a9609df757826dbe7e51bb6a2c6f45f601263cf668836193513cf008ab6b36a7d5447039f1268821ec37e
CT: 5d5375b9d9cff6d0c1dbd14221509a0d
TAG: d8850bbc838e068b817c24d018f8f1e1cb8aac0a68392a700f48099f81b6c37c
KEY: f3e9c507478d3f99dbf3e2421e45929b096ab3f3d4aa4ef9c338c5a1a2425c9936b7df602502d33cbafcf781350da77e
NONCE: d4872a30c9d1fa9001a25afe
IN: 25e05ea69a956b12a9be4ef03ae9d30c
AD: 8b346c20e7c64b805d9c8d325829201753069c60b3f221f31474f55cb20315373ccd7c2a8f215e9efc407ae91b05d8b6d693a3780fdd65d7715cdded86c3d6204055812f3fce897f829d1df9ffaaf48885291701ac1765090c383162dd13d6bac88baa0cb2d748363bbb79843a1594ec6d8778854a63b7c9ffeb6d1fb17e90f1
CT: 61325c7e0d29e9ad50b9c0fec02d7ef4
TAG: 4b2d0caece46ce2496445883c03234e900189c22b54390b399d78ee4ebfbb7d4
KEY: 3d9b651e65e9239c9e33aafb091b348161ab797901fd0468aedd014e4d5683c8f3f54f20ea6bb07bb25dd258df7bcd5e
NONCE: 32bcf856a14437114e7814cc
IN: 08a667c2923f87a7db6502478d32280bdc
AD:
CT: 5e8e02cc91c732356bb9f1fc599426a379
TAG: 5449e878d558beff4bc7dfbb5f0195444705cfb259773b4faec524fbaca37ea0
KEY: 2124cedb5f3f2558f8b9a2304a29c0df6102333cb4aa10625aa82cd76ab645c73f3b7cbf7c96cacdcb9e0b738e40c042
NONCE: 7ae419446a3a105beb2fbcc5
IN: a305dc4a2e50cc8e7a65a4b10b73849636
AD: 70
CT: fcaea620f7e9ed1337214c4b432d9869d2
TAG: bfc739c8504a4d9033ab1915f46c1bf65c5382fe9ed1c134026ba32c63ca131e
KEY: b027feb1aced8fb3af27a9fd7f531c30991ec1abd9f230a3e5d6ee9fc6a77747013f8e14dcdbd07b0083d0ce23dfa711
NONCE: a30a6520f933ff5265e6e305
IN: a705f842d542cb6957fbce21854755c6dc
AD: 447bdaf34dfab9cc3dd7777ebaf80077f391093bac9817bf02ad98db9d3f271282ecaf0ff19652f92076d1
CT: 3ddcb07c121b498f1abb73bedb527d4df4
TAG: 55957a0e884dea22d6ace10e5936cdac891f5b54225349ede5c44715f1064b5e
KEY: ffefb7770a7cf125395703985823f3e926f3722ca0764518fd2b8996577bec03648c8d542af1c6e36b51174b0ba88316
NONCE: 4c31394b4b24f6251a839891
IN: f026a1d352c37b204c6c1138abee9a9a75
AD: 1e7c0f71a3aacd87ea785521ea31f93b1efd0bdf97952e0b84ecd50c706806deffc19caea312b5a9988454d2
CT: 23c8bae37db93ed9f55f2903e04b7c6a8e
TAG: 89d0a7e7d921dea5bb54c28e79b612688e42506aa69b141de830c8d63bdefcee
KEY: 453cf5e4f48ce5a961c94af0e1639c156965970f561ac17fe08d5b75975abe3db87412640972e463290800666be80441
NONCE: b3e3f9708a86c7cdf139e496
IN: 53f1b11de497cc6ecb411a777dc3d60197
AD: afe29e074dcce850ac6640230e6b9f66a64587c5fbe8679144e065d3b1700c721833ba8f918e926c9142f5f362
CT: 15d5f597be46a19566a72c5e843b77f70c
TAG: a561c3375c096a116a721e9404e555a2deaf3f677a8611694281663274708f58
KEY: 3d497f81d0652d475bcd85cf53bda13f79ef0afeaec09dd679a6e5ea58f87ba6576269f836096d5ac034594b17073331
NONCE: 3fb1664830821e2b524890c8
IN: bd75c313f5c8f6007a2185bc39d0af01bb
AD: 50744ed959e2b8ba5b5f4807e2997ea0b96ebfcdeaa1c6b33853219844592e82ad67abf6ccbb272cfdba6a3e45c07fec4d4a0ebe4235f11d916771a764d9a129d39f6b84f0b5fb4cdf789ca2f5ea306b25d047a9b1a1e2e90905b6fba472e70b2fa25c96602cfa0031f31c68954d7487507081b8e70f8aa1342cb8b4a98ce9c2
CT: abe3869ac43fd8b429ee8b8539c970bc86
TAG: 33fcd301c2bf624bccb92a986c2dd5f2ecafc32649ff550eb5312fc81cbce46e
KEY: 353c3e9f87b40fc0281869c68d9d9bee5c95771dd79998c059bc5ceda71f139fe447cfdf340e9eac57f232b9d230e45d
NONCE: cc7a4b46b02f4e7f96fd34e3
IN: 44bcb61332930f606276268ddbf3287bcaedb5b25704489cbee63ec839d7a69533dbfb6e95fe5b4694eb485beb1437f0777774868ecf45c8a5b3edafa1d62a
AD:
CT: d038d67b8b690519fafa7467c9fb94135f9bf0bcd8247cd2c30da62ddf37a6d9a3a9bdcf8ec081fb4469c0fc2798e2e30afede7cda384438fd01e5d672dcb8
TAG: db2c685a59cdf304c1fb57b66966a5ca1cc3536fe21eb1113c25868428640c7d
KEY: 3b3786e38e110ec0c8b05fbdb3d9b6d117d1ebcdc0e7d942249fea6baafa31fe5caac227979fc833b104641e8e9ed01e
NONCE: 53bf31912a3ededc01c91f84
IN: 6de5890028382aafb186042864c5cca1a77ff80ba4f7f0942dcffa1579711093fb652c8d475dfca81a976be8ca77eb9c7a6b49dca1425610c945bf404ba65b
AD: a9
CT: 886939354fa117139f5e077baa186825ee7e2955c3a74f88af3a86b260ee9f9959a90409e7d602e36cea31e606aeaa8b9229e28f7fa58ace6fd217e5cce1e7
TAG: 91a769003ec900dbb40ea9c9b959882d822421b510ba85ca826bc4af3b5c42e0
KEY: 5a75c97f3583983bbc5eee4a882b766a6708d798a46f71e63b7509af69afd7cf86f9b42df04b626940914007078a8b9b
NONCE: 426e8bcbcffb6b425706dae0
IN: c24fa29a66197cad518c5a1a76abd9446a8f24c2dd81e953bfc5c00544c119d67986781a1c754224af234b0ec5e44e78610a4420eb78c283e9a56637c35c24
AD: 6376835513967e4ccaff9a0c56b4d27a2bd0d013cd54abf95fe9a162d036af285ebc9567a16ed5abfa69aa
CT: bc4daeef3ccdf9abdaa75591781685eee3fd7825bfe63132817a7e0f93817f22bfca30ed775a773f5bb290aac3a381a01085e861cab7b9fe4c5143138e17a5
TAG: 79c779bfcb974ad9a8ac88dce5027df5691a3a1163a5d5893b4cdb1663b17aa1
KEY: d1b301c029fe3b81e4b97e08e84dbc03b138f422161c0e74ccbda3172c034b99610f09a9e611f0e9a3ca40af4fcb3c56
NONCE: 4032c79eb3ee4b63e44fa932
IN: 71bcf5a5198787b85a66221c22e7bdb9d038dd3e10000555ec9271e54bfefc460ef4e71729ff7ae52859015b49f45df89ddf183fe1e19de3acb032dbaa4d57
AD: f1cd18ff1e5ad2b65de41e083b5175966625ebebb3031e1027761e407dae4e8e193ffe7dea52ff61147f1b4e
CT: 7c521a703b7d1cbd086bdc316d4f2ff0852c462eeaa1d7a586c561354be9ed412d9d9bd1f78cc85468750f1af09b7b17dc1ee84c926760d63504cd3a1dfa3a
TAG: 831f3552890d997f0a8f2d832b6e92e26f6e865424699f0364a82d86ab7734d0
KEY: fdd24bf37b36666a4f641115581ab4bd6b896dd3017006031b3675beed33f21a314363e3a07bbbf4359d9ac02eec847f
NONCE: 7767cff1a096a9f7d8a9b32c
IN: e62b7695dd41baf49d1b356e64c6d5504784380b75724b86f5f3185d1a530664aea0e5f9aeef347e1ea4754acaa7f3c233638db234c0e93db02e0bf988e7ab
AD: 2d650f3daed2564b0df86fa23ed0343634663adfae2c422f80f9d5674bbb63e824f01ad3994834f889133bbc0e
CT: a51f50a6ce77a22ec472bc18c37d08fb28e77efe55065b600e3edbd9ac97f0fd0eec93cd312ec7ef886cb04e1849526f0a38b14d862bcd578b99bf9a007c2e
TAG: 89d83264364c9c84ba705e5549abcd496abed3900f65e3daa012275fed18a7da
KEY: 0f88e2d00d2c4bd682f1591ea5f4c1a1090180e1195809cb363b27c863360a85b27814e6a724effa44f298430d6c9628
NONCE: 6e2e62ecb2aa47c7e5921d25
IN: 91efc710a57adb57017725cfa26d17d3e2993c5ee66942ca42e770a83763e9df8a455bd408dc1e2661cf301f1dd669cd6d5b4d92a886be0f54527779bae8f9
AD: d060cbe84271e85f25a3dcb6dbf299551f0dcd5783e3df80468636e491c0100f3ec8316f24240482a88bc430a398b0ecaee5c48a274ffb2d835e200bc39ec0aa86a1c90c9e2dcb4217595d48826a81de90eb949846a33fc26bf8886ca0554e1b8f12cbeee36e65e33cbbf610c2d24264619fa93c44c88e0e3d9d368fdece461b
CT: 10d99b98ed67d85a44fa57e706a8b028c61ef17f35f6713613d158cad90e826f90ef036a2190ba123f9b68b352ca94fbebf8ea947e569ad45f00e6a36975f8
TAG: e345bebcc4a8ac01528bc5f317e5c378236b292c2baab6ae8654245da35d90d6
KEY: 1ccec52c77239bdf6ca50e5b702943b23015d08cb1d9bac592b3dec4c96be904110713e52e114a8bc294df26530a758a
NONCE: 38554b7c40027afe9721e14a
IN: dac91fcdb3768df8d5ae9ddba1fe5917c084a5d9e6b14eee9a609cab2da34ec9f95cf2d10fff77108477e694c76f362e29b9a9287d8b190a748ed0a929967ff8
AD:
CT: e6bcb38b3bfd0b428a14bb3aca01a4a9e54b0853f10bd7750f5bb58d0e7dd18006f8929d7d862e5d6601ef63be8442334b4d51a99219cfedaa31f7ab19028459
TAG: c4f05d9415840c2325dabbcd12dbeda31e47637437514c606dedfb8ce622edd0
KEY: c82ad4c6f248bc51d3a51b958ecc2460a3c64d669f6c485c2309d26abb3fa84644a0d8c28da8091f90184b53cd556413
NONCE: 35a29938fb7a31225b08d0e4
IN: bb0045cec5587e50b148b140b6969612425243ed1412e812aa9f4b471ed34ced6dfa9e0acf3e31455893e4ee7e66b4661c6e1f80b7d6f1159c11387ce579b80f
AD: 12
CT: 5f1854fc2fb11fd721755445a1efa5a28607a725ad71cda9a3464860a6a0efe3f58727c0e0cd315f867611232abd72034dfc2b9deace8cf6cb507b1cd4032b59
TAG: e40429ca19a88da73a7654d7ed8e0621ac2e504b0245615e262ac70bd05a3f47
KEY: b01bec74fe97e5af7db2a0b1432f8b4c069447d2b56dc2668371387f753b03465412213999d2394a4b79873db06c590a
NONCE: fec7de97d54dec8d36c9f253
IN: 88ab078d03ffacd128edbceea7ace2e6465f4076097445a5db7f0e61ed817b6e24f22874489049bee0c58d0aa2b42b4db0bbef6ec88d032da9c82ebef57c424d
AD: cf0ceb3e80a76d1a75f6e070f5d3fee1cd1e2699434f96e7cb3adce12d4a3148dd433b08c68b9d66962f24
CT: 8aa3c7478b0cd86fa30870957fb5307345f89346a869d508da9d3a4fe36fb3d6a9b0c3c1bc2d44c8ea31ec028012098d6032085af0b54603dc2fa65ff091fdd6
TAG: acb670172ec3754064b366566bdccf5056eae132e2041f1a285c5883e7eff4f3
KEY: 699a94f6e6eb457b186af58c25118fcea81c8f0ad265e7c16bd6cdca15c9db64bb9a537580ca0474a4b4d54d47412d88
NONCE: ac3fb6525f4357d831529407
IN: a7300aa94f3d357cdb272f0a739979e08aad9551dd3bfcd0b5aca6a0972a71b502639e79e1b9e0d22db2f3220b982800d9cebbac3d10d9bf86ea25d3d417fc57
AD: 19c3d34bb9d57d0f63f14bdd3da06a43a5afe6a8c505f038cb403515876a2765c2d61aa7e4c84e11c999b81d
CT: 8b472f1069ace78172611369b03073f751e5206dcd2ce3b45c431095f303e70c59bfad3af8006e66e4a68f8fa2ffa534bd76bdef089d07dd38988cbf723393c6
TAG: 8e7c3c2c41b1117928ca1cd0cd48c25c319c18e009804c007d1aab0967c0d0d4
KEY: f3a7b8c2a39531d5fb3c97bc9224168aa835973f48243d6f046d00937ed428e5d672e22af26e734f0c24f989fe62621a
NONCE: 65c61af60769672f0eeda005
IN: 59667fceb2594e002c844a47d2b3935d2c99570b1639f0887fb082499e1d36f9699ff9ef53be3b4236136aa9e441abdc63dfe536e6fc9fa8f332baa1dad577ad
AD: f79036742501f1ac19dbb2984e09cf5000bc4bc0424082376c307b8f1e5bf74dd29c802139d7ea93d55d336464
CT: 9375a81f016c2dc59a8e99dc33fc0db7ef99ab2f9ade4b0ba000a614ff2bd13bfbee2d4a2338109c98c1147edca6023cea43570adc503da98379326ace89d796
TAG: f563869420699dfa0aa84751526bd75af1473bd88311001e49230b09b8ef2797
KEY: 27611a8f11cb57d08648ec816b5f3c45882dae394200cdfc803d1a52bb03f225206574ea63b63423da6972bf5a994332
NONCE: a7f617fe7a52dd76ee443dff
IN: d6ccb950515a4a2de7c3cf5a73b568f32fe30567bb22b3b46feb7ef07205d3215a3d689b96d4b9dbaac5a5bd6ecac6ba50314b19b37179fff2557c869950e162
AD: 777282a98b2f262ed9456fed3610a2028bcc4433eb8f028597d3bfa220bdb0c04882de03a276d0191cd1a125270ce1630c1b94e2ec0021ce5c494d2e0bdb8745e6e94a387cbb31a0898965174bcff8bba105f94dbf080059b49dee71c3194fefe679ef6c00065154ea809293b088c0c3f2ed7824aac72319a4c4ad85ea990844
CT: 41eacc31aa3c3a282ae7638d48fc7541d2f129e4cb3455df7e60259be9a814c8e1642ea826ac1ec7ed1fcc216a6624e79845521e7a8b16702566f27f7a7f3317
TAG: b959992feb7005410f9ea6963525e3d9244f038731ffab8da8c4ebc72489f17a
KEY: 0d9322713cd132c339c38ec7a75862860de304c70486b89b0f587095c66bfd1abe56f0b34f9ca0dac577fd4262616600
NONCE: 3298d02dd4eb85a98cb935e3
IN: 5dfedb1d168fe262d35f78d797560b2634f71d40f438c21cdcb8e73cf9884c11570554f55a6abd23d0e7775a9ab385ae6c9bbd67f08d1aec57347a8fad5a4b8c7b042b03c25facbffc76f0b1ce2e6c07d427eaebe71255d661ac8e8bfe8867e2d947d496ce2318a601d0beed02426311ca678d036deb3b4c65b1f89bd644a410
AD:
CT: ff09fe27f12a87d5208bf246378ee0740e848262442b8b9c7670c8a73fe6732192cde43c1a1246743ed49e15ec63c87dc06eb3e0c92c1f286108b2c7e0754dcf1b9c3fc87efe3683289daabf2db71d8742061f93098788c3c6f26328b86e358507a03af296d2c29009562cad3763399e0e2b89ed440f756c16214c8ab7ddfb84
TAG: 5076c80fc76c67d6e4f9b9d470cc184db62ea7da49cae44cb3ce9e46c2f2ca9e
KEY: 2695671fe86f1658d8b01ec856fb4c9d09a0c51a1b994fc87a3f72bec12052537b7429f11f7eb4aef0b128302ec8f336
NONCE: 9739e577595418c47b9c10b7
IN: c723c39be334a0761db795076e81e3dd85e37a57258c7e0e10fe0f48dc31bd5e683430aa70531b7c8e3a904e49bec838e760d07afa9f86b2cf78ae90f612c4560632acb7ea2d89fb1fd5396d0337111c429cdba99c6a52e863e8603aac24a83302ebf86ae69a212cb938e12085cbf73a28f75e4422995a5ec8705b12d4aa8b6d
AD: 31
CT: 1569b20732ee6395e605217e1cb419ce57496ba6f6e889bdfa3c93575e969eb7a0410c7930b7ea146e88577376d84f0e824b62890eb84bfe768a1513a12c2958ad1835bc1eabe602cf40f7812c7dd7da955567242cd7512090fca685fdd7306bd98a908b09464961114abbdcd610c153637400a1f81825cfdf06505947fe54ee
TAG: d07e14a62a32ef1933abc2127cc5bfc1e43bbca663e460409c6faa3a4ccf99f3
KEY: 1785ef6e7016733dd1952b3268639f231e7afa973c0a3db8780b81084c67a1783200149a1ed849ca8b5c14c7b1798b4b
NONCE: cdf48b73c3c8d8625e52fe11
IN: 14002f17e056d7f5524537cee6c2061e2741c01a6f9a82e2cb1747887875860d51bebf8d9b63950a051f6b228ad7567227f8a45b9fa7c4ab47eab410125303defa7e3141bd9bc5bf4ed56550801ff3bfc2dfaaf499c192b1e18879b2f59e1230778132818df8f6ad8a3dce9a1d11c98075b8b4e560edd9b5ea180f0424ab3706
AD: a35e86e22e9a3df65e4c08e5175b4216fa9895a1be6252de911cf98349841494617eefaa007759dad7f337
CT: 99eae989435578cb57715a7457da31b807b8078a59c2332a0a866eee9da5188baed3f517b6808095f0067e9b4b91cc1424a464f0a09fc946adbe4135a17b0e8e545d2046f81cdfdb233aa3520797319c0884ccbade8235c32d195e7b802017f88ddd86fb630de19eb97f4bf91029c001fc8f1cd2189a8ee6c120e9f1682a8703
TAG: 1848f0b163e7b0d270e2a0ced288ea6525697170aae15038f3dcbb4ea49ef843
KEY: ba9aed2bfa90eaed9b27a697bb44c715c0209cae6b2c4ddffc684bcf07ab51b0e096dbcfa26c18fc24b63408317da567
NONCE: 4b850d6bfa64520f1aa1e79e
IN: 5bcc2ea4d729c84340c5ceb827f239578971c595e915f0bd9d49ed51d723f8d0e8362e69fd11466230bda0dad57ad724307edcc621ebde1e57fa91fee206d81d2bb6ead94b4a804f74b6cae979f66bdfa4ad93d107ccf114c59cd3d261aa6e2fc0dfbd0df5f7c18e80d0699cc1712abbefab5029e35549d2919d0f937d444051
AD: f80c759062e9ed0ee597406aedbcda9a14261d66a9546f1c939d20cb1d0d0974fe7a9b33d8c93287a6a8d60a
CT: dae4fc873d302c51e55910e67482bb80ac68e9bc6ef77cb3e57a31d85fe75f9071d0b64026ba16d0b68fa9c0b7e958cf7682bcd329c4174ea0e3f3f9d2e65d82aae1350a53ea7cdcf9ab848b85cd731751f0e2917628e5066f5b1ddebc7dbda5d2d37e46a7a7ee62bb49c4431af730f9cd3da4c1d0e5f8593d8c99803f781bee
TAG: 58b42e9117fc8cc2ba5cff74b0d92e8b381a444fa837018b15e9514fc4319fb4
KEY: 37235623acb0d650f905f106dc3bfe6fd83192e53056de8795ed8d20c6e58e5efd84584007ecb17de9e76b392e12fcd7
NONCE: dc441f1c743a92c4b975c6b6
IN: 960ceb8d80774bd88b7c5f17042ad2e4baac71b4021c548458cffcd9a049291cb0df93076c115b54f9af878745acebc6e8f04666d053b1ed980728043c4fe7f67b2bcb0341d8a4973ed126342f9add14279f8402cbbffcecfc847379dca8a68ba4f2f26141acfca7f3ef558dbaf04629f0f46e43246b19d875be452f14e7bf56
AD: 32579218062560f15ff966932838460f99099782e79f1f8c41cd9f6eb59b4c2c3d2dae9cd199fe66d74c7a9940
CT: 49ad8e24a31e90ab1f8dc37dc51dff0f93f1420e79eb108f90f800274a5aa573f64e274cd52f1dbfdee363e4f86e1457bfb8f87ce57aefd34c3a5a3a93db4ebde3f73a3b4c202c993903ab378ae71042ad238e94f400c7ac1891a9890b19d445eb1db60773a3ea165f7c4b2bb2071faaf588daebac7ce09ebfc88f4d9232d9ca
TAG: 82f908b837a5768598982f860ecea16aee84427371c4de1f1314749b70ffc173
KEY: e7fc36c9fe87a38f9bb4ca67723267e80e16bf39740eb1090234a473d68aed9c96fe2f96e539795eb042276aec5d7505
NONCE: 83d768746d40dcd695e49ff4
IN: e61f0e02a70249b62ec9a8fdbaf6622c9c6316599daff421f1b19815707b67587d196b7e1452c7d7609f108ea946675ac5d97ed215b92a451aa6a11717ab7819f84848151007f37e2cdc8aa99969c3d5652aeeb65fc21b621865f47f44eb2c528ee1142d11f513761a6bb2d169126503db5b263a410cadd2773ff931a032a885
AD: 59114e9f21b380ae6068609ac36688e6aa7c2533cbfe07013ad1b6663bfa42e39f20e62b45c0faa256c1d33caa9f59b1e30d8502bb7148d051451b3d0265cb9fd0d82e4f4e0489ac606956762d8e7b70abd7eca413ddb708f119c342b3d0d5df673769d8df281656d909b68b6f6438edd60339fd84ff69918b6036ad12a0a588
CT: 4f12807736c9ab32a2be2e00c9a0236394a8bcfcec6037e7582af462a73bf10aa73bd90e2bc24b97f7001ccf653574aea294bc7b30b77540f475e0e846ab78ffcfa1fef28058e540fea43d9017d4efa05c837611b2eacf0034f26cb7903eff7874973c6da7843892bfc676170a75f839e297dc7f04c74b40f4bda20a45b2a352
TAG: 9b05aab44ba4d1451f14e087be626232ed11c4ed04081f0d4d47ab593fc619b1
@@ -0,0 +1,336 @@
KEY: a5060fecb0a738d8ff6dd50009a757c6e58db73228534d03f32c26baa1c209f402c3e03a6947c1d9421d63ce43f6df26d30ce783f5ed0d6b88edd389d9f92d8d
NONCE: b52227e92203630a79ec7f5c
IN:
AD:
CT:
TAG: e61a28f5df7061b4236834d2034d2b62cb63c660b7de696c26b345e66b34d222
KEY: d676047046bd5be9263ae39caaa0f688abb1bc67c083658894da6aeeff80b6d58ffc7ca1a1c88f49e629bf5544b2cc7669367202b158fce83fc4a4826dd90a7c
NONCE: eabef87a00fd99ebb6ed6d25
IN:
AD: 83
CT:
TAG: 473cf728899cd5fdd54f18d6f934c3901f7ca118fc5ab2cbb837feefa7852a67
KEY: 5eaef3b8e068fbb652bd37df4dfad6490095642cd49761a35476dffc2b5b5f75236d0351d96a9028660788893323a777ea8a2ac88bb5e500b334af02b1c2a648
NONCE: 34d049342b9db5ffa039eac0
IN:
AD: 7578949699d44dec9188a7f7e14b0a23637cddb9107dbb1f8e2a968aad0443356d7eeceff4316ba7b2e8fe
CT:
TAG: 4d2612c21357638bada9290d2a272f10fb5f070337bf87bae396a1e7253633ae
KEY: eb7b3d7eeb5f26010915a36837dc83da2bad07eba714566584bf1ce62fa9b61210b0ead7182bc28c8f0427699bf04786583fa32f3c3a8a6582cdc254930043bc
NONCE: 3bee5ebcdfc72f4ab0023211
IN:
AD: efecb57e79a326c6b2ce0ae74d7656992a005fbb8da5a55b9595fc5348a5489ee2e69541ec0e8a727a560625
CT:
TAG: f457db1e274adabe5fc898fb1eb7c4a5a8e9a2b66f964d0958aa058c1f9e15ba
KEY: 1c1abffa8a2667a8c1ab347860528162d316d58e3966050dc140fd360e6ff7c557520a8982aae97c5db5495d8951eaa485e1cac4cd8f448a13d071d759885474
NONCE: 4fdce4e59bfdf5d9b57c78e9
IN:
AD: 55125cefc919379b3b4b2a24ee1794f44ac66fd99b8b68f98d4abd45ba50a5b76e5375d08abe3b8b8d3c576bc8
CT:
TAG: c021d2c73737e54ac6e7f61f9bb44818e5bdbf8d81d43842fd25a535790fafba
KEY: 366cf53bc185473acf62610b74231e53aace84e9c5d6fbf71fc24db4f42956065d3eec01ecc72a6c89266565ff530075f4532c860e3192e866b41aee98c5c42a
NONCE: 9ff54bd7b10f4fdfd8db76c7
IN:
AD: 853ef59ae873bf0bfe1465e9dd8c2cddfcf123d213ba4f599d984e4ea69d3c85a23508ec7941ca740a9157ca2a788e9b519291240b307d6c5a8c6860a96b4be698659d19e31ab0ac7ae6ba31dcd609c1db67ad580fe4422e42d368c3e93a56f2a087b0d587188462310c2ebe58ecfcf7178412223808eeb2eda76446168730fe
CT:
TAG: 12d869dc4bd4ac4ce9ed643cccda9e11a1ade65c76f7c1535fa4ec2bcc5eb4c3
KEY: 147b41369bed390f0a9561586fd975474e3b3bbf7f7ebb7a35e5cc43b516c044dce93e154ac790a109709ac5299bb17b709a913d33fd57ebfef2b48ed66393b3
NONCE: 85b81732d2863b41d2551763
IN: 73
AD:
CT: bc
TAG: 47fd81f6eed8d3c66afe06d788ffe40717847785f4b4c617d75a11171690a60c
KEY: 9bf35c1194659c1da634eab6707c55b853c8f61d087187162e926adbae02f8bd4d15bae5b05865d0e2236d64715fc39f32e4e3679a0309396c37eab13d1c637b
NONCE: 8da14a98ee741a5fce0de732
IN: 10
AD: 8e
CT: 17
TAG: b76af41002a946af4947f98f42a873b7da0871f482990a70bda8f005274ca179
KEY: 0befac10caec674c9f23676d121f065dbcc8c91852dd5eb4e80c41076995a2138077592fec665954d21fd6787234d32d3d54bf9c220cf2bf018b374bde29926e
NONCE: a96bfb49f3a136840a0e32ff
IN: 59
AD: 236adab55e1bb8a8db384c01bb2afd30ff35da71f955fb217b8305a45ee075e7f8d863d4c0e5dbe36e297c
CT: ac
TAG: 7bb634357e0835b02a0642352a834ff6598c2ded1af8e8ab60b9ef0641fe863d
KEY: acc672aecf6f10119ee77070abbc2b4fade7e910efd1f93a5716161f88606469a49df05b40332b390d3ac289abfdf6bf7c37c033b1671082922d939139de0d42
NONCE: af0f57b55f1a73794b3ce5cc
IN: ee
AD: f385a50ef027e532635878a4df0deb23369774be47c42f17cbd44925b668f628338ea5f8256c5ad8219c13cf
CT: 71
TAG: 13a5296075ef23216c2f2e83b940d24e8e1e6a01967af96599360f11499ac0a6
KEY: 6195ef5ce3ee01188c48b04ce7a28b3ddd04b78711a6d1233121fc8ec3db3a7a0e496d1b6a416675b1e666b9a3df167efb8ade29e4f22fc77111f32ba8bd1ec2
NONCE: 092070b2f8b65fcfe646f6bc
IN: 26
AD: 98526dba4437d88f657c0b7ce2a2be44ef4951711a40747a7d14b195e4c0eae97247256bba7dbd93d6a8f738c1
CT: 83
TAG: b6aad3f91a26a38245031d6a7eb97be0d386939d4536b2a27c90a2ddb891de73
KEY: 40335487f9958dfc00b76ff06dfec162ae5c6be4e26918bd12e3f21760cb0bd364521a11f5bfae11dee989627525ab5295ee404bce476c280d13d238dea1bd40
NONCE: ecf77c7c827a34efd8cdf79d
IN: 34
AD: f6e661254bf235c7d5b8ee330cb754087480dec5fe4c31dee65d1ab4479642101404bb563522937fb2e41d3aa8a4d269a222e6e0bcfd07ec4b29c1185f99fff7cb5bd2ca8c5b38742270e586c8db19138b446833f2ee07a11dae5b6a1a4c28657f3380e84bffe1bafeccad57d9cfea3da7f728119ec5bb18b79e002954f4379c
CT: 5c
TAG: f3420d4cecae2c1ad79d977abbe408045bd87525c0da2b93e0af3e6c53ba7d74
KEY: bf32ef44c7ca9851f397e70df736d7e0e6243cfd875ebb81d76ad7612dbcfd084cab6b0d67c6a6e8b567c93fd0c3abb78ae121fdb3051a62ccfa045692d3453c
NONCE: 46e0cc64d6e431c1efc2bd2d
IN: 959348a8ad6912d7d6c8eae52f19b1
AD:
CT: 55e8cb6fd958f18b3c19451c5c79a7
TAG: af09194071cb0ed4488d27e79700f938ce77386e5d772f9853b17b719f2b1ebc
KEY: a6b5b8b051edf5cea0353ead88ea887fab048ef32f8303275e93d8f926da0d4b0e34b9447cf44fa70c24c9ab964380065398336bbb20be167fc6cd5e591ef50e
NONCE: 371363612c4675a2e59ebd39
IN: 443d16621b0cf9a12552216f9558ca
AD: 32
CT: b7f432eeda8e4b8a25f0445f17ca7c
TAG: 649934922826febab4d59dfb52a7558e6d30d56e273602b98f3c55fd8e24f4da
KEY: 075b75434269a3fcc57922ee8cc55b5bbe1b90516a3b71838ade73d41ed1d1f33ae1e0e86f88f6ed7e091cae3ccb05144b3ef239831554d6e79ff97c4d8f150e
NONCE: 754d5c4ccbfb291133859de3
IN: 62a151add825077c59459fbf82b708
AD: c8db27487de71124a95eb6359270a8363908159200333b46ee74e2709b308878779686bd43c24e9ecabfc3
CT: 2ffb9a9f65c9fe3daad13768ab56bf
TAG: 4430a90fed7d4b5b2adf5a60d6854956be4feef497781ac7d864a04259e99516
KEY: e787fdeca1095f2f2760a1c5e0f302e07d6b08de39ce31fe6a0db2f76e4626eb0968768ae04d37082c114573c307699707630b8c7ceef60abe3b7831d2adcd6e
NONCE: 9dc9bcfe8b4e2ea059e349bb
IN: 3ad57105144e544f95b82d485f80bb
AD: 96bce5dcaf4a90f6638a7e30cfd840a1e8dbc60cb70ab9592803f8799f909cafe71a83c2d884e1e289cc61e7
CT: e504109cdbf57b0e8a87080379e00d
TAG: 1798a64b5261761ecd88f36eaf7f86ed3db62100aed20dc6e337bc93c459487e
KEY: b43ab650bdd201cf05e0436afe89ac54867383f04c5ed2faea5db8e6784c720d905234f1f5443c550ca14edd8d697fa2d9e288aa58c9a337b30e6d41cfa56545
NONCE: 4e3dd3efe527902b9de45a5f
IN: e386663e249b241fb8249cfec33ac2
AD: 3cf7a396e1bd034ea77a54ffca789f206f94263d90d98bf3e69cb42205fc5c95cfbd0481b0ec490ea447299159
CT: 94aacf00092723e778d25ba78e9d27
TAG: bd5fcf90b9532e7abfa858aed90d5170f08edcdd28ff2c673e0ab45b8c0a0f39
KEY: b22a7c5bb38715025cd59cc0feed9ad8e51101200000168052b294fb1ead545a517dee636a7acd22b8283afb33d30adbe02c1c8557715eea7147f3d98a97cbb9
NONCE: 3b4244c9ad9fedd3f10fdf7a
IN: da79e1ed131856cec3250fde7bda4b
AD: 4b77472ade3f06500169405b86a793d63cfa58f57bde0dd706f369b391142c2fa8a3e6345ccf0a9c29b2182f578e22f55c576f155a05be5e81997fbe06410034ecddd871e5ed94b5eeffc6dbd90a8e66449da01f8ef47d28a4a4bd253ffc427f868867c73b5c709b01732bd8035b1a23ff0a903def1eb136fc90d8b3c8279769
CT: 5d8ad7abc047bfdf9d9cd0b0aaa53e
TAG: 41d050d518d0e51ce16bc2920aa6c76eb8eabd4ed76373c59618c6354885f47a
KEY: 04b3fd8126d65f851f47b3dea22cd6e32506f21effaa3e29820ac7825e01b51c5a2816f0298154f2d8addefa2fdc34c0635d4d6b80ad23eb320c4d4f2aa1de1c
NONCE: fae1b1da40471dbdcec64d4e
IN: 509f116ef7435b0640cf141d5b958aaf
AD:
CT: ecf553eba80e6dd1fae2eab24d772a89
TAG: 11473566e80cff5d7421f65949c34301f34de378e91ad50928cf2caeadc466d4
KEY: 413d154dadc7d8869e9e0f24b3320019a04b7a37620dd9e7aa40b5c08d70dea03c12ccf7faad7009e972680e81544b647650c6ff033f56e5bcdac9a35bd7f804
NONCE: 6a4404adae3f4a7bd2bef95c
IN: 3539fe02b75981fad4f8762772b3c11f
AD: eb
CT: 3f8a96905609a4ef1a95fdb87337503d
TAG: 8ee076fd624d90e1f6336a92165e80408ca6f0e165b201547d351177c95e8d51
KEY: ddc10df673e720c00f28fdfb69f1b8fba99696f23b6f29704a0114444cc0c8a6c8606e8d37fa95aabfd65b29c655678fcec50966c8758a3fb15332a1854a8eac
NONCE: 06331613842b4af86c13f8a2
IN: 55d74bcfc3d1cfc716c6e6b7153c6369
AD: acc264344ae79959f9dd5130664273ba6f345c3fc7bc33c6c1ce33312bfbd5f181a3c7a24f15e7acf72ccf
CT: 20650d9e846eb42854692d438b21d5e8
TAG: 973857523e7ff600cf9bcfcc98403b34ab38d939a6d76716beac42678ca5f5bd
KEY: be0c884db54cf761fc24ff3dd572362910dedacece5e1d93a916df277f923f78e7dcd908e60beb0043503c5b4877a9d962a7de37cacc7387a7553949b52894ec
NONCE: 3f027a93e2716668c7634195
IN: 1ba8f3a87ac6738167aac1491b602ddd
AD: d06dd1b9360a68afa3de5d239b6d91d212c5c555567545a4f133bf5a3b0f26addb9379e1cc1cd690cd427c57
CT: 3596cc50ae72db932dd83bbc8661641d
TAG: 44a1834b1587d0f88e34137dcebbca059dfb8f65ddab18f338a8a30152167be0
KEY: 2ee848726730c64332877a4f88ad7fb241a73b71fbee8eeb4d9d6485855ea32b487e03968e1a7b9e8ac8ab7fbd84257efbce0aa207aeefa67302d5847e0d9c05
NONCE: 526b0a79b6359d133ad51011
IN: a0c0477e8a9ebfd275b674ed33230d42
AD: ded2f0f3f28aea28b17aa58d4b906c6a9b3078f97ffe95b7e161b0c3dbf66879bea7603a046da4945c802ac8b3
CT: b1691c8275f12f7d9af85e71dde9dd5d
TAG: 65a5742dcbc49295c4805387e0a15f986ae47e51add9389dfabb6468a6e83013
KEY: f4a7c0e29ff510c034778e47bb30a468a92140a707936d381b1554d421af107c578e74c53ea08c7f7d93cf67612061359ae458408a9c79250f776ca4192016c0
NONCE: 025bc10dc99346c4d0766a7d
IN: d449a2e812429beb5c466d344f5b5eec
AD: 304dbf9a59bfd33b777d8dec9dddce4c365e72aed851210eb964c1da18119bd13248266a67408e88ac2eadfc54def0fb57f23743d376b11293377565d253d2bffe0309f2946cb78d4e9536dde4691fe1eef9ce2dc916a773d06b42fe2b014e7974d4aeffce25a0902c9b44265e5d6d26809b5f24875e80cc13f1f8872b04a237
CT: f366e7b66683f52586e1c363c15b7fb1
TAG: e0e1bb733471f150ddce1b83f3fc2d88589d286ca052574b7f0735bb598362d2
KEY: eb78ea626b219e12937057155884547cb7578718f569dc8f2b370c0fea80e7f0d0f5cb590f0b7341d20c775bcd6a3c818e23b6cea949cf99eb94a23a81cd2249
NONCE: 75a10f16d429b809cf12b9ef
IN: 6b0203316e8108ff01b12df91ba6644382
AD:
CT: 7ee07054f76471115be159259340c24391
TAG: ab970669d1603767d588a93cf215673ad307244f9179f46fca56e97f64a5fbac
KEY: 3221167926be262b7bd0591f56be6bf030365d45ab84a93a94ea41a5e07735b17245ad43787e8791e7ceaa0472b562ed17e3b609c66c868c9b08304c8bb328b1
NONCE: a94d8417d2bb0323bcfd354d
IN: cec81bac7b85c441b6261163d67921eb49
AD: dd
CT: ddd8860fa9e2e8087db30c9da1ec9f9487
TAG: 26a3b9bc4d4cd802cc22e7647a19fc2a5092293c9f5b1c84bdab7245a6d8f4ab
KEY: 4b16e2d62294f76cd2a6c8e0928279d9de40f0b169ef9465738cbfa064c520128ee89cf657da27e4e532d8c4709d992970bfc9daab2f31b3a67e53200d3d6710
NONCE: e746d498b9031007332447f7
IN: 16841e3fc1f53990d33f7ba525dab121a0
AD: a785917bc9f3aaadfd170abe83bb30c0c5d595fc8b491d983131aeab1a7b8d8771f1a963c251976152dd63
CT: 6bcf5eac15ef74cb8a706856f62eb5e8c7
TAG: 9dc84b06e8ec8921be4bc7762e8cebb61a95ac5660022520f9438e8f77b45796
KEY: ff2f5944111226df1d9a300533d3e871694fe15a418b2090265cd8c0111b249dfb7ee86bd9228f7ea5d89d8afcf10bf69942ee4c29bfa8409b63c00c2213629e
NONCE: 477060f0c61555873bbeb225
IN: f091891c43e2374c2755a88a11b04beb4a
AD: f1323fd1ac4de9719dc5966dae45dd7b8ddbee3f8da4f4f4d5f25d06bdb8ebf57328dde76d0bdb9bdc5f6b12
CT: e0d96f6f3ed0493a289d4c3b79238b9ed6
TAG: 71276c05b52bab0063108dbf4e8ff57cf3e15079055a309d725f14bb86671ce1
KEY: 1ce841bcf2ad8accc458a2d94774c3aa53a99e7dbec587376212101303ca2b42272a23fe28514be190b82e503e7772a3713800f4360fdb767e85ea5e1f7b8eca
NONCE: a2f8afc5ceb5382882907630
IN: 620fece1e843d1d0b5c5a541a6f615a81d
AD: ded910647464d0fbb0a5d93ffb9839de3360c675179c5991ad3470285d79071436025111153628c563ad1b595e
CT: 34431c3422e009373c50f3ee6c5b3fcc2d
TAG: 6e4e8a3967307f47e233a36ce05a4826a698fada2ac19543bab7c9ac4f79451b
KEY: 6bafd28a32690851fda667eb2d3c5993f13df52b2e97630527f26c498fd5019f26177a78f27c0c41616d2a4a73757fcaf9cd92a7da8498f90315d41e7479d90a
NONCE: 75166c506c8e1d10da4da8b9
IN: 697bea4d6eed5e6ed243cf01cc79bfd3a5
AD: c0fa663961c3f7e09a8c7bc73e252a232977dd6c9483f02067b34fe695f341d05338ea2002952439ce08295ee5c12f38dafffeb5716908d3f1d4bfbf9eb0e4077bf8e534f19568ed04fca3bbff95da9088cb939f7a20cc97cc0994f9308e184219bf12c8af0d66df436c296ad39832d661b88c98cbb168c751719ac1383c9124
CT: 8f37885b9602725385fd9a244ab2a156ea
TAG: 7fa5cedd330887900f4a44d098e04d5eca16cf94e21f897fa54b0fc116b711b6
KEY: 815786c7744d15afe1d6ab452cb6696fead8b88269ba3eb35c458f6248bad77b404acc744ebb74612c4f97deaccb99a7bcc6ad41917d61057c05b30c581dc4a0
NONCE: 12342e4704f02336ebfc91df
IN: 7f15e696b49ae5104ced5bebbf58a9d8ddcfaf46ddce9df88fe0d58a2f8546feeb83b975c66e4dafddb7fd9d17e80127e70af06b3b8b13c3390f1f50a227e7
AD:
CT: 22e7c5d54a7b622c47a9edb77cfe7c094e500b0ef9595bc346de736e0088e5934dc07160aea34f24d3ab21440878213d28059551cbfdaa418af40d344674f7
TAG: 8c271ea5c15aa771c900388267efb2f435f001c2e83f4ec297e77c608de2d579
KEY: 66d87d2b18e46257476456a1f87123424477decf196b88b09acfd3ca74bdebef4c98f1b93803098a141e0acc3ce8eede065417a0c1eda9b4614558d2383762b6
NONCE: 1ec0ca1d3b09ef186ac4bb1a
IN: cbb59e14098c2a8ab7e84ace913515c74e056e0fb272c7b88d0dddfb62e395afb695647d97d1071eb09cc1e1776b609fceaf4e30e92640379bb8f0e762ca9c
AD: ec
CT: 832804b8003b0ca1b4eff1dc4da6f6a9649e5a582854bb72cd74357476bf38d81ea3bc8ac0463f21fe37683bcbe07360d0ec2d7ab90b588adf669099303ac1
TAG: 9fecafc768fca71ffe7d640dbb7a052d97d6c8e2fc86001d71feaf284ab609f0
KEY: fbff97085351f4500e73190ac139dd3ac91e268042b5926b57e0394c750b10348b47641d195d5fb5b0846256ab229f102538b81e209db5d93b4d55f30c453d9c
NONCE: d4868c918de2af7d3e3f57d3
IN: 4f14aa5a680d66ae15ce0ce4739888f64d827def862572f9a6cd620badbe4ee9d75f4f9bc1f73d409f519a657f53a50d50e68e22f33a8ef5aa08b1212889e5
AD: c41253e96696a948ce500030af27086842aacb79c04cc02a42b858a65c630065a5292bb9b2e69ea5fe5a7a
CT: 08596ac0550574e352edc13d7e390d8fd0a57406dd61e1543066b4aa0ea06670f356e26ada0d6c61c1e41de1b4fd7a251c961fae44b23523ce227eec99a338
TAG: 72f58de3e6697c8419ef518748fe0bb3cb930907c71b6d682c5e61068206d991
KEY: c78c550aba82b571d39ce21d6ecf5e5f7c2a7bf921c6162c64ec1fdff4d0b8c41bfcea0e2486cc86b9ed9e9ceb73c4ec228a2ecbcfa0379174e76475cc21ae31
NONCE: b5adf4de19980a71cb8ae8e6
IN: 3d5e43ce95ff9d7f797f27b904c07291a35678fe76a9c57f0c0cba724f38acbb22c6c185db864a2a17b7ef2d67a04810ee5a45fd5a4e28a15a1ae16971451d
AD: b5eeb9a18d436ada7bd5601944784f50fb0a989397b5c781a2cdf29337315dc7664f3c1cbf17f37fd0cc8b30
CT: f91f1f20d06ad4480ff233480228994cfa052f9bf3038d06d997d31eb68bffa4960341b93eb5ed2260341e6816519c47bf231db2a41ad8a9719f4de6a33de5
TAG: 6e5eabda421961e26dc17a7e1f750425235df4eaf9a97934c1e1b4439fc22791
KEY: 17b90dec44546d9dbc489e55a01f2cc64452a9b0e50506a8ad7c81bc6fb21328285cafed901a7204048866ff3bd543003fdcbeb3e9e2f3d580f9062362879633
NONCE: f0c0cb247d210031f9b233bc
IN: 75b9b524cbfd1287259da116f536aff56112a406f069aa08f545b5372d45b66d7a5d05e02728c4bc2c779609dfe251386f78c5f48b9dad90b363d324826cd6
AD: 8a604a9b06ad595ce0b9ad1644a596c7d3cde81490abc80840c764c40d6df08fc71d1e8196eae0802f8c8dfc24
CT: 23ad62a668f942e613c3b5a7828142048f1f6a67f7f0e0cc8bf3fffb2d1dd967da472d080353dc9c23b900a566f20afb850e4a47688ee507faa6178fef2afd
TAG: e9e82d3221f964d9e6c09d761afa3f05d1316d39c82618a82dafa23607bb40a3
KEY: d5c09fe24201fcc3ad4c9a9c4b759345f643e930301c3714f62c8dd4974bb15a026b217ac637b4f0e8d6ef40f36be967c50aaea83b2e72df18eeb9576865f1d8
NONCE: 9cfa0df1fe0910b33ee9849d
IN: bfeb3d86ce3f4c5ccd0c3945e1da0e75dd057aa5b4e1f070593394f4a0227abedac0b77478e04d498506245b162e909cb711d8b875d33f9c4578e80a0e2113
AD: b874a8523799554436a1174ab124677dc2ae2042a436c85065c50d5b5e7519623379ffed9a9c2b84b9626214b13c1806b65a432ba79066ff28ed94d17628f5ff84618593954389181e997ebd245d31f520539e250b31c86b99992983820f79e74aeaacb3a95e690e2841aba5a384d0333ebaa5d1fde06b4b8e3e1cabc6639459
CT: afa649ea47db94936f89612ece681bb175664a97aa6faae5745f49ac9fcbfd4287b73cb58e8d8aa12eccf309182f075098f339db697fc60540481dad0cd82e
TAG: 9909335130df0326650823de5a4f5b6f45e6941a6a72ceaf80ef32fe67363944
KEY: a13c4654606f532a8df47c367dab1b214166e4f7188c20560831ac30ba5e58d316d29764e4c716ec0126657c926ba2e4541da062447228ae61340a951101b4a0
NONCE: a2df3417ebb86bbb2f954939
IN: f1954e59a319547d32e81f846e0c79db41c681166b43eb9c10458948606ced50a44df26fad5654a7c25d3fb52539cf25fcc1c11707c4b5aca7910a76e2374740
AD:
CT: 374726a4691f178a4c0a6f96108ba30c4ca8a30242c14e84380969473879d4a5de580fab4cf6ef6e465560a15028ba78a1a88f9e62322cb698b15ccce6ba83a8
TAG: 683e5a3e61d9d9c8b170f1d4eaa4f74dcbecb1a4cb1551dc364bbb336d4e4109
KEY: 0c1751677a9b7373e0c2ceab2c8e4dab50af22e2230be3187c21ed46069168d173c28a7474d8f7c3cab39401663405aebdcc474ce136e1fff9cfc520bfe17ca6
NONCE: 38bc2efcd97998de1528b064
IN: 8a3c6212240bdcb86da98f0e3ab3e9e78f7f61f0627ea088ab283e739a0bed5c360eeed26cea43ec09b4f3556049a1d7f8ef86abfd1118f9c0e34cc6eea4544a
AD: 20
CT: a1a9f7f4750be3d89fc4f25917f8ffa7dd462ce712ddf61792a01b1840bc8e428000372252f1b41055416a961db3be8fbe774f0a0a71a82e79e74927522703a0
TAG: ae24708df0d5893a902765f6c6c2eebae0c11312936cd415bf4a74bb8498a367
KEY: 154c21eb43d8d556e5f782ddd64d577ac8066fa172c2936fc2b2e875aa437f941819d9ecfaefa2e388fdeea81a0ece8dcb7647f2c68da48884aeb1315b577c09
NONCE: e14d1bd8681373d41702a762
IN: a2c880fcda87d9d4681a735a6790d93a1c9c68e55b87d5f7b3146665a6b2051398eb9895e1f5d522841668b9915633aa8cb40048c619baf6d63ca2da486cdeb8
AD: b0b725cf634349ce1d3ac49d48313a09697efd9996cc5afd06b1d0817181d0374db05825dc2f08207bfb3b
CT: 1cc0db5980863df7a40c78e323a78be6c6d556d4e3b5f930d8d0f2c6a10c6477e31c000d3f0563b46e1a4aa566a4ef4b433e17e94c43338b51a7a3f862739b6e
TAG: fe005424112de2a5ca6e68ada40984df1ae5ac666cf5fee19e9a0f203dd69f52
KEY: c34482341724ee431b5272ee2964b245d7657778f7927cad4b5a1bc30a176b1eb88a83ac9faf58215a72855edf94f8e86fade58c5b5907994bb8381c9f21b753
NONCE: 4934d9afc32fc7e2d8851594
IN: aa3d32adc47b0b84d1b038ddcaeb007a7d5c96cc06a943eba5da6d0d367625330556e67da099c84086b3f46bb4b72986e076eb426913e415cd20bee34e434bd0
AD: 076a7bc587b306f3da3ba88e66a55cb8125bbf8aa000dda266e950f381e35ac938ac86f8a15a83022a25f28b
CT: cf017d87da8927e42c1f10fd3d73cf483bae43f4e110363159a9fbb7cba363930a0364cd42a5de2c70171edc4caf15bfc7238f7087bf1402b32c7bdb1f493393
TAG: 3961efea656aab1b83082522b801fafdae346f7d4be70db1981283f323e5b5dd
KEY: 363e10d8b3fe349014d6222761bba7af86545dcd1812fe2e5ada564c5008f8ea1850f374208e87362afa135f20f9e79dd0ad32f86448263416086d3afc5d37c0
NONCE: cc545928edd3b21c0e8bc0f1
IN: b68e3a54d17dab6eb41b03de2df14e792201d78a9c1cbf341da421da82b026ff471d4305ede5c6baae162a098c73da5cab93f30d6d540b4eaa0ee772448dade8
AD: e21498edf4e25ada2dd6a382eceaf737623e501db34f5c5bd5c963f45818b146a6e45aa92db2a2069e55d46a4c
CT: e4920c1fddb5dfed2268781fbb17e9ad2ea88bf2a0f116fbb7b309b25a5b9f989e1abc334999ab175b65f87e874d8ba80792044b458dc27d2b24c989d24385e1
TAG: f0dcfa064cdf042e0b9a0443d634c38695dd09b99dadc647195fc2ad53dde547
KEY: ae93f58aefa94e4e0622f2e962529fd2efdab840fd0bce62e163ca0fb004ec3b22e246073614203d9b63fe2842ef5903ed08b3e52abf7ea18acbe16fa8f66368
NONCE: c9ac237c87270f2d88b91b64
IN: a75f49778a6c03b0f8915f5d09efe99c5f4e9cd928713882e6b9b78bab3541812db41792b893c7e2259debc6c660ce708851912a5b9eaf91416d86b5de114ce1
AD: a4b198a329e9c5bb6d9f31a6415811eb33c79422b0db130b78d788c38c0b9a5122688cbc50fea811afa20789465f9ee4362336cc3701ece701179af96eb7c86d5a00ed8582f24364393287d5dbc3e83a82b7a585cee5b152b5da40aa45ccd46dc841004778998c7efe9eb43c9762d1c8581eee64e18c5a961bda5aafdd5cfec8
CT: 453fad9395106a703ccbfe811bf775f1827ea960c71d79242d2ea0e3e31b14baa76eb6d107dfc6e484f4e5146f8cad5b389e4c0fa18260c96a193edbc8091a36
TAG: b67082c21557b31392a9821fbce4b93706f96856d2581c92e7fb65dd2166624f
KEY: a145adafac46280e1cee8696903c5f3866540f27f17a519637373d95dca4ac5ac0bfd85ca6e1f8df8ae3fcfc9158421581669db52c20a3e19c5d251952f63218
NONCE: 90bd43611f235ff225b23208
IN: cbe5f3a5b7a94b8665cac1a4d173a225679e1a3926d8596b5adc0ef4fd00f7d93a432ff141cc04f877be60b6a17fff40ac845a91bcee3b483862f67d9a76ef498ce5e49c361bfc018e401aff47b397e96b2982d4fdcd043ca09905be9634e83dc22a667c955bc992ec96ca1b76f73631767f64fc7151284d5aa81c1aa42eb3aa
AD:
CT: 604f718dbce17dfca1fc5e0f400151cb65bea9d7d8f26d56687a76a23f89201aab01ef928006d15493f5b1501bb99c517cf123acd956ab575e687298488a88d5739c266e67ca6a20a5dbe5f5f27ac778816f04e7b1764cb716477f3aa01482cb6b25fe034ab5d942013164aa124608cacf13d6cc9487446cfba54315fc6bfc42
TAG: 8e3e1a01945bfd9e1aa4eff1cdd0a6da6d8fdd5446e6d732a673effe8e44d76a
KEY: 63ac8e2561341587bc066c87cd23f7f33e6023bdc1521a91d6ce63d3ab213825d95d674928b56da1741aad8e85a8b703239ad74e0304ad555eeadebf4ae30aa6
NONCE: 4f3073c3b780ebb146e136c7
IN: 7f9a05b1aead29b4d5361c2606e5db8a48122858842679cd46f8386ef9359f998cd2c6c266791429624ff634a160d08faf1523b650c30b2fcd71517da5f377000251ef23cfd2510a0630215ad45fa6d2313f9add040a07df8259b82d3f29cf1ab8477cd114c9ee579d3e2ce60c5da2f3375b68b4d6e0913d39dac9399c00bd32
AD: 22
CT: d4ed811c8db932348e0c311e9278ef22f22cec8af88b3ac0cef77f13bbd9b8cca037c1ea87590a0ce3f3e7b3ffe1dcc4c7cd9e721baa5f126a3e0afb26dcfa02bf44428846c0f1e07ba0e026c23a39877de1e69e16a2766ff4fa3d4e8d3a97ba28f407f459ae3520dd840e8f9e149ea582048dc6e3d0227bd86a9c26ddd59895
TAG: 0abc9111229bcb725953d139a2dcb1aa0cb9d3d6c01ef4733482dc5edcc88958
KEY: 355454fbe12f125edbc13550a7494f37efbe12b843058d29f892e1524289c2868ef0050a75a232d3083c381289e4950e352d68d64bf05f0608d694763c36641c
NONCE: 0a344bb3da1c4260f2daf256
IN: 362e97f8ef09f30e5db2f21d40568d347d9bc42d4c94a563484b12eb109886ccfd2c61c40dfe93eb836bb6aa4f828e77c137485da2df494cbeb6a9a0192c3777b4d7a927fba11a8eaf604b85a81ac4719ce8b595a74656286fd0b80d1ad3f3393e6038b258af97af9a77f6760d486d9caf5a451ba26dee51bda0f76d75bfc26e
AD: c7c2e8196f37185b44515480d5d9451d79d07df4c1256bff6382f942727ce9b3a4f81ae964d8af2cd9f638
CT: 32a67922947fd6b1c1bfaf3e1d41397173b97095e55307cae1c574daca275778d4aa4313fb1fe5b3997ff18800903ce044c7d0976abbb03b6cc1f7498d8b56d00672bd74f7cb152b677c632ef7a6f6fc13e95e82b6e35d663eb47f27c229c81174fd7c62c94c414e47216af2580fe822643e54907af77ae18e903fe856a02173
TAG: 72d0fe5baee8090c5f8e79890b77f6d72a4213a7d1a81e0d1f1c9e6731e44d54
KEY: 664478c9d30d2cbc39351ec3b3494f3edb81e32e48bd4ef05969da07e770e4181a9ada3b2f83b46f40fc2d9ad35fd8ee6864ff3d70436d6cca3f8e0563cc3b06
NONCE: 7313df9679181ffad2972a6b
IN: 142f073f2ce443c68822f120b5009e39bea3453017dc04c1b091adfddcb2a7e361c2b79eab1bf0818bc86e9d7964834d3775698b56a11ee07a0c9c03cb7bb895bf1a1dde3975c3662d233052824f1539f58cd6ad5cadb58fecaf2b34935ff711c45a639d642fb8fc3a52929b1296683bb13e67f2cc8ed9090126cdf28a4395c6
AD: d0d78b94505793af546912f3780699dd72e288c775bfc75da6e306defcd868f6d40c6d6ce34fab9c11574ef5
CT: cb913e40ea5dfe76beae612e9732d23ce352789987134822b2324db585179bf90d0ee20bee102e93a49a55fc978d19e99ba316cf8d9a10d2f2bcb75da4b135d1fcb8057edc33a180586015d8829a128f8fdc87b72497016c280f54f4d974c2c7e9d32ae137eaa1bcb670be237269fa73c3a0f273da9e70d89600ae7c231fc9d4
TAG: dcc158c254ff7e131ad854a2158d51c643c281dfd7df342d5481384ab236a685
KEY: 409d1b4e1c187c8b1c053e999f2af648583e1045d56d553cce9270d08c5643ef365eb35e3bdeaedcd164b0122ad185e71c75146a9807104d9b65b56d9bc1dc55
NONCE: 1cce3f08a5aa5824d063a6f2
IN: a255239e4065f3effe6aa5e88814d516236d016c51cd8eb35af7cee86418966559802f8ff7ac39c6a45acc1f1b18cc28d7cc32ae66dff43289fe44c3a2a72fbadf3a7249d76c1ba9671dfc420ddf513539f2da5f31030f2b6775c57432c2c3486621d841e80dd4894229debc12ef47d74716838f2d807e208f0fdaf733bce76e
AD: 8f34f8b676e71844841c6a7b63fef1ad3061f2449c1044e1a281595da2d9e9fd141aea7350bd8cf9774d375e67
CT: 969fc2c64261db415e51eee8cc5e0cf5185b8e3325dea516a70e32115a5b72233a44458c40f2daff3594d71e42ca2e3fc1c444ce171d22ef40009d798456613fa4b76beaa6d469e235997a302ac468c8bcfb8ef5de5cda58d7e554a9eab6cb568945dc37f28b0dbd674c083dfbd2e42fda1b42d0c1966e9652a21b32af71e2d5
TAG: fa0789a83c255412501944a67bdceaff3f01d9a23b0c749be38abc956e2acae6
KEY: e6fd8144cdb305bf9e62a2c901764c62902f354409d8c5b9c8cbfc0ba8ac7d0859ff8994e573e46784395d89c355a91a313f601b56e86ed3fd10ba428a5481ce
NONCE: bae080718d3e5c5998542f15
IN: 2258ffcd6fcf91b1723f8db0047525d61cc8ffc440acf3290690685d16384292493807312b7dfc23ac9d9c3ee1405baab21a3770a05875cfe325268b65fc877463e3208c842ea4a32cf144cc46d57afd91f6b6b5d85fb2dedb0702f0c4e7f742cf4c9b4aec02f07267ec1f7b96a5a3ef25f6c1b4c27bd829e86583e239cd854b
AD: 51ae57749b7757718aef9b9c47da5794659516e7f98bc80e6c18c89253f8617963331f54d4f009f087d1d2bd69a083f3a4b98f2a51ce24ffc6079774f7c7b01638b6131bfccebe21fea67bc839c259a50fcc0a16a69ada3c5adee4097d9e053a03266cb9b4b39ee2a465ec1aa058e61a0b9888b93bfcfd103f91ca3a7b274a10
CT: 5b2fe8eea3313cc04d5ec75d75d05b3242b6e3b65c6fa1761716780c9529ff8ca523096dd037c5bda27984aa93c702ce9c01c63569a90657cc6373ad5d4473028b7eef69dd79c44c38d0063e8a8b7f1aa2bf6b646711ecd4eea3fa27408e089d9c4c4aceedff29a25baa6a9069eb7eac83a53212c0b387d700547c46cdc525e3
TAG: 60319de093aec5c0bb8d5f17e950b0f4df0dfd20ad96490f6f12db461b2a4a84
+2
View File
@@ -76,6 +76,8 @@ AES-128-GCM:00000000000000000000000000000000:000000000000000000000000:0000000000
AES-128-GCM:00000000000000000000000000000000:000000000000000000000000:0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:0388dace60b6a392f328c2b971b2fe78f795aaab494b5923f7fd89ff948bc1e0200211214e7394da2089b6acd093abe0c94da219118e297d7b7ebcbcc9c388f28ade7d85a8ee35616f7124a9d527029195b84d1b96c690ff2f2de30bf2ec89e00253786e126504f0dab90c48a30321de3345e6b0461e7c9e6c6b7afedde83f40::cac45f60e31efd3b5a43b98a22ce1aa1
# 192 bytes plaintext, iv is chosen so that initial counter LSB is 0xFF
AES-128-GCM:00000000000000000000000000000000:ffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:56b3373ca9ef6e4a2b64fe1e9a17b61425f10d47a75a5fce13efc6bc784af24f4141bdd48cf7c770887afd573cca5418a9aeffcd7c5ceddfc6a78397b9a85b499da558257267caab2ad0b23ca476a53cb17fb41c4b8b475cb4f3f7165094c229c9e8c4dc0a2a5ff1903e501511221376a1cdb8364c5061a20cae74bc4acd76ceb0abc9fd3217ef9f8c90be402ddf6d8697f4f880dff15bfb7a6b28241ec8fe183c2d59e3f9dfff653c7126f0acb9e64211f42bae12af462b1070bef1ab5e3606::566f8ef683078bfdeeffa869d751a017
# 288 bytes plaintext, iv is chosen so that initial counter LSB is 0xFF
AES-128-GCM:00000000000000000000000000000000:ffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:56b3373ca9ef6e4a2b64fe1e9a17b61425f10d47a75a5fce13efc6bc784af24f4141bdd48cf7c770887afd573cca5418a9aeffcd7c5ceddfc6a78397b9a85b499da558257267caab2ad0b23ca476a53cb17fb41c4b8b475cb4f3f7165094c229c9e8c4dc0a2a5ff1903e501511221376a1cdb8364c5061a20cae74bc4acd76ceb0abc9fd3217ef9f8c90be402ddf6d8697f4f880dff15bfb7a6b28241ec8fe183c2d59e3f9dfff653c7126f0acb9e64211f42bae12af462b1070bef1ab5e3606872ca10dee15b3249b1a1b958f23134c4bccb7d03200bce420a2f8eb66dcf3644d1423c1b5699003c13ecef4bf38a3b60eedc34033bac1902783dc6d89e2e774188a439c7ebcc0672dbda4ddcfb2794613b0be41315ef778708a70ee7d75165c::8b307f6b33286d0ab026a9ed3fe1e85f
# 80 bytes plaintext, submitted by Intel
AES-128-GCM:843ffcf5d2b72694d19ed01d01249412:dbcca32ebf9b804617c3aa9e:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f:6268c6fa2a80b2d137467f092f657ac04d89be2beaa623d61b5a868c8f03ff95d3dcee23ad2f1ab3a6c80eaf4b140eb05de3457f0fbc111a6b43d0763aa422a3013cf1dc37fe417d1fbfc449b75d4cc5:00000000000000000000000000000000101112131415161718191a1b1c1d1e1f:3b629ccfbc1119b7319e1dce2cd6fd6d
+3 -3
View File
@@ -93,10 +93,10 @@ static int probe_for_NEON() {
sigset_t original_sigmask;
sigprocmask(SIG_SETMASK, &sigmask, &original_sigmask);
sigaction(SIGILL, &sigill_action, &sigill_original_action);
if (sigsetjmp(sigill_jmp, 1 /* save signals */) == 0) {
sigaction(SIGILL, &sigill_action, &sigill_original_action);
// This function cannot be inline asm because GCC will refuse to compile
// inline NEON instructions unless building with -mfpu=neon, which would
// defeat the point of probing for support at runtime.
@@ -168,7 +168,7 @@ void OPENSSL_cpuid_setup(void) {
}
#endif
OPENSSL_armcap_P |= ARMV7_NEON | ARMV7_NEON_FUNCTIONAL;
OPENSSL_armcap_P |= ARMV7_NEON;
if (hwcap & kAES) {
OPENSSL_armcap_P |= ARMV8_AES;
-4
View File
@@ -110,10 +110,6 @@ for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
&cmp ("ebp",0);
&jne (&label("notintel"));
&or ("edx",1<<30); # set reserved bit#30 on Intel CPUs
&and (&HB("eax"),15); # familiy ID
&cmp (&HB("eax"),15); # P4?
&jne (&label("notintel"));
&or ("edx",1<<20); # set reserved bit#20 to engage RC4_CHAR
&set_label("notintel");
&bt ("edx",28); # test hyper-threading bit
&jnc (&label("generic"));
-4
View File
@@ -122,10 +122,6 @@ OPENSSL_ia32_cpuid:
cmp \$0,%r9d
jne .Lnotintel
or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
and \$15,%ah
cmp \$15,%ah # examine Family ID
jne .Lnotintel
or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
.Lnotintel:
bt \$28,%edx # test hyper-threading bit
jnc .Lgeneric
+52
View File
@@ -349,6 +349,35 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
}
}
static const uint8_t kOddParity[256] = {
1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14,
14, 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28,
31, 31, 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44,
44, 47, 47, 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59,
61, 61, 62, 62, 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74,
74, 76, 76, 79, 79, 81, 81, 82, 82, 84, 84, 87, 87, 88, 88,
91, 91, 93, 93, 94, 94, 97, 97, 98, 98, 100, 100, 103, 103, 104,
104, 107, 107, 109, 109, 110, 110, 112, 112, 115, 115, 117, 117, 118, 118,
121, 121, 122, 122, 124, 124, 127, 127, 128, 128, 131, 131, 133, 133, 134,
134, 137, 137, 138, 138, 140, 140, 143, 143, 145, 145, 146, 146, 148, 148,
151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 161, 161, 162, 162, 164,
164, 167, 167, 168, 168, 171, 171, 173, 173, 174, 174, 176, 176, 179, 179,
181, 181, 182, 182, 185, 185, 186, 186, 188, 188, 191, 191, 193, 193, 194,
194, 196, 196, 199, 199, 200, 200, 203, 203, 205, 205, 206, 206, 208, 208,
211, 211, 213, 213, 214, 214, 217, 217, 218, 218, 220, 220, 223, 223, 224,
224, 227, 227, 229, 229, 230, 230, 233, 233, 234, 234, 236, 236, 239, 239,
241, 241, 242, 242, 244, 244, 247, 247, 248, 248, 251, 251, 253, 253, 254,
254
};
void DES_set_odd_parity(DES_cblock *key) {
unsigned i;
for (i = 0; i < DES_KEY_SZ; i++) {
key->bytes[i] = kOddParity[key->bytes[i]];
}
}
static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
uint32_t l, r, t, u;
const uint32_t *s;
@@ -609,6 +638,29 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
tin[0] = tin[1] = 0;
}
void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output,
const DES_key_schedule *ks1, const DES_key_schedule *ks2,
const DES_key_schedule *ks3, int enc) {
uint32_t l0, l1;
uint32_t ll[2];
const uint8_t *in = input->bytes;
uint8_t *out = output->bytes;
c2l(in, l0);
c2l(in, l1);
ll[0] = l0;
ll[1] = l1;
if (enc) {
DES_encrypt3(ll, ks1, ks2, ks3);
} else {
DES_decrypt3(ll, ks1, ks2, ks3);
}
l0 = ll[0];
l1 = ll[1];
l2c(l0, out);
l2c(l1, out);
}
void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
+1 -1
View File
@@ -12,7 +12,7 @@ add_library(
add_executable(
digest_test
digest_test.c
digest_test.cc
)
target_link_libraries(digest_test crypto)
@@ -23,24 +23,26 @@
#include <openssl/md5.h>
#include <openssl/sha.h>
#include "../test/scoped_types.h"
typedef struct {
/* md_func is the digest to test. */
struct TestVector {
// md_func is the digest to test.
const EVP_MD *(*md_func)(void);
/* one_shot_func is the convenience one-shot version of the
* digest. */
// one_shot_func is the convenience one-shot version of the
// digest.
uint8_t *(*one_shot_func)(const uint8_t *, size_t, uint8_t *);
/* input is a NUL-terminated string to hash. */
// input is a NUL-terminated string to hash.
const char *input;
/* repeat is the number of times to repeat input. */
// repeat is the number of times to repeat input.
size_t repeat;
/* expected_hex is the expected digest in hexadecimal. */
// expected_hex is the expected digest in hexadecimal.
const char *expected_hex;
} TEST_VECTOR;
};
static const TEST_VECTOR kTestVectors[] = {
/* MD4 tests, from RFC 1320. (crypto/md4 does not provide a
* one-shot MD4 function.) */
static const TestVector kTestVectors[] = {
// MD4 tests, from RFC 1320. (crypto/md4 does not provide a
// one-shot MD4 function.)
{ &EVP_md4, NULL, "", 1, "31d6cfe0d16ae931b73c59d7e0c089c0" },
{ &EVP_md4, NULL, "a", 1, "bde52cb31de33e46245e05fbdbd6fb24" },
{ &EVP_md4, NULL, "abc", 1, "a448017aaf21d8525fc10ae87aa6729d" },
@@ -53,7 +55,7 @@ static const TEST_VECTOR kTestVectors[] = {
"043f8582f241db351ce627e153e7f0e4" },
{ &EVP_md4, NULL, "1234567890", 8, "e33b4ddc9c38f2199c3e7b164fcc0536" },
/* MD5 tests, from RFC 1321. */
// MD5 tests, from RFC 1321.
{ &EVP_md5, &MD5, "", 1, "d41d8cd98f00b204e9800998ecf8427e" },
{ &EVP_md5, &MD5, "a", 1, "0cc175b9c0f1b6a831c399e269772661" },
{ &EVP_md5, &MD5, "abc", 1, "900150983cd24fb0d6963f7d28e17f72" },
@@ -65,7 +67,7 @@ static const TEST_VECTOR kTestVectors[] = {
"d174ab98d277d9f5a5611c2c9f419d9f" },
{ &EVP_md5, &MD5, "1234567890", 8, "57edf4a22be3c955ac49da2e2107b67a" },
/* SHA-1 tests, from RFC 3174. */
// SHA-1 tests, from RFC 3174.
{ &EVP_sha1, &SHA1, "abc", 1, "a9993e364706816aba3e25717850c26c9cd0d89d" },
{ &EVP_sha1, &SHA1,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
@@ -76,7 +78,7 @@ static const TEST_VECTOR kTestVectors[] = {
"0123456701234567012345670123456701234567012345670123456701234567", 10,
"dea356a2cddd90c7a7ecedc5ebb563934f460452" },
/* SHA-224 tests, from RFC 3874. */
// SHA-224 tests, from RFC 3874.
{ &EVP_sha224, &SHA224, "abc", 1,
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" },
{ &EVP_sha224, &SHA224,
@@ -86,14 +88,14 @@ static const TEST_VECTOR kTestVectors[] = {
"a", 1000000,
"20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" },
/* SHA-256 tests, from NIST. */
// SHA-256 tests, from NIST.
{ &EVP_sha256, &SHA256, "abc", 1,
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
{ &EVP_sha256, &SHA256,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1,
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" },
/* SHA-384 tests, from NIST. */
// SHA-384 tests, from NIST.
{ &EVP_sha384, &SHA384, "abc", 1,
"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed"
"8086072ba1e7cc2358baeca134c825a7" },
@@ -103,7 +105,7 @@ static const TEST_VECTOR kTestVectors[] = {
"09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712"
"fcc7c71a557e2db966c3e9fa91746039" },
/* SHA-512 tests, from NIST. */
// SHA-512 tests, from NIST.
{ &EVP_sha512, &SHA512, "abc", 1,
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" },
@@ -113,12 +115,12 @@ static const TEST_VECTOR kTestVectors[] = {
"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018"
"501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" },
/* MD5-SHA1 tests. */
// MD5-SHA1 tests.
{ &EVP_md5_sha1, NULL, "abc", 1,
"900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d" },
};
static int compare_digest(const TEST_VECTOR *test,
static bool CompareDigest(const TestVector *test,
const uint8_t *digest,
size_t digest_len) {
static const char kHexTable[] = "0123456789abcdef";
@@ -135,105 +137,94 @@ static int compare_digest(const TEST_VECTOR *test,
fprintf(stderr, "%s(\"%s\" * %d) = %s; want %s\n",
EVP_MD_name(test->md_func()), test->input, (int)test->repeat,
digest_hex, test->expected_hex);
return 0;
return false;
}
return 1;
return true;
}
static int test_digest(const TEST_VECTOR *test) {
int ret = 0;
EVP_MD_CTX ctx;
size_t i;
uint8_t digest[EVP_MAX_MD_SIZE];
unsigned digest_len;
static int TestDigest(const TestVector *test) {
ScopedEVP_MD_CTX ctx;
EVP_MD_CTX_init(&ctx);
/* Test the input provided. */
if (!EVP_DigestInit_ex(&ctx, test->md_func(), NULL)) {
// Test the input provided.
if (!EVP_DigestInit_ex(ctx.get(), test->md_func(), NULL)) {
fprintf(stderr, "EVP_DigestInit_ex failed\n");
goto done;
return false;
}
for (i = 0; i < test->repeat; i++) {
if (!EVP_DigestUpdate(&ctx, test->input, strlen(test->input))) {
for (size_t i = 0; i < test->repeat; i++) {
if (!EVP_DigestUpdate(ctx.get(), test->input, strlen(test->input))) {
fprintf(stderr, "EVP_DigestUpdate failed\n");
goto done;
return false;
}
}
if (!EVP_DigestFinal_ex(&ctx, digest, &digest_len)) {
uint8_t digest[EVP_MAX_MD_SIZE];
unsigned digest_len;
if (!EVP_DigestFinal_ex(ctx.get(), digest, &digest_len)) {
fprintf(stderr, "EVP_DigestFinal_ex failed\n");
goto done;
return false;
}
if (!compare_digest(test, digest, digest_len)) {
goto done;
if (!CompareDigest(test, digest, digest_len)) {
return false;
}
/* Test the input one character at a time. */
if (!EVP_DigestInit_ex(&ctx, test->md_func(), NULL)) {
// Test the input one character at a time.
if (!EVP_DigestInit_ex(ctx.get(), test->md_func(), NULL)) {
fprintf(stderr, "EVP_DigestInit_ex failed\n");
goto done;
return false;
}
if (!EVP_DigestUpdate(&ctx, NULL, 0)) {
if (!EVP_DigestUpdate(ctx.get(), NULL, 0)) {
fprintf(stderr, "EVP_DigestUpdate failed\n");
goto done;
return false;
}
for (i = 0; i < test->repeat; i++) {
const char *p;
for (p = test->input; *p; p++) {
if (!EVP_DigestUpdate(&ctx, p, 1)) {
for (size_t i = 0; i < test->repeat; i++) {
for (const char *p = test->input; *p; p++) {
if (!EVP_DigestUpdate(ctx.get(), p, 1)) {
fprintf(stderr, "EVP_DigestUpdate failed\n");
goto done;
return false;
}
}
}
if (!EVP_DigestFinal_ex(&ctx, digest, &digest_len)) {
if (!EVP_DigestFinal_ex(ctx.get(), digest, &digest_len)) {
fprintf(stderr, "EVP_DigestFinal_ex failed\n");
goto done;
return false;
}
if (digest_len != EVP_MD_size(test->md_func())) {
fprintf(stderr, "EVP_MD_size output incorrect\n");
goto done;
return false;
}
if (!compare_digest(test, digest, digest_len)) {
goto done;
if (!CompareDigest(test, digest, digest_len)) {
return false;
}
/* Test the one-shot function. */
// Test the one-shot function.
if (test->one_shot_func && test->repeat == 1) {
uint8_t *out = test->one_shot_func((const uint8_t *)test->input,
strlen(test->input), digest);
if (out != digest) {
fprintf(stderr, "one_shot_func gave incorrect return\n");
goto done;
return false;
}
if (!compare_digest(test, digest, EVP_MD_size(test->md_func()))) {
goto done;
if (!CompareDigest(test, digest, EVP_MD_size(test->md_func()))) {
return false;
}
/* Test the deprecated static buffer variant, until it's removed. */
// Test the deprecated static buffer variant, until it's removed.
out = test->one_shot_func((const uint8_t *)test->input, strlen(test->input),
NULL);
if (!compare_digest(test, out, EVP_MD_size(test->md_func()))) {
goto done;
if (!CompareDigest(test, out, EVP_MD_size(test->md_func()))) {
return false;
}
}
ret = 1;
done:
EVP_MD_CTX_cleanup(&ctx);
return ret;
return true;
}
int main(void) {
size_t i;
CRYPTO_library_init();
ERR_load_crypto_strings();
for (i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) {
if (!test_digest(&kTestVectors[i])) {
for (size_t i = 0; i < sizeof(kTestVectors) / sizeof(kTestVectors[0]); i++) {
if (!TestDigest(&kTestVectors[i])) {
fprintf(stderr, "Test %d failed\n", (int)i);
return 1;
}
+6 -7
View File
@@ -426,7 +426,7 @@ void EC_GROUP_free(EC_GROUP *group) {
OPENSSL_free(group);
}
int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) {
int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src) {
if (dest->meth->group_copy == 0) {
OPENSSL_PUT_ERROR(EC, EC_GROUP_copy, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
@@ -482,7 +482,7 @@ EC_GROUP *EC_GROUP_dup(const EC_GROUP *a) {
if (t == NULL) {
return NULL;
}
if (!EC_GROUP_copy(t, a)) {
if (!ec_group_copy(t, a)) {
goto err;
}
@@ -499,11 +499,10 @@ err:
}
}
int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b) {
if (a->curve_name == NID_undef || b->curve_name == NID_undef) {
return 0;
}
return a->curve_name == b->curve_name;
int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ignored) {
return a->curve_name == NID_undef ||
b->curve_name == NID_undef ||
a->curve_name != b->curve_name;
}
const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group) {
+11 -18
View File
@@ -290,16 +290,9 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
EC_KEY *ret = NULL;
EC_PRIVATEKEY *priv_key = NULL;
priv_key = EC_PRIVATEKEY_new();
if (priv_key == NULL) {
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_MALLOC_FAILURE);
return NULL;
}
priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len);
priv_key = d2i_EC_PRIVATEKEY(NULL, in, len);
if (priv_key == NULL) {
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_EC_LIB);
EC_PRIVATEKEY_free(priv_key);
return NULL;
}
@@ -309,9 +302,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_MALLOC_FAILURE);
goto err;
}
if (a) {
*a = ret;
}
} else {
ret = *a;
}
@@ -380,17 +370,17 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) {
ret->enc_flag |= EC_PKEY_NO_PUBKEY;
}
if (a) {
*a = ret;
}
ok = 1;
err:
if (!ok) {
if (ret) {
if (ret && (a == NULL || *a != ret)) {
EC_KEY_free(ret);
}
ret = NULL;
if (a) {
*a = ret;
}
}
if (priv_key) {
@@ -519,18 +509,21 @@ EC_KEY *d2i_ECParameters(EC_KEY **key, const uint8_t **inp, long len) {
OPENSSL_PUT_ERROR(EC, d2i_ECParameters, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (key) {
*key = ret;
}
} else {
ret = *key;
}
if (!d2i_ECPKParameters(&ret->group, inp, len)) {
OPENSSL_PUT_ERROR(EC, d2i_ECParameters, ERR_R_EC_LIB);
if (key == NULL || *key == NULL) {
EC_KEY_free(ret);
}
return NULL;
}
if (key) {
*key = ret;
}
return ret;
}
+4 -12
View File
@@ -170,35 +170,27 @@ EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) {
OPENSSL_PUT_ERROR(EC, EC_KEY_copy, ERR_R_PASSED_NULL_PARAMETER);
return NULL;
}
/* copy the parameters */
/* Copy the parameters. */
if (src->group) {
/* TODO(fork): duplicating the group seems wasteful. */
const EC_METHOD *meth = src->group->meth;
/* clear the old group */
if (dest->group) {
EC_GROUP_free(dest->group);
}
dest->group = ec_group_new(meth);
dest->group = EC_GROUP_dup(src->group);
if (dest->group == NULL) {
return NULL;
}
if (!EC_GROUP_copy(dest->group, src->group)) {
return NULL;
}
}
/* copy the public key */
/* 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);
dest->pub_key = EC_POINT_dup(src->pub_key, 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 */
+1
View File
@@ -250,6 +250,7 @@ struct ec_point_st {
} /* EC_POINT */;
EC_GROUP *ec_group_new(const EC_METHOD *meth);
int ec_group_copy(EC_GROUP *dest, const EC_GROUP *src);
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
+33 -1
View File
@@ -1,18 +1,50 @@
include_directories(. .. ../../include)
add_custom_command(
OUTPUT err_data.c
COMMAND ${GO_EXECUTABLE} run err_data_generate.go > ${CMAKE_CURRENT_BINARY_DIR}/err_data.c
DEPENDS
err_data_generate.go
asn1.errordata
bio.errordata
bn.errordata
buf.errordata
cipher.errordata
conf.errordata
crypto.errordata
dh.errordata
digest.errordata
dsa.errordata
ecdh.errordata
ecdsa.errordata
ec.errordata
engine.errordata
evp.errordata
hkdf.errordata
obj.errordata
pem.errordata
pkcs8.errordata
rsa.errordata
ssl.errordata
x509.errordata
x509v3.errordata
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_library(
err
OBJECT
err.c
err_data.c
err_impl.c
)
add_executable(
err_test
err_test.c
err_test.cc
)
target_link_libraries(err_test crypto)
+5
View File
@@ -1,4 +1,5 @@
CIPHER,function,100,EVP_AEAD_CTX_init
CIPHER,function,131,EVP_AEAD_CTX_init_with_direction
CIPHER,function,101,EVP_AEAD_CTX_open
CIPHER,function,102,EVP_AEAD_CTX_seal
CIPHER,function,103,EVP_CIPHER_CTX_copy
@@ -7,6 +8,9 @@ CIPHER,function,105,EVP_CIPHER_CTX_set_key_length
CIPHER,function,106,EVP_CipherInit_ex
CIPHER,function,107,EVP_DecryptFinal_ex
CIPHER,function,108,EVP_EncryptFinal_ex
CIPHER,function,132,aead_aes_ctr_hmac_sha256_init
CIPHER,function,133,aead_aes_ctr_hmac_sha256_open
CIPHER,function,134,aead_aes_ctr_hmac_sha256_seal
CIPHER,function,109,aead_aes_gcm_init
CIPHER,function,110,aead_aes_gcm_open
CIPHER,function,111,aead_aes_gcm_seal
@@ -44,6 +48,7 @@ CIPHER,reason,111,INVALID_NONCE_SIZE
CIPHER,reason,112,INVALID_OPERATION
CIPHER,reason,113,IV_TOO_LARGE
CIPHER,reason,114,NO_CIPHER_SET
CIPHER,reason,124,NO_DIRECTION_SET
CIPHER,reason,115,OUTPUT_ALIASES_INPUT
CIPHER,reason,116,TAG_TOO_LARGE
CIPHER,reason,117,TOO_LARGE
+14 -9
View File
@@ -117,7 +117,7 @@
#if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3)
#include <Windows.h>
#include <windows.h>
#pragma warning(pop)
#endif
@@ -126,6 +126,14 @@
#include <openssl/thread.h>
extern const uint32_t kOpenSSLFunctionValues[];
extern const size_t kOpenSSLFunctionValuesLen;
extern const char kOpenSSLFunctionStringData[];
extern const uint32_t kOpenSSLReasonValues[];
extern const size_t kOpenSSLReasonValuesLen;
extern const char kOpenSSLReasonStringData[];
/* err_fns contains a pointer to the current error implementation. */
static const struct ERR_FNS_st *err_fns = NULL;
extern const struct ERR_FNS_st openssl_err_default_impl;
@@ -423,8 +431,6 @@ void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
}
}
#include "err_data.h"
// err_string_cmp is a compare function for searching error values with
// |bsearch| in |err_string_lookup|.
static int err_string_cmp(const void *a, const void *b) {
@@ -545,9 +551,9 @@ const char *ERR_func_error_string(uint32_t packed_error) {
}
return err_string_lookup(ERR_GET_LIB(packed_error),
ERR_GET_FUNC(packed_error), kFunctionValues,
sizeof(kFunctionValues) / sizeof(kFunctionValues[0]),
kFunctionStringData);
ERR_GET_FUNC(packed_error), kOpenSSLFunctionValues,
kOpenSSLFunctionValuesLen,
kOpenSSLFunctionStringData);
}
const char *ERR_reason_error_string(uint32_t packed_error) {
@@ -582,9 +588,8 @@ const char *ERR_reason_error_string(uint32_t packed_error) {
}
}
return err_string_lookup(lib, reason, kReasonValues,
sizeof(kReasonValues) / sizeof(kReasonValues[0]),
kReasonStringData);
return err_string_lookup(lib, reason, kOpenSSLReasonValues,
kOpenSSLReasonValuesLen, kOpenSSLReasonStringData);
}
void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -140,13 +140,16 @@ func (st *stringList) WriteTo(out stringWriter, name string) {
list := st.buildList()
fmt.Fprintf(os.Stderr, "%s: %d bytes of list and %d bytes of string data.\n", name, 4*len(list), len(st.stringData))
out.WriteString("static const uint32_t k" + name + "Values[] = {\n")
values := "kOpenSSL" + name + "Values"
out.WriteString("const uint32_t " + values + "[] = {\n")
for _, v := range list {
fmt.Fprintf(out, " 0x%x,\n", v)
}
out.WriteString("};\n\n")
out.WriteString("const size_t " + values + "Len = sizeof(" + values + ") / sizeof(" + values + "[0]);\n\n");
out.WriteString("static const char k" + name + "StringData[] =\n \"")
stringData := "kOpenSSL" + name + "StringData"
out.WriteString("const char " + stringData + "[] =\n \"")
for i, c := range st.stringData {
if c == 0 {
out.WriteString("\\0\"\n \"")
@@ -267,6 +270,7 @@ func main() {
/* This file was generated by err_data_generate.go. */
#include <openssl/base.h>
#include <openssl/err.h>
#include <openssl/type_check.h>
@@ -20,55 +20,52 @@
#include <openssl/mem.h>
static int test_overflow(void) {
unsigned i;
for (i = 0; i < ERR_NUM_ERRORS*2; i++) {
static bool TestOverflow() {
for (unsigned i = 0; i < ERR_NUM_ERRORS*2; i++) {
ERR_put_error(1, 2, i+1, "test", 1);
}
for (i = 0; i < ERR_NUM_ERRORS - 1; i++) {
for (unsigned i = 0; i < ERR_NUM_ERRORS - 1; i++) {
uint32_t err = ERR_get_error();
/* Errors are returned in order they were pushed, with the least recent ones
* removed, up to |ERR_NUM_ERRORS - 1| errors. So the errors returned are
* |ERR_NUM_ERRORS + 2| through |ERR_NUM_ERRORS * 2|, inclusive. */
if (err == 0 || ERR_GET_REASON(err) != i + ERR_NUM_ERRORS + 2) {
fprintf(stderr, "ERR_get_error failed at %u\n", i);
return 0;
return false;
}
}
if (ERR_get_error() != 0) {
fprintf(stderr, "ERR_get_error more than the expected number of values.\n");
return 0;
return false;
}
return 1;
return true;
}
static int test_put_error(void) {
uint32_t peeked_packed_error, packed_error;
int peeked_line, line, peeked_flags, flags;
const char *peeked_file, *file, *peeked_data, *data;
static bool TestPutError() {
if (ERR_get_error() != 0) {
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
return 0;
return false;
}
ERR_put_error(1, 2, 3, "test", 4);
ERR_add_error_data(1, "testing");
peeked_packed_error = ERR_peek_error_line_data(&peeked_file, &peeked_line,
&peeked_data, &peeked_flags);
packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
int peeked_line, line, peeked_flags, flags;
const char *peeked_file, *file, *peeked_data, *data;
uint32_t peeked_packed_error =
ERR_peek_error_line_data(&peeked_file, &peeked_line, &peeked_data,
&peeked_flags);
uint32_t packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
if (peeked_packed_error != packed_error ||
peeked_file != file ||
peeked_data != data ||
peeked_flags != flags) {
fprintf(stderr, "Bad peeked error data returned.\n");
return 0;
return false;
}
if (strcmp(file, "test") != 0 ||
@@ -79,16 +76,16 @@ static int test_put_error(void) {
ERR_GET_REASON(packed_error) != 3 ||
strcmp(data, "testing") != 0) {
fprintf(stderr, "Bad error data returned.\n");
return 0;
return false;
}
return 1;
return true;
}
static int test_clear_error(void) {
static bool TestClearError() {
if (ERR_get_error() != 0) {
fprintf(stderr, "ERR_get_error returned value before an error was added.\n");
return 0;
return false;
}
ERR_put_error(1, 2, 3, "test", 4);
@@ -96,42 +93,39 @@ static int test_clear_error(void) {
if (ERR_get_error() != 0) {
fprintf(stderr, "Error remained after clearing.\n");
return 0;
return false;
}
return 1;
return true;
}
static int test_print(void) {
size_t i;
char buf[256];
uint32_t packed_error;
static bool TestPrint() {
ERR_put_error(1, 2, 3, "test", 4);
ERR_add_error_data(1, "testing");
packed_error = ERR_get_error();
uint32_t packed_error = ERR_get_error();
for (i = 0; i <= sizeof(buf); i++) {
char buf[256];
for (size_t i = 0; i <= sizeof(buf); i++) {
ERR_error_string_n(packed_error, buf, i);
}
return 1;
return true;
}
static int test_release(void) {
static bool TestRelease() {
ERR_put_error(1, 2, 3, "test", 4);
ERR_remove_thread_state(NULL);
return 1;
return true;
}
int main(void) {
int main() {
CRYPTO_library_init();
if (!test_overflow() ||
!test_put_error() ||
!test_clear_error() ||
!test_print() ||
!test_release()) {
if (!TestOverflow() ||
!TestPutError() ||
!TestClearError() ||
!TestPrint() ||
!TestRelease()) {
return 1;
}
+2
View File
@@ -2,6 +2,7 @@ EVP,function,100,EVP_DigestSignAlgorithm
EVP,function,101,EVP_DigestVerifyInitFromAlgorithm
EVP,function,102,EVP_PKEY_CTX_ctrl
EVP,function,103,EVP_PKEY_CTX_dup
EVP,function,159,EVP_PKEY_CTX_get0_rsa_oaep_label
EVP,function,104,EVP_PKEY_copy_parameters
EVP,function,105,EVP_PKEY_decrypt
EVP,function,106,EVP_PKEY_decrypt_init
@@ -45,6 +46,7 @@ EVP,function,143,pkey_ec_derive
EVP,function,144,pkey_ec_keygen
EVP,function,145,pkey_ec_paramgen
EVP,function,146,pkey_ec_sign
EVP,function,158,pkey_hmac_ctrl
EVP,function,147,pkey_rsa_ctrl
EVP,function,148,pkey_rsa_decrypt
EVP,function,149,pkey_rsa_encrypt
+4
View File
@@ -56,10 +56,13 @@ SSL,function,154,dtls1_buffer_record
SSL,function,155,dtls1_check_timeout_num
SSL,function,156,dtls1_connect
SSL,function,157,dtls1_do_write
SSL,function,263,dtls1_get_buffered_message
SSL,function,158,dtls1_get_hello_verify
SSL,function,159,dtls1_get_message
SSL,function,160,dtls1_get_message_fragment
SSL,function,265,dtls1_hm_fragment_new
SSL,function,161,dtls1_preprocess_fragment
SSL,function,264,dtls1_process_fragment
SSL,function,162,dtls1_process_record
SSL,function,163,dtls1_read_bytes
SSL,function,164,dtls1_send_hello_verify_request
@@ -216,6 +219,7 @@ SSL,reason,151,EVP_DIGESTSIGNFINAL_FAILED
SSL,reason,152,EVP_DIGESTSIGNINIT_FAILED
SSL,reason,153,EXCESSIVE_MESSAGE_SIZE
SSL,reason,154,EXTRA_DATA_IN_MESSAGE
SSL,reason,271,FRAGMENT_MISMATCH
SSL,reason,155,GOT_A_FIN_BEFORE_A_CCS
SSL,reason,156,GOT_CHANNEL_ID_BEFORE_A_CCS
SSL,reason,157,GOT_NEXT_PROTO_BEFORE_A_CCS
+3
View File
@@ -3,6 +3,7 @@ X509,function,101,ASN1_item_sign_ctx
X509,function,102,ASN1_item_verify
X509,function,103,NETSCAPE_SPKI_b64_decode
X509,function,104,NETSCAPE_SPKI_b64_encode
X509,function,158,PKCS7_get_CRLs
X509,function,105,PKCS7_get_certificates
X509,function,106,X509_ATTRIBUTE_create_by_NID
X509,function,107,X509_ATTRIBUTE_create_by_OBJ
@@ -52,6 +53,7 @@ X509,function,150,get_cert_by_subject
X509,function,151,i2d_DSA_PUBKEY
X509,function,152,i2d_EC_PUBKEY
X509,function,153,i2d_RSA_PUBKEY
X509,function,157,pkcs7_parse_header
X509,function,154,x509_name_encode
X509,function,155,x509_name_ex_d2i
X509,function,156,x509_name_ex_new
@@ -78,6 +80,7 @@ X509,reason,119,NEWER_CRL_NOT_NEWER
X509,reason,120,NOT_PKCS7_SIGNED_DATA
X509,reason,121,NO_CERTIFICATES_INCLUDED
X509,reason,122,NO_CERT_SET_FOR_US_TO_VERIFY
X509,reason,136,NO_CRLS_INCLUDED
X509,reason,123,NO_CRL_NUMBER
X509,reason,124,PUBLIC_KEY_DECODE_ERROR
X509,reason,125,PUBLIC_KEY_ENCODE_ERROR
+2 -2
View File
@@ -24,13 +24,13 @@ add_library(
add_executable(
evp_test
evp_test.c
evp_test.cc
)
add_executable(
pbkdf_test
pbkdf_test.c
pbkdf_test.cc
)
target_link_libraries(evp_test crypto)
+7 -8
View File
@@ -65,9 +65,8 @@
/* md_begin_digset is a callback from the |EVP_MD_CTX| code that is called when
* a new digest is begun. */
static int md_begin_digest(EVP_MD_CTX *ctx) {
int r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
return r > 0 || r == -2;
return EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);
}
static const struct evp_md_pctx_ops md_pctx_ops = {
@@ -98,24 +97,24 @@ static int do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
if (is_verify) {
if (ctx->pctx->pmeth->verifyctx_init) {
if (ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx) <= 0) {
if (!ctx->pctx->pmeth->verifyctx_init(ctx->pctx, ctx)) {
return 0;
}
ctx->pctx->operation = EVP_PKEY_OP_VERIFYCTX;
} else if (EVP_PKEY_verify_init(ctx->pctx) <= 0) {
} else if (!EVP_PKEY_verify_init(ctx->pctx)) {
return 0;
}
} else {
if (ctx->pctx->pmeth->signctx_init) {
if (ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx) <= 0) {
if (!ctx->pctx->pmeth->signctx_init(ctx->pctx, ctx)) {
return 0;
}
ctx->pctx->operation = EVP_PKEY_OP_SIGNCTX;
} else if (EVP_PKEY_sign_init(ctx->pctx) <= 0) {
} else if (!EVP_PKEY_sign_init(ctx->pctx)) {
return 0;
}
}
if (EVP_PKEY_CTX_set_signature_md(ctx->pctx, type) <= 0) {
if (!EVP_PKEY_CTX_set_signature_md(ctx->pctx, type)) {
return 0;
}
if (pctx) {
+5 -11
View File
@@ -109,12 +109,6 @@ void EVP_PKEY_free(EVP_PKEY *pkey) {
}
free_it(pkey);
if (pkey->attributes) {
/* TODO(fork): layering: X509_ATTRIBUTE_free is an X.509 function. In
* practice this path isn't called but should be removed in the future. */
/*sk_X509_ATTRIBUTE_pop_free(pkey->attributes, X509_ATTRIBUTE_free);*/
assert(0);
}
OPENSSL_free(pkey);
}
@@ -237,11 +231,11 @@ EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const uint8_t *mac_key,
return NULL;
}
if (EVP_PKEY_keygen_init(mac_ctx) <= 0 ||
EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
EVP_PKEY_CTRL_SET_MAC_KEY, mac_key_len,
(uint8_t *)mac_key) <= 0 ||
EVP_PKEY_keygen(mac_ctx, &ret) <= 0) {
if (!EVP_PKEY_keygen_init(mac_ctx) ||
!EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
EVP_PKEY_CTRL_SET_MAC_KEY, mac_key_len,
(uint8_t *)mac_key) ||
!EVP_PKEY_keygen(mac_ctx, &ret)) {
ret = NULL;
goto merr;
}
+5 -12
View File
@@ -212,32 +212,25 @@ void *EVP_PKEY_CTX_get_app_data(EVP_PKEY_CTX *ctx) { return ctx->app_data; }
int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, int cmd,
int p1, void *p2) {
int ret;
if (!ctx || !ctx->pmeth || !ctx->pmeth->ctrl) {
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
return -2;
return 0;
}
if (keytype != -1 && ctx->pmeth->pkey_id != keytype) {
return -1;
return 0;
}
if (ctx->operation == EVP_PKEY_OP_UNDEFINED) {
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_NO_OPERATION_SET);
return -1;
return 0;
}
if (optype != -1 && !(ctx->operation & optype)) {
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_INVALID_OPERATION);
return -1;
return 0;
}
ret = ctx->pmeth->ctrl(ctx, cmd, p1, p2);
if (ret == -2) {
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
}
return ret;
return ctx->pmeth->ctrl(ctx, cmd, p1, p2);
}
int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx) {
+164 -286
View File
@@ -16,6 +16,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <openssl/bio.h>
#include <openssl/bytestring.h>
#include <openssl/crypto.h>
@@ -25,9 +27,11 @@
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include "../test/scoped_types.h"
/* kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
* should never use this key anywhere but in an example. */
// kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
// should never use this key anywhere but in an example.
static const uint8_t kExampleRSAKeyDER[] = {
0x30, 0x82, 0x02, 0x5c, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xf8,
0xb8, 0x6c, 0x83, 0xb4, 0xbc, 0xd9, 0xa8, 0x57, 0xc0, 0xa5, 0xb4, 0x59,
@@ -98,8 +102,8 @@ static const uint8_t kSignature[] = {
0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42,
};
/* kExamplePSSCert is an example self-signed certificate, signed with
* kExampleRSAKeyDER using RSA-PSS with default hash functions. */
// kExamplePSSCert is an example self-signed certificate, signed with
// kExampleRSAKeyDER using RSA-PSS with default hash functions.
static const uint8_t kExamplePSSCert[] = {
0x30, 0x82, 0x02, 0x62, 0x30, 0x82, 0x01, 0xc6, 0xa0, 0x03, 0x02, 0x01,
0x02, 0x02, 0x09, 0x00, 0x8d, 0xea, 0x53, 0x24, 0xfa, 0x48, 0x87, 0xf3,
@@ -155,8 +159,8 @@ static const uint8_t kExamplePSSCert[] = {
0x8c, 0x16,
};
/* kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
* PrivateKeyInfo. */
// kExampleRSAKeyPKCS8 is kExampleRSAKeyDER encoded in a PKCS #8
// PrivateKeyInfo.
static const uint8_t kExampleRSAKeyPKCS8[] = {
0x30, 0x82, 0x02, 0x76, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
@@ -213,8 +217,8 @@ static const uint8_t kExampleRSAKeyPKCS8[] = {
0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf,
};
/* kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
* structure. */
// kExampleECKeyDER is a sample EC private key encoded as an ECPrivateKey
// structure.
static const uint8_t kExampleECKeyDER[] = {
0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x07, 0x0f, 0x08, 0x72, 0x7a,
0xd4, 0xa0, 0x4a, 0x9c, 0xdd, 0x59, 0xc9, 0x4d, 0x89, 0x68, 0x77, 0x08,
@@ -229,8 +233,8 @@ static const uint8_t kExampleECKeyDER[] = {
0xc1,
};
/* kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
* structure. The private key is equal to the order and will fail to import */
// kExampleBadECKeyDER is a sample EC private key encoded as an ECPrivateKey
// structure. The private key is equal to the order and will fail to import.
static const uint8_t kExampleBadECKeyDER[] = {
0x30, 0x66, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48,
0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03,
@@ -243,237 +247,143 @@ static const uint8_t kExampleBadECKeyDER[] = {
0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
};
static EVP_PKEY *load_example_rsa_key(void) {
EVP_PKEY *ret = NULL;
static ScopedEVP_PKEY LoadExampleRSAKey() {
const uint8_t *derp = kExampleRSAKeyDER;
EVP_PKEY *pkey = NULL;
RSA *rsa = NULL;
if (!d2i_RSAPrivateKey(&rsa, &derp, sizeof(kExampleRSAKeyDER))) {
return NULL;
ScopedRSA rsa(d2i_RSAPrivateKey(nullptr, &derp, sizeof(kExampleRSAKeyDER)));
if (!rsa) {
return nullptr;
}
pkey = EVP_PKEY_new();
if (pkey == NULL || !EVP_PKEY_set1_RSA(pkey, rsa)) {
goto out;
ScopedEVP_PKEY pkey(EVP_PKEY_new());
if (!pkey || !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) {
return nullptr;
}
ret = pkey;
pkey = NULL;
out:
if (pkey) {
EVP_PKEY_free(pkey);
}
if (rsa) {
RSA_free(rsa);
}
return ret;
return pkey;
}
static int test_EVP_DigestSignInit(void) {
int ret = 0;
EVP_PKEY *pkey = NULL;
uint8_t *sig = NULL;
static bool TestEVP_DigestSignInit(void) {
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
!EVP_DigestSignUpdate(md_ctx.get(), kMsg, sizeof(kMsg))) {
return false;
}
// Determine the size of the signature.
size_t sig_len = 0;
EVP_MD_CTX md_ctx, md_ctx_verify;
EVP_MD_CTX_init(&md_ctx);
EVP_MD_CTX_init(&md_ctx_verify);
pkey = load_example_rsa_key();
if (pkey == NULL ||
!EVP_DigestSignInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
!EVP_DigestSignUpdate(&md_ctx, kMsg, sizeof(kMsg))) {
goto out;
if (!EVP_DigestSignFinal(md_ctx.get(), NULL, &sig_len)) {
return false;
}
/* Determine the size of the signature. */
if (!EVP_DigestSignFinal(&md_ctx, NULL, &sig_len)) {
goto out;
}
/* Sanity check for testing. */
if (sig_len != EVP_PKEY_size(pkey)) {
// Sanity check for testing.
if (sig_len != (size_t)EVP_PKEY_size(pkey.get())) {
fprintf(stderr, "sig_len mismatch\n");
goto out;
return false;
}
sig = malloc(sig_len);
if (sig == NULL || !EVP_DigestSignFinal(&md_ctx, sig, &sig_len)) {
goto out;
std::vector<uint8_t> sig;
sig.resize(sig_len);
if (!EVP_DigestSignFinal(md_ctx.get(), bssl::vector_data(&sig), &sig_len)) {
return false;
}
sig.resize(sig_len);
// Ensure that the signature round-trips.
md_ctx.Reset();
if (!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
!EVP_DigestVerifyUpdate(md_ctx.get(), kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(md_ctx.get(), bssl::vector_data(&sig), sig_len)) {
return false;
}
/* Ensure that the signature round-trips. */
if (!EVP_DigestVerifyInit(&md_ctx_verify, NULL, EVP_sha256(), NULL, pkey) ||
!EVP_DigestVerifyUpdate(&md_ctx_verify, kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(&md_ctx_verify, sig, sig_len)) {
goto out;
}
ret = 1;
out:
if (!ret) {
BIO_print_errors_fp(stderr);
}
EVP_MD_CTX_cleanup(&md_ctx);
EVP_MD_CTX_cleanup(&md_ctx_verify);
if (pkey) {
EVP_PKEY_free(pkey);
}
if (sig) {
free(sig);
}
return ret;
return true;
}
static int test_EVP_DigestVerifyInit(void) {
int ret = 0;
EVP_PKEY *pkey = NULL;
EVP_MD_CTX md_ctx;
EVP_MD_CTX_init(&md_ctx);
pkey = load_example_rsa_key();
if (pkey == NULL ||
!EVP_DigestVerifyInit(&md_ctx, NULL, EVP_sha256(), NULL, pkey) ||
!EVP_DigestVerifyUpdate(&md_ctx, kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(&md_ctx, kSignature, sizeof(kSignature))) {
goto out;
static bool TestEVP_DigestVerifyInit(void) {
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL,
pkey.get()) ||
!EVP_DigestVerifyUpdate(md_ctx.get(), kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(md_ctx.get(), kSignature, sizeof(kSignature))) {
return false;
}
ret = 1;
out:
if (!ret) {
BIO_print_errors_fp(stderr);
}
EVP_MD_CTX_cleanup(&md_ctx);
if (pkey) {
EVP_PKEY_free(pkey);
}
return ret;
return true;
}
/* test_algorithm_roundtrip signs a message using an already-initialized
* |md_ctx|, sampling the AlgorithmIdentifier. It then uses |pkey| and the
* AlgorithmIdentifier to verify the signature. */
static int test_algorithm_roundtrip(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) {
int ret = 0;
uint8_t *sig = NULL;
size_t sig_len = 0;
EVP_MD_CTX md_ctx_verify;
X509_ALGOR *algor = NULL;
EVP_MD_CTX_init(&md_ctx_verify);
// TestAlgorithmRoundtrip signs a message using an already-initialized
// |md_ctx|, sampling the AlgorithmIdentifier. It then uses |pkey| and the
// AlgorithmIdentifier to verify the signature.
static bool TestAlgorithmRoundtrip(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) {
if (!EVP_DigestSignUpdate(md_ctx, kMsg, sizeof(kMsg))) {
goto out;
return false;
}
/* Save the algorithm. */
algor = X509_ALGOR_new();
if (algor == NULL || !EVP_DigestSignAlgorithm(md_ctx, algor)) {
goto out;
// Save the algorithm.
ScopedX509_ALGOR algor(X509_ALGOR_new());
if (!algor || !EVP_DigestSignAlgorithm(md_ctx, algor.get())) {
return false;
}
/* Determine the size of the signature. */
// Determine the size of the signature.
size_t sig_len = 0;
if (!EVP_DigestSignFinal(md_ctx, NULL, &sig_len)) {
goto out;
return false;
}
/* Sanity check for testing. */
if (sig_len != EVP_PKEY_size(pkey)) {
// Sanity check for testing.
if (sig_len != (size_t)EVP_PKEY_size(pkey)) {
fprintf(stderr, "sig_len mismatch\n");
goto out;
return false;
}
sig = malloc(sig_len);
if (sig == NULL || !EVP_DigestSignFinal(md_ctx, sig, &sig_len)) {
goto out;
std::vector<uint8_t> sig;
sig.resize(sig_len);
if (!EVP_DigestSignFinal(md_ctx, bssl::vector_data(&sig), &sig_len)) {
return false;
}
sig.resize(sig_len);
// Ensure that the signature round-trips.
ScopedEVP_MD_CTX md_ctx_verify;
if (!EVP_DigestVerifyInitFromAlgorithm(md_ctx_verify.get(), algor.get(),
pkey) ||
!EVP_DigestVerifyUpdate(md_ctx_verify.get(), kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(md_ctx_verify.get(), bssl::vector_data(&sig),
sig_len)) {
return false;
}
/* Ensure that the signature round-trips. */
if (!EVP_DigestVerifyInitFromAlgorithm(&md_ctx_verify, algor, pkey) ||
!EVP_DigestVerifyUpdate(&md_ctx_verify, kMsg, sizeof(kMsg)) ||
!EVP_DigestVerifyFinal(&md_ctx_verify, sig, sig_len)) {
goto out;
}
ret = 1;
out:
EVP_MD_CTX_cleanup(&md_ctx_verify);
if (sig) {
free(sig);
}
if (algor) {
X509_ALGOR_free(algor);
}
return ret;
return true;
}
static int test_EVP_DigestSignAlgorithm(void) {
int ret = 0;
EVP_PKEY *pkey = NULL;
EVP_MD_CTX md_ctx;
EVP_PKEY_CTX *pkey_ctx;
static bool TestEVP_DigestSignAlgorithm(void) {
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
EVP_MD_CTX_init(&md_ctx);
pkey = load_example_rsa_key();
if (pkey == NULL) {
goto out;
}
/* Test a simple AlgorithmIdentifier. */
if (!EVP_DigestSignInit(&md_ctx, &pkey_ctx, EVP_sha256(), NULL, pkey) ||
!test_algorithm_roundtrip(&md_ctx, pkey)) {
// Test a simple AlgorithmIdentifier.
ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
!TestAlgorithmRoundtrip(md_ctx.get(), pkey.get())) {
fprintf(stderr, "RSA with SHA-256 failed\n");
goto out;
return false;
}
EVP_MD_CTX_cleanup(&md_ctx);
EVP_MD_CTX_init(&md_ctx);
/* Test RSA-PSS with custom parameters. */
if (!EVP_DigestSignInit(&md_ctx, &pkey_ctx, EVP_sha256(), NULL, pkey) ||
EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) != 1 ||
EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512()) != 1 ||
!test_algorithm_roundtrip(&md_ctx, pkey)) {
// Test RSA-PSS with custom parameters.
md_ctx.Reset();
EVP_PKEY_CTX *pkey_ctx;
if (!EVP_DigestSignInit(md_ctx.get(), &pkey_ctx, EVP_sha256(), NULL,
pkey.get()) ||
!EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) ||
!EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512()) ||
!TestAlgorithmRoundtrip(md_ctx.get(), pkey.get())) {
fprintf(stderr, "RSA-PSS failed\n");
goto out;
return false;
}
ret = 1;
out:
if (!ret) {
BIO_print_errors_fp(stderr);
}
EVP_MD_CTX_cleanup(&md_ctx);
if (pkey) {
EVP_PKEY_free(pkey);
}
return ret;
return true;
}
static int test_EVP_DigestVerifyInitFromAlgorithm(void) {
int ret = 0;
static bool TestEVP_DigestVerifyInitFromAlgorithm(void) {
CBS cert, cert_body, tbs_cert, algorithm, signature;
uint8_t padding;
X509_ALGOR *algor = NULL;
const uint8_t *derp;
EVP_PKEY *pkey = NULL;
EVP_MD_CTX md_ctx;
EVP_MD_CTX_init(&md_ctx);
CBS_init(&cert, kExamplePSSCert, sizeof(kExamplePSSCert));
if (!CBS_get_asn1(&cert, &cert_body, CBS_ASN1_SEQUENCE) ||
CBS_len(&cert) != 0 ||
@@ -482,158 +392,126 @@ static int test_EVP_DigestVerifyInitFromAlgorithm(void) {
!CBS_get_asn1(&cert_body, &signature, CBS_ASN1_BITSTRING) ||
CBS_len(&cert_body) != 0) {
fprintf(stderr, "Failed to parse certificate\n");
goto out;
return false;
}
/* Signatures are BIT STRINGs, but they have are multiple of 8 bytes, so the
leading phase byte is just a zero. */
// Signatures are BIT STRINGs, but they have are multiple of 8 bytes, so the
// leading phase byte is just a zero.
uint8_t padding;
if (!CBS_get_u8(&signature, &padding) || padding != 0) {
fprintf(stderr, "Invalid signature padding\n");
goto out;
return false;
}
derp = CBS_data(&algorithm);
if (!d2i_X509_ALGOR(&algor, &derp, CBS_len(&algorithm)) ||
derp != CBS_data(&algorithm) + CBS_len(&algorithm)) {
const uint8_t *derp = CBS_data(&algorithm);
ScopedX509_ALGOR algor(d2i_X509_ALGOR(NULL, &derp, CBS_len(&algorithm)));
if (!algor || derp != CBS_data(&algorithm) + CBS_len(&algorithm)) {
fprintf(stderr, "Failed to parse algorithm\n");
return false;
}
pkey = load_example_rsa_key();
if (pkey == NULL ||
!EVP_DigestVerifyInitFromAlgorithm(&md_ctx, algor, pkey) ||
!EVP_DigestVerifyUpdate(&md_ctx, CBS_data(&tbs_cert),
ScopedEVP_PKEY pkey = LoadExampleRSAKey();
ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestVerifyInitFromAlgorithm(md_ctx.get(), algor.get(),
pkey.get()) ||
!EVP_DigestVerifyUpdate(md_ctx.get(), CBS_data(&tbs_cert),
CBS_len(&tbs_cert)) ||
!EVP_DigestVerifyFinal(&md_ctx, CBS_data(&signature),
!EVP_DigestVerifyFinal(md_ctx.get(), CBS_data(&signature),
CBS_len(&signature))) {
goto out;
return false;
}
ret = 1;
out:
if (!ret) {
BIO_print_errors_fp(stderr);
}
EVP_MD_CTX_cleanup(&md_ctx);
if (pkey) {
EVP_PKEY_free(pkey);
}
if (algor != NULL) {
X509_ALGOR_free(algor);
}
return ret;
return true;
}
static int test_d2i_AutoPrivateKey(const uint8_t *input, size_t input_len,
static bool Testd2i_AutoPrivateKey(const uint8_t *input, size_t input_len,
int expected_id) {
int ret = 0;
const uint8_t *p;
EVP_PKEY *pkey = NULL;
p = input;
pkey = d2i_AutoPrivateKey(NULL, &p, input_len);
if (pkey == NULL || p != input + input_len) {
const uint8_t *p = input;
ScopedEVP_PKEY pkey(d2i_AutoPrivateKey(NULL, &p, input_len));
if (!pkey || p != input + input_len) {
fprintf(stderr, "d2i_AutoPrivateKey failed\n");
goto done;
return false;
}
if (EVP_PKEY_id(pkey) != expected_id) {
if (EVP_PKEY_id(pkey.get()) != expected_id) {
fprintf(stderr, "Did not decode expected type\n");
goto done;
return false;
}
ret = 1;
done:
if (!ret) {
BIO_print_errors_fp(stderr);
}
if (pkey != NULL) {
EVP_PKEY_free(pkey);
}
return ret;
return true;
}
/* Tests loading a bad key in PKCS8 format */
static int test_EVP_PKCS82PKEY(void) {
int ret = 0;
// TestEVP_PKCS82PKEY tests loading a bad key in PKCS8 format.
static bool TestEVP_PKCS82PKEY(void) {
const uint8_t *derp = kExampleBadECKeyDER;
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
EVP_PKEY *pkey = NULL;
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER));
ScopedPKCS8_PRIV_KEY_INFO p8inf(
d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, sizeof(kExampleBadECKeyDER)));
if (!p8inf || derp != kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER)) {
fprintf(stderr, "Failed to parse key\n");
goto done;
return false;
}
pkey = EVP_PKCS82PKEY(p8inf);
ScopedEVP_PKEY pkey(EVP_PKCS82PKEY(p8inf.get()));
if (pkey) {
fprintf(stderr, "Imported invalid EC key\n");
goto done;
return false;
}
ret = 1;
done:
if (p8inf != NULL) {
PKCS8_PRIV_KEY_INFO_free(p8inf);
}
if (pkey != NULL) {
EVP_PKEY_free(pkey);
}
return ret;
return true;
}
int main(void) {
CRYPTO_library_init();
ERR_load_crypto_strings();
if (!test_EVP_DigestSignInit()) {
if (!TestEVP_DigestSignInit()) {
fprintf(stderr, "EVP_DigestSignInit failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_EVP_DigestVerifyInit()) {
if (!TestEVP_DigestVerifyInit()) {
fprintf(stderr, "EVP_DigestVerifyInit failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_EVP_DigestSignAlgorithm()) {
if (!TestEVP_DigestSignAlgorithm()) {
fprintf(stderr, "EVP_DigestSignInit failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_EVP_DigestVerifyInitFromAlgorithm()) {
if (!TestEVP_DigestVerifyInitFromAlgorithm()) {
fprintf(stderr, "EVP_DigestVerifyInitFromAlgorithm failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
EVP_PKEY_RSA)) {
if (!Testd2i_AutoPrivateKey(kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER),
EVP_PKEY_RSA)) {
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyDER) failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_d2i_AutoPrivateKey(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8),
EVP_PKEY_RSA)) {
if (!Testd2i_AutoPrivateKey(kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8),
EVP_PKEY_RSA)) {
fprintf(stderr, "d2i_AutoPrivateKey(kExampleRSAKeyPKCS8) failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_d2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
EVP_PKEY_EC)) {
if (!Testd2i_AutoPrivateKey(kExampleECKeyDER, sizeof(kExampleECKeyDER),
EVP_PKEY_EC)) {
fprintf(stderr, "d2i_AutoPrivateKey(kExampleECKeyDER) failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
if (!test_EVP_PKCS82PKEY()) {
fprintf(stderr, "test_EVP_PKCS82PKEY failed\n");
if (!TestEVP_PKCS82PKEY()) {
fprintf(stderr, "TestEVP_PKCS82PKEY failed\n");
BIO_print_errors_fp(stderr);
return 1;
}
+43
View File
@@ -170,8 +170,49 @@ typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
#define EVP_PKEY_OP_TYPE_GEN (EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN)
/* EVP_PKEY_CTX_ctrl performs |cmd| on |ctx|. The |keytype| and |optype|
* arguments can be -1 to specify that any type and operation are acceptable,
* otherwise |keytype| must match the type of |ctx| and the bits of |optype|
* must intersect the operation flags set on |ctx|.
*
* The |p1| and |p2| arguments depend on the value of |cmd|.
*
* It returns one on success and zero on error. */
OPENSSL_EXPORT int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
int cmd, int p1, void *p2);
/* EVP_PKEY_CTRL_DIGESTINIT is an internal value. It's called by
* EVP_DigestInit_ex to signal the |EVP_PKEY| that a digest operation is
* starting.
*
* TODO(davidben): This is only needed to support the deprecated HMAC |EVP_PKEY|
* types. */
#define EVP_PKEY_CTRL_DIGESTINIT 3
/* EVP_PKEY_CTRL_PEER_KEY is called with different values of |p1|:
* 0: Is called from |EVP_PKEY_derive_set_peer| and |p2| contains a peer key.
* If the return value is <= 0, the key is rejected.
* 1: Is called at the end of |EVP_PKEY_derive_set_peer| and |p2| contains a
* peer key. If the return value is <= 0, the key is rejected.
* 2: Is called with |p2| == NULL to test whether the peer's key was used.
* (EC)DH always return one in this case.
* 3: Is called with |p2| == NULL to set whether the peer's key was used.
* (EC)DH always return one in this case. This was only used for GOST. */
#define EVP_PKEY_CTRL_PEER_KEY 4
/* EVP_PKEY_CTRL_SET_MAC_KEY sets a MAC key. For example, this can be done an
* |EVP_PKEY_CTX| prior to calling |EVP_PKEY_keygen| in order to generate an
* HMAC |EVP_PKEY| with the given key. It returns one on success and zero on
* error. */
#define EVP_PKEY_CTRL_SET_MAC_KEY 5
/* EVP_PKEY_ALG_CTRL is the base value from which key-type specific ctrl
* commands are numbered. */
#define EVP_PKEY_ALG_CTRL 0x1000
#define EVP_PKEY_CTRL_MD 1
#define EVP_PKEY_CTRL_GET_MD 2
#define EVP_PKEY_CTRL_RSA_PADDING (EVP_PKEY_ALG_CTRL + 1)
#define EVP_PKEY_CTRL_GET_RSA_PADDING (EVP_PKEY_ALG_CTRL + 2)
#define EVP_PKEY_CTRL_RSA_PSS_SALTLEN (EVP_PKEY_ALG_CTRL + 3)
@@ -185,6 +226,8 @@ typedef int EVP_PKEY_gen_cb(EVP_PKEY_CTX *ctx);
#define EVP_PKEY_CTRL_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 11)
#define EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL (EVP_PKEY_ALG_CTRL + 12)
#define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID (EVP_PKEY_ALG_CTRL + 1)
struct evp_pkey_ctx_st {
/* Method associated with this operation */
const EVP_PKEY_METHOD *pmeth;
+2 -1
View File
@@ -241,7 +241,8 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
return 1;
default:
return -2;
OPENSSL_PUT_ERROR(EVP, pkey_ec_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
return 0;
}
}
+6 -11
View File
@@ -142,23 +142,14 @@ static EC_KEY *eckey_type2param(int ptype, void *pval) {
}
} else if (ptype == V_ASN1_OBJECT) {
ASN1_OBJECT *poid = pval;
EC_GROUP *group;
/* type == V_ASN1_OBJECT => the parameters are given
* by an asn1 OID */
eckey = EC_KEY_new();
eckey = EC_KEY_new_by_curve_name(OBJ_obj2nid(poid));
if (eckey == NULL) {
OPENSSL_PUT_ERROR(EVP, eckey_type2param, ERR_R_MALLOC_FAILURE);
goto err;
}
group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));
if (group == NULL) {
goto err;
}
if (EC_KEY_set_group(eckey, group) == 0) {
goto err;
}
EC_GROUP_free(group);
} else {
OPENSSL_PUT_ERROR(EVP, eckey_type2param, EVP_R_DECODE_ERROR);
goto err;
@@ -382,7 +373,11 @@ static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) {
static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) {
const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
*group_b = EC_KEY_get0_group(b->pkey.ec);
return EC_GROUP_cmp(group_a, group_b);
if (EC_GROUP_cmp(group_a, group_b, NULL) != 0) {
/* mismatch */
return 0;
}
return 1;
}
static void int_ec_free(EVP_PKEY *pkey) { EC_KEY_free(pkey->pkey.ec); }
+2 -1
View File
@@ -204,7 +204,8 @@ static int pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
break;
default:
return -2;
OPENSSL_PUT_ERROR(EVP, pkey_hmac_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
return 0;
}
return 1;
}
+27 -15
View File
@@ -55,10 +55,12 @@
#include <openssl/evp.h>
#include <limits.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/buf.h>
#include <openssl/bytestring.h>
#include <openssl/digest.h>
#include <openssl/err.h>
#include <openssl/mem.h>
@@ -369,7 +371,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
0 == (ctx->operation & EVP_PKEY_OP_TYPE_CRYPT))) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl,
EVP_R_ILLEGAL_OR_UNSUPPORTED_PADDING_MODE);
return -2;
return 0;
}
if ((p1 == RSA_PKCS1_PSS_PADDING || p1 == RSA_PKCS1_OAEP_PADDING) &&
rctx->md == NULL) {
@@ -386,13 +388,13 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
case EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN:
if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PSS_SALTLEN);
return -2;
return 0;
}
if (type == EVP_PKEY_CTRL_GET_RSA_PSS_SALTLEN) {
*(int *)p2 = rctx->saltlen;
} else {
if (p1 < -2) {
return -2;
return 0;
}
rctx->saltlen = p1;
}
@@ -401,14 +403,14 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
case EVP_PKEY_CTRL_RSA_KEYGEN_BITS:
if (p1 < 256) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_KEYBITS);
return -2;
return 0;
}
rctx->nbits = p1;
return 1;
case EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP:
if (!p2) {
return -2;
return 0;
}
BN_free(rctx->pub_exp);
rctx->pub_exp = p2;
@@ -418,7 +420,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
case EVP_PKEY_CTRL_GET_RSA_OAEP_MD:
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
return -2;
return 0;
}
if (type == EVP_PKEY_CTRL_GET_RSA_OAEP_MD) {
*(const EVP_MD **)p2 = rctx->md;
@@ -443,7 +445,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
if (rctx->pad_mode != RSA_PKCS1_PSS_PADDING &&
rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_MGF1_MD);
return -2;
return 0;
}
if (type == EVP_PKEY_CTRL_GET_RSA_MGF1_MD) {
if (rctx->mgf1md) {
@@ -459,7 +461,7 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
case EVP_PKEY_CTRL_RSA_OAEP_LABEL:
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
return -2;
return 0;
}
if (rctx->oaep_label) {
OPENSSL_free(rctx->oaep_label);
@@ -478,16 +480,17 @@ static int pkey_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
case EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL:
if (rctx->pad_mode != RSA_PKCS1_OAEP_PADDING) {
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_INVALID_PADDING_MODE);
return -2;
return 0;
}
*(uint8_t **)p2 = rctx->oaep_label;
return rctx->oaep_labellen;
CBS_init((CBS *)p2, rctx->oaep_label, rctx->oaep_labellen);
return 1;
case EVP_PKEY_CTRL_DIGESTINIT:
return 1;
default:
return -2;
OPENSSL_PUT_ERROR(EVP, pkey_rsa_ctrl, EVP_R_COMMAND_NOT_SUPPORTED);
return 0;
}
}
@@ -584,7 +587,7 @@ int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, const uint8_t *label,
size_t label_len) {
int label_len_int = label_len;
if (((size_t) label_len_int) != label_len) {
return -2;
return 0;
}
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
@@ -594,6 +597,15 @@ int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, const uint8_t *label,
int EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx,
const uint8_t **out_label) {
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, (void *) out_label);
CBS label;
if (!EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT,
EVP_PKEY_CTRL_GET_RSA_OAEP_LABEL, 0, &label)) {
return -1;
}
if (CBS_len(&label) > INT_MAX) {
OPENSSL_PUT_ERROR(EVP, EVP_PKEY_CTX_get0_rsa_oaep_label, ERR_R_OVERFLOW);
return -1;
}
*out_label = CBS_data(&label);
return (int)CBS_len(&label);
}
+6 -6
View File
@@ -521,8 +521,8 @@ static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx) {
EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(pkctx);
int saltlen, rv = 0;
if (EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) <= 0 ||
EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) <= 0 ||
if (!EVP_PKEY_CTX_get_signature_md(pkctx, &sigmd) ||
!EVP_PKEY_CTX_get_rsa_mgf1_md(pkctx, &mgf1md) ||
!EVP_PKEY_CTX_get_rsa_pss_saltlen(pkctx, &saltlen)) {
goto err;
}
@@ -625,9 +625,9 @@ static int rsa_pss_to_ctx(EVP_MD_CTX *ctx, X509_ALGOR *sigalg, EVP_PKEY *pkey) {
}
if (!EVP_DigestVerifyInit(ctx, &pkctx, md, NULL, pkey) ||
EVP_PKEY_CTX_set_rsa_padding(pkctx, RSA_PKCS1_PSS_PADDING) <= 0 ||
EVP_PKEY_CTX_set_rsa_pss_saltlen(pkctx, saltlen) <= 0 ||
EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md) <= 0) {
!EVP_PKEY_CTX_set_rsa_padding(pkctx, RSA_PKCS1_PSS_PADDING) ||
!EVP_PKEY_CTX_set_rsa_pss_saltlen(pkctx, saltlen) ||
!EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md)) {
goto err;
}
@@ -659,7 +659,7 @@ static evp_digest_sign_algorithm_result_t rsa_digest_sign_algorithm(
EVP_MD_CTX *ctx, X509_ALGOR *sigalg) {
int pad_mode;
EVP_PKEY_CTX *pkctx = ctx->pctx;
if (EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode) <= 0) {
if (!EVP_PKEY_CTX_get_rsa_padding(pkctx, &pad_mode)) {
return EVP_DIGEST_SIGN_ALGORITHM_ERROR;
}
if (pad_mode == RSA_PKCS1_PSS_PADDING) {
@@ -22,17 +22,16 @@
#include <openssl/evp.h>
/* Prints out the data buffer as a sequence of hex bytes */
static void print_data_hex(const void *data, size_t len) {
size_t i;
for (i = 0; i < len; ++i) {
// Prints out the data buffer as a sequence of hex bytes.
static void PrintDataHex(const void *data, size_t len) {
for (size_t i = 0; i < len; ++i) {
fprintf(stderr, "%02x", (int)((const uint8_t *)data)[i]);
}
}
/* Helper for testing that PBKDF2 derives the expected key from the given
* inputs. Returns 1 on success, 0 otherwise. */
static int test_PBKDF2(const void *password, size_t password_len,
// Helper for testing that PBKDF2 derives the expected key from the given
// inputs. Returns 1 on success, 0 otherwise.
static bool TestPBKDF2(const void *password, size_t password_len,
const void *salt, size_t salt_len, unsigned iterations,
const EVP_MD *digest, size_t key_len,
const uint8_t *expected_key) {
@@ -40,64 +39,65 @@ static int test_PBKDF2(const void *password, size_t password_len,
if (key_len > sizeof(key)) {
fprintf(stderr, "Output buffer is not large enough.\n");
return 0;
return false;
}
if (!PKCS5_PBKDF2_HMAC(password, password_len, salt, salt_len, iterations,
digest, key_len, key)) {
if (!PKCS5_PBKDF2_HMAC((const char *)password, password_len,
(const uint8_t *)salt, salt_len, iterations, digest,
key_len, key)) {
fprintf(stderr, "Call to PKCS5_PBKDF2_HMAC failed\n");
BIO_print_errors_fp(stderr);
return 0;
return false;
}
if (memcmp(key, expected_key, key_len) != 0) {
fprintf(stderr, "Resulting key material does not match expectation\n");
fprintf(stderr, "Expected:\n ");
print_data_hex(expected_key, key_len);
PrintDataHex(expected_key, key_len);
fprintf(stderr, "\nActual:\n ");
print_data_hex(key, key_len);
PrintDataHex(key, key_len);
fprintf(stderr, "\n");
return 0;
return false;
}
return 1;
return true;
}
/* Tests deriving a key using an empty password (specified both as NULL and as
* non-NULL). Note that NULL has special meaning to HMAC initialization. */
static int test_empty_password(void) {
// Tests deriving a key using an empty password (specified both as NULL and as
// non-NULL). Note that NULL has special meaning to HMAC initialization.
static bool TestEmptyPassword() {
const uint8_t kKey[] = {0xa3, 0x3d, 0xdd, 0xc3, 0x04, 0x78, 0x18,
0x55, 0x15, 0x31, 0x1f, 0x87, 0x52, 0x89,
0x5d, 0x36, 0xea, 0x43, 0x63, 0xa2};
if (!test_PBKDF2(NULL, 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey) ||
!test_PBKDF2("", 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey)) {
return 0;
if (!TestPBKDF2(NULL, 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey) ||
!TestPBKDF2("", 0, "salt", 4, 1, EVP_sha1(), sizeof(kKey), kKey)) {
return false;
}
return 1;
return true;
}
/* Tests deriving a key using an empty salt. Note that the expectation was
* generated using OpenSSL itself, and hence is not verified. */
static int test_empty_salt(void) {
// Tests deriving a key using an empty salt. Note that the expectation was
// generated using OpenSSL itself, and hence is not verified.
static bool TestEmptySalt() {
const uint8_t kKey[] = {0x8b, 0xc2, 0xf9, 0x16, 0x7a, 0x81, 0xcd, 0xcf,
0xad, 0x12, 0x35, 0xcd, 0x90, 0x47, 0xf1, 0x13,
0x62, 0x71, 0xc1, 0xf9, 0x78, 0xfc, 0xfc, 0xb3,
0x5e, 0x22, 0xdb, 0xea, 0xfa, 0x46, 0x34, 0xf6};
if (!test_PBKDF2("password", 8, NULL, 0, 2, EVP_sha256(), sizeof(kKey),
kKey) ||
!test_PBKDF2("password", 8, "", 0, 2, EVP_sha256(), sizeof(kKey), kKey)) {
return 0;
if (!TestPBKDF2("password", 8, NULL, 0, 2, EVP_sha256(), sizeof(kKey),
kKey) ||
!TestPBKDF2("password", 8, "", 0, 2, EVP_sha256(), sizeof(kKey), kKey)) {
return false;
}
return 1;
return true;
}
/* Exercises test vectors taken from https://tools.ietf.org/html/rfc6070.
* Note that each of these test vectors uses SHA-1 as the digest. */
static int test_rfc6070_vectors(void) {
// Exercises test vectors taken from https://tools.ietf.org/html/rfc6070.
// Note that each of these test vectors uses SHA-1 as the digest.
static bool TestRFC6070Vectors() {
const uint8_t kKey1[] = {0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e,
0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60,
0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6};
@@ -107,29 +107,29 @@ static int test_rfc6070_vectors(void) {
const uint8_t kKey3[] = {0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3};
if (!test_PBKDF2("password", 8, "salt", 4, 1, EVP_sha1(), sizeof(kKey1),
kKey1) ||
!test_PBKDF2("password", 8, "salt", 4, 2, EVP_sha1(), sizeof(kKey2),
kKey2) ||
!test_PBKDF2("pass\0word", 9, "sa\0lt", 5, 4096, EVP_sha1(),
sizeof(kKey3), kKey3)) {
return 0;
if (!TestPBKDF2("password", 8, "salt", 4, 1, EVP_sha1(), sizeof(kKey1),
kKey1) ||
!TestPBKDF2("password", 8, "salt", 4, 2, EVP_sha1(), sizeof(kKey2),
kKey2) ||
!TestPBKDF2("pass\0word", 9, "sa\0lt", 5, 4096, EVP_sha1(),
sizeof(kKey3), kKey3)) {
return false;
}
return 1;
return true;
}
/* Tests key derivation using SHA-2 digests */
static int test_sha2(void) {
/* This test was taken from:
* http://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors */
// Tests key derivation using SHA-2 digests.
static bool TestSHA2() {
// This test was taken from:
// http://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors.
const uint8_t kKey1[] = {0xae, 0x4d, 0x0c, 0x95, 0xaf, 0x6b, 0x46, 0xd3,
0x2d, 0x0a, 0xdf, 0xf9, 0x28, 0xf0, 0x6d, 0xd0,
0x2a, 0x30, 0x3f, 0x8e, 0xf3, 0xc2, 0x51, 0xdf,
0xd6, 0xe2, 0xd8, 0x5a, 0x95, 0x47, 0x4c, 0x43};
/* This test was taken from:
* http://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors */
// This test was taken from:
// http://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors.
const uint8_t kKey2[] = {
0x8c, 0x05, 0x11, 0xf4, 0xc6, 0xe5, 0x97, 0xc6, 0xac, 0x63, 0x15,
0xd8, 0xf0, 0x36, 0x2e, 0x22, 0x5f, 0x3c, 0x50, 0x14, 0x95, 0xba,
@@ -138,38 +138,38 @@ static int test_sha2(void) {
0x75, 0xae, 0xfe, 0x30, 0x22, 0x5c, 0x58, 0x3a, 0x18, 0x6c, 0xd8,
0x2b, 0xd4, 0xda, 0xea, 0x97, 0x24, 0xa3, 0xd3, 0xb8};
if (!test_PBKDF2("password", 8, "salt", 4, 2, EVP_sha256(), sizeof(kKey1),
kKey1) ||
!test_PBKDF2("passwordPASSWORDpassword", 24,
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096,
EVP_sha512(), sizeof(kKey2), kKey2)) {
return 0;
if (!TestPBKDF2("password", 8, "salt", 4, 2, EVP_sha256(), sizeof(kKey1),
kKey1) ||
!TestPBKDF2("passwordPASSWORDpassword", 24,
"saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096,
EVP_sha512(), sizeof(kKey2), kKey2)) {
return false;
}
return 1;
return true;
}
int main(void) {
CRYPTO_library_init();
ERR_load_crypto_strings();
if (!test_empty_password()) {
fprintf(stderr, "test_empty_password failed\n");
if (!TestEmptyPassword()) {
fprintf(stderr, "TestEmptyPassword failed\n");
return 1;
}
if (!test_empty_salt()) {
fprintf(stderr, "test_empty_salt failed\n");
if (!TestEmptySalt()) {
fprintf(stderr, "TestEmptySalt failed\n");
return 1;
}
if (!test_rfc6070_vectors()) {
fprintf(stderr, "test_rfc6070_vectors failed\n");
if (!TestRFC6070Vectors()) {
fprintf(stderr, "TestRFC6070Vectors failed\n");
return 1;
}
if (!test_sha2()) {
fprintf(stderr, "test_sha2 failed\n");
if (!TestSHA2()) {
fprintf(stderr, "TestSHA2 failed\n");
return 1;
}
+5 -5
View File
@@ -92,9 +92,9 @@ int EVP_SignFinal(const EVP_MD_CTX *ctx, uint8_t *sig,
EVP_MD_CTX_cleanup(&tmp_ctx);
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!pkctx || EVP_PKEY_sign_init(pkctx) <= 0 ||
EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0 ||
EVP_PKEY_sign(pkctx, sig, &sig_len, m, m_len) <= 0) {
if (!pkctx || !EVP_PKEY_sign_init(pkctx) ||
!EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) ||
!EVP_PKEY_sign(pkctx, sig, &sig_len, m, m_len)) {
goto out;
}
*out_sig_len = sig_len;
@@ -138,8 +138,8 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const uint8_t *sig, size_t sig_len,
pkctx = EVP_PKEY_CTX_new(pkey, NULL);
if (!pkctx ||
EVP_PKEY_verify_init(pkctx) <= 0 ||
EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0) {
!EVP_PKEY_verify_init(pkctx) ||
!EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest)) {
goto out;
}
ret = EVP_PKEY_verify(pkctx, sig, sig_len, m, m_len);
+1 -1
View File
@@ -12,7 +12,7 @@ add_library(
add_executable(
hmac_test
hmac_test.c
hmac_test.cc
)
target_link_libraries(hmac_test crypto)
+28 -33
View File
@@ -76,7 +76,7 @@ uint8_t *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
}
HMAC_CTX_init(&ctx);
if (!HMAC_Init(&ctx, key, key_len, evp_md) ||
if (!HMAC_Init_ex(&ctx, key, key_len, evp_md, NULL) ||
!HMAC_Update(&ctx, data, data_len) ||
!HMAC_Final(&ctx, out, out_len)) {
out = NULL;
@@ -88,7 +88,6 @@ uint8_t *HMAC(const EVP_MD *evp_md, const void *key, size_t key_len,
void HMAC_CTX_init(HMAC_CTX *ctx) {
ctx->md = NULL;
ctx->key_length = 0;
EVP_MD_CTX_init(&ctx->i_ctx);
EVP_MD_CTX_init(&ctx->o_ctx);
EVP_MD_CTX_init(&ctx->md_ctx);
@@ -103,48 +102,44 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx) {
int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,
const EVP_MD *md, ENGINE *impl) {
unsigned i, reset = 0;
uint8_t pad[HMAC_MAX_MD_CBLOCK];
if (md != NULL) {
if (ctx->md == NULL && key == NULL && ctx->key_length == 0) {
/* TODO(eroman): Change the API instead of this hack.
* If a key hasn't yet been assigned to the context, then default to using
* an all-zero key. This is to work around callers of
* HMAC_Init_ex(key=NULL, key_len=0) intending to set a zero-length key.
* Rather than resulting in uninitialized memory reads, it will
* predictably use a zero key. */
memset(ctx->key, 0, sizeof(ctx->key));
}
reset = 1;
ctx->md = md;
} else {
if (md == NULL) {
md = ctx->md;
}
if (key != NULL) {
/* If either |key| is non-NULL or |md| has changed, initialize with a new key
* rather than rewinding the previous one.
*
* TODO(davidben,eroman): Passing the previous |md| with a NULL |key| is
* ambiguous between using the empty key and reusing the previous key. There
* exist callers which intend the latter, but the former is an awkward edge
* case. Fix to API to avoid this. */
if (md != ctx->md || key != NULL) {
size_t i;
uint8_t pad[HMAC_MAX_MD_CBLOCK];
uint8_t key_block[HMAC_MAX_MD_CBLOCK];
unsigned key_block_len;
size_t block_size = EVP_MD_block_size(md);
reset = 1;
assert(block_size <= sizeof(ctx->key));
assert(block_size <= sizeof(key_block));
if (block_size < key_len) {
/* Long keys are hashed. */
if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl) ||
!EVP_DigestUpdate(&ctx->md_ctx, key, key_len) ||
!EVP_DigestFinal_ex(&(ctx->md_ctx), ctx->key, &ctx->key_length)) {
!EVP_DigestFinal_ex(&ctx->md_ctx, key_block, &key_block_len)) {
goto err;
}
} else {
assert(key_len >= 0 && key_len <= sizeof(ctx->key));
memcpy(ctx->key, key, key_len);
ctx->key_length = key_len;
assert(key_len >= 0 && key_len <= sizeof(key_block));
memcpy(key_block, key, key_len);
key_block_len = (unsigned)key_len;
}
if (ctx->key_length != HMAC_MAX_MD_CBLOCK) {
memset(&ctx->key[ctx->key_length], 0, sizeof(ctx->key) - ctx->key_length);
/* Keys are then padded with zeros. */
if (key_block_len != HMAC_MAX_MD_CBLOCK) {
memset(&key_block[key_block_len], 0, sizeof(key_block) - key_block_len);
}
}
if (reset) {
for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++) {
pad[i] = 0x36 ^ ctx->key[i];
pad[i] = 0x36 ^ key_block[i];
}
if (!EVP_DigestInit_ex(&ctx->i_ctx, md, impl) ||
!EVP_DigestUpdate(&ctx->i_ctx, pad, EVP_MD_block_size(md))) {
@@ -152,12 +147,14 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, size_t key_len,
}
for (i = 0; i < HMAC_MAX_MD_CBLOCK; i++) {
pad[i] = 0x5c ^ ctx->key[i];
pad[i] = 0x5c ^ key_block[i];
}
if (!EVP_DigestInit_ex(&ctx->o_ctx, md, impl) ||
!EVP_DigestUpdate(&ctx->o_ctx, pad, EVP_MD_block_size(md))) {
goto err;
}
ctx->md = md;
}
if (!EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->i_ctx)) {
@@ -200,8 +197,6 @@ int HMAC_CTX_copy_ex(HMAC_CTX *dest, const HMAC_CTX *src) {
return 0;
}
memcpy(dest->key, src->key, HMAC_MAX_MD_CBLOCK);
dest->key_length = src->key_length;
dest->md = src->md;
return 1;
}
@@ -58,12 +58,17 @@
#include <stdio.h>
#include <string.h>
#include <string>
#include <openssl/crypto.h>
#include <openssl/digest.h>
#include <openssl/hmac.h>
#include <openssl/mem.h>
#include "../test/scoped_types.h"
struct test_st {
struct Test {
uint8_t key[16];
size_t key_len;
uint8_t data[64];
@@ -71,9 +76,7 @@ struct test_st {
const char *hex_digest;
};
#define NUM_TESTS 4
static const struct test_st kTests[NUM_TESTS] = {
static const Test kTests[] = {
{
"", 0, "More text test vectors to stuff up EBCDIC machines :-)", 54,
"e9139d1e6ee064ef8cf514fc7dc83e86",
@@ -110,109 +113,105 @@ static const struct test_st kTests[NUM_TESTS] = {
},
};
static char *to_hex(const uint8_t *md, size_t md_len) {
size_t i;
static char buf[80];
for (i = 0; i < md_len; i++) {
sprintf(&(buf[i * 2]), "%02x", md[i]);
static std::string ToHex(const uint8_t *md, size_t md_len) {
std::string ret;
for (size_t i = 0; i < md_len; i++) {
char buf[2 + 1 /* NUL */];
BIO_snprintf(buf, sizeof(buf), "%02x", md[i]);
ret.append(buf, 2);
}
return buf;
return ret;
}
int main(int argc, char *argv[]) {
unsigned i;
char *p;
int err = 0;
uint8_t out[EVP_MAX_MD_SIZE];
unsigned out_len;
CRYPTO_library_init();
for (i = 0; i < NUM_TESTS; i++) {
const struct test_st *test = &kTests[i];
for (unsigned i = 0; i < sizeof(kTests) / sizeof(kTests[0]); i++) {
const Test *test = &kTests[i];
/* Test using the one-shot API. */
// Test using the one-shot API.
if (NULL == HMAC(EVP_md5(), test->key, test->key_len, test->data,
test->data_len, out, &out_len)) {
fprintf(stderr, "%u: HMAC failed.\n", i);
err++;
continue;
}
p = to_hex(out, out_len);
if (strcmp(p, test->hex_digest) != 0) {
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
std::string out_hex = ToHex(out, out_len);
if (out_hex != test->hex_digest) {
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
test->hex_digest);
err++;
}
/* Test using HMAC_CTX. */
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
if (!HMAC_Init_ex(&ctx, test->key, test->key_len, EVP_md5(), NULL) ||
!HMAC_Update(&ctx, test->data, test->data_len) ||
!HMAC_Final(&ctx, out, &out_len)) {
// Test using HMAC_CTX.
ScopedHMAC_CTX ctx;
if (!HMAC_Init_ex(ctx.get(), test->key, test->key_len, EVP_md5(), NULL) ||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
!HMAC_Final(ctx.get(), out, &out_len)) {
fprintf(stderr, "%u: HMAC failed.\n", i);
err++;
HMAC_CTX_cleanup(&ctx);
continue;
}
p = to_hex(out, out_len);
if (strcmp(p, test->hex_digest) != 0) {
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
out_hex = ToHex(out, out_len);
if (out_hex != test->hex_digest) {
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
test->hex_digest);
err++;
}
/* Test that an HMAC_CTX may be reset with the same key. */
if (!HMAC_Init_ex(&ctx, NULL, 0, EVP_md5(), NULL) ||
!HMAC_Update(&ctx, test->data, test->data_len) ||
!HMAC_Final(&ctx, out, &out_len)) {
// Test that an HMAC_CTX may be reset with the same key.
if (!HMAC_Init_ex(ctx.get(), NULL, 0, EVP_md5(), NULL) ||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
!HMAC_Final(ctx.get(), out, &out_len)) {
fprintf(stderr, "%u: HMAC failed.\n", i);
err++;
HMAC_CTX_cleanup(&ctx);
continue;
}
p = to_hex(out, out_len);
if (strcmp(p, test->hex_digest) != 0) {
fprintf(stderr, "%u: got %s instead of %s\n", i, p, test->hex_digest);
out_hex = ToHex(out, out_len);
if (out_hex != test->hex_digest) {
fprintf(stderr, "%u: got %s instead of %s\n", i, out_hex.c_str(),
test->hex_digest);
err++;
}
HMAC_CTX_cleanup(&ctx);
}
/* Test that HMAC() uses the empty key when called with key = NULL. */
const struct test_st *test = &kTests[0];
// Test that HMAC() uses the empty key when called with key = NULL.
const Test *test = &kTests[0];
assert(test->key_len == 0);
if (NULL == HMAC(EVP_md5(), NULL, 0, test->data, test->data_len, out,
&out_len)) {
fprintf(stderr, "HMAC failed.\n");
err++;
} else {
p = to_hex(out, out_len);
if (strcmp(p, test->hex_digest) != 0) {
fprintf(stderr, "got %s instead of %s\n", p, test->hex_digest);
std::string out_hex = ToHex(out, out_len);
if (out_hex != test->hex_digest) {
fprintf(stderr, "got %s instead of %s\n", out_hex.c_str(),
test->hex_digest);
err++;
}
}
/* Test that HMAC_Init, etc., uses the empty key when called initially with
* key = NULL. */
// Test that HMAC_Init, etc., uses the empty key when called initially with
// key = NULL.
assert(test->key_len == 0);
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
if (!HMAC_Init_ex(&ctx, NULL, 0, EVP_md5(), NULL) ||
!HMAC_Update(&ctx, test->data, test->data_len) ||
!HMAC_Final(&ctx, out, &out_len)) {
ScopedHMAC_CTX ctx;
if (!HMAC_Init_ex(ctx.get(), NULL, 0, EVP_md5(), NULL) ||
!HMAC_Update(ctx.get(), test->data, test->data_len) ||
!HMAC_Final(ctx.get(), out, &out_len)) {
fprintf(stderr, "HMAC failed.\n");
err++;
} else {
p = to_hex(out, out_len);
if (strcmp(p, test->hex_digest) != 0) {
fprintf(stderr, "got %s instead of %s\n", p, test->hex_digest);
std::string out_hex = ToHex(out, out_len);
if (out_hex != test->hex_digest) {
fprintf(stderr, "got %s instead of %s\n", out_hex.c_str(),
test->hex_digest);
err++;
}
}
HMAC_CTX_cleanup(&ctx);
if (err) {
return 1;
+61
View File
@@ -111,6 +111,10 @@
#include <openssl/ex_data.h>
#if !defined(OPENSSL_WINDOWS)
#include <pthread.h>
#endif
#if defined(__cplusplus)
extern "C" {
#endif
@@ -295,6 +299,63 @@ static inline int constant_time_select_int(unsigned int mask, int a, int b) {
}
/* Thread-safe initialisation. */
#if !defined(OPENSSL_WINDOWS)
typedef pthread_once_t CRYPTO_once_t;
#define CRYPTO_ONCE_INIT PTHREAD_ONCE_INIT
#else
typedef int32_t CRYPTO_once_t;
#define CRYPTO_ONCE_INIT 0
#endif
/* CRYPTO_once calls |init| exactly once per process. This is thread-safe: if
* concurrent threads call |CRYPTO_once| with the same |CRYPTO_once_t| argument
* then they will block until |init| completes, but |init| will have only been
* called once.
*
* The |once| argument must be a |CRYPTO_once_t| that has been initialised with
* the value |CRYPTO_ONCE_INIT|. */
OPENSSL_EXPORT void CRYPTO_once(CRYPTO_once_t *once, void (*init)(void));
/* Thread local storage. */
/* thread_local_data_t enumerates the types of thread-local data that can be
* stored. */
typedef enum {
OPENSSL_THREAD_LOCAL_ERR = 0,
OPENSSL_THREAD_LOCAL_TEST,
NUM_OPENSSL_THREAD_LOCALS,
} thread_local_data_t;
/* thread_local_destructor_t is the type of a destructor function that will be
* called when a thread exits and its thread-local storage needs to be freed. */
typedef void (*thread_local_destructor_t)(void *);
/* CRYPTO_get_thread_local gets the pointer value that is stored for the
* current thread for the given index, or NULL if none has been set. */
OPENSSL_EXPORT void *CRYPTO_get_thread_local(thread_local_data_t value);
/* CRYPTO_set_thread_local sets a pointer value for the current thread at the
* given index. This function should only be called once per thread for a given
* |index|: rather than update the pointer value itself, update the data that
* is pointed to.
*
* The destructor function will be called when a thread exits to free this
* thread-local data. All calls to |CRYPTO_set_thread_local| with the same
* |index| should have the same |destructor| argument. The destructor may be
* called with a NULL argument if a thread that never set a thread-local
* pointer for |index|, exits. The destructor may be called concurrently with
* different arguments.
*
* This function returns one on success or zero on error. If it returns zero
* then |destructor| has been called with |value| already. */
OPENSSL_EXPORT int CRYPTO_set_thread_local(
thread_local_data_t index, void *value,
thread_local_destructor_t destructor);
#if defined(__cplusplus)
} /* extern C */
#endif
+1 -1
View File
@@ -66,7 +66,7 @@
#if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3)
#include <Windows.h>
#include <windows.h>
#pragma warning(pop)
#else
#include <strings.h>
+2 -2
View File
@@ -42,8 +42,8 @@
# below and combine it with reduction algorithm from x86 module.
# Performance improvement over previous version varies from 65% on
# Snapdragon S4 to 110% on Cortex A9. In absolute terms Cortex A8
# processes one byte in 8.45 cycles, A9 - in 10.2, Snapdragon S4 -
# in 9.33.
# processes one byte in 8.45 cycles, A9 - in 10.2, A15 - in 7.63,
# Snapdragon S4 - in 9.33.
#
# Câmara, D.; Gouvêa, C. P. L.; López, J. & Dahab, R.: Fast Software
# Polynomial Multiplication on ARM Processors using the NEON Engine.
+2 -2
View File
@@ -131,8 +131,8 @@ require "x86asm.pl";
&asm_init($ARGV[0],"ghash-x86.pl",$x86only = $ARGV[$#ARGV] eq "386");
$sse2=1;
#for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
$sse2=0;
for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
($Zhh,$Zhl,$Zlh,$Zll) = ("ebp","edx","ecx","ebx");
$inp = "edi";
-167
View File
@@ -1,167 +0,0 @@
#!/usr/bin/env perl
# PowerPC assembler distiller by <appro>.
my $flavour = shift;
my $output = shift;
open STDOUT,">$output" || die "can't open $output: $!";
my %GLOBALS;
my $dotinlocallabels=($flavour=~/linux/)?1:0;
################################################################
# directives which need special treatment on different platforms
################################################################
my $globl = sub {
my $junk = shift;
my $name = shift;
my $global = \$GLOBALS{$name};
my $ret;
$name =~ s|^[\.\_]||;
SWITCH: for ($flavour) {
/aix/ && do { $name = ".$name";
last;
};
/osx/ && do { $name = "_$name";
last;
};
/linux.*(32|64le)/
&& do { $ret .= ".globl $name\n";
$ret .= ".type $name,\@function";
last;
};
/linux.*64/ && do { $ret .= ".globl $name\n";
$ret .= ".type $name,\@function\n";
$ret .= ".section \".opd\",\"aw\"\n";
$ret .= ".align 3\n";
$ret .= "$name:\n";
$ret .= ".quad .$name,.TOC.\@tocbase,0\n";
$ret .= ".previous\n";
$name = ".$name";
last;
};
}
$ret = ".globl $name" if (!$ret);
$$global = $name;
$ret;
};
my $text = sub {
my $ret = ($flavour =~ /aix/) ? ".csect" : ".text";
$ret = ".abiversion 2\n".$ret if ($flavour =~ /linux.*64le/);
$ret;
};
my $machine = sub {
my $junk = shift;
my $arch = shift;
if ($flavour =~ /osx/)
{ $arch =~ s/\"//g;
$arch = ($flavour=~/64/) ? "ppc970-64" : "ppc970" if ($arch eq "any");
}
".machine $arch";
};
my $size = sub {
if ($flavour =~ /linux/)
{ shift;
my $name = shift; $name =~ s|^[\.\_]||;
my $ret = ".size $name,.-".($flavour=~/64$/?".":"").$name;
$ret .= "\n.size .$name,.-.$name" if ($flavour=~/64$/);
$ret;
}
else
{ ""; }
};
my $asciz = sub {
shift;
my $line = join(",",@_);
if ($line =~ /^"(.*)"$/)
{ ".byte " . join(",",unpack("C*",$1),0) . "\n.align 2"; }
else
{ ""; }
};
################################################################
# simplified mnemonics not handled by at least one assembler
################################################################
my $cmplw = sub {
my $f = shift;
my $cr = 0; $cr = shift if ($#_>1);
# Some out-of-date 32-bit GNU assembler just can't handle cmplw...
($flavour =~ /linux.*32/) ?
" .long ".sprintf "0x%x",31<<26|$cr<<23|$_[0]<<16|$_[1]<<11|64 :
" cmplw ".join(',',$cr,@_);
};
my $bdnz = sub {
my $f = shift;
my $bo = $f=~/[\+\-]/ ? 16+9 : 16; # optional "to be taken" hint
" bc $bo,0,".shift;
} if ($flavour!~/linux/);
my $bltlr = sub {
my $f = shift;
my $bo = $f=~/\-/ ? 12+2 : 12; # optional "not to be taken" hint
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
" .long ".sprintf "0x%x",19<<26|$bo<<21|16<<1 :
" bclr $bo,0";
};
my $bnelr = sub {
my $f = shift;
my $bo = $f=~/\-/ ? 4+2 : 4; # optional "not to be taken" hint
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
" .long ".sprintf "0x%x",19<<26|$bo<<21|2<<16|16<<1 :
" bclr $bo,2";
};
my $beqlr = sub {
my $f = shift;
my $bo = $f=~/-/ ? 12+2 : 12; # optional "not to be taken" hint
($flavour =~ /linux/) ? # GNU as doesn't allow most recent hints
" .long ".sprintf "0x%X",19<<26|$bo<<21|2<<16|16<<1 :
" bclr $bo,2";
};
# GNU assembler can't handle extrdi rA,rS,16,48, or when sum of last two
# arguments is 64, with "operand out of range" error.
my $extrdi = sub {
my ($f,$ra,$rs,$n,$b) = @_;
$b = ($b+$n)&63; $n = 64-$n;
" rldicl $ra,$rs,$b,$n";
};
while($line=<>) {
$line =~ s|[#!;].*$||; # get rid of asm-style comments...
$line =~ s|/\*.*\*/||; # ... and C-style comments...
$line =~ s|^\s+||; # ... and skip white spaces in beginning...
$line =~ s|\s+$||; # ... and at the end
{
$line =~ s|\b\.L(\w+)|L$1|g; # common denominator for Locallabel
$line =~ s|\bL(\w+)|\.L$1|g if ($dotinlocallabels);
}
{
$line =~ s|(^[\.\w]+)\:\s*||;
my $label = $1;
if ($label) {
printf "%s:",($GLOBALS{$label} or $label);
printf "\n.localentry\t$GLOBALS{$label},0" if ($GLOBALS{$label} && $flavour =~ /linux.*64le/);
}
}
{
$line =~ s|^\s*(\.?)(\w+)([\.\+\-]?)\s*||;
my $c = $1; $c = "\t" if ($c eq "");
my $mnemonic = $2;
my $f = $3;
my $opcode = eval("\$$mnemonic");
$line =~ s|\bc?[rf]([0-9]+)\b|$1|g if ($c ne "." and $flavour !~ /osx/);
if (ref($opcode) eq 'CODE') { $line = &$opcode($f,split(',',$line)); }
elsif ($mnemonic) { $line = $c.$mnemonic.$f."\t".$line; }
}
print $line if ($line);
print "\n";
}
close STDOUT;
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -497,7 +497,11 @@ my %globals;
$self->{value} = $dir . "\t" . $line;
if ($dir =~ /\.extern/) {
$self->{value} = ""; # swallow extern
if ($flavour eq "elf") {
$self->{value} .= "\n.hidden $line";
} else {
$self->{value} = "";
}
} elsif (!$elf && $dir =~ /\.type/) {
$self->{value} = "";
$self->{value} = ".def\t" . ($globals{$1} or $1) . ";\t" .
+6 -9
View File
@@ -18,10 +18,10 @@ sub ::generic
if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no []
{ $opcode="mov"; }
elsif ($opcode !~ /movq/)
elsif ($opcode !~ /mov[dq]$/)
{ # fix xmm references
$arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
$arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
$arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[-1]=~/\bxmm[0-7]\b/i);
$arg[-1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
}
&::emit($opcode,@arg);
@@ -160,16 +160,13 @@ sub ::public_label
{ push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
sub ::data_byte
{ push(@out,("DB\t").join(',',@_)."\n"); }
{ push(@out,("DB\t").join(',',splice(@_,0,16))."\n") while(@_); }
sub ::data_short
{ push(@out,("DW\t").join(',',@_)."\n"); }
{ push(@out,("DW\t").join(',',splice(@_,0,8))."\n") while(@_); }
sub ::data_word
{ # MASM can't handle long lines, so emit one word at a time.
foreach(@_)
{ push(@out,"DD\t$_\n"); }
}
{ push(@out,("DD\t").join(',',splice(@_,0,4))."\n") while(@_); }
sub ::align
{ push(@out,"ALIGN\t$_[0]\n"); }
+1 -1
View File
@@ -21,7 +21,7 @@
#pragma warning(push, 3)
#include <Windows.h>
#include <windows.h>
/* #define needed to link in RtlGenRandom(), a.k.a. SystemFunction036. See the
* "Community Additions" comment on MSDN here:
-26
View File
@@ -502,32 +502,6 @@ asm_RC4_set_key:
mov %eax,-4($dat)
ret
.size asm_RC4_set_key,.-asm_RC4_set_key
.globl RC4_options
.type RC4_options,\@abi-omnipotent
.align 16
RC4_options:
lea .Lopts(%rip),%rax
mov OPENSSL_ia32cap_P(%rip),%rdx
mov (%rdx),%edx
bt \$20,%edx
jc .L8xchar
bt \$30,%edx
jnc .Ldone
add \$25,%rax
ret
.L8xchar:
add \$12,%rax
.Ldone:
ret
.align 64
.Lopts:
.asciz "rc4(8x,int)"
.asciz "rc4(8x,char)"
.asciz "rc4(16x,int)"
.asciz "RC4 for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
.align 64
.size RC4_options,.-RC4_options
___
# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
+5 -38
View File
@@ -67,8 +67,6 @@
#error "Unknown word size"
#endif
#define RC4_INT uint32_t
/* RC4 as implemented from a posting from
* Newsgroups: sci.crypt
@@ -78,44 +76,14 @@
* Date: Wed, 14 Sep 1994 06:35:31 GMT */
void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
register RC4_INT *d;
register RC4_INT x, y, tx, ty;
uint32_t *d;
uint32_t x, y, tx, ty;
size_t i;
x = key->x;
y = key->y;
d = key->data;
#if defined(RC4_CHUNK)
/* The original reason for implementing this(*) was the fact that
* pre-21164a Alpha CPUs don't have byte load/store instructions
* and e.g. a byte store has to be done with 64-bit load, shift,
* and, or and finally 64-bit store. Peaking data and operating
* at natural word size made it possible to reduce amount of
* instructions as well as to perform early read-ahead without
* suffering from RAW (read-after-write) hazard. This resulted
* in ~40%(**) performance improvement on 21064 box with gcc.
* But it's not only Alpha users who win here:-) Thanks to the
* early-n-wide read-ahead this implementation also exhibits
* >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending
* on sizeof(RC4_INT)).
*
* (*) "this" means code which recognizes the case when input
* and output pointers appear to be aligned at natural CPU
* word boundary
* (**) i.e. according to 'apps/openssl speed rc4' benchmark,
* crypto/rc4/rc4speed.c exhibits almost 70% speed-up...
*
* Cavets.
*
* - RC4_CHUNK="unsigned long long" should be a #1 choice for
* UltraSPARC. Unfortunately gcc generates very slow code
* (2.5-3 times slower than one generated by Sun's WorkShop
* C) and therefore gcc (at least 2.95 and earlier) should
* always be told that RC4_CHUNK="unsigned long".
*
* <appro@fy.chalmers.se> */
#define RC4_STEP \
(x = (x + 1) & 0xff, tx = d[x], y = (tx + y) & 0xff, ty = d[y], d[y] = tx, \
d[x] = ty, (RC4_CHUNK)d[(tx + ty) & 0xff])
@@ -255,7 +223,6 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
return;
}
}
#endif
#define LOOP(in, out) \
x = ((x + 1) & 0xff); \
tx = d[x]; \
@@ -328,9 +295,9 @@ void RC4(RC4_KEY *key, size_t len, const uint8_t *in, uint8_t *out) {
}
void RC4_set_key(RC4_KEY *rc4key, unsigned len, const uint8_t *key) {
register RC4_INT tmp;
register int id1, id2;
register RC4_INT *d;
uint32_t tmp;
int id1, id2;
uint32_t *d;
unsigned int i;
d = &rc4key->data[0];
-9
View File
@@ -113,15 +113,6 @@ int RSA_padding_add_none(uint8_t *to, unsigned to_len, const uint8_t *from,
int RSA_padding_check_none(uint8_t *to, unsigned to_len, const uint8_t *from,
unsigned from_len);
/* RSA_verify_PKCS1_PSS_mgf1 */
int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const uint8_t *mHash,
const EVP_MD *Hash, const EVP_MD *mgf1Hash,
const uint8_t *EM, int sLen);
int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, uint8_t *EM, const uint8_t *mHash,
const EVP_MD *Hash, const EVP_MD *mgf1Hash,
int sLen);
/* RSA_private_transform calls either the method-specific |private_transform|
* function (if given) or the generic one. See the comment for
* |private_transform| in |rsa_meth_st|. */
+5 -11
View File
@@ -125,7 +125,7 @@ void RSA_free(RSA *rsa) {
}
METHOD_unref(rsa->meth);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, rsa, &rsa->ex_data);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, rsa, &rsa->ex_data);
if (rsa->n != NULL) {
BN_clear_free(rsa->n);
@@ -347,12 +347,6 @@ static const struct pkcs1_sig_prefix kPKCS1SigPrefixes[] = {
{0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40},
},
{
NID_ripemd160,
14,
{0x30, 0x20, 0x30, 0x08, 0x06, 0x06, 0x28, 0xcf, 0x06, 0x03, 0x00, 0x31,
0x04, 0x14},
},
{
NID_undef, 0, {0},
},
@@ -375,7 +369,7 @@ static int pkcs1_prefixed_msg(uint8_t **out_msg, size_t *out_msg_len,
if (hash_nid == NID_md5_sha1) {
/* Special case: SSL signature, just check the length. */
if (msg_len != SSL_SIG_LENGTH) {
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_INVALID_MESSAGE_LENGTH);
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_INVALID_MESSAGE_LENGTH);
return 0;
}
@@ -395,19 +389,19 @@ static int pkcs1_prefixed_msg(uint8_t **out_msg, size_t *out_msg_len,
}
if (prefix == NULL) {
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_UNKNOWN_ALGORITHM_TYPE);
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_UNKNOWN_ALGORITHM_TYPE);
return 0;
}
signed_msg_len = prefix_len + msg_len;
if (signed_msg_len < prefix_len) {
OPENSSL_PUT_ERROR(RSA, RSA_sign, RSA_R_TOO_LONG);
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, RSA_R_TOO_LONG);
return 0;
}
signed_msg = OPENSSL_malloc(signed_msg_len);
if (!signed_msg) {
OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_MALLOC_FAILURE);
OPENSSL_PUT_ERROR(RSA, pkcs1_prefixed_msg, ERR_R_MALLOC_FAILURE);
return 0;
}
+1 -3
View File
@@ -360,8 +360,7 @@ static int sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
}
if (!RSA_private_transform(rsa, out, buf, rsa_size)) {
OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR);
goto err;
goto err;
}
*out_len = rsa_size;
@@ -400,7 +399,6 @@ static int decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
}
if (!RSA_private_transform(rsa, buf, in, rsa_size)) {
OPENSSL_PUT_ERROR(RSA, decrypt, ERR_R_INTERNAL_ERROR);
goto err;
}
+1 -1
View File
@@ -450,7 +450,7 @@ sub sha1msg2 { sha1op38(0xca,@_); }
&sub ("esp",32);
&movdqu ($ABCD,&QWP(0,$ctx));
&movd ($E,&QWP(16,$ctx));
&movd ($E,&DWP(16,$ctx));
&and ("esp",-32);
&movdqa ($BSWAP,&QWP(0x50,$tmp1)); # byte-n-word swap
+4 -1
View File
@@ -60,7 +60,9 @@
# is ~2.5x larger and there are some redundant instructions executed
# when processing last block, improvement is not as big for smallest
# blocks, only ~30%. Snapdragon S4 is a tad faster, 6.4 cycles per
# byte, which is also >80% faster than integer-only code.
# byte, which is also >80% faster than integer-only code. Cortex-A15
# is even faster spending 5.6 cycles per byte outperforming integer-
# only code by factor of 2.
# May 2014.
#
@@ -642,6 +644,7 @@ ___
$code.=<<___;
#if __ARM_MAX_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___
+1
View File
@@ -621,6 +621,7 @@ $code.=<<___;
.align 2
#if __ARM_MAX_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___
+4 -10
View File
@@ -34,16 +34,9 @@
# terms it's 22.6 cycles per byte, which is disappointing result.
# Technical writers asserted that 3-way S4 pipeline can sustain
# multiple NEON instructions per cycle, but dual NEON issue could
# not be observed, and for NEON-only sequences IPC(*) was found to
# be limited by 1:-( 0.33 and 0.66 were measured for sequences with
# ILPs(*) of 1 and 2 respectively. This in turn means that you can
# even find yourself striving, as I did here, for achieving IPC
# adequate to one delivered by Cortex A8 [for reference, it's
# 0.5 for ILP of 1, and 1 for higher ILPs].
#
# (*) ILP, instruction-level parallelism, how many instructions
# *can* execute at the same time. IPC, instructions per cycle,
# indicates how many instructions actually execute.
# not be observed, see http://www.openssl.org/~appro/Snapdragon-S4.html
# for further details. On side note Cortex-A15 processes one byte in
# 16 cycles.
# Byte order [in]dependence. =========================================
#
@@ -599,6 +592,7 @@ $code.=<<___;
.align 2
#if __ARM_MAX_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___
+91
View File
@@ -0,0 +1,91 @@
/* Copyright (c) 2015, Google Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#ifndef OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
#define OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
#include <stdint.h>
#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/dh.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/mem.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include "stl_compat.h"
template<typename T, void (*func)(T*)>
struct OpenSSLDeleter {
void operator()(T *obj) {
func(obj);
}
};
template<typename T>
struct OpenSSLFree {
void operator()(T *buf) {
OPENSSL_free(buf);
}
};
template<typename T, void (*func)(T*)>
using ScopedOpenSSLType = bssl::unique_ptr<T, OpenSSLDeleter<T, func>>;
template<typename T, typename CleanupRet, void (*init_func)(T*),
CleanupRet (*cleanup_func)(T*)>
class ScopedOpenSSLContext {
public:
ScopedOpenSSLContext() {
init_func(&ctx_);
}
~ScopedOpenSSLContext() {
cleanup_func(&ctx_);
}
T *get() { return &ctx_; }
const T *get() const { return &ctx_; }
void Reset() {
cleanup_func(&ctx_);
init_func(&ctx_);
}
private:
T ctx_;
};
using ScopedBIO = ScopedOpenSSLType<BIO, BIO_vfree>;
using ScopedBIGNUM = ScopedOpenSSLType<BIGNUM, BN_free>;
using ScopedBN_CTX = ScopedOpenSSLType<BN_CTX, BN_CTX_free>;
using ScopedBN_MONT_CTX = ScopedOpenSSLType<BN_MONT_CTX, BN_MONT_CTX_free>;
using ScopedDH = ScopedOpenSSLType<DH, DH_free>;
using ScopedEVP_PKEY = ScopedOpenSSLType<EVP_PKEY, EVP_PKEY_free>;
using ScopedPKCS8_PRIV_KEY_INFO = ScopedOpenSSLType<PKCS8_PRIV_KEY_INFO,
PKCS8_PRIV_KEY_INFO_free>;
using ScopedRSA = ScopedOpenSSLType<RSA, RSA_free>;
using ScopedX509_ALGOR = ScopedOpenSSLType<X509_ALGOR, X509_ALGOR_free>;
using ScopedEVP_MD_CTX = ScopedOpenSSLContext<EVP_MD_CTX, int, EVP_MD_CTX_init,
EVP_MD_CTX_cleanup>;
using ScopedHMAC_CTX = ScopedOpenSSLContext<HMAC_CTX, void, HMAC_CTX_init,
HMAC_CTX_cleanup>;
using ScopedOpenSSLBytes = bssl::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>;
#endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
+139
View File
@@ -0,0 +1,139 @@
/* Copyright (c) 2015, Google Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#ifndef OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
#define OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
#include <assert.h>
#include <vector>
// This header contains re-implementations of library functions from C++11. They
// will be replaced with their standard counterparts once Chromium has C++11
// library support in its toolchain.
namespace bssl {
// vector_data is a reimplementation of |std::vector::data| from C++11.
template <class T>
static T *vector_data(std::vector<T> *out) {
return out->empty() ? nullptr : &(*out)[0];
}
// remove_reference is a reimplementation of |std::remove_reference| from C++11.
template <class T>
struct remove_reference {
using type = T;
};
template <class T>
struct remove_reference<T&> {
using type = T;
};
template <class T>
struct remove_reference<T&&> {
using type = T;
};
// move is a reimplementation of |std::move| from C++11.
template <class T>
typename remove_reference<T>::type &&move(T &&t) {
return static_cast<typename remove_reference<T>::type&&>(t);
}
// default_delete is a partial reimplementation of |std::default_delete| from
// C++11.
template <class T>
struct default_delete {
void operator()(T *t) const {
enum { type_must_be_complete = sizeof(T) };
delete t;
}
};
// nullptr_t is |std::nullptr_t| from C++11.
using nullptr_t = decltype(nullptr);
// unique_ptr is a partial reimplementation of |std::unique_ptr| from C++11. It
// intentionally does not support stateful deleters to avoid having to bother
// with the empty member optimization.
template <class T, class Deleter = default_delete<T>>
class unique_ptr {
public:
unique_ptr() : ptr_(nullptr) {}
unique_ptr(nullptr_t) : ptr_(nullptr) {}
unique_ptr(T *ptr) : ptr_(ptr) {}
unique_ptr(const unique_ptr &u) = delete;
unique_ptr(unique_ptr &&u) : ptr_(nullptr) {
reset(u.release());
}
~unique_ptr() {
reset();
}
unique_ptr &operator=(nullptr_t) {
reset();
return *this;
}
unique_ptr &operator=(unique_ptr &&u) {
reset(u.release());
return *this;
}
unique_ptr& operator=(const unique_ptr &u) = delete;
explicit operator bool() const {
return ptr_ != nullptr;
}
T &operator*() const {
assert(ptr_ != nullptr);
return *ptr_;
}
T *operator->() const {
assert(ptr_ != nullptr);
return ptr_;
}
T *get() const {
return ptr_;
}
T *release() {
T *ptr = ptr_;
ptr_ = nullptr;
return ptr;
}
void reset(T *ptr = nullptr) {
if (ptr_ != nullptr) {
Deleter()(ptr_);
}
ptr_ = ptr;
}
private:
T *ptr_;
};
} // namespace bssl
#endif // OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
+7 -16
View File
@@ -61,32 +61,23 @@
#if defined(OPENSSL_WINDOWS)
#pragma warning(push, 3)
#include <Windows.h>
#include <windows.h>
#pragma warning(pop)
#endif
#include <openssl/mem.h>
#include <openssl/type_check.h>
#define CRYPTO_LOCK_ITEM(x) #x
/* lock_names contains the names of all the locks defined in thread.h. */
static const char *const lock_names[] = {
"<<ERROR>>", "err", "ex_data", "x509",
"x509_info", "x509_pkey", "x509_crl", "x509_req",
"dsa", "rsa", "evp_pkey", "x509_store",
"ssl_ctx", "ssl_cert", "ssl_session", "ssl_sess_cert",
"ssl", "ssl_method", "rand", "rand2",
"debug_malloc", "BIO", "gethostbyname", "getservbyname",
"readdir", "RSA_blinding", "dh", "debug_malloc2",
"dso", "dynlock", "engine", "ui",
"ecdsa", "ec", "ecdh", "bn",
"ec_pre_comp", "store", "comp", "fips",
"fips2", "obj",
CRYPTO_LOCK_LIST
};
OPENSSL_COMPILE_ASSERT(CRYPTO_NUM_LOCKS ==
sizeof(lock_names) / sizeof(lock_names[0]),
CRYPTO_NUM_LOCKS_inconsistent);
#undef CRYPTO_LOCK_ITEM
#define CRYPTO_NUM_LOCKS (sizeof(lock_names) / sizeof(lock_names[0]))
static void (*locking_callback)(int mode, int lock_num, const char *file,
int line) = 0;

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