diff options
| author | miod <> | 2014-06-20 10:38:22 +0000 | 
|---|---|---|
| committer | miod <> | 2014-06-20 10:38:22 +0000 | 
| commit | e2f4d1f11674f0d450848c4298ba165b2e5bbd7c (patch) | |
| tree | 8729ae02a63602619107aa9cd246443bb42c429e | |
| parent | 8eee83a2cf1dc10b0fd2b0879ccbe9d5b1359462 (diff) | |
| download | openbsd-e2f4d1f11674f0d450848c4298ba165b2e5bbd7c.tar.gz openbsd-e2f4d1f11674f0d450848c4298ba165b2e5bbd7c.tar.bz2 openbsd-e2f4d1f11674f0d450848c4298ba165b2e5bbd7c.zip | |
Simple regress test for the amd64 bn_mul_mont bug found by Joyent
( https://github.com/joyent/node/issues/7704 ), about to be fixed in
libcrypto.
| -rw-r--r-- | src/regress/lib/libcrypto/bn/Makefile | 5 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/bn/mont/Makefile | 9 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/bn/mont/mont.c | 74 | 
3 files changed, 86 insertions, 2 deletions
| diff --git a/src/regress/lib/libcrypto/bn/Makefile b/src/regress/lib/libcrypto/bn/Makefile index a19e456892..93c3962e12 100644 --- a/src/regress/lib/libcrypto/bn/Makefile +++ b/src/regress/lib/libcrypto/bn/Makefile | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/06/20 10:30:40 miod Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2014/06/20 10:38:22 miod Exp $ | 
| 2 | 2 | ||
| 3 | SUBDIR= \ | 3 | SUBDIR= \ | 
| 4 | general | 4 | general \ | 
| 5 | mont | ||
| 5 | 6 | ||
| 6 | install: | 7 | install: | 
| 7 | 8 | ||
| diff --git a/src/regress/lib/libcrypto/bn/mont/Makefile b/src/regress/lib/libcrypto/bn/mont/Makefile new file mode 100644 index 0000000000..3a946b41a8 --- /dev/null +++ b/src/regress/lib/libcrypto/bn/mont/Makefile | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/06/20 10:38:22 miod Exp $ | ||
| 2 | |||
| 3 | PROG= mont | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
| diff --git a/src/regress/lib/libcrypto/bn/mont/mont.c b/src/regress/lib/libcrypto/bn/mont/mont.c new file mode 100644 index 0000000000..2a60c022c3 --- /dev/null +++ b/src/regress/lib/libcrypto/bn/mont/mont.c | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | /* $OpenBSD: mont.c,v 1.1 2014/06/20 10:38:22 miod Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2014 Miodrag Vallat. | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | #include <err.h> | ||
| 23 | |||
| 24 | #include <openssl/bn.h> | ||
| 25 | #include <openssl/crypto.h> | ||
| 26 | #include <openssl/dh.h> | ||
| 27 | #include <openssl/err.h> | ||
| 28 | #include <openssl/rand.h> | ||
| 29 | |||
| 30 | /* | ||
| 31 | * Test for proper bn_mul_mont behaviour when operands are of vastly different | ||
| 32 | * sizes. | ||
| 33 | */ | ||
| 34 | |||
| 35 | int | ||
| 36 | main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | DH *dh; | ||
| 39 | unsigned char *key, r[32 + 16 * 8]; | ||
| 40 | size_t privsz; | ||
| 41 | |||
| 42 | RAND_bytes(r, sizeof r); | ||
| 43 | |||
| 44 | for (privsz = 32; privsz <= sizeof(r); privsz += 8) { | ||
| 45 | dh = DH_new(); | ||
| 46 | if (dh == NULL) | ||
| 47 | goto err; | ||
| 48 | if (DH_generate_parameters_ex(dh, 32, DH_GENERATOR_2, | ||
| 49 | NULL) == 0) | ||
| 50 | goto err; | ||
| 51 | |||
| 52 | /* force private key to be much larger than public one */ | ||
| 53 | dh->priv_key = BN_bin2bn(r, privsz, NULL); | ||
| 54 | if (dh->priv_key == NULL) | ||
| 55 | goto err; | ||
| 56 | |||
| 57 | if (DH_generate_key(dh) == 0) | ||
| 58 | goto err; | ||
| 59 | key = malloc(DH_size(dh)); | ||
| 60 | if (key == NULL) | ||
| 61 | err(1, "malloc"); | ||
| 62 | if (DH_compute_key(key, dh->pub_key, dh) == -1) | ||
| 63 | goto err; | ||
| 64 | |||
| 65 | free(key); | ||
| 66 | DH_free(dh); | ||
| 67 | } | ||
| 68 | |||
| 69 | return 0; | ||
| 70 | |||
| 71 | err: | ||
| 72 | ERR_print_errors_fp(stderr); | ||
| 73 | return 1; | ||
| 74 | } | ||
