diff options
| author | cvs2svn <admin@example.com> | 2018-11-07 01:08:50 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2018-11-07 01:08:50 +0000 |
| commit | 2035faf3f8aa95b888d9416c3cc7328c0ea18beb (patch) | |
| tree | f08a08d357c5d30455c569890f747c1d9b241316 /src/regress/lib | |
| parent | be03b61c1b8f59ccdd34dbe5f6c6b30de697d28b (diff) | |
| download | openbsd-bluhm_20181106.tar.gz openbsd-bluhm_20181106.tar.bz2 openbsd-bluhm_20181106.zip | |
This commit was manufactured by cvs2git to create tag 'bluhm_20181106'.bluhm_20181106
Diffstat (limited to '')
380 files changed, 0 insertions, 56003 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile deleted file mode 100644 index 0530008c49..0000000000 --- a/src/regress/lib/libc/Makefile +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.51 2017/10/15 12:15:30 visa Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= _setjmp | ||
| 4 | SUBDIR+= alloca arc4random-fork atexit | ||
| 5 | SUBDIR+= basename | ||
| 6 | SUBDIR+= cephes cxa-atexit | ||
| 7 | SUBDIR+= db dirname | ||
| 8 | SUBDIR+= env explicit_bzero | ||
| 9 | SUBDIR+= fmemopen fnmatch fpclassify | ||
| 10 | SUBDIR+= getaddrinfo getcap getopt_long glob | ||
| 11 | SUBDIR+= hsearch | ||
| 12 | SUBDIR+= ieeefp ifnameindex | ||
| 13 | SUBDIR+= ldexp longjmp locale | ||
| 14 | SUBDIR+= malloc mkstemp modf | ||
| 15 | SUBDIR+= netdb | ||
| 16 | SUBDIR+= open_memstream orientation | ||
| 17 | SUBDIR+= popen printf | ||
| 18 | SUBDIR+= qsort | ||
| 19 | SUBDIR+= regex | ||
| 20 | SUBDIR+= setjmp setjmp-signal sigsetjmp sprintf stdio_threading | ||
| 21 | SUBDIR+= stpncpy strerror strlcat strlcpy strnlen strtod strtol strtonum | ||
| 22 | SUBDIR+= telldir time timingsafe | ||
| 23 | SUBDIR+= vis | ||
| 24 | |||
| 25 | .if defined(REGRESS_FULL) || make(clean) || make(cleandir) || make(obj) | ||
| 26 | SUBDIR+= setjmp-fpu | ||
| 27 | .endif | ||
| 28 | |||
| 29 | .if exists(arch/${MACHINE_ARCH}) | ||
| 30 | SUBDIR+= arch/${MACHINE_ARCH} | ||
| 31 | .endif | ||
| 32 | |||
| 33 | install: | ||
| 34 | |||
| 35 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/_setjmp/Makefile b/src/regress/lib/libc/_setjmp/Makefile deleted file mode 100644 index 5d58242523..0000000000 --- a/src/regress/lib/libc/_setjmp/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:38:44 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= _setjmptest | ||
| 5 | SRCS= jmptest.c | ||
| 6 | |||
| 7 | CFLAGS+= -DTEST_U_SETJMP | ||
| 8 | |||
| 9 | .PATH: ${.CURDIR}/../setjmp | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/Makefile b/src/regress/lib/libc/alloca/Makefile deleted file mode 100644 index f31417cda7..0000000000 --- a/src/regress/lib/libc/alloca/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/02/12 06:49:04 mickey Exp $ | ||
| 2 | |||
| 3 | PROG= alloca | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/alloca.c b/src/regress/lib/libc/alloca/alloca.c deleted file mode 100644 index 54fa90edae..0000000000 --- a/src/regress/lib/libc/alloca/alloca.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | /* $OpenBSD: alloca.c,v 1.7 2004/03/10 01:17:45 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Michael Shalayeff, 2003, Public Domain. */ | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char *argv[]) | ||
| 11 | { | ||
| 12 | char *q, *p; | ||
| 13 | |||
| 14 | p = alloca(41); | ||
| 15 | strlcpy(p, "hellow world", 41); | ||
| 16 | |||
| 17 | q = alloca(53); | ||
| 18 | strlcpy(q, "hellow world", 53); | ||
| 19 | |||
| 20 | exit(strcmp(p, q)); | ||
| 21 | } | ||
diff --git a/src/regress/lib/libc/arc4random-fork/Makefile b/src/regress/lib/libc/arc4random-fork/Makefile deleted file mode 100644 index 05762e33ff..0000000000 --- a/src/regress/lib/libc/arc4random-fork/Makefile +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/06/18 08:24:00 matthew Exp $ | ||
| 2 | |||
| 3 | PROG= arc4random-fork | ||
| 4 | |||
| 5 | REGRESS_TARGETS= \ | ||
| 6 | run \ | ||
| 7 | run-buf \ | ||
| 8 | run-prefork \ | ||
| 9 | run-buf-prefork | ||
| 10 | |||
| 11 | run: ${PROG} | ||
| 12 | ./${PROG} | ||
| 13 | |||
| 14 | run-buf: ${PROG} | ||
| 15 | ./${PROG} -b | ||
| 16 | |||
| 17 | run-prefork: ${PROG} | ||
| 18 | ./${PROG} -p | ||
| 19 | |||
| 20 | run-buf-prefork: ${PROG} | ||
| 21 | ./${PROG} -bp | ||
| 22 | |||
| 23 | .PHONY: ${REGRESS_TARGETS} | ||
| 24 | |||
| 25 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c b/src/regress/lib/libc/arc4random-fork/arc4random-fork.c deleted file mode 100644 index 4bc9c634f1..0000000000 --- a/src/regress/lib/libc/arc4random-fork/arc4random-fork.c +++ /dev/null | |||
| @@ -1,171 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2014 Google Inc. | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <sys/mman.h> | ||
| 18 | #include <sys/wait.h> | ||
| 19 | #include <assert.h> | ||
| 20 | #include <err.h> | ||
| 21 | #include <errno.h> | ||
| 22 | #include <signal.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <stdint.h> | ||
| 27 | |||
| 28 | #define CHECK(x) assert(x) | ||
| 29 | #define CHECK_EQ(a, b) assert((a) == (b)) | ||
| 30 | #define CHECK_NE(a, b) assert((a) != (b)) | ||
| 31 | #define CHECK_GE(a, b) assert((a) >= (b)) | ||
| 32 | #define CHECK_LE(a, b) assert((a) <= (b)) | ||
| 33 | |||
| 34 | /* Test arc4random_buf(3) instead of arc4random(3). */ | ||
| 35 | static int flagbuf; | ||
| 36 | |||
| 37 | /* Initialize arc4random(3) before forking. */ | ||
| 38 | static int flagprefork; | ||
| 39 | |||
| 40 | enum { | ||
| 41 | N = 4096 | ||
| 42 | }; | ||
| 43 | |||
| 44 | typedef struct { | ||
| 45 | uint32_t x[N]; | ||
| 46 | } Buf; | ||
| 47 | |||
| 48 | static int | ||
| 49 | isfullbuf(const Buf *buf) | ||
| 50 | { | ||
| 51 | size_t i; | ||
| 52 | for (i = 0; i < N; i++) | ||
| 53 | if (buf->x[i]) | ||
| 54 | return (1); | ||
| 55 | return (0); | ||
| 56 | } | ||
| 57 | |||
| 58 | static void | ||
| 59 | fillbuf(Buf *buf) | ||
| 60 | { | ||
| 61 | if (flagbuf) { | ||
| 62 | arc4random_buf(buf->x, sizeof(buf->x)); | ||
| 63 | } else { | ||
| 64 | size_t i; | ||
| 65 | for (i = 0; i < N; i++) | ||
| 66 | buf->x[i] = arc4random(); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | static void | ||
| 71 | usage() | ||
| 72 | { | ||
| 73 | errx(1, "usage: arc4random-fork [-bp]"); | ||
| 74 | } | ||
| 75 | |||
| 76 | static pid_t | ||
| 77 | safewaitpid(pid_t pid, int *status, int options) | ||
| 78 | { | ||
| 79 | pid_t ret; | ||
| 80 | do { | ||
| 81 | ret = waitpid(pid, status, options); | ||
| 82 | } while (ret == -1 && errno == EINTR); | ||
| 83 | return (ret); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | main(int argc, char *argv[]) | ||
| 88 | { | ||
| 89 | int opt, status; | ||
| 90 | Buf *bufparent, *bufchildone, *bufchildtwo; | ||
| 91 | pid_t pidone, pidtwo; | ||
| 92 | size_t i, countone = 0, counttwo = 0, countkids = 0; | ||
| 93 | |||
| 94 | /* Ensure SIGCHLD isn't set to SIG_IGN. */ | ||
| 95 | const struct sigaction sa = { | ||
| 96 | .sa_handler = SIG_DFL, | ||
| 97 | }; | ||
| 98 | CHECK_EQ(0, sigaction(SIGCHLD, &sa, NULL)); | ||
| 99 | |||
| 100 | while ((opt = getopt(argc, argv, "bp")) != -1) { | ||
| 101 | switch (opt) { | ||
| 102 | case 'b': | ||
| 103 | flagbuf = 1; | ||
| 104 | break; | ||
| 105 | case 'p': | ||
| 106 | flagprefork = 1; | ||
| 107 | break; | ||
| 108 | default: | ||
| 109 | usage(); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | if (flagprefork) | ||
| 114 | arc4random(); | ||
| 115 | |||
| 116 | bufparent = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
| 117 | MAP_ANON|MAP_PRIVATE, -1, 0); | ||
| 118 | CHECK_NE(MAP_FAILED, bufparent); | ||
| 119 | |||
| 120 | bufchildone = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
| 121 | MAP_ANON|MAP_SHARED, -1, 0); | ||
| 122 | CHECK_NE(MAP_FAILED, bufchildone); | ||
| 123 | |||
| 124 | bufchildtwo = mmap(NULL, sizeof(Buf), PROT_READ|PROT_WRITE, | ||
| 125 | MAP_ANON|MAP_SHARED, -1, 0); | ||
| 126 | CHECK_NE(MAP_FAILED, bufchildtwo); | ||
| 127 | |||
| 128 | pidone = fork(); | ||
| 129 | CHECK_GE(pidone, 0); | ||
| 130 | if (pidone == 0) { | ||
| 131 | fillbuf(bufchildone); | ||
| 132 | _exit(0); | ||
| 133 | } | ||
| 134 | |||
| 135 | pidtwo = fork(); | ||
| 136 | CHECK_GE(pidtwo, 0); | ||
| 137 | if (pidtwo == 0) { | ||
| 138 | fillbuf(bufchildtwo); | ||
| 139 | _exit(0); | ||
| 140 | } | ||
| 141 | |||
| 142 | fillbuf(bufparent); | ||
| 143 | |||
| 144 | CHECK_EQ(pidone, safewaitpid(pidone, &status, 0)); | ||
| 145 | CHECK(WIFEXITED(status)); | ||
| 146 | CHECK_EQ(0, WEXITSTATUS(status)); | ||
| 147 | |||
| 148 | CHECK_EQ(pidtwo, safewaitpid(pidtwo, &status, 0)); | ||
| 149 | CHECK(WIFEXITED(status)); | ||
| 150 | CHECK_EQ(0, WEXITSTATUS(status)); | ||
| 151 | |||
| 152 | CHECK(isfullbuf(bufchildone)); | ||
| 153 | CHECK(isfullbuf(bufchildtwo)); | ||
| 154 | |||
| 155 | for (i = 0; i < N; i++) { | ||
| 156 | countone += bufparent->x[i] == bufchildone->x[i]; | ||
| 157 | counttwo += bufparent->x[i] == bufchildtwo->x[i]; | ||
| 158 | countkids += bufchildone->x[i] == bufchildtwo->x[i]; | ||
| 159 | } | ||
| 160 | |||
| 161 | /* | ||
| 162 | * These checks are inherently probabilistic and theoretically risk | ||
| 163 | * flaking, but there's less than a 1 in 2^40 chance of more than | ||
| 164 | * one pairwise match between two vectors of 4096 32-bit integers. | ||
| 165 | */ | ||
| 166 | CHECK_LE(countone, 1); | ||
| 167 | CHECK_LE(counttwo, 1); | ||
| 168 | CHECK_LE(countkids, 1); | ||
| 169 | |||
| 170 | return (0); | ||
| 171 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/Makefile b/src/regress/lib/libc/arch/alpha/Makefile deleted file mode 100644 index 8c4dfb735c..0000000000 --- a/src/regress/lib/libc/arch/alpha/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/02/23 01:25:11 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:31 cgd Exp $ | ||
| 3 | |||
| 4 | # do nothing here; none of the tests here can be run automatically | ||
| 5 | SUBDIR= | ||
| 6 | |||
| 7 | install: | ||
| 8 | |||
| 9 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/Makefile b/src/regress/lib/libc/arch/alpha/divremtest/Makefile deleted file mode 100644 index 1da3ac8494..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/Makefile +++ /dev/null | |||
| @@ -1,30 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2001/01/29 02:05:39 niklas Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:34 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= divremtest | ||
| 5 | NOMAN= | ||
| 6 | |||
| 7 | CLEANFILES+= mkcases cases.c mktestcases testcases | ||
| 8 | |||
| 9 | divremtest.c: cases.c | ||
| 10 | |||
| 11 | cases.c: mkcases | ||
| 12 | /bin/rm -f cases.c | ||
| 13 | mkcases > cases.c | ||
| 14 | |||
| 15 | # a typical strategy to use this: | ||
| 16 | # compile a NetBSD divremtest binary, an OSF/1 divremtest binary, and an | ||
| 17 | # OSF/1 mktestcases binary. You then run mktestecases | divremtest -g | ||
| 18 | # on an OSF/1 machine, and pipe the output to an rsh to a NetBSD machine | ||
| 19 | # which then runs divremtest. You can test an infinite number of random | ||
| 20 | # values that way; I like to put a 'dd' in, so I can see how much I've done. | ||
| 21 | |||
| 22 | testcases: mktestcases divremtest | ||
| 23 | /bin/rm -f testcases | ||
| 24 | mktestcases | divremtest -g > testcases | ||
| 25 | |||
| 26 | regress: | ||
| 27 | @echo THIS TEST CANNOT BE RUN AUTOMATICALLY. | ||
| 28 | @false | ||
| 29 | |||
| 30 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c deleted file mode 100644 index 3d9e8a6de2..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | /* $OpenBSD: divremtest.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
| 2 | /* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <stdio.h> | ||
| 36 | #include <unistd.h> | ||
| 37 | #include <signal.h> | ||
| 38 | |||
| 39 | void testfile(); | ||
| 40 | void usage(); | ||
| 41 | |||
| 42 | int generate; | ||
| 43 | |||
| 44 | int | ||
| 45 | main(argc, argv) | ||
| 46 | int argc; | ||
| 47 | char **argv; | ||
| 48 | { | ||
| 49 | int c; | ||
| 50 | |||
| 51 | signal(SIGFPE, SIG_IGN); | ||
| 52 | |||
| 53 | while ((c = getopt(argc, argv, "g")) != -1) | ||
| 54 | switch (c) { | ||
| 55 | case 'g': | ||
| 56 | generate = 1; | ||
| 57 | break; | ||
| 58 | |||
| 59 | default: | ||
| 60 | usage(); | ||
| 61 | break; | ||
| 62 | } | ||
| 63 | |||
| 64 | argc -= optind; | ||
| 65 | argv += optind; | ||
| 66 | |||
| 67 | if (argc == 0) | ||
| 68 | testfile(); | ||
| 69 | else | ||
| 70 | for (; argc != 0; argc--, argv++) { | ||
| 71 | if (freopen(argv[0], "r", stdin) == NULL) { | ||
| 72 | fprintf(stderr, | ||
| 73 | "divremtest: couldn't open %s\n", | ||
| 74 | argv[0]); | ||
| 75 | exit(1); | ||
| 76 | } | ||
| 77 | |||
| 78 | testfile(); | ||
| 79 | } | ||
| 80 | |||
| 81 | exit(0); | ||
| 82 | } | ||
| 83 | |||
| 84 | void | ||
| 85 | testfile() | ||
| 86 | { | ||
| 87 | union operand { | ||
| 88 | unsigned long input; | ||
| 89 | int op_int; | ||
| 90 | unsigned int op_u_int; | ||
| 91 | long op_long; | ||
| 92 | unsigned long op_u_long; | ||
| 93 | } op1, op2, divres, modres, divwant, modwant; | ||
| 94 | char opspec[6]; | ||
| 95 | int encoded, i; | ||
| 96 | |||
| 97 | while (scanf("%6c %lx %lx %lx %lx\n", opspec, &op1.input, | ||
| 98 | &op2.input, &divwant.input, &modwant.input) != EOF) { | ||
| 99 | |||
| 100 | encoded = 0; | ||
| 101 | |||
| 102 | for (i = 0; i < 6; i += 2) { | ||
| 103 | int posval; | ||
| 104 | |||
| 105 | switch (opspec[i]) { | ||
| 106 | case '.': | ||
| 107 | posval = 0; | ||
| 108 | break; | ||
| 109 | case '-': | ||
| 110 | posval = 1; | ||
| 111 | break; | ||
| 112 | default: | ||
| 113 | fprintf(stderr, | ||
| 114 | "unknown signedness spec %c\n", | ||
| 115 | opspec[i]); | ||
| 116 | exit(1); | ||
| 117 | } | ||
| 118 | encoded |= posval << ((5 - i) * 4); | ||
| 119 | } | ||
| 120 | |||
| 121 | for (i = 1; i < 6; i += 2) { | ||
| 122 | int posval; | ||
| 123 | |||
| 124 | switch (opspec[i]) { | ||
| 125 | case 'i': | ||
| 126 | posval = 0; | ||
| 127 | break; | ||
| 128 | case 'l': | ||
| 129 | posval = 1; | ||
| 130 | break; | ||
| 131 | default: | ||
| 132 | fprintf(stderr, "unknown length spec %c\n", | ||
| 133 | opspec[i]); | ||
| 134 | exit(1); | ||
| 135 | } | ||
| 136 | encoded |= posval << ((5 - i) * 4); | ||
| 137 | } | ||
| 138 | |||
| 139 | /* KILL ME!!! */ | ||
| 140 | switch (encoded) { | ||
| 141 | |||
| 142 | #define TRY_IT(a, b, c) \ | ||
| 143 | divres.a = op1.b / op2.c; \ | ||
| 144 | modres.a = op1.b % op2.c; \ | ||
| 145 | if (generate) { \ | ||
| 146 | printf("%6s 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", \ | ||
| 147 | opspec, op1.input, op2.input, \ | ||
| 148 | divres.a, modres.a); \ | ||
| 149 | } else { \ | ||
| 150 | if ((divres.a != divwant.a) || \ | ||
| 151 | (modres.a != modwant.a)) { \ | ||
| 152 | fprintf(stderr, "%6s 0x%016lx 0x%016lx\n", \ | ||
| 153 | opspec, op1.input, op2.input); \ | ||
| 154 | fprintf(stderr, "FAILED:\n"); \ | ||
| 155 | fprintf(stderr, \ | ||
| 156 | "div:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
| 157 | divwant.a, divres.a); \ | ||
| 158 | fprintf(stderr, \ | ||
| 159 | "mod:\twanted 0x%16lx, got 0x%16lx\n", \ | ||
| 160 | modwant.a, modres.a); \ | ||
| 161 | \ | ||
| 162 | exit(1); \ | ||
| 163 | } \ | ||
| 164 | } | ||
| 165 | |||
| 166 | #include "cases.c" | ||
| 167 | |||
| 168 | #undef TRY_IT | ||
| 169 | |||
| 170 | default: | ||
| 171 | fprintf(stderr, | ||
| 172 | "INTERNAL ERROR: unknown encoding %x\n", encoded); | ||
| 173 | exit(1); | ||
| 174 | } | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | void | ||
| 179 | usage() | ||
| 180 | { | ||
| 181 | |||
| 182 | fprintf(stderr, "usage: divremtest [-v] [testfile ...]\n"); | ||
| 183 | exit(1); | ||
| 184 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c deleted file mode 100644 index fcb4765b8c..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | /* $OpenBSD: mkcases.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
| 2 | /* $NetBSD: mkcases.c,v 1.1 1995/04/24 05:53:36 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | char *tab[4] = { "u_int", "int", "u_long", "long" }; | ||
| 36 | |||
| 37 | int | ||
| 38 | main() | ||
| 39 | { | ||
| 40 | int i; | ||
| 41 | |||
| 42 | for (i = 0; i < 64; i++) { | ||
| 43 | printf( | ||
| 44 | " case 0x%d%d%d%d%d%d: /* %s <= %s op %s */\n", | ||
| 45 | (i >> 5) & 1, | ||
| 46 | (i >> 4) & 1, | ||
| 47 | (i >> 3) & 1, | ||
| 48 | (i >> 2) & 1, | ||
| 49 | (i >> 1) & 1, | ||
| 50 | (i >> 0) & 1, | ||
| 51 | tab[(i >> 4) & 0x3], | ||
| 52 | tab[(i >> 2) & 0x3], | ||
| 53 | tab[(i >> 0) & 0x3]); | ||
| 54 | printf( | ||
| 55 | " TRY_IT(op_%s, op_%s, op_%s);\n", | ||
| 56 | tab[(i >> 4) & 0x3], | ||
| 57 | tab[(i >> 2) & 0x3], | ||
| 58 | tab[(i >> 0) & 0x3]); | ||
| 59 | printf( | ||
| 60 | " break;\n\n"); | ||
| 61 | } | ||
| 62 | |||
| 63 | exit(0); | ||
| 64 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c deleted file mode 100644 index 3b01653f32..0000000000 --- a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | /* $OpenBSD: mktestcases.c,v 1.2 2001/01/29 02:05:40 niklas Exp $ */ | ||
| 2 | /* $NetBSD: mktestcases.c,v 1.1 1995/04/24 05:53:37 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1995 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <stdio.h> | ||
| 36 | |||
| 37 | int | ||
| 38 | main() | ||
| 39 | { | ||
| 40 | int i, j; | ||
| 41 | unsigned long n1, n2; | ||
| 42 | |||
| 43 | srandom(time(NULL)); | ||
| 44 | |||
| 45 | for (i = 1; /* i < 10240 */ 1; i++) { | ||
| 46 | n1 = (unsigned) | ||
| 47 | (random() & ((random() & random()) | 0x80000000)); | ||
| 48 | n1 <<= 32; | ||
| 49 | n1 |= (unsigned)(random() & random() & random()); | ||
| 50 | |||
| 51 | n2 = (unsigned) | ||
| 52 | (random() & ((random() & random()) | 0x80000000)); | ||
| 53 | n2 <<= 32; | ||
| 54 | n2 |= (unsigned)(random() & random() & random()); | ||
| 55 | |||
| 56 | for (j = 0; j < 64; j++) { | ||
| 57 | char *tab[] = { ".i", ".l", "-i", "-l" }; | ||
| 58 | |||
| 59 | printf("%s%s%s 0x%lx 0x%lx 0 0\n", | ||
| 60 | tab[(j >> 4) & 0x3], | ||
| 61 | tab[(j >> 2) & 0x3], | ||
| 62 | tab[(j >> 0) & 0x3], | ||
| 63 | n1, n2); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | exit(0); | ||
| 68 | } | ||
diff --git a/src/regress/lib/libc/asr/Makefile b/src/regress/lib/libc/asr/Makefile deleted file mode 100644 index 12e59536e0..0000000000 --- a/src/regress/lib/libc/asr/Makefile +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2017/03/10 17:23:48 eric Exp $ | ||
| 2 | |||
| 3 | # | ||
| 4 | # Notes on building and running the regression tests | ||
| 5 | # | ||
| 6 | # The regress suite builds two sets of static executables: the former linked | ||
| 7 | # against the system libc, and the latter against the libc found in /usr/obj | ||
| 8 | # The idea is to compare the output of all programs with internal changes in | ||
| 9 | # the libc (more specifically the resolver). They will be run in a chrooted | ||
| 10 | # environment to test various /etc configurations without touching the local | ||
| 11 | # machine config files. | ||
| 12 | # | ||
| 13 | # First, build a libc that needs testing, then: | ||
| 14 | # | ||
| 15 | # $ make | ||
| 16 | # $ doas make install | ||
| 17 | # $ doas make regress | ||
| 18 | # | ||
| 19 | # Tests output goes into a $REGRESSDIR/tmp.XXXXXXXXXX directory, and a digest | ||
| 20 | # is displayed at the end. | ||
| 21 | # | ||
| 22 | |||
| 23 | REGRESSDIR?= /tmp/regress-asr | ||
| 24 | REGRESS?= regress.sh | ||
| 25 | |||
| 26 | A?= .a | ||
| 27 | B?= .b | ||
| 28 | |||
| 29 | DIRA?= /usr/lib | ||
| 30 | DIRB?= /usr/obj/lib/libc | ||
| 31 | |||
| 32 | |||
| 33 | all: build | ||
| 34 | |||
| 35 | build: | ||
| 36 | cd bin && EXT=${A} LDFLAGS=-L${DIRA} make | ||
| 37 | cd bin && EXT=${B} LDFLAGS=-L${DIRB} make | ||
| 38 | |||
| 39 | clean: | ||
| 40 | cd bin && EXT=${A} make clean | ||
| 41 | cd bin && EXT=${B} make clean | ||
| 42 | |||
| 43 | install: | ||
| 44 | mkdir -p ${REGRESSDIR}/bin | ||
| 45 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=${A} make install | ||
| 46 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=${B} make install | ||
| 47 | |||
| 48 | uninstall: | ||
| 49 | rm -rf ${REGRESSDIR} | ||
| 50 | |||
| 51 | regress: | ||
| 52 | RUNDIR=${REGRESSDIR} A=${A} B=${B} sh ${.CURDIR}/${REGRESS} | ||
diff --git a/src/regress/lib/libc/asr/bin/Makefile b/src/regress/lib/libc/asr/bin/Makefile deleted file mode 100644 index 1f986a8e69..0000000000 --- a/src/regress/lib/libc/asr/bin/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | SUBDIR= res_mkquery | ||
| 2 | SUBDIR+= res_query | ||
| 3 | SUBDIR+= gethostnamadr | ||
| 4 | SUBDIR+= getnetnamadr | ||
| 5 | SUBDIR+= getrrsetbyname | ||
| 6 | SUBDIR+= getnameinfo | ||
| 7 | SUBDIR+= getaddrinfo | ||
| 8 | SUBDIR+= threads | ||
| 9 | |||
| 10 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/Makefile.inc b/src/regress/lib/libc/asr/bin/Makefile.inc deleted file mode 100644 index 80b4805136..0000000000 --- a/src/regress/lib/libc/asr/bin/Makefile.inc +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.2 2012/09/05 21:21:13 eric Exp $ | ||
| 2 | |||
| 3 | NOMAN= noman | ||
| 4 | |||
| 5 | SRCS+= common.c | ||
| 6 | CFLAGS+= -Wall -Wstrict-prototypes -Werror -Wundef -g | ||
| 7 | LDSTATIC= ${STATIC} | ||
| 8 | PROG:= ${PROG}${EXT} | ||
diff --git a/src/regress/lib/libc/asr/bin/common.c b/src/regress/lib/libc/asr/bin/common.c deleted file mode 100644 index c808c86d61..0000000000 --- a/src/regress/lib/libc/asr/bin/common.c +++ /dev/null | |||
| @@ -1,635 +0,0 @@ | |||
| 1 | /* $OpenBSD: common.c,v 1.3 2014/08/10 07:31:58 guenther Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/types.h> | ||
| 18 | #include <sys/socket.h> | ||
| 19 | #include <netinet/in.h> | ||
| 20 | #include <arpa/inet.h> | ||
| 21 | #include <arpa/nameser.h> | ||
| 22 | |||
| 23 | #include <err.h> | ||
| 24 | #include <errno.h> | ||
| 25 | #include <inttypes.h> | ||
| 26 | #include <netdb.h> | ||
| 27 | #include <resolv.h> | ||
| 28 | #include <stdio.h> | ||
| 29 | #include <string.h> | ||
| 30 | |||
| 31 | #include "common.h" | ||
| 32 | |||
| 33 | int long_err; | ||
| 34 | int gai_errno; | ||
| 35 | int rrset_errno; | ||
| 36 | |||
| 37 | |||
| 38 | char * | ||
| 39 | gethostarg(char *n) | ||
| 40 | { | ||
| 41 | if (n == NULL) | ||
| 42 | return (n); | ||
| 43 | if (!strcmp(n, "NULL")) | ||
| 44 | return (NULL); | ||
| 45 | if (!strcmp(n, "EMPTY")) | ||
| 46 | return (""); | ||
| 47 | return (n); | ||
| 48 | } | ||
| 49 | |||
| 50 | const char *rrsetstrerror(int); | ||
| 51 | char * print_addr(const struct sockaddr *, char *, size_t); | ||
| 52 | |||
| 53 | struct kv { int code; const char *name; }; | ||
| 54 | |||
| 55 | struct kv kv_family[] = { | ||
| 56 | { AF_UNIX, "unix" }, | ||
| 57 | { AF_INET, "inet" }, | ||
| 58 | { AF_INET6, "inet6" }, | ||
| 59 | { 0, NULL, } | ||
| 60 | }; | ||
| 61 | struct kv kv_socktype[] = { | ||
| 62 | { SOCK_STREAM, "stream" }, | ||
| 63 | { SOCK_DGRAM, "dgram" }, | ||
| 64 | { SOCK_RAW, "raw" }, | ||
| 65 | { SOCK_SEQPACKET, "seqpacket" }, | ||
| 66 | { 0, NULL, } | ||
| 67 | }; | ||
| 68 | struct kv kv_protocol[] = { | ||
| 69 | { IPPROTO_UDP, "udp" }, | ||
| 70 | { IPPROTO_TCP, "tcp" }, | ||
| 71 | { IPPROTO_ICMP, "icmp" }, | ||
| 72 | { IPPROTO_ICMPV6, "icmpv6" }, | ||
| 73 | { 0, NULL, } | ||
| 74 | }; | ||
| 75 | |||
| 76 | static const char * | ||
| 77 | kv_lookup_name(struct kv *kv, int code, char *buf, size_t sz) | ||
| 78 | { | ||
| 79 | while (kv->name) { | ||
| 80 | if (kv->code == code) | ||
| 81 | return (kv->name); | ||
| 82 | kv++; | ||
| 83 | } | ||
| 84 | snprintf(buf, sz, "%i", code); | ||
| 85 | return (buf); | ||
| 86 | } | ||
| 87 | |||
| 88 | struct keyval { | ||
| 89 | const char *key; | ||
| 90 | uint16_t value; | ||
| 91 | }; | ||
| 92 | |||
| 93 | static struct keyval kv_class[] = { | ||
| 94 | { "IN", C_IN }, | ||
| 95 | { "CHAOS", C_CHAOS }, | ||
| 96 | { "HS", C_HS }, | ||
| 97 | { "ANY", C_ANY }, | ||
| 98 | { NULL, 0 }, | ||
| 99 | }; | ||
| 100 | |||
| 101 | static struct keyval kv_type[] = { | ||
| 102 | { "A", T_A }, | ||
| 103 | { "NS", T_NS }, | ||
| 104 | { "MD", T_MD }, | ||
| 105 | { "MF", T_MF }, | ||
| 106 | { "CNAME", T_CNAME }, | ||
| 107 | { "SOA", T_SOA }, | ||
| 108 | { "MB", T_MB }, | ||
| 109 | { "MG", T_MG }, | ||
| 110 | { "MR", T_MR }, | ||
| 111 | { "NULL", T_NULL }, | ||
| 112 | { "WKS", T_WKS }, | ||
| 113 | { "PTR", T_PTR }, | ||
| 114 | { "HINFO", T_HINFO }, | ||
| 115 | { "MINFO", T_MINFO }, | ||
| 116 | { "MX", T_MX }, | ||
| 117 | { "TXT", T_TXT }, | ||
| 118 | |||
| 119 | { "AAAA", T_AAAA }, | ||
| 120 | |||
| 121 | { "AXFR", T_AXFR }, | ||
| 122 | { "MAILB", T_MAILB }, | ||
| 123 | { "MAILA", T_MAILA }, | ||
| 124 | { "ANY", T_ANY }, | ||
| 125 | { NULL, 0 }, | ||
| 126 | }; | ||
| 127 | |||
| 128 | static struct keyval kv_rcode[] = { | ||
| 129 | { "NOERROR", NOERROR }, | ||
| 130 | { "FORMERR", FORMERR }, | ||
| 131 | { "SERVFAIL", SERVFAIL }, | ||
| 132 | { "NXDOMAIN", NXDOMAIN }, | ||
| 133 | { "NOTIMP", NOTIMP }, | ||
| 134 | { "REFUSED", REFUSED }, | ||
| 135 | { NULL, 0 }, | ||
| 136 | }; | ||
| 137 | |||
| 138 | |||
| 139 | const char * | ||
| 140 | rcodetostr(uint16_t v) | ||
| 141 | { | ||
| 142 | static char buf[16]; | ||
| 143 | size_t i; | ||
| 144 | |||
| 145 | for(i = 0; kv_rcode[i].key; i++) | ||
| 146 | if (kv_rcode[i].value == v) | ||
| 147 | return (kv_rcode[i].key); | ||
| 148 | |||
| 149 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 150 | |||
| 151 | return (buf); | ||
| 152 | } | ||
| 153 | |||
| 154 | const char * | ||
| 155 | typetostr(uint16_t v) | ||
| 156 | { | ||
| 157 | static char buf[16]; | ||
| 158 | size_t i; | ||
| 159 | |||
| 160 | for(i = 0; kv_type[i].key; i++) | ||
| 161 | if (kv_type[i].value == v) | ||
| 162 | return (kv_type[i].key); | ||
| 163 | |||
| 164 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 165 | |||
| 166 | return (buf); | ||
| 167 | } | ||
| 168 | |||
| 169 | const char * | ||
| 170 | classtostr(uint16_t v) | ||
| 171 | { | ||
| 172 | static char buf[16]; | ||
| 173 | size_t i; | ||
| 174 | |||
| 175 | for(i = 0; kv_class[i].key; i++) | ||
| 176 | if (kv_class[i].value == v) | ||
| 177 | return (kv_class[i].key); | ||
| 178 | |||
| 179 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 180 | |||
| 181 | return (buf); | ||
| 182 | } | ||
| 183 | |||
| 184 | uint16_t | ||
| 185 | strtotype(const char *name) | ||
| 186 | { | ||
| 187 | size_t i; | ||
| 188 | |||
| 189 | for(i = 0; kv_type[i].key; i++) | ||
| 190 | if (!strcmp(kv_type[i].key, name)) | ||
| 191 | return (kv_type[i].value); | ||
| 192 | |||
| 193 | return (0); | ||
| 194 | } | ||
| 195 | |||
| 196 | uint16_t | ||
| 197 | strtoclass(const char *name) | ||
| 198 | { | ||
| 199 | size_t i; | ||
| 200 | |||
| 201 | for(i = 0; kv_class[i].key; i++) | ||
| 202 | if (!strcmp(kv_class[i].key, name)) | ||
| 203 | return (kv_class[i].value); | ||
| 204 | |||
| 205 | return (0); | ||
| 206 | } | ||
| 207 | |||
| 208 | void | ||
| 209 | print_hostent(struct hostent *e) | ||
| 210 | { | ||
| 211 | char buf[256], **c; | ||
| 212 | |||
| 213 | printf("name = \"%s\"\n", e->h_name); | ||
| 214 | printf("aliases ="); | ||
| 215 | for(c = e->h_aliases; *c; c++) | ||
| 216 | printf(" \"%s\"", *c); | ||
| 217 | printf("\n"); | ||
| 218 | printf("addrtype = %i\n", e->h_addrtype); | ||
| 219 | printf("addrlength = %i\n", e->h_length); | ||
| 220 | printf("addr_list ="); | ||
| 221 | for(c = e->h_addr_list; *c; c++) { | ||
| 222 | printf(" %s", inet_ntop(e->h_addrtype, *c, buf, sizeof buf)); | ||
| 223 | } | ||
| 224 | printf("\n"); | ||
| 225 | } | ||
| 226 | |||
| 227 | void | ||
| 228 | print_netent(struct netent *e) | ||
| 229 | { | ||
| 230 | char buf[256], **c; | ||
| 231 | uint32_t addr; | ||
| 232 | |||
| 233 | /* network number are given in host order */ | ||
| 234 | addr = htonl(e->n_net); | ||
| 235 | |||
| 236 | printf("name = \"%s\"\n", e->n_name); | ||
| 237 | printf("aliases ="); | ||
| 238 | for (c = e->n_aliases; *c; c++) | ||
| 239 | printf(" \"%s\"", *c); | ||
| 240 | printf("\n"); | ||
| 241 | printf("addrtype = %i\n", e->n_addrtype); | ||
| 242 | printf("net = %s\n", inet_ntop(e->n_addrtype, &addr, buf, sizeof buf)); | ||
| 243 | } | ||
| 244 | |||
| 245 | void | ||
| 246 | print_addrinfo(struct addrinfo *ai) | ||
| 247 | { | ||
| 248 | char buf[256], bf[64], bt[64], bp[64]; | ||
| 249 | |||
| 250 | printf("family=%s socktype=%s protocol=%s addr=%s canonname=%s\n", | ||
| 251 | kv_lookup_name(kv_family, ai->ai_family, bf, sizeof bf), | ||
| 252 | kv_lookup_name(kv_socktype, ai->ai_socktype, bt, sizeof bt), | ||
| 253 | kv_lookup_name(kv_protocol, ai->ai_protocol, bp, sizeof bp), | ||
| 254 | print_addr(ai->ai_addr, buf, sizeof buf), | ||
| 255 | ai->ai_canonname); | ||
| 256 | } | ||
| 257 | |||
| 258 | const char * | ||
| 259 | rrsetstrerror(int e) | ||
| 260 | { | ||
| 261 | switch (e) { | ||
| 262 | case 0: | ||
| 263 | return "OK"; | ||
| 264 | case ERRSET_NONAME: | ||
| 265 | return "ERRSET_NONAME"; | ||
| 266 | case ERRSET_NODATA: | ||
| 267 | return "ERRSET_NODATA"; | ||
| 268 | case ERRSET_NOMEMORY: | ||
| 269 | return "ERRSET_NOMEMORY"; | ||
| 270 | case ERRSET_INVAL: | ||
| 271 | return "ERRSET_INVAL"; | ||
| 272 | case ERRSET_FAIL: | ||
| 273 | return "ERRSET_FAIL"; | ||
| 274 | default: | ||
| 275 | return "???"; | ||
| 276 | } | ||
| 277 | } | ||
| 278 | |||
| 279 | void | ||
| 280 | print_rrsetinfo(struct rrsetinfo * rrset) | ||
| 281 | { | ||
| 282 | printf("rri_flags=%u\n", rrset->rri_flags); | ||
| 283 | printf("rri_rdclass=%u\n", rrset->rri_rdclass); | ||
| 284 | printf("rri_rdtype=%u\n", rrset->rri_rdtype); | ||
| 285 | printf("rri_ttl=%u\n", rrset->rri_ttl); | ||
| 286 | printf("rri_nrdatas=%u\n", rrset->rri_nrdatas); | ||
| 287 | printf("rri_nsigs=%u\n", rrset->rri_nsigs); | ||
| 288 | printf("rri_name=\"%s\"\n", rrset->rri_name); | ||
| 289 | } | ||
| 290 | |||
| 291 | void | ||
| 292 | print_errors(void) | ||
| 293 | { | ||
| 294 | switch (long_err) { | ||
| 295 | case 0: | ||
| 296 | return; | ||
| 297 | case 1: | ||
| 298 | printf(" => errno %i, h_errno %i", errno, h_errno); | ||
| 299 | printf(", rrset_errno %i", rrset_errno); | ||
| 300 | printf(", gai_errno %i", gai_errno); | ||
| 301 | printf ("\n"); | ||
| 302 | return; | ||
| 303 | default: | ||
| 304 | printf(" => errno %i: %s\n => h_errno %i: %s\n => rrset_errno %i: %s\n", | ||
| 305 | errno, errno ? strerror(errno) : "ok", | ||
| 306 | h_errno, h_errno ? hstrerror(h_errno) : "ok", | ||
| 307 | rrset_errno, rrset_errno ? rrsetstrerror(rrset_errno) : "ok"); | ||
| 308 | printf(" => gai_errno %i: %s\n", | ||
| 309 | gai_errno, gai_errno ? gai_strerror(gai_errno) : "ok"); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | |||
| 314 | static char * | ||
| 315 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
| 316 | { | ||
| 317 | switch (sa->sa_family) { | ||
| 318 | case AF_INET: | ||
| 319 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, | ||
| 320 | buf, len); | ||
| 321 | break; | ||
| 322 | case AF_INET6: | ||
| 323 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, | ||
| 324 | buf, len); | ||
| 325 | break; | ||
| 326 | default: | ||
| 327 | buf[0] = '\0'; | ||
| 328 | } | ||
| 329 | return (buf); | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | char * | ||
| 334 | print_addr(const struct sockaddr *sa, char *buf, size_t len) | ||
| 335 | { | ||
| 336 | char h[256]; | ||
| 337 | |||
| 338 | print_host(sa, h, sizeof h); | ||
| 339 | |||
| 340 | switch (sa->sa_family) { | ||
| 341 | case AF_INET: | ||
| 342 | snprintf(buf, len, "%s:%i", h, | ||
| 343 | ntohs(((struct sockaddr_in*)(sa))->sin_port)); | ||
| 344 | break; | ||
| 345 | case AF_INET6: | ||
| 346 | snprintf(buf, len, "[%s]:%i", h, | ||
| 347 | ntohs(((struct sockaddr_in6*)(sa))->sin6_port)); | ||
| 348 | break; | ||
| 349 | default: | ||
| 350 | snprintf(buf, len, "?"); | ||
| 351 | break; | ||
| 352 | } | ||
| 353 | |||
| 354 | return (buf); | ||
| 355 | } | ||
| 356 | |||
| 357 | void | ||
| 358 | packed_init(struct packed *pack, char *data, size_t len) | ||
| 359 | { | ||
| 360 | pack->data = data; | ||
| 361 | pack->len = len; | ||
| 362 | pack->offset = 0; | ||
| 363 | pack->err = NULL; | ||
| 364 | } | ||
| 365 | |||
| 366 | |||
| 367 | static ssize_t | ||
| 368 | dname_expand(const unsigned char *data, size_t len, size_t offset, | ||
| 369 | size_t *newoffset, char *dst, size_t max) | ||
| 370 | { | ||
| 371 | size_t n, count, end, ptr, start; | ||
| 372 | ssize_t res; | ||
| 373 | |||
| 374 | if (offset >= len) | ||
| 375 | return (-1); | ||
| 376 | |||
| 377 | res = 0; | ||
| 378 | end = start = offset; | ||
| 379 | |||
| 380 | for(; (n = data[offset]); ) { | ||
| 381 | if ((n & 0xc0) == 0xc0) { | ||
| 382 | if (offset + 2 > len) | ||
| 383 | return (-1); | ||
| 384 | ptr = 256 * (n & ~0xc0) + data[offset + 1]; | ||
| 385 | if (ptr >= start) | ||
| 386 | return (-1); | ||
| 387 | if (end < offset + 2) | ||
| 388 | end = offset + 2; | ||
| 389 | offset = ptr; | ||
| 390 | continue; | ||
| 391 | } | ||
| 392 | if (offset + n + 1 > len) | ||
| 393 | return (-1); | ||
| 394 | |||
| 395 | |||
| 396 | /* copy n + at offset+1 */ | ||
| 397 | if (dst != NULL && max != 0) { | ||
| 398 | count = (max < n + 1) ? (max) : (n + 1); | ||
| 399 | memmove(dst, data + offset, count); | ||
| 400 | dst += count; | ||
| 401 | max -= count; | ||
| 402 | } | ||
| 403 | res += n + 1; | ||
| 404 | offset += n + 1; | ||
| 405 | if (end < offset) | ||
| 406 | end = offset; | ||
| 407 | } | ||
| 408 | if (end < offset + 1) | ||
| 409 | end = offset + 1; | ||
| 410 | |||
| 411 | if (dst != NULL && max != 0) | ||
| 412 | dst[0] = 0; | ||
| 413 | if (newoffset) | ||
| 414 | *newoffset = end; | ||
| 415 | return (res + 1); | ||
| 416 | } | ||
| 417 | |||
| 418 | static int | ||
| 419 | unpack_data(struct packed *p, void *data, size_t len) | ||
| 420 | { | ||
| 421 | if (p->err) | ||
| 422 | return (-1); | ||
| 423 | |||
| 424 | if (p->len - p->offset < len) { | ||
| 425 | p->err = "too short"; | ||
| 426 | return (-1); | ||
| 427 | } | ||
| 428 | |||
| 429 | memmove(data, p->data + p->offset, len); | ||
| 430 | p->offset += len; | ||
| 431 | |||
| 432 | return (0); | ||
| 433 | } | ||
| 434 | |||
| 435 | static int | ||
| 436 | unpack_u16(struct packed *p, uint16_t *u16) | ||
| 437 | { | ||
| 438 | if (unpack_data(p, u16, 2) == -1) | ||
| 439 | return (-1); | ||
| 440 | |||
| 441 | *u16 = ntohs(*u16); | ||
| 442 | |||
| 443 | return (0); | ||
| 444 | } | ||
| 445 | |||
| 446 | static int | ||
| 447 | unpack_u32(struct packed *p, uint32_t *u32) | ||
| 448 | { | ||
| 449 | if (unpack_data(p, u32, 4) == -1) | ||
| 450 | return (-1); | ||
| 451 | |||
| 452 | *u32 = ntohl(*u32); | ||
| 453 | |||
| 454 | return (0); | ||
| 455 | } | ||
| 456 | |||
| 457 | static int | ||
| 458 | unpack_inaddr(struct packed *p, struct in_addr *a) | ||
| 459 | { | ||
| 460 | return (unpack_data(p, a, 4)); | ||
| 461 | } | ||
| 462 | |||
| 463 | static int | ||
| 464 | unpack_in6addr(struct packed *p, struct in6_addr *a6) | ||
| 465 | { | ||
| 466 | return (unpack_data(p, a6, 16)); | ||
| 467 | } | ||
| 468 | |||
| 469 | static int | ||
| 470 | unpack_dname(struct packed *p, char *dst, size_t max) | ||
| 471 | { | ||
| 472 | ssize_t e; | ||
| 473 | |||
| 474 | if (p->err) | ||
| 475 | return (-1); | ||
| 476 | |||
| 477 | e = dname_expand(p->data, p->len, p->offset, &p->offset, dst, max); | ||
| 478 | if (e == -1) { | ||
| 479 | p->err = "bad domain name"; | ||
| 480 | return (-1); | ||
| 481 | } | ||
| 482 | if (e < 0 || e > MAXDNAME) { | ||
| 483 | p->err = "domain name too long"; | ||
| 484 | return (-1); | ||
| 485 | } | ||
| 486 | |||
| 487 | return (0); | ||
| 488 | } | ||
| 489 | |||
| 490 | int | ||
| 491 | unpack_header(struct packed *p, struct header *h) | ||
| 492 | { | ||
| 493 | if (unpack_data(p, h, HFIXEDSZ) == -1) | ||
| 494 | return (-1); | ||
| 495 | |||
| 496 | h->flags = ntohs(h->flags); | ||
| 497 | h->qdcount = ntohs(h->qdcount); | ||
| 498 | h->ancount = ntohs(h->ancount); | ||
| 499 | h->nscount = ntohs(h->nscount); | ||
| 500 | h->arcount = ntohs(h->arcount); | ||
| 501 | |||
| 502 | return (0); | ||
| 503 | } | ||
| 504 | |||
| 505 | int | ||
| 506 | unpack_query(struct packed *p, struct query *q) | ||
| 507 | { | ||
| 508 | unpack_dname(p, q->q_dname, sizeof(q->q_dname)); | ||
| 509 | unpack_u16(p, &q->q_type); | ||
| 510 | unpack_u16(p, &q->q_class); | ||
| 511 | |||
| 512 | return (p->err) ? (-1) : (0); | ||
| 513 | } | ||
| 514 | |||
| 515 | int | ||
| 516 | unpack_rr(struct packed *p, struct rr *rr) | ||
| 517 | { | ||
| 518 | uint16_t rdlen; | ||
| 519 | size_t save_offset; | ||
| 520 | |||
| 521 | unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname)); | ||
| 522 | unpack_u16(p, &rr->rr_type); | ||
| 523 | unpack_u16(p, &rr->rr_class); | ||
| 524 | unpack_u32(p, &rr->rr_ttl); | ||
| 525 | unpack_u16(p, &rdlen); | ||
| 526 | |||
| 527 | if (p->err) | ||
| 528 | return (-1); | ||
| 529 | |||
| 530 | if (p->len - p->offset < rdlen) { | ||
| 531 | p->err = "too short"; | ||
| 532 | return (-1); | ||
| 533 | } | ||
| 534 | |||
| 535 | save_offset = p->offset; | ||
| 536 | |||
| 537 | switch(rr->rr_type) { | ||
| 538 | |||
| 539 | case T_CNAME: | ||
| 540 | unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname)); | ||
| 541 | break; | ||
| 542 | |||
| 543 | case T_MX: | ||
| 544 | unpack_u16(p, &rr->rr.mx.preference); | ||
| 545 | unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange)); | ||
| 546 | break; | ||
| 547 | |||
| 548 | case T_NS: | ||
| 549 | unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname)); | ||
| 550 | break; | ||
| 551 | |||
| 552 | case T_PTR: | ||
| 553 | unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname)); | ||
| 554 | break; | ||
| 555 | |||
| 556 | case T_SOA: | ||
| 557 | unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname)); | ||
| 558 | unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname)); | ||
| 559 | unpack_u32(p, &rr->rr.soa.serial); | ||
| 560 | unpack_u32(p, &rr->rr.soa.refresh); | ||
| 561 | unpack_u32(p, &rr->rr.soa.retry); | ||
| 562 | unpack_u32(p, &rr->rr.soa.expire); | ||
| 563 | unpack_u32(p, &rr->rr.soa.minimum); | ||
| 564 | break; | ||
| 565 | |||
| 566 | case T_A: | ||
| 567 | if (rr->rr_class != C_IN) | ||
| 568 | goto other; | ||
| 569 | unpack_inaddr(p, &rr->rr.in_a.addr); | ||
| 570 | break; | ||
| 571 | |||
| 572 | case T_AAAA: | ||
| 573 | if (rr->rr_class != C_IN) | ||
| 574 | goto other; | ||
| 575 | unpack_in6addr(p, &rr->rr.in_aaaa.addr6); | ||
| 576 | break; | ||
| 577 | default: | ||
| 578 | other: | ||
| 579 | rr->rr.other.rdata = p->data + p->offset; | ||
| 580 | rr->rr.other.rdlen = rdlen; | ||
| 581 | p->offset += rdlen; | ||
| 582 | } | ||
| 583 | |||
| 584 | if (p->err) | ||
| 585 | return (-1); | ||
| 586 | |||
| 587 | /* make sure that the advertised rdlen is really ok */ | ||
| 588 | if (p->offset - save_offset != rdlen) | ||
| 589 | p->err = "bad dlen"; | ||
| 590 | |||
| 591 | return (p->err) ? (-1) : (0); | ||
| 592 | } | ||
| 593 | |||
| 594 | int | ||
| 595 | sockaddr_from_str(struct sockaddr *sa, int family, const char *str) | ||
| 596 | { | ||
| 597 | struct in_addr ina; | ||
| 598 | struct in6_addr in6a; | ||
| 599 | struct sockaddr_in *sin; | ||
| 600 | struct sockaddr_in6 *sin6; | ||
| 601 | |||
| 602 | switch (family) { | ||
| 603 | case PF_UNSPEC: | ||
| 604 | if (sockaddr_from_str(sa, PF_INET, str) == 0) | ||
| 605 | return (0); | ||
| 606 | return sockaddr_from_str(sa, PF_INET6, str); | ||
| 607 | |||
| 608 | case PF_INET: | ||
| 609 | if (inet_pton(PF_INET, str, &ina) != 1) | ||
| 610 | return (-1); | ||
| 611 | |||
| 612 | sin = (struct sockaddr_in *)sa; | ||
| 613 | memset(sin, 0, sizeof *sin); | ||
| 614 | sin->sin_len = sizeof(struct sockaddr_in); | ||
| 615 | sin->sin_family = PF_INET; | ||
| 616 | sin->sin_addr.s_addr = ina.s_addr; | ||
| 617 | return (0); | ||
| 618 | |||
| 619 | case PF_INET6: | ||
| 620 | if (inet_pton(PF_INET6, str, &in6a) != 1) | ||
| 621 | return (-1); | ||
| 622 | |||
| 623 | sin6 = (struct sockaddr_in6 *)sa; | ||
| 624 | memset(sin6, 0, sizeof *sin6); | ||
| 625 | sin6->sin6_len = sizeof(struct sockaddr_in6); | ||
| 626 | sin6->sin6_family = PF_INET6; | ||
| 627 | sin6->sin6_addr = in6a; | ||
| 628 | return (0); | ||
| 629 | |||
| 630 | default: | ||
| 631 | break; | ||
| 632 | } | ||
| 633 | |||
| 634 | return (-1); | ||
| 635 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/common.h b/src/regress/lib/libc/asr/bin/common.h deleted file mode 100644 index 87df4ae4a2..0000000000 --- a/src/regress/lib/libc/asr/bin/common.h +++ /dev/null | |||
| @@ -1,136 +0,0 @@ | |||
| 1 | /* $OpenBSD: common.h,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/types.h> | ||
| 18 | #include <sys/socket.h> | ||
| 19 | |||
| 20 | #include <arpa/nameser.h> | ||
| 21 | |||
| 22 | #include <netinet/in.h> | ||
| 23 | |||
| 24 | #include <netdb.h> | ||
| 25 | |||
| 26 | |||
| 27 | #define unpack_rr __unpack_rr | ||
| 28 | #define unpack_header __unpack_header | ||
| 29 | #define packed_init __packed_init | ||
| 30 | #define unpack_query __unpack_query | ||
| 31 | #define sockaddr_from_str __sockaddr_from_str | ||
| 32 | #define print_addr __print_addr | ||
| 33 | |||
| 34 | extern int long_err; | ||
| 35 | extern int gai_errno; | ||
| 36 | extern int rrset_errno; | ||
| 37 | |||
| 38 | const char *classtostr(uint16_t); | ||
| 39 | const char *typetostr(uint16_t); | ||
| 40 | const char *rcodetostr(uint16_t); | ||
| 41 | |||
| 42 | uint16_t strtotype(const char*); | ||
| 43 | uint16_t strtoclass(const char*); | ||
| 44 | |||
| 45 | void print_rrsetinfo(struct rrsetinfo *); | ||
| 46 | void print_addrinfo(struct addrinfo *); | ||
| 47 | void print_errors(void); | ||
| 48 | void print_hostent(struct hostent *); | ||
| 49 | void print_netent(struct netent *); | ||
| 50 | |||
| 51 | int sockaddr_from_str(struct sockaddr *, int, const char *); | ||
| 52 | int addr_from_str(char *, int *, int *, const char *); | ||
| 53 | char* gethostarg(char *); | ||
| 54 | |||
| 55 | #define QR_MASK (0x1 << 15) | ||
| 56 | #define OPCODE_MASK (0xf << 11) | ||
| 57 | #define AA_MASK (0x1 << 10) | ||
| 58 | #define TC_MASK (0x1 << 9) | ||
| 59 | #define RD_MASK (0x1 << 8) | ||
| 60 | #define RA_MASK (0x1 << 7) | ||
| 61 | #define Z_MASK (0x7 << 4) | ||
| 62 | #define RCODE_MASK (0xf) | ||
| 63 | |||
| 64 | #define OPCODE(v) ((v) & OPCODE_MASK) | ||
| 65 | #define RCODE(v) ((v) & RCODE_MASK) | ||
| 66 | |||
| 67 | |||
| 68 | struct packed { | ||
| 69 | char *data; | ||
| 70 | size_t len; | ||
| 71 | size_t offset; | ||
| 72 | const char *err; | ||
| 73 | }; | ||
| 74 | |||
| 75 | struct header { | ||
| 76 | uint16_t id; | ||
| 77 | uint16_t flags; | ||
| 78 | uint16_t qdcount; | ||
| 79 | uint16_t ancount; | ||
| 80 | uint16_t nscount; | ||
| 81 | uint16_t arcount; | ||
| 82 | }; | ||
| 83 | |||
| 84 | struct query { | ||
| 85 | char q_dname[MAXDNAME]; | ||
| 86 | uint16_t q_type; | ||
| 87 | uint16_t q_class; | ||
| 88 | }; | ||
| 89 | |||
| 90 | struct rr { | ||
| 91 | char rr_dname[MAXDNAME]; | ||
| 92 | uint16_t rr_type; | ||
| 93 | uint16_t rr_class; | ||
| 94 | uint32_t rr_ttl; | ||
| 95 | union { | ||
| 96 | struct { | ||
| 97 | char cname[MAXDNAME]; | ||
| 98 | } cname; | ||
| 99 | struct { | ||
| 100 | uint16_t preference; | ||
| 101 | char exchange[MAXDNAME]; | ||
| 102 | } mx; | ||
| 103 | struct { | ||
| 104 | char nsname[MAXDNAME]; | ||
| 105 | } ns; | ||
| 106 | struct { | ||
| 107 | char ptrname[MAXDNAME]; | ||
| 108 | } ptr; | ||
| 109 | struct { | ||
| 110 | char mname[MAXDNAME]; | ||
| 111 | char rname[MAXDNAME]; | ||
| 112 | uint32_t serial; | ||
| 113 | uint32_t refresh; | ||
| 114 | uint32_t retry; | ||
| 115 | uint32_t expire; | ||
| 116 | uint32_t minimum; | ||
| 117 | } soa; | ||
| 118 | struct { | ||
| 119 | struct in_addr addr; | ||
| 120 | } in_a; | ||
| 121 | struct { | ||
| 122 | struct in6_addr addr6; | ||
| 123 | } in_aaaa; | ||
| 124 | struct { | ||
| 125 | uint16_t rdlen; | ||
| 126 | const void *rdata; | ||
| 127 | } other; | ||
| 128 | } rr; | ||
| 129 | }; | ||
| 130 | |||
| 131 | void packed_init(struct packed*, char*, size_t); | ||
| 132 | int pack_header(struct packed*, const struct header*); | ||
| 133 | int pack_query(struct packed*, uint16_t, uint16_t, const char*); | ||
| 134 | int unpack_header(struct packed*, struct header*); | ||
| 135 | int unpack_query(struct packed*, struct query*); | ||
| 136 | int unpack_rr(struct packed*, struct rr*); | ||
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo.c b/src/regress/lib/libc/asr/bin/getaddrinfo.c deleted file mode 100644 index 7b8674aea9..0000000000 --- a/src/regress/lib/libc/asr/bin/getaddrinfo.c +++ /dev/null | |||
| @@ -1,135 +0,0 @@ | |||
| 1 | /* $OpenBSD: getaddrinfo.c,v 1.2 2013/03/28 09:36:03 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/types.h> | ||
| 18 | #include <sys/socket.h> | ||
| 19 | |||
| 20 | #include <netinet/in.h> | ||
| 21 | |||
| 22 | #include <err.h> | ||
| 23 | #include <errno.h> | ||
| 24 | #include <getopt.h> | ||
| 25 | #include <netdb.h> | ||
| 26 | #include <stdio.h> | ||
| 27 | #include <stdlib.h> | ||
| 28 | #include <string.h> | ||
| 29 | |||
| 30 | #include "common.h" | ||
| 31 | |||
| 32 | static void | ||
| 33 | usage(void) | ||
| 34 | { | ||
| 35 | extern const char * __progname; | ||
| 36 | |||
| 37 | fprintf(stderr, "usage: %s [-CHSPe] [-f family] [-p proto] " | ||
| 38 | "[-s servname]\n [-t socktype] <host...>\n", __progname); | ||
| 39 | exit(1); | ||
| 40 | } | ||
| 41 | |||
| 42 | int | ||
| 43 | main(int argc, char *argv[]) | ||
| 44 | { | ||
| 45 | struct addrinfo *ai, *res, hints; | ||
| 46 | char *servname = NULL, *host; | ||
| 47 | int i, ch; | ||
| 48 | |||
| 49 | memset(&hints, 0, sizeof hints); | ||
| 50 | |||
| 51 | while((ch = getopt(argc, argv, "CFHPSef:p:s:t:")) != -1) { | ||
| 52 | switch(ch) { | ||
| 53 | case 'C': | ||
| 54 | hints.ai_flags |= AI_CANONNAME; | ||
| 55 | break; | ||
| 56 | case 'F': | ||
| 57 | hints.ai_flags |= AI_FQDN; | ||
| 58 | break; | ||
| 59 | case 'H': | ||
| 60 | hints.ai_flags |= AI_NUMERICHOST; | ||
| 61 | break; | ||
| 62 | case 'P': | ||
| 63 | hints.ai_flags |= AI_PASSIVE; | ||
| 64 | break; | ||
| 65 | case 'S': | ||
| 66 | hints.ai_flags |= AI_NUMERICSERV; | ||
| 67 | break; | ||
| 68 | case 'e': | ||
| 69 | long_err += 1; | ||
| 70 | break; | ||
| 71 | case 'f': | ||
| 72 | if (!strcmp(optarg, "inet")) | ||
| 73 | hints.ai_family = AF_INET; | ||
| 74 | else if (!strcmp(optarg, "inet6")) | ||
| 75 | hints.ai_family = AF_INET6; | ||
| 76 | else | ||
| 77 | usage(); | ||
| 78 | break; | ||
| 79 | case 'p': | ||
| 80 | if (!strcmp(optarg, "udp")) | ||
| 81 | hints.ai_protocol = IPPROTO_UDP; | ||
| 82 | else if (!strcmp(optarg, "tcp")) | ||
| 83 | hints.ai_protocol = IPPROTO_TCP; | ||
| 84 | else if (!strcmp(optarg, "icmp")) | ||
| 85 | hints.ai_protocol = IPPROTO_ICMP; | ||
| 86 | else if (!strcmp(optarg, "icmpv6")) | ||
| 87 | hints.ai_protocol = IPPROTO_ICMPV6; | ||
| 88 | else | ||
| 89 | usage(); | ||
| 90 | break; | ||
| 91 | case 's': | ||
| 92 | servname = optarg; | ||
| 93 | break; | ||
| 94 | case 't': | ||
| 95 | if (!strcmp(optarg, "stream")) | ||
| 96 | hints.ai_socktype = SOCK_STREAM; | ||
| 97 | else if (!strcmp(optarg, "dgram")) | ||
| 98 | hints.ai_socktype = SOCK_DGRAM; | ||
| 99 | else if (!strcmp(optarg, "raw")) | ||
| 100 | hints.ai_socktype = SOCK_RAW; | ||
| 101 | else | ||
| 102 | usage(); | ||
| 103 | break; | ||
| 104 | default: | ||
| 105 | usage(); | ||
| 106 | /* NOTREACHED */ | ||
| 107 | } | ||
| 108 | } | ||
| 109 | argc -= optind; | ||
| 110 | argv += optind; | ||
| 111 | |||
| 112 | for(i = 0; i < argc; i++) { | ||
| 113 | |||
| 114 | if (i) | ||
| 115 | printf("\n"); | ||
| 116 | printf("===> \"%s\"\n", argv[i]); | ||
| 117 | host = gethostarg(argv[i]); | ||
| 118 | |||
| 119 | errno = 0; | ||
| 120 | h_errno = 0; | ||
| 121 | gai_errno = 0; | ||
| 122 | rrset_errno = 0; | ||
| 123 | |||
| 124 | gai_errno = getaddrinfo(host, servname, &hints, &ai); | ||
| 125 | |||
| 126 | print_errors(); | ||
| 127 | if (gai_errno == 0) { | ||
| 128 | for (res = ai; res; res = res->ai_next) | ||
| 129 | print_addrinfo(res); | ||
| 130 | freeaddrinfo(ai); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | return (0); | ||
| 135 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile b/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile deleted file mode 100644 index ec2f104ec7..0000000000 --- a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getaddrinfo | ||
| 6 | SRCS+= getaddrinfo.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr.c b/src/regress/lib/libc/asr/bin/gethostnamadr.c deleted file mode 100644 index b1b3e331a7..0000000000 --- a/src/regress/lib/libc/asr/bin/gethostnamadr.c +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | /* $OpenBSD: gethostnamadr.c,v 1.2 2012/07/29 19:51:36 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/types.h> | ||
| 18 | #include <sys/socket.h> | ||
| 19 | #include <netinet/in.h> | ||
| 20 | #include <arpa/inet.h> | ||
| 21 | |||
| 22 | #include <err.h> | ||
| 23 | #include <errno.h> | ||
| 24 | #include <getopt.h> | ||
| 25 | #include <stdio.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <string.h> | ||
| 28 | |||
| 29 | #include "common.h" | ||
| 30 | |||
| 31 | static void | ||
| 32 | usage(void) | ||
| 33 | { | ||
| 34 | extern const char * __progname; | ||
| 35 | |||
| 36 | fprintf(stderr, "usage: %s [-46e] <host...>\n", __progname); | ||
| 37 | exit(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | int | ||
| 41 | main(int argc, char *argv[]) | ||
| 42 | { | ||
| 43 | int i, ch, aflag, family = AF_INET; | ||
| 44 | struct hostent *h; | ||
| 45 | char *host; | ||
| 46 | char addr[16]; | ||
| 47 | int addrlen; | ||
| 48 | |||
| 49 | aflag = 0; | ||
| 50 | while((ch = getopt(argc, argv, "46ae")) != -1) { | ||
| 51 | switch(ch) { | ||
| 52 | case '4': | ||
| 53 | family = AF_INET; | ||
| 54 | break; | ||
| 55 | case '6': | ||
| 56 | family = AF_INET6; | ||
| 57 | break; | ||
| 58 | case 'a': | ||
| 59 | aflag = 1; | ||
| 60 | break; | ||
| 61 | case 'e': | ||
| 62 | long_err += 1; | ||
| 63 | break; | ||
| 64 | default: | ||
| 65 | usage(); | ||
| 66 | /* NOTREACHED */ | ||
| 67 | } | ||
| 68 | } | ||
| 69 | argc -= optind; | ||
| 70 | argv += optind; | ||
| 71 | |||
| 72 | for(i = 0; i < argc; i++) { | ||
| 73 | |||
| 74 | if (i) | ||
| 75 | printf("\n"); | ||
| 76 | printf("===> \"%s\"\n", argv[i]); | ||
| 77 | host = gethostarg(argv[i]); | ||
| 78 | |||
| 79 | if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1) | ||
| 80 | errx(1, "bad address"); | ||
| 81 | |||
| 82 | errno = 0; | ||
| 83 | h_errno = 0; | ||
| 84 | gai_errno = 0; | ||
| 85 | rrset_errno = 0; | ||
| 86 | |||
| 87 | if (aflag == 0) | ||
| 88 | h = gethostbyname2(host, family); | ||
| 89 | else | ||
| 90 | h = gethostbyaddr(addr, addrlen, family); | ||
| 91 | if (h) | ||
| 92 | print_hostent(h); | ||
| 93 | print_errors(); | ||
| 94 | } | ||
| 95 | |||
| 96 | return (0); | ||
| 97 | } | ||
| 98 | |||
| 99 | int | ||
| 100 | addr_from_str(char *addr, int *family, int *len, const char *src) | ||
| 101 | { | ||
| 102 | if (inet_pton(AF_INET6, src, addr) == 1) { | ||
| 103 | *family = AF_INET6; | ||
| 104 | *len = 16; | ||
| 105 | return (0); | ||
| 106 | } | ||
| 107 | if (inet_pton(AF_INET, src, addr) == 1) { | ||
| 108 | *family = AF_INET; | ||
| 109 | *len = 4; | ||
| 110 | return (0); | ||
| 111 | } | ||
| 112 | return (-1); | ||
| 113 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile b/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile deleted file mode 100644 index 84906ffbbd..0000000000 --- a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= gethostnamadr | ||
| 6 | SRCS+= gethostnamadr.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo.c b/src/regress/lib/libc/asr/bin/getnameinfo.c deleted file mode 100644 index 8702937a47..0000000000 --- a/src/regress/lib/libc/asr/bin/getnameinfo.c +++ /dev/null | |||
| @@ -1,112 +0,0 @@ | |||
| 1 | /* $OpenBSD: getnameinfo.c,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <errno.h> | ||
| 20 | #include <getopt.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | |||
| 25 | #include "common.h" | ||
| 26 | |||
| 27 | static void | ||
| 28 | usage(void) | ||
| 29 | { | ||
| 30 | extern const char * __progname; | ||
| 31 | |||
| 32 | fprintf(stderr, "usage: %s [-DFHNSe] [-p portno] <addr...>\n", __progname); | ||
| 33 | exit(1); | ||
| 34 | } | ||
| 35 | |||
| 36 | int | ||
| 37 | main(int argc, char *argv[]) | ||
| 38 | { | ||
| 39 | char serv[1024]; | ||
| 40 | char host[1024]; | ||
| 41 | const char *e; | ||
| 42 | int i, ch, flags = 0, port = 0; | ||
| 43 | struct sockaddr_storage ss; | ||
| 44 | struct sockaddr *sa; | ||
| 45 | |||
| 46 | sa = (struct sockaddr*)&ss; | ||
| 47 | |||
| 48 | while((ch = getopt(argc, argv, "DFHNSaep:")) != -1) { | ||
| 49 | switch(ch) { | ||
| 50 | case 'D': | ||
| 51 | flags |= NI_DGRAM; | ||
| 52 | break; | ||
| 53 | case 'F': | ||
| 54 | flags |= NI_NOFQDN; | ||
| 55 | break; | ||
| 56 | case 'H': | ||
| 57 | flags |= NI_NUMERICHOST; | ||
| 58 | break; | ||
| 59 | case 'N': | ||
| 60 | flags |= NI_NAMEREQD; | ||
| 61 | break; | ||
| 62 | case 'S': | ||
| 63 | flags |= NI_NUMERICSERV; | ||
| 64 | break; | ||
| 65 | case 'e': | ||
| 66 | long_err += 1; | ||
| 67 | break; | ||
| 68 | case 'p': | ||
| 69 | port = strtonum(optarg, 0, 65535, &e); | ||
| 70 | if (e) | ||
| 71 | usage(); | ||
| 72 | break; | ||
| 73 | default: | ||
| 74 | usage(); | ||
| 75 | /* NOTREACHED */ | ||
| 76 | } | ||
| 77 | } | ||
| 78 | argc -= optind; | ||
| 79 | argv += optind; | ||
| 80 | |||
| 81 | for(i = 0; i < argc; i++) { | ||
| 82 | |||
| 83 | if (i) | ||
| 84 | printf("\n"); | ||
| 85 | printf("===> \"%s\"\n", argv[i]); | ||
| 86 | |||
| 87 | if (sockaddr_from_str(sa, AF_UNSPEC, argv[i]) == -1) { | ||
| 88 | printf(" => invalid address\n"); | ||
| 89 | continue; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (sa->sa_family == PF_INET) | ||
| 93 | ((struct sockaddr_in *)sa)->sin_port = htons(port); | ||
| 94 | else if (sa->sa_family == PF_INET6) | ||
| 95 | ((struct sockaddr_in6 *)sa)->sin6_port = htons(port); | ||
| 96 | |||
| 97 | errno = 0; | ||
| 98 | h_errno = 0; | ||
| 99 | gai_errno = 0; | ||
| 100 | rrset_errno = 0; | ||
| 101 | |||
| 102 | gai_errno = getnameinfo(sa, sa->sa_len, host, sizeof host, serv, | ||
| 103 | sizeof serv, flags); | ||
| 104 | |||
| 105 | if (gai_errno == 0) | ||
| 106 | printf(" %s:%s\n", host, serv); | ||
| 107 | print_errors(); | ||
| 108 | |||
| 109 | } | ||
| 110 | |||
| 111 | return (0); | ||
| 112 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile b/src/regress/lib/libc/asr/bin/getnameinfo/Makefile deleted file mode 100644 index 4927ee9486..0000000000 --- a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getnameinfo | ||
| 6 | SRCS+= getnameinfo.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr.c b/src/regress/lib/libc/asr/bin/getnetnamadr.c deleted file mode 100644 index 4b7414264b..0000000000 --- a/src/regress/lib/libc/asr/bin/getnetnamadr.c +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | /* $OpenBSD: getnetnamadr.c,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/types.h> | ||
| 18 | #include <sys/socket.h> | ||
| 19 | #include <netinet/in.h> | ||
| 20 | #include <arpa/inet.h> | ||
| 21 | |||
| 22 | #include <err.h> | ||
| 23 | #include <errno.h> | ||
| 24 | #include <getopt.h> | ||
| 25 | #include <stdio.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <string.h> | ||
| 28 | |||
| 29 | #include "common.h" | ||
| 30 | |||
| 31 | static void | ||
| 32 | usage(void) | ||
| 33 | { | ||
| 34 | extern const char * __progname; | ||
| 35 | |||
| 36 | fprintf(stderr, "usage: %s [-aen] [host...]\n", __progname); | ||
| 37 | exit(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | int | ||
| 41 | main(int argc, char *argv[]) | ||
| 42 | { | ||
| 43 | int i, ch, nflag = 0; | ||
| 44 | struct netent *n; | ||
| 45 | char *host; | ||
| 46 | |||
| 47 | while((ch = getopt(argc, argv, "en")) != -1) { | ||
| 48 | switch(ch) { | ||
| 49 | case 'e': | ||
| 50 | long_err += 1; | ||
| 51 | break; | ||
| 52 | case 'n': | ||
| 53 | nflag = 1; | ||
| 54 | break; | ||
| 55 | default: | ||
| 56 | usage(); | ||
| 57 | /* NOTREACHED */ | ||
| 58 | } | ||
| 59 | } | ||
| 60 | argc -= optind; | ||
| 61 | argv += optind; | ||
| 62 | |||
| 63 | for(i = 0; i < argc; i++) { | ||
| 64 | |||
| 65 | if (i) | ||
| 66 | printf("\n"); | ||
| 67 | printf("===> \"%s\"\n", argv[i]); | ||
| 68 | host = gethostarg(argv[i]); | ||
| 69 | |||
| 70 | errno = 0; | ||
| 71 | h_errno = 0; | ||
| 72 | gai_errno = 0; | ||
| 73 | rrset_errno = 0; | ||
| 74 | |||
| 75 | if (nflag) | ||
| 76 | n = getnetbyname(host); | ||
| 77 | else | ||
| 78 | n = getnetbyaddr(inet_network(host), AF_INET); | ||
| 79 | if (n) | ||
| 80 | print_netent(n); | ||
| 81 | print_errors(); | ||
| 82 | } | ||
| 83 | |||
| 84 | return (0); | ||
| 85 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile b/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile deleted file mode 100644 index 521bf8eb7e..0000000000 --- a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getnetnamadr | ||
| 6 | SRCS+= getnetnamadr.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname.c b/src/regress/lib/libc/asr/bin/getrrsetbyname.c deleted file mode 100644 index 4a5aa57209..0000000000 --- a/src/regress/lib/libc/asr/bin/getrrsetbyname.c +++ /dev/null | |||
| @@ -1,88 +0,0 @@ | |||
| 1 | /* $OpenBSD: getrrsetbyname.c,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | |||
| 20 | #include <netinet/in.h> | ||
| 21 | #include <arpa/nameser.h> | ||
| 22 | |||
| 23 | #include <err.h> | ||
| 24 | #include <errno.h> | ||
| 25 | #include <getopt.h> | ||
| 26 | #include <resolv.h> | ||
| 27 | #include <stdio.h> | ||
| 28 | #include <stdlib.h> | ||
| 29 | #include <string.h> | ||
| 30 | |||
| 31 | #include "common.h" | ||
| 32 | |||
| 33 | static void | ||
| 34 | usage(void) | ||
| 35 | { | ||
| 36 | extern const char * __progname; | ||
| 37 | |||
| 38 | fprintf(stderr, "usage: %s [-e] [-t type] [host...]\n", | ||
| 39 | __progname); | ||
| 40 | exit(1); | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | main(int argc, char *argv[]) | ||
| 45 | { | ||
| 46 | int ch, i; | ||
| 47 | uint16_t type = T_A; | ||
| 48 | char *host; | ||
| 49 | struct rrsetinfo *rrset; | ||
| 50 | |||
| 51 | while((ch = getopt(argc, argv, "et:")) != -1) { | ||
| 52 | switch(ch) { | ||
| 53 | case 'e': | ||
| 54 | long_err += 1; | ||
| 55 | break; | ||
| 56 | case 't': | ||
| 57 | if ((type = strtotype(optarg)) == 0) | ||
| 58 | usage(); | ||
| 59 | break; | ||
| 60 | default: | ||
| 61 | usage(); | ||
| 62 | /* NOTREACHED */ | ||
| 63 | } | ||
| 64 | } | ||
| 65 | argc -= optind; | ||
| 66 | argv += optind; | ||
| 67 | |||
| 68 | for (i = 0; i < argc; i++) { | ||
| 69 | |||
| 70 | if (i) | ||
| 71 | printf("\n"); | ||
| 72 | printf("===> \"%s\"\n", argv[i]); | ||
| 73 | host = gethostarg(argv[i]); | ||
| 74 | |||
| 75 | errno = 0; | ||
| 76 | h_errno = 0; | ||
| 77 | gai_errno = 0; | ||
| 78 | rrset_errno = 0; | ||
| 79 | |||
| 80 | rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset); | ||
| 81 | |||
| 82 | if (rrset_errno == 0) | ||
| 83 | print_rrsetinfo(rrset); | ||
| 84 | print_errors(); | ||
| 85 | } | ||
| 86 | |||
| 87 | return (0); | ||
| 88 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile b/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile deleted file mode 100644 index 131403bea1..0000000000 --- a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getrrsetbyname | ||
| 6 | SRCS+= getrrsetbyname.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery.c b/src/regress/lib/libc/asr/bin/res_mkquery.c deleted file mode 100644 index a52023c5c0..0000000000 --- a/src/regress/lib/libc/asr/bin/res_mkquery.c +++ /dev/null | |||
| @@ -1,319 +0,0 @@ | |||
| 1 | /* $OpenBSD: res_mkquery.c,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | #include <sys/socket.h> | ||
| 20 | |||
| 21 | #include <netinet/in.h> | ||
| 22 | #include <arpa/nameser.h> | ||
| 23 | #include <arpa/inet.h> | ||
| 24 | |||
| 25 | #include <err.h> | ||
| 26 | #include <errno.h> | ||
| 27 | #include <getopt.h> | ||
| 28 | #include <inttypes.h> | ||
| 29 | #include <resolv.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | #include "common.h" | ||
| 35 | |||
| 36 | /* in asr.c but we don't want them exposed right now */ | ||
| 37 | static void dump_packet(const void *, size_t); | ||
| 38 | |||
| 39 | static char *print_query(struct query *, char *, size_t); | ||
| 40 | static char *print_rr(struct rr *, char *, size_t); | ||
| 41 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
| 42 | static char* print_dname(const char *, char *, size_t); | ||
| 43 | |||
| 44 | |||
| 45 | static void | ||
| 46 | usage(void) | ||
| 47 | { | ||
| 48 | extern const char * __progname; | ||
| 49 | |||
| 50 | fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n", | ||
| 51 | __progname); | ||
| 52 | exit(1); | ||
| 53 | } | ||
| 54 | |||
| 55 | int | ||
| 56 | main(int argc, char *argv[]) | ||
| 57 | { | ||
| 58 | int ch, i, r; | ||
| 59 | uint16_t type = T_A; | ||
| 60 | char buf[1024], *host; | ||
| 61 | |||
| 62 | while((ch = getopt(argc, argv, "et:")) != -1) { | ||
| 63 | switch(ch) { | ||
| 64 | case 'e': | ||
| 65 | long_err += 1; | ||
| 66 | break; | ||
| 67 | case 't': | ||
| 68 | if ((type = strtotype(optarg)) == 0) | ||
| 69 | usage(); | ||
| 70 | break; | ||
| 71 | default: | ||
| 72 | usage(); | ||
| 73 | /* NOTREACHED */ | ||
| 74 | } | ||
| 75 | } | ||
| 76 | argc -= optind; | ||
| 77 | argv += optind; | ||
| 78 | |||
| 79 | for (i = 0; i < argc; i++) { | ||
| 80 | |||
| 81 | if (i) | ||
| 82 | printf("\n"); | ||
| 83 | |||
| 84 | printf("===> \"%s\"\n", argv[i]); | ||
| 85 | host = gethostarg(argv[i]); | ||
| 86 | |||
| 87 | errno = 0; | ||
| 88 | h_errno = 0; | ||
| 89 | gai_errno = 0; | ||
| 90 | rrset_errno = 0; | ||
| 91 | |||
| 92 | r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf)); | ||
| 93 | if (r != -1) { | ||
| 94 | dump_packet(buf, r); | ||
| 95 | printf(";; MSG SIZE %i\n", r); | ||
| 96 | } | ||
| 97 | print_errors(); | ||
| 98 | } | ||
| 99 | |||
| 100 | return (0); | ||
| 101 | } | ||
| 102 | |||
| 103 | #define OPCODE_SHIFT 11 | ||
| 104 | #define Z_SHIFT 4 | ||
| 105 | |||
| 106 | static char* | ||
| 107 | print_header(struct header *h, char *buf, size_t max) | ||
| 108 | { | ||
| 109 | snprintf(buf, max, | ||
| 110 | "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i", | ||
| 111 | (h->flags & QR_MASK) ? "QR":" ", | ||
| 112 | (int)(OPCODE(h->flags) >> OPCODE_SHIFT), | ||
| 113 | (h->flags & AA_MASK) ? "AA":" ", | ||
| 114 | (h->flags & TC_MASK) ? "TC":" ", | ||
| 115 | (h->flags & RD_MASK) ? "RD":" ", | ||
| 116 | (h->flags & RA_MASK) ? "RA":" ", | ||
| 117 | ((h->flags & Z_MASK) >> Z_SHIFT), | ||
| 118 | rcodetostr(RCODE(h->flags)), | ||
| 119 | h->qdcount, h->ancount, h->nscount, h->arcount); | ||
| 120 | |||
| 121 | return buf; | ||
| 122 | } | ||
| 123 | |||
| 124 | static void | ||
| 125 | dump_packet(const void *data, size_t len) | ||
| 126 | { | ||
| 127 | char buf[1024]; | ||
| 128 | struct packed p; | ||
| 129 | struct header h; | ||
| 130 | struct query q; | ||
| 131 | struct rr rr; | ||
| 132 | int i, an, ns, ar, n; | ||
| 133 | |||
| 134 | packed_init(&p, (char *)data, len); | ||
| 135 | |||
| 136 | if (unpack_header(&p, &h) == -1) { | ||
| 137 | printf(";; BAD PACKET: %s\n", p.err); | ||
| 138 | return; | ||
| 139 | } | ||
| 140 | |||
| 141 | printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf)); | ||
| 142 | |||
| 143 | if (h.qdcount) | ||
| 144 | printf(";; QUERY SECTION:\n"); | ||
| 145 | for (i = 0; i < h.qdcount; i++) { | ||
| 146 | if (unpack_query(&p, &q) == -1) | ||
| 147 | goto error; | ||
| 148 | printf("%s\n", print_query(&q, buf, sizeof buf)); | ||
| 149 | } | ||
| 150 | |||
| 151 | an = 0; | ||
| 152 | ns = an + h.ancount; | ||
| 153 | ar = ns + h.nscount; | ||
| 154 | n = ar + h.arcount; | ||
| 155 | |||
| 156 | for (i = 0; i < n; i++) { | ||
| 157 | if (i == an) | ||
| 158 | printf("\n;; ANSWER SECTION:\n"); | ||
| 159 | if (i == ns) | ||
| 160 | printf("\n;; AUTHORITY SECTION:\n"); | ||
| 161 | if (i == ar) | ||
| 162 | printf("\n;; ADDITIONAL SECTION:\n"); | ||
| 163 | |||
| 164 | if (unpack_rr(&p, &rr) == -1) | ||
| 165 | goto error; | ||
| 166 | printf("%s\n", print_rr(&rr, buf, sizeof buf)); | ||
| 167 | } | ||
| 168 | |||
| 169 | if (p.offset != len) | ||
| 170 | printf(";; REMAINING GARBAGE %zu\n", len - p.offset); | ||
| 171 | |||
| 172 | error: | ||
| 173 | if (p.err) | ||
| 174 | printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, | ||
| 175 | p.err); | ||
| 176 | } | ||
| 177 | |||
| 178 | static const char * | ||
| 179 | inet6_ntoa(struct in6_addr a) | ||
| 180 | { | ||
| 181 | static char buf[256]; | ||
| 182 | struct sockaddr_in6 si; | ||
| 183 | |||
| 184 | si.sin6_len = sizeof(si); | ||
| 185 | si.sin6_family = PF_INET6; | ||
| 186 | si.sin6_addr = a; | ||
| 187 | |||
| 188 | return print_host((struct sockaddr*)&si, buf, sizeof buf); | ||
| 189 | } | ||
| 190 | |||
| 191 | static char* | ||
| 192 | print_rr(struct rr *rr, char *buf, size_t max) | ||
| 193 | { | ||
| 194 | char *res; | ||
| 195 | char tmp[256]; | ||
| 196 | char tmp2[256]; | ||
| 197 | int r; | ||
| 198 | |||
| 199 | res = buf; | ||
| 200 | |||
| 201 | r = snprintf(buf, max, "%s %u %s %s ", | ||
| 202 | print_dname(rr->rr_dname, tmp, sizeof tmp), | ||
| 203 | rr->rr_ttl, | ||
| 204 | classtostr(rr->rr_class), | ||
| 205 | typetostr(rr->rr_type)); | ||
| 206 | if (r == -1) { | ||
| 207 | buf[0] = '\0'; | ||
| 208 | return buf; | ||
| 209 | } | ||
| 210 | |||
| 211 | if ((size_t)r >= max) | ||
| 212 | return buf; | ||
| 213 | |||
| 214 | max -= r; | ||
| 215 | buf += r; | ||
| 216 | |||
| 217 | switch(rr->rr_type) { | ||
| 218 | case T_CNAME: | ||
| 219 | print_dname(rr->rr.cname.cname, buf, max); | ||
| 220 | break; | ||
| 221 | case T_MX: | ||
| 222 | snprintf(buf, max, "%"PRIu32" %s", | ||
| 223 | rr->rr.mx.preference, | ||
| 224 | print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); | ||
| 225 | break; | ||
| 226 | case T_NS: | ||
| 227 | print_dname(rr->rr.ns.nsname, buf, max); | ||
| 228 | break; | ||
| 229 | case T_PTR: | ||
| 230 | print_dname(rr->rr.ptr.ptrname, buf, max); | ||
| 231 | break; | ||
| 232 | case T_SOA: | ||
| 233 | snprintf(buf, max, | ||
| 234 | "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32, | ||
| 235 | print_dname(rr->rr.soa.rname, tmp, sizeof tmp), | ||
| 236 | print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), | ||
| 237 | rr->rr.soa.serial, | ||
| 238 | rr->rr.soa.refresh, | ||
| 239 | rr->rr.soa.retry, | ||
| 240 | rr->rr.soa.expire, | ||
| 241 | rr->rr.soa.minimum); | ||
| 242 | break; | ||
| 243 | case T_A: | ||
| 244 | if (rr->rr_class != C_IN) | ||
| 245 | goto other; | ||
| 246 | snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr)); | ||
| 247 | break; | ||
| 248 | case T_AAAA: | ||
| 249 | if (rr->rr_class != C_IN) | ||
| 250 | goto other; | ||
| 251 | snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6)); | ||
| 252 | break; | ||
| 253 | default: | ||
| 254 | other: | ||
| 255 | snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen); | ||
| 256 | break; | ||
| 257 | } | ||
| 258 | |||
| 259 | return (res); | ||
| 260 | } | ||
| 261 | |||
| 262 | static char* | ||
| 263 | print_query(struct query *q, char *buf, size_t max) | ||
| 264 | { | ||
| 265 | char b[256]; | ||
| 266 | |||
| 267 | snprintf(buf, max, "%s %s %s", | ||
| 268 | print_dname(q->q_dname, b, sizeof b), | ||
| 269 | classtostr(q->q_class), typetostr(q->q_type)); | ||
| 270 | |||
| 271 | return (buf); | ||
| 272 | } | ||
| 273 | |||
| 274 | |||
| 275 | static char * | ||
| 276 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
| 277 | { | ||
| 278 | switch (sa->sa_family) { | ||
| 279 | case AF_INET: | ||
| 280 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len); | ||
| 281 | break; | ||
| 282 | case AF_INET6: | ||
| 283 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len); | ||
| 284 | break; | ||
| 285 | default: | ||
| 286 | buf[0] = '\0'; | ||
| 287 | } | ||
| 288 | return (buf); | ||
| 289 | } | ||
| 290 | |||
| 291 | static char* | ||
| 292 | print_dname(const char *_dname, char *buf, size_t max) | ||
| 293 | { | ||
| 294 | const unsigned char *dname = _dname; | ||
| 295 | char *res; | ||
| 296 | size_t left, n, count; | ||
| 297 | |||
| 298 | if (_dname[0] == 0) { | ||
| 299 | strlcpy(buf, ".", max); | ||
| 300 | return buf; | ||
| 301 | } | ||
| 302 | |||
| 303 | res = buf; | ||
| 304 | left = max - 1; | ||
| 305 | for (n = 0; dname[0] && left; n += dname[0]) { | ||
| 306 | count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); | ||
| 307 | memmove(buf, dname + 1, count); | ||
| 308 | dname += dname[0] + 1; | ||
| 309 | left -= count; | ||
| 310 | buf += count; | ||
| 311 | if (left) { | ||
| 312 | left -= 1; | ||
| 313 | *buf++ = '.'; | ||
| 314 | } | ||
| 315 | } | ||
| 316 | buf[0] = 0; | ||
| 317 | |||
| 318 | return (res); | ||
| 319 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile b/src/regress/lib/libc/asr/bin/res_mkquery/Makefile deleted file mode 100644 index 4ae259e45d..0000000000 --- a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= res_mkquery | ||
| 6 | SRCS+= res_mkquery.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/res_query.c b/src/regress/lib/libc/asr/bin/res_query.c deleted file mode 100644 index 3565eeebed..0000000000 --- a/src/regress/lib/libc/asr/bin/res_query.c +++ /dev/null | |||
| @@ -1,355 +0,0 @@ | |||
| 1 | /* $OpenBSD: res_query.c,v 1.2 2017/03/09 07:56:38 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | #include <sys/socket.h> | ||
| 20 | #include <sys/time.h> | ||
| 21 | |||
| 22 | #include <netinet/in.h> | ||
| 23 | #include <arpa/nameser.h> | ||
| 24 | #include <arpa/inet.h> | ||
| 25 | |||
| 26 | #include <err.h> | ||
| 27 | #include <errno.h> | ||
| 28 | #include <getopt.h> | ||
| 29 | #include <inttypes.h> | ||
| 30 | #include <resolv.h> | ||
| 31 | #include <stdio.h> | ||
| 32 | #include <stdlib.h> | ||
| 33 | #include <string.h> | ||
| 34 | |||
| 35 | #include "common.h" | ||
| 36 | |||
| 37 | /* in asr.c but we don't want them exposed right now */ | ||
| 38 | static void dump_packet(const void *, size_t); | ||
| 39 | |||
| 40 | static char *print_query(struct query *, char *, size_t); | ||
| 41 | static char *print_rr(struct rr *, char *, size_t); | ||
| 42 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
| 43 | static char* print_dname(const char *, char *, size_t); | ||
| 44 | |||
| 45 | |||
| 46 | static int | ||
| 47 | msec(struct timeval start, struct timeval end) | ||
| 48 | { | ||
| 49 | return (int)((end.tv_sec - start.tv_sec) * 1000 | ||
| 50 | + (end.tv_usec - start.tv_usec) / 1000); | ||
| 51 | } | ||
| 52 | |||
| 53 | static void | ||
| 54 | usage(void) | ||
| 55 | { | ||
| 56 | extern const char * __progname; | ||
| 57 | |||
| 58 | fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n", | ||
| 59 | __progname); | ||
| 60 | exit(1); | ||
| 61 | } | ||
| 62 | |||
| 63 | int | ||
| 64 | main(int argc, char *argv[]) | ||
| 65 | { | ||
| 66 | struct timeval start, end; | ||
| 67 | time_t when; | ||
| 68 | int ch, i, qflag, dflag, r; | ||
| 69 | uint16_t type = T_A; | ||
| 70 | char buf[1024], *host; | ||
| 71 | |||
| 72 | dflag = 0; | ||
| 73 | qflag = 0; | ||
| 74 | |||
| 75 | while((ch = getopt(argc, argv, "deqt:")) != -1) { | ||
| 76 | switch(ch) { | ||
| 77 | case 'd': | ||
| 78 | dflag = 1; | ||
| 79 | break; | ||
| 80 | case 'e': | ||
| 81 | long_err += 1; | ||
| 82 | break; | ||
| 83 | case 'q': | ||
| 84 | qflag = 1; | ||
| 85 | break; | ||
| 86 | case 't': | ||
| 87 | if ((type = strtotype(optarg)) == 0) | ||
| 88 | usage(); | ||
| 89 | break; | ||
| 90 | default: | ||
| 91 | usage(); | ||
| 92 | /* NOTREACHED */ | ||
| 93 | } | ||
| 94 | } | ||
| 95 | argc -= optind; | ||
| 96 | argv += optind; | ||
| 97 | |||
| 98 | for (i = 0; i < argc; i++) { | ||
| 99 | |||
| 100 | if (i) | ||
| 101 | printf("\n"); | ||
| 102 | |||
| 103 | printf("===> \"%s\"\n", argv[i]); | ||
| 104 | host = gethostarg(argv[i]); | ||
| 105 | |||
| 106 | errno = 0; | ||
| 107 | h_errno = 0; | ||
| 108 | gai_errno = 0; | ||
| 109 | rrset_errno = 0; | ||
| 110 | |||
| 111 | if (gettimeofday(&start, NULL) != 0) | ||
| 112 | err(1, "gettimeofday"); | ||
| 113 | |||
| 114 | if (qflag) | ||
| 115 | r = res_query(host, C_IN, type, buf, sizeof(buf)); | ||
| 116 | else | ||
| 117 | r = res_search(host, C_IN, type, buf, sizeof(buf)); | ||
| 118 | |||
| 119 | if (gettimeofday(&end, NULL) != 0) | ||
| 120 | err(1, "gettimeofday"); | ||
| 121 | |||
| 122 | if (r != -1) { | ||
| 123 | dump_packet(buf, r); | ||
| 124 | printf("\n"); | ||
| 125 | if (dflag) { | ||
| 126 | printf(";; Query time: %d msec\n", | ||
| 127 | msec(start, end)); | ||
| 128 | when = time(NULL); | ||
| 129 | printf(";; WHEN: %s", ctime(&when)); | ||
| 130 | } | ||
| 131 | printf(";; MSG SIZE rcvd: %i\n", r); | ||
| 132 | } | ||
| 133 | print_errors(); | ||
| 134 | } | ||
| 135 | |||
| 136 | return (0); | ||
| 137 | } | ||
| 138 | |||
| 139 | #define OPCODE_SHIFT 11 | ||
| 140 | #define Z_SHIFT 4 | ||
| 141 | |||
| 142 | static char* | ||
| 143 | print_header(struct header *h, char *buf, size_t max) | ||
| 144 | { | ||
| 145 | snprintf(buf, max, | ||
| 146 | "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i", | ||
| 147 | (h->flags & QR_MASK) ? "QR":" ", | ||
| 148 | (int)(OPCODE(h->flags) >> OPCODE_SHIFT), | ||
| 149 | (h->flags & AA_MASK) ? "AA":" ", | ||
| 150 | (h->flags & TC_MASK) ? "TC":" ", | ||
| 151 | (h->flags & RD_MASK) ? "RD":" ", | ||
| 152 | (h->flags & RA_MASK) ? "RA":" ", | ||
| 153 | ((h->flags & Z_MASK) >> Z_SHIFT), | ||
| 154 | rcodetostr(RCODE(h->flags)), | ||
| 155 | h->qdcount, h->ancount, h->nscount, h->arcount); | ||
| 156 | |||
| 157 | return buf; | ||
| 158 | } | ||
| 159 | |||
| 160 | static void | ||
| 161 | dump_packet(const void *data, size_t len) | ||
| 162 | { | ||
| 163 | char buf[1024]; | ||
| 164 | struct packed p; | ||
| 165 | struct header h; | ||
| 166 | struct query q; | ||
| 167 | struct rr rr; | ||
| 168 | int i, an, ns, ar, n; | ||
| 169 | |||
| 170 | packed_init(&p, (char *)data, len); | ||
| 171 | |||
| 172 | if (unpack_header(&p, &h) == -1) { | ||
| 173 | printf(";; BAD PACKET: %s\n", p.err); | ||
| 174 | return; | ||
| 175 | } | ||
| 176 | |||
| 177 | printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf)); | ||
| 178 | |||
| 179 | if (h.qdcount) | ||
| 180 | printf(";; QUERY SECTION:\n"); | ||
| 181 | for (i = 0; i < h.qdcount; i++) { | ||
| 182 | if (unpack_query(&p, &q) == -1) | ||
| 183 | goto error; | ||
| 184 | printf("%s\n", print_query(&q, buf, sizeof buf)); | ||
| 185 | } | ||
| 186 | |||
| 187 | an = 0; | ||
| 188 | ns = an + h.ancount; | ||
| 189 | ar = ns + h.nscount; | ||
| 190 | n = ar + h.arcount; | ||
| 191 | |||
| 192 | for (i = 0; i < n; i++) { | ||
| 193 | if (i == an) | ||
| 194 | printf("\n;; ANSWER SECTION:\n"); | ||
| 195 | if (i == ns) | ||
| 196 | printf("\n;; AUTHORITY SECTION:\n"); | ||
| 197 | if (i == ar) | ||
| 198 | printf("\n;; ADDITIONAL SECTION:\n"); | ||
| 199 | |||
| 200 | if (unpack_rr(&p, &rr) == -1) | ||
| 201 | goto error; | ||
| 202 | printf("%s\n", print_rr(&rr, buf, sizeof buf)); | ||
| 203 | } | ||
| 204 | |||
| 205 | if (p.offset != len) | ||
| 206 | printf(";; REMAINING GARBAGE %zu\n", len - p.offset); | ||
| 207 | |||
| 208 | error: | ||
| 209 | if (p.err) | ||
| 210 | printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, | ||
| 211 | p.err); | ||
| 212 | } | ||
| 213 | |||
| 214 | static const char * | ||
| 215 | inet6_ntoa(struct in6_addr a) | ||
| 216 | { | ||
| 217 | static char buf[256]; | ||
| 218 | struct sockaddr_in6 si; | ||
| 219 | |||
| 220 | si.sin6_len = sizeof(si); | ||
| 221 | si.sin6_family = PF_INET6; | ||
| 222 | si.sin6_addr = a; | ||
| 223 | |||
| 224 | return print_host((struct sockaddr*)&si, buf, sizeof buf); | ||
| 225 | } | ||
| 226 | |||
| 227 | static char* | ||
| 228 | print_rr(struct rr *rr, char *buf, size_t max) | ||
| 229 | { | ||
| 230 | char *res; | ||
| 231 | char tmp[256]; | ||
| 232 | char tmp2[256]; | ||
| 233 | int r; | ||
| 234 | |||
| 235 | res = buf; | ||
| 236 | |||
| 237 | r = snprintf(buf, max, "%s %u %s %s ", | ||
| 238 | print_dname(rr->rr_dname, tmp, sizeof tmp), | ||
| 239 | rr->rr_ttl, | ||
| 240 | classtostr(rr->rr_class), | ||
| 241 | typetostr(rr->rr_type)); | ||
| 242 | if (r == -1) { | ||
| 243 | buf[0] = '\0'; | ||
| 244 | return buf; | ||
| 245 | } | ||
| 246 | |||
| 247 | if ((size_t)r >= max) | ||
| 248 | return buf; | ||
| 249 | |||
| 250 | max -= r; | ||
| 251 | buf += r; | ||
| 252 | |||
| 253 | switch(rr->rr_type) { | ||
| 254 | case T_CNAME: | ||
| 255 | print_dname(rr->rr.cname.cname, buf, max); | ||
| 256 | break; | ||
| 257 | case T_MX: | ||
| 258 | snprintf(buf, max, "%"PRIu32" %s", | ||
| 259 | rr->rr.mx.preference, | ||
| 260 | print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); | ||
| 261 | break; | ||
| 262 | case T_NS: | ||
| 263 | print_dname(rr->rr.ns.nsname, buf, max); | ||
| 264 | break; | ||
| 265 | case T_PTR: | ||
| 266 | print_dname(rr->rr.ptr.ptrname, buf, max); | ||
| 267 | break; | ||
| 268 | case T_SOA: | ||
| 269 | snprintf(buf, max, | ||
| 270 | "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32, | ||
| 271 | print_dname(rr->rr.soa.rname, tmp, sizeof tmp), | ||
| 272 | print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), | ||
| 273 | rr->rr.soa.serial, | ||
| 274 | rr->rr.soa.refresh, | ||
| 275 | rr->rr.soa.retry, | ||
| 276 | rr->rr.soa.expire, | ||
| 277 | rr->rr.soa.minimum); | ||
| 278 | break; | ||
| 279 | case T_A: | ||
| 280 | if (rr->rr_class != C_IN) | ||
| 281 | goto other; | ||
| 282 | snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr)); | ||
| 283 | break; | ||
| 284 | case T_AAAA: | ||
| 285 | if (rr->rr_class != C_IN) | ||
| 286 | goto other; | ||
| 287 | snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6)); | ||
| 288 | break; | ||
| 289 | default: | ||
| 290 | other: | ||
| 291 | snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen); | ||
| 292 | break; | ||
| 293 | } | ||
| 294 | |||
| 295 | return (res); | ||
| 296 | } | ||
| 297 | |||
| 298 | static char* | ||
| 299 | print_query(struct query *q, char *buf, size_t max) | ||
| 300 | { | ||
| 301 | char b[256]; | ||
| 302 | |||
| 303 | snprintf(buf, max, "%s %s %s", | ||
| 304 | print_dname(q->q_dname, b, sizeof b), | ||
| 305 | classtostr(q->q_class), typetostr(q->q_type)); | ||
| 306 | |||
| 307 | return (buf); | ||
| 308 | } | ||
| 309 | |||
| 310 | |||
| 311 | static char * | ||
| 312 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
| 313 | { | ||
| 314 | switch (sa->sa_family) { | ||
| 315 | case AF_INET: | ||
| 316 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len); | ||
| 317 | break; | ||
| 318 | case AF_INET6: | ||
| 319 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len); | ||
| 320 | break; | ||
| 321 | default: | ||
| 322 | buf[0] = '\0'; | ||
| 323 | } | ||
| 324 | return (buf); | ||
| 325 | } | ||
| 326 | |||
| 327 | static char* | ||
| 328 | print_dname(const char *_dname, char *buf, size_t max) | ||
| 329 | { | ||
| 330 | const unsigned char *dname = _dname; | ||
| 331 | char *res; | ||
| 332 | size_t left, n, count; | ||
| 333 | |||
| 334 | if (_dname[0] == 0) { | ||
| 335 | strlcpy(buf, ".", max); | ||
| 336 | return buf; | ||
| 337 | } | ||
| 338 | |||
| 339 | res = buf; | ||
| 340 | left = max - 1; | ||
| 341 | for (n = 0; dname[0] && left; n += dname[0]) { | ||
| 342 | count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); | ||
| 343 | memmove(buf, dname + 1, count); | ||
| 344 | dname += dname[0] + 1; | ||
| 345 | left -= count; | ||
| 346 | buf += count; | ||
| 347 | if (left) { | ||
| 348 | left -= 1; | ||
| 349 | *buf++ = '.'; | ||
| 350 | } | ||
| 351 | } | ||
| 352 | buf[0] = 0; | ||
| 353 | |||
| 354 | return (res); | ||
| 355 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/res_query/Makefile b/src/regress/lib/libc/asr/bin/res_query/Makefile deleted file mode 100644 index 6f4d83392b..0000000000 --- a/src/regress/lib/libc/asr/bin/res_query/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= res_query | ||
| 6 | SRCS+= res_query.c | ||
| 7 | |||
| 8 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/bin/threads.c b/src/regress/lib/libc/asr/bin/threads.c deleted file mode 100644 index f296f1d6f7..0000000000 --- a/src/regress/lib/libc/asr/bin/threads.c +++ /dev/null | |||
| @@ -1,140 +0,0 @@ | |||
| 1 | /* $OpenBSD: threads.c,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <sys/time.h> | ||
| 18 | #include <sys/resource.h> | ||
| 19 | |||
| 20 | #include <assert.h> | ||
| 21 | #include <err.h> | ||
| 22 | #include <getopt.h> | ||
| 23 | #include <pthread.h> | ||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <time.h> | ||
| 27 | |||
| 28 | #include <netdb.h> | ||
| 29 | |||
| 30 | #define MAX_THREADS 50 | ||
| 31 | |||
| 32 | int ac; | ||
| 33 | char **av; | ||
| 34 | int loop; | ||
| 35 | int nthreads; | ||
| 36 | |||
| 37 | int long_err; | ||
| 38 | int gai_errno; | ||
| 39 | int rrset_errno; | ||
| 40 | |||
| 41 | void async_resolver_done(void *); | ||
| 42 | |||
| 43 | void stats(void) | ||
| 44 | { | ||
| 45 | struct rusage ru; | ||
| 46 | |||
| 47 | getrusage(RUSAGE_SELF, &ru); | ||
| 48 | printf("%li\n", ru.ru_maxrss); | ||
| 49 | } | ||
| 50 | |||
| 51 | void* | ||
| 52 | task(void *arg) | ||
| 53 | { | ||
| 54 | int id, i, j, c; | ||
| 55 | struct addrinfo *ai, *n; | ||
| 56 | |||
| 57 | id = *((int*) arg); | ||
| 58 | |||
| 59 | n = NULL; c =0; | ||
| 60 | |||
| 61 | for(j = 0; j < loop; j++) | ||
| 62 | for(i = 0; i < ac; i++) { | ||
| 63 | if (getaddrinfo(av[i], NULL, NULL, &ai) == 0) { | ||
| 64 | /* | ||
| 65 | for (c = 0, n = ai; n; c++, n = n->ai_next); | ||
| 66 | printf("%i:%s: ok: %i\n", id, av[i], c); | ||
| 67 | */ | ||
| 68 | freeaddrinfo(ai); | ||
| 69 | } else { | ||
| 70 | /* | ||
| 71 | printf("%i:%s: fail\n", id, av[i]); | ||
| 72 | */ | ||
| 73 | } | ||
| 74 | } | ||
| 75 | return (NULL); | ||
| 76 | } | ||
| 77 | |||
| 78 | void | ||
| 79 | usage(void) | ||
| 80 | { | ||
| 81 | extern const char *__progname; | ||
| 82 | fprintf(stderr, "usage: %s [-L loop] [-l loop] [-t threads] <host> ...\n", | ||
| 83 | __progname); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | main(int argc, char **argv) | ||
| 88 | { | ||
| 89 | pthread_t th[MAX_THREADS]; | ||
| 90 | int th_args[MAX_THREADS], r, i, ch; | ||
| 91 | int n, LOOP; | ||
| 92 | |||
| 93 | nthreads = 1; | ||
| 94 | loop = 1; | ||
| 95 | LOOP = 1; | ||
| 96 | |||
| 97 | while ((ch = getopt(argc, argv, "L:l:t:")) != -1) { | ||
| 98 | switch (ch) { | ||
| 99 | case 'L': | ||
| 100 | LOOP = atoi(optarg); | ||
| 101 | break; | ||
| 102 | case 'l': | ||
| 103 | loop = atoi(optarg); | ||
| 104 | break; | ||
| 105 | case 't': | ||
| 106 | nthreads = atoi(optarg); | ||
| 107 | if (nthreads > MAX_THREADS) | ||
| 108 | nthreads = MAX_THREADS; | ||
| 109 | break; | ||
| 110 | default: | ||
| 111 | usage(); | ||
| 112 | /* NOTREACHED */ | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | argc -= optind; | ||
| 117 | argv += optind; | ||
| 118 | |||
| 119 | ac = argc; | ||
| 120 | av = argv; | ||
| 121 | |||
| 122 | printf("%i %i %i\n", LOOP, nthreads, loop); | ||
| 123 | for (n = 0; n < LOOP; n ++) { | ||
| 124 | for (i = 0; i < nthreads; i++) { | ||
| 125 | th_args[i] = i; | ||
| 126 | r = pthread_create(&th[i], NULL, task, (void *) &th_args[i]); | ||
| 127 | if (r == -1) | ||
| 128 | errx(1, "pthread_create"); | ||
| 129 | } | ||
| 130 | for (i = 0; i < nthreads; i++) | ||
| 131 | pthread_join(th[i], NULL); | ||
| 132 | |||
| 133 | if (nthreads == 0) | ||
| 134 | task(&n); | ||
| 135 | |||
| 136 | stats(); | ||
| 137 | } | ||
| 138 | |||
| 139 | return (0); | ||
| 140 | } | ||
diff --git a/src/regress/lib/libc/asr/bin/threads/Makefile b/src/regress/lib/libc/asr/bin/threads/Makefile deleted file mode 100644 index 3252511cd1..0000000000 --- a/src/regress/lib/libc/asr/bin/threads/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= threads | ||
| 6 | SRCS+= threads.c | ||
| 7 | |||
| 8 | LDADD= -lpthread | ||
| 9 | |||
| 10 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/asr/regress.sh b/src/regress/lib/libc/asr/regress.sh deleted file mode 100644 index a0950cefde..0000000000 --- a/src/regress/lib/libc/asr/regress.sh +++ /dev/null | |||
| @@ -1,111 +0,0 @@ | |||
| 1 | # $OpenBSD: regress.sh,v 1.7 2017/03/10 17:23:48 eric Exp $ | ||
| 2 | |||
| 3 | . regress.subr | ||
| 4 | |||
| 5 | test_res_mkquery() | ||
| 6 | { | ||
| 7 | for i in $@; do | ||
| 8 | regress res_mkquery $i | ||
| 9 | done | ||
| 10 | } | ||
| 11 | |||
| 12 | test_res_query() | ||
| 13 | { | ||
| 14 | for i in $@; do | ||
| 15 | regress res_query $i | ||
| 16 | regress res_query -q $i | ||
| 17 | done | ||
| 18 | } | ||
| 19 | |||
| 20 | test_getrrsetbyname() | ||
| 21 | { | ||
| 22 | for i in $@; do | ||
| 23 | regress getrrsetbyname $i | ||
| 24 | regress getrrsetbyname -t MX $i | ||
| 25 | regress getrrsetbyname -t AAAA $i | ||
| 26 | done | ||
| 27 | } | ||
| 28 | |||
| 29 | test_gethostbyname() | ||
| 30 | { | ||
| 31 | for i in $@; do | ||
| 32 | regress gethostnamadr $i | ||
| 33 | regress gethostnamadr -4 $i | ||
| 34 | regress gethostnamadr -6 $i | ||
| 35 | done | ||
| 36 | } | ||
| 37 | |||
| 38 | test_gethostbyaddr() | ||
| 39 | { | ||
| 40 | for i in $@; do | ||
| 41 | regress gethostnamadr -a $i | ||
| 42 | done | ||
| 43 | } | ||
| 44 | |||
| 45 | test_getaddrinfo() | ||
| 46 | { | ||
| 47 | for i in $@; do | ||
| 48 | regress getaddrinfo $i | ||
| 49 | regress getaddrinfo -C $i | ||
| 50 | regress getaddrinfo -F $i | ||
| 51 | regress getaddrinfo -CF $i | ||
| 52 | regress getaddrinfo -P $i | ||
| 53 | regress getaddrinfo -PF $i | ||
| 54 | regress getaddrinfo -PC $i | ||
| 55 | regress getaddrinfo -H $i | ||
| 56 | regress getaddrinfo -p tcp $i | ||
| 57 | regress getaddrinfo -p udp $i | ||
| 58 | regress getaddrinfo -s www $i | ||
| 59 | regress getaddrinfo -s bad $i | ||
| 60 | regress getaddrinfo -S -s 8081 $i | ||
| 61 | regress getaddrinfo -S -s bad $i | ||
| 62 | regress getaddrinfo -P -s syslog $i | ||
| 63 | regress getaddrinfo -P -s syslog -p tcp $i | ||
| 64 | regress getaddrinfo -P -s syslog -p udp $i | ||
| 65 | done | ||
| 66 | } | ||
| 67 | |||
| 68 | test_getaddrinfo2() | ||
| 69 | { | ||
| 70 | for i in $@; do | ||
| 71 | regress getaddrinfo -f inet6 -t raw -p icmpv6 $i | ||
| 72 | done | ||
| 73 | } | ||
| 74 | |||
| 75 | test_getnameinfo() | ||
| 76 | { | ||
| 77 | for i in $@; do | ||
| 78 | regress getnameinfo $i | ||
| 79 | regress getnameinfo -D $i | ||
| 80 | regress getnameinfo -F $i | ||
| 81 | regress getnameinfo -H $i | ||
| 82 | regress getnameinfo -N $i | ||
| 83 | regress getnameinfo -S $i | ||
| 84 | regress getnameinfo -p 80 $i | ||
| 85 | regress getnameinfo -p 514 $i | ||
| 86 | regress getnameinfo -p 514 -D $i | ||
| 87 | regress getnameinfo -p 5566 $i | ||
| 88 | done | ||
| 89 | } | ||
| 90 | |||
| 91 | WEIRD="EMPTY . .. ..." | ||
| 92 | BASIC="localhost $(hostname -s) $(hostname)" | ||
| 93 | EXTRA="undeadly.org www.openbsd.org cvs.openbsd.org www.google.com www.bing.com" | ||
| 94 | |||
| 95 | ADDRS="0.0.0.0 :: 127.0.0.1 ::1 212.227.193.194" | ||
| 96 | |||
| 97 | for e in file bind local; do | ||
| 98 | regress_setenv $e | ||
| 99 | |||
| 100 | test_res_mkquery $WEIRD $BASIC | ||
| 101 | test_res_query $WEIRD $BASIC $EXTRA | ||
| 102 | test_getrrsetbyname $WEIRD $BASIC $EXTRA | ||
| 103 | test_gethostbyname $WEIRD $BASIC $EXTRA | ||
| 104 | test_gethostbyaddr $ADDRS | ||
| 105 | test_getaddrinfo NULL $WEIRD $BASIC $EXTRA | ||
| 106 | test_getaddrinfo2 undeadly.org www.kame.net | ||
| 107 | test_getnameinfo $ADDRS | ||
| 108 | test_gethostbyname $ADDRS | ||
| 109 | done | ||
| 110 | |||
| 111 | regress_digest | ||
diff --git a/src/regress/lib/libc/asr/regress.subr b/src/regress/lib/libc/asr/regress.subr deleted file mode 100644 index 6ce645bc33..0000000000 --- a/src/regress/lib/libc/asr/regress.subr +++ /dev/null | |||
| @@ -1,122 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # $OpenBSD: regress.subr,v 1.4 2017/03/14 20:22:06 eric Exp $ | ||
| 3 | |||
| 4 | set -e | ||
| 5 | |||
| 6 | fail() | ||
| 7 | { | ||
| 8 | echo "*** ERROR: $@" | ||
| 9 | exit 1 | ||
| 10 | } | ||
| 11 | |||
| 12 | regress() | ||
| 13 | { | ||
| 14 | local cmd="$1" | ||
| 15 | local bin0="/bin/${cmd}${A}" | ||
| 16 | local bin1="/bin/${cmd}${B}" | ||
| 17 | local out="${OUTDIR}/test-${COUNT}.out" | ||
| 18 | local out0="${OUTDIR}/test-${COUNT}${A}.out" | ||
| 19 | local out1="${OUTDIR}/test-${COUNT}${B}.out" | ||
| 20 | local err0="${OUTDIR}/test-${COUNT}${A}.err" | ||
| 21 | local err1="${OUTDIR}/test-${COUNT}${B}.err" | ||
| 22 | local outdiff="${OUTDIR}/test-${COUNT}${A}${B}.diff" | ||
| 23 | shift | ||
| 24 | |||
| 25 | test -x "${ROOTDIR}${bin0}" || fail "${ROOTDIR}${bin0}" not executable | ||
| 26 | test -x "${ROOTDIR}${bin1}" || fail "${ROOTDIR}${bin1}" not executable | ||
| 27 | |||
| 28 | echo -n "${cmd} $@ ." | ||
| 29 | |||
| 30 | set +e | ||
| 31 | chroot -u bin "${ROOTDIR}" ${bin0} $@ > ${out0} | ||
| 32 | echo -n . | ||
| 33 | chroot -u bin "${ROOTDIR}" ${bin1} $@ > ${out1} | ||
| 34 | echo -n "." | ||
| 35 | |||
| 36 | diff -u ${out0} ${out1} > ${outdiff} | ||
| 37 | set -e | ||
| 38 | if test -s ${outdiff}; then | ||
| 39 | FAIL=$((FAIL+1)) | ||
| 40 | echo fail | ||
| 41 | echo "### FAIL [#${COUNT} env=${REGRESSENV}] ${cmd} $@" >> $ERR | ||
| 42 | cat ${outdiff} >> $ERR | ||
| 43 | echo >> $ERR | ||
| 44 | else | ||
| 45 | rm ${outdiff} | ||
| 46 | rm ${out1} | ||
| 47 | mv ${out0} ${out} | ||
| 48 | OK=$((OK+1)) | ||
| 49 | echo ok | ||
| 50 | echo "### OK [#${COUNT} env=$REGRESSENV] ${cmd} $@" >> $OUT | ||
| 51 | cat ${out} >> $OUT | ||
| 52 | echo >> $OUT | ||
| 53 | fi | ||
| 54 | |||
| 55 | COUNT=$((COUNT+1)) | ||
| 56 | } | ||
| 57 | |||
| 58 | regress_setenv() | ||
| 59 | { | ||
| 60 | local _name="$1" | ||
| 61 | |||
| 62 | echo "==> using env $_name" | ||
| 63 | |||
| 64 | mkdir -p "${ROOTDIR}/etc/" | ||
| 65 | cp /etc/hosts "${ROOTDIR}/etc/" | ||
| 66 | cp /etc/resolv.conf "${ROOTDIR}/etc/" | ||
| 67 | cp /etc/protocols "${ROOTDIR}/etc/" | ||
| 68 | cp /etc/networks "${ROOTDIR}/etc/" | ||
| 69 | cp /etc/services "${ROOTDIR}/etc/" | ||
| 70 | |||
| 71 | case $_name in | ||
| 72 | empty) | ||
| 73 | rm -f "${ROOTDIR}/etc/*" | ||
| 74 | ;; | ||
| 75 | local) | ||
| 76 | ;; | ||
| 77 | file) | ||
| 78 | grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf" | ||
| 79 | echo "lookup file" >> "${ROOTDIR}/etc/resolv.conf" | ||
| 80 | ;; | ||
| 81 | bind) | ||
| 82 | grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf" | ||
| 83 | echo "lookup bind" >> "${ROOTDIR}/etc/resolv.conf" | ||
| 84 | ;; | ||
| 85 | *) | ||
| 86 | fail unknown env $_name | ||
| 87 | ;; | ||
| 88 | esac | ||
| 89 | REGRESSENV=$_name | ||
| 90 | } | ||
| 91 | |||
| 92 | regress_digest() | ||
| 93 | { | ||
| 94 | echo "===> done" | ||
| 95 | test -f $ERR && (echo; cat $ERR; echo "===> errfile=$ERR") | ||
| 96 | echo "===> logfile=$OUT" | ||
| 97 | echo "===> run=$COUNT ok=$OK fail=$FAIL error=$ERROR" | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | # needed for chroot | ||
| 102 | test "$(id -u)" -ne 0 && fail need root privileges to run this script | ||
| 103 | |||
| 104 | # we really really want to avoid erasing /etc later | ||
| 105 | test "${RUNDIR}" || fail RUNDIR is not set | ||
| 106 | |||
| 107 | ROOTDIR=$(readlink -fn ${RUNDIR}) | ||
| 108 | test "${ROOTDIR}" == "/" && fail RUNDIR is root dir: ${RUNDIR} | ||
| 109 | |||
| 110 | COUNT=0 | ||
| 111 | OK=0 | ||
| 112 | FAIL=0 | ||
| 113 | ERROR=0 | ||
| 114 | A=${A:=.a} | ||
| 115 | B=${B:=.b} | ||
| 116 | |||
| 117 | OUTDIR=$(mktemp -d -p $ROOTDIR) | ||
| 118 | chmod a+rx ${OUTDIR} | ||
| 119 | echo "===> ${OUTDIR}" | ||
| 120 | |||
| 121 | OUT=$OUTDIR/regress.log | ||
| 122 | ERR=$OUTDIR/regress.err | ||
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile deleted file mode 100644 index eb8c55e91e..0000000000 --- a/src/regress/lib/libc/atexit/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.7 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = atexit_test | ||
| 4 | CPPFLAGS = -I${.CURDIR}/../../../../lib/libc | ||
| 5 | CLEANFILES = invalid.out valid.out | ||
| 6 | LDADD = -static | ||
| 7 | |||
| 8 | run-regress-${PROG}: ${PROG} | ||
| 9 | ./${PROG} -valid 2>${.OBJDIR}/valid.out | ||
| 10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 11 | ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out | ||
| 12 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
| 13 | ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out | ||
| 14 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c deleted file mode 100644 index b060a9b341..0000000000 --- a/src/regress/lib/libc/atexit/atexit_test.c +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | /* $OpenBSD: atexit_test.c,v 1.9 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2002 Daniel Hartmeier | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | * | ||
| 31 | * Effort sponsored in part by the Defense Advanced Research Projects | ||
| 32 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
| 33 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. | ||
| 34 | * | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <stdio.h> | ||
| 38 | #include <stdlib.h> | ||
| 39 | #include <string.h> | ||
| 40 | #include <signal.h> | ||
| 41 | #include <unistd.h> | ||
| 42 | |||
| 43 | #include "include/namespace.h" | ||
| 44 | #include "hidden/stdlib.h" | ||
| 45 | #include "stdlib/atexit.h" | ||
| 46 | |||
| 47 | void handle_first(void); | ||
| 48 | void handle_middle(void); | ||
| 49 | void handle_last(void); | ||
| 50 | void handle_invalid(void *); | ||
| 51 | void handle_cleanup(void); | ||
| 52 | void handle_signal(int); | ||
| 53 | |||
| 54 | static int counter; | ||
| 55 | |||
| 56 | int | ||
| 57 | main(int argc, char *argv[]) | ||
| 58 | { | ||
| 59 | int i; | ||
| 60 | |||
| 61 | if (argc != 2 || (strcmp(argv[1], "-valid") && | ||
| 62 | strcmp(argv[1], "-invalid-atexit") && | ||
| 63 | strcmp(argv[1], "-invalid-cleanup"))) { | ||
| 64 | fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", | ||
| 65 | argv[0]); | ||
| 66 | return (1); | ||
| 67 | } | ||
| 68 | fprintf(stderr, "main()\n"); | ||
| 69 | if (atexit(handle_last)) { | ||
| 70 | perror("atexit(handle_last) failed"); | ||
| 71 | return (1); | ||
| 72 | } | ||
| 73 | for (i = 0; i < 65535; ++i) { | ||
| 74 | if (atexit(handle_middle)) { | ||
| 75 | perror("atexit(handle_middle) failed"); | ||
| 76 | return (1); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | if (atexit(handle_first)) { | ||
| 80 | perror("atexit(handle_first) failed"); | ||
| 81 | return (1); | ||
| 82 | } | ||
| 83 | /* this is supposed to segfault */ | ||
| 84 | if (!strcmp(argv[1], "-invalid-atexit")) { | ||
| 85 | signal(SIGSEGV, handle_signal); | ||
| 86 | __atexit->fns[0].fn_ptr = handle_invalid; | ||
| 87 | } else if (!strcmp(argv[1], "-invalid-cleanup")) { | ||
| 88 | struct atexit *p = __atexit; | ||
| 89 | |||
| 90 | signal(SIGSEGV, handle_signal); | ||
| 91 | while (p != NULL && p->next != NULL) | ||
| 92 | p = p->next; | ||
| 93 | if (p == NULL) | ||
| 94 | fprintf(stderr, "p == NULL, no page found\n"); | ||
| 95 | p->fns[0].fn_ptr = handle_invalid; | ||
| 96 | } | ||
| 97 | __atexit_register_cleanup(handle_cleanup); | ||
| 98 | counter = 0; | ||
| 99 | fprintf(stderr, "main() returns\n"); | ||
| 100 | return (0); | ||
| 101 | } | ||
| 102 | |||
| 103 | void | ||
| 104 | handle_first(void) | ||
| 105 | { | ||
| 106 | fprintf(stderr, "handle_first() counter == %i\n", counter); | ||
| 107 | } | ||
| 108 | |||
| 109 | void | ||
| 110 | handle_middle(void) | ||
| 111 | { | ||
| 112 | counter++; | ||
| 113 | } | ||
| 114 | |||
| 115 | void | ||
| 116 | handle_last(void) | ||
| 117 | { | ||
| 118 | fprintf(stderr, "handle_last() counter == %i\n", counter); | ||
| 119 | } | ||
| 120 | |||
| 121 | void | ||
| 122 | handle_cleanup(void) | ||
| 123 | { | ||
| 124 | fprintf(stderr, "handle_cleanup()\n"); | ||
| 125 | } | ||
| 126 | |||
| 127 | void | ||
| 128 | handle_invalid(void *arg) | ||
| 129 | { | ||
| 130 | fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n"); | ||
| 131 | } | ||
| 132 | |||
| 133 | void | ||
| 134 | handle_signal(int sigraised) | ||
| 135 | { | ||
| 136 | switch (sigraised) { | ||
| 137 | case SIGSEGV: | ||
| 138 | dprintf(STDERR_FILENO, "SIGSEGV\n"); | ||
| 139 | exit(0); | ||
| 140 | default: | ||
| 141 | dprintf(STDERR_FILENO, "unexpected signal caught\n"); | ||
| 142 | exit(1); | ||
| 143 | } | ||
| 144 | } | ||
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok deleted file mode 100644 index 98cbf8c1de..0000000000 --- a/src/regress/lib/libc/atexit/invalid.ok +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | main() | ||
| 2 | SIGSEGV | ||
| 3 | handle_first() counter == 0 | ||
| 4 | handle_last() counter == 65535 | ||
diff --git a/src/regress/lib/libc/atexit/valid.ok b/src/regress/lib/libc/atexit/valid.ok deleted file mode 100644 index 6509e827a7..0000000000 --- a/src/regress/lib/libc/atexit/valid.ok +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | main() | ||
| 2 | main() returns | ||
| 3 | handle_first() counter == 0 | ||
| 4 | handle_last() counter == 65535 | ||
| 5 | handle_cleanup() | ||
diff --git a/src/regress/lib/libc/basename/Makefile b/src/regress/lib/libc/basename/Makefile deleted file mode 100644 index 958b06fd11..0000000000 --- a/src/regress/lib/libc/basename/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | PROG=basename_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/basename/basename_test.c b/src/regress/lib/libc/basename/basename_test.c deleted file mode 100644 index 34e138c726..0000000000 --- a/src/regress/lib/libc/basename/basename_test.c +++ /dev/null | |||
| @@ -1,79 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <sys/param.h> | ||
| 8 | |||
| 9 | #include <libgen.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <errno.h> | ||
| 14 | |||
| 15 | int | ||
| 16 | main(void) | ||
| 17 | { | ||
| 18 | char path[2 * MAXPATHLEN]; | ||
| 19 | const char *dir = "junk/"; | ||
| 20 | const char *fname = "file.name.ext"; | ||
| 21 | char *str; | ||
| 22 | int i; | ||
| 23 | |||
| 24 | /* Test normal functioning */ | ||
| 25 | strlcpy(path, "/", sizeof(path)); | ||
| 26 | strlcat(path, dir, sizeof(path)); | ||
| 27 | strlcat(path, fname, sizeof(path)); | ||
| 28 | str = basename(path); | ||
| 29 | if (strcmp(str, fname) != 0) | ||
| 30 | goto fail; | ||
| 31 | |||
| 32 | /* | ||
| 33 | * There are four states that require special handling: | ||
| 34 | * | ||
| 35 | * 1) path is NULL | ||
| 36 | * 2) path is the empty string | ||
| 37 | * 3) path is composed entirely of slashes | ||
| 38 | * 4) the resulting name is larger than MAXPATHLEN | ||
| 39 | * | ||
| 40 | * The first two cases require that a pointer | ||
| 41 | * to the string "." be returned. | ||
| 42 | * | ||
| 43 | * The third case requires that a pointer | ||
| 44 | * to the string "/" be returned. | ||
| 45 | * | ||
| 46 | * The final case requires that NULL be returned | ||
| 47 | * and errno * be set to ENAMETOOLONG. | ||
| 48 | */ | ||
| 49 | /* Case 1 */ | ||
| 50 | str = basename(NULL); | ||
| 51 | if (strcmp(str, ".") != 0) | ||
| 52 | goto fail; | ||
| 53 | |||
| 54 | /* Case 2 */ | ||
| 55 | strlcpy(path, "", sizeof(path)); | ||
| 56 | str = basename(path); | ||
| 57 | if (strcmp(str, ".") != 0) | ||
| 58 | goto fail; | ||
| 59 | |||
| 60 | /* Case 3 */ | ||
| 61 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
| 62 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
| 63 | str = basename(path); | ||
| 64 | if (strcmp(str, "/") != 0) | ||
| 65 | goto fail; | ||
| 66 | |||
| 67 | /* Case 4 */ | ||
| 68 | strlcpy(path, "/", sizeof(path)); | ||
| 69 | strlcat(path, dir, sizeof(path)); | ||
| 70 | for (i = 0; i <= MAXPATHLEN; i += sizeof(fname)) | ||
| 71 | strlcat(path, fname, sizeof(path)); | ||
| 72 | str = basename(path); | ||
| 73 | if (str != NULL || errno != ENAMETOOLONG) | ||
| 74 | goto fail; | ||
| 75 | |||
| 76 | return (0); | ||
| 77 | fail: | ||
| 78 | return (1); | ||
| 79 | } | ||
diff --git a/src/regress/lib/libc/cephes/Makefile b/src/regress/lib/libc/cephes/Makefile deleted file mode 100644 index 75cc85f4a8..0000000000 --- a/src/regress/lib/libc/cephes/Makefile +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2011/07/02 18:11:01 martynas Exp $ | ||
| 2 | |||
| 3 | PROG = ieetst | ||
| 4 | SRCS = drand.c econst.c eexp.c elog.c epow.c etanh.c etodec.c ieee.c \ | ||
| 5 | ieetst.c mtherr.c | ||
| 6 | |||
| 7 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cephes/drand.c b/src/regress/lib/libc/cephes/drand.c deleted file mode 100644 index 7f7000b4e8..0000000000 --- a/src/regress/lib/libc/cephes/drand.c +++ /dev/null | |||
| @@ -1,174 +0,0 @@ | |||
| 1 | /* $OpenBSD: drand.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* drand.c | ||
| 20 | * | ||
| 21 | * Pseudorandom number generator | ||
| 22 | * | ||
| 23 | * | ||
| 24 | * | ||
| 25 | * SYNOPSIS: | ||
| 26 | * | ||
| 27 | * double y, drand(); | ||
| 28 | * | ||
| 29 | * drand( &y ); | ||
| 30 | * | ||
| 31 | * | ||
| 32 | * | ||
| 33 | * DESCRIPTION: | ||
| 34 | * | ||
| 35 | * Yields a random number 1.0 <= y < 2.0. | ||
| 36 | * | ||
| 37 | * The three-generator congruential algorithm by Brian | ||
| 38 | * Wichmann and David Hill (BYTE magazine, March, 1987, | ||
| 39 | * pp 127-8) is used. The period, given by them, is | ||
| 40 | * 6953607871644. | ||
| 41 | * | ||
| 42 | * Versions invoked by the different arithmetic compile | ||
| 43 | * time options DEC, IBMPC, and MIEEE, produce | ||
| 44 | * approximately the same sequences, differing only in the | ||
| 45 | * least significant bits of the numbers. The UNK option | ||
| 46 | * implements the algorithm as recommended in the BYTE | ||
| 47 | * article. It may be used on all computers. However, | ||
| 48 | * the low order bits of a double precision number may | ||
| 49 | * not be adequately random, and may vary due to arithmetic | ||
| 50 | * implementation details on different computers. | ||
| 51 | * | ||
| 52 | * The other compile options generate an additional random | ||
| 53 | * integer that overwrites the low order bits of the double | ||
| 54 | * precision number. This reduces the period by a factor of | ||
| 55 | * two but tends to overcome the problems mentioned. | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "mconf.h" | ||
| 60 | |||
| 61 | |||
| 62 | /* Three-generator random number algorithm | ||
| 63 | * of Brian Wichmann and David Hill | ||
| 64 | * BYTE magazine, March, 1987 pp 127-8 | ||
| 65 | * | ||
| 66 | * The period, given by them, is (p-1)(q-1)(r-1)/4 = 6.95e12. | ||
| 67 | */ | ||
| 68 | |||
| 69 | static int sx = 1; | ||
| 70 | static int sy = 10000; | ||
| 71 | static int sz = 3000; | ||
| 72 | |||
| 73 | static union { | ||
| 74 | double d; | ||
| 75 | unsigned short s[4]; | ||
| 76 | } unkans; | ||
| 77 | |||
| 78 | /* This function implements the three | ||
| 79 | * congruential generators. | ||
| 80 | */ | ||
| 81 | |||
| 82 | static int ranwh() | ||
| 83 | { | ||
| 84 | int r, s; | ||
| 85 | |||
| 86 | /* sx = sx * 171 mod 30269 */ | ||
| 87 | r = sx/177; | ||
| 88 | s = sx - 177 * r; | ||
| 89 | sx = 171 * s - 2 * r; | ||
| 90 | if( sx < 0 ) | ||
| 91 | sx += 30269; | ||
| 92 | |||
| 93 | |||
| 94 | /* sy = sy * 172 mod 30307 */ | ||
| 95 | r = sy/176; | ||
| 96 | s = sy - 176 * r; | ||
| 97 | sy = 172 * s - 35 * r; | ||
| 98 | if( sy < 0 ) | ||
| 99 | sy += 30307; | ||
| 100 | |||
| 101 | /* sz = 170 * sz mod 30323 */ | ||
| 102 | r = sz/178; | ||
| 103 | s = sz - 178 * r; | ||
| 104 | sz = 170 * s - 63 * r; | ||
| 105 | if( sz < 0 ) | ||
| 106 | sz += 30323; | ||
| 107 | /* The results are in static sx, sy, sz. */ | ||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | /* drand.c | ||
| 112 | * | ||
| 113 | * Random double precision floating point number between 1 and 2. | ||
| 114 | * | ||
| 115 | * C callable: | ||
| 116 | * drand( &x ); | ||
| 117 | */ | ||
| 118 | |||
| 119 | int drand( a ) | ||
| 120 | double *a; | ||
| 121 | { | ||
| 122 | unsigned short r; | ||
| 123 | #ifdef DEC | ||
| 124 | unsigned short s, t; | ||
| 125 | #endif | ||
| 126 | |||
| 127 | /* This algorithm of Wichmann and Hill computes a floating point | ||
| 128 | * result: | ||
| 129 | */ | ||
| 130 | ranwh(); | ||
| 131 | unkans.d = sx/30269.0 + sy/30307.0 + sz/30323.0; | ||
| 132 | r = unkans.d; | ||
| 133 | unkans.d -= r; | ||
| 134 | unkans.d += 1.0; | ||
| 135 | |||
| 136 | /* if UNK option, do nothing further. | ||
| 137 | * Otherwise, make a random 16 bit integer | ||
| 138 | * to overwrite the least significant word | ||
| 139 | * of unkans. | ||
| 140 | */ | ||
| 141 | #ifdef UNK | ||
| 142 | /* do nothing */ | ||
| 143 | #else | ||
| 144 | ranwh(); | ||
| 145 | r = sx * sy + sz; | ||
| 146 | #endif | ||
| 147 | |||
| 148 | #ifdef DEC | ||
| 149 | /* To make the numbers as similar as possible | ||
| 150 | * in all arithmetics, the random integer has | ||
| 151 | * to be inserted 3 bits higher up in a DEC number. | ||
| 152 | * An alternative would be put it 3 bits lower down | ||
| 153 | * in all the other number types. | ||
| 154 | */ | ||
| 155 | s = unkans.s[2]; | ||
| 156 | t = s & 07; /* save these bits to put in at the bottom */ | ||
| 157 | s &= 0177770; | ||
| 158 | s |= (r >> 13) & 07; | ||
| 159 | unkans.s[2] = s; | ||
| 160 | t |= r << 3; | ||
| 161 | unkans.s[3] = t; | ||
| 162 | #endif | ||
| 163 | |||
| 164 | #ifdef IBMPC | ||
| 165 | unkans.s[0] = r; | ||
| 166 | #endif | ||
| 167 | |||
| 168 | #ifdef MIEEE | ||
| 169 | unkans.s[3] = r; | ||
| 170 | #endif | ||
| 171 | |||
| 172 | *a = unkans.d; | ||
| 173 | return 0; | ||
| 174 | } | ||
diff --git a/src/regress/lib/libc/cephes/econst.c b/src/regress/lib/libc/cephes/econst.c deleted file mode 100644 index 4232059e4c..0000000000 --- a/src/regress/lib/libc/cephes/econst.c +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | /* $OpenBSD: econst.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* econst.c */ | ||
| 20 | /* e type constants used by high precision check routines */ | ||
| 21 | |||
| 22 | #include "ehead.h" | ||
| 23 | |||
| 24 | |||
| 25 | #if NE == 10 | ||
| 26 | /* 0.0 */ | ||
| 27 | unsigned short ezero[NE] = | ||
| 28 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 29 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,}; | ||
| 30 | |||
| 31 | /* 5.0E-1 */ | ||
| 32 | unsigned short ehalf[NE] = | ||
| 33 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 34 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,}; | ||
| 35 | |||
| 36 | /* 1.0E0 */ | ||
| 37 | unsigned short eone[NE] = | ||
| 38 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 39 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,}; | ||
| 40 | |||
| 41 | /* 2.0E0 */ | ||
| 42 | unsigned short etwo[NE] = | ||
| 43 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 44 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,}; | ||
| 45 | |||
| 46 | /* 3.2E1 */ | ||
| 47 | unsigned short e32[NE] = | ||
| 48 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 49 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,}; | ||
| 50 | |||
| 51 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
| 52 | unsigned short elog2[NE] = | ||
| 53 | {0x40f3, 0xf6af, 0x03f2, 0xb398, | ||
| 54 | 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,}; | ||
| 55 | |||
| 56 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
| 57 | unsigned short esqrt2[NE] = | ||
| 58 | {0x1d6f, 0xbe9f, 0x754a, 0x89b3, | ||
| 59 | 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,}; | ||
| 60 | |||
| 61 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
| 62 | unsigned short epi[NE] = | ||
| 63 | {0x2902, 0x1cd1, 0x80dc, 0x628b, | ||
| 64 | 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,}; | ||
| 65 | |||
| 66 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
| 67 | unsigned short eeul[NE] = { | ||
| 68 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
| 69 | |||
| 70 | #else | ||
| 71 | |||
| 72 | /* 0.0 */ | ||
| 73 | unsigned short ezero[NE] = { | ||
| 74 | 0, 0000000,0000000,0000000,0000000,0000000,}; | ||
| 75 | /* 5.0E-1 */ | ||
| 76 | unsigned short ehalf[NE] = { | ||
| 77 | 0, 0000000,0000000,0000000,0100000,0x3ffe,}; | ||
| 78 | /* 1.0E0 */ | ||
| 79 | unsigned short eone[NE] = { | ||
| 80 | 0, 0000000,0000000,0000000,0100000,0x3fff,}; | ||
| 81 | /* 2.0E0 */ | ||
| 82 | unsigned short etwo[NE] = { | ||
| 83 | 0, 0000000,0000000,0000000,0100000,0040000,}; | ||
| 84 | /* 3.2E1 */ | ||
| 85 | unsigned short e32[NE] = { | ||
| 86 | 0, 0000000,0000000,0000000,0100000,0040004,}; | ||
| 87 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
| 88 | unsigned short elog2[NE] = { | ||
| 89 | 0xc9e4,0x79ab,0150717,0013767,0130562,0x3ffe,}; | ||
| 90 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
| 91 | unsigned short esqrt2[NE] = { | ||
| 92 | 0x597e,0x6484,0174736,0171463,0132404,0x3fff,}; | ||
| 93 | /* 2/sqrt(PI) = | ||
| 94 | * 1.12837916709551257389615890312154517168810125865800E0 */ | ||
| 95 | unsigned short eoneopi[NE] = { | ||
| 96 | 0x71d5,0x688d,0012333,0135202,0110156,0x3fff,}; | ||
| 97 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
| 98 | unsigned short epi[NE] = { | ||
| 99 | 0xc4c6,0xc234,0020550,0155242,0144417,0040000,}; | ||
| 100 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
| 101 | unsigned short eeul[NE] = { | ||
| 102 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
| 103 | #endif | ||
| 104 | extern unsigned short ezero[]; | ||
| 105 | extern unsigned short ehalf[]; | ||
| 106 | extern unsigned short eone[]; | ||
| 107 | extern unsigned short etwo[]; | ||
| 108 | extern unsigned short e32[]; | ||
| 109 | extern unsigned short elog2[]; | ||
| 110 | extern unsigned short esqrt2[]; | ||
| 111 | extern unsigned short eoneopi[]; | ||
| 112 | extern unsigned short epi[]; | ||
| 113 | extern unsigned short eeul[]; | ||
| 114 | |||
diff --git a/src/regress/lib/libc/cephes/eexp.c b/src/regress/lib/libc/cephes/eexp.c deleted file mode 100644 index 74f0d6adb3..0000000000 --- a/src/regress/lib/libc/cephes/eexp.c +++ /dev/null | |||
| @@ -1,86 +0,0 @@ | |||
| 1 | /* $OpenBSD: eexp.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* xexp.c */ | ||
| 20 | /* exponential function check routine */ | ||
| 21 | /* by Stephen L. Moshier. */ | ||
| 22 | |||
| 23 | |||
| 24 | #include "ehead.h" | ||
| 25 | |||
| 26 | void eexp( x, y ) | ||
| 27 | unsigned short *x, *y; | ||
| 28 | { | ||
| 29 | unsigned short num[NE], den[NE], x2[NE]; | ||
| 30 | long i; | ||
| 31 | unsigned short sign, expchk; | ||
| 32 | |||
| 33 | /* range reduction theory: x = i + f, 0<=f<1; | ||
| 34 | * e**x = e**i * e**f | ||
| 35 | * e**i = 2**(i/log 2). | ||
| 36 | * Let i/log2 = i1 + f1, 0<=f1<1. | ||
| 37 | * Then e**i = 2**i1 * 2**f1, so | ||
| 38 | * e**x = 2**i1 * e**(log 2 * f1) * e**f. | ||
| 39 | */ | ||
| 40 | if( ecmp(x, ezero) == 0 ) | ||
| 41 | { | ||
| 42 | emov( eone, y ); | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | emov(x, x2); | ||
| 46 | expchk = x2[NE-1]; | ||
| 47 | sign = expchk & 0x8000; | ||
| 48 | x2[NE-1] &= 0x7fff; | ||
| 49 | |||
| 50 | /* Test for excessively large argument */ | ||
| 51 | expchk &= 0x7fff; | ||
| 52 | if( expchk > (EXONE + 15) ) | ||
| 53 | { | ||
| 54 | eclear( y ); | ||
| 55 | if( sign == 0 ) | ||
| 56 | einfin( y ); | ||
| 57 | return; | ||
| 58 | } | ||
| 59 | |||
| 60 | eifrac( x2, &i, num ); /* x = i + f */ | ||
| 61 | |||
| 62 | if( i != 0 ) | ||
| 63 | { | ||
| 64 | ltoe( &i, den ); /* floating point i */ | ||
| 65 | ediv( elog2, den, den ); /* i/log 2 */ | ||
| 66 | eifrac( den, &i, den ); /* i/log 2 = i1 + f1 */ | ||
| 67 | emul( elog2, den, den ); /* log 2 * f1 */ | ||
| 68 | eadd( den, num, x2 ); /* log 2 * f1 + f */ | ||
| 69 | } | ||
| 70 | |||
| 71 | /*x2[NE-1] -= 1;*/ | ||
| 72 | eldexp( x2, -1L, x2 ); /* divide by 2 */ | ||
| 73 | etanh( x2, x2 ); /* tanh( x/2 ) */ | ||
| 74 | eadd( x2, eone, num ); /* 1 + tanh */ | ||
| 75 | eneg( x2 ); | ||
| 76 | eadd( x2, eone, den ); /* 1 - tanh */ | ||
| 77 | ediv( den, num, y ); /* (1 + tanh)/(1 - tanh) */ | ||
| 78 | |||
| 79 | /*y[NE-1] += i;*/ | ||
| 80 | if( sign ) | ||
| 81 | { | ||
| 82 | ediv( y, eone, y ); | ||
| 83 | i = -i; | ||
| 84 | } | ||
| 85 | eldexp( y, i, y ); /* multiply by 2**i */ | ||
| 86 | } | ||
diff --git a/src/regress/lib/libc/cephes/ehead.h b/src/regress/lib/libc/cephes/ehead.h deleted file mode 100644 index 009bcf89cc..0000000000 --- a/src/regress/lib/libc/cephes/ehead.h +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | /* $OpenBSD: ehead.h,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 file for extended precision arithmetic programs. | ||
| 20 | */ | ||
| 21 | |||
| 22 | /* Number of 16 bit words in external x type format */ | ||
| 23 | #define NE 10 | ||
| 24 | |||
| 25 | /* Number of 16 bit words in internal format */ | ||
| 26 | #define NI (NE+3) | ||
| 27 | |||
| 28 | /* Array offset to exponent */ | ||
| 29 | #define E 1 | ||
| 30 | |||
| 31 | /* Array offset to high guard word */ | ||
| 32 | #define M 2 | ||
| 33 | |||
| 34 | /* Number of bits of precision */ | ||
| 35 | #define NBITS ((NI-4)*16) | ||
| 36 | |||
| 37 | /* Maximum number of decimal digits in ASCII conversion | ||
| 38 | * = NBITS*log10(2) | ||
| 39 | */ | ||
| 40 | #define NDEC (NBITS*8/27) | ||
| 41 | |||
| 42 | /* The exponent of 1.0 */ | ||
| 43 | #define EXONE (0x3fff) | ||
| 44 | |||
| 45 | void eadd(), esub(), emul(), ediv(); | ||
| 46 | int ecmp(), enormlz(), eshift(); | ||
| 47 | void eshup1(), eshup8(), eshup6(), eshdn1(), eshdn8(), eshdn6(); | ||
| 48 | void eabs(), eneg(), emov(), eclear(), einfin(), efloor(); | ||
| 49 | void eldexp(), efrexp(), eifrac(), ltoe(); | ||
| 50 | void esqrt(), elog(), eexp(), etanh(), epow(); | ||
| 51 | void asctoe(), asctoe24(), asctoe53(), asctoe64(); | ||
| 52 | void etoasc(), e24toasc(), e53toasc(), e64toasc(); | ||
| 53 | void etoe64(), etoe53(), etoe24(), e64toe(), e53toe(), e24toe(); | ||
| 54 | int mtherr(); | ||
| 55 | extern unsigned short ezero[], ehalf[], eone[], etwo[]; | ||
| 56 | extern unsigned short elog2[], esqrt2[]; | ||
| 57 | |||
| 58 | |||
| 59 | /* by Stephen L. Moshier. */ | ||
diff --git a/src/regress/lib/libc/cephes/elog.c b/src/regress/lib/libc/cephes/elog.c deleted file mode 100644 index 079cc754f4..0000000000 --- a/src/regress/lib/libc/cephes/elog.c +++ /dev/null | |||
| @@ -1,110 +0,0 @@ | |||
| 1 | /* $OpenBSD: elog.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* xlog.c */ | ||
| 20 | /* natural logarithm */ | ||
| 21 | /* by Stephen L. Moshier. */ | ||
| 22 | |||
| 23 | #include "mconf.h" | ||
| 24 | #include "ehead.h" | ||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | void elog( x, y ) | ||
| 29 | unsigned short *x, *y; | ||
| 30 | { | ||
| 31 | unsigned short xx[NE], z[NE], a[NE], b[NE], t[NE], qj[NE]; | ||
| 32 | long ex; | ||
| 33 | int fex; | ||
| 34 | |||
| 35 | |||
| 36 | if( x[NE-1] & (unsigned short )0x8000 ) | ||
| 37 | { | ||
| 38 | eclear(y); | ||
| 39 | mtherr( "elog", DOMAIN ); | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | if( ecmp( x, ezero ) == 0 ) | ||
| 43 | { | ||
| 44 | einfin( y ); | ||
| 45 | eneg(y); | ||
| 46 | mtherr( "elog", SING ); | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | if( ecmp( x, eone ) == 0 ) | ||
| 50 | { | ||
| 51 | eclear( y ); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | |||
| 55 | /* range reduction: log x = log( 2**ex * m ) = ex * log2 + log m */ | ||
| 56 | efrexp( x, &fex, xx ); | ||
| 57 | /* | ||
| 58 | emov(x, xx ); | ||
| 59 | ex = xx[NX-1] & 0x7fff; | ||
| 60 | ex -= 0x3ffe; | ||
| 61 | xx[NX-1] = 0x3ffe; | ||
| 62 | */ | ||
| 63 | |||
| 64 | /* Adjust range to 1/sqrt(2), sqrt(2) */ | ||
| 65 | esqrt2[NE-1] -= 1; | ||
| 66 | if( ecmp( xx, esqrt2 ) < 0 ) | ||
| 67 | { | ||
| 68 | fex -= 1; | ||
| 69 | emul( xx, etwo, xx ); | ||
| 70 | } | ||
| 71 | esqrt2[NE-1] += 1; | ||
| 72 | |||
| 73 | esub( eone, xx, a ); | ||
| 74 | if( a[NE-1] == 0 ) | ||
| 75 | { | ||
| 76 | eclear( y ); | ||
| 77 | goto logdon; | ||
| 78 | } | ||
| 79 | eadd( eone, xx, b ); | ||
| 80 | ediv( b, a, y ); /* store (x-1)/(x+1) in y */ | ||
| 81 | |||
| 82 | emul( y, y, z ); | ||
| 83 | |||
| 84 | emov( eone, a ); | ||
| 85 | emov( eone, b ); | ||
| 86 | emov( eone, qj ); | ||
| 87 | do | ||
| 88 | { | ||
| 89 | eadd( etwo, qj, qj ); /* 2 * i + 1 */ | ||
| 90 | emul( z, a, a ); | ||
| 91 | ediv( qj, a, t ); | ||
| 92 | eadd( t, b, b ); | ||
| 93 | } | ||
| 94 | while( ((b[NE-1] & 0x7fff) - (t[NE-1] & 0x7fff)) < NBITS ); | ||
| 95 | |||
| 96 | |||
| 97 | emul( b, y, y ); | ||
| 98 | emul( y, etwo, y ); | ||
| 99 | |||
| 100 | logdon: | ||
| 101 | |||
| 102 | /* now add log of 2**ex */ | ||
| 103 | if( fex != 0 ) | ||
| 104 | { | ||
| 105 | ex = fex; | ||
| 106 | ltoe( &ex, b ); | ||
| 107 | emul( elog2, b, b ); | ||
| 108 | eadd( b, y, y ); | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/src/regress/lib/libc/cephes/epow.c b/src/regress/lib/libc/cephes/epow.c deleted file mode 100644 index 646268fce7..0000000000 --- a/src/regress/lib/libc/cephes/epow.c +++ /dev/null | |||
| @@ -1,187 +0,0 @@ | |||
| 1 | /* $OpenBSD: epow.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* epow.c */ | ||
| 20 | /* power function: z = x**y */ | ||
| 21 | /* by Stephen L. Moshier. */ | ||
| 22 | |||
| 23 | |||
| 24 | #include "ehead.h" | ||
| 25 | |||
| 26 | extern int rndprc; | ||
| 27 | void epowi(); | ||
| 28 | |||
| 29 | void epow( x, y, z ) | ||
| 30 | unsigned short *x, *y, *z; | ||
| 31 | { | ||
| 32 | unsigned short w[NE]; | ||
| 33 | int rndsav; | ||
| 34 | long li; | ||
| 35 | |||
| 36 | efloor( y, w ); | ||
| 37 | if( ecmp(y,w) == 0 ) | ||
| 38 | { | ||
| 39 | eifrac( y, &li, w ); | ||
| 40 | if( li < 0 ) | ||
| 41 | li = -li; | ||
| 42 | if( (li < 0x7fffffff) && (li != 0x80000000) ) | ||
| 43 | { | ||
| 44 | epowi( x, y, z ); | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | /* z = exp( y * log(x) ) */ | ||
| 49 | rndsav = rndprc; | ||
| 50 | rndprc = NBITS; | ||
| 51 | elog( x, w ); | ||
| 52 | emul( y, w, w ); | ||
| 53 | eexp( w, z ); | ||
| 54 | rndprc = rndsav; | ||
| 55 | emul( eone, z, z ); | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | /* y is integer valued. */ | ||
| 60 | |||
| 61 | void epowi( x, y, z ) | ||
| 62 | unsigned short x[], y[], z[]; | ||
| 63 | { | ||
| 64 | unsigned short w[NE]; | ||
| 65 | long li, lx; | ||
| 66 | unsigned long lu; | ||
| 67 | int rndsav; | ||
| 68 | unsigned short signx; | ||
| 69 | /* unsigned short signy; */ | ||
| 70 | |||
| 71 | rndsav = rndprc; | ||
| 72 | eifrac( y, &li, w ); | ||
| 73 | if( li < 0 ) | ||
| 74 | lx = -li; | ||
| 75 | else | ||
| 76 | lx = li; | ||
| 77 | |||
| 78 | if( (lx == 0x7fffffff) || (lx == 0x80000000) ) | ||
| 79 | { | ||
| 80 | epow( x, y, z ); | ||
| 81 | goto done; | ||
| 82 | } | ||
| 83 | |||
| 84 | if( (x[NE-1] & (unsigned short )0x7fff) == 0 ) | ||
| 85 | { | ||
| 86 | if( li == 0 ) | ||
| 87 | { | ||
| 88 | emov( eone, z ); | ||
| 89 | return; | ||
| 90 | } | ||
| 91 | else if( li < 0 ) | ||
| 92 | { | ||
| 93 | einfin( z ); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | else | ||
| 97 | { | ||
| 98 | eclear( z ); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | if( li == 0L ) | ||
| 104 | { | ||
| 105 | emov( eone, z ); | ||
| 106 | return; | ||
| 107 | } | ||
| 108 | |||
| 109 | emov( x, w ); | ||
| 110 | signx = w[NE-1] & (unsigned short )0x8000; | ||
| 111 | w[NE-1] &= (unsigned short )0x7fff; | ||
| 112 | |||
| 113 | /* Overflow detection */ | ||
| 114 | /* | ||
| 115 | lx = li * (w[NE-1] - 0x3fff); | ||
| 116 | if( lx > 16385L ) | ||
| 117 | { | ||
| 118 | einfin( z ); | ||
| 119 | mtherr( "epowi", OVERFLOW ); | ||
| 120 | goto done; | ||
| 121 | } | ||
| 122 | if( lx < -16450L ) | ||
| 123 | { | ||
| 124 | eclear( z ); | ||
| 125 | return; | ||
| 126 | } | ||
| 127 | */ | ||
| 128 | rndprc = NBITS; | ||
| 129 | |||
| 130 | if( li < 0 ) | ||
| 131 | { | ||
| 132 | lu = (unsigned int )( -li ); | ||
| 133 | /* signy = 0xffff;*/ | ||
| 134 | ediv( w, eone, w ); | ||
| 135 | } | ||
| 136 | else | ||
| 137 | { | ||
| 138 | lu = (unsigned int )li; | ||
| 139 | /* signy = 0;*/ | ||
| 140 | } | ||
| 141 | |||
| 142 | /* First bit of the power */ | ||
| 143 | if( lu & 1 ) | ||
| 144 | { | ||
| 145 | emov( w, z ); | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | emov( eone, z ); | ||
| 150 | signx = 0; | ||
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | lu >>= 1; | ||
| 155 | while( lu != 0L ) | ||
| 156 | { | ||
| 157 | emul( w, w, w ); /* arg to the 2-to-the-kth power */ | ||
| 158 | if( lu & 1L ) /* if that bit is set, then include in product */ | ||
| 159 | emul( w, z, z ); | ||
| 160 | lu >>= 1; | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | done: | ||
| 165 | |||
| 166 | if( signx ) | ||
| 167 | eneg( z ); /* odd power of negative number */ | ||
| 168 | |||
| 169 | /* | ||
| 170 | if( signy ) | ||
| 171 | { | ||
| 172 | if( ecmp( z, ezero ) != 0 ) | ||
| 173 | { | ||
| 174 | ediv( z, eone, z ); | ||
| 175 | } | ||
| 176 | else | ||
| 177 | { | ||
| 178 | einfin( z ); | ||
| 179 | printf( "epowi OVERFLOW\n" ); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | */ | ||
| 183 | rndprc = rndsav; | ||
| 184 | emul( eone, z, z ); | ||
| 185 | } | ||
| 186 | |||
| 187 | |||
diff --git a/src/regress/lib/libc/cephes/etanh.c b/src/regress/lib/libc/cephes/etanh.c deleted file mode 100644 index 4ac5ff1c21..0000000000 --- a/src/regress/lib/libc/cephes/etanh.c +++ /dev/null | |||
| @@ -1,70 +0,0 @@ | |||
| 1 | /* $OpenBSD: etanh.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* xtanh.c */ | ||
| 20 | /* hyperbolic tangent check routine */ | ||
| 21 | /* this subroutine is used by the exponential function routine */ | ||
| 22 | /* by Stephen L. Moshier. */ | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | #include "ehead.h" | ||
| 27 | |||
| 28 | |||
| 29 | void etanh( x, y ) | ||
| 30 | unsigned short *x, *y; | ||
| 31 | { | ||
| 32 | unsigned short e[NE], r[NE], j[NE], xx[NE], m2[NE]; | ||
| 33 | short i, n; | ||
| 34 | long lj; | ||
| 35 | |||
| 36 | emov( x, r ); | ||
| 37 | r[NE-1] &= (unsigned short )0x7fff; | ||
| 38 | if( ecmp(r, eone) >= 0 ) | ||
| 39 | { | ||
| 40 | /* tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) | ||
| 41 | * Note eexp() calls xtanh, but with an argument less than (1 + log 2)/2. | ||
| 42 | */ | ||
| 43 | eexp( r, e ); | ||
| 44 | ediv( e, eone, r ); | ||
| 45 | esub( r, e, xx ); | ||
| 46 | eadd( r, e, j ); | ||
| 47 | ediv( j, xx, y ); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | |||
| 51 | emov( etwo, m2 ); | ||
| 52 | eneg( m2 ); | ||
| 53 | |||
| 54 | n = NBITS/8; /* Number of terms to do in the continued fraction */ | ||
| 55 | lj = 2 * n + 1; | ||
| 56 | ltoe( &lj, j ); | ||
| 57 | |||
| 58 | emov( j, e ); | ||
| 59 | emul( x, x, xx ); | ||
| 60 | |||
| 61 | /* continued fraction */ | ||
| 62 | for( i=0; i<n; i++) | ||
| 63 | { | ||
| 64 | ediv( e, xx, r ); | ||
| 65 | eadd( m2, j, j ); | ||
| 66 | eadd( r, j, e ); | ||
| 67 | } | ||
| 68 | |||
| 69 | ediv( e, x, y ); | ||
| 70 | } | ||
diff --git a/src/regress/lib/libc/cephes/etodec.c b/src/regress/lib/libc/cephes/etodec.c deleted file mode 100644 index a15845efb6..0000000000 --- a/src/regress/lib/libc/cephes/etodec.c +++ /dev/null | |||
| @@ -1,199 +0,0 @@ | |||
| 1 | /* $OpenBSD: etodec.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 "ehead.h" | ||
| 20 | void emovi(), emovo(), ecleaz(), eshdn8(), emdnorm(); | ||
| 21 | void todec(); | ||
| 22 | /* | ||
| 23 | ; convert DEC double precision to e type | ||
| 24 | ; double d; | ||
| 25 | ; short e[NE]; | ||
| 26 | ; dectoe( &d, e ); | ||
| 27 | */ | ||
| 28 | void dectoe( d, e ) | ||
| 29 | unsigned short *d; | ||
| 30 | unsigned short *e; | ||
| 31 | { | ||
| 32 | unsigned short y[NI]; | ||
| 33 | register unsigned short r, *p; | ||
| 34 | |||
| 35 | ecleaz(y); /* start with a zero */ | ||
| 36 | p = y; /* point to our number */ | ||
| 37 | r = *d; /* get DEC exponent word */ | ||
| 38 | if( *d & (unsigned int )0x8000 ) | ||
| 39 | *p = 0xffff; /* fill in our sign */ | ||
| 40 | ++p; /* bump pointer to our exponent word */ | ||
| 41 | r &= 0x7fff; /* strip the sign bit */ | ||
| 42 | if( r == 0 ) /* answer = 0 if high order DEC word = 0 */ | ||
| 43 | goto done; | ||
| 44 | |||
| 45 | |||
| 46 | r >>= 7; /* shift exponent word down 7 bits */ | ||
| 47 | r += EXONE - 0201; /* subtract DEC exponent offset */ | ||
| 48 | /* add our e type exponent offset */ | ||
| 49 | *p++ = r; /* to form our exponent */ | ||
| 50 | |||
| 51 | r = *d++; /* now do the high order mantissa */ | ||
| 52 | r &= 0177; /* strip off the DEC exponent and sign bits */ | ||
| 53 | r |= 0200; /* the DEC understood high order mantissa bit */ | ||
| 54 | *p++ = r; /* put result in our high guard word */ | ||
| 55 | |||
| 56 | *p++ = *d++; /* fill in the rest of our mantissa */ | ||
| 57 | *p++ = *d++; | ||
| 58 | *p = *d; | ||
| 59 | |||
| 60 | eshdn8(y); /* shift our mantissa down 8 bits */ | ||
| 61 | done: | ||
| 62 | emovo( y, e ); | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | /* | ||
| 68 | ; convert e type to DEC double precision | ||
| 69 | ; double d; | ||
| 70 | ; short e[NE]; | ||
| 71 | ; etodec( e, &d ); | ||
| 72 | */ | ||
| 73 | #if 0 | ||
| 74 | static unsigned short decbit[NI] = {0,0,0,0,0,0,0200,0}; | ||
| 75 | void etodec( x, d ) | ||
| 76 | unsigned short *x, *d; | ||
| 77 | { | ||
| 78 | unsigned short xi[NI]; | ||
| 79 | register unsigned short r; | ||
| 80 | int i, j; | ||
| 81 | |||
| 82 | emovi( x, xi ); | ||
| 83 | *d = 0; | ||
| 84 | if( xi[0] != 0 ) | ||
| 85 | *d = 0100000; | ||
| 86 | r = xi[E]; | ||
| 87 | if( r < (EXONE - 128) ) | ||
| 88 | goto zout; | ||
| 89 | i = xi[M+4]; | ||
| 90 | if( (i & 0200) != 0 ) | ||
| 91 | { | ||
| 92 | if( (i & 0377) == 0200 ) | ||
| 93 | { | ||
| 94 | if( (i & 0400) != 0 ) | ||
| 95 | { | ||
| 96 | /* check all less significant bits */ | ||
| 97 | for( j=M+5; j<NI; j++ ) | ||
| 98 | { | ||
| 99 | if( xi[j] != 0 ) | ||
| 100 | goto yesrnd; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | goto nornd; | ||
| 104 | } | ||
| 105 | yesrnd: | ||
| 106 | eaddm( decbit, xi ); | ||
| 107 | r -= enormlz(xi); | ||
| 108 | } | ||
| 109 | |||
| 110 | nornd: | ||
| 111 | |||
| 112 | r -= EXONE; | ||
| 113 | r += 0201; | ||
| 114 | if( r < 0 ) | ||
| 115 | { | ||
| 116 | zout: | ||
| 117 | *d++ = 0; | ||
| 118 | *d++ = 0; | ||
| 119 | *d++ = 0; | ||
| 120 | *d++ = 0; | ||
| 121 | return; | ||
| 122 | } | ||
| 123 | if( r >= 0377 ) | ||
| 124 | { | ||
| 125 | *d++ = 077777; | ||
| 126 | *d++ = -1; | ||
| 127 | *d++ = -1; | ||
| 128 | *d++ = -1; | ||
| 129 | return; | ||
| 130 | } | ||
| 131 | r &= 0377; | ||
| 132 | r <<= 7; | ||
| 133 | eshup8( xi ); | ||
| 134 | xi[M] &= 0177; | ||
| 135 | r |= xi[M]; | ||
| 136 | *d++ |= r; | ||
| 137 | *d++ = xi[M+1]; | ||
| 138 | *d++ = xi[M+2]; | ||
| 139 | *d++ = xi[M+3]; | ||
| 140 | } | ||
| 141 | #else | ||
| 142 | |||
| 143 | extern int rndprc; | ||
| 144 | |||
| 145 | void etodec( x, d ) | ||
| 146 | unsigned short *x, *d; | ||
| 147 | { | ||
| 148 | unsigned short xi[NI]; | ||
| 149 | long exp; | ||
| 150 | int rndsav; | ||
| 151 | |||
| 152 | emovi( x, xi ); | ||
| 153 | exp = (long )xi[E] - (EXONE - 0201); /* adjust exponent for offsets */ | ||
| 154 | /* round off to nearest or even */ | ||
| 155 | rndsav = rndprc; | ||
| 156 | rndprc = 56; | ||
| 157 | emdnorm( xi, 0, 0, exp, 64 ); | ||
| 158 | rndprc = rndsav; | ||
| 159 | todec( xi, d ); | ||
| 160 | } | ||
| 161 | |||
| 162 | void todec( x, y ) | ||
| 163 | unsigned short *x, *y; | ||
| 164 | { | ||
| 165 | unsigned short i; | ||
| 166 | unsigned short *p; | ||
| 167 | |||
| 168 | p = x; | ||
| 169 | *y = 0; | ||
| 170 | if( *p++ ) | ||
| 171 | *y = 0100000; | ||
| 172 | i = *p++; | ||
| 173 | if( i == 0 ) | ||
| 174 | { | ||
| 175 | *y++ = 0; | ||
| 176 | *y++ = 0; | ||
| 177 | *y++ = 0; | ||
| 178 | *y++ = 0; | ||
| 179 | return; | ||
| 180 | } | ||
| 181 | if( i > 0377 ) | ||
| 182 | { | ||
| 183 | *y++ |= 077777; | ||
| 184 | *y++ = 0xffff; | ||
| 185 | *y++ = 0xffff; | ||
| 186 | *y++ = 0xffff; | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | i &= 0377; | ||
| 190 | i <<= 7; | ||
| 191 | eshup8( x ); | ||
| 192 | x[M] &= 0177; | ||
| 193 | i |= x[M]; | ||
| 194 | *y++ |= i; | ||
| 195 | *y++ = x[M+1]; | ||
| 196 | *y++ = x[M+2]; | ||
| 197 | *y++ = x[M+3]; | ||
| 198 | } | ||
| 199 | #endif | ||
diff --git a/src/regress/lib/libc/cephes/ieee.c b/src/regress/lib/libc/cephes/ieee.c deleted file mode 100644 index e2b8aa7b99..0000000000 --- a/src/regress/lib/libc/cephes/ieee.c +++ /dev/null | |||
| @@ -1,4153 +0,0 @@ | |||
| 1 | /* $OpenBSD: ieee.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* ieee.c | ||
| 20 | * | ||
| 21 | * Extended precision IEEE binary floating point arithmetic routines | ||
| 22 | * | ||
| 23 | * Numbers are stored in C language as arrays of 16-bit unsigned | ||
| 24 | * short integers. The arguments of the routines are pointers to | ||
| 25 | * the arrays. | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * External e type data structure, simulates Intel 8087 chip | ||
| 29 | * temporary real format but possibly with a larger significand: | ||
| 30 | * | ||
| 31 | * NE-1 significand words (least significant word first, | ||
| 32 | * most significant bit is normally set) | ||
| 33 | * exponent (value = EXONE for 1.0, | ||
| 34 | * top bit is the sign) | ||
| 35 | * | ||
| 36 | * | ||
| 37 | * Internal data structure of a number (a "word" is 16 bits): | ||
| 38 | * | ||
| 39 | * ei[0] sign word (0 for positive, 0xffff for negative) | ||
| 40 | * ei[1] biased exponent (value = EXONE for the number 1.0) | ||
| 41 | * ei[2] high guard word (always zero after normalization) | ||
| 42 | * ei[3] | ||
| 43 | * to ei[NI-2] significand (NI-4 significand words, | ||
| 44 | * most significant word first, | ||
| 45 | * most significant bit is set) | ||
| 46 | * ei[NI-1] low guard word (0x8000 bit is rounding place) | ||
| 47 | * | ||
| 48 | * | ||
| 49 | * | ||
| 50 | * Routines for external format numbers | ||
| 51 | * | ||
| 52 | * asctoe( string, e ) ASCII string to extended double e type | ||
| 53 | * asctoe64( string, &d ) ASCII string to long double | ||
| 54 | * asctoe53( string, &d ) ASCII string to double | ||
| 55 | * asctoe24( string, &f ) ASCII string to single | ||
| 56 | * asctoeg( string, e, prec ) ASCII string to specified precision | ||
| 57 | * e24toe( &f, e ) IEEE single precision to e type | ||
| 58 | * e53toe( &d, e ) IEEE double precision to e type | ||
| 59 | * e64toe( &d, e ) IEEE long double precision to e type | ||
| 60 | * eabs(e) absolute value | ||
| 61 | * eadd( a, b, c ) c = b + a | ||
| 62 | * eclear(e) e = 0 | ||
| 63 | * ecmp (a, b) Returns 1 if a > b, 0 if a == b, | ||
| 64 | * -1 if a < b, -2 if either a or b is a NaN. | ||
| 65 | * ediv( a, b, c ) c = b / a | ||
| 66 | * efloor( a, b ) truncate to integer, toward -infinity | ||
| 67 | * efrexp( a, exp, s ) extract exponent and significand | ||
| 68 | * eifrac( e, &l, frac ) e to long integer and e type fraction | ||
| 69 | * euifrac( e, &l, frac ) e to unsigned long integer and e type fraction | ||
| 70 | * einfin( e ) set e to infinity, leaving its sign alone | ||
| 71 | * eldexp( a, n, b ) multiply by 2**n | ||
| 72 | * emov( a, b ) b = a | ||
| 73 | * emul( a, b, c ) c = b * a | ||
| 74 | * eneg(e) e = -e | ||
| 75 | * eround( a, b ) b = nearest integer value to a | ||
| 76 | * esub( a, b, c ) c = b - a | ||
| 77 | * e24toasc( &f, str, n ) single to ASCII string, n digits after decimal | ||
| 78 | * e53toasc( &d, str, n ) double to ASCII string, n digits after decimal | ||
| 79 | * e64toasc( &d, str, n ) long double to ASCII string | ||
| 80 | * etoasc( e, str, n ) e to ASCII string, n digits after decimal | ||
| 81 | * etoe24( e, &f ) convert e type to IEEE single precision | ||
| 82 | * etoe53( e, &d ) convert e type to IEEE double precision | ||
| 83 | * etoe64( e, &d ) convert e type to IEEE long double precision | ||
| 84 | * ltoe( &l, e ) long (32 bit) integer to e type | ||
| 85 | * ultoe( &l, e ) unsigned long (32 bit) integer to e type | ||
| 86 | * eisneg( e ) 1 if sign bit of e != 0, else 0 | ||
| 87 | * eisinf( e ) 1 if e has maximum exponent (non-IEEE) | ||
| 88 | * or is infinite (IEEE) | ||
| 89 | * eisnan( e ) 1 if e is a NaN | ||
| 90 | * esqrt( a, b ) b = square root of a | ||
| 91 | * | ||
| 92 | * | ||
| 93 | * Routines for internal format numbers | ||
| 94 | * | ||
| 95 | * eaddm( ai, bi ) add significands, bi = bi + ai | ||
| 96 | * ecleaz(ei) ei = 0 | ||
| 97 | * ecleazs(ei) set ei = 0 but leave its sign alone | ||
| 98 | * ecmpm( ai, bi ) compare significands, return 1, 0, or -1 | ||
| 99 | * edivm( ai, bi ) divide significands, bi = bi / ai | ||
| 100 | * emdnorm(ai,l,s,exp) normalize and round off | ||
| 101 | * emovi( a, ai ) convert external a to internal ai | ||
| 102 | * emovo( ai, a ) convert internal ai to external a | ||
| 103 | * emovz( ai, bi ) bi = ai, low guard word of bi = 0 | ||
| 104 | * emulm( ai, bi ) multiply significands, bi = bi * ai | ||
| 105 | * enormlz(ei) left-justify the significand | ||
| 106 | * eshdn1( ai ) shift significand and guards down 1 bit | ||
| 107 | * eshdn8( ai ) shift down 8 bits | ||
| 108 | * eshdn6( ai ) shift down 16 bits | ||
| 109 | * eshift( ai, n ) shift ai n bits up (or down if n < 0) | ||
| 110 | * eshup1( ai ) shift significand and guards up 1 bit | ||
| 111 | * eshup8( ai ) shift up 8 bits | ||
| 112 | * eshup6( ai ) shift up 16 bits | ||
| 113 | * esubm( ai, bi ) subtract significands, bi = bi - ai | ||
| 114 | * | ||
| 115 | * | ||
| 116 | * The result is always normalized and rounded to NI-4 word precision | ||
| 117 | * after each arithmetic operation. | ||
| 118 | * | ||
| 119 | * Exception flags are NOT fully supported. | ||
| 120 | * | ||
| 121 | * Define INFINITY in mconf.h for support of infinity; otherwise a | ||
| 122 | * saturation arithmetic is implemented. | ||
| 123 | * | ||
| 124 | * Define NANS for support of Not-a-Number items; otherwise the | ||
| 125 | * arithmetic will never produce a NaN output, and might be confused | ||
| 126 | * by a NaN input. | ||
| 127 | * If NaN's are supported, the output of ecmp(a,b) is -2 if | ||
| 128 | * either a or b is a NaN. This means asking if(ecmp(a,b) < 0) | ||
| 129 | * may not be legitimate. Use if(ecmp(a,b) == -1) for less-than | ||
| 130 | * if in doubt. | ||
| 131 | * Signaling NaN's are NOT supported; they are treated the same | ||
| 132 | * as quiet NaN's. | ||
| 133 | * | ||
| 134 | * Denormals are always supported here where appropriate (e.g., not | ||
| 135 | * for conversion to DEC numbers). | ||
| 136 | */ | ||
| 137 | |||
| 138 | /* | ||
| 139 | * Revision history: | ||
| 140 | * | ||
| 141 | * 5 Jan 84 PDP-11 assembly language version | ||
| 142 | * 2 Mar 86 fixed bug in asctoq() | ||
| 143 | * 6 Dec 86 C language version | ||
| 144 | * 30 Aug 88 100 digit version, improved rounding | ||
| 145 | * 15 May 92 80-bit long double support | ||
| 146 | * | ||
| 147 | * Author: S. L. Moshier. | ||
| 148 | */ | ||
| 149 | |||
| 150 | #include <stdio.h> | ||
| 151 | #include "mconf.h" | ||
| 152 | #include "ehead.h" | ||
| 153 | |||
| 154 | /* Change UNK into something else. */ | ||
| 155 | #ifdef UNK | ||
| 156 | #undef UNK | ||
| 157 | #if BIGENDIAN | ||
| 158 | #define MIEEE 1 | ||
| 159 | #else | ||
| 160 | #define IBMPC 1 | ||
| 161 | #endif | ||
| 162 | #endif | ||
| 163 | |||
| 164 | /* NaN's require infinity support. */ | ||
| 165 | #ifdef NANS | ||
| 166 | #ifndef INFINITY | ||
| 167 | #define INFINITY | ||
| 168 | #endif | ||
| 169 | #endif | ||
| 170 | |||
| 171 | /* This handles 64-bit long ints. */ | ||
| 172 | #define LONGBITS (8 * sizeof(long)) | ||
| 173 | |||
| 174 | /* Control register for rounding precision. | ||
| 175 | * This can be set to 80 (if NE=6), 64, 56, 53, or 24 bits. | ||
| 176 | */ | ||
| 177 | int rndprc = NBITS; | ||
| 178 | extern int rndprc; | ||
| 179 | |||
| 180 | void eaddm(), esubm(), emdnorm(), asctoeg(), enan(); | ||
| 181 | static void toe24(), toe53(), toe64(), toe113(); | ||
| 182 | void eremain(), einit(), eiremain(); | ||
| 183 | int ecmpm(), edivm(), emulm(), eisneg(), eisinf(); | ||
| 184 | void emovi(), emovo(), emovz(), ecleaz(), eadd1(); | ||
| 185 | void etodec(), todec(), dectoe(); | ||
| 186 | int eisnan(), eiisnan(); | ||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | void einit() | ||
| 191 | { | ||
| 192 | } | ||
| 193 | |||
| 194 | /* | ||
| 195 | ; Clear out entire external format number. | ||
| 196 | ; | ||
| 197 | ; unsigned short x[]; | ||
| 198 | ; eclear( x ); | ||
| 199 | */ | ||
| 200 | |||
| 201 | void eclear( x ) | ||
| 202 | register unsigned short *x; | ||
| 203 | { | ||
| 204 | register int i; | ||
| 205 | |||
| 206 | for( i=0; i<NE; i++ ) | ||
| 207 | *x++ = 0; | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | /* Move external format number from a to b. | ||
| 213 | * | ||
| 214 | * emov( a, b ); | ||
| 215 | */ | ||
| 216 | |||
| 217 | void emov( a, b ) | ||
| 218 | register unsigned short *a, *b; | ||
| 219 | { | ||
| 220 | register int i; | ||
| 221 | |||
| 222 | for( i=0; i<NE; i++ ) | ||
| 223 | *b++ = *a++; | ||
| 224 | } | ||
| 225 | |||
| 226 | |||
| 227 | /* | ||
| 228 | ; Absolute value of external format number | ||
| 229 | ; | ||
| 230 | ; short x[NE]; | ||
| 231 | ; eabs( x ); | ||
| 232 | */ | ||
| 233 | |||
| 234 | void eabs(x) | ||
| 235 | unsigned short x[]; /* x is the memory address of a short */ | ||
| 236 | { | ||
| 237 | |||
| 238 | x[NE-1] &= 0x7fff; /* sign is top bit of last word of external format */ | ||
| 239 | } | ||
| 240 | |||
| 241 | |||
| 242 | |||
| 243 | |||
| 244 | /* | ||
| 245 | ; Negate external format number | ||
| 246 | ; | ||
| 247 | ; unsigned short x[NE]; | ||
| 248 | ; eneg( x ); | ||
| 249 | */ | ||
| 250 | |||
| 251 | void eneg(x) | ||
| 252 | unsigned short x[]; | ||
| 253 | { | ||
| 254 | |||
| 255 | #ifdef NANS | ||
| 256 | if( eisnan(x) ) | ||
| 257 | return; | ||
| 258 | #endif | ||
| 259 | x[NE-1] ^= 0x8000; /* Toggle the sign bit */ | ||
| 260 | } | ||
| 261 | |||
| 262 | |||
| 263 | |||
| 264 | /* Return 1 if external format number is negative, | ||
| 265 | * else return zero. | ||
| 266 | */ | ||
| 267 | int eisneg(x) | ||
| 268 | unsigned short x[]; | ||
| 269 | { | ||
| 270 | |||
| 271 | #ifdef NANS | ||
| 272 | if( eisnan(x) ) | ||
| 273 | return( 0 ); | ||
| 274 | #endif | ||
| 275 | if( x[NE-1] & 0x8000 ) | ||
| 276 | return( 1 ); | ||
| 277 | else | ||
| 278 | return( 0 ); | ||
| 279 | } | ||
| 280 | |||
| 281 | |||
| 282 | /* Return 1 if external format number has maximum possible exponent, | ||
| 283 | * else return zero. | ||
| 284 | */ | ||
| 285 | int eisinf(x) | ||
| 286 | unsigned short x[]; | ||
| 287 | { | ||
| 288 | |||
| 289 | if( (x[NE-1] & 0x7fff) == 0x7fff ) | ||
| 290 | { | ||
| 291 | #ifdef NANS | ||
| 292 | if( eisnan(x) ) | ||
| 293 | return( 0 ); | ||
| 294 | #endif | ||
| 295 | return( 1 ); | ||
| 296 | } | ||
| 297 | else | ||
| 298 | return( 0 ); | ||
| 299 | } | ||
| 300 | |||
| 301 | /* Check if e-type number is not a number. | ||
| 302 | */ | ||
| 303 | int eisnan(x) | ||
| 304 | unsigned short x[]; | ||
| 305 | { | ||
| 306 | |||
| 307 | #ifdef NANS | ||
| 308 | int i; | ||
| 309 | /* NaN has maximum exponent */ | ||
| 310 | if( (x[NE-1] & 0x7fff) != 0x7fff ) | ||
| 311 | return (0); | ||
| 312 | /* ... and non-zero significand field. */ | ||
| 313 | for( i=0; i<NE-1; i++ ) | ||
| 314 | { | ||
| 315 | if( *x++ != 0 ) | ||
| 316 | return (1); | ||
| 317 | } | ||
| 318 | #endif | ||
| 319 | return (0); | ||
| 320 | } | ||
| 321 | |||
| 322 | /* | ||
| 323 | ; Fill entire number, including exponent and significand, with | ||
| 324 | ; largest possible number. These programs implement a saturation | ||
| 325 | ; value that is an ordinary, legal number. A special value | ||
| 326 | ; "infinity" may also be implemented; this would require tests | ||
| 327 | ; for that value and implementation of special rules for arithmetic | ||
| 328 | ; operations involving inifinity. | ||
| 329 | */ | ||
| 330 | |||
| 331 | void einfin(x) | ||
| 332 | register unsigned short *x; | ||
| 333 | { | ||
| 334 | register int i; | ||
| 335 | |||
| 336 | #ifdef INFINITY | ||
| 337 | for( i=0; i<NE-1; i++ ) | ||
| 338 | *x++ = 0; | ||
| 339 | *x |= 32767; | ||
| 340 | #else | ||
| 341 | for( i=0; i<NE-1; i++ ) | ||
| 342 | *x++ = 0xffff; | ||
| 343 | *x |= 32766; | ||
| 344 | if( rndprc < NBITS ) | ||
| 345 | { | ||
| 346 | if (rndprc == 113) | ||
| 347 | { | ||
| 348 | *(x - 9) = 0; | ||
| 349 | *(x - 8) = 0; | ||
| 350 | } | ||
| 351 | if( rndprc == 64 ) | ||
| 352 | { | ||
| 353 | *(x-5) = 0; | ||
| 354 | } | ||
| 355 | if( rndprc == 53 ) | ||
| 356 | { | ||
| 357 | *(x-4) = 0xf800; | ||
| 358 | } | ||
| 359 | else | ||
| 360 | { | ||
| 361 | *(x-4) = 0; | ||
| 362 | *(x-3) = 0; | ||
| 363 | *(x-2) = 0xff00; | ||
| 364 | } | ||
| 365 | } | ||
| 366 | #endif | ||
| 367 | } | ||
| 368 | |||
| 369 | |||
| 370 | |||
| 371 | /* Move in external format number, | ||
| 372 | * converting it to internal format. | ||
| 373 | */ | ||
| 374 | void emovi( a, b ) | ||
| 375 | unsigned short *a, *b; | ||
| 376 | { | ||
| 377 | register unsigned short *p, *q; | ||
| 378 | int i; | ||
| 379 | |||
| 380 | q = b; | ||
| 381 | p = a + (NE-1); /* point to last word of external number */ | ||
| 382 | /* get the sign bit */ | ||
| 383 | if( *p & 0x8000 ) | ||
| 384 | *q++ = 0xffff; | ||
| 385 | else | ||
| 386 | *q++ = 0; | ||
| 387 | /* get the exponent */ | ||
| 388 | *q = *p--; | ||
| 389 | *q++ &= 0x7fff; /* delete the sign bit */ | ||
| 390 | #ifdef INFINITY | ||
| 391 | if( (*(q-1) & 0x7fff) == 0x7fff ) | ||
| 392 | { | ||
| 393 | #ifdef NANS | ||
| 394 | if( eisnan(a) ) | ||
| 395 | { | ||
| 396 | *q++ = 0; | ||
| 397 | for( i=3; i<NI; i++ ) | ||
| 398 | *q++ = *p--; | ||
| 399 | return; | ||
| 400 | } | ||
| 401 | #endif | ||
| 402 | for( i=2; i<NI; i++ ) | ||
| 403 | *q++ = 0; | ||
| 404 | return; | ||
| 405 | } | ||
| 406 | #endif | ||
| 407 | /* clear high guard word */ | ||
| 408 | *q++ = 0; | ||
| 409 | /* move in the significand */ | ||
| 410 | for( i=0; i<NE-1; i++ ) | ||
| 411 | *q++ = *p--; | ||
| 412 | /* clear low guard word */ | ||
| 413 | *q = 0; | ||
| 414 | } | ||
| 415 | |||
| 416 | |||
| 417 | /* Move internal format number out, | ||
| 418 | * converting it to external format. | ||
| 419 | */ | ||
| 420 | void emovo( a, b ) | ||
| 421 | unsigned short *a, *b; | ||
| 422 | { | ||
| 423 | register unsigned short *p, *q; | ||
| 424 | unsigned short i; | ||
| 425 | |||
| 426 | p = a; | ||
| 427 | q = b + (NE-1); /* point to output exponent */ | ||
| 428 | /* combine sign and exponent */ | ||
| 429 | i = *p++; | ||
| 430 | if( i ) | ||
| 431 | *q-- = *p++ | 0x8000; | ||
| 432 | else | ||
| 433 | *q-- = *p++; | ||
| 434 | #ifdef INFINITY | ||
| 435 | if( *(p-1) == 0x7fff ) | ||
| 436 | { | ||
| 437 | #ifdef NANS | ||
| 438 | if( eiisnan(a) ) | ||
| 439 | { | ||
| 440 | enan( b, NBITS ); | ||
| 441 | return; | ||
| 442 | } | ||
| 443 | #endif | ||
| 444 | einfin(b); | ||
| 445 | return; | ||
| 446 | } | ||
| 447 | #endif | ||
| 448 | /* skip over guard word */ | ||
| 449 | ++p; | ||
| 450 | /* move the significand */ | ||
| 451 | for( i=0; i<NE-1; i++ ) | ||
| 452 | *q-- = *p++; | ||
| 453 | } | ||
| 454 | |||
| 455 | |||
| 456 | |||
| 457 | |||
| 458 | /* Clear out internal format number. | ||
| 459 | */ | ||
| 460 | |||
| 461 | void ecleaz( xi ) | ||
| 462 | register unsigned short *xi; | ||
| 463 | { | ||
| 464 | register int i; | ||
| 465 | |||
| 466 | for( i=0; i<NI; i++ ) | ||
| 467 | *xi++ = 0; | ||
| 468 | } | ||
| 469 | |||
| 470 | /* same, but don't touch the sign. */ | ||
| 471 | |||
| 472 | void ecleazs( xi ) | ||
| 473 | register unsigned short *xi; | ||
| 474 | { | ||
| 475 | register int i; | ||
| 476 | |||
| 477 | ++xi; | ||
| 478 | for(i=0; i<NI-1; i++) | ||
| 479 | *xi++ = 0; | ||
| 480 | } | ||
| 481 | |||
| 482 | |||
| 483 | |||
| 484 | |||
| 485 | /* Move internal format number from a to b. | ||
| 486 | */ | ||
| 487 | void emovz( a, b ) | ||
| 488 | register unsigned short *a, *b; | ||
| 489 | { | ||
| 490 | register int i; | ||
| 491 | |||
| 492 | for( i=0; i<NI-1; i++ ) | ||
| 493 | *b++ = *a++; | ||
| 494 | /* clear low guard word */ | ||
| 495 | *b = 0; | ||
| 496 | } | ||
| 497 | |||
| 498 | /* Return nonzero if internal format number is a NaN. | ||
| 499 | */ | ||
| 500 | |||
| 501 | int eiisnan (x) | ||
| 502 | unsigned short x[]; | ||
| 503 | { | ||
| 504 | int i; | ||
| 505 | |||
| 506 | if( (x[E] & 0x7fff) == 0x7fff ) | ||
| 507 | { | ||
| 508 | for( i=M+1; i<NI; i++ ) | ||
| 509 | { | ||
| 510 | if( x[i] != 0 ) | ||
| 511 | return(1); | ||
| 512 | } | ||
| 513 | } | ||
| 514 | return(0); | ||
| 515 | } | ||
| 516 | |||
| 517 | #ifdef INFINITY | ||
| 518 | /* Return nonzero if internal format number is infinite. */ | ||
| 519 | |||
| 520 | static int | ||
| 521 | eiisinf (x) | ||
| 522 | unsigned short x[]; | ||
| 523 | { | ||
| 524 | |||
| 525 | #ifdef NANS | ||
| 526 | if (eiisnan (x)) | ||
| 527 | return (0); | ||
| 528 | #endif | ||
| 529 | if ((x[E] & 0x7fff) == 0x7fff) | ||
| 530 | return (1); | ||
| 531 | return (0); | ||
| 532 | } | ||
| 533 | #endif | ||
| 534 | |||
| 535 | /* | ||
| 536 | ; Compare significands of numbers in internal format. | ||
| 537 | ; Guard words are included in the comparison. | ||
| 538 | ; | ||
| 539 | ; unsigned short a[NI], b[NI]; | ||
| 540 | ; cmpm( a, b ); | ||
| 541 | ; | ||
| 542 | ; for the significands: | ||
| 543 | ; returns +1 if a > b | ||
| 544 | ; 0 if a == b | ||
| 545 | ; -1 if a < b | ||
| 546 | */ | ||
| 547 | int ecmpm( a, b ) | ||
| 548 | register unsigned short *a, *b; | ||
| 549 | { | ||
| 550 | int i; | ||
| 551 | |||
| 552 | a += M; /* skip up to significand area */ | ||
| 553 | b += M; | ||
| 554 | for( i=M; i<NI; i++ ) | ||
| 555 | { | ||
| 556 | if( *a++ != *b++ ) | ||
| 557 | goto difrnt; | ||
| 558 | } | ||
| 559 | return(0); | ||
| 560 | |||
| 561 | difrnt: | ||
| 562 | if( *(--a) > *(--b) ) | ||
| 563 | return(1); | ||
| 564 | else | ||
| 565 | return(-1); | ||
| 566 | } | ||
| 567 | |||
| 568 | |||
| 569 | /* | ||
| 570 | ; Shift significand down by 1 bit | ||
| 571 | */ | ||
| 572 | |||
| 573 | void eshdn1(x) | ||
| 574 | register unsigned short *x; | ||
| 575 | { | ||
| 576 | register unsigned short bits; | ||
| 577 | int i; | ||
| 578 | |||
| 579 | x += M; /* point to significand area */ | ||
| 580 | |||
| 581 | bits = 0; | ||
| 582 | for( i=M; i<NI; i++ ) | ||
| 583 | { | ||
| 584 | if( *x & 1 ) | ||
| 585 | bits |= 1; | ||
| 586 | *x >>= 1; | ||
| 587 | if( bits & 2 ) | ||
| 588 | *x |= 0x8000; | ||
| 589 | bits <<= 1; | ||
| 590 | ++x; | ||
| 591 | } | ||
| 592 | } | ||
| 593 | |||
| 594 | |||
| 595 | |||
| 596 | /* | ||
| 597 | ; Shift significand up by 1 bit | ||
| 598 | */ | ||
| 599 | |||
| 600 | void eshup1(x) | ||
| 601 | register unsigned short *x; | ||
| 602 | { | ||
| 603 | register unsigned short bits; | ||
| 604 | int i; | ||
| 605 | |||
| 606 | x += NI-1; | ||
| 607 | bits = 0; | ||
| 608 | |||
| 609 | for( i=M; i<NI; i++ ) | ||
| 610 | { | ||
| 611 | if( *x & 0x8000 ) | ||
| 612 | bits |= 1; | ||
| 613 | *x <<= 1; | ||
| 614 | if( bits & 2 ) | ||
| 615 | *x |= 1; | ||
| 616 | bits <<= 1; | ||
| 617 | --x; | ||
| 618 | } | ||
| 619 | } | ||
| 620 | |||
| 621 | |||
| 622 | |||
| 623 | /* | ||
| 624 | ; Shift significand down by 8 bits | ||
| 625 | */ | ||
| 626 | |||
| 627 | void eshdn8(x) | ||
| 628 | register unsigned short *x; | ||
| 629 | { | ||
| 630 | register unsigned short newbyt, oldbyt; | ||
| 631 | int i; | ||
| 632 | |||
| 633 | x += M; | ||
| 634 | oldbyt = 0; | ||
| 635 | for( i=M; i<NI; i++ ) | ||
| 636 | { | ||
| 637 | newbyt = *x << 8; | ||
| 638 | *x >>= 8; | ||
| 639 | *x |= oldbyt; | ||
| 640 | oldbyt = newbyt; | ||
| 641 | ++x; | ||
| 642 | } | ||
| 643 | } | ||
| 644 | |||
| 645 | /* | ||
| 646 | ; Shift significand up by 8 bits | ||
| 647 | */ | ||
| 648 | |||
| 649 | void eshup8(x) | ||
| 650 | register unsigned short *x; | ||
| 651 | { | ||
| 652 | int i; | ||
| 653 | register unsigned short newbyt, oldbyt; | ||
| 654 | |||
| 655 | x += NI-1; | ||
| 656 | oldbyt = 0; | ||
| 657 | |||
| 658 | for( i=M; i<NI; i++ ) | ||
| 659 | { | ||
| 660 | newbyt = *x >> 8; | ||
| 661 | *x <<= 8; | ||
| 662 | *x |= oldbyt; | ||
| 663 | oldbyt = newbyt; | ||
| 664 | --x; | ||
| 665 | } | ||
| 666 | } | ||
| 667 | |||
| 668 | /* | ||
| 669 | ; Shift significand up by 16 bits | ||
| 670 | */ | ||
| 671 | |||
| 672 | void eshup6(x) | ||
| 673 | register unsigned short *x; | ||
| 674 | { | ||
| 675 | int i; | ||
| 676 | register unsigned short *p; | ||
| 677 | |||
| 678 | p = x + M; | ||
| 679 | x += M + 1; | ||
| 680 | |||
| 681 | for( i=M; i<NI-1; i++ ) | ||
| 682 | *p++ = *x++; | ||
| 683 | |||
| 684 | *p = 0; | ||
| 685 | } | ||
| 686 | |||
| 687 | /* | ||
| 688 | ; Shift significand down by 16 bits | ||
| 689 | */ | ||
| 690 | |||
| 691 | void eshdn6(x) | ||
| 692 | register unsigned short *x; | ||
| 693 | { | ||
| 694 | int i; | ||
| 695 | register unsigned short *p; | ||
| 696 | |||
| 697 | x += NI-1; | ||
| 698 | p = x + 1; | ||
| 699 | |||
| 700 | for( i=M; i<NI-1; i++ ) | ||
| 701 | *(--p) = *(--x); | ||
| 702 | |||
| 703 | *(--p) = 0; | ||
| 704 | } | ||
| 705 | |||
| 706 | /* | ||
| 707 | ; Add significands | ||
| 708 | ; x + y replaces y | ||
| 709 | */ | ||
| 710 | |||
| 711 | void eaddm( x, y ) | ||
| 712 | unsigned short *x, *y; | ||
| 713 | { | ||
| 714 | register unsigned long a; | ||
| 715 | int i; | ||
| 716 | unsigned int carry; | ||
| 717 | |||
| 718 | x += NI-1; | ||
| 719 | y += NI-1; | ||
| 720 | carry = 0; | ||
| 721 | for( i=M; i<NI; i++ ) | ||
| 722 | { | ||
| 723 | a = (unsigned long )(*x) + (unsigned long )(*y) + carry; | ||
| 724 | if( a & 0x10000 ) | ||
| 725 | carry = 1; | ||
| 726 | else | ||
| 727 | carry = 0; | ||
| 728 | *y = (unsigned short )a; | ||
| 729 | --x; | ||
| 730 | --y; | ||
| 731 | } | ||
| 732 | } | ||
| 733 | |||
| 734 | /* | ||
| 735 | ; Subtract significands | ||
| 736 | ; y - x replaces y | ||
| 737 | */ | ||
| 738 | |||
| 739 | void esubm( x, y ) | ||
| 740 | unsigned short *x, *y; | ||
| 741 | { | ||
| 742 | unsigned long a; | ||
| 743 | int i; | ||
| 744 | unsigned int carry; | ||
| 745 | |||
| 746 | x += NI-1; | ||
| 747 | y += NI-1; | ||
| 748 | carry = 0; | ||
| 749 | for( i=M; i<NI; i++ ) | ||
| 750 | { | ||
| 751 | a = (unsigned long )(*y) - (unsigned long )(*x) - carry; | ||
| 752 | if( a & 0x10000 ) | ||
| 753 | carry = 1; | ||
| 754 | else | ||
| 755 | carry = 0; | ||
| 756 | *y = (unsigned short )a; | ||
| 757 | --x; | ||
| 758 | --y; | ||
| 759 | } | ||
| 760 | } | ||
| 761 | |||
| 762 | |||
| 763 | /* Divide significands */ | ||
| 764 | |||
| 765 | static unsigned short equot[NI] = {0}; /* was static */ | ||
| 766 | |||
| 767 | #if 0 | ||
| 768 | int edivm( den, num ) | ||
| 769 | unsigned short den[], num[]; | ||
| 770 | { | ||
| 771 | int i; | ||
| 772 | register unsigned short *p, *q; | ||
| 773 | unsigned short j; | ||
| 774 | |||
| 775 | p = &equot[0]; | ||
| 776 | *p++ = num[0]; | ||
| 777 | *p++ = num[1]; | ||
| 778 | |||
| 779 | for( i=M; i<NI; i++ ) | ||
| 780 | { | ||
| 781 | *p++ = 0; | ||
| 782 | } | ||
| 783 | |||
| 784 | /* Use faster compare and subtraction if denominator | ||
| 785 | * has only 15 bits of significance. | ||
| 786 | */ | ||
| 787 | p = &den[M+2]; | ||
| 788 | if( *p++ == 0 ) | ||
| 789 | { | ||
| 790 | for( i=M+3; i<NI; i++ ) | ||
| 791 | { | ||
| 792 | if( *p++ != 0 ) | ||
| 793 | goto fulldiv; | ||
| 794 | } | ||
| 795 | if( (den[M+1] & 1) != 0 ) | ||
| 796 | goto fulldiv; | ||
| 797 | eshdn1(num); | ||
| 798 | eshdn1(den); | ||
| 799 | |||
| 800 | p = &den[M+1]; | ||
| 801 | q = &num[M+1]; | ||
| 802 | |||
| 803 | for( i=0; i<NBITS+2; i++ ) | ||
| 804 | { | ||
| 805 | if( *p <= *q ) | ||
| 806 | { | ||
| 807 | *q -= *p; | ||
| 808 | j = 1; | ||
| 809 | } | ||
| 810 | else | ||
| 811 | { | ||
| 812 | j = 0; | ||
| 813 | } | ||
| 814 | eshup1(equot); | ||
| 815 | equot[NI-2] |= j; | ||
| 816 | eshup1(num); | ||
| 817 | } | ||
| 818 | goto divdon; | ||
| 819 | } | ||
| 820 | |||
| 821 | /* The number of quotient bits to calculate is | ||
| 822 | * NBITS + 1 scaling guard bit + 1 roundoff bit. | ||
| 823 | */ | ||
| 824 | fulldiv: | ||
| 825 | |||
| 826 | p = &equot[NI-2]; | ||
| 827 | for( i=0; i<NBITS+2; i++ ) | ||
| 828 | { | ||
| 829 | if( ecmpm(den,num) <= 0 ) | ||
| 830 | { | ||
| 831 | esubm(den, num); | ||
| 832 | j = 1; /* quotient bit = 1 */ | ||
| 833 | } | ||
| 834 | else | ||
| 835 | j = 0; | ||
| 836 | eshup1(equot); | ||
| 837 | *p |= j; | ||
| 838 | eshup1(num); | ||
| 839 | } | ||
| 840 | |||
| 841 | divdon: | ||
| 842 | |||
| 843 | eshdn1( equot ); | ||
| 844 | eshdn1( equot ); | ||
| 845 | |||
| 846 | /* test for nonzero remainder after roundoff bit */ | ||
| 847 | p = &num[M]; | ||
| 848 | j = 0; | ||
| 849 | for( i=M; i<NI; i++ ) | ||
| 850 | { | ||
| 851 | j |= *p++; | ||
| 852 | } | ||
| 853 | if( j ) | ||
| 854 | j = 1; | ||
| 855 | |||
| 856 | |||
| 857 | for( i=0; i<NI; i++ ) | ||
| 858 | num[i] = equot[i]; | ||
| 859 | return( (int )j ); | ||
| 860 | } | ||
| 861 | |||
| 862 | /* Multiply significands */ | ||
| 863 | int emulm( a, b ) | ||
| 864 | unsigned short a[], b[]; | ||
| 865 | { | ||
| 866 | unsigned short *p, *q; | ||
| 867 | int i, j, k; | ||
| 868 | |||
| 869 | equot[0] = b[0]; | ||
| 870 | equot[1] = b[1]; | ||
| 871 | for( i=M; i<NI; i++ ) | ||
| 872 | equot[i] = 0; | ||
| 873 | |||
| 874 | p = &a[NI-2]; | ||
| 875 | k = NBITS; | ||
| 876 | while( *p == 0 ) /* significand is not supposed to be all zero */ | ||
| 877 | { | ||
| 878 | eshdn6(a); | ||
| 879 | k -= 16; | ||
| 880 | } | ||
| 881 | if( (*p & 0xff) == 0 ) | ||
| 882 | { | ||
| 883 | eshdn8(a); | ||
| 884 | k -= 8; | ||
| 885 | } | ||
| 886 | |||
| 887 | q = &equot[NI-1]; | ||
| 888 | j = 0; | ||
| 889 | for( i=0; i<k; i++ ) | ||
| 890 | { | ||
| 891 | if( *p & 1 ) | ||
| 892 | eaddm(b, equot); | ||
| 893 | /* remember if there were any nonzero bits shifted out */ | ||
| 894 | if( *q & 1 ) | ||
| 895 | j |= 1; | ||
| 896 | eshdn1(a); | ||
| 897 | eshdn1(equot); | ||
| 898 | } | ||
| 899 | |||
| 900 | for( i=0; i<NI; i++ ) | ||
| 901 | b[i] = equot[i]; | ||
| 902 | |||
| 903 | /* return flag for lost nonzero bits */ | ||
| 904 | return(j); | ||
| 905 | } | ||
| 906 | |||
| 907 | #else | ||
| 908 | |||
| 909 | /* Multiply significand of e-type number b | ||
| 910 | by 16-bit quantity a, e-type result to c. */ | ||
| 911 | |||
| 912 | void m16m( a, b, c ) | ||
| 913 | unsigned short a; | ||
| 914 | unsigned short b[], c[]; | ||
| 915 | { | ||
| 916 | register unsigned short *pp; | ||
| 917 | register unsigned long carry; | ||
| 918 | unsigned short *ps; | ||
| 919 | unsigned short p[NI]; | ||
| 920 | unsigned long aa, m; | ||
| 921 | int i; | ||
| 922 | |||
| 923 | aa = a; | ||
| 924 | pp = &p[NI-2]; | ||
| 925 | *pp++ = 0; | ||
| 926 | *pp = 0; | ||
| 927 | ps = &b[NI-1]; | ||
| 928 | |||
| 929 | for( i=M+1; i<NI; i++ ) | ||
| 930 | { | ||
| 931 | if( *ps == 0 ) | ||
| 932 | { | ||
| 933 | --ps; | ||
| 934 | --pp; | ||
| 935 | *(pp-1) = 0; | ||
| 936 | } | ||
| 937 | else | ||
| 938 | { | ||
| 939 | m = (unsigned long) aa * *ps--; | ||
| 940 | carry = (m & 0xffff) + *pp; | ||
| 941 | *pp-- = (unsigned short )carry; | ||
| 942 | carry = (carry >> 16) + (m >> 16) + *pp; | ||
| 943 | *pp = (unsigned short )carry; | ||
| 944 | *(pp-1) = carry >> 16; | ||
| 945 | } | ||
| 946 | } | ||
| 947 | for( i=M; i<NI; i++ ) | ||
| 948 | c[i] = p[i]; | ||
| 949 | } | ||
| 950 | |||
| 951 | |||
| 952 | /* Divide significands. Neither the numerator nor the denominator | ||
| 953 | is permitted to have its high guard word nonzero. */ | ||
| 954 | |||
| 955 | |||
| 956 | int edivm( den, num ) | ||
| 957 | unsigned short den[], num[]; | ||
| 958 | { | ||
| 959 | int i; | ||
| 960 | register unsigned short *p; | ||
| 961 | unsigned long tnum; | ||
| 962 | unsigned short j, tdenm, tquot; | ||
| 963 | unsigned short tprod[NI+1]; | ||
| 964 | |||
| 965 | p = &equot[0]; | ||
| 966 | *p++ = num[0]; | ||
| 967 | *p++ = num[1]; | ||
| 968 | |||
| 969 | for( i=M; i<NI; i++ ) | ||
| 970 | { | ||
| 971 | *p++ = 0; | ||
| 972 | } | ||
| 973 | eshdn1( num ); | ||
| 974 | tdenm = den[M+1]; | ||
| 975 | for( i=M; i<NI; i++ ) | ||
| 976 | { | ||
| 977 | /* Find trial quotient digit (the radix is 65536). */ | ||
| 978 | tnum = (((unsigned long) num[M]) << 16) + num[M+1]; | ||
| 979 | |||
| 980 | /* Do not execute the divide instruction if it will overflow. */ | ||
| 981 | if( (tdenm * 0xffffL) < tnum ) | ||
| 982 | tquot = 0xffff; | ||
| 983 | else | ||
| 984 | tquot = tnum / tdenm; | ||
| 985 | |||
| 986 | /* Prove that the divide worked. */ | ||
| 987 | /* | ||
| 988 | tcheck = (unsigned long )tquot * tdenm; | ||
| 989 | if( tnum - tcheck > tdenm ) | ||
| 990 | tquot = 0xffff; | ||
| 991 | */ | ||
| 992 | /* Multiply denominator by trial quotient digit. */ | ||
| 993 | m16m( tquot, den, tprod ); | ||
| 994 | /* The quotient digit may have been overestimated. */ | ||
| 995 | if( ecmpm( tprod, num ) > 0 ) | ||
| 996 | { | ||
| 997 | tquot -= 1; | ||
| 998 | esubm( den, tprod ); | ||
| 999 | if( ecmpm( tprod, num ) > 0 ) | ||
| 1000 | { | ||
| 1001 | tquot -= 1; | ||
| 1002 | esubm( den, tprod ); | ||
| 1003 | } | ||
| 1004 | } | ||
| 1005 | /* | ||
| 1006 | if( ecmpm( tprod, num ) > 0 ) | ||
| 1007 | { | ||
| 1008 | eshow( "tprod", tprod ); | ||
| 1009 | eshow( "num ", num ); | ||
| 1010 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
| 1011 | tnum, den[M+1], tquot ); | ||
| 1012 | } | ||
| 1013 | */ | ||
| 1014 | esubm( tprod, num ); | ||
| 1015 | /* | ||
| 1016 | if( ecmpm( num, den ) >= 0 ) | ||
| 1017 | { | ||
| 1018 | eshow( "num ", num ); | ||
| 1019 | eshow( "den ", den ); | ||
| 1020 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
| 1021 | tnum, den[M+1], tquot ); | ||
| 1022 | } | ||
| 1023 | */ | ||
| 1024 | equot[i] = tquot; | ||
| 1025 | eshup6(num); | ||
| 1026 | } | ||
| 1027 | /* test for nonzero remainder after roundoff bit */ | ||
| 1028 | p = &num[M]; | ||
| 1029 | j = 0; | ||
| 1030 | for( i=M; i<NI; i++ ) | ||
| 1031 | { | ||
| 1032 | j |= *p++; | ||
| 1033 | } | ||
| 1034 | if( j ) | ||
| 1035 | j = 1; | ||
| 1036 | |||
| 1037 | for( i=0; i<NI; i++ ) | ||
| 1038 | num[i] = equot[i]; | ||
| 1039 | |||
| 1040 | return( (int )j ); | ||
| 1041 | } | ||
| 1042 | |||
| 1043 | |||
| 1044 | |||
| 1045 | /* Multiply significands */ | ||
| 1046 | int emulm( a, b ) | ||
| 1047 | unsigned short a[], b[]; | ||
| 1048 | { | ||
| 1049 | unsigned short *p, *q; | ||
| 1050 | unsigned short pprod[NI]; | ||
| 1051 | unsigned short j; | ||
| 1052 | int i; | ||
| 1053 | |||
| 1054 | equot[0] = b[0]; | ||
| 1055 | equot[1] = b[1]; | ||
| 1056 | for( i=M; i<NI; i++ ) | ||
| 1057 | equot[i] = 0; | ||
| 1058 | |||
| 1059 | j = 0; | ||
| 1060 | p = &a[NI-1]; | ||
| 1061 | q = &equot[NI-1]; | ||
| 1062 | for( i=M+1; i<NI; i++ ) | ||
| 1063 | { | ||
| 1064 | if( *p == 0 ) | ||
| 1065 | { | ||
| 1066 | --p; | ||
| 1067 | } | ||
| 1068 | else | ||
| 1069 | { | ||
| 1070 | m16m( *p--, b, pprod ); | ||
| 1071 | eaddm(pprod, equot); | ||
| 1072 | } | ||
| 1073 | j |= *q; | ||
| 1074 | eshdn6(equot); | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | for( i=0; i<NI; i++ ) | ||
| 1078 | b[i] = equot[i]; | ||
| 1079 | |||
| 1080 | /* return flag for lost nonzero bits */ | ||
| 1081 | return( (int)j ); | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | |||
| 1085 | /* | ||
| 1086 | eshow(str, x) | ||
| 1087 | char *str; | ||
| 1088 | unsigned short *x; | ||
| 1089 | { | ||
| 1090 | int i; | ||
| 1091 | |||
| 1092 | printf( "%s ", str ); | ||
| 1093 | for( i=0; i<NI; i++ ) | ||
| 1094 | printf( "%04x ", *x++ ); | ||
| 1095 | printf( "\n" ); | ||
| 1096 | } | ||
| 1097 | */ | ||
| 1098 | #endif | ||
| 1099 | |||
| 1100 | |||
| 1101 | |||
| 1102 | /* | ||
| 1103 | * Normalize and round off. | ||
| 1104 | * | ||
| 1105 | * The internal format number to be rounded is "s". | ||
| 1106 | * Input "lost" indicates whether the number is exact. | ||
| 1107 | * This is the so-called sticky bit. | ||
| 1108 | * | ||
| 1109 | * Input "subflg" indicates whether the number was obtained | ||
| 1110 | * by a subtraction operation. In that case if lost is nonzero | ||
| 1111 | * then the number is slightly smaller than indicated. | ||
| 1112 | * | ||
| 1113 | * Input "exp" is the biased exponent, which may be negative. | ||
| 1114 | * the exponent field of "s" is ignored but is replaced by | ||
| 1115 | * "exp" as adjusted by normalization and rounding. | ||
| 1116 | * | ||
| 1117 | * Input "rcntrl" is the rounding control. | ||
| 1118 | */ | ||
| 1119 | |||
| 1120 | static int rlast = -1; | ||
| 1121 | static int rw = 0; | ||
| 1122 | static unsigned short rmsk = 0; | ||
| 1123 | static unsigned short rmbit = 0; | ||
| 1124 | static unsigned short rebit = 0; | ||
| 1125 | static int re = 0; | ||
| 1126 | static unsigned short rbit[NI] = {0,0,0,0,0,0,0,0}; | ||
| 1127 | |||
| 1128 | void emdnorm( s, lost, subflg, exp, rcntrl ) | ||
| 1129 | unsigned short s[]; | ||
| 1130 | int lost; | ||
| 1131 | int subflg; | ||
| 1132 | long exp; | ||
| 1133 | int rcntrl; | ||
| 1134 | { | ||
| 1135 | int i, j; | ||
| 1136 | unsigned short r; | ||
| 1137 | |||
| 1138 | /* Normalize */ | ||
| 1139 | j = enormlz( s ); | ||
| 1140 | |||
| 1141 | /* a blank significand could mean either zero or infinity. */ | ||
| 1142 | #ifndef INFINITY | ||
| 1143 | if( j > NBITS ) | ||
| 1144 | { | ||
| 1145 | ecleazs( s ); | ||
| 1146 | return; | ||
| 1147 | } | ||
| 1148 | #endif | ||
| 1149 | exp -= j; | ||
| 1150 | #ifndef INFINITY | ||
| 1151 | if( exp >= 32767L ) | ||
| 1152 | goto overf; | ||
| 1153 | #else | ||
| 1154 | if( (j > NBITS) && (exp < 32767L) ) | ||
| 1155 | { | ||
| 1156 | ecleazs( s ); | ||
| 1157 | return; | ||
| 1158 | } | ||
| 1159 | #endif | ||
| 1160 | if( exp < 0L ) | ||
| 1161 | { | ||
| 1162 | if( exp > (long )(-NBITS-1) ) | ||
| 1163 | { | ||
| 1164 | j = (int )exp; | ||
| 1165 | i = eshift( s, j ); | ||
| 1166 | if( i ) | ||
| 1167 | lost = 1; | ||
| 1168 | } | ||
| 1169 | else | ||
| 1170 | { | ||
| 1171 | ecleazs( s ); | ||
| 1172 | return; | ||
| 1173 | } | ||
| 1174 | } | ||
| 1175 | /* Round off, unless told not to by rcntrl. */ | ||
| 1176 | if( rcntrl == 0 ) | ||
| 1177 | goto mdfin; | ||
| 1178 | /* Set up rounding parameters if the control register changed. */ | ||
| 1179 | if( rndprc != rlast ) | ||
| 1180 | { | ||
| 1181 | ecleaz( rbit ); | ||
| 1182 | switch( rndprc ) | ||
| 1183 | { | ||
| 1184 | default: | ||
| 1185 | case NBITS: | ||
| 1186 | rw = NI-1; /* low guard word */ | ||
| 1187 | rmsk = 0xffff; | ||
| 1188 | rmbit = 0x8000; | ||
| 1189 | rebit = 1; | ||
| 1190 | re = rw - 1; | ||
| 1191 | break; | ||
| 1192 | case 113: | ||
| 1193 | rw = 10; | ||
| 1194 | rmsk = 0x7fff; | ||
| 1195 | rmbit = 0x4000; | ||
| 1196 | rebit = 0x8000; | ||
| 1197 | re = rw; | ||
| 1198 | break; | ||
| 1199 | case 64: | ||
| 1200 | rw = 7; | ||
| 1201 | rmsk = 0xffff; | ||
| 1202 | rmbit = 0x8000; | ||
| 1203 | rebit = 1; | ||
| 1204 | re = rw-1; | ||
| 1205 | break; | ||
| 1206 | /* For DEC arithmetic */ | ||
| 1207 | case 56: | ||
| 1208 | rw = 6; | ||
| 1209 | rmsk = 0xff; | ||
| 1210 | rmbit = 0x80; | ||
| 1211 | rebit = 0x100; | ||
| 1212 | re = rw; | ||
| 1213 | break; | ||
| 1214 | case 53: | ||
| 1215 | rw = 6; | ||
| 1216 | rmsk = 0x7ff; | ||
| 1217 | rmbit = 0x0400; | ||
| 1218 | rebit = 0x800; | ||
| 1219 | re = rw; | ||
| 1220 | break; | ||
| 1221 | case 24: | ||
| 1222 | rw = 4; | ||
| 1223 | rmsk = 0xff; | ||
| 1224 | rmbit = 0x80; | ||
| 1225 | rebit = 0x100; | ||
| 1226 | re = rw; | ||
| 1227 | break; | ||
| 1228 | } | ||
| 1229 | rbit[re] = rebit; | ||
| 1230 | rlast = rndprc; | ||
| 1231 | } | ||
| 1232 | |||
| 1233 | /* Shift down 1 temporarily if the data structure has an implied | ||
| 1234 | * most significant bit and the number is denormal. | ||
| 1235 | * For rndprc = 64 or NBITS, there is no implied bit. | ||
| 1236 | * But Intel long double denormals lose one bit of significance even so. | ||
| 1237 | */ | ||
| 1238 | #ifdef IBMPC | ||
| 1239 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
| 1240 | #else | ||
| 1241 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
| 1242 | #endif | ||
| 1243 | { | ||
| 1244 | lost |= s[NI-1] & 1; | ||
| 1245 | eshdn1(s); | ||
| 1246 | } | ||
| 1247 | /* Clear out all bits below the rounding bit, | ||
| 1248 | * remembering in r if any were nonzero. | ||
| 1249 | */ | ||
| 1250 | r = s[rw] & rmsk; | ||
| 1251 | if( rndprc < NBITS ) | ||
| 1252 | { | ||
| 1253 | i = rw + 1; | ||
| 1254 | while( i < NI ) | ||
| 1255 | { | ||
| 1256 | if( s[i] ) | ||
| 1257 | r |= 1; | ||
| 1258 | s[i] = 0; | ||
| 1259 | ++i; | ||
| 1260 | } | ||
| 1261 | } | ||
| 1262 | s[rw] &= ~rmsk; | ||
| 1263 | if( (r & rmbit) != 0 ) | ||
| 1264 | { | ||
| 1265 | if( r == rmbit ) | ||
| 1266 | { | ||
| 1267 | if( lost == 0 ) | ||
| 1268 | { /* round to even */ | ||
| 1269 | if( (s[re] & rebit) == 0 ) | ||
| 1270 | goto mddone; | ||
| 1271 | } | ||
| 1272 | else | ||
| 1273 | { | ||
| 1274 | if( subflg != 0 ) | ||
| 1275 | goto mddone; | ||
| 1276 | } | ||
| 1277 | } | ||
| 1278 | eaddm( rbit, s ); | ||
| 1279 | } | ||
| 1280 | mddone: | ||
| 1281 | #ifdef IBMPC | ||
| 1282 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
| 1283 | #else | ||
| 1284 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
| 1285 | #endif | ||
| 1286 | { | ||
| 1287 | eshup1(s); | ||
| 1288 | } | ||
| 1289 | if( s[2] != 0 ) | ||
| 1290 | { /* overflow on roundoff */ | ||
| 1291 | eshdn1(s); | ||
| 1292 | exp += 1; | ||
| 1293 | } | ||
| 1294 | mdfin: | ||
| 1295 | s[NI-1] = 0; | ||
| 1296 | if( exp >= 32767L ) | ||
| 1297 | { | ||
| 1298 | #ifndef INFINITY | ||
| 1299 | overf: | ||
| 1300 | #endif | ||
| 1301 | #ifdef INFINITY | ||
| 1302 | s[1] = 32767; | ||
| 1303 | for( i=2; i<NI-1; i++ ) | ||
| 1304 | s[i] = 0; | ||
| 1305 | #else | ||
| 1306 | s[1] = 32766; | ||
| 1307 | s[2] = 0; | ||
| 1308 | for( i=M+1; i<NI-1; i++ ) | ||
| 1309 | s[i] = 0xffff; | ||
| 1310 | s[NI-1] = 0; | ||
| 1311 | if( (rndprc < 64) || (rndprc == 113) ) | ||
| 1312 | { | ||
| 1313 | s[rw] &= ~rmsk; | ||
| 1314 | if( rndprc == 24 ) | ||
| 1315 | { | ||
| 1316 | s[5] = 0; | ||
| 1317 | s[6] = 0; | ||
| 1318 | } | ||
| 1319 | } | ||
| 1320 | #endif | ||
| 1321 | return; | ||
| 1322 | } | ||
| 1323 | if( exp < 0 ) | ||
| 1324 | s[1] = 0; | ||
| 1325 | else | ||
| 1326 | s[1] = (unsigned short )exp; | ||
| 1327 | } | ||
| 1328 | |||
| 1329 | |||
| 1330 | |||
| 1331 | /* | ||
| 1332 | ; Subtract external format numbers. | ||
| 1333 | ; | ||
| 1334 | ; unsigned short a[NE], b[NE], c[NE]; | ||
| 1335 | ; esub( a, b, c ); c = b - a | ||
| 1336 | */ | ||
| 1337 | |||
| 1338 | static int subflg = 0; | ||
| 1339 | |||
| 1340 | void esub( a, b, c ) | ||
| 1341 | unsigned short *a, *b, *c; | ||
| 1342 | { | ||
| 1343 | |||
| 1344 | #ifdef NANS | ||
| 1345 | if( eisnan(a) ) | ||
| 1346 | { | ||
| 1347 | emov (a, c); | ||
| 1348 | return; | ||
| 1349 | } | ||
| 1350 | if( eisnan(b) ) | ||
| 1351 | { | ||
| 1352 | emov(b,c); | ||
| 1353 | return; | ||
| 1354 | } | ||
| 1355 | /* Infinity minus infinity is a NaN. | ||
| 1356 | * Test for subtracting infinities of the same sign. | ||
| 1357 | */ | ||
| 1358 | if( eisinf(a) && eisinf(b) && ((eisneg (a) ^ eisneg (b)) == 0)) | ||
| 1359 | { | ||
| 1360 | mtherr( "esub", DOMAIN ); | ||
| 1361 | enan( c, NBITS ); | ||
| 1362 | return; | ||
| 1363 | } | ||
| 1364 | #endif | ||
| 1365 | subflg = 1; | ||
| 1366 | eadd1( a, b, c ); | ||
| 1367 | } | ||
| 1368 | |||
| 1369 | |||
| 1370 | /* | ||
| 1371 | ; Add. | ||
| 1372 | ; | ||
| 1373 | ; unsigned short a[NE], b[NE], c[NE]; | ||
| 1374 | ; eadd( a, b, c ); c = b + a | ||
| 1375 | */ | ||
| 1376 | void eadd( a, b, c ) | ||
| 1377 | unsigned short *a, *b, *c; | ||
| 1378 | { | ||
| 1379 | |||
| 1380 | #ifdef NANS | ||
| 1381 | /* NaN plus anything is a NaN. */ | ||
| 1382 | if( eisnan(a) ) | ||
| 1383 | { | ||
| 1384 | emov(a,c); | ||
| 1385 | return; | ||
| 1386 | } | ||
| 1387 | if( eisnan(b) ) | ||
| 1388 | { | ||
| 1389 | emov(b,c); | ||
| 1390 | return; | ||
| 1391 | } | ||
| 1392 | /* Infinity minus infinity is a NaN. | ||
| 1393 | * Test for adding infinities of opposite signs. | ||
| 1394 | */ | ||
| 1395 | if( eisinf(a) && eisinf(b) | ||
| 1396 | && ((eisneg(a) ^ eisneg(b)) != 0) ) | ||
| 1397 | { | ||
| 1398 | mtherr( "eadd", DOMAIN ); | ||
| 1399 | enan( c, NBITS ); | ||
| 1400 | return; | ||
| 1401 | } | ||
| 1402 | #endif | ||
| 1403 | subflg = 0; | ||
| 1404 | eadd1( a, b, c ); | ||
| 1405 | } | ||
| 1406 | |||
| 1407 | void eadd1( a, b, c ) | ||
| 1408 | unsigned short *a, *b, *c; | ||
| 1409 | { | ||
| 1410 | unsigned short ai[NI], bi[NI], ci[NI]; | ||
| 1411 | int i, lost, j, k; | ||
| 1412 | long lt, lta, ltb; | ||
| 1413 | |||
| 1414 | #ifdef INFINITY | ||
| 1415 | if( eisinf(a) ) | ||
| 1416 | { | ||
| 1417 | emov(a,c); | ||
| 1418 | if( subflg ) | ||
| 1419 | eneg(c); | ||
| 1420 | return; | ||
| 1421 | } | ||
| 1422 | if( eisinf(b) ) | ||
| 1423 | { | ||
| 1424 | emov(b,c); | ||
| 1425 | return; | ||
| 1426 | } | ||
| 1427 | #endif | ||
| 1428 | emovi( a, ai ); | ||
| 1429 | emovi( b, bi ); | ||
| 1430 | if( subflg ) | ||
| 1431 | ai[0] = ~ai[0]; | ||
| 1432 | |||
| 1433 | /* compare exponents */ | ||
| 1434 | lta = ai[E]; | ||
| 1435 | ltb = bi[E]; | ||
| 1436 | lt = lta - ltb; | ||
| 1437 | if( lt > 0L ) | ||
| 1438 | { /* put the larger number in bi */ | ||
| 1439 | emovz( bi, ci ); | ||
| 1440 | emovz( ai, bi ); | ||
| 1441 | emovz( ci, ai ); | ||
| 1442 | ltb = bi[E]; | ||
| 1443 | lt = -lt; | ||
| 1444 | } | ||
| 1445 | lost = 0; | ||
| 1446 | if( lt != 0L ) | ||
| 1447 | { | ||
| 1448 | if( lt < (long )(-NBITS-1) ) | ||
| 1449 | goto done; /* answer same as larger addend */ | ||
| 1450 | k = (int )lt; | ||
| 1451 | lost = eshift( ai, k ); /* shift the smaller number down */ | ||
| 1452 | } | ||
| 1453 | else | ||
| 1454 | { | ||
| 1455 | /* exponents were the same, so must compare significands */ | ||
| 1456 | i = ecmpm( ai, bi ); | ||
| 1457 | if( i == 0 ) | ||
| 1458 | { /* the numbers are identical in magnitude */ | ||
| 1459 | /* if different signs, result is zero */ | ||
| 1460 | if( ai[0] != bi[0] ) | ||
| 1461 | { | ||
| 1462 | eclear(c); | ||
| 1463 | return; | ||
| 1464 | } | ||
| 1465 | /* if same sign, result is double */ | ||
| 1466 | /* double denomalized tiny number */ | ||
| 1467 | if( (bi[E] == 0) && ((bi[3] & 0x8000) == 0) ) | ||
| 1468 | { | ||
| 1469 | eshup1( bi ); | ||
| 1470 | goto done; | ||
| 1471 | } | ||
| 1472 | /* add 1 to exponent unless both are zero! */ | ||
| 1473 | for( j=1; j<NI-1; j++ ) | ||
| 1474 | { | ||
| 1475 | if( bi[j] != 0 ) | ||
| 1476 | { | ||
| 1477 | ltb += 1; | ||
| 1478 | if( ltb >= 0x7fff ) | ||
| 1479 | { | ||
| 1480 | eclear(c); | ||
| 1481 | einfin(c); | ||
| 1482 | if( ai[0] != 0 ) | ||
| 1483 | eneg(c); | ||
| 1484 | return; | ||
| 1485 | } | ||
| 1486 | break; | ||
| 1487 | } | ||
| 1488 | } | ||
| 1489 | bi[E] = (unsigned short )ltb; | ||
| 1490 | goto done; | ||
| 1491 | } | ||
| 1492 | if( i > 0 ) | ||
| 1493 | { /* put the larger number in bi */ | ||
| 1494 | emovz( bi, ci ); | ||
| 1495 | emovz( ai, bi ); | ||
| 1496 | emovz( ci, ai ); | ||
| 1497 | } | ||
| 1498 | } | ||
| 1499 | if( ai[0] == bi[0] ) | ||
| 1500 | { | ||
| 1501 | eaddm( ai, bi ); | ||
| 1502 | subflg = 0; | ||
| 1503 | } | ||
| 1504 | else | ||
| 1505 | { | ||
| 1506 | esubm( ai, bi ); | ||
| 1507 | subflg = 1; | ||
| 1508 | } | ||
| 1509 | emdnorm( bi, lost, subflg, ltb, 64 ); | ||
| 1510 | |||
| 1511 | done: | ||
| 1512 | emovo( bi, c ); | ||
| 1513 | } | ||
| 1514 | |||
| 1515 | |||
| 1516 | |||
| 1517 | /* | ||
| 1518 | ; Divide. | ||
| 1519 | ; | ||
| 1520 | ; unsigned short a[NE], b[NE], c[NE]; | ||
| 1521 | ; ediv( a, b, c ); c = b / a | ||
| 1522 | */ | ||
| 1523 | void ediv( a, b, c ) | ||
| 1524 | unsigned short *a, *b, *c; | ||
| 1525 | { | ||
| 1526 | unsigned short ai[NI], bi[NI]; | ||
| 1527 | int i, sign; | ||
| 1528 | long lt, lta, ltb; | ||
| 1529 | |||
| 1530 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
| 1531 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
| 1532 | sign = eisneg(a) ^ eisneg(b); | ||
| 1533 | |||
| 1534 | #ifdef NANS | ||
| 1535 | /* Return any NaN input. */ | ||
| 1536 | if( eisnan(a) ) | ||
| 1537 | { | ||
| 1538 | emov(a,c); | ||
| 1539 | return; | ||
| 1540 | } | ||
| 1541 | if( eisnan(b) ) | ||
| 1542 | { | ||
| 1543 | emov(b,c); | ||
| 1544 | return; | ||
| 1545 | } | ||
| 1546 | /* Zero over zero, or infinity over infinity, is a NaN. */ | ||
| 1547 | if( ((ecmp(a,ezero) == 0) && (ecmp(b,ezero) == 0)) | ||
| 1548 | || (eisinf (a) && eisinf (b)) ) | ||
| 1549 | { | ||
| 1550 | mtherr( "ediv", DOMAIN ); | ||
| 1551 | enan( c, NBITS ); | ||
| 1552 | return; | ||
| 1553 | } | ||
| 1554 | #endif | ||
| 1555 | /* Infinity over anything else is infinity. */ | ||
| 1556 | #ifdef INFINITY | ||
| 1557 | if( eisinf(b) ) | ||
| 1558 | { | ||
| 1559 | einfin(c); | ||
| 1560 | goto divsign; | ||
| 1561 | } | ||
| 1562 | if( eisinf(a) ) | ||
| 1563 | { | ||
| 1564 | eclear(c); | ||
| 1565 | goto divsign; | ||
| 1566 | } | ||
| 1567 | #endif | ||
| 1568 | emovi( a, ai ); | ||
| 1569 | emovi( b, bi ); | ||
| 1570 | lta = ai[E]; | ||
| 1571 | ltb = bi[E]; | ||
| 1572 | if( bi[E] == 0 ) | ||
| 1573 | { /* See if numerator is zero. */ | ||
| 1574 | for( i=1; i<NI-1; i++ ) | ||
| 1575 | { | ||
| 1576 | if( bi[i] != 0 ) | ||
| 1577 | { | ||
| 1578 | ltb -= enormlz( bi ); | ||
| 1579 | goto dnzro1; | ||
| 1580 | } | ||
| 1581 | } | ||
| 1582 | eclear(c); | ||
| 1583 | goto divsign; | ||
| 1584 | } | ||
| 1585 | dnzro1: | ||
| 1586 | |||
| 1587 | if( ai[E] == 0 ) | ||
| 1588 | { /* possible divide by zero */ | ||
| 1589 | for( i=1; i<NI-1; i++ ) | ||
| 1590 | { | ||
| 1591 | if( ai[i] != 0 ) | ||
| 1592 | { | ||
| 1593 | lta -= enormlz( ai ); | ||
| 1594 | goto dnzro2; | ||
| 1595 | } | ||
| 1596 | } | ||
| 1597 | einfin(c); | ||
| 1598 | mtherr( "ediv", SING ); | ||
| 1599 | goto divsign; | ||
| 1600 | } | ||
| 1601 | dnzro2: | ||
| 1602 | |||
| 1603 | i = edivm( ai, bi ); | ||
| 1604 | /* calculate exponent */ | ||
| 1605 | lt = ltb - lta + EXONE; | ||
| 1606 | emdnorm( bi, i, 0, lt, 64 ); | ||
| 1607 | emovo( bi, c ); | ||
| 1608 | |||
| 1609 | divsign: | ||
| 1610 | |||
| 1611 | if( sign ) | ||
| 1612 | *(c+(NE-1)) |= 0x8000; | ||
| 1613 | else | ||
| 1614 | *(c+(NE-1)) &= ~0x8000; | ||
| 1615 | } | ||
| 1616 | |||
| 1617 | |||
| 1618 | |||
| 1619 | /* | ||
| 1620 | ; Multiply. | ||
| 1621 | ; | ||
| 1622 | ; unsigned short a[NE], b[NE], c[NE]; | ||
| 1623 | ; emul( a, b, c ); c = b * a | ||
| 1624 | */ | ||
| 1625 | void emul( a, b, c ) | ||
| 1626 | unsigned short *a, *b, *c; | ||
| 1627 | { | ||
| 1628 | unsigned short ai[NI], bi[NI]; | ||
| 1629 | int i, j, sign; | ||
| 1630 | long lt, lta, ltb; | ||
| 1631 | |||
| 1632 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
| 1633 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
| 1634 | sign = eisneg(a) ^ eisneg(b); | ||
| 1635 | |||
| 1636 | #ifdef NANS | ||
| 1637 | /* NaN times anything is the same NaN. */ | ||
| 1638 | if( eisnan(a) ) | ||
| 1639 | { | ||
| 1640 | emov(a,c); | ||
| 1641 | return; | ||
| 1642 | } | ||
| 1643 | if( eisnan(b) ) | ||
| 1644 | { | ||
| 1645 | emov(b,c); | ||
| 1646 | return; | ||
| 1647 | } | ||
| 1648 | /* Zero times infinity is a NaN. */ | ||
| 1649 | if( (eisinf(a) && (ecmp(b,ezero) == 0)) | ||
| 1650 | || (eisinf(b) && (ecmp(a,ezero) == 0)) ) | ||
| 1651 | { | ||
| 1652 | mtherr( "emul", DOMAIN ); | ||
| 1653 | enan( c, NBITS ); | ||
| 1654 | return; | ||
| 1655 | } | ||
| 1656 | #endif | ||
| 1657 | /* Infinity times anything else is infinity. */ | ||
| 1658 | #ifdef INFINITY | ||
| 1659 | if( eisinf(a) || eisinf(b) ) | ||
| 1660 | { | ||
| 1661 | einfin(c); | ||
| 1662 | goto mulsign; | ||
| 1663 | } | ||
| 1664 | #endif | ||
| 1665 | emovi( a, ai ); | ||
| 1666 | emovi( b, bi ); | ||
| 1667 | lta = ai[E]; | ||
| 1668 | ltb = bi[E]; | ||
| 1669 | if( ai[E] == 0 ) | ||
| 1670 | { | ||
| 1671 | for( i=1; i<NI-1; i++ ) | ||
| 1672 | { | ||
| 1673 | if( ai[i] != 0 ) | ||
| 1674 | { | ||
| 1675 | lta -= enormlz( ai ); | ||
| 1676 | goto mnzer1; | ||
| 1677 | } | ||
| 1678 | } | ||
| 1679 | eclear(c); | ||
| 1680 | goto mulsign; | ||
| 1681 | } | ||
| 1682 | mnzer1: | ||
| 1683 | |||
| 1684 | if( bi[E] == 0 ) | ||
| 1685 | { | ||
| 1686 | for( i=1; i<NI-1; i++ ) | ||
| 1687 | { | ||
| 1688 | if( bi[i] != 0 ) | ||
| 1689 | { | ||
| 1690 | ltb -= enormlz( bi ); | ||
| 1691 | goto mnzer2; | ||
| 1692 | } | ||
| 1693 | } | ||
| 1694 | eclear(c); | ||
| 1695 | goto mulsign; | ||
| 1696 | } | ||
| 1697 | mnzer2: | ||
| 1698 | |||
| 1699 | /* Multiply significands */ | ||
| 1700 | j = emulm( ai, bi ); | ||
| 1701 | /* calculate exponent */ | ||
| 1702 | lt = lta + ltb - (EXONE - 1); | ||
| 1703 | emdnorm( bi, j, 0, lt, 64 ); | ||
| 1704 | emovo( bi, c ); | ||
| 1705 | /* IEEE says sign is "-" if and only if operands have opposite signs. */ | ||
| 1706 | mulsign: | ||
| 1707 | if( sign ) | ||
| 1708 | *(c+(NE-1)) |= 0x8000; | ||
| 1709 | else | ||
| 1710 | *(c+(NE-1)) &= ~0x8000; | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | |||
| 1714 | |||
| 1715 | |||
| 1716 | /* | ||
| 1717 | ; Convert IEEE double precision to e type | ||
| 1718 | ; double d; | ||
| 1719 | ; unsigned short x[N+2]; | ||
| 1720 | ; e53toe( &d, x ); | ||
| 1721 | */ | ||
| 1722 | void e53toe( pe, y ) | ||
| 1723 | unsigned short *pe, *y; | ||
| 1724 | { | ||
| 1725 | #ifdef DEC | ||
| 1726 | |||
| 1727 | dectoe( pe, y ); /* see etodec.c */ | ||
| 1728 | |||
| 1729 | #else | ||
| 1730 | |||
| 1731 | register unsigned short r; | ||
| 1732 | register unsigned short *p, *e; | ||
| 1733 | unsigned short yy[NI]; | ||
| 1734 | int denorm, k; | ||
| 1735 | |||
| 1736 | e = pe; | ||
| 1737 | denorm = 0; /* flag if denormalized number */ | ||
| 1738 | ecleaz(yy); | ||
| 1739 | #ifdef IBMPC | ||
| 1740 | e += 3; | ||
| 1741 | #endif | ||
| 1742 | r = *e; | ||
| 1743 | yy[0] = 0; | ||
| 1744 | if( r & 0x8000 ) | ||
| 1745 | yy[0] = 0xffff; | ||
| 1746 | yy[M] = (r & 0x0f) | 0x10; | ||
| 1747 | r &= ~0x800f; /* strip sign and 4 significand bits */ | ||
| 1748 | #ifdef INFINITY | ||
| 1749 | if( r == 0x7ff0 ) | ||
| 1750 | { | ||
| 1751 | #ifdef NANS | ||
| 1752 | #ifdef IBMPC | ||
| 1753 | if( ((pe[3] & 0xf) != 0) || (pe[2] != 0) | ||
| 1754 | || (pe[1] != 0) || (pe[0] != 0) ) | ||
| 1755 | { | ||
| 1756 | enan( y, NBITS ); | ||
| 1757 | return; | ||
| 1758 | } | ||
| 1759 | #else | ||
| 1760 | if( ((pe[0] & 0xf) != 0) || (pe[1] != 0) | ||
| 1761 | || (pe[2] != 0) || (pe[3] != 0) ) | ||
| 1762 | { | ||
| 1763 | enan( y, NBITS ); | ||
| 1764 | return; | ||
| 1765 | } | ||
| 1766 | #endif | ||
| 1767 | #endif /* NANS */ | ||
| 1768 | eclear( y ); | ||
| 1769 | einfin( y ); | ||
| 1770 | if( yy[0] ) | ||
| 1771 | eneg(y); | ||
| 1772 | return; | ||
| 1773 | } | ||
| 1774 | #endif | ||
| 1775 | r >>= 4; | ||
| 1776 | /* If zero exponent, then the significand is denormalized. | ||
| 1777 | * So, take back the understood high significand bit. */ | ||
| 1778 | if( r == 0 ) | ||
| 1779 | { | ||
| 1780 | denorm = 1; | ||
| 1781 | yy[M] &= ~0x10; | ||
| 1782 | } | ||
| 1783 | r += EXONE - 01777; | ||
| 1784 | yy[E] = r; | ||
| 1785 | p = &yy[M+1]; | ||
| 1786 | #ifdef IBMPC | ||
| 1787 | *p++ = *(--e); | ||
| 1788 | *p++ = *(--e); | ||
| 1789 | *p++ = *(--e); | ||
| 1790 | #endif | ||
| 1791 | #ifdef MIEEE | ||
| 1792 | ++e; | ||
| 1793 | *p++ = *e++; | ||
| 1794 | *p++ = *e++; | ||
| 1795 | *p++ = *e++; | ||
| 1796 | #endif | ||
| 1797 | (void )eshift( yy, -5 ); | ||
| 1798 | if( denorm ) | ||
| 1799 | { /* if zero exponent, then normalize the significand */ | ||
| 1800 | if( (k = enormlz(yy)) > NBITS ) | ||
| 1801 | ecleazs(yy); | ||
| 1802 | else | ||
| 1803 | yy[E] -= (unsigned short )(k-1); | ||
| 1804 | } | ||
| 1805 | emovo( yy, y ); | ||
| 1806 | #endif /* not DEC */ | ||
| 1807 | } | ||
| 1808 | |||
| 1809 | void e64toe( pe, y ) | ||
| 1810 | unsigned short *pe, *y; | ||
| 1811 | { | ||
| 1812 | unsigned short yy[NI]; | ||
| 1813 | unsigned short *p, *q, *e; | ||
| 1814 | int i; | ||
| 1815 | |||
| 1816 | e = pe; | ||
| 1817 | p = yy; | ||
| 1818 | for( i=0; i<NE-5; i++ ) | ||
| 1819 | *p++ = 0; | ||
| 1820 | #ifdef IBMPC | ||
| 1821 | for( i=0; i<5; i++ ) | ||
| 1822 | *p++ = *e++; | ||
| 1823 | #endif | ||
| 1824 | #ifdef DEC | ||
| 1825 | for( i=0; i<5; i++ ) | ||
| 1826 | *p++ = *e++; | ||
| 1827 | #endif | ||
| 1828 | #ifdef MIEEE | ||
| 1829 | p = &yy[0] + (NE-1); | ||
| 1830 | *p-- = *e++; | ||
| 1831 | ++e; | ||
| 1832 | for( i=0; i<4; i++ ) | ||
| 1833 | *p-- = *e++; | ||
| 1834 | #endif | ||
| 1835 | |||
| 1836 | #ifdef IBMPC | ||
| 1837 | /* For Intel long double, shift denormal significand up 1 | ||
| 1838 | -- but only if the top significand bit is zero. */ | ||
| 1839 | if((yy[NE-1] & 0x7fff) == 0 && (yy[NE-2] & 0x8000) == 0) | ||
| 1840 | { | ||
| 1841 | unsigned short temp[NI+1]; | ||
| 1842 | emovi(yy, temp); | ||
| 1843 | eshup1(temp); | ||
| 1844 | emovo(temp,y); | ||
| 1845 | return; | ||
| 1846 | } | ||
| 1847 | #endif | ||
| 1848 | #ifdef INFINITY | ||
| 1849 | /* Point to the exponent field. */ | ||
| 1850 | p = &yy[NE-1]; | ||
| 1851 | if ((*p & 0x7fff) == 0x7fff) | ||
| 1852 | { | ||
| 1853 | #ifdef NANS | ||
| 1854 | #ifdef IBMPC | ||
| 1855 | for( i=0; i<4; i++ ) | ||
| 1856 | { | ||
| 1857 | if((i != 3 && pe[i] != 0) | ||
| 1858 | /* Check for Intel long double infinity pattern. */ | ||
| 1859 | || (i == 3 && pe[i] != 0x8000)) | ||
| 1860 | { | ||
| 1861 | enan( y, NBITS ); | ||
| 1862 | return; | ||
| 1863 | } | ||
| 1864 | } | ||
| 1865 | #else | ||
| 1866 | /* In Motorola extended precision format, the most significant | ||
| 1867 | bit of an infinity mantissa could be either 1 or 0. It is | ||
| 1868 | the lower order bits that tell whether the value is a NaN. */ | ||
| 1869 | if ((pe[2] & 0x7fff) != 0) | ||
| 1870 | goto bigend_nan; | ||
| 1871 | |||
| 1872 | for( i=3; i<=5; i++ ) | ||
| 1873 | { | ||
| 1874 | if( pe[i] != 0 ) | ||
| 1875 | { | ||
| 1876 | bigend_nan: | ||
| 1877 | enan( y, NBITS ); | ||
| 1878 | return; | ||
| 1879 | } | ||
| 1880 | } | ||
| 1881 | #endif | ||
| 1882 | #endif /* NANS */ | ||
| 1883 | eclear( y ); | ||
| 1884 | einfin( y ); | ||
| 1885 | if( *p & 0x8000 ) | ||
| 1886 | eneg(y); | ||
| 1887 | return; | ||
| 1888 | } | ||
| 1889 | #endif | ||
| 1890 | p = yy; | ||
| 1891 | q = y; | ||
| 1892 | for( i=0; i<NE; i++ ) | ||
| 1893 | *q++ = *p++; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | void e113toe(pe,y) | ||
| 1897 | unsigned short *pe, *y; | ||
| 1898 | { | ||
| 1899 | register unsigned short r; | ||
| 1900 | unsigned short *e, *p; | ||
| 1901 | unsigned short yy[NI]; | ||
| 1902 | int denorm, i; | ||
| 1903 | |||
| 1904 | e = pe; | ||
| 1905 | denorm = 0; | ||
| 1906 | ecleaz(yy); | ||
| 1907 | #ifdef IBMPC | ||
| 1908 | e += 7; | ||
| 1909 | #endif | ||
| 1910 | r = *e; | ||
| 1911 | yy[0] = 0; | ||
| 1912 | if( r & 0x8000 ) | ||
| 1913 | yy[0] = 0xffff; | ||
| 1914 | r &= 0x7fff; | ||
| 1915 | #ifdef INFINITY | ||
| 1916 | if( r == 0x7fff ) | ||
| 1917 | { | ||
| 1918 | #ifdef NANS | ||
| 1919 | #ifdef IBMPC | ||
| 1920 | for( i=0; i<7; i++ ) | ||
| 1921 | { | ||
| 1922 | if( pe[i] != 0 ) | ||
| 1923 | { | ||
| 1924 | enan( y, NBITS ); | ||
| 1925 | return; | ||
| 1926 | } | ||
| 1927 | } | ||
| 1928 | #else | ||
| 1929 | for( i=1; i<8; i++ ) | ||
| 1930 | { | ||
| 1931 | if( pe[i] != 0 ) | ||
| 1932 | { | ||
| 1933 | enan( y, NBITS ); | ||
| 1934 | return; | ||
| 1935 | } | ||
| 1936 | } | ||
| 1937 | #endif | ||
| 1938 | #endif /* NANS */ | ||
| 1939 | eclear( y ); | ||
| 1940 | einfin( y ); | ||
| 1941 | if( *e & 0x8000 ) | ||
| 1942 | eneg(y); | ||
| 1943 | return; | ||
| 1944 | } | ||
| 1945 | #endif /* INFINITY */ | ||
| 1946 | yy[E] = r; | ||
| 1947 | p = &yy[M + 1]; | ||
| 1948 | #ifdef IBMPC | ||
| 1949 | for( i=0; i<7; i++ ) | ||
| 1950 | *p++ = *(--e); | ||
| 1951 | #endif | ||
| 1952 | #ifdef MIEEE | ||
| 1953 | ++e; | ||
| 1954 | for( i=0; i<7; i++ ) | ||
| 1955 | *p++ = *e++; | ||
| 1956 | #endif | ||
| 1957 | /* If denormal, remove the implied bit; else shift down 1. */ | ||
| 1958 | if( r == 0 ) | ||
| 1959 | { | ||
| 1960 | yy[M] = 0; | ||
| 1961 | } | ||
| 1962 | else | ||
| 1963 | { | ||
| 1964 | yy[M] = 1; | ||
| 1965 | eshift( yy, -1 ); | ||
| 1966 | } | ||
| 1967 | emovo(yy,y); | ||
| 1968 | } | ||
| 1969 | |||
| 1970 | |||
| 1971 | /* | ||
| 1972 | ; Convert IEEE single precision to e type | ||
| 1973 | ; float d; | ||
| 1974 | ; unsigned short x[N+2]; | ||
| 1975 | ; dtox( &d, x ); | ||
| 1976 | */ | ||
| 1977 | void e24toe( pe, y ) | ||
| 1978 | unsigned short *pe, *y; | ||
| 1979 | { | ||
| 1980 | register unsigned short r; | ||
| 1981 | register unsigned short *p, *e; | ||
| 1982 | unsigned short yy[NI]; | ||
| 1983 | int denorm, k; | ||
| 1984 | |||
| 1985 | e = pe; | ||
| 1986 | denorm = 0; /* flag if denormalized number */ | ||
| 1987 | ecleaz(yy); | ||
| 1988 | #ifdef IBMPC | ||
| 1989 | e += 1; | ||
| 1990 | #endif | ||
| 1991 | #ifdef DEC | ||
| 1992 | e += 1; | ||
| 1993 | #endif | ||
| 1994 | r = *e; | ||
| 1995 | yy[0] = 0; | ||
| 1996 | if( r & 0x8000 ) | ||
| 1997 | yy[0] = 0xffff; | ||
| 1998 | yy[M] = (r & 0x7f) | 0200; | ||
| 1999 | r &= ~0x807f; /* strip sign and 7 significand bits */ | ||
| 2000 | #ifdef INFINITY | ||
| 2001 | if( r == 0x7f80 ) | ||
| 2002 | { | ||
| 2003 | #ifdef NANS | ||
| 2004 | #ifdef MIEEE | ||
| 2005 | if( ((pe[0] & 0x7f) != 0) || (pe[1] != 0) ) | ||
| 2006 | { | ||
| 2007 | enan( y, NBITS ); | ||
| 2008 | return; | ||
| 2009 | } | ||
| 2010 | #else | ||
| 2011 | if( ((pe[1] & 0x7f) != 0) || (pe[0] != 0) ) | ||
| 2012 | { | ||
| 2013 | enan( y, NBITS ); | ||
| 2014 | return; | ||
| 2015 | } | ||
| 2016 | #endif | ||
| 2017 | #endif /* NANS */ | ||
| 2018 | eclear( y ); | ||
| 2019 | einfin( y ); | ||
| 2020 | if( yy[0] ) | ||
| 2021 | eneg(y); | ||
| 2022 | return; | ||
| 2023 | } | ||
| 2024 | #endif | ||
| 2025 | r >>= 7; | ||
| 2026 | /* If zero exponent, then the significand is denormalized. | ||
| 2027 | * So, take back the understood high significand bit. */ | ||
| 2028 | if( r == 0 ) | ||
| 2029 | { | ||
| 2030 | denorm = 1; | ||
| 2031 | yy[M] &= ~0200; | ||
| 2032 | } | ||
| 2033 | r += EXONE - 0177; | ||
| 2034 | yy[E] = r; | ||
| 2035 | p = &yy[M+1]; | ||
| 2036 | #ifdef IBMPC | ||
| 2037 | *p++ = *(--e); | ||
| 2038 | #endif | ||
| 2039 | #ifdef DEC | ||
| 2040 | *p++ = *(--e); | ||
| 2041 | #endif | ||
| 2042 | #ifdef MIEEE | ||
| 2043 | ++e; | ||
| 2044 | *p++ = *e++; | ||
| 2045 | #endif | ||
| 2046 | (void )eshift( yy, -8 ); | ||
| 2047 | if( denorm ) | ||
| 2048 | { /* if zero exponent, then normalize the significand */ | ||
| 2049 | if( (k = enormlz(yy)) > NBITS ) | ||
| 2050 | ecleazs(yy); | ||
| 2051 | else | ||
| 2052 | yy[E] -= (unsigned short )(k-1); | ||
| 2053 | } | ||
| 2054 | emovo( yy, y ); | ||
| 2055 | } | ||
| 2056 | |||
| 2057 | void etoe113(x,e) | ||
| 2058 | unsigned short *x, *e; | ||
| 2059 | { | ||
| 2060 | unsigned short xi[NI]; | ||
| 2061 | long exp; | ||
| 2062 | int rndsav; | ||
| 2063 | |||
| 2064 | #ifdef NANS | ||
| 2065 | if( eisnan(x) ) | ||
| 2066 | { | ||
| 2067 | enan( e, 113 ); | ||
| 2068 | return; | ||
| 2069 | } | ||
| 2070 | #endif | ||
| 2071 | emovi( x, xi ); | ||
| 2072 | exp = (long )xi[E]; | ||
| 2073 | #ifdef INFINITY | ||
| 2074 | if( eisinf(x) ) | ||
| 2075 | goto nonorm; | ||
| 2076 | #endif | ||
| 2077 | /* round off to nearest or even */ | ||
| 2078 | rndsav = rndprc; | ||
| 2079 | rndprc = 113; | ||
| 2080 | emdnorm( xi, 0, 0, exp, 64 ); | ||
| 2081 | rndprc = rndsav; | ||
| 2082 | nonorm: | ||
| 2083 | toe113 (xi, e); | ||
| 2084 | } | ||
| 2085 | |||
| 2086 | /* move out internal format to ieee long double */ | ||
| 2087 | static void toe113(a,b) | ||
| 2088 | unsigned short *a, *b; | ||
| 2089 | { | ||
| 2090 | register unsigned short *p, *q; | ||
| 2091 | unsigned short i; | ||
| 2092 | |||
| 2093 | #ifdef NANS | ||
| 2094 | if( eiisnan(a) ) | ||
| 2095 | { | ||
| 2096 | enan( b, 113 ); | ||
| 2097 | return; | ||
| 2098 | } | ||
| 2099 | #endif | ||
| 2100 | p = a; | ||
| 2101 | #ifdef MIEEE | ||
| 2102 | q = b; | ||
| 2103 | #else | ||
| 2104 | q = b + 7; /* point to output exponent */ | ||
| 2105 | #endif | ||
| 2106 | |||
| 2107 | /* If not denormal, delete the implied bit. */ | ||
| 2108 | if( a[E] != 0 ) | ||
| 2109 | { | ||
| 2110 | eshup1 (a); | ||
| 2111 | } | ||
| 2112 | /* combine sign and exponent */ | ||
| 2113 | i = *p++; | ||
| 2114 | #ifdef MIEEE | ||
| 2115 | if( i ) | ||
| 2116 | *q++ = *p++ | 0x8000; | ||
| 2117 | else | ||
| 2118 | *q++ = *p++; | ||
| 2119 | #else | ||
| 2120 | if( i ) | ||
| 2121 | *q-- = *p++ | 0x8000; | ||
| 2122 | else | ||
| 2123 | *q-- = *p++; | ||
| 2124 | #endif | ||
| 2125 | /* skip over guard word */ | ||
| 2126 | ++p; | ||
| 2127 | /* move the significand */ | ||
| 2128 | #ifdef MIEEE | ||
| 2129 | for (i = 0; i < 7; i++) | ||
| 2130 | *q++ = *p++; | ||
| 2131 | #else | ||
| 2132 | for (i = 0; i < 7; i++) | ||
| 2133 | *q-- = *p++; | ||
| 2134 | #endif | ||
| 2135 | } | ||
| 2136 | |||
| 2137 | |||
| 2138 | void etoe64( x, e ) | ||
| 2139 | unsigned short *x, *e; | ||
| 2140 | { | ||
| 2141 | unsigned short xi[NI]; | ||
| 2142 | long exp; | ||
| 2143 | int rndsav; | ||
| 2144 | |||
| 2145 | #ifdef NANS | ||
| 2146 | if( eisnan(x) ) | ||
| 2147 | { | ||
| 2148 | enan( e, 64 ); | ||
| 2149 | return; | ||
| 2150 | } | ||
| 2151 | #endif | ||
| 2152 | emovi( x, xi ); | ||
| 2153 | exp = (long )xi[E]; /* adjust exponent for offset */ | ||
| 2154 | #ifdef INFINITY | ||
| 2155 | if( eisinf(x) ) | ||
| 2156 | goto nonorm; | ||
| 2157 | #endif | ||
| 2158 | /* round off to nearest or even */ | ||
| 2159 | rndsav = rndprc; | ||
| 2160 | rndprc = 64; | ||
| 2161 | emdnorm( xi, 0, 0, exp, 64 ); | ||
| 2162 | rndprc = rndsav; | ||
| 2163 | nonorm: | ||
| 2164 | toe64( xi, e ); | ||
| 2165 | } | ||
| 2166 | |||
| 2167 | /* move out internal format to ieee long double */ | ||
| 2168 | static void toe64( a, b ) | ||
| 2169 | unsigned short *a, *b; | ||
| 2170 | { | ||
| 2171 | register unsigned short *p, *q; | ||
| 2172 | unsigned short i; | ||
| 2173 | |||
| 2174 | #ifdef NANS | ||
| 2175 | if( eiisnan(a) ) | ||
| 2176 | { | ||
| 2177 | enan( b, 64 ); | ||
| 2178 | return; | ||
| 2179 | } | ||
| 2180 | #endif | ||
| 2181 | #ifdef IBMPC | ||
| 2182 | /* Shift Intel denormal significand down 1. */ | ||
| 2183 | if( a[E] == 0 ) | ||
| 2184 | eshdn1(a); | ||
| 2185 | #endif | ||
| 2186 | p = a; | ||
| 2187 | #ifdef MIEEE | ||
| 2188 | q = b; | ||
| 2189 | #else | ||
| 2190 | q = b + 4; /* point to output exponent */ | ||
| 2191 | #if 1 | ||
| 2192 | /* NOTE: if data type is 96 bits wide, clear the last word here. */ | ||
| 2193 | *(q+1)= 0; | ||
| 2194 | #endif | ||
| 2195 | #endif | ||
| 2196 | |||
| 2197 | /* combine sign and exponent */ | ||
| 2198 | i = *p++; | ||
| 2199 | #ifdef MIEEE | ||
| 2200 | if( i ) | ||
| 2201 | *q++ = *p++ | 0x8000; | ||
| 2202 | else | ||
| 2203 | *q++ = *p++; | ||
| 2204 | *q++ = 0; | ||
| 2205 | #else | ||
| 2206 | if( i ) | ||
| 2207 | *q-- = *p++ | 0x8000; | ||
| 2208 | else | ||
| 2209 | *q-- = *p++; | ||
| 2210 | #endif | ||
| 2211 | /* skip over guard word */ | ||
| 2212 | ++p; | ||
| 2213 | /* move the significand */ | ||
| 2214 | #ifdef MIEEE | ||
| 2215 | for( i=0; i<4; i++ ) | ||
| 2216 | *q++ = *p++; | ||
| 2217 | #else | ||
| 2218 | #ifdef INFINITY | ||
| 2219 | if (eiisinf (a)) | ||
| 2220 | { | ||
| 2221 | /* Intel long double infinity. */ | ||
| 2222 | *q-- = 0x8000; | ||
| 2223 | *q-- = 0; | ||
| 2224 | *q-- = 0; | ||
| 2225 | *q = 0; | ||
| 2226 | return; | ||
| 2227 | } | ||
| 2228 | #endif | ||
| 2229 | for( i=0; i<4; i++ ) | ||
| 2230 | *q-- = *p++; | ||
| 2231 | #endif | ||
| 2232 | } | ||
| 2233 | |||
| 2234 | |||
| 2235 | /* | ||
| 2236 | ; e type to IEEE double precision | ||
| 2237 | ; double d; | ||
| 2238 | ; unsigned short x[NE]; | ||
| 2239 | ; etoe53( x, &d ); | ||
| 2240 | */ | ||
| 2241 | |||
| 2242 | #ifdef DEC | ||
| 2243 | |||
| 2244 | void etoe53( x, e ) | ||
| 2245 | unsigned short *x, *e; | ||
| 2246 | { | ||
| 2247 | etodec( x, e ); /* see etodec.c */ | ||
| 2248 | } | ||
| 2249 | |||
| 2250 | static void toe53( x, y ) | ||
| 2251 | unsigned short *x, *y; | ||
| 2252 | { | ||
| 2253 | todec( x, y ); | ||
| 2254 | } | ||
| 2255 | |||
| 2256 | #else | ||
| 2257 | |||
| 2258 | void etoe53( x, e ) | ||
| 2259 | unsigned short *x, *e; | ||
| 2260 | { | ||
| 2261 | unsigned short xi[NI]; | ||
| 2262 | long exp; | ||
| 2263 | int rndsav; | ||
| 2264 | |||
| 2265 | #ifdef NANS | ||
| 2266 | if( eisnan(x) ) | ||
| 2267 | { | ||
| 2268 | enan( e, 53 ); | ||
| 2269 | return; | ||
| 2270 | } | ||
| 2271 | #endif | ||
| 2272 | emovi( x, xi ); | ||
| 2273 | exp = (long )xi[E] - (EXONE - 0x3ff); /* adjust exponent for offsets */ | ||
| 2274 | #ifdef INFINITY | ||
| 2275 | if( eisinf(x) ) | ||
| 2276 | goto nonorm; | ||
| 2277 | #endif | ||
| 2278 | /* round off to nearest or even */ | ||
| 2279 | rndsav = rndprc; | ||
| 2280 | rndprc = 53; | ||
| 2281 | emdnorm( xi, 0, 0, exp, 64 ); | ||
| 2282 | rndprc = rndsav; | ||
| 2283 | nonorm: | ||
| 2284 | toe53( xi, e ); | ||
| 2285 | } | ||
| 2286 | |||
| 2287 | |||
| 2288 | static void toe53( x, y ) | ||
| 2289 | unsigned short *x, *y; | ||
| 2290 | { | ||
| 2291 | unsigned short i; | ||
| 2292 | unsigned short *p; | ||
| 2293 | |||
| 2294 | |||
| 2295 | #ifdef NANS | ||
| 2296 | if( eiisnan(x) ) | ||
| 2297 | { | ||
| 2298 | enan( y, 53 ); | ||
| 2299 | return; | ||
| 2300 | } | ||
| 2301 | #endif | ||
| 2302 | p = &x[0]; | ||
| 2303 | #ifdef IBMPC | ||
| 2304 | y += 3; | ||
| 2305 | #endif | ||
| 2306 | *y = 0; /* output high order */ | ||
| 2307 | if( *p++ ) | ||
| 2308 | *y = 0x8000; /* output sign bit */ | ||
| 2309 | |||
| 2310 | i = *p++; | ||
| 2311 | if( i >= (unsigned int )2047 ) | ||
| 2312 | { /* Saturate at largest number less than infinity. */ | ||
| 2313 | #ifdef INFINITY | ||
| 2314 | *y |= 0x7ff0; | ||
| 2315 | #ifdef IBMPC | ||
| 2316 | *(--y) = 0; | ||
| 2317 | *(--y) = 0; | ||
| 2318 | *(--y) = 0; | ||
| 2319 | #endif | ||
| 2320 | #ifdef MIEEE | ||
| 2321 | ++y; | ||
| 2322 | *y++ = 0; | ||
| 2323 | *y++ = 0; | ||
| 2324 | *y++ = 0; | ||
| 2325 | #endif | ||
| 2326 | #else | ||
| 2327 | *y |= (unsigned short )0x7fef; | ||
| 2328 | #ifdef IBMPC | ||
| 2329 | *(--y) = 0xffff; | ||
| 2330 | *(--y) = 0xffff; | ||
| 2331 | *(--y) = 0xffff; | ||
| 2332 | #endif | ||
| 2333 | #ifdef MIEEE | ||
| 2334 | ++y; | ||
| 2335 | *y++ = 0xffff; | ||
| 2336 | *y++ = 0xffff; | ||
| 2337 | *y++ = 0xffff; | ||
| 2338 | #endif | ||
| 2339 | #endif | ||
| 2340 | return; | ||
| 2341 | } | ||
| 2342 | if( i == 0 ) | ||
| 2343 | { | ||
| 2344 | (void )eshift( x, 4 ); | ||
| 2345 | } | ||
| 2346 | else | ||
| 2347 | { | ||
| 2348 | i <<= 4; | ||
| 2349 | (void )eshift( x, 5 ); | ||
| 2350 | } | ||
| 2351 | i |= *p++ & (unsigned short )0x0f; /* *p = xi[M] */ | ||
| 2352 | *y |= (unsigned short )i; /* high order output already has sign bit set */ | ||
| 2353 | #ifdef IBMPC | ||
| 2354 | *(--y) = *p++; | ||
| 2355 | *(--y) = *p++; | ||
| 2356 | *(--y) = *p; | ||
| 2357 | #endif | ||
| 2358 | #ifdef MIEEE | ||
| 2359 | ++y; | ||
| 2360 | *y++ = *p++; | ||
| 2361 | *y++ = *p++; | ||
| 2362 | *y++ = *p++; | ||
| 2363 | #endif | ||
| 2364 | } | ||
| 2365 | |||
| 2366 | #endif /* not DEC */ | ||
| 2367 | |||
| 2368 | |||
| 2369 | |||
| 2370 | /* | ||
| 2371 | ; e type to IEEE single precision | ||
| 2372 | ; float d; | ||
| 2373 | ; unsigned short x[N+2]; | ||
| 2374 | ; xtod( x, &d ); | ||
| 2375 | */ | ||
| 2376 | void etoe24( x, e ) | ||
| 2377 | unsigned short *x, *e; | ||
| 2378 | { | ||
| 2379 | long exp; | ||
| 2380 | unsigned short xi[NI]; | ||
| 2381 | int rndsav; | ||
| 2382 | |||
| 2383 | #ifdef NANS | ||
| 2384 | if( eisnan(x) ) | ||
| 2385 | { | ||
| 2386 | enan( e, 24 ); | ||
| 2387 | return; | ||
| 2388 | } | ||
| 2389 | #endif | ||
| 2390 | emovi( x, xi ); | ||
| 2391 | exp = (long )xi[E] - (EXONE - 0177); /* adjust exponent for offsets */ | ||
| 2392 | #ifdef INFINITY | ||
| 2393 | if( eisinf(x) ) | ||
| 2394 | goto nonorm; | ||
| 2395 | #endif | ||
| 2396 | /* round off to nearest or even */ | ||
| 2397 | rndsav = rndprc; | ||
| 2398 | rndprc = 24; | ||
| 2399 | emdnorm( xi, 0, 0, exp, 64 ); | ||
| 2400 | rndprc = rndsav; | ||
| 2401 | nonorm: | ||
| 2402 | toe24( xi, e ); | ||
| 2403 | } | ||
| 2404 | |||
| 2405 | static void toe24( x, y ) | ||
| 2406 | unsigned short *x, *y; | ||
| 2407 | { | ||
| 2408 | unsigned short i; | ||
| 2409 | unsigned short *p; | ||
| 2410 | |||
| 2411 | #ifdef NANS | ||
| 2412 | if( eiisnan(x) ) | ||
| 2413 | { | ||
| 2414 | enan( y, 24 ); | ||
| 2415 | return; | ||
| 2416 | } | ||
| 2417 | #endif | ||
| 2418 | p = &x[0]; | ||
| 2419 | #ifdef IBMPC | ||
| 2420 | y += 1; | ||
| 2421 | #endif | ||
| 2422 | #ifdef DEC | ||
| 2423 | y += 1; | ||
| 2424 | #endif | ||
| 2425 | *y = 0; /* output high order */ | ||
| 2426 | if( *p++ ) | ||
| 2427 | *y = 0x8000; /* output sign bit */ | ||
| 2428 | |||
| 2429 | i = *p++; | ||
| 2430 | if( i >= 255 ) | ||
| 2431 | { /* Saturate at largest number less than infinity. */ | ||
| 2432 | #ifdef INFINITY | ||
| 2433 | *y |= (unsigned short )0x7f80; | ||
| 2434 | #ifdef IBMPC | ||
| 2435 | *(--y) = 0; | ||
| 2436 | #endif | ||
| 2437 | #ifdef DEC | ||
| 2438 | *(--y) = 0; | ||
| 2439 | #endif | ||
| 2440 | #ifdef MIEEE | ||
| 2441 | ++y; | ||
| 2442 | *y = 0; | ||
| 2443 | #endif | ||
| 2444 | #else | ||
| 2445 | *y |= (unsigned short )0x7f7f; | ||
| 2446 | #ifdef IBMPC | ||
| 2447 | *(--y) = 0xffff; | ||
| 2448 | #endif | ||
| 2449 | #ifdef DEC | ||
| 2450 | *(--y) = 0xffff; | ||
| 2451 | #endif | ||
| 2452 | #ifdef MIEEE | ||
| 2453 | ++y; | ||
| 2454 | *y = 0xffff; | ||
| 2455 | #endif | ||
| 2456 | #endif | ||
| 2457 | return; | ||
| 2458 | } | ||
| 2459 | if( i == 0 ) | ||
| 2460 | { | ||
| 2461 | (void )eshift( x, 7 ); | ||
| 2462 | } | ||
| 2463 | else | ||
| 2464 | { | ||
| 2465 | i <<= 7; | ||
| 2466 | (void )eshift( x, 8 ); | ||
| 2467 | } | ||
| 2468 | i |= *p++ & (unsigned short )0x7f; /* *p = xi[M] */ | ||
| 2469 | *y |= i; /* high order output already has sign bit set */ | ||
| 2470 | #ifdef IBMPC | ||
| 2471 | *(--y) = *p; | ||
| 2472 | #endif | ||
| 2473 | #ifdef DEC | ||
| 2474 | *(--y) = *p; | ||
| 2475 | #endif | ||
| 2476 | #ifdef MIEEE | ||
| 2477 | ++y; | ||
| 2478 | *y = *p; | ||
| 2479 | #endif | ||
| 2480 | } | ||
| 2481 | |||
| 2482 | |||
| 2483 | /* Compare two e type numbers. | ||
| 2484 | * | ||
| 2485 | * unsigned short a[NE], b[NE]; | ||
| 2486 | * ecmp( a, b ); | ||
| 2487 | * | ||
| 2488 | * returns +1 if a > b | ||
| 2489 | * 0 if a == b | ||
| 2490 | * -1 if a < b | ||
| 2491 | * -2 if either a or b is a NaN. | ||
| 2492 | */ | ||
| 2493 | int ecmp( a, b ) | ||
| 2494 | unsigned short *a, *b; | ||
| 2495 | { | ||
| 2496 | unsigned short ai[NI], bi[NI]; | ||
| 2497 | register unsigned short *p, *q; | ||
| 2498 | register int i; | ||
| 2499 | int msign; | ||
| 2500 | |||
| 2501 | #ifdef NANS | ||
| 2502 | if (eisnan (a) || eisnan (b)) | ||
| 2503 | return( -2 ); | ||
| 2504 | #endif | ||
| 2505 | emovi( a, ai ); | ||
| 2506 | p = ai; | ||
| 2507 | emovi( b, bi ); | ||
| 2508 | q = bi; | ||
| 2509 | |||
| 2510 | if( *p != *q ) | ||
| 2511 | { /* the signs are different */ | ||
| 2512 | /* -0 equals + 0 */ | ||
| 2513 | for( i=1; i<NI-1; i++ ) | ||
| 2514 | { | ||
| 2515 | if( ai[i] != 0 ) | ||
| 2516 | goto nzro; | ||
| 2517 | if( bi[i] != 0 ) | ||
| 2518 | goto nzro; | ||
| 2519 | } | ||
| 2520 | return(0); | ||
| 2521 | nzro: | ||
| 2522 | if( *p == 0 ) | ||
| 2523 | return( 1 ); | ||
| 2524 | else | ||
| 2525 | return( -1 ); | ||
| 2526 | } | ||
| 2527 | /* both are the same sign */ | ||
| 2528 | if( *p == 0 ) | ||
| 2529 | msign = 1; | ||
| 2530 | else | ||
| 2531 | msign = -1; | ||
| 2532 | i = NI-1; | ||
| 2533 | do | ||
| 2534 | { | ||
| 2535 | if( *p++ != *q++ ) | ||
| 2536 | { | ||
| 2537 | goto diff; | ||
| 2538 | } | ||
| 2539 | } | ||
| 2540 | while( --i > 0 ); | ||
| 2541 | |||
| 2542 | return(0); /* equality */ | ||
| 2543 | |||
| 2544 | |||
| 2545 | |||
| 2546 | diff: | ||
| 2547 | |||
| 2548 | if( *(--p) > *(--q) ) | ||
| 2549 | return( msign ); /* p is bigger */ | ||
| 2550 | else | ||
| 2551 | return( -msign ); /* p is littler */ | ||
| 2552 | } | ||
| 2553 | |||
| 2554 | |||
| 2555 | |||
| 2556 | |||
| 2557 | /* Find nearest integer to x = floor( x + 0.5 ) | ||
| 2558 | * | ||
| 2559 | * unsigned short x[NE], y[NE] | ||
| 2560 | * eround( x, y ); | ||
| 2561 | */ | ||
| 2562 | void eround( x, y ) | ||
| 2563 | unsigned short *x, *y; | ||
| 2564 | { | ||
| 2565 | |||
| 2566 | eadd( ehalf, x, y ); | ||
| 2567 | efloor( y, y ); | ||
| 2568 | } | ||
| 2569 | |||
| 2570 | |||
| 2571 | |||
| 2572 | |||
| 2573 | /* | ||
| 2574 | ; convert long (32-bit) integer to e type | ||
| 2575 | ; | ||
| 2576 | ; long l; | ||
| 2577 | ; unsigned short x[NE]; | ||
| 2578 | ; ltoe( &l, x ); | ||
| 2579 | ; note &l is the memory address of l | ||
| 2580 | */ | ||
| 2581 | void ltoe( lp, y ) | ||
| 2582 | long *lp; /* lp is the memory address of a long integer */ | ||
| 2583 | unsigned short *y; /* y is the address of a short */ | ||
| 2584 | { | ||
| 2585 | unsigned short yi[NI]; | ||
| 2586 | unsigned long ll; | ||
| 2587 | int k; | ||
| 2588 | |||
| 2589 | ecleaz( yi ); | ||
| 2590 | if( *lp < 0 ) | ||
| 2591 | { | ||
| 2592 | ll = (unsigned long )( -(*lp) ); /* make it positive */ | ||
| 2593 | yi[0] = 0xffff; /* put correct sign in the e type number */ | ||
| 2594 | } | ||
| 2595 | else | ||
| 2596 | { | ||
| 2597 | ll = (unsigned long )( *lp ); | ||
| 2598 | } | ||
| 2599 | /* move the long integer to yi significand area */ | ||
| 2600 | if( sizeof(long) == 8 ) | ||
| 2601 | { | ||
| 2602 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
| 2603 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
| 2604 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
| 2605 | yi[M + 3] = (unsigned short) ll; | ||
| 2606 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
| 2607 | } | ||
| 2608 | else | ||
| 2609 | { | ||
| 2610 | yi[M] = (unsigned short )(ll >> 16); | ||
| 2611 | yi[M+1] = (unsigned short )ll; | ||
| 2612 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
| 2613 | } | ||
| 2614 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
| 2615 | ecleaz( yi ); /* it was zero */ | ||
| 2616 | else | ||
| 2617 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
| 2618 | emovo( yi, y ); /* output the answer */ | ||
| 2619 | } | ||
| 2620 | |||
| 2621 | /* | ||
| 2622 | ; convert unsigned long (32-bit) integer to e type | ||
| 2623 | ; | ||
| 2624 | ; unsigned long l; | ||
| 2625 | ; unsigned short x[NE]; | ||
| 2626 | ; ltox( &l, x ); | ||
| 2627 | ; note &l is the memory address of l | ||
| 2628 | */ | ||
| 2629 | void ultoe( lp, y ) | ||
| 2630 | unsigned long *lp; /* lp is the memory address of a long integer */ | ||
| 2631 | unsigned short *y; /* y is the address of a short */ | ||
| 2632 | { | ||
| 2633 | unsigned short yi[NI]; | ||
| 2634 | unsigned long ll; | ||
| 2635 | int k; | ||
| 2636 | |||
| 2637 | ecleaz( yi ); | ||
| 2638 | ll = *lp; | ||
| 2639 | |||
| 2640 | /* move the long integer to ayi significand area */ | ||
| 2641 | if( sizeof(long) == 8 ) | ||
| 2642 | { | ||
| 2643 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
| 2644 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
| 2645 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
| 2646 | yi[M + 3] = (unsigned short) ll; | ||
| 2647 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
| 2648 | } | ||
| 2649 | else | ||
| 2650 | { | ||
| 2651 | yi[M] = (unsigned short )(ll >> 16); | ||
| 2652 | yi[M+1] = (unsigned short )ll; | ||
| 2653 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
| 2654 | } | ||
| 2655 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
| 2656 | ecleaz( yi ); /* it was zero */ | ||
| 2657 | else | ||
| 2658 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
| 2659 | emovo( yi, y ); /* output the answer */ | ||
| 2660 | } | ||
| 2661 | |||
| 2662 | |||
| 2663 | /* | ||
| 2664 | ; Find long integer and fractional parts | ||
| 2665 | |||
| 2666 | ; long i; | ||
| 2667 | ; unsigned short x[NE], frac[NE]; | ||
| 2668 | ; xifrac( x, &i, frac ); | ||
| 2669 | |||
| 2670 | The integer output has the sign of the input. The fraction is | ||
| 2671 | the positive fractional part of abs(x). | ||
| 2672 | */ | ||
| 2673 | void eifrac( x, i, frac ) | ||
| 2674 | unsigned short *x; | ||
| 2675 | long *i; | ||
| 2676 | unsigned short *frac; | ||
| 2677 | { | ||
| 2678 | unsigned short xi[NI]; | ||
| 2679 | int j, k; | ||
| 2680 | unsigned long ll; | ||
| 2681 | |||
| 2682 | emovi( x, xi ); | ||
| 2683 | k = (int )xi[E] - (EXONE - 1); | ||
| 2684 | if( k <= 0 ) | ||
| 2685 | { | ||
| 2686 | /* if exponent <= 0, integer = 0 and real output is fraction */ | ||
| 2687 | *i = 0L; | ||
| 2688 | emovo( xi, frac ); | ||
| 2689 | return; | ||
| 2690 | } | ||
| 2691 | if( k > (8 * sizeof(long) - 1) ) | ||
| 2692 | { | ||
| 2693 | /* | ||
| 2694 | ; long integer overflow: output large integer | ||
| 2695 | ; and correct fraction | ||
| 2696 | */ | ||
| 2697 | j = 8 * sizeof(long) - 1; | ||
| 2698 | if( xi[0] ) | ||
| 2699 | *i = (long) ((unsigned long) 1) << j; | ||
| 2700 | else | ||
| 2701 | *i = (long) (((unsigned long) (~(0L))) >> 1); | ||
| 2702 | (void )eshift( xi, k ); | ||
| 2703 | } | ||
| 2704 | if( k > 16 ) | ||
| 2705 | { | ||
| 2706 | /* | ||
| 2707 | Shift more than 16 bits: shift up k-16 mod 16 | ||
| 2708 | then shift by 16's. | ||
| 2709 | */ | ||
| 2710 | j = k - ((k >> 4) << 4); | ||
| 2711 | eshift (xi, j); | ||
| 2712 | ll = xi[M]; | ||
| 2713 | k -= j; | ||
| 2714 | do | ||
| 2715 | { | ||
| 2716 | eshup6 (xi); | ||
| 2717 | ll = (ll << 16) | xi[M]; | ||
| 2718 | } | ||
| 2719 | while ((k -= 16) > 0); | ||
| 2720 | *i = ll; | ||
| 2721 | if (xi[0]) | ||
| 2722 | *i = -(*i); | ||
| 2723 | } | ||
| 2724 | else | ||
| 2725 | { | ||
| 2726 | /* shift not more than 16 bits */ | ||
| 2727 | eshift( xi, k ); | ||
| 2728 | *i = (long )xi[M] & 0xffff; | ||
| 2729 | if( xi[0] ) | ||
| 2730 | *i = -(*i); | ||
| 2731 | } | ||
| 2732 | xi[0] = 0; | ||
| 2733 | xi[E] = EXONE - 1; | ||
| 2734 | xi[M] = 0; | ||
| 2735 | if( (k = enormlz( xi )) > NBITS ) | ||
| 2736 | ecleaz( xi ); | ||
| 2737 | else | ||
| 2738 | xi[E] -= (unsigned short )k; | ||
| 2739 | |||
| 2740 | emovo( xi, frac ); | ||
| 2741 | } | ||
| 2742 | |||
| 2743 | |||
| 2744 | /* | ||
| 2745 | ; Find unsigned long integer and fractional parts | ||
| 2746 | |||
| 2747 | ; unsigned long i; | ||
| 2748 | ; unsigned short x[NE], frac[NE]; | ||
| 2749 | ; xifrac( x, &i, frac ); | ||
| 2750 | |||
| 2751 | A negative e type input yields integer output = 0 | ||
| 2752 | but correct fraction. | ||
| 2753 | */ | ||
| 2754 | void euifrac( x, i, frac ) | ||
| 2755 | unsigned short *x; | ||
| 2756 | unsigned long *i; | ||
| 2757 | unsigned short *frac; | ||
| 2758 | { | ||
| 2759 | unsigned short xi[NI]; | ||
| 2760 | int j, k; | ||
| 2761 | unsigned long ll; | ||
| 2762 | |||
| 2763 | emovi( x, xi ); | ||
| 2764 | k = (int )xi[E] - (EXONE - 1); | ||
| 2765 | if( k <= 0 ) | ||
| 2766 | { | ||
| 2767 | /* if exponent <= 0, integer = 0 and argument is fraction */ | ||
| 2768 | *i = 0L; | ||
| 2769 | emovo( xi, frac ); | ||
| 2770 | return; | ||
| 2771 | } | ||
| 2772 | if( k > (8 * sizeof(long)) ) | ||
| 2773 | { | ||
| 2774 | /* | ||
| 2775 | ; long integer overflow: output large integer | ||
| 2776 | ; and correct fraction | ||
| 2777 | */ | ||
| 2778 | *i = ~(0L); | ||
| 2779 | (void )eshift( xi, k ); | ||
| 2780 | } | ||
| 2781 | else if( k > 16 ) | ||
| 2782 | { | ||
| 2783 | /* | ||
| 2784 | Shift more than 16 bits: shift up k-16 mod 16 | ||
| 2785 | then shift up by 16's. | ||
| 2786 | */ | ||
| 2787 | j = k - ((k >> 4) << 4); | ||
| 2788 | eshift (xi, j); | ||
| 2789 | ll = xi[M]; | ||
| 2790 | k -= j; | ||
| 2791 | do | ||
| 2792 | { | ||
| 2793 | eshup6 (xi); | ||
| 2794 | ll = (ll << 16) | xi[M]; | ||
| 2795 | } | ||
| 2796 | while ((k -= 16) > 0); | ||
| 2797 | *i = ll; | ||
| 2798 | } | ||
| 2799 | else | ||
| 2800 | { | ||
| 2801 | /* shift not more than 16 bits */ | ||
| 2802 | eshift( xi, k ); | ||
| 2803 | *i = (long )xi[M] & 0xffff; | ||
| 2804 | } | ||
| 2805 | |||
| 2806 | if( xi[0] ) /* A negative value yields unsigned integer 0. */ | ||
| 2807 | *i = 0L; | ||
| 2808 | |||
| 2809 | xi[0] = 0; | ||
| 2810 | xi[E] = EXONE - 1; | ||
| 2811 | xi[M] = 0; | ||
| 2812 | if( (k = enormlz( xi )) > NBITS ) | ||
| 2813 | ecleaz( xi ); | ||
| 2814 | else | ||
| 2815 | xi[E] -= (unsigned short )k; | ||
| 2816 | |||
| 2817 | emovo( xi, frac ); | ||
| 2818 | } | ||
| 2819 | |||
| 2820 | |||
| 2821 | |||
| 2822 | /* | ||
| 2823 | ; Shift significand | ||
| 2824 | ; | ||
| 2825 | ; Shifts significand area up or down by the number of bits | ||
| 2826 | ; given by the variable sc. | ||
| 2827 | */ | ||
| 2828 | int eshift( x, sc ) | ||
| 2829 | unsigned short *x; | ||
| 2830 | int sc; | ||
| 2831 | { | ||
| 2832 | unsigned short lost; | ||
| 2833 | unsigned short *p; | ||
| 2834 | |||
| 2835 | if( sc == 0 ) | ||
| 2836 | return( 0 ); | ||
| 2837 | |||
| 2838 | lost = 0; | ||
| 2839 | p = x + NI-1; | ||
| 2840 | |||
| 2841 | if( sc < 0 ) | ||
| 2842 | { | ||
| 2843 | sc = -sc; | ||
| 2844 | while( sc >= 16 ) | ||
| 2845 | { | ||
| 2846 | lost |= *p; /* remember lost bits */ | ||
| 2847 | eshdn6(x); | ||
| 2848 | sc -= 16; | ||
| 2849 | } | ||
| 2850 | |||
| 2851 | while( sc >= 8 ) | ||
| 2852 | { | ||
| 2853 | lost |= *p & 0xff; | ||
| 2854 | eshdn8(x); | ||
| 2855 | sc -= 8; | ||
| 2856 | } | ||
| 2857 | |||
| 2858 | while( sc > 0 ) | ||
| 2859 | { | ||
| 2860 | lost |= *p & 1; | ||
| 2861 | eshdn1(x); | ||
| 2862 | sc -= 1; | ||
| 2863 | } | ||
| 2864 | } | ||
| 2865 | else | ||
| 2866 | { | ||
| 2867 | while( sc >= 16 ) | ||
| 2868 | { | ||
| 2869 | eshup6(x); | ||
| 2870 | sc -= 16; | ||
| 2871 | } | ||
| 2872 | |||
| 2873 | while( sc >= 8 ) | ||
| 2874 | { | ||
| 2875 | eshup8(x); | ||
| 2876 | sc -= 8; | ||
| 2877 | } | ||
| 2878 | |||
| 2879 | while( sc > 0 ) | ||
| 2880 | { | ||
| 2881 | eshup1(x); | ||
| 2882 | sc -= 1; | ||
| 2883 | } | ||
| 2884 | } | ||
| 2885 | if( lost ) | ||
| 2886 | lost = 1; | ||
| 2887 | return( (int )lost ); | ||
| 2888 | } | ||
| 2889 | |||
| 2890 | |||
| 2891 | |||
| 2892 | /* | ||
| 2893 | ; normalize | ||
| 2894 | ; | ||
| 2895 | ; Shift normalizes the significand area pointed to by argument | ||
| 2896 | ; shift count (up = positive) is returned. | ||
| 2897 | */ | ||
| 2898 | int enormlz(x) | ||
| 2899 | unsigned short x[]; | ||
| 2900 | { | ||
| 2901 | register unsigned short *p; | ||
| 2902 | int sc; | ||
| 2903 | |||
| 2904 | sc = 0; | ||
| 2905 | p = &x[M]; | ||
| 2906 | if( *p != 0 ) | ||
| 2907 | goto normdn; | ||
| 2908 | ++p; | ||
| 2909 | if( *p & 0x8000 ) | ||
| 2910 | return( 0 ); /* already normalized */ | ||
| 2911 | while( *p == 0 ) | ||
| 2912 | { | ||
| 2913 | eshup6(x); | ||
| 2914 | sc += 16; | ||
| 2915 | /* With guard word, there are NBITS+16 bits available. | ||
| 2916 | * return true if all are zero. | ||
| 2917 | */ | ||
| 2918 | if( sc > NBITS ) | ||
| 2919 | return( sc ); | ||
| 2920 | } | ||
| 2921 | /* see if high byte is zero */ | ||
| 2922 | while( (*p & 0xff00) == 0 ) | ||
| 2923 | { | ||
| 2924 | eshup8(x); | ||
| 2925 | sc += 8; | ||
| 2926 | } | ||
| 2927 | /* now shift 1 bit at a time */ | ||
| 2928 | while( (*p & 0x8000) == 0) | ||
| 2929 | { | ||
| 2930 | eshup1(x); | ||
| 2931 | sc += 1; | ||
| 2932 | if( sc > (NBITS+16) ) | ||
| 2933 | { | ||
| 2934 | mtherr( "enormlz", UNDERFLOW ); | ||
| 2935 | return( sc ); | ||
| 2936 | } | ||
| 2937 | } | ||
| 2938 | return( sc ); | ||
| 2939 | |||
| 2940 | /* Normalize by shifting down out of the high guard word | ||
| 2941 | of the significand */ | ||
| 2942 | normdn: | ||
| 2943 | |||
| 2944 | if( *p & 0xff00 ) | ||
| 2945 | { | ||
| 2946 | eshdn8(x); | ||
| 2947 | sc -= 8; | ||
| 2948 | } | ||
| 2949 | while( *p != 0 ) | ||
| 2950 | { | ||
| 2951 | eshdn1(x); | ||
| 2952 | sc -= 1; | ||
| 2953 | |||
| 2954 | if( sc < -NBITS ) | ||
| 2955 | { | ||
| 2956 | mtherr( "enormlz", OVERFLOW ); | ||
| 2957 | return( sc ); | ||
| 2958 | } | ||
| 2959 | } | ||
| 2960 | return( sc ); | ||
| 2961 | } | ||
| 2962 | |||
| 2963 | |||
| 2964 | |||
| 2965 | |||
| 2966 | /* Convert e type number to decimal format ASCII string. | ||
| 2967 | * The constants are for 64 bit precision. | ||
| 2968 | */ | ||
| 2969 | |||
| 2970 | #define NTEN 12 | ||
| 2971 | #define MAXP 4096 | ||
| 2972 | |||
| 2973 | #if NE == 10 | ||
| 2974 | static unsigned short etens[NTEN + 1][NE] = | ||
| 2975 | { | ||
| 2976 | {0x6576, 0x4a92, 0x804a, 0x153f, | ||
| 2977 | 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */ | ||
| 2978 | {0x6a32, 0xce52, 0x329a, 0x28ce, | ||
| 2979 | 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */ | ||
| 2980 | {0x526c, 0x50ce, 0xf18b, 0x3d28, | ||
| 2981 | 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,}, | ||
| 2982 | {0x9c66, 0x58f8, 0xbc50, 0x5c54, | ||
| 2983 | 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,}, | ||
| 2984 | {0x851e, 0xeab7, 0x98fe, 0x901b, | ||
| 2985 | 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,}, | ||
| 2986 | {0x0235, 0x0137, 0x36b1, 0x336c, | ||
| 2987 | 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,}, | ||
| 2988 | {0x50f8, 0x25fb, 0xc76b, 0x6b71, | ||
| 2989 | 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,}, | ||
| 2990 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 2991 | 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,}, | ||
| 2992 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 2993 | 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,}, | ||
| 2994 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 2995 | 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,}, | ||
| 2996 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 2997 | 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,}, | ||
| 2998 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 2999 | 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,}, | ||
| 3000 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
| 3001 | 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */ | ||
| 3002 | }; | ||
| 3003 | |||
| 3004 | static unsigned short emtens[NTEN + 1][NE] = | ||
| 3005 | { | ||
| 3006 | {0x2030, 0xcffc, 0xa1c3, 0x8123, | ||
| 3007 | 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */ | ||
| 3008 | {0x8264, 0xd2cb, 0xf2ea, 0x12d4, | ||
| 3009 | 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */ | ||
| 3010 | {0xf53f, 0xf698, 0x6bd3, 0x0158, | ||
| 3011 | 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,}, | ||
| 3012 | {0xe731, 0x04d4, 0xe3f2, 0xd332, | ||
| 3013 | 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,}, | ||
| 3014 | {0xa23e, 0x5308, 0xfefb, 0x1155, | ||
| 3015 | 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,}, | ||
| 3016 | {0xe26d, 0xdbde, 0xd05d, 0xb3f6, | ||
| 3017 | 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,}, | ||
| 3018 | {0x2a20, 0x6224, 0x47b3, 0x98d7, | ||
| 3019 | 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,}, | ||
| 3020 | {0x0b5b, 0x4af2, 0xa581, 0x18ed, | ||
| 3021 | 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,}, | ||
| 3022 | {0xbf71, 0xa9b3, 0x7989, 0xbe68, | ||
| 3023 | 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,}, | ||
| 3024 | {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b, | ||
| 3025 | 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,}, | ||
| 3026 | {0xc155, 0xa4a8, 0x404e, 0x6113, | ||
| 3027 | 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,}, | ||
| 3028 | {0xd70a, 0x70a3, 0x0a3d, 0xa3d7, | ||
| 3029 | 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,}, | ||
| 3030 | {0xcccd, 0xcccc, 0xcccc, 0xcccc, | ||
| 3031 | 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */ | ||
| 3032 | }; | ||
| 3033 | #else | ||
| 3034 | static unsigned short etens[NTEN+1][NE] = { | ||
| 3035 | {0xc94c,0x979a,0x8a20,0x5202,0xc460,0x7525,},/* 10**4096 */ | ||
| 3036 | {0xa74d,0x5de4,0xc53d,0x3b5d,0x9e8b,0x5a92,},/* 10**2048 */ | ||
| 3037 | {0x650d,0x0c17,0x8175,0x7586,0xc976,0x4d48,}, | ||
| 3038 | {0xcc65,0x91c6,0xa60e,0xa0ae,0xe319,0x46a3,}, | ||
| 3039 | {0xddbc,0xde8d,0x9df9,0xebfb,0xaa7e,0x4351,}, | ||
| 3040 | {0xc66f,0x8cdf,0x80e9,0x47c9,0x93ba,0x41a8,}, | ||
| 3041 | {0x3cbf,0xa6d5,0xffcf,0x1f49,0xc278,0x40d3,}, | ||
| 3042 | {0xf020,0xb59d,0x2b70,0xada8,0x9dc5,0x4069,}, | ||
| 3043 | {0x0000,0x0000,0x0400,0xc9bf,0x8e1b,0x4034,}, | ||
| 3044 | {0x0000,0x0000,0x0000,0x2000,0xbebc,0x4019,}, | ||
| 3045 | {0x0000,0x0000,0x0000,0x0000,0x9c40,0x400c,}, | ||
| 3046 | {0x0000,0x0000,0x0000,0x0000,0xc800,0x4005,}, | ||
| 3047 | {0x0000,0x0000,0x0000,0x0000,0xa000,0x4002,}, /* 10**1 */ | ||
| 3048 | }; | ||
| 3049 | |||
| 3050 | static unsigned short emtens[NTEN+1][NE] = { | ||
| 3051 | {0x2de4,0x9fde,0xd2ce,0x04c8,0xa6dd,0x0ad8,}, /* 10**-4096 */ | ||
| 3052 | {0x4925,0x2de4,0x3436,0x534f,0xceae,0x256b,}, /* 10**-2048 */ | ||
| 3053 | {0x87a6,0xc0bd,0xda57,0x82a5,0xa2a6,0x32b5,}, | ||
| 3054 | {0x7133,0xd21c,0xdb23,0xee32,0x9049,0x395a,}, | ||
| 3055 | {0xfa91,0x1939,0x637a,0x4325,0xc031,0x3cac,}, | ||
| 3056 | {0xac7d,0xe4a0,0x64bc,0x467c,0xddd0,0x3e55,}, | ||
| 3057 | {0x3f24,0xe9a5,0xa539,0xea27,0xa87f,0x3f2a,}, | ||
| 3058 | {0x67de,0x94ba,0x4539,0x1ead,0xcfb1,0x3f94,}, | ||
| 3059 | {0x4c2f,0xe15b,0xc44d,0x94be,0xe695,0x3fc9,}, | ||
| 3060 | {0xfdc2,0xcefc,0x8461,0x7711,0xabcc,0x3fe4,}, | ||
| 3061 | {0xd3c3,0x652b,0xe219,0x1758,0xd1b7,0x3ff1,}, | ||
| 3062 | {0x3d71,0xd70a,0x70a3,0x0a3d,0xa3d7,0x3ff8,}, | ||
| 3063 | {0xcccd,0xcccc,0xcccc,0xcccc,0xcccc,0x3ffb,}, /* 10**-1 */ | ||
| 3064 | }; | ||
| 3065 | #endif | ||
| 3066 | |||
| 3067 | void e24toasc( x, string, ndigs ) | ||
| 3068 | unsigned short x[]; | ||
| 3069 | char *string; | ||
| 3070 | int ndigs; | ||
| 3071 | { | ||
| 3072 | unsigned short w[NI]; | ||
| 3073 | |||
| 3074 | e24toe( x, w ); | ||
| 3075 | etoasc( w, string, ndigs ); | ||
| 3076 | } | ||
| 3077 | |||
| 3078 | |||
| 3079 | void e53toasc( x, string, ndigs ) | ||
| 3080 | unsigned short x[]; | ||
| 3081 | char *string; | ||
| 3082 | int ndigs; | ||
| 3083 | { | ||
| 3084 | unsigned short w[NI]; | ||
| 3085 | |||
| 3086 | e53toe( x, w ); | ||
| 3087 | etoasc( w, string, ndigs ); | ||
| 3088 | } | ||
| 3089 | |||
| 3090 | |||
| 3091 | void e64toasc( x, string, ndigs ) | ||
| 3092 | unsigned short x[]; | ||
| 3093 | char *string; | ||
| 3094 | int ndigs; | ||
| 3095 | { | ||
| 3096 | unsigned short w[NI]; | ||
| 3097 | |||
| 3098 | e64toe( x, w ); | ||
| 3099 | etoasc( w, string, ndigs ); | ||
| 3100 | } | ||
| 3101 | |||
| 3102 | void e113toasc (x, string, ndigs) | ||
| 3103 | unsigned short x[]; | ||
| 3104 | char *string; | ||
| 3105 | int ndigs; | ||
| 3106 | { | ||
| 3107 | unsigned short w[NI]; | ||
| 3108 | |||
| 3109 | e113toe (x, w); | ||
| 3110 | etoasc (w, string, ndigs); | ||
| 3111 | } | ||
| 3112 | |||
| 3113 | |||
| 3114 | void etoasc( x, string, ndigs ) | ||
| 3115 | unsigned short x[]; | ||
| 3116 | char *string; | ||
| 3117 | int ndigs; | ||
| 3118 | { | ||
| 3119 | long digit; | ||
| 3120 | unsigned short y[NI], t[NI], u[NI], w[NI]; | ||
| 3121 | unsigned short *p, *r, *ten; | ||
| 3122 | unsigned short sign; | ||
| 3123 | int i, j, k, expon, rndsav; | ||
| 3124 | char *s, *ss; | ||
| 3125 | unsigned short m; | ||
| 3126 | |||
| 3127 | rndsav = rndprc; | ||
| 3128 | #ifdef NANS | ||
| 3129 | if( eisnan(x) ) | ||
| 3130 | { | ||
| 3131 | sprintf( string, " NaN " ); | ||
| 3132 | goto bxit; | ||
| 3133 | } | ||
| 3134 | #endif | ||
| 3135 | rndprc = NBITS; /* set to full precision */ | ||
| 3136 | emov( x, y ); /* retain external format */ | ||
| 3137 | if( y[NE-1] & 0x8000 ) | ||
| 3138 | { | ||
| 3139 | sign = 0xffff; | ||
| 3140 | y[NE-1] &= 0x7fff; | ||
| 3141 | } | ||
| 3142 | else | ||
| 3143 | { | ||
| 3144 | sign = 0; | ||
| 3145 | } | ||
| 3146 | expon = 0; | ||
| 3147 | ten = &etens[NTEN][0]; | ||
| 3148 | emov( eone, t ); | ||
| 3149 | /* Test for zero exponent */ | ||
| 3150 | if( y[NE-1] == 0 ) | ||
| 3151 | { | ||
| 3152 | for( k=0; k<NE-1; k++ ) | ||
| 3153 | { | ||
| 3154 | if( y[k] != 0 ) | ||
| 3155 | goto tnzro; /* denormalized number */ | ||
| 3156 | } | ||
| 3157 | goto isone; /* legal all zeros */ | ||
| 3158 | } | ||
| 3159 | tnzro: | ||
| 3160 | |||
| 3161 | /* Test for infinity. | ||
| 3162 | */ | ||
| 3163 | if( y[NE-1] == 0x7fff ) | ||
| 3164 | { | ||
| 3165 | if( sign ) | ||
| 3166 | sprintf( string, " -Infinity " ); | ||
| 3167 | else | ||
| 3168 | sprintf( string, " Infinity " ); | ||
| 3169 | goto bxit; | ||
| 3170 | } | ||
| 3171 | |||
| 3172 | /* Test for exponent nonzero but significand denormalized. | ||
| 3173 | * This is an error condition. | ||
| 3174 | */ | ||
| 3175 | if( (y[NE-1] != 0) && ((y[NE-2] & 0x8000) == 0) ) | ||
| 3176 | { | ||
| 3177 | mtherr( "etoasc", DOMAIN ); | ||
| 3178 | sprintf( string, "NaN" ); | ||
| 3179 | goto bxit; | ||
| 3180 | } | ||
| 3181 | |||
| 3182 | /* Compare to 1.0 */ | ||
| 3183 | i = ecmp( eone, y ); | ||
| 3184 | if( i == 0 ) | ||
| 3185 | goto isone; | ||
| 3186 | |||
| 3187 | if( i < 0 ) | ||
| 3188 | { /* Number is greater than 1 */ | ||
| 3189 | /* Convert significand to an integer and strip trailing decimal zeros. */ | ||
| 3190 | emov( y, u ); | ||
| 3191 | u[NE-1] = EXONE + NBITS - 1; | ||
| 3192 | |||
| 3193 | p = &etens[NTEN-4][0]; | ||
| 3194 | m = 16; | ||
| 3195 | do | ||
| 3196 | { | ||
| 3197 | ediv( p, u, t ); | ||
| 3198 | efloor( t, w ); | ||
| 3199 | for( j=0; j<NE-1; j++ ) | ||
| 3200 | { | ||
| 3201 | if( t[j] != w[j] ) | ||
| 3202 | goto noint; | ||
| 3203 | } | ||
| 3204 | emov( t, u ); | ||
| 3205 | expon += (int )m; | ||
| 3206 | noint: | ||
| 3207 | p += NE; | ||
| 3208 | m >>= 1; | ||
| 3209 | } | ||
| 3210 | while( m != 0 ); | ||
| 3211 | |||
| 3212 | /* Rescale from integer significand */ | ||
| 3213 | u[NE-1] += y[NE-1] - (unsigned int )(EXONE + NBITS - 1); | ||
| 3214 | emov( u, y ); | ||
| 3215 | /* Find power of 10 */ | ||
| 3216 | emov( eone, t ); | ||
| 3217 | m = MAXP; | ||
| 3218 | p = &etens[0][0]; | ||
| 3219 | while( ecmp( ten, u ) <= 0 ) | ||
| 3220 | { | ||
| 3221 | if( ecmp( p, u ) <= 0 ) | ||
| 3222 | { | ||
| 3223 | ediv( p, u, u ); | ||
| 3224 | emul( p, t, t ); | ||
| 3225 | expon += (int )m; | ||
| 3226 | } | ||
| 3227 | m >>= 1; | ||
| 3228 | if( m == 0 ) | ||
| 3229 | break; | ||
| 3230 | p += NE; | ||
| 3231 | } | ||
| 3232 | } | ||
| 3233 | else | ||
| 3234 | { /* Number is less than 1.0 */ | ||
| 3235 | /* Pad significand with trailing decimal zeros. */ | ||
| 3236 | if( y[NE-1] == 0 ) | ||
| 3237 | { | ||
| 3238 | while( (y[NE-2] & 0x8000) == 0 ) | ||
| 3239 | { | ||
| 3240 | emul( ten, y, y ); | ||
| 3241 | expon -= 1; | ||
| 3242 | } | ||
| 3243 | } | ||
| 3244 | else | ||
| 3245 | { | ||
| 3246 | emovi( y, w ); | ||
| 3247 | for( i=0; i<NDEC+1; i++ ) | ||
| 3248 | { | ||
| 3249 | if( (w[NI-1] & 0x7) != 0 ) | ||
| 3250 | break; | ||
| 3251 | /* multiply by 10 */ | ||
| 3252 | emovz( w, u ); | ||
| 3253 | eshdn1( u ); | ||
| 3254 | eshdn1( u ); | ||
| 3255 | eaddm( w, u ); | ||
| 3256 | u[1] += 3; | ||
| 3257 | while( u[2] != 0 ) | ||
| 3258 | { | ||
| 3259 | eshdn1(u); | ||
| 3260 | u[1] += 1; | ||
| 3261 | } | ||
| 3262 | if( u[NI-1] != 0 ) | ||
| 3263 | break; | ||
| 3264 | if( eone[NE-1] <= u[1] ) | ||
| 3265 | break; | ||
| 3266 | emovz( u, w ); | ||
| 3267 | expon -= 1; | ||
| 3268 | } | ||
| 3269 | emovo( w, y ); | ||
| 3270 | } | ||
| 3271 | k = -MAXP; | ||
| 3272 | p = &emtens[0][0]; | ||
| 3273 | r = &etens[0][0]; | ||
| 3274 | emov( y, w ); | ||
| 3275 | emov( eone, t ); | ||
| 3276 | while( ecmp( eone, w ) > 0 ) | ||
| 3277 | { | ||
| 3278 | if( ecmp( p, w ) >= 0 ) | ||
| 3279 | { | ||
| 3280 | emul( r, w, w ); | ||
| 3281 | emul( r, t, t ); | ||
| 3282 | expon += k; | ||
| 3283 | } | ||
| 3284 | k /= 2; | ||
| 3285 | if( k == 0 ) | ||
| 3286 | break; | ||
| 3287 | p += NE; | ||
| 3288 | r += NE; | ||
| 3289 | } | ||
| 3290 | ediv( t, eone, t ); | ||
| 3291 | } | ||
| 3292 | isone: | ||
| 3293 | /* Find the first (leading) digit. */ | ||
| 3294 | emovi( t, w ); | ||
| 3295 | emovz( w, t ); | ||
| 3296 | emovi( y, w ); | ||
| 3297 | emovz( w, y ); | ||
| 3298 | eiremain( t, y ); | ||
| 3299 | digit = equot[NI-1]; | ||
| 3300 | while( (digit == 0) && (ecmp(y,ezero) != 0) ) | ||
| 3301 | { | ||
| 3302 | eshup1( y ); | ||
| 3303 | emovz( y, u ); | ||
| 3304 | eshup1( u ); | ||
| 3305 | eshup1( u ); | ||
| 3306 | eaddm( u, y ); | ||
| 3307 | eiremain( t, y ); | ||
| 3308 | digit = equot[NI-1]; | ||
| 3309 | expon -= 1; | ||
| 3310 | } | ||
| 3311 | s = string; | ||
| 3312 | if( sign ) | ||
| 3313 | *s++ = '-'; | ||
| 3314 | else | ||
| 3315 | *s++ = ' '; | ||
| 3316 | /* Examine number of digits requested by caller. */ | ||
| 3317 | if( ndigs < 0 ) | ||
| 3318 | ndigs = 0; | ||
| 3319 | if( ndigs > NDEC ) | ||
| 3320 | ndigs = NDEC; | ||
| 3321 | if( digit == 10 ) | ||
| 3322 | { | ||
| 3323 | *s++ = '1'; | ||
| 3324 | *s++ = '.'; | ||
| 3325 | if( ndigs > 0 ) | ||
| 3326 | { | ||
| 3327 | *s++ = '0'; | ||
| 3328 | ndigs -= 1; | ||
| 3329 | } | ||
| 3330 | expon += 1; | ||
| 3331 | } | ||
| 3332 | else | ||
| 3333 | { | ||
| 3334 | *s++ = (char )digit + '0'; | ||
| 3335 | *s++ = '.'; | ||
| 3336 | } | ||
| 3337 | /* Generate digits after the decimal point. */ | ||
| 3338 | for( k=0; k<=ndigs; k++ ) | ||
| 3339 | { | ||
| 3340 | /* multiply current number by 10, without normalizing */ | ||
| 3341 | eshup1( y ); | ||
| 3342 | emovz( y, u ); | ||
| 3343 | eshup1( u ); | ||
| 3344 | eshup1( u ); | ||
| 3345 | eaddm( u, y ); | ||
| 3346 | eiremain( t, y ); | ||
| 3347 | *s++ = (char )equot[NI-1] + '0'; | ||
| 3348 | } | ||
| 3349 | digit = equot[NI-1]; | ||
| 3350 | --s; | ||
| 3351 | ss = s; | ||
| 3352 | /* round off the ASCII string */ | ||
| 3353 | if( digit > 4 ) | ||
| 3354 | { | ||
| 3355 | /* Test for critical rounding case in ASCII output. */ | ||
| 3356 | if( digit == 5 ) | ||
| 3357 | { | ||
| 3358 | emovo( y, t ); | ||
| 3359 | if( ecmp(t,ezero) != 0 ) | ||
| 3360 | goto roun; /* round to nearest */ | ||
| 3361 | if( (*(s-1) & 1) == 0 ) | ||
| 3362 | goto doexp; /* round to even */ | ||
| 3363 | } | ||
| 3364 | /* Round up and propagate carry-outs */ | ||
| 3365 | roun: | ||
| 3366 | --s; | ||
| 3367 | k = *s & 0x7f; | ||
| 3368 | /* Carry out to most significant digit? */ | ||
| 3369 | if( k == '.' ) | ||
| 3370 | { | ||
| 3371 | --s; | ||
| 3372 | k = *s; | ||
| 3373 | k += 1; | ||
| 3374 | *s = (char )k; | ||
| 3375 | /* Most significant digit carries to 10? */ | ||
| 3376 | if( k > '9' ) | ||
| 3377 | { | ||
| 3378 | expon += 1; | ||
| 3379 | *s = '1'; | ||
| 3380 | } | ||
| 3381 | goto doexp; | ||
| 3382 | } | ||
| 3383 | /* Round up and carry out from less significant digits */ | ||
| 3384 | k += 1; | ||
| 3385 | *s = (char )k; | ||
| 3386 | if( k > '9' ) | ||
| 3387 | { | ||
| 3388 | *s = '0'; | ||
| 3389 | goto roun; | ||
| 3390 | } | ||
| 3391 | } | ||
| 3392 | doexp: | ||
| 3393 | /* | ||
| 3394 | if( expon >= 0 ) | ||
| 3395 | sprintf( ss, "e+%d", expon ); | ||
| 3396 | else | ||
| 3397 | sprintf( ss, "e%d", expon ); | ||
| 3398 | */ | ||
| 3399 | sprintf( ss, "E%d", expon ); | ||
| 3400 | bxit: | ||
| 3401 | rndprc = rndsav; | ||
| 3402 | } | ||
| 3403 | |||
| 3404 | |||
| 3405 | |||
| 3406 | |||
| 3407 | /* | ||
| 3408 | ; ASCTOQ | ||
| 3409 | ; ASCTOQ.MAC LATEST REV: 11 JAN 84 | ||
| 3410 | ; SLM, 3 JAN 78 | ||
| 3411 | ; | ||
| 3412 | ; Convert ASCII string to quadruple precision floating point | ||
| 3413 | ; | ||
| 3414 | ; Numeric input is free field decimal number | ||
| 3415 | ; with max of 15 digits with or without | ||
| 3416 | ; decimal point entered as ASCII from teletype. | ||
| 3417 | ; Entering E after the number followed by a second | ||
| 3418 | ; number causes the second number to be interpreted | ||
| 3419 | ; as a power of 10 to be multiplied by the first number | ||
| 3420 | ; (i.e., "scientific" notation). | ||
| 3421 | ; | ||
| 3422 | ; Usage: | ||
| 3423 | ; asctoq( string, q ); | ||
| 3424 | */ | ||
| 3425 | |||
| 3426 | /* ASCII to single */ | ||
| 3427 | void asctoe24( s, y ) | ||
| 3428 | char *s; | ||
| 3429 | unsigned short *y; | ||
| 3430 | { | ||
| 3431 | asctoeg( s, y, 24 ); | ||
| 3432 | } | ||
| 3433 | |||
| 3434 | |||
| 3435 | /* ASCII to double */ | ||
| 3436 | void asctoe53( s, y ) | ||
| 3437 | char *s; | ||
| 3438 | unsigned short *y; | ||
| 3439 | { | ||
| 3440 | #ifdef DEC | ||
| 3441 | asctoeg( s, y, 56 ); | ||
| 3442 | #else | ||
| 3443 | asctoeg( s, y, 53 ); | ||
| 3444 | #endif | ||
| 3445 | } | ||
| 3446 | |||
| 3447 | |||
| 3448 | /* ASCII to long double */ | ||
| 3449 | void asctoe64( s, y ) | ||
| 3450 | char *s; | ||
| 3451 | unsigned short *y; | ||
| 3452 | { | ||
| 3453 | asctoeg( s, y, 64 ); | ||
| 3454 | } | ||
| 3455 | |||
| 3456 | /* ASCII to 128-bit long double */ | ||
| 3457 | void asctoe113 (s, y) | ||
| 3458 | char *s; | ||
| 3459 | unsigned short *y; | ||
| 3460 | { | ||
| 3461 | asctoeg( s, y, 113 ); | ||
| 3462 | } | ||
| 3463 | |||
| 3464 | /* ASCII to super double */ | ||
| 3465 | void asctoe( s, y ) | ||
| 3466 | char *s; | ||
| 3467 | unsigned short *y; | ||
| 3468 | { | ||
| 3469 | asctoeg( s, y, NBITS ); | ||
| 3470 | } | ||
| 3471 | |||
| 3472 | /* Space to make a copy of the input string: */ | ||
| 3473 | static char lstr[82] = {0}; | ||
| 3474 | |||
| 3475 | void asctoeg( ss, y, oprec ) | ||
| 3476 | char *ss; | ||
| 3477 | unsigned short *y; | ||
| 3478 | int oprec; | ||
| 3479 | { | ||
| 3480 | unsigned short yy[NI], xt[NI], tt[NI]; | ||
| 3481 | int esign, decflg, sgnflg, nexp, exp, prec, lost; | ||
| 3482 | int k, trail, c, rndsav; | ||
| 3483 | long lexp; | ||
| 3484 | unsigned short nsign, *p; | ||
| 3485 | char *sp, *s; | ||
| 3486 | |||
| 3487 | /* Copy the input string. */ | ||
| 3488 | s = ss; | ||
| 3489 | while( *s == ' ' ) /* skip leading spaces */ | ||
| 3490 | ++s; | ||
| 3491 | sp = lstr; | ||
| 3492 | for( k=0; k<79; k++ ) | ||
| 3493 | { | ||
| 3494 | if( (*sp++ = *s++) == '\0' ) | ||
| 3495 | break; | ||
| 3496 | } | ||
| 3497 | *sp = '\0'; | ||
| 3498 | s = lstr; | ||
| 3499 | |||
| 3500 | rndsav = rndprc; | ||
| 3501 | rndprc = NBITS; /* Set to full precision */ | ||
| 3502 | lost = 0; | ||
| 3503 | nsign = 0; | ||
| 3504 | decflg = 0; | ||
| 3505 | sgnflg = 0; | ||
| 3506 | nexp = 0; | ||
| 3507 | exp = 0; | ||
| 3508 | prec = 0; | ||
| 3509 | ecleaz( yy ); | ||
| 3510 | trail = 0; | ||
| 3511 | |||
| 3512 | nxtcom: | ||
| 3513 | k = *s - '0'; | ||
| 3514 | if( (k >= 0) && (k <= 9) ) | ||
| 3515 | { | ||
| 3516 | /* Ignore leading zeros */ | ||
| 3517 | if( (prec == 0) && (decflg == 0) && (k == 0) ) | ||
| 3518 | goto donchr; | ||
| 3519 | /* Identify and strip trailing zeros after the decimal point. */ | ||
| 3520 | if( (trail == 0) && (decflg != 0) ) | ||
| 3521 | { | ||
| 3522 | sp = s; | ||
| 3523 | while( (*sp >= '0') && (*sp <= '9') ) | ||
| 3524 | ++sp; | ||
| 3525 | /* Check for syntax error */ | ||
| 3526 | c = *sp & 0x7f; | ||
| 3527 | if( (c != 'e') && (c != 'E') && (c != '\0') | ||
| 3528 | && (c != '\n') && (c != '\r') && (c != ' ') | ||
| 3529 | && (c != ',') ) | ||
| 3530 | goto error; | ||
| 3531 | --sp; | ||
| 3532 | while( *sp == '0' ) | ||
| 3533 | *sp-- = 'z'; | ||
| 3534 | trail = 1; | ||
| 3535 | if( *s == 'z' ) | ||
| 3536 | goto donchr; | ||
| 3537 | } | ||
| 3538 | /* If enough digits were given to more than fill up the yy register, | ||
| 3539 | * continuing until overflow into the high guard word yy[2] | ||
| 3540 | * guarantees that there will be a roundoff bit at the top | ||
| 3541 | * of the low guard word after normalization. | ||
| 3542 | */ | ||
| 3543 | if( yy[2] == 0 ) | ||
| 3544 | { | ||
| 3545 | if( decflg ) | ||
| 3546 | nexp += 1; /* count digits after decimal point */ | ||
| 3547 | eshup1( yy ); /* multiply current number by 10 */ | ||
| 3548 | emovz( yy, xt ); | ||
| 3549 | eshup1( xt ); | ||
| 3550 | eshup1( xt ); | ||
| 3551 | eaddm( xt, yy ); | ||
| 3552 | ecleaz( xt ); | ||
| 3553 | xt[NI-2] = (unsigned short )k; | ||
| 3554 | eaddm( xt, yy ); | ||
| 3555 | } | ||
| 3556 | else | ||
| 3557 | { | ||
| 3558 | /* Mark any lost non-zero digit. */ | ||
| 3559 | lost |= k; | ||
| 3560 | /* Count lost digits before the decimal point. */ | ||
| 3561 | if (decflg == 0) | ||
| 3562 | nexp -= 1; | ||
| 3563 | } | ||
| 3564 | prec += 1; | ||
| 3565 | goto donchr; | ||
| 3566 | } | ||
| 3567 | |||
| 3568 | switch( *s ) | ||
| 3569 | { | ||
| 3570 | case 'z': | ||
| 3571 | break; | ||
| 3572 | case 'E': | ||
| 3573 | case 'e': | ||
| 3574 | goto expnt; | ||
| 3575 | case '.': /* decimal point */ | ||
| 3576 | if( decflg ) | ||
| 3577 | goto error; | ||
| 3578 | ++decflg; | ||
| 3579 | break; | ||
| 3580 | case '-': | ||
| 3581 | nsign = 0xffff; | ||
| 3582 | if( sgnflg ) | ||
| 3583 | goto error; | ||
| 3584 | ++sgnflg; | ||
| 3585 | break; | ||
| 3586 | case '+': | ||
| 3587 | if( sgnflg ) | ||
| 3588 | goto error; | ||
| 3589 | ++sgnflg; | ||
| 3590 | break; | ||
| 3591 | case ',': | ||
| 3592 | case ' ': | ||
| 3593 | case '\0': | ||
| 3594 | case '\n': | ||
| 3595 | case '\r': | ||
| 3596 | goto daldone; | ||
| 3597 | case 'i': | ||
| 3598 | case 'I': | ||
| 3599 | goto infinite; | ||
| 3600 | default: | ||
| 3601 | error: | ||
| 3602 | #ifdef NANS | ||
| 3603 | enan( yy, NI*16 ); | ||
| 3604 | #else | ||
| 3605 | mtherr( "asctoe", DOMAIN ); | ||
| 3606 | ecleaz(yy); | ||
| 3607 | #endif | ||
| 3608 | goto aexit; | ||
| 3609 | } | ||
| 3610 | donchr: | ||
| 3611 | ++s; | ||
| 3612 | goto nxtcom; | ||
| 3613 | |||
| 3614 | /* Exponent interpretation */ | ||
| 3615 | expnt: | ||
| 3616 | |||
| 3617 | esign = 1; | ||
| 3618 | exp = 0; | ||
| 3619 | ++s; | ||
| 3620 | /* check for + or - */ | ||
| 3621 | if( *s == '-' ) | ||
| 3622 | { | ||
| 3623 | esign = -1; | ||
| 3624 | ++s; | ||
| 3625 | } | ||
| 3626 | if( *s == '+' ) | ||
| 3627 | ++s; | ||
| 3628 | while( (*s >= '0') && (*s <= '9') ) | ||
| 3629 | { | ||
| 3630 | exp *= 10; | ||
| 3631 | exp += *s++ - '0'; | ||
| 3632 | if (exp > 4977) | ||
| 3633 | { | ||
| 3634 | if (esign < 0) | ||
| 3635 | goto zero; | ||
| 3636 | else | ||
| 3637 | goto infinite; | ||
| 3638 | } | ||
| 3639 | } | ||
| 3640 | if( esign < 0 ) | ||
| 3641 | exp = -exp; | ||
| 3642 | if( exp > 4932 ) | ||
| 3643 | { | ||
| 3644 | infinite: | ||
| 3645 | ecleaz(yy); | ||
| 3646 | yy[E] = 0x7fff; /* infinity */ | ||
| 3647 | goto aexit; | ||
| 3648 | } | ||
| 3649 | if( exp < -4977 ) | ||
| 3650 | { | ||
| 3651 | zero: | ||
| 3652 | ecleaz(yy); | ||
| 3653 | goto aexit; | ||
| 3654 | } | ||
| 3655 | |||
| 3656 | daldone: | ||
| 3657 | nexp = exp - nexp; | ||
| 3658 | /* Pad trailing zeros to minimize power of 10, per IEEE spec. */ | ||
| 3659 | while( (nexp > 0) && (yy[2] == 0) ) | ||
| 3660 | { | ||
| 3661 | emovz( yy, xt ); | ||
| 3662 | eshup1( xt ); | ||
| 3663 | eshup1( xt ); | ||
| 3664 | eaddm( yy, xt ); | ||
| 3665 | eshup1( xt ); | ||
| 3666 | if( xt[2] != 0 ) | ||
| 3667 | break; | ||
| 3668 | nexp -= 1; | ||
| 3669 | emovz( xt, yy ); | ||
| 3670 | } | ||
| 3671 | if( (k = enormlz(yy)) > NBITS ) | ||
| 3672 | { | ||
| 3673 | ecleaz(yy); | ||
| 3674 | goto aexit; | ||
| 3675 | } | ||
| 3676 | lexp = (EXONE - 1 + NBITS) - k; | ||
| 3677 | emdnorm( yy, lost, 0, lexp, 64 ); | ||
| 3678 | /* convert to external format */ | ||
| 3679 | |||
| 3680 | |||
| 3681 | /* Multiply by 10**nexp. If precision is 64 bits, | ||
| 3682 | * the maximum relative error incurred in forming 10**n | ||
| 3683 | * for 0 <= n <= 324 is 8.2e-20, at 10**180. | ||
| 3684 | * For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947. | ||
| 3685 | * For 0 >= n >= -999, it is -1.55e-19 at 10**-435. | ||
| 3686 | */ | ||
| 3687 | lexp = yy[E]; | ||
| 3688 | if( nexp == 0 ) | ||
| 3689 | { | ||
| 3690 | k = 0; | ||
| 3691 | goto expdon; | ||
| 3692 | } | ||
| 3693 | esign = 1; | ||
| 3694 | if( nexp < 0 ) | ||
| 3695 | { | ||
| 3696 | nexp = -nexp; | ||
| 3697 | esign = -1; | ||
| 3698 | if( nexp > 4096 ) | ||
| 3699 | { /* Punt. Can't handle this without 2 divides. */ | ||
| 3700 | emovi( etens[0], tt ); | ||
| 3701 | lexp -= tt[E]; | ||
| 3702 | k = edivm( tt, yy ); | ||
| 3703 | lexp += EXONE; | ||
| 3704 | nexp -= 4096; | ||
| 3705 | } | ||
| 3706 | } | ||
| 3707 | p = &etens[NTEN][0]; | ||
| 3708 | emov( eone, xt ); | ||
| 3709 | exp = 1; | ||
| 3710 | do | ||
| 3711 | { | ||
| 3712 | if( exp & nexp ) | ||
| 3713 | emul( p, xt, xt ); | ||
| 3714 | p -= NE; | ||
| 3715 | exp = exp + exp; | ||
| 3716 | } | ||
| 3717 | while( exp <= MAXP ); | ||
| 3718 | |||
| 3719 | emovi( xt, tt ); | ||
| 3720 | if( esign < 0 ) | ||
| 3721 | { | ||
| 3722 | lexp -= tt[E]; | ||
| 3723 | k = edivm( tt, yy ); | ||
| 3724 | lexp += EXONE; | ||
| 3725 | } | ||
| 3726 | else | ||
| 3727 | { | ||
| 3728 | lexp += tt[E]; | ||
| 3729 | k = emulm( tt, yy ); | ||
| 3730 | lexp -= EXONE - 1; | ||
| 3731 | } | ||
| 3732 | |||
| 3733 | expdon: | ||
| 3734 | |||
| 3735 | /* Round and convert directly to the destination type */ | ||
| 3736 | if( oprec == 53 ) | ||
| 3737 | lexp -= EXONE - 0x3ff; | ||
| 3738 | else if( oprec == 24 ) | ||
| 3739 | lexp -= EXONE - 0177; | ||
| 3740 | #ifdef DEC | ||
| 3741 | else if( oprec == 56 ) | ||
| 3742 | lexp -= EXONE - 0201; | ||
| 3743 | #endif | ||
| 3744 | rndprc = oprec; | ||
| 3745 | emdnorm( yy, k, 0, lexp, 64 ); | ||
| 3746 | |||
| 3747 | aexit: | ||
| 3748 | |||
| 3749 | rndprc = rndsav; | ||
| 3750 | yy[0] = nsign; | ||
| 3751 | switch( oprec ) | ||
| 3752 | { | ||
| 3753 | #ifdef DEC | ||
| 3754 | case 56: | ||
| 3755 | todec( yy, y ); /* see etodec.c */ | ||
| 3756 | break; | ||
| 3757 | #endif | ||
| 3758 | case 53: | ||
| 3759 | toe53( yy, y ); | ||
| 3760 | break; | ||
| 3761 | case 24: | ||
| 3762 | toe24( yy, y ); | ||
| 3763 | break; | ||
| 3764 | case 64: | ||
| 3765 | toe64( yy, y ); | ||
| 3766 | break; | ||
| 3767 | case 113: | ||
| 3768 | toe113( yy, y ); | ||
| 3769 | break; | ||
| 3770 | case NBITS: | ||
| 3771 | emovo( yy, y ); | ||
| 3772 | break; | ||
| 3773 | } | ||
| 3774 | } | ||
| 3775 | |||
| 3776 | |||
| 3777 | |||
| 3778 | /* y = largest integer not greater than x | ||
| 3779 | * (truncated toward minus infinity) | ||
| 3780 | * | ||
| 3781 | * unsigned short x[NE], y[NE] | ||
| 3782 | * | ||
| 3783 | * efloor( x, y ); | ||
| 3784 | */ | ||
| 3785 | static unsigned short bmask[] = { | ||
| 3786 | 0xffff, | ||
| 3787 | 0xfffe, | ||
| 3788 | 0xfffc, | ||
| 3789 | 0xfff8, | ||
| 3790 | 0xfff0, | ||
| 3791 | 0xffe0, | ||
| 3792 | 0xffc0, | ||
| 3793 | 0xff80, | ||
| 3794 | 0xff00, | ||
| 3795 | 0xfe00, | ||
| 3796 | 0xfc00, | ||
| 3797 | 0xf800, | ||
| 3798 | 0xf000, | ||
| 3799 | 0xe000, | ||
| 3800 | 0xc000, | ||
| 3801 | 0x8000, | ||
| 3802 | 0x0000, | ||
| 3803 | }; | ||
| 3804 | |||
| 3805 | void efloor( x, y ) | ||
| 3806 | unsigned short x[], y[]; | ||
| 3807 | { | ||
| 3808 | register unsigned short *p; | ||
| 3809 | int e, expon, i; | ||
| 3810 | unsigned short f[NE]; | ||
| 3811 | |||
| 3812 | emov( x, f ); /* leave in external format */ | ||
| 3813 | expon = (int )f[NE-1]; | ||
| 3814 | e = (expon & 0x7fff) - (EXONE - 1); | ||
| 3815 | if( e <= 0 ) | ||
| 3816 | { | ||
| 3817 | eclear(y); | ||
| 3818 | goto isitneg; | ||
| 3819 | } | ||
| 3820 | /* number of bits to clear out */ | ||
| 3821 | e = NBITS - e; | ||
| 3822 | emov( f, y ); | ||
| 3823 | if( e <= 0 ) | ||
| 3824 | return; | ||
| 3825 | |||
| 3826 | p = &y[0]; | ||
| 3827 | while( e >= 16 ) | ||
| 3828 | { | ||
| 3829 | *p++ = 0; | ||
| 3830 | e -= 16; | ||
| 3831 | } | ||
| 3832 | /* clear the remaining bits */ | ||
| 3833 | *p &= bmask[e]; | ||
| 3834 | /* truncate negatives toward minus infinity */ | ||
| 3835 | isitneg: | ||
| 3836 | |||
| 3837 | if( (unsigned short )expon & (unsigned short )0x8000 ) | ||
| 3838 | { | ||
| 3839 | for( i=0; i<NE-1; i++ ) | ||
| 3840 | { | ||
| 3841 | if( f[i] != y[i] ) | ||
| 3842 | { | ||
| 3843 | esub( eone, y, y ); | ||
| 3844 | break; | ||
| 3845 | } | ||
| 3846 | } | ||
| 3847 | } | ||
| 3848 | } | ||
| 3849 | |||
| 3850 | |||
| 3851 | /* unsigned short x[], s[]; | ||
| 3852 | * long *exp; | ||
| 3853 | * | ||
| 3854 | * efrexp( x, exp, s ); | ||
| 3855 | * | ||
| 3856 | * Returns s and exp such that s * 2**exp = x and .5 <= s < 1. | ||
| 3857 | * For example, 1.1 = 0.55 * 2**1 | ||
| 3858 | * Handles denormalized numbers properly using long integer exp. | ||
| 3859 | */ | ||
| 3860 | void efrexp( x, exp, s ) | ||
| 3861 | unsigned short x[]; | ||
| 3862 | long *exp; | ||
| 3863 | unsigned short s[]; | ||
| 3864 | { | ||
| 3865 | unsigned short xi[NI]; | ||
| 3866 | long li; | ||
| 3867 | |||
| 3868 | emovi( x, xi ); | ||
| 3869 | li = (long )((short )xi[1]); | ||
| 3870 | |||
| 3871 | if( li == 0 ) | ||
| 3872 | { | ||
| 3873 | li -= enormlz( xi ); | ||
| 3874 | } | ||
| 3875 | xi[1] = 0x3ffe; | ||
| 3876 | emovo( xi, s ); | ||
| 3877 | *exp = li - 0x3ffe; | ||
| 3878 | } | ||
| 3879 | |||
| 3880 | |||
| 3881 | |||
| 3882 | /* unsigned short x[], y[]; | ||
| 3883 | * long pwr2; | ||
| 3884 | * | ||
| 3885 | * eldexp( x, pwr2, y ); | ||
| 3886 | * | ||
| 3887 | * Returns y = x * 2**pwr2. | ||
| 3888 | */ | ||
| 3889 | void eldexp( x, pwr2, y ) | ||
| 3890 | unsigned short x[]; | ||
| 3891 | long pwr2; | ||
| 3892 | unsigned short y[]; | ||
| 3893 | { | ||
| 3894 | unsigned short xi[NI]; | ||
| 3895 | long li; | ||
| 3896 | int i; | ||
| 3897 | |||
| 3898 | emovi( x, xi ); | ||
| 3899 | li = xi[1]; | ||
| 3900 | li += pwr2; | ||
| 3901 | i = 0; | ||
| 3902 | emdnorm( xi, i, i, li, 64 ); | ||
| 3903 | emovo( xi, y ); | ||
| 3904 | } | ||
| 3905 | |||
| 3906 | |||
| 3907 | /* c = remainder after dividing b by a | ||
| 3908 | * Least significant integer quotient bits left in equot[]. | ||
| 3909 | */ | ||
| 3910 | void eremain( a, b, c ) | ||
| 3911 | unsigned short a[], b[], c[]; | ||
| 3912 | { | ||
| 3913 | unsigned short den[NI], num[NI]; | ||
| 3914 | |||
| 3915 | #ifdef NANS | ||
| 3916 | if( eisinf(b) || (ecmp(a,ezero) == 0) || eisnan(a) || eisnan(b)) | ||
| 3917 | { | ||
| 3918 | enan( c, NBITS ); | ||
| 3919 | return; | ||
| 3920 | } | ||
| 3921 | #endif | ||
| 3922 | if( ecmp(a,ezero) == 0 ) | ||
| 3923 | { | ||
| 3924 | mtherr( "eremain", SING ); | ||
| 3925 | eclear( c ); | ||
| 3926 | return; | ||
| 3927 | } | ||
| 3928 | emovi( a, den ); | ||
| 3929 | emovi( b, num ); | ||
| 3930 | eiremain( den, num ); | ||
| 3931 | /* Sign of remainder = sign of quotient */ | ||
| 3932 | if( a[0] == b[0] ) | ||
| 3933 | num[0] = 0; | ||
| 3934 | else | ||
| 3935 | num[0] = 0xffff; | ||
| 3936 | emovo( num, c ); | ||
| 3937 | } | ||
| 3938 | |||
| 3939 | |||
| 3940 | void eiremain( den, num ) | ||
| 3941 | unsigned short den[], num[]; | ||
| 3942 | { | ||
| 3943 | long ld, ln; | ||
| 3944 | unsigned short j; | ||
| 3945 | |||
| 3946 | ld = den[E]; | ||
| 3947 | ld -= enormlz( den ); | ||
| 3948 | ln = num[E]; | ||
| 3949 | ln -= enormlz( num ); | ||
| 3950 | ecleaz( equot ); | ||
| 3951 | while( ln >= ld ) | ||
| 3952 | { | ||
| 3953 | if( ecmpm(den,num) <= 0 ) | ||
| 3954 | { | ||
| 3955 | esubm(den, num); | ||
| 3956 | j = 1; | ||
| 3957 | } | ||
| 3958 | else | ||
| 3959 | { | ||
| 3960 | j = 0; | ||
| 3961 | } | ||
| 3962 | eshup1(equot); | ||
| 3963 | equot[NI-1] |= j; | ||
| 3964 | eshup1(num); | ||
| 3965 | ln -= 1; | ||
| 3966 | } | ||
| 3967 | emdnorm( num, 0, 0, ln, 0 ); | ||
| 3968 | } | ||
| 3969 | |||
| 3970 | /* NaN bit patterns | ||
| 3971 | */ | ||
| 3972 | #ifdef MIEEE | ||
| 3973 | unsigned short nan113[8] = { | ||
| 3974 | 0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
| 3975 | unsigned short nan64[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
| 3976 | unsigned short nan53[4] = {0x7fff, 0xffff, 0xffff, 0xffff}; | ||
| 3977 | unsigned short nan24[2] = {0x7fff, 0xffff}; | ||
| 3978 | #endif | ||
| 3979 | |||
| 3980 | #ifdef IBMPC | ||
| 3981 | unsigned short nan113[8] = {0, 0, 0, 0, 0, 0, 0xc000, 0xffff}; | ||
| 3982 | unsigned short nan64[6] = {0, 0, 0, 0xc000, 0xffff, 0}; | ||
| 3983 | unsigned short nan53[4] = {0, 0, 0, 0xfff8}; | ||
| 3984 | unsigned short nan24[2] = {0, 0xffc0}; | ||
| 3985 | #endif | ||
| 3986 | |||
| 3987 | |||
| 3988 | void enan (nan, size) | ||
| 3989 | unsigned short *nan; | ||
| 3990 | int size; | ||
| 3991 | { | ||
| 3992 | int i, n; | ||
| 3993 | unsigned short *p; | ||
| 3994 | |||
| 3995 | switch( size ) | ||
| 3996 | { | ||
| 3997 | #ifndef DEC | ||
| 3998 | case 113: | ||
| 3999 | n = 8; | ||
| 4000 | p = nan113; | ||
| 4001 | break; | ||
| 4002 | |||
| 4003 | case 64: | ||
| 4004 | n = 6; | ||
| 4005 | p = nan64; | ||
| 4006 | break; | ||
| 4007 | |||
| 4008 | case 53: | ||
| 4009 | n = 4; | ||
| 4010 | p = nan53; | ||
| 4011 | break; | ||
| 4012 | |||
| 4013 | case 24: | ||
| 4014 | n = 2; | ||
| 4015 | p = nan24; | ||
| 4016 | break; | ||
| 4017 | |||
| 4018 | case NBITS: | ||
| 4019 | for( i=0; i<NE-2; i++ ) | ||
| 4020 | *nan++ = 0; | ||
| 4021 | *nan++ = 0xc000; | ||
| 4022 | *nan++ = 0x7fff; | ||
| 4023 | return; | ||
| 4024 | |||
| 4025 | case NI*16: | ||
| 4026 | *nan++ = 0; | ||
| 4027 | *nan++ = 0x7fff; | ||
| 4028 | *nan++ = 0; | ||
| 4029 | *nan++ = 0xc000; | ||
| 4030 | for( i=4; i<NI; i++ ) | ||
| 4031 | *nan++ = 0; | ||
| 4032 | return; | ||
| 4033 | #endif | ||
| 4034 | default: | ||
| 4035 | mtherr( "enan", DOMAIN ); | ||
| 4036 | return; | ||
| 4037 | } | ||
| 4038 | for (i=0; i < n; i++) | ||
| 4039 | *nan++ = *p++; | ||
| 4040 | } | ||
| 4041 | |||
| 4042 | |||
| 4043 | |||
| 4044 | /* Longhand square root. */ | ||
| 4045 | |||
| 4046 | static int esqinited = 0; | ||
| 4047 | static unsigned short sqrndbit[NI]; | ||
| 4048 | |||
| 4049 | void esqrt( x, y ) | ||
| 4050 | short *x, *y; | ||
| 4051 | { | ||
| 4052 | unsigned short temp[NI], num[NI], sq[NI], xx[NI]; | ||
| 4053 | int i, j, k, n, nlups; | ||
| 4054 | long m, exp; | ||
| 4055 | |||
| 4056 | if( esqinited == 0 ) | ||
| 4057 | { | ||
| 4058 | ecleaz( sqrndbit ); | ||
| 4059 | sqrndbit[NI-2] = 1; | ||
| 4060 | esqinited = 1; | ||
| 4061 | } | ||
| 4062 | /* Check for arg <= 0 */ | ||
| 4063 | i = ecmp( x, ezero ); | ||
| 4064 | if( i <= 0 ) | ||
| 4065 | { | ||
| 4066 | #ifdef NANS | ||
| 4067 | if (i == -2) | ||
| 4068 | { | ||
| 4069 | enan (y, NBITS); | ||
| 4070 | return; | ||
| 4071 | } | ||
| 4072 | #endif | ||
| 4073 | eclear(y); | ||
| 4074 | if( i < 0 ) | ||
| 4075 | mtherr( "esqrt", DOMAIN ); | ||
| 4076 | return; | ||
| 4077 | } | ||
| 4078 | |||
| 4079 | #ifdef INFINITY | ||
| 4080 | if( eisinf(x) ) | ||
| 4081 | { | ||
| 4082 | eclear(y); | ||
| 4083 | einfin(y); | ||
| 4084 | return; | ||
| 4085 | } | ||
| 4086 | #endif | ||
| 4087 | /* Bring in the arg and renormalize if it is denormal. */ | ||
| 4088 | emovi( x, xx ); | ||
| 4089 | m = (long )xx[1]; /* local long word exponent */ | ||
| 4090 | if( m == 0 ) | ||
| 4091 | m -= enormlz( xx ); | ||
| 4092 | |||
| 4093 | /* Divide exponent by 2 */ | ||
| 4094 | m -= 0x3ffe; | ||
| 4095 | exp = (unsigned short )( (m / 2) + 0x3ffe ); | ||
| 4096 | |||
| 4097 | /* Adjust if exponent odd */ | ||
| 4098 | if( (m & 1) != 0 ) | ||
| 4099 | { | ||
| 4100 | if( m > 0 ) | ||
| 4101 | exp += 1; | ||
| 4102 | eshdn1( xx ); | ||
| 4103 | } | ||
| 4104 | |||
| 4105 | ecleaz( sq ); | ||
| 4106 | ecleaz( num ); | ||
| 4107 | n = 8; /* get 8 bits of result per inner loop */ | ||
| 4108 | nlups = rndprc; | ||
| 4109 | j = 0; | ||
| 4110 | |||
| 4111 | while( nlups > 0 ) | ||
| 4112 | { | ||
| 4113 | /* bring in next word of arg */ | ||
| 4114 | if( j < NE ) | ||
| 4115 | num[NI-1] = xx[j+3]; | ||
| 4116 | /* Do additional bit on last outer loop, for roundoff. */ | ||
| 4117 | if( nlups <= 8 ) | ||
| 4118 | n = nlups + 1; | ||
| 4119 | for( i=0; i<n; i++ ) | ||
| 4120 | { | ||
| 4121 | /* Next 2 bits of arg */ | ||
| 4122 | eshup1( num ); | ||
| 4123 | eshup1( num ); | ||
| 4124 | /* Shift up answer */ | ||
| 4125 | eshup1( sq ); | ||
| 4126 | /* Make trial divisor */ | ||
| 4127 | for( k=0; k<NI; k++ ) | ||
| 4128 | temp[k] = sq[k]; | ||
| 4129 | eshup1( temp ); | ||
| 4130 | eaddm( sqrndbit, temp ); | ||
| 4131 | /* Subtract and insert answer bit if it goes in */ | ||
| 4132 | if( ecmpm( temp, num ) <= 0 ) | ||
| 4133 | { | ||
| 4134 | esubm( temp, num ); | ||
| 4135 | sq[NI-2] |= 1; | ||
| 4136 | } | ||
| 4137 | } | ||
| 4138 | nlups -= n; | ||
| 4139 | j += 1; | ||
| 4140 | } | ||
| 4141 | |||
| 4142 | /* Adjust for extra, roundoff loop done. */ | ||
| 4143 | exp += (NBITS - 1) - rndprc; | ||
| 4144 | |||
| 4145 | /* Sticky bit = 1 if the remainder is nonzero. */ | ||
| 4146 | k = 0; | ||
| 4147 | for( i=3; i<NI; i++ ) | ||
| 4148 | k |= (int )num[i]; | ||
| 4149 | |||
| 4150 | /* Renormalize and round off. */ | ||
| 4151 | emdnorm( sq, k, 0, exp, 64 ); | ||
| 4152 | emovo( sq, y ); | ||
| 4153 | } | ||
diff --git a/src/regress/lib/libc/cephes/ieetst.c b/src/regress/lib/libc/cephes/ieetst.c deleted file mode 100644 index 974fb65c13..0000000000 --- a/src/regress/lib/libc/cephes/ieetst.c +++ /dev/null | |||
| @@ -1,881 +0,0 @@ | |||
| 1 | /* $OpenBSD: ieetst.c,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* Floating point to ASCII input and output string test program. | ||
| 20 | * | ||
| 21 | * Numbers in the native machine data structure are converted | ||
| 22 | * to e type, then to and from decimal ASCII strings. Native | ||
| 23 | * printf() and scanf() functions are also used to produce | ||
| 24 | * and read strings. The resulting e type binary values | ||
| 25 | * are compared, with diagnostic printouts of any discrepancies. | ||
| 26 | * | ||
| 27 | * Steve Moshier, 16 Dec 88 | ||
| 28 | * last revision: 16 May 92 | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include <float.h> | ||
| 32 | #include <stdio.h> | ||
| 33 | |||
| 34 | #include "mconf.h" | ||
| 35 | #include "ehead.h" | ||
| 36 | |||
| 37 | /* Include tests of 80-bit long double precision: */ | ||
| 38 | #if LDBL_MANT_DIG == 64 | ||
| 39 | #define LDOUBLE 1 | ||
| 40 | #else /* LDBL_MANT_DIG == 64 */ | ||
| 41 | #define LDOUBLE 0 | ||
| 42 | #endif /* LDBL_MANT_DIG == 64 */ | ||
| 43 | /* Abort subtest after getting this many errors: */ | ||
| 44 | #define MAXERR 5 | ||
| 45 | /* Number of random arguments to try (set as large as you have | ||
| 46 | * patience for): */ | ||
| 47 | #define NRAND 100 | ||
| 48 | /* Perform internal consistency test: */ | ||
| 49 | #define CHKINTERNAL 0 | ||
| 50 | |||
| 51 | static unsigned short fullp[NE], rounded[NE]; | ||
| 52 | float prec24, sprec24, ssprec24; | ||
| 53 | double prec53, sprec53, ssprec53; | ||
| 54 | #if LDOUBLE | ||
| 55 | long double prec64, sprec64, ssprec64; | ||
| 56 | #endif | ||
| 57 | |||
| 58 | static unsigned short rprint[NE], rscan[NE]; | ||
| 59 | static unsigned short q1[NE], q2[NE], q5[NE]; | ||
| 60 | static unsigned short e1[NE], e2[NE], e3[NE]; | ||
| 61 | static double d1, d2; | ||
| 62 | static int errprint = 0; | ||
| 63 | static int errscan = 0; | ||
| 64 | static int identerr = 0; | ||
| 65 | static int errtot = 0; | ||
| 66 | static int count = 0; | ||
| 67 | static char str0[80], str1[80], str2[80], str3[80]; | ||
| 68 | static unsigned short eten[NE], maxm[NE]; | ||
| 69 | |||
| 70 | int m, n, k2, mprec, SPREC; | ||
| 71 | |||
| 72 | char *Ten = "10.0"; | ||
| 73 | char tformat[10]; | ||
| 74 | char *format24 = "%.8e"; | ||
| 75 | #ifdef DEC | ||
| 76 | char *format53 = "%.17e"; | ||
| 77 | #else | ||
| 78 | char *format53 = "%.16e"; | ||
| 79 | #endif | ||
| 80 | char *fformat24 = "%e"; | ||
| 81 | char *fformat53 = "%le"; | ||
| 82 | char *pct = "%"; | ||
| 83 | char *quo = "\042"; | ||
| 84 | #if LDOUBLE | ||
| 85 | char *format64 = "%.20Le"; | ||
| 86 | char *fformat64 = "%Le"; | ||
| 87 | #endif | ||
| 88 | char *format; | ||
| 89 | char *fformat; | ||
| 90 | char *toomany = "Too many errors; aborting this test.\n"; | ||
| 91 | |||
| 92 | static int mnrflag; | ||
| 93 | static int etrflag; | ||
| 94 | void chkit(), printerr(), mnrand(), etrand(), shownoncrit(); | ||
| 95 | void chkid(), pvec(); | ||
| 96 | |||
| 97 | int | ||
| 98 | main() | ||
| 99 | { | ||
| 100 | int i, iprec, retval = 0; | ||
| 101 | |||
| 102 | printf( "Steve Moshier's printf/scanf tester, version 0.2.\n\n" ); | ||
| 103 | #ifdef DEC | ||
| 104 | /* DEC PDP-11/VAX single precision not yet implemented */ | ||
| 105 | for( iprec = 1; iprec<2; iprec++ ) | ||
| 106 | #else | ||
| 107 | for( iprec = 0; iprec<3; iprec++ ) | ||
| 108 | /*for( iprec = 2; iprec<3; iprec++ )*/ | ||
| 109 | #endif | ||
| 110 | { | ||
| 111 | errscan = 0; | ||
| 112 | identerr = 0; | ||
| 113 | errprint = 0; | ||
| 114 | eclear( rprint ); | ||
| 115 | eclear( rscan ); | ||
| 116 | |||
| 117 | switch( iprec ) | ||
| 118 | { | ||
| 119 | case 0: | ||
| 120 | SPREC = 8; /* # digits after the decimal point */ | ||
| 121 | mprec = 24; /* # bits in the significand */ | ||
| 122 | m = 9; /* max # decimal digits for correct rounding */ | ||
| 123 | n = 13; /* max power of ten for correct rounding */ | ||
| 124 | k2 = -125; /* underflow beyond 2^-k2 */ | ||
| 125 | format = format24; /* printf format string */ | ||
| 126 | fformat = fformat24; /* scanf format string */ | ||
| 127 | mnrflag = 1; /* sets interval for random numbers */ | ||
| 128 | etrflag = 1; | ||
| 129 | printf( "Testing FLOAT precision.\n" ); | ||
| 130 | break; | ||
| 131 | |||
| 132 | case 1: | ||
| 133 | #ifdef DEC | ||
| 134 | SPREC = 17; | ||
| 135 | mprec = 56; | ||
| 136 | m = 17; | ||
| 137 | n = 27; | ||
| 138 | k2 = -125; | ||
| 139 | format = format53; | ||
| 140 | fformat = fformat53; | ||
| 141 | mnrflag = 2; | ||
| 142 | etrflag = 1; | ||
| 143 | printf( "Testing DEC DOUBLE precision.\n" ); | ||
| 144 | break; | ||
| 145 | #else | ||
| 146 | SPREC = 16; | ||
| 147 | mprec = 53; | ||
| 148 | m = 17; | ||
| 149 | n = 27; | ||
| 150 | k2 = -1021; | ||
| 151 | format = format53; | ||
| 152 | fformat = fformat53; | ||
| 153 | mnrflag = 2; | ||
| 154 | etrflag = 2; | ||
| 155 | printf( "Testing DOUBLE precision.\n" ); | ||
| 156 | break; | ||
| 157 | #endif | ||
| 158 | case 2: | ||
| 159 | #if LDOUBLE | ||
| 160 | SPREC = 20; | ||
| 161 | mprec = 64; | ||
| 162 | m = 20; | ||
| 163 | n = 34; | ||
| 164 | k2 = -16382; | ||
| 165 | format = format64; | ||
| 166 | fformat = fformat64; | ||
| 167 | mnrflag = 3; | ||
| 168 | etrflag = 3; | ||
| 169 | printf( "Testing LONG DOUBLE precision.\n" ); | ||
| 170 | break; | ||
| 171 | #else | ||
| 172 | goto nodenorm; | ||
| 173 | #endif | ||
| 174 | } | ||
| 175 | |||
| 176 | asctoe( Ten, eten ); | ||
| 177 | /* 10^m - 1 */ | ||
| 178 | d2 = m; | ||
| 179 | e53toe( &d2, e1 ); | ||
| 180 | epow( eten, e1, maxm ); | ||
| 181 | esub( eone, maxm, maxm ); | ||
| 182 | |||
| 183 | /* test 1 */ | ||
| 184 | printf( "1. Checking 10^n - 1 for n = %d to %d.\n", -m, m ); | ||
| 185 | emov( eone, q5 ); | ||
| 186 | for( count=0; count<=m; count++ ) | ||
| 187 | { | ||
| 188 | esub( eone, q5, fullp ); | ||
| 189 | chkit( 1 ); | ||
| 190 | ediv( q5, eone, q2 ); | ||
| 191 | esub( eone, q2, fullp ); | ||
| 192 | chkit( 1 ); | ||
| 193 | emul( eten, q5, q5 ); | ||
| 194 | if( errtot >= MAXERR ) | ||
| 195 | { | ||
| 196 | printf( "%s", toomany ); | ||
| 197 | goto end1; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | end1: | ||
| 201 | printerr(); | ||
| 202 | |||
| 203 | |||
| 204 | /* test 2 */ | ||
| 205 | printf( "2. Checking powers of 10 from 10^-%d to 10^%d.\n", n, n ); | ||
| 206 | emov( eone, q5 ); | ||
| 207 | for( count=0; count<=n; count++ ) | ||
| 208 | { | ||
| 209 | emov( q5, fullp ); | ||
| 210 | chkit( 2 ); | ||
| 211 | ediv( q5, eone, fullp ); | ||
| 212 | chkit( 2 ); | ||
| 213 | emul( eten, q5, q5 ); | ||
| 214 | if( errtot >= MAXERR ) | ||
| 215 | { | ||
| 216 | printf( "%s", toomany ); | ||
| 217 | goto end2; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | end2: | ||
| 221 | printerr(); | ||
| 222 | |||
| 223 | /* test 3 */ | ||
| 224 | printf( "3. Checking (10^%d-1)*10^n from n = -%d to %d.\n", m, n, n ); | ||
| 225 | emov( eone, q5 ); | ||
| 226 | for( count= -n; count<=n; count++ ) | ||
| 227 | { | ||
| 228 | emul( maxm, q5, fullp ); | ||
| 229 | chkit( 3 ); | ||
| 230 | emov( q5, fullp ); | ||
| 231 | ediv( fullp, eone, fullp ); | ||
| 232 | emul( maxm, fullp, fullp ); | ||
| 233 | chkit( 3 ); | ||
| 234 | emul( eten, q5, q5 ); | ||
| 235 | if( errtot >= MAXERR ) | ||
| 236 | { | ||
| 237 | printf( "%s", toomany ); | ||
| 238 | goto end3; | ||
| 239 | } | ||
| 240 | } | ||
| 241 | end3: | ||
| 242 | printerr(); | ||
| 243 | |||
| 244 | |||
| 245 | |||
| 246 | /* test 4 */ | ||
| 247 | printf( "4. Checking powers of 2 from 2^-24 to 2^+56.\n" ); | ||
| 248 | d1 = -24.0; | ||
| 249 | e53toe( &d1, q1 ); | ||
| 250 | epow( etwo, q1, q5 ); | ||
| 251 | |||
| 252 | for( count = -24; count <= 56; count++ ) | ||
| 253 | { | ||
| 254 | emov( q5, fullp ); | ||
| 255 | chkit( 4 ); | ||
| 256 | emul( etwo, q5, q5 ); | ||
| 257 | if( errtot >= MAXERR ) | ||
| 258 | { | ||
| 259 | printf( "%s", toomany ); | ||
| 260 | goto end4; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | end4: | ||
| 264 | printerr(); | ||
| 265 | |||
| 266 | |||
| 267 | /* test 5 */ | ||
| 268 | printf( "5. Checking 2^n - 1 for n = 0 to %d.\n", mprec ); | ||
| 269 | emov( eone, q5 ); | ||
| 270 | for( count=0; count<=mprec; count++ ) | ||
| 271 | { | ||
| 272 | esub( eone, q5, fullp ); | ||
| 273 | chkit( 5 ); | ||
| 274 | emul( etwo, q5, q5 ); | ||
| 275 | if( errtot >= MAXERR ) | ||
| 276 | { | ||
| 277 | printf( "%s", toomany ); | ||
| 278 | goto end5; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | end5: | ||
| 282 | printerr(); | ||
| 283 | |||
| 284 | /* test 6 */ | ||
| 285 | printf( "6. Checking 2^n + 1 for n = 0 to %d.\n", mprec ); | ||
| 286 | emov( eone, q5 ); | ||
| 287 | for( count=0; count<=mprec; count++ ) | ||
| 288 | { | ||
| 289 | eadd( eone, q5, fullp ); | ||
| 290 | chkit( 6 ); | ||
| 291 | emul( etwo, q5, q5 ); | ||
| 292 | if( errtot >= MAXERR ) | ||
| 293 | { | ||
| 294 | printf( "%s", toomany ); | ||
| 295 | goto end6; | ||
| 296 | } | ||
| 297 | } | ||
| 298 | end6: | ||
| 299 | printerr(); | ||
| 300 | |||
| 301 | /* test 7 */ | ||
| 302 | printf( | ||
| 303 | "7. Checking %d values M * 10^N with random integer M and N,\n", | ||
| 304 | NRAND ); | ||
| 305 | printf(" 1 <= M <= 10^%d - 1 and -%d <= N <= +%d.\n", m, n, n ); | ||
| 306 | for( i=0; i<NRAND; i++ ) | ||
| 307 | { | ||
| 308 | mnrand( fullp ); | ||
| 309 | chkit( 7 ); | ||
| 310 | if( errtot >= MAXERR ) | ||
| 311 | { | ||
| 312 | printf( "%s", toomany ); | ||
| 313 | goto end7; | ||
| 314 | } | ||
| 315 | } | ||
| 316 | end7: | ||
| 317 | printerr(); | ||
| 318 | |||
| 319 | /* test 8 */ | ||
| 320 | printf("8. Checking critical rounding cases.\n" ); | ||
| 321 | for( i=0; i<20; i++ ) | ||
| 322 | { | ||
| 323 | mnrand( fullp ); | ||
| 324 | eabs( fullp ); | ||
| 325 | if( ecmp( fullp, eone ) < 0 ) | ||
| 326 | ediv( fullp, eone, fullp ); | ||
| 327 | efloor( fullp, fullp ); | ||
| 328 | eadd( ehalf, fullp, fullp ); | ||
| 329 | chkit( 8 ); | ||
| 330 | if( errtot >= MAXERR ) | ||
| 331 | { | ||
| 332 | printf( "%s", toomany ); | ||
| 333 | goto end8; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | end8: | ||
| 337 | printerr(); | ||
| 338 | |||
| 339 | |||
| 340 | |||
| 341 | /* test 9 */ | ||
| 342 | printf("9. Testing on %d random non-denormal values.\n", NRAND ); | ||
| 343 | for( i=0; i<NRAND; i++ ) | ||
| 344 | { | ||
| 345 | etrand( fullp ); | ||
| 346 | chkit( 9 ); | ||
| 347 | } | ||
| 348 | printerr(); | ||
| 349 | shownoncrit(); | ||
| 350 | |||
| 351 | /* test 10 */ | ||
| 352 | #if 0 | ||
| 353 | printf( | ||
| 354 | "Do you want to check denormal numbers in this precision ? (y/n) " ); | ||
| 355 | gets( str0 ); | ||
| 356 | if( str0[0] != 'y' ) | ||
| 357 | goto nodenorm; | ||
| 358 | #endif | ||
| 359 | |||
| 360 | printf( "10. Checking denormal numbers.\n" ); | ||
| 361 | |||
| 362 | /* Form 2^-starting power */ | ||
| 363 | d1 = k2; | ||
| 364 | e53toe( &d1, q1 ); | ||
| 365 | epow( etwo, q1, e1 ); | ||
| 366 | |||
| 367 | /* Find 2^-mprec less than starting power */ | ||
| 368 | d1 = -mprec + 4; | ||
| 369 | e53toe( &d1, q1 ); | ||
| 370 | epow( etwo, q1, e3 ); | ||
| 371 | emul( e1, e3, e3 ); | ||
| 372 | emov( e3, e2 ); | ||
| 373 | ediv( etwo, e2, e2 ); | ||
| 374 | |||
| 375 | while( ecmp(e1,e2) != 0 ) | ||
| 376 | { | ||
| 377 | eadd( e1, e2, fullp ); | ||
| 378 | switch( mprec ) | ||
| 379 | { | ||
| 380 | #if LDOUBLE | ||
| 381 | case 64: | ||
| 382 | etoe64( e1, &sprec64 ); | ||
| 383 | e64toe( &sprec64, q1 ); | ||
| 384 | etoe64( fullp, &prec64 ); | ||
| 385 | e64toe( &prec64, q2 ); | ||
| 386 | break; | ||
| 387 | #endif | ||
| 388 | #ifdef DEC | ||
| 389 | case 56: | ||
| 390 | #endif | ||
| 391 | case 53: | ||
| 392 | etoe53( e1, &sprec53 ); | ||
| 393 | e53toe( &sprec53, q1 ); | ||
| 394 | etoe53( fullp, &prec53 ); | ||
| 395 | e53toe( &prec53, q2 ); | ||
| 396 | break; | ||
| 397 | |||
| 398 | case 24: | ||
| 399 | etoe24( e1, &sprec24 ); | ||
| 400 | e24toe( &sprec24, q1 ); | ||
| 401 | etoe24( fullp, &prec24 ); | ||
| 402 | e24toe( &prec24, q2 ); | ||
| 403 | break; | ||
| 404 | } | ||
| 405 | if( ecmp( q2, ezero ) == 0 ) | ||
| 406 | goto maxden; | ||
| 407 | chkit(10); | ||
| 408 | if( ecmp(q1,q2) == 0 ) | ||
| 409 | { | ||
| 410 | ediv( etwo, e1, e1 ); | ||
| 411 | emov( e3, e2 ); | ||
| 412 | } | ||
| 413 | if( errtot >= MAXERR ) | ||
| 414 | { | ||
| 415 | printf( "%s", toomany ); | ||
| 416 | goto maxden; | ||
| 417 | } | ||
| 418 | ediv( etwo, e2, e2 ); | ||
| 419 | } | ||
| 420 | maxden: | ||
| 421 | printerr(); | ||
| 422 | nodenorm: | ||
| 423 | printf( "\n" ); | ||
| 424 | retval |= errscan | identerr | errprint; | ||
| 425 | } /* loop on precision */ | ||
| 426 | printf( "End of test.\n" ); | ||
| 427 | return (retval); | ||
| 428 | } | ||
| 429 | |||
| 430 | #if CHKINTERNAL | ||
| 431 | long double xprec64; | ||
| 432 | double xprec53; | ||
| 433 | float xprec24; | ||
| 434 | |||
| 435 | /* Check binary -> printf -> scanf -> binary identity | ||
| 436 | * of internal routines | ||
| 437 | */ | ||
| 438 | void chkinternal( ref, tst, string ) | ||
| 439 | unsigned short ref[], tst[]; | ||
| 440 | char *string; | ||
| 441 | { | ||
| 442 | |||
| 443 | if( ecmp(ref,tst) != 0 ) | ||
| 444 | { | ||
| 445 | printf( "internal identity compare error!\n" ); | ||
| 446 | chkid( ref, tst, string ); | ||
| 447 | } | ||
| 448 | } | ||
| 449 | #endif | ||
| 450 | |||
| 451 | |||
| 452 | /* Check binary -> printf -> scanf -> binary identity | ||
| 453 | */ | ||
| 454 | void chkid( print, scan, string ) | ||
| 455 | unsigned short print[], scan[]; | ||
| 456 | char *string; | ||
| 457 | { | ||
| 458 | /* Test printf-scanf identity */ | ||
| 459 | if( ecmp( print, scan ) != 0 ) | ||
| 460 | { | ||
| 461 | pvec( print, NE ); | ||
| 462 | printf( " ->printf-> %s ->scanf->\n", string ); | ||
| 463 | pvec( scan, NE ); | ||
| 464 | printf( " is not an identity.\n" ); | ||
| 465 | ++identerr; | ||
| 466 | } | ||
| 467 | } | ||
| 468 | |||
| 469 | |||
| 470 | /* Check scanf result | ||
| 471 | */ | ||
| 472 | void chkscan( ref, tst, string ) | ||
| 473 | unsigned short ref[], tst[]; | ||
| 474 | char *string; | ||
| 475 | { | ||
| 476 | /* Test scanf() */ | ||
| 477 | if( ecmp( ref, tst ) != 0 ) | ||
| 478 | { | ||
| 479 | printf( "scanf(%s) -> ", string ); | ||
| 480 | pvec( tst, NE ); | ||
| 481 | printf( "\n should be " ); | ||
| 482 | pvec( ref, NE ); | ||
| 483 | printf( ".\n" ); | ||
| 484 | ++errscan; | ||
| 485 | ++errtot; | ||
| 486 | } | ||
| 487 | } | ||
| 488 | |||
| 489 | |||
| 490 | /* Test printf() result | ||
| 491 | */ | ||
| 492 | void chkprint( ref, tst, string ) | ||
| 493 | unsigned short ref[], tst[]; | ||
| 494 | char *string; | ||
| 495 | { | ||
| 496 | if( ecmp(ref, tst) != 0 ) | ||
| 497 | { | ||
| 498 | printf( "printf( "); | ||
| 499 | pvec( ref, NE ); | ||
| 500 | printf( ") -> %s\n", string ); | ||
| 501 | printf( " = " ); | ||
| 502 | pvec( tst, NE ); | ||
| 503 | printf( ".\n" ); | ||
| 504 | ++errprint; | ||
| 505 | ++errtot; | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | |||
| 510 | /* Print array of n 16-bit shorts | ||
| 511 | */ | ||
| 512 | void pvec( x, n ) | ||
| 513 | unsigned short x[]; | ||
| 514 | int n; | ||
| 515 | { | ||
| 516 | int i; | ||
| 517 | |||
| 518 | for( i=0; i<n; i++ ) | ||
| 519 | { | ||
| 520 | printf( "%04x ", x[i] ); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 524 | /* Measure worst case printf rounding error | ||
| 525 | */ | ||
| 526 | void cmpprint( ref, tst ) | ||
| 527 | unsigned short ref[], tst[]; | ||
| 528 | { | ||
| 529 | unsigned short e[NE]; | ||
| 530 | |||
| 531 | if( ecmp( ref, ezero ) != 0 ) | ||
| 532 | { | ||
| 533 | esub( ref, tst, e ); | ||
| 534 | ediv( ref, e, e ); | ||
| 535 | eabs( e ); | ||
| 536 | if( ecmp( e, rprint ) > 0 ) | ||
| 537 | emov( e, rprint ); | ||
| 538 | } | ||
| 539 | } | ||
| 540 | |||
| 541 | /* Measure worst case scanf rounding error | ||
| 542 | */ | ||
| 543 | void cmpscan( ref, tst ) | ||
| 544 | unsigned short ref[], tst[]; | ||
| 545 | { | ||
| 546 | unsigned short er[NE]; | ||
| 547 | |||
| 548 | if( ecmp( ref, ezero ) != 0 ) | ||
| 549 | { | ||
| 550 | esub( ref, tst, er ); | ||
| 551 | ediv( ref, er, er ); | ||
| 552 | eabs( er ); | ||
| 553 | if( ecmp( er, rscan ) > 0 ) | ||
| 554 | emov( er, rscan ); | ||
| 555 | if( ecmp( er, ehalf ) > 0 ) | ||
| 556 | { | ||
| 557 | etoasc( tst, str1, 21 ); | ||
| 558 | printf( "Bad error: scanf(%s) = %s !\n", str0, str1 ); | ||
| 559 | } | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | /* Check rounded-down decimal string output of printf | ||
| 564 | */ | ||
| 565 | void cmptrunc( ref, tst ) | ||
| 566 | unsigned short ref[], tst[]; | ||
| 567 | { | ||
| 568 | if( ecmp( ref, tst ) != 0 ) | ||
| 569 | { | ||
| 570 | printf( "printf(%s%s%s, %s) -> %s\n", quo, tformat, quo, str1, str2 ); | ||
| 571 | printf( "should be %s .\n", str3 ); | ||
| 572 | errprint += 1; | ||
| 573 | } | ||
| 574 | } | ||
| 575 | |||
| 576 | |||
| 577 | void shownoncrit() | ||
| 578 | { | ||
| 579 | |||
| 580 | etoasc( rprint, str0, 3 ); | ||
| 581 | printf( "Maximum relative printf error found = %s .\n", str0 ); | ||
| 582 | etoasc( rscan, str0, 3 ); | ||
| 583 | printf( "Maximum relative scanf error found = %s .\n", str0 ); | ||
| 584 | } | ||
| 585 | |||
| 586 | |||
| 587 | |||
| 588 | /* Produce arguments and call comparison subroutines. | ||
| 589 | */ | ||
| 590 | void chkit( testno ) | ||
| 591 | int testno; | ||
| 592 | { | ||
| 593 | unsigned short t[NE], u[NE], v[NE]; | ||
| 594 | int j; | ||
| 595 | |||
| 596 | switch( mprec ) | ||
| 597 | { | ||
| 598 | #if LDOUBLE | ||
| 599 | case 64: | ||
| 600 | etoe64( fullp, &prec64 ); | ||
| 601 | e64toe( &prec64, rounded ); | ||
| 602 | #if CHKINTERNAL | ||
| 603 | e64toasc( &prec64, str1, SPREC ); | ||
| 604 | asctoe64( str1, &xprec64 ); | ||
| 605 | e64toe( &xprec64, t ); | ||
| 606 | chkinternal( rounded, t, str1 ); | ||
| 607 | #endif | ||
| 608 | /* check printf and scanf */ | ||
| 609 | sprintf( str2, format, prec64 ); | ||
| 610 | sscanf( str2, fformat, &sprec64 ); | ||
| 611 | e64toe( &sprec64, u ); | ||
| 612 | chkid( rounded, u, str2 ); | ||
| 613 | asctoe64( str2, &ssprec64 ); | ||
| 614 | e64toe( &ssprec64, v ); | ||
| 615 | chkscan( v, u, str2 ); | ||
| 616 | chkprint( rounded, v, str2 ); | ||
| 617 | if( testno < 8 ) | ||
| 618 | break; | ||
| 619 | /* rounding error measurement */ | ||
| 620 | etoasc( fullp, str0, 24 ); | ||
| 621 | etoe64( fullp, &ssprec64 ); | ||
| 622 | e64toe( &ssprec64, u ); | ||
| 623 | sprintf( str2, format, ssprec64 ); | ||
| 624 | asctoe( str2, t ); | ||
| 625 | cmpprint( u, t ); | ||
| 626 | sscanf( str0, fformat, &sprec64 ); | ||
| 627 | e64toe( &sprec64, t ); | ||
| 628 | cmpscan( fullp, t ); | ||
| 629 | if( testno < 8 ) | ||
| 630 | break; | ||
| 631 | /* strings rounded to less than maximum precision */ | ||
| 632 | e64toasc( &ssprec64, str1, 24 ); | ||
| 633 | for( j=SPREC-1; j>0; j-- ) | ||
| 634 | { | ||
| 635 | e64toasc( &ssprec64, str3, j ); | ||
| 636 | asctoe( str3, v ); | ||
| 637 | sprintf( tformat, "%s.%dLe", pct, j ); | ||
| 638 | sprintf( str2, tformat, ssprec64 ); | ||
| 639 | asctoe( str2, t ); | ||
| 640 | cmptrunc( v, t ); | ||
| 641 | } | ||
| 642 | break; | ||
| 643 | #endif | ||
| 644 | #ifdef DEC | ||
| 645 | case 56: | ||
| 646 | #endif | ||
| 647 | case 53: | ||
| 648 | etoe53( fullp, &prec53 ); | ||
| 649 | e53toe( &prec53, rounded ); | ||
| 650 | #if CHKINTERNAL | ||
| 651 | e53toasc( &prec53, str1, SPREC ); | ||
| 652 | asctoe53( str1, &xprec53 ); | ||
| 653 | e53toe( &xprec53, t ); | ||
| 654 | chkinternal( rounded, t, str1 ); | ||
| 655 | #endif | ||
| 656 | sprintf( str2, format, prec53 ); | ||
| 657 | sscanf( str2, fformat, &sprec53 ); | ||
| 658 | e53toe( &sprec53, u ); | ||
| 659 | chkid( rounded, u, str2 ); | ||
| 660 | asctoe53( str2, &ssprec53 ); | ||
| 661 | e53toe( &ssprec53, v ); | ||
| 662 | chkscan( v, u, str2 ); | ||
| 663 | chkprint( rounded, v, str2 ); | ||
| 664 | if( testno < 8 ) | ||
| 665 | break; | ||
| 666 | /* rounding error measurement */ | ||
| 667 | etoasc( fullp, str0, 24 ); | ||
| 668 | etoe53( fullp, &ssprec53 ); | ||
| 669 | e53toe( &ssprec53, u ); | ||
| 670 | sprintf( str2, format, ssprec53 ); | ||
| 671 | asctoe( str2, t ); | ||
| 672 | cmpprint( u, t ); | ||
| 673 | sscanf( str0, fformat, &sprec53 ); | ||
| 674 | e53toe( &sprec53, t ); | ||
| 675 | cmpscan( fullp, t ); | ||
| 676 | if( testno < 8 ) | ||
| 677 | break; | ||
| 678 | e53toasc( &ssprec53, str1, 24 ); | ||
| 679 | for( j=SPREC-1; j>0; j-- ) | ||
| 680 | { | ||
| 681 | e53toasc( &ssprec53, str3, j ); | ||
| 682 | asctoe( str3, v ); | ||
| 683 | sprintf( tformat, "%s.%de", pct, j ); | ||
| 684 | sprintf( str2, tformat, ssprec53 ); | ||
| 685 | asctoe( str2, t ); | ||
| 686 | cmptrunc( v, t ); | ||
| 687 | } | ||
| 688 | break; | ||
| 689 | |||
| 690 | case 24: | ||
| 691 | etoe24( fullp, &prec24 ); | ||
| 692 | e24toe( &prec24, rounded ); | ||
| 693 | #if CHKINTERNAL | ||
| 694 | e24toasc( &prec24, str1, SPREC ); | ||
| 695 | asctoe24( str1, &xprec24 ); | ||
| 696 | e24toe( &xprec24, t ); | ||
| 697 | chkinternal( rounded, t, str1 ); | ||
| 698 | #endif | ||
| 699 | sprintf( str2, format, prec24 ); | ||
| 700 | sscanf( str2, fformat, &sprec24 ); | ||
| 701 | e24toe( &sprec24, u ); | ||
| 702 | chkid( rounded, u, str2 ); | ||
| 703 | asctoe24( str2, &ssprec24 ); | ||
| 704 | e24toe( &ssprec24, v ); | ||
| 705 | chkscan( v, u, str2 ); | ||
| 706 | chkprint( rounded, v, str2 ); | ||
| 707 | if( testno < 8 ) | ||
| 708 | break; | ||
| 709 | /* rounding error measurement */ | ||
| 710 | etoasc( fullp, str0, 24 ); | ||
| 711 | etoe24( fullp, &ssprec24 ); | ||
| 712 | e24toe( &ssprec24, u ); | ||
| 713 | sprintf( str2, format, ssprec24 ); | ||
| 714 | asctoe( str2, t ); | ||
| 715 | cmpprint( u, t ); | ||
| 716 | sscanf( str0, fformat, &sprec24 ); | ||
| 717 | e24toe( &sprec24, t ); | ||
| 718 | cmpscan( fullp, t ); | ||
| 719 | /* | ||
| 720 | if( testno < 8 ) | ||
| 721 | break; | ||
| 722 | */ | ||
| 723 | e24toasc( &ssprec24, str1, 24 ); | ||
| 724 | for( j=SPREC-1; j>0; j-- ) | ||
| 725 | { | ||
| 726 | e24toasc( &ssprec24, str3, j ); | ||
| 727 | asctoe( str3, v ); | ||
| 728 | sprintf( tformat, "%s.%de", pct, j ); | ||
| 729 | sprintf( str2, tformat, ssprec24 ); | ||
| 730 | asctoe( str2, t ); | ||
| 731 | cmptrunc( v, t ); | ||
| 732 | } | ||
| 733 | break; | ||
| 734 | } | ||
| 735 | } | ||
| 736 | |||
| 737 | |||
| 738 | void printerr() | ||
| 739 | { | ||
| 740 | if( (errscan == 0) && (identerr == 0) && (errprint == 0) ) | ||
| 741 | printf( "No errors found.\n" ); | ||
| 742 | else | ||
| 743 | { | ||
| 744 | printf( "%d binary -> decimal errors found.\n", errprint ); | ||
| 745 | printf( "%d decimal -> binary errors found.\n", errscan ); | ||
| 746 | } | ||
| 747 | errscan = 0; /* reset for next test */ | ||
| 748 | identerr = 0; | ||
| 749 | errprint = 0; | ||
| 750 | errtot = 0; | ||
| 751 | } | ||
| 752 | |||
| 753 | |||
| 754 | /* Random number generator | ||
| 755 | * in the range M * 10^N, where 1 <= M <= 10^17 - 1 | ||
| 756 | * and -27 <= N <= +27. Test values of M are logarithmically distributed | ||
| 757 | * random integers; test values of N are uniformly distributed random integers. | ||
| 758 | */ | ||
| 759 | |||
| 760 | static char *fwidth = "1.036163291797320557783096e1"; /* log(sqrt(10^9-1)) */ | ||
| 761 | static char *dwidth = "1.957197329044938830915E1"; /* log(sqrt(10^17-1)) */ | ||
| 762 | static char *ldwidth = "2.302585092994045684017491e1"; /* log(sqrt(10^20-1)) */ | ||
| 763 | |||
| 764 | static char *a13 = "13.0"; | ||
| 765 | static char *a27 = "27.0"; | ||
| 766 | static char *a34 = "34.0"; | ||
| 767 | static char *a10m13 = "1.0e-13"; | ||
| 768 | static unsigned short LOW[ NE ], WIDTH[NE], e27[NE], e10m13[NE]; | ||
| 769 | |||
| 770 | |||
| 771 | void mnrand( erand ) | ||
| 772 | unsigned short erand[]; | ||
| 773 | { | ||
| 774 | unsigned short ea[NE], em[NE], en[NE], ex[NE]; | ||
| 775 | double x, a; | ||
| 776 | |||
| 777 | if( mnrflag ) | ||
| 778 | { | ||
| 779 | if( mnrflag == 3 ) | ||
| 780 | { | ||
| 781 | asctoe( ldwidth, WIDTH ); | ||
| 782 | asctoe( a34, e27 ); | ||
| 783 | } | ||
| 784 | if( mnrflag == 2 ) | ||
| 785 | { | ||
| 786 | asctoe( dwidth, WIDTH ); | ||
| 787 | asctoe( a27, e27 ); | ||
| 788 | } | ||
| 789 | if( mnrflag == 1 ) | ||
| 790 | { | ||
| 791 | asctoe( fwidth, WIDTH ); | ||
| 792 | asctoe( a13, e27 ); | ||
| 793 | } | ||
| 794 | asctoe( a10m13, e10m13 ); | ||
| 795 | mnrflag = 0; | ||
| 796 | } | ||
| 797 | drand( &x ); | ||
| 798 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
| 799 | esub( eone, ex, ex ); | ||
| 800 | emul( WIDTH, ex, ex ); | ||
| 801 | eexp( ex, ex ); /* x = exp(x); */ | ||
| 802 | |||
| 803 | drand( &a ); | ||
| 804 | e53toe( &a, ea ); | ||
| 805 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
| 806 | emul( e10m13, ea, ea ); | ||
| 807 | eabs( ea ); | ||
| 808 | eadd( ea, ex, ex ); /* add fuzz */ | ||
| 809 | emul( ex, ex, ex ); /* square it, to get range to 10^17 - 1 */ | ||
| 810 | efloor( ex, em ); /* this is M */ | ||
| 811 | |||
| 812 | /* Random power of 10 */ | ||
| 813 | drand( &a ); | ||
| 814 | e53toe( &a, ex ); | ||
| 815 | esub( eone, ex, ex ); /* y3 = 54.0 * ( y3 - 1.0 ) + 0.5; */ | ||
| 816 | emul( e27, ex, ex ); | ||
| 817 | eadd( ex, ex, ex ); | ||
| 818 | eadd( ehalf, ex, ex ); | ||
| 819 | efloor( ex, ex ); /* y3 = floor( y3 ) - 27.0; */ | ||
| 820 | esub( e27, ex, en ); /* this is N */ | ||
| 821 | epow( eten, en, ex ); | ||
| 822 | emul( ex, em, erand ); | ||
| 823 | } | ||
| 824 | |||
| 825 | /* -ln 2^16382 */ | ||
| 826 | char *ldemin = "-1.1355137111933024058873097E4"; | ||
| 827 | char *ldewid = "2.2710274223866048117746193E4"; | ||
| 828 | /* -ln 2^1022 */ | ||
| 829 | char *demin = "-7.0839641853226410622441123E2"; | ||
| 830 | char *dewid = "1.4167928370645282124488225E3"; | ||
| 831 | /* -ln 2^125 */ | ||
| 832 | char *femin = "-8.6643397569993163677154015E1"; | ||
| 833 | char *fewid = "1.7328679513998632735430803E2"; | ||
| 834 | |||
| 835 | void etrand( erand ) | ||
| 836 | unsigned short erand[]; | ||
| 837 | { | ||
| 838 | unsigned short ea[NE], ex[NE]; | ||
| 839 | double x, a; | ||
| 840 | |||
| 841 | if( etrflag ) | ||
| 842 | { | ||
| 843 | if( etrflag == 3 ) | ||
| 844 | { | ||
| 845 | asctoe( ldemin, LOW ); | ||
| 846 | asctoe( ldewid, WIDTH ); | ||
| 847 | asctoe( a34, e27 ); | ||
| 848 | } | ||
| 849 | if( etrflag == 2 ) | ||
| 850 | { | ||
| 851 | asctoe( demin, LOW ); | ||
| 852 | asctoe( dewid, WIDTH ); | ||
| 853 | asctoe( a27, e27 ); | ||
| 854 | } | ||
| 855 | if( etrflag == 1 ) | ||
| 856 | { | ||
| 857 | asctoe( femin, LOW ); | ||
| 858 | asctoe( fewid, WIDTH ); | ||
| 859 | asctoe( a13, e27 ); | ||
| 860 | } | ||
| 861 | asctoe( a10m13, e10m13 ); | ||
| 862 | etrflag = 0; | ||
| 863 | } | ||
| 864 | drand( &x ); | ||
| 865 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
| 866 | esub( eone, ex, ex ); | ||
| 867 | emul( WIDTH, ex, ex ); | ||
| 868 | eadd( LOW, ex, ex ); | ||
| 869 | eexp( ex, ex ); /* x = exp(x); */ | ||
| 870 | |||
| 871 | /* add fuzz | ||
| 872 | */ | ||
| 873 | drand( &a ); | ||
| 874 | e53toe( &a, ea ); | ||
| 875 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
| 876 | emul( e10m13, ea, ea ); | ||
| 877 | if( ecmp( ex, ezero ) > 0 ) | ||
| 878 | eneg( ea ); | ||
| 879 | eadd( ea, ex, erand ); | ||
| 880 | } | ||
| 881 | |||
diff --git a/src/regress/lib/libc/cephes/mconf.h b/src/regress/lib/libc/cephes/mconf.h deleted file mode 100644 index 410849c355..0000000000 --- a/src/regress/lib/libc/cephes/mconf.h +++ /dev/null | |||
| @@ -1,189 +0,0 @@ | |||
| 1 | /* $OpenBSD: mconf.h,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* mconf.h | ||
| 20 | * | ||
| 21 | * Common include file for math routines | ||
| 22 | * | ||
| 23 | * | ||
| 24 | * | ||
| 25 | * SYNOPSIS: | ||
| 26 | * | ||
| 27 | * #include "mconf.h" | ||
| 28 | * | ||
| 29 | * | ||
| 30 | * | ||
| 31 | * DESCRIPTION: | ||
| 32 | * | ||
| 33 | * This file contains definitions for error codes that are | ||
| 34 | * passed to the common error handling routine mtherr() | ||
| 35 | * (which see). | ||
| 36 | * | ||
| 37 | * The file also includes a conditional assembly definition | ||
| 38 | * for the type of computer arithmetic (IEEE, DEC, Motorola | ||
| 39 | * IEEE, or UNKnown). | ||
| 40 | * | ||
| 41 | * For Digital Equipment PDP-11 and VAX computers, certain | ||
| 42 | * IBM systems, and others that use numbers with a 56-bit | ||
| 43 | * significand, the symbol DEC should be defined. In this | ||
| 44 | * mode, most floating point constants are given as arrays | ||
| 45 | * of octal integers to eliminate decimal to binary conversion | ||
| 46 | * errors that might be introduced by the compiler. | ||
| 47 | * | ||
| 48 | * For little-endian computers, such as IBM PC, that follow the | ||
| 49 | * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE | ||
| 50 | * Std 754-1985), the symbol IBMPC should be defined. These | ||
| 51 | * numbers have 53-bit significands. In this mode, constants | ||
| 52 | * are provided as arrays of hexadecimal 16 bit integers. | ||
| 53 | * | ||
| 54 | * Big-endian IEEE format is denoted MIEEE. On some RISC | ||
| 55 | * systems such as Sun SPARC, double precision constants | ||
| 56 | * must be stored on 8-byte address boundaries. Since integer | ||
| 57 | * arrays may be aligned differently, the MIEEE configuration | ||
| 58 | * may fail on such machines. | ||
| 59 | * | ||
| 60 | * To accommodate other types of computer arithmetic, all | ||
| 61 | * constants are also provided in a normal decimal radix | ||
| 62 | * which one can hope are correctly converted to a suitable | ||
| 63 | * format by the available C language compiler. To invoke | ||
| 64 | * this mode, define the symbol UNK. | ||
| 65 | * | ||
| 66 | * An important difference among these modes is a predefined | ||
| 67 | * set of machine arithmetic constants for each. The numbers | ||
| 68 | * MACHEP (the machine roundoff error), MAXNUM (largest number | ||
| 69 | * represented), and several other parameters are preset by | ||
| 70 | * the configuration symbol. Check the file const.c to | ||
| 71 | * ensure that these values are correct for your computer. | ||
| 72 | * | ||
| 73 | * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL | ||
| 74 | * may fail on many systems. Verify that they are supposed | ||
| 75 | * to work on your computer. | ||
| 76 | */ | ||
| 77 | |||
| 78 | #include <sys/types.h> | ||
| 79 | #include <endian.h> | ||
| 80 | |||
| 81 | /* Constant definitions for math error conditions | ||
| 82 | */ | ||
| 83 | |||
| 84 | #define DOMAIN 1 /* argument domain error */ | ||
| 85 | #define SING 2 /* argument singularity */ | ||
| 86 | #define OVERFLOW 3 /* overflow range error */ | ||
| 87 | #define UNDERFLOW 4 /* underflow range error */ | ||
| 88 | #define TLOSS 5 /* total loss of precision */ | ||
| 89 | #define PLOSS 6 /* partial loss of precision */ | ||
| 90 | |||
| 91 | #define EDOM 33 | ||
| 92 | #define ERANGE 34 | ||
| 93 | |||
| 94 | /* Complex numeral. */ | ||
| 95 | typedef struct | ||
| 96 | { | ||
| 97 | double r; | ||
| 98 | double i; | ||
| 99 | } cmplx; | ||
| 100 | |||
| 101 | /* Long double complex numeral. */ | ||
| 102 | typedef struct | ||
| 103 | { | ||
| 104 | double r; | ||
| 105 | double i; | ||
| 106 | } cmplxl; | ||
| 107 | |||
| 108 | /* Type of computer arithmetic */ | ||
| 109 | |||
| 110 | /* PDP-11, Pro350, VAX: | ||
| 111 | */ | ||
| 112 | #ifdef __vax__ | ||
| 113 | #define DEC 1 | ||
| 114 | #endif /* __vax__ */ | ||
| 115 | |||
| 116 | /* Intel IEEE, low order words come first: | ||
| 117 | */ | ||
| 118 | /* #define IBMPC 1 */ | ||
| 119 | |||
| 120 | /* Motorola IEEE, high order words come first | ||
| 121 | * (Sun 680x0 workstation): | ||
| 122 | */ | ||
| 123 | /* #define MIEEE 1 */ | ||
| 124 | |||
| 125 | /* UNKnown arithmetic, invokes coefficients given in | ||
| 126 | * normal decimal format. Beware of range boundary | ||
| 127 | * problems (MACHEP, MAXLOG, etc. in const.c) and | ||
| 128 | * roundoff problems in pow.c: | ||
| 129 | * (Sun SPARCstation) | ||
| 130 | */ | ||
| 131 | #ifndef __vax__ | ||
| 132 | #define UNK 1 | ||
| 133 | #endif /* !__vax__ */ | ||
| 134 | |||
| 135 | /* If you define UNK, then be sure to set BIGENDIAN properly. */ | ||
| 136 | #if BYTE_ORDER == BIG_ENDIAN | ||
| 137 | #define BIGENDIAN 1 | ||
| 138 | #endif /* BYTE_ORDER == BIG_ENDIAN */ | ||
| 139 | |||
| 140 | /* Define this `volatile' if your compiler thinks | ||
| 141 | * that floating point arithmetic obeys the associative | ||
| 142 | * and distributive laws. It will defeat some optimizations | ||
| 143 | * (but probably not enough of them). | ||
| 144 | * | ||
| 145 | * #define VOLATILE volatile | ||
| 146 | */ | ||
| 147 | #define VOLATILE | ||
| 148 | |||
| 149 | /* For 12-byte long doubles on an i386, pad a 16-bit short 0 | ||
| 150 | * to the end of real constants initialized by integer arrays. | ||
| 151 | * | ||
| 152 | * #define XPD 0, | ||
| 153 | * | ||
| 154 | * Otherwise, the type is 10 bytes long and XPD should be | ||
| 155 | * defined blank (e.g., Microsoft C). | ||
| 156 | * | ||
| 157 | * #define XPD | ||
| 158 | */ | ||
| 159 | #define XPD 0, | ||
| 160 | |||
| 161 | /* Define to support tiny denormal numbers, else undefine. */ | ||
| 162 | #ifndef __vax__ | ||
| 163 | #define DENORMAL 1 | ||
| 164 | #endif /* !__vax__ */ | ||
| 165 | |||
| 166 | /* Define to ask for infinity support, else undefine. */ | ||
| 167 | #ifndef __vax__ | ||
| 168 | #define INFINITIES 1 | ||
| 169 | #endif /* !__vax__ */ | ||
| 170 | |||
| 171 | /* Define to ask for support of numbers that are Not-a-Number, | ||
| 172 | else undefine. This may automatically define INFINITIES in some files. */ | ||
| 173 | #ifndef __vax__ | ||
| 174 | #define NANS 1 | ||
| 175 | #endif /* !__vax__ */ | ||
| 176 | |||
| 177 | /* Define to distinguish between -0.0 and +0.0. */ | ||
| 178 | #define MINUSZERO 1 | ||
| 179 | |||
| 180 | /* Define 1 for ANSI C atan2() function | ||
| 181 | See atan.c and clog.c. */ | ||
| 182 | #define ANSIC 1 | ||
| 183 | |||
| 184 | int mtherr(); | ||
| 185 | |||
| 186 | /* Variable for error reporting. See mtherr.c. */ | ||
| 187 | extern int merror; | ||
| 188 | |||
| 189 | int drand(double *); | ||
diff --git a/src/regress/lib/libc/cephes/mtherr.c b/src/regress/lib/libc/cephes/mtherr.c deleted file mode 100644 index 9a47a198bd..0000000000 --- a/src/regress/lib/libc/cephes/mtherr.c +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | /* $OpenBSD: mtherr.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 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 | /* mtherr.c | ||
| 20 | * | ||
| 21 | * Library common error handling routine | ||
| 22 | * | ||
| 23 | * | ||
| 24 | * | ||
| 25 | * SYNOPSIS: | ||
| 26 | * | ||
| 27 | * char *fctnam; | ||
| 28 | * int code; | ||
| 29 | * int mtherr(); | ||
| 30 | * | ||
| 31 | * mtherr( fctnam, code ); | ||
| 32 | * | ||
| 33 | * | ||
| 34 | * | ||
| 35 | * DESCRIPTION: | ||
| 36 | * | ||
| 37 | * This routine may be called to report one of the following | ||
| 38 | * error conditions (in the include file mconf.h). | ||
| 39 | * | ||
| 40 | * Mnemonic Value Significance | ||
| 41 | * | ||
| 42 | * DOMAIN 1 argument domain error | ||
| 43 | * SING 2 function singularity | ||
| 44 | * OVERFLOW 3 overflow range error | ||
| 45 | * UNDERFLOW 4 underflow range error | ||
| 46 | * TLOSS 5 total loss of precision | ||
| 47 | * PLOSS 6 partial loss of precision | ||
| 48 | * EDOM 33 Unix domain error code | ||
| 49 | * ERANGE 34 Unix range error code | ||
| 50 | * | ||
| 51 | * The default version of the file prints the function name, | ||
| 52 | * passed to it by the pointer fctnam, followed by the | ||
| 53 | * error condition. The display is directed to the standard | ||
| 54 | * output device. The routine then returns to the calling | ||
| 55 | * program. Users may wish to modify the program to abort by | ||
| 56 | * calling exit() under severe error conditions such as domain | ||
| 57 | * errors. | ||
| 58 | * | ||
| 59 | * Since all error conditions pass control to this function, | ||
| 60 | * the display may be easily changed, eliminated, or directed | ||
| 61 | * to an error logging device. | ||
| 62 | * | ||
| 63 | * SEE ALSO: | ||
| 64 | * | ||
| 65 | * mconf.h | ||
| 66 | * | ||
| 67 | */ | ||
| 68 | |||
| 69 | #include <stdio.h> | ||
| 70 | #include "mconf.h" | ||
| 71 | |||
| 72 | int merror = 0; | ||
| 73 | |||
| 74 | /* Notice: the order of appearance of the following | ||
| 75 | * messages is bound to the error codes defined | ||
| 76 | * in mconf.h. | ||
| 77 | */ | ||
| 78 | static char *ermsg[7] = { | ||
| 79 | "unknown", /* error code 0 */ | ||
| 80 | "domain", /* error code 1 */ | ||
| 81 | "singularity", /* et seq. */ | ||
| 82 | "overflow", | ||
| 83 | "underflow", | ||
| 84 | "total loss of precision", | ||
| 85 | "partial loss of precision" | ||
| 86 | }; | ||
| 87 | |||
| 88 | |||
| 89 | int mtherr( name, code ) | ||
| 90 | char *name; | ||
| 91 | int code; | ||
| 92 | { | ||
| 93 | |||
| 94 | /* Display string passed by calling program, | ||
| 95 | * which is supposed to be the name of the | ||
| 96 | * function in which the error occurred: | ||
| 97 | */ | ||
| 98 | printf( "\n%s ", name ); | ||
| 99 | |||
| 100 | /* Set global error message word */ | ||
| 101 | merror = code; | ||
| 102 | |||
| 103 | /* Display error message defined | ||
| 104 | * by the code argument. | ||
| 105 | */ | ||
| 106 | if( (code <= 0) || (code >= 7) ) | ||
| 107 | code = 0; | ||
| 108 | printf( "%s error\n", ermsg[code] ); | ||
| 109 | |||
| 110 | /* Return to calling | ||
| 111 | * program | ||
| 112 | */ | ||
| 113 | return( 0 ); | ||
| 114 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/Makefile b/src/regress/lib/libc/cxa-atexit/Makefile deleted file mode 100644 index a2821e01d3..0000000000 --- a/src/regress/lib/libc/cxa-atexit/Makefile +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2013/08/06 19:11:53 miod Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= libgd1 libgd2 test1 | ||
| 4 | |||
| 5 | install: | ||
| 6 | |||
| 7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile deleted file mode 100644 index 958b726d28..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
| 2 | |||
| 3 | LIB=gd1 | ||
| 4 | SRCS= gd1.C | ||
| 5 | NOPROFILE=yes | ||
| 6 | |||
| 7 | regress: all | ||
| 8 | |||
| 9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C deleted file mode 100644 index b3ecd56d91..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | /* $OpenBSD: gd1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 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 | |||
| 21 | extern int check1; | ||
| 22 | |||
| 23 | struct global_destructor_test_obj1 { | ||
| 24 | inline ~global_destructor_test_obj1() { | ||
| 25 | check1 = 0; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | extern "C" void gd_test1() | ||
| 30 | { | ||
| 31 | static global_destructor_test_obj1 gdt; | ||
| 32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version deleted file mode 100644 index 97c9f92d6b..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version +++ /dev/null | |||
| @@ -1,2 +0,0 @@ | |||
| 1 | major=0 | ||
| 2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile deleted file mode 100644 index 7ca21d8bd2..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
| 2 | |||
| 3 | LIB=gd2 | ||
| 4 | SRCS= gd2.C | ||
| 5 | NOPROFILE=yes | ||
| 6 | |||
| 7 | regress: all | ||
| 8 | |||
| 9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C deleted file mode 100644 index 69e7ffb220..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | /* $OpenBSD: gd2.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 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 | |||
| 21 | extern int check2; | ||
| 22 | |||
| 23 | struct global_destructor_test_obj2 { | ||
| 24 | inline ~global_destructor_test_obj2() { | ||
| 25 | check2 = 0; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | extern "C" void gd_test2() | ||
| 30 | { | ||
| 31 | static global_destructor_test_obj2 gdt; | ||
| 32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version deleted file mode 100644 index 97c9f92d6b..0000000000 --- a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version +++ /dev/null | |||
| @@ -1,2 +0,0 @@ | |||
| 1 | major=0 | ||
| 2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/Makefile b/src/regress/lib/libc/cxa-atexit/test1/Makefile deleted file mode 100644 index 162922b35a..0000000000 --- a/src/regress/lib/libc/cxa-atexit/test1/Makefile +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2015/05/29 04:17:11 miod Exp $ | ||
| 2 | |||
| 3 | .include <bsd.obj.mk> | ||
| 4 | |||
| 5 | GD1_DIR=${.CURDIR}/../libgd1 | ||
| 6 | GD1_OBJDIR!= if [ -d $(GD1_DIR)/${__objdir} ]; then \ | ||
| 7 | echo "$(GD1_DIR)/${__objdir}"; \ | ||
| 8 | else \ | ||
| 9 | echo "$(GD1_DIR)"; \ | ||
| 10 | fi | ||
| 11 | |||
| 12 | GD2_DIR=${.CURDIR}/../libgd2 | ||
| 13 | GD2_OBJDIR!= if [ -d $(GD2_DIR)/${__objdir} ]; then \ | ||
| 14 | echo "$(GD2_DIR)/${__objdir}"; \ | ||
| 15 | else \ | ||
| 16 | echo "$(GD2_DIR)"; \ | ||
| 17 | fi | ||
| 18 | |||
| 19 | PROG= test1 | ||
| 20 | |||
| 21 | SRCS= test1.C | ||
| 22 | |||
| 23 | CXXFLAGS+= -DLIBGD1="\"$(GD1_OBJDIR)/libgd1.so\"" | ||
| 24 | CXXFLAGS+= -DLIBGD2="\"$(GD2_OBJDIR)/libgd2.so\"" | ||
| 25 | LDFLAGS+= -Wl,-E | ||
| 26 | |||
| 27 | NOMAN= | ||
| 28 | |||
| 29 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/test1.C b/src/regress/lib/libc/cxa-atexit/test1/test1.C deleted file mode 100644 index 75fb967a90..0000000000 --- a/src/regress/lib/libc/cxa-atexit/test1/test1.C +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | /* $OpenBSD: test1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
| 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 <dlfcn.h> | ||
| 20 | #include <err.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | |||
| 23 | int check1, check2; | ||
| 24 | |||
| 25 | int | ||
| 26 | main() | ||
| 27 | { | ||
| 28 | void *libgd1, *libgd2; | ||
| 29 | void (*gd_test)(); | ||
| 30 | int i; | ||
| 31 | |||
| 32 | for (i=0; i < 50; i++) { | ||
| 33 | check1 = check2 = 1; | ||
| 34 | |||
| 35 | libgd1 = dlopen(LIBGD1, RTLD_LAZY); | ||
| 36 | if (libgd1 == NULL) | ||
| 37 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD1); | ||
| 38 | |||
| 39 | gd_test = (void (*)())dlsym(libgd1, "gd_test1"); | ||
| 40 | if (gd_test == NULL) | ||
| 41 | errx(1, "dlsym(libgd1, \"gd_test1\") FAILED\n"); | ||
| 42 | |||
| 43 | (*gd_test)(); | ||
| 44 | |||
| 45 | libgd2 = dlopen(LIBGD2, RTLD_LAZY); | ||
| 46 | if (libgd2 == NULL) | ||
| 47 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD2); | ||
| 48 | |||
| 49 | gd_test = (void (*)())dlsym(libgd2, "gd_test2"); | ||
| 50 | if (gd_test == NULL) | ||
| 51 | errx(1, "dlsym(libgd2, \"gd_test2\") FAILED\n"); | ||
| 52 | |||
| 53 | (*gd_test)(); | ||
| 54 | |||
| 55 | dlclose(libgd1); | ||
| 56 | dlclose(libgd2); | ||
| 57 | |||
| 58 | if (check1 || check2) | ||
| 59 | errx(1, "global destructors not called\n"); | ||
| 60 | } | ||
| 61 | |||
| 62 | return (0); | ||
| 63 | } | ||
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile deleted file mode 100644 index 7d2882594d..0000000000 --- a/src/regress/lib/libc/db/Makefile +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.10 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= dbtest | ||
| 5 | |||
| 6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | ||
| 7 | # for this to work, libc must be compiled with -DSTATISTICS as well | ||
| 8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG | ||
| 9 | CLEANFILES+= t1 t2 t3 log | ||
| 10 | |||
| 11 | DBTARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 20 | ||
| 12 | |||
| 13 | .for DT in ${DBTARGETS} | ||
| 14 | db-${DT}: ${PROG} | ||
| 15 | sh ${.CURDIR}/run.test ${DT} | ||
| 16 | REGRESS_TARGETS+=db-${DT} | ||
| 17 | .PHONY: db-${DT} | ||
| 18 | .endfor | ||
| 19 | |||
| 20 | REGRESS_SLOW_TARGETS+=db-3 db-12 db-20 | ||
| 21 | |||
| 22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README deleted file mode 100644 index 23a1b77221..0000000000 --- a/src/regress/lib/libc/db/README +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | # $OpenBSD: README,v 1.3 2001/01/29 02:05:40 niklas Exp $ | ||
| 2 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ | ||
| 3 | # @(#)README 8.8 (Berkeley) 7/31/94 | ||
| 4 | |||
| 5 | To run the tests, enter "make regress". | ||
| 6 | |||
| 7 | Fairly large files (the command files) are built in this directory during | ||
| 8 | the test runs, and even larger files (the database files) are created in | ||
| 9 | "/var/tmp". If the latter directory doesn't exist, set the environmental | ||
| 10 | variable TMPDIR to a directory where the files can be built. | ||
| 11 | |||
| 12 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
| 13 | The script file consists of lines with an initial character which is | ||
| 14 | the command for that line, or an initial character indicating a key | ||
| 15 | or data entry for a previous command. | ||
| 16 | |||
| 17 | Legal command characters are as follows: | ||
| 18 | |||
| 19 | c: compare a record | ||
| 20 | + must be followed by [kK][dD]; the data value in the database | ||
| 21 | associated with the specified key is compared to the specified | ||
| 22 | data value. | ||
| 23 | e: echo a string | ||
| 24 | + writes out the rest of the line into the output file; if the | ||
| 25 | last character is not a carriage-return, a newline is appended. | ||
| 26 | f: set the flags for the next command | ||
| 27 | + no value zero's the flags | ||
| 28 | g: do a get command | ||
| 29 | + must be followed by [kK] | ||
| 30 | + writes out the retrieved data DBT. | ||
| 31 | o [r]: dump [reverse] | ||
| 32 | + dump the database out, if 'r' is set, in reverse order. | ||
| 33 | p: do a put command | ||
| 34 | + must be followed by [kK][dD] | ||
| 35 | r: do a del command | ||
| 36 | + must be followed by [kK] unless R_CURSOR flag set. | ||
| 37 | S: sync the database | ||
| 38 | s: do a seq command | ||
| 39 | + must be followed by [kK] if R_CURSOR flag set. | ||
| 40 | + writes out the retrieved data DBT. | ||
| 41 | |||
| 42 | Legal key/data characters are as follows: | ||
| 43 | |||
| 44 | D [file]: data file | ||
| 45 | + set the current data value to the contents of the file | ||
| 46 | d [data]: | ||
| 47 | + set the current key value to the contents of the line. | ||
| 48 | K [file]: key file | ||
| 49 | + set the current key value to the contents of the file | ||
| 50 | k [data]: | ||
| 51 | + set the current key value to the contents of the line. | ||
| 52 | |||
| 53 | Blank lines, lines with leading white space, and lines with leading | ||
| 54 | hash marks (#) are ignored. | ||
| 55 | |||
| 56 | Options to dbtest are as follows: | ||
| 57 | |||
| 58 | -d: Set the DB_LOCK flag. | ||
| 59 | -f: Use the file argument as the database file. | ||
| 60 | -i: Use the rest of the argument to set elements in the info | ||
| 61 | structure. If the type is btree, then "-i cachesize=10240" | ||
| 62 | will set BTREEINFO.cachesize to 10240. | ||
| 63 | -o: The rest of the argument is the output file instead of | ||
| 64 | using stdout. | ||
| 65 | -s: Don't delete the database file before opening it, i.e. | ||
| 66 | use the database file from a previous run. | ||
| 67 | |||
| 68 | Dbtest requires two arguments, the type of access "hash", "recno" | ||
| 69 | or "btree", and the script name or "-" to indicate stdin. | ||
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c deleted file mode 100644 index 6a79e4c187..0000000000 --- a/src/regress/lib/libc/db/dbtest.c +++ /dev/null | |||
| @@ -1,731 +0,0 @@ | |||
| 1 | /* $OpenBSD: dbtest.c,v 1.16 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1992, 1993, 1994 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. Neither the name of the University nor the names of its contributors | ||
| 17 | * may be used to endorse or promote products derived from this software | ||
| 18 | * without specific prior written permission. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | #include <sys/param.h> | ||
| 34 | #include <sys/stat.h> | ||
| 35 | |||
| 36 | #include <ctype.h> | ||
| 37 | #include <errno.h> | ||
| 38 | #include <fcntl.h> | ||
| 39 | #include <stdint.h> | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <stdarg.h> | ||
| 44 | #include <unistd.h> | ||
| 45 | |||
| 46 | #include <db.h> | ||
| 47 | |||
| 48 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | ||
| 49 | |||
| 50 | void compare(DBT *, DBT *); | ||
| 51 | DBTYPE dbtype(char *); | ||
| 52 | void dump(DB *, int); | ||
| 53 | void __dead dberr(const char *, ...); | ||
| 54 | void get(DB *, DBT *); | ||
| 55 | void getdata(DB *, DBT *, DBT *); | ||
| 56 | void put(DB *, DBT *, DBT *); | ||
| 57 | void rem(DB *, DBT *); | ||
| 58 | char *sflags(int); | ||
| 59 | void synk(DB *); | ||
| 60 | void *rfile(char *, size_t *); | ||
| 61 | void seq(DB *, DBT *); | ||
| 62 | u_int setflags(char *); | ||
| 63 | void *setinfo(DBTYPE, char *); | ||
| 64 | void __dead usage(void); | ||
| 65 | void *xmalloc(char *, size_t); | ||
| 66 | |||
| 67 | DBTYPE type; /* Database type. */ | ||
| 68 | void *infop; /* Iflags. */ | ||
| 69 | u_long lineno; /* Current line in test script. */ | ||
| 70 | u_int flags; /* Current DB flags. */ | ||
| 71 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
| 72 | |||
| 73 | DB *XXdbp; /* Global for gdb. */ | ||
| 74 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
| 75 | |||
| 76 | int | ||
| 77 | main(int argc, char *argv[]) | ||
| 78 | { | ||
| 79 | extern int optind; | ||
| 80 | extern char *optarg; | ||
| 81 | enum S command, state; | ||
| 82 | DB *dbp; | ||
| 83 | DBT data, key, keydata; | ||
| 84 | size_t len; | ||
| 85 | int ch, oflags, sflag; | ||
| 86 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; | ||
| 87 | |||
| 88 | infoarg = NULL; | ||
| 89 | fname = NULL; | ||
| 90 | oflags = O_CREAT | O_RDWR; | ||
| 91 | sflag = 0; | ||
| 92 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) | ||
| 93 | switch (ch) { | ||
| 94 | case 'f': | ||
| 95 | fname = optarg; | ||
| 96 | break; | ||
| 97 | case 'i': | ||
| 98 | infoarg = optarg; | ||
| 99 | break; | ||
| 100 | case 'l': | ||
| 101 | oflags |= DB_LOCK; | ||
| 102 | break; | ||
| 103 | case 'o': | ||
| 104 | if ((ofd = open(optarg, | ||
| 105 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | ||
| 106 | dberr("%s: %s", optarg, strerror(errno)); | ||
| 107 | break; | ||
| 108 | case 's': | ||
| 109 | sflag = 1; | ||
| 110 | break; | ||
| 111 | case '?': | ||
| 112 | default: | ||
| 113 | usage(); | ||
| 114 | } | ||
| 115 | argc -= optind; | ||
| 116 | argv += optind; | ||
| 117 | |||
| 118 | if (argc != 2) | ||
| 119 | usage(); | ||
| 120 | |||
| 121 | /* Set the type. */ | ||
| 122 | type = dbtype(*argv++); | ||
| 123 | |||
| 124 | /* Open the descriptor file. */ | ||
| 125 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) | ||
| 126 | dberr("%s: %s", *argv, strerror(errno)); | ||
| 127 | |||
| 128 | /* Set up the db structure as necessary. */ | ||
| 129 | if (infoarg == NULL) | ||
| 130 | infop = NULL; | ||
| 131 | else | ||
| 132 | for (p = strtok(infoarg, ",\t "); p != NULL; | ||
| 133 | p = strtok(0, ",\t ")) | ||
| 134 | if (*p != '\0') | ||
| 135 | infop = setinfo(type, p); | ||
| 136 | |||
| 137 | /* | ||
| 138 | * Open the DB. Delete any preexisting copy, you almost never | ||
| 139 | * want it around, and it often screws up tests. | ||
| 140 | */ | ||
| 141 | if (fname == NULL) { | ||
| 142 | p = getenv("TMPDIR"); | ||
| 143 | if (p == NULL) | ||
| 144 | p = "/var/tmp"; | ||
| 145 | (void)snprintf(buf, sizeof buf, "%s/__dbtest", p); | ||
| 146 | fname = buf; | ||
| 147 | (void)unlink(buf); | ||
| 148 | } else if (!sflag) | ||
| 149 | (void)unlink(fname); | ||
| 150 | |||
| 151 | if ((dbp = dbopen(fname, | ||
| 152 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | ||
| 153 | dberr("dbopen: %s", strerror(errno)); | ||
| 154 | XXdbp = dbp; | ||
| 155 | |||
| 156 | state = COMMAND; | ||
| 157 | for (lineno = 1; | ||
| 158 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | ||
| 159 | /* Delete the newline, displaying the key/data is easier. */ | ||
| 160 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) | ||
| 161 | *t = '\0'; | ||
| 162 | if ((len = strlen(buf)) == 0 || isspace((unsigned char)*p) || *p == '#') | ||
| 163 | continue; | ||
| 164 | |||
| 165 | /* Convenient gdb break point. */ | ||
| 166 | if (XXlineno == lineno) | ||
| 167 | XXlineno = 1; | ||
| 168 | switch (*p) { | ||
| 169 | case 'c': /* compare */ | ||
| 170 | if (state != COMMAND) | ||
| 171 | dberr("line %lu: not expecting command", | ||
| 172 | lineno); | ||
| 173 | state = KEY; | ||
| 174 | command = COMPARE; | ||
| 175 | break; | ||
| 176 | case 'e': /* echo */ | ||
| 177 | if (state != COMMAND) | ||
| 178 | dberr("line %lu: not expecting command", | ||
| 179 | lineno); | ||
| 180 | /* Don't display the newline, if CR at EOL. */ | ||
| 181 | if (p[len - 2] == '\r') | ||
| 182 | --len; | ||
| 183 | if (write(ofd, p + 1, len - 1) != len - 1 || | ||
| 184 | write(ofd, "\n", 1) != 1) | ||
| 185 | dberr("write: %s", strerror(errno)); | ||
| 186 | break; | ||
| 187 | case 'g': /* get */ | ||
| 188 | if (state != COMMAND) | ||
| 189 | dberr("line %lu: not expecting command", | ||
| 190 | lineno); | ||
| 191 | state = KEY; | ||
| 192 | command = GET; | ||
| 193 | break; | ||
| 194 | case 'p': /* put */ | ||
| 195 | if (state != COMMAND) | ||
| 196 | dberr("line %lu: not expecting command", | ||
| 197 | lineno); | ||
| 198 | state = KEY; | ||
| 199 | command = PUT; | ||
| 200 | break; | ||
| 201 | case 'r': /* remove */ | ||
| 202 | if (state != COMMAND) | ||
| 203 | dberr("line %lu: not expecting command", | ||
| 204 | lineno); | ||
| 205 | if (flags == R_CURSOR) { | ||
| 206 | rem(dbp, &key); | ||
| 207 | state = COMMAND; | ||
| 208 | } else { | ||
| 209 | state = KEY; | ||
| 210 | command = REMOVE; | ||
| 211 | } | ||
| 212 | break; | ||
| 213 | case 'S': /* sync */ | ||
| 214 | if (state != COMMAND) | ||
| 215 | dberr("line %lu: not expecting command", | ||
| 216 | lineno); | ||
| 217 | synk(dbp); | ||
| 218 | state = COMMAND; | ||
| 219 | break; | ||
| 220 | case 's': /* seq */ | ||
| 221 | if (state != COMMAND) | ||
| 222 | dberr("line %lu: not expecting command", | ||
| 223 | lineno); | ||
| 224 | if (flags == R_CURSOR) { | ||
| 225 | state = KEY; | ||
| 226 | command = SEQ; | ||
| 227 | } else | ||
| 228 | seq(dbp, &key); | ||
| 229 | break; | ||
| 230 | case 'f': | ||
| 231 | flags = setflags(p + 1); | ||
| 232 | break; | ||
| 233 | case 'D': /* data file */ | ||
| 234 | if (state != DATA) | ||
| 235 | dberr("line %lu: not expecting data", lineno); | ||
| 236 | data.data = rfile(p + 1, &data.size); | ||
| 237 | goto ldata; | ||
| 238 | case 'd': /* data */ | ||
| 239 | if (state != DATA) | ||
| 240 | dberr("line %lu: not expecting data", lineno); | ||
| 241 | data.data = xmalloc(p + 1, len - 1); | ||
| 242 | data.size = len - 1; | ||
| 243 | ldata: switch (command) { | ||
| 244 | case COMPARE: | ||
| 245 | compare(&keydata, &data); | ||
| 246 | break; | ||
| 247 | case PUT: | ||
| 248 | put(dbp, &key, &data); | ||
| 249 | break; | ||
| 250 | default: | ||
| 251 | dberr("line %lu: command doesn't take data", | ||
| 252 | lineno); | ||
| 253 | } | ||
| 254 | if (type != DB_RECNO) | ||
| 255 | free(key.data); | ||
| 256 | free(data.data); | ||
| 257 | state = COMMAND; | ||
| 258 | break; | ||
| 259 | case 'K': /* key file */ | ||
| 260 | if (state != KEY) | ||
| 261 | dberr("line %lu: not expecting a key", lineno); | ||
| 262 | if (type == DB_RECNO) | ||
| 263 | dberr("line %lu: 'K' not available for recno", | ||
| 264 | lineno); | ||
| 265 | key.data = rfile(p + 1, &key.size); | ||
| 266 | goto lkey; | ||
| 267 | case 'k': /* key */ | ||
| 268 | if (state != KEY) | ||
| 269 | dberr("line %lu: not expecting a key", lineno); | ||
| 270 | if (type == DB_RECNO) { | ||
| 271 | static recno_t recno; | ||
| 272 | recno = atoi(p + 1); | ||
| 273 | key.data = &recno; | ||
| 274 | key.size = sizeof(recno); | ||
| 275 | } else { | ||
| 276 | key.data = xmalloc(p + 1, len - 1); | ||
| 277 | key.size = len - 1; | ||
| 278 | } | ||
| 279 | lkey: switch (command) { | ||
| 280 | case COMPARE: | ||
| 281 | getdata(dbp, &key, &keydata); | ||
| 282 | state = DATA; | ||
| 283 | break; | ||
| 284 | case GET: | ||
| 285 | get(dbp, &key); | ||
| 286 | if (type != DB_RECNO) | ||
| 287 | free(key.data); | ||
| 288 | state = COMMAND; | ||
| 289 | break; | ||
| 290 | case PUT: | ||
| 291 | state = DATA; | ||
| 292 | break; | ||
| 293 | case REMOVE: | ||
| 294 | rem(dbp, &key); | ||
| 295 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
| 296 | free(key.data); | ||
| 297 | state = COMMAND; | ||
| 298 | break; | ||
| 299 | case SEQ: | ||
| 300 | seq(dbp, &key); | ||
| 301 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
| 302 | free(key.data); | ||
| 303 | state = COMMAND; | ||
| 304 | break; | ||
| 305 | default: | ||
| 306 | dberr("line %lu: command doesn't take a key", | ||
| 307 | lineno); | ||
| 308 | } | ||
| 309 | break; | ||
| 310 | case 'o': | ||
| 311 | dump(dbp, p[1] == 'r'); | ||
| 312 | break; | ||
| 313 | default: | ||
| 314 | dberr("line %lu: %s: unknown command character", | ||
| 315 | lineno, p); | ||
| 316 | } | ||
| 317 | } | ||
| 318 | #ifdef STATISTICS | ||
| 319 | /* | ||
| 320 | * -l must be used (DB_LOCK must be set) for this to be | ||
| 321 | * used, otherwise a page will be locked and it will fail. | ||
| 322 | */ | ||
| 323 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
| 324 | __bt_stat(dbp); | ||
| 325 | #endif | ||
| 326 | if (dbp->close(dbp)) | ||
| 327 | dberr("db->close: %s", strerror(errno)); | ||
| 328 | (void)close(ofd); | ||
| 329 | exit(0); | ||
| 330 | } | ||
| 331 | |||
| 332 | #define NOOVERWRITE "put failed, would overwrite key\n" | ||
| 333 | |||
| 334 | void | ||
| 335 | compare(db1, db2) | ||
| 336 | DBT *db1, *db2; | ||
| 337 | { | ||
| 338 | register size_t len; | ||
| 339 | register u_char *p1, *p2; | ||
| 340 | |||
| 341 | if (db1->size != db2->size) | ||
| 342 | printf("compare failed: key->data len %lu != data len %lu\n", | ||
| 343 | db1->size, db2->size); | ||
| 344 | |||
| 345 | len = MIN(db1->size, db2->size); | ||
| 346 | for (p1 = db1->data, p2 = db2->data; len--;) | ||
| 347 | if (*p1++ != *p2++) { | ||
| 348 | printf("compare failed at offset %ld\n", | ||
| 349 | p1 - (u_char *)db1->data); | ||
| 350 | break; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | |||
| 354 | void | ||
| 355 | get(dbp, kp) | ||
| 356 | DB *dbp; | ||
| 357 | DBT *kp; | ||
| 358 | { | ||
| 359 | DBT data; | ||
| 360 | |||
| 361 | switch (dbp->get(dbp, kp, &data, flags)) { | ||
| 362 | case 0: | ||
| 363 | (void)write(ofd, data.data, data.size); | ||
| 364 | if (ofd == STDOUT_FILENO) | ||
| 365 | (void)write(ofd, "\n", 1); | ||
| 366 | break; | ||
| 367 | case -1: | ||
| 368 | dberr("line %lu: get: %s", lineno, strerror(errno)); | ||
| 369 | /* NOTREACHED */ | ||
| 370 | case 1: | ||
| 371 | #define NOSUCHKEY "get failed, no such key\n" | ||
| 372 | if (ofd != STDOUT_FILENO) | ||
| 373 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 374 | else | ||
| 375 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
| 376 | MIN((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
| 377 | #undef NOSUCHKEY | ||
| 378 | break; | ||
| 379 | } | ||
| 380 | } | ||
| 381 | |||
| 382 | void | ||
| 383 | getdata(dbp, kp, dp) | ||
| 384 | DB *dbp; | ||
| 385 | DBT *kp, *dp; | ||
| 386 | { | ||
| 387 | switch (dbp->get(dbp, kp, dp, flags)) { | ||
| 388 | case 0: | ||
| 389 | return; | ||
| 390 | case -1: | ||
| 391 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); | ||
| 392 | /* NOTREACHED */ | ||
| 393 | case 1: | ||
| 394 | dberr("line %lu: getdata failed, no such key", lineno); | ||
| 395 | /* NOTREACHED */ | ||
| 396 | } | ||
| 397 | } | ||
| 398 | |||
| 399 | void | ||
| 400 | put(dbp, kp, dp) | ||
| 401 | DB *dbp; | ||
| 402 | DBT *kp, *dp; | ||
| 403 | { | ||
| 404 | switch (dbp->put(dbp, kp, dp, flags)) { | ||
| 405 | case 0: | ||
| 406 | break; | ||
| 407 | case -1: | ||
| 408 | dberr("line %lu: put: %s", lineno, strerror(errno)); | ||
| 409 | /* NOTREACHED */ | ||
| 410 | case 1: | ||
| 411 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | ||
| 412 | break; | ||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | void | ||
| 417 | rem(dbp, kp) | ||
| 418 | DB *dbp; | ||
| 419 | DBT *kp; | ||
| 420 | { | ||
| 421 | switch (dbp->del(dbp, kp, flags)) { | ||
| 422 | case 0: | ||
| 423 | break; | ||
| 424 | case -1: | ||
| 425 | dberr("line %lu: rem: %s", lineno, strerror(errno)); | ||
| 426 | /* NOTREACHED */ | ||
| 427 | case 1: | ||
| 428 | #define NOSUCHKEY "rem failed, no such key\n" | ||
| 429 | if (ofd != STDOUT_FILENO) | ||
| 430 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 431 | else if (flags != R_CURSOR) | ||
| 432 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
| 433 | MIN((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
| 434 | else | ||
| 435 | (void)fprintf(stderr, | ||
| 436 | "%lu: rem of cursor failed\n", lineno); | ||
| 437 | #undef NOSUCHKEY | ||
| 438 | break; | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | void | ||
| 443 | synk(dbp) | ||
| 444 | DB *dbp; | ||
| 445 | { | ||
| 446 | switch (dbp->sync(dbp, flags)) { | ||
| 447 | case 0: | ||
| 448 | break; | ||
| 449 | case -1: | ||
| 450 | dberr("line %lu: synk: %s", lineno, strerror(errno)); | ||
| 451 | /* NOTREACHED */ | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | void | ||
| 456 | seq(dbp, kp) | ||
| 457 | DB *dbp; | ||
| 458 | DBT *kp; | ||
| 459 | { | ||
| 460 | DBT data; | ||
| 461 | |||
| 462 | switch (dbp->seq(dbp, kp, &data, flags)) { | ||
| 463 | case 0: | ||
| 464 | (void)write(ofd, data.data, data.size); | ||
| 465 | if (ofd == STDOUT_FILENO) | ||
| 466 | (void)write(ofd, "\n", 1); | ||
| 467 | break; | ||
| 468 | case -1: | ||
| 469 | dberr("line %lu: seq: %s", lineno, strerror(errno)); | ||
| 470 | /* NOTREACHED */ | ||
| 471 | case 1: | ||
| 472 | #define NOSUCHKEY "seq failed, no such key\n" | ||
| 473 | if (ofd != STDOUT_FILENO) | ||
| 474 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
| 475 | else if (flags == R_CURSOR) | ||
| 476 | (void)fprintf(stderr, "%lu: %.*s: %s", lineno, | ||
| 477 | MIN((int)kp->size, 20), kp->data, NOSUCHKEY); | ||
| 478 | else | ||
| 479 | (void)fprintf(stderr, | ||
| 480 | "%lu: seq (%s) failed\n", lineno, sflags(flags)); | ||
| 481 | #undef NOSUCHKEY | ||
| 482 | break; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | |||
| 486 | void | ||
| 487 | dump(dbp, rev) | ||
| 488 | DB *dbp; | ||
| 489 | int rev; | ||
| 490 | { | ||
| 491 | DBT key, data; | ||
| 492 | int flags, nflags; | ||
| 493 | |||
| 494 | if (rev) { | ||
| 495 | flags = R_LAST; | ||
| 496 | nflags = R_PREV; | ||
| 497 | } else { | ||
| 498 | flags = R_FIRST; | ||
| 499 | nflags = R_NEXT; | ||
| 500 | } | ||
| 501 | for (;; flags = nflags) | ||
| 502 | switch (dbp->seq(dbp, &key, &data, flags)) { | ||
| 503 | case 0: | ||
| 504 | (void)write(ofd, data.data, data.size); | ||
| 505 | if (ofd == STDOUT_FILENO) | ||
| 506 | (void)write(ofd, "\n", 1); | ||
| 507 | break; | ||
| 508 | case 1: | ||
| 509 | goto done; | ||
| 510 | case -1: | ||
| 511 | dberr("line %lu: (dump) seq: %s", | ||
| 512 | lineno, strerror(errno)); | ||
| 513 | /* NOTREACHED */ | ||
| 514 | } | ||
| 515 | done: return; | ||
| 516 | } | ||
| 517 | |||
| 518 | u_int | ||
| 519 | setflags(s) | ||
| 520 | char *s; | ||
| 521 | { | ||
| 522 | char *p; | ||
| 523 | |||
| 524 | for (; isspace((unsigned char)*s); ++s); | ||
| 525 | if (*s == '\n' || *s == '\0') | ||
| 526 | return (0); | ||
| 527 | if ((p = strchr(s, '\n')) != NULL) | ||
| 528 | *p = '\0'; | ||
| 529 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); | ||
| 530 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); | ||
| 531 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); | ||
| 532 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); | ||
| 533 | if (!strcmp(s, "R_LAST")) return (R_LAST); | ||
| 534 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); | ||
| 535 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); | ||
| 536 | if (!strcmp(s, "R_PREV")) return (R_PREV); | ||
| 537 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); | ||
| 538 | |||
| 539 | dberr("line %lu: %s: unknown flag", lineno, s); | ||
| 540 | /* NOTREACHED */ | ||
| 541 | } | ||
| 542 | |||
| 543 | char * | ||
| 544 | sflags(flags) | ||
| 545 | int flags; | ||
| 546 | { | ||
| 547 | switch (flags) { | ||
| 548 | case R_CURSOR: return ("R_CURSOR"); | ||
| 549 | case R_FIRST: return ("R_FIRST"); | ||
| 550 | case R_IAFTER: return ("R_IAFTER"); | ||
| 551 | case R_IBEFORE: return ("R_IBEFORE"); | ||
| 552 | case R_LAST: return ("R_LAST"); | ||
| 553 | case R_NEXT: return ("R_NEXT"); | ||
| 554 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
| 555 | case R_PREV: return ("R_PREV"); | ||
| 556 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
| 557 | } | ||
| 558 | |||
| 559 | return ("UNKNOWN!"); | ||
| 560 | } | ||
| 561 | |||
| 562 | DBTYPE | ||
| 563 | dbtype(s) | ||
| 564 | char *s; | ||
| 565 | { | ||
| 566 | if (!strcmp(s, "btree")) | ||
| 567 | return (DB_BTREE); | ||
| 568 | if (!strcmp(s, "hash")) | ||
| 569 | return (DB_HASH); | ||
| 570 | if (!strcmp(s, "recno")) | ||
| 571 | return (DB_RECNO); | ||
| 572 | dberr("%s: unknown type (use btree, hash or recno)", s); | ||
| 573 | /* NOTREACHED */ | ||
| 574 | } | ||
| 575 | |||
| 576 | void * | ||
| 577 | setinfo(type, s) | ||
| 578 | DBTYPE type; | ||
| 579 | char *s; | ||
| 580 | { | ||
| 581 | static BTREEINFO ib; | ||
| 582 | static HASHINFO ih; | ||
| 583 | static RECNOINFO rh; | ||
| 584 | char *eq; | ||
| 585 | |||
| 586 | if ((eq = strchr(s, '=')) == NULL) | ||
| 587 | dberr("%s: illegal structure set statement", s); | ||
| 588 | *eq++ = '\0'; | ||
| 589 | if (!isdigit((unsigned char)*eq)) | ||
| 590 | dberr("%s: structure set statement must be a number", s); | ||
| 591 | |||
| 592 | switch (type) { | ||
| 593 | case DB_BTREE: | ||
| 594 | if (!strcmp("flags", s)) { | ||
| 595 | ib.flags = atoi(eq); | ||
| 596 | return (&ib); | ||
| 597 | } | ||
| 598 | if (!strcmp("cachesize", s)) { | ||
| 599 | ib.cachesize = atoi(eq); | ||
| 600 | return (&ib); | ||
| 601 | } | ||
| 602 | if (!strcmp("maxkeypage", s)) { | ||
| 603 | ib.maxkeypage = atoi(eq); | ||
| 604 | return (&ib); | ||
| 605 | } | ||
| 606 | if (!strcmp("minkeypage", s)) { | ||
| 607 | ib.minkeypage = atoi(eq); | ||
| 608 | return (&ib); | ||
| 609 | } | ||
| 610 | if (!strcmp("lorder", s)) { | ||
| 611 | ib.lorder = atoi(eq); | ||
| 612 | return (&ib); | ||
| 613 | } | ||
| 614 | if (!strcmp("psize", s)) { | ||
| 615 | ib.psize = atoi(eq); | ||
| 616 | return (&ib); | ||
| 617 | } | ||
| 618 | break; | ||
| 619 | case DB_HASH: | ||
| 620 | if (!strcmp("bsize", s)) { | ||
| 621 | ih.bsize = atoi(eq); | ||
| 622 | return (&ih); | ||
| 623 | } | ||
| 624 | if (!strcmp("ffactor", s)) { | ||
| 625 | ih.ffactor = atoi(eq); | ||
| 626 | return (&ih); | ||
| 627 | } | ||
| 628 | if (!strcmp("nelem", s)) { | ||
| 629 | ih.nelem = atoi(eq); | ||
| 630 | return (&ih); | ||
| 631 | } | ||
| 632 | if (!strcmp("cachesize", s)) { | ||
| 633 | ih.cachesize = atoi(eq); | ||
| 634 | return (&ih); | ||
| 635 | } | ||
| 636 | if (!strcmp("lorder", s)) { | ||
| 637 | ih.lorder = atoi(eq); | ||
| 638 | return (&ih); | ||
| 639 | } | ||
| 640 | break; | ||
| 641 | case DB_RECNO: | ||
| 642 | if (!strcmp("flags", s)) { | ||
| 643 | rh.flags = atoi(eq); | ||
| 644 | return (&rh); | ||
| 645 | } | ||
| 646 | if (!strcmp("cachesize", s)) { | ||
| 647 | rh.cachesize = atoi(eq); | ||
| 648 | return (&rh); | ||
| 649 | } | ||
| 650 | if (!strcmp("lorder", s)) { | ||
| 651 | rh.lorder = atoi(eq); | ||
| 652 | return (&rh); | ||
| 653 | } | ||
| 654 | if (!strcmp("reclen", s)) { | ||
| 655 | rh.reclen = atoi(eq); | ||
| 656 | return (&rh); | ||
| 657 | } | ||
| 658 | if (!strcmp("bval", s)) { | ||
| 659 | rh.bval = atoi(eq); | ||
| 660 | return (&rh); | ||
| 661 | } | ||
| 662 | if (!strcmp("psize", s)) { | ||
| 663 | rh.psize = atoi(eq); | ||
| 664 | return (&rh); | ||
| 665 | } | ||
| 666 | break; | ||
| 667 | } | ||
| 668 | dberr("%s: unknown structure value", s); | ||
| 669 | /* NOTREACHED */ | ||
| 670 | } | ||
| 671 | |||
| 672 | void * | ||
| 673 | rfile(name, lenp) | ||
| 674 | char *name; | ||
| 675 | size_t *lenp; | ||
| 676 | { | ||
| 677 | struct stat sb; | ||
| 678 | void *p; | ||
| 679 | int fd; | ||
| 680 | char *np; | ||
| 681 | |||
| 682 | for (; isspace((unsigned char)*name); ++name); | ||
| 683 | if ((np = strchr(name, '\n')) != NULL) | ||
| 684 | *np = '\0'; | ||
| 685 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | ||
| 686 | fstat(fd, &sb)) | ||
| 687 | dberr("%s: %s\n", name, strerror(errno)); | ||
| 688 | if (sb.st_size > (off_t)INT_MAX) | ||
| 689 | dberr("%s: %s\n", name, strerror(E2BIG)); | ||
| 690 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | ||
| 691 | dberr("%s", strerror(errno)); | ||
| 692 | (void)read(fd, p, (int)sb.st_size); | ||
| 693 | *lenp = sb.st_size; | ||
| 694 | (void)close(fd); | ||
| 695 | return (p); | ||
| 696 | } | ||
| 697 | |||
| 698 | void * | ||
| 699 | xmalloc(text, len) | ||
| 700 | char *text; | ||
| 701 | size_t len; | ||
| 702 | { | ||
| 703 | void *p; | ||
| 704 | |||
| 705 | if ((p = (void *)malloc(len)) == NULL) | ||
| 706 | dberr("%s", strerror(errno)); | ||
| 707 | memmove(p, text, len); | ||
| 708 | return (p); | ||
| 709 | } | ||
| 710 | |||
| 711 | void __dead | ||
| 712 | usage() | ||
| 713 | { | ||
| 714 | (void)fprintf(stderr, | ||
| 715 | "usage: dbtest [-l] [-f file] [-i info] [-o file] type script\n"); | ||
| 716 | exit(1); | ||
| 717 | } | ||
| 718 | |||
| 719 | void __dead | ||
| 720 | dberr(const char *fmt, ...) | ||
| 721 | { | ||
| 722 | va_list ap; | ||
| 723 | |||
| 724 | va_start(ap, fmt); | ||
| 725 | (void)fprintf(stderr, "dbtest: "); | ||
| 726 | (void)vfprintf(stderr, fmt, ap); | ||
| 727 | va_end(ap); | ||
| 728 | (void)fprintf(stderr, "\n"); | ||
| 729 | exit(1); | ||
| 730 | /* NOTREACHED */ | ||
| 731 | } | ||
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test deleted file mode 100644 index 0d6837e360..0000000000 --- a/src/regress/lib/libc/db/run.test +++ /dev/null | |||
| @@ -1,707 +0,0 @@ | |||
| 1 | #!/bin/sh - | ||
| 2 | # | ||
| 3 | # $OpenBSD: run.test,v 1.3 2001/01/29 02:05:41 niklas Exp $ | ||
| 4 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ | ||
| 5 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
| 6 | # | ||
| 7 | |||
| 8 | # db regression tests | ||
| 9 | main() | ||
| 10 | { | ||
| 11 | |||
| 12 | PROG=./dbtest | ||
| 13 | TMP1=t1 | ||
| 14 | TMP2=t2 | ||
| 15 | TMP3=t3 | ||
| 16 | |||
| 17 | if [ -f /usr/share/dict/words ]; then | ||
| 18 | DICT=/usr/share/dict/words | ||
| 19 | elif [ -f /usr/dict/words ]; then | ||
| 20 | DICT=/usr/dict/words | ||
| 21 | else | ||
| 22 | echo 'run.test: no dictionary' | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | if [ $# -eq 0 ]; then | ||
| 27 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | ||
| 28 | test$t | ||
| 29 | done | ||
| 30 | else | ||
| 31 | while [ $# -gt 0 ] | ||
| 32 | do case "$1" in | ||
| 33 | test*) | ||
| 34 | $1;; | ||
| 35 | [0-9]*) | ||
| 36 | test$1;; | ||
| 37 | btree) | ||
| 38 | for t in 1 2 3 7 8 9 10 12 13; do | ||
| 39 | test$t | ||
| 40 | done;; | ||
| 41 | hash) | ||
| 42 | for t in 1 2 3 8 13 20; do | ||
| 43 | test$t | ||
| 44 | done;; | ||
| 45 | recno) | ||
| 46 | for t in 1 2 3 4 5 6 7 10 11; do | ||
| 47 | test$t | ||
| 48 | done;; | ||
| 49 | *) | ||
| 50 | echo "run.test: unknown test $1" | ||
| 51 | echo "usage: run.test test# | type" | ||
| 52 | exit 1 | ||
| 53 | esac | ||
| 54 | shift | ||
| 55 | done | ||
| 56 | fi | ||
| 57 | rm -f $TMP1 $TMP2 $TMP3 | ||
| 58 | exit 0 | ||
| 59 | } | ||
| 60 | |||
| 61 | # Take the first hundred entries in the dictionary, and make them | ||
| 62 | # be key/data pairs. | ||
| 63 | test1() | ||
| 64 | { | ||
| 65 | echo "Test 1: btree, hash: small key, small data pairs" | ||
| 66 | sed 200q $DICT > $TMP1 | ||
| 67 | for type in btree hash; do | ||
| 68 | rm -f $TMP2 $TMP3 | ||
| 69 | for i in `sed 200q $DICT`; do | ||
| 70 | echo p | ||
| 71 | echo k$i | ||
| 72 | echo d$i | ||
| 73 | echo g | ||
| 74 | echo k$i | ||
| 75 | done > $TMP2 | ||
| 76 | $PROG -o $TMP3 $type $TMP2 | ||
| 77 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 78 | else | ||
| 79 | echo "test1: type $type: failed" | ||
| 80 | exit 1 | ||
| 81 | fi | ||
| 82 | done | ||
| 83 | echo "Test 1: recno: small key, small data pairs" | ||
| 84 | rm -f $TMP2 $TMP3 | ||
| 85 | sed 200q $DICT | | ||
| 86 | awk '{ | ||
| 87 | ++i; | ||
| 88 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
| 89 | }' > $TMP2 | ||
| 90 | $PROG -o $TMP3 recno $TMP2 | ||
| 91 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 92 | else | ||
| 93 | echo "test1: type recno: failed" | ||
| 94 | exit 1 | ||
| 95 | fi | ||
| 96 | } | ||
| 97 | |||
| 98 | # Take the first 200 entries in the dictionary, and give them | ||
| 99 | # each a medium size data entry. | ||
| 100 | test2() | ||
| 101 | { | ||
| 102 | echo "Test 2: btree, hash: small key, medium data pairs" | ||
| 103 | mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
| 104 | echo $mdata | | ||
| 105 | awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 | ||
| 106 | for type in hash btree; do | ||
| 107 | rm -f $TMP2 $TMP3 | ||
| 108 | for i in `sed 200q $DICT`; do | ||
| 109 | echo p | ||
| 110 | echo k$i | ||
| 111 | echo d$mdata | ||
| 112 | echo g | ||
| 113 | echo k$i | ||
| 114 | done > $TMP2 | ||
| 115 | $PROG -o $TMP3 $type $TMP2 | ||
| 116 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 117 | else | ||
| 118 | echo "test2: type $type: failed" | ||
| 119 | exit 1 | ||
| 120 | fi | ||
| 121 | done | ||
| 122 | echo "Test 2: recno: small key, medium data pairs" | ||
| 123 | rm -f $TMP2 $TMP3 | ||
| 124 | echo $mdata | | ||
| 125 | awk '{ for (i = 1; i < 201; ++i) | ||
| 126 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
| 127 | }' > $TMP2 | ||
| 128 | $PROG -o $TMP3 recno $TMP2 | ||
| 129 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 130 | else | ||
| 131 | echo "test2: type recno: failed" | ||
| 132 | exit 1 | ||
| 133 | fi | ||
| 134 | } | ||
| 135 | |||
| 136 | # Insert the programs in /bin with their paths as their keys. | ||
| 137 | test3() | ||
| 138 | { | ||
| 139 | echo "Test 3: hash: small key, big data pairs" | ||
| 140 | rm -f $TMP1 | ||
| 141 | (find /bin -type f -print | xargs cat) > $TMP1 | ||
| 142 | for type in hash; do | ||
| 143 | rm -f $TMP2 $TMP3 | ||
| 144 | for i in `find /bin -type f -print`; do | ||
| 145 | echo p | ||
| 146 | echo k$i | ||
| 147 | echo D$i | ||
| 148 | echo g | ||
| 149 | echo k$i | ||
| 150 | done > $TMP2 | ||
| 151 | $PROG -o $TMP3 $type $TMP2 | ||
| 152 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 153 | else | ||
| 154 | echo "test3: $type: failed" | ||
| 155 | exit 1 | ||
| 156 | fi | ||
| 157 | done | ||
| 158 | echo "Test 3: btree: small key, big data pairs" | ||
| 159 | for psize in 512 16384 65536; do | ||
| 160 | echo " page size $psize" | ||
| 161 | for type in btree; do | ||
| 162 | rm -f $TMP2 $TMP3 | ||
| 163 | for i in `find /bin -type f -print`; do | ||
| 164 | echo p | ||
| 165 | echo k$i | ||
| 166 | echo D$i | ||
| 167 | echo g | ||
| 168 | echo k$i | ||
| 169 | done > $TMP2 | ||
| 170 | $PROG -i psize=$psize -o $TMP3 $type $TMP2 | ||
| 171 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 172 | else | ||
| 173 | echo "test3: $type: page size $psize: failed" | ||
| 174 | exit 1 | ||
| 175 | fi | ||
| 176 | done | ||
| 177 | done | ||
| 178 | echo "Test 3: recno: big data pairs" | ||
| 179 | rm -f $TMP2 $TMP3 | ||
| 180 | find /bin -type f -print | | ||
| 181 | awk '{ | ||
| 182 | ++i; | ||
| 183 | printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); | ||
| 184 | }' > $TMP2 | ||
| 185 | for psize in 512 16384 65536; do | ||
| 186 | echo " page size $psize" | ||
| 187 | $PROG -i psize=$psize -o $TMP3 recno $TMP2 | ||
| 188 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 189 | else | ||
| 190 | echo "test3: recno: page size $psize: failed" | ||
| 191 | exit 1 | ||
| 192 | fi | ||
| 193 | done | ||
| 194 | } | ||
| 195 | |||
| 196 | # Do random recno entries. | ||
| 197 | test4() | ||
| 198 | { | ||
| 199 | echo "Test 4: recno: random entries" | ||
| 200 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 201 | awk '{ | ||
| 202 | for (i = 37; i <= 37 + 88 * 17; i += 17) { | ||
| 203 | if (i % 41) | ||
| 204 | s = substr($0, 1, i % 41); | ||
| 205 | else | ||
| 206 | s = substr($0, 1); | ||
| 207 | printf("input key %d: %s\n", i, s); | ||
| 208 | } | ||
| 209 | for (i = 1; i <= 15; ++i) { | ||
| 210 | if (i % 41) | ||
| 211 | s = substr($0, 1, i % 41); | ||
| 212 | else | ||
| 213 | s = substr($0, 1); | ||
| 214 | printf("input key %d: %s\n", i, s); | ||
| 215 | } | ||
| 216 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) { | ||
| 217 | if (i % 41) | ||
| 218 | s = substr($0, 1, i % 41); | ||
| 219 | else | ||
| 220 | s = substr($0, 1); | ||
| 221 | printf("input key %d: %s\n", i, s); | ||
| 222 | } | ||
| 223 | exit | ||
| 224 | }' > $TMP1 | ||
| 225 | rm -f $TMP2 $TMP3 | ||
| 226 | cat $TMP1 | | ||
| 227 | awk 'BEGIN { | ||
| 228 | i = 37; | ||
| 229 | incr = 17; | ||
| 230 | } | ||
| 231 | { | ||
| 232 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 233 | if (i == 19234 + 61 * 27) | ||
| 234 | exit; | ||
| 235 | if (i == 37 + 88 * 17) { | ||
| 236 | i = 1; | ||
| 237 | incr = 1; | ||
| 238 | } else if (i == 15) { | ||
| 239 | i = 19234; | ||
| 240 | incr = 27; | ||
| 241 | } else | ||
| 242 | i += incr; | ||
| 243 | } | ||
| 244 | END { | ||
| 245 | for (i = 37; i <= 37 + 88 * 17; i += 17) | ||
| 246 | printf("g\nk%d\n", i); | ||
| 247 | for (i = 1; i <= 15; ++i) | ||
| 248 | printf("g\nk%d\n", i); | ||
| 249 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) | ||
| 250 | printf("g\nk%d\n", i); | ||
| 251 | }' > $TMP2 | ||
| 252 | $PROG -o $TMP3 recno $TMP2 | ||
| 253 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 254 | else | ||
| 255 | echo "test4: type recno: failed" | ||
| 256 | exit 1 | ||
| 257 | fi | ||
| 258 | } | ||
| 259 | |||
| 260 | # Do reverse order recno entries. | ||
| 261 | test5() | ||
| 262 | { | ||
| 263 | echo "Test 5: recno: reverse order entries" | ||
| 264 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 265 | awk ' { | ||
| 266 | for (i = 1500; i; --i) { | ||
| 267 | if (i % 34) | ||
| 268 | s = substr($0, 1, i % 34); | ||
| 269 | else | ||
| 270 | s = substr($0, 1); | ||
| 271 | printf("input key %d: %s\n", i, s); | ||
| 272 | } | ||
| 273 | exit; | ||
| 274 | }' > $TMP1 | ||
| 275 | rm -f $TMP2 $TMP3 | ||
| 276 | cat $TMP1 | | ||
| 277 | awk 'BEGIN { | ||
| 278 | i = 1500; | ||
| 279 | } | ||
| 280 | { | ||
| 281 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 282 | --i; | ||
| 283 | } | ||
| 284 | END { | ||
| 285 | for (i = 1500; i; --i) | ||
| 286 | printf("g\nk%d\n", i); | ||
| 287 | }' > $TMP2 | ||
| 288 | $PROG -o $TMP3 recno $TMP2 | ||
| 289 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 290 | else | ||
| 291 | echo "test5: type recno: failed" | ||
| 292 | exit 1 | ||
| 293 | fi | ||
| 294 | } | ||
| 295 | |||
| 296 | # Do alternating order recno entries. | ||
| 297 | test6() | ||
| 298 | { | ||
| 299 | echo "Test 6: recno: alternating order entries" | ||
| 300 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 301 | awk ' { | ||
| 302 | for (i = 1; i < 1200; i += 2) { | ||
| 303 | if (i % 34) | ||
| 304 | s = substr($0, 1, i % 34); | ||
| 305 | else | ||
| 306 | s = substr($0, 1); | ||
| 307 | printf("input key %d: %s\n", i, s); | ||
| 308 | } | ||
| 309 | for (i = 2; i < 1200; i += 2) { | ||
| 310 | if (i % 34) | ||
| 311 | s = substr($0, 1, i % 34); | ||
| 312 | else | ||
| 313 | s = substr($0, 1); | ||
| 314 | printf("input key %d: %s\n", i, s); | ||
| 315 | } | ||
| 316 | exit; | ||
| 317 | }' > $TMP1 | ||
| 318 | rm -f $TMP2 $TMP3 | ||
| 319 | cat $TMP1 | | ||
| 320 | awk 'BEGIN { | ||
| 321 | i = 1; | ||
| 322 | even = 0; | ||
| 323 | } | ||
| 324 | { | ||
| 325 | printf("p\nk%d\nd%s\n", i, $0); | ||
| 326 | i += 2; | ||
| 327 | if (i >= 1200) { | ||
| 328 | if (even == 1) | ||
| 329 | exit; | ||
| 330 | even = 1; | ||
| 331 | i = 2; | ||
| 332 | } | ||
| 333 | } | ||
| 334 | END { | ||
| 335 | for (i = 1; i < 1200; ++i) | ||
| 336 | printf("g\nk%d\n", i); | ||
| 337 | }' > $TMP2 | ||
| 338 | $PROG -o $TMP3 recno $TMP2 | ||
| 339 | sort -o $TMP1 $TMP1 | ||
| 340 | sort -o $TMP3 $TMP3 | ||
| 341 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 342 | else | ||
| 343 | echo "test6: type recno: failed" | ||
| 344 | exit 1 | ||
| 345 | fi | ||
| 346 | } | ||
| 347 | |||
| 348 | # Delete cursor record | ||
| 349 | test7() | ||
| 350 | { | ||
| 351 | echo "Test 7: btree, recno: delete cursor record" | ||
| 352 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 353 | awk '{ | ||
| 354 | for (i = 1; i <= 120; ++i) | ||
| 355 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 356 | printf("%05d: input key %d: %s\n", 120, 120, $0); | ||
| 357 | printf("seq failed, no such key\n"); | ||
| 358 | printf("%05d: input key %d: %s\n", 1, 1, $0); | ||
| 359 | printf("%05d: input key %d: %s\n", 2, 2, $0); | ||
| 360 | exit; | ||
| 361 | }' > $TMP1 | ||
| 362 | rm -f $TMP2 $TMP3 | ||
| 363 | |||
| 364 | for type in btree recno; do | ||
| 365 | cat $TMP1 | | ||
| 366 | awk '{ | ||
| 367 | if (i == 120) | ||
| 368 | exit; | ||
| 369 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 370 | } | ||
| 371 | END { | ||
| 372 | printf("fR_NEXT\n"); | ||
| 373 | for (i = 1; i <= 120; ++i) | ||
| 374 | printf("s\n"); | ||
| 375 | printf("fR_CURSOR\ns\nk120\n"); | ||
| 376 | printf("r\n"); | ||
| 377 | printf("fR_NEXT\ns\n"); | ||
| 378 | printf("fR_CURSOR\ns\nk1\n"); | ||
| 379 | printf("r\n"); | ||
| 380 | printf("fR_FIRST\ns\n"); | ||
| 381 | }' > $TMP2 | ||
| 382 | $PROG -o $TMP3 recno $TMP2 | ||
| 383 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 384 | else | ||
| 385 | echo "test7: type $type: failed" | ||
| 386 | exit 1 | ||
| 387 | fi | ||
| 388 | done | ||
| 389 | } | ||
| 390 | |||
| 391 | # Make sure that overflow pages are reused. | ||
| 392 | test8() | ||
| 393 | { | ||
| 394 | echo "Test 8: btree, hash: repeated small key, big data pairs" | ||
| 395 | rm -f $TMP1 | ||
| 396 | echo "" | | ||
| 397 | awk 'BEGIN { | ||
| 398 | for (i = 1; i <= 10; ++i) { | ||
| 399 | printf("p\nkkey1\nD/bin/sh\n"); | ||
| 400 | printf("p\nkkey2\nD/bin/csh\n"); | ||
| 401 | if (i % 8 == 0) { | ||
| 402 | printf("c\nkkey2\nD/bin/csh\n"); | ||
| 403 | printf("c\nkkey1\nD/bin/sh\n"); | ||
| 404 | printf("e\t%d of 10 (comparison)\n", i); | ||
| 405 | } else | ||
| 406 | printf("e\t%d of 10 \n", i); | ||
| 407 | printf("r\nkkey1\nr\nkkey2\n"); | ||
| 408 | } | ||
| 409 | }' > $TMP1 | ||
| 410 | $PROG btree $TMP1 | ||
| 411 | # $PROG hash $TMP1 | ||
| 412 | # No explicit test for success. | ||
| 413 | } | ||
| 414 | |||
| 415 | # Test btree duplicate keys | ||
| 416 | test9() | ||
| 417 | { | ||
| 418 | echo "Test 9: btree: duplicate keys" | ||
| 419 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 420 | awk '{ | ||
| 421 | for (i = 1; i <= 543; ++i) | ||
| 422 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 423 | exit; | ||
| 424 | }' > $TMP1 | ||
| 425 | rm -f $TMP2 $TMP3 | ||
| 426 | |||
| 427 | for type in btree; do | ||
| 428 | cat $TMP1 | | ||
| 429 | awk '{ | ||
| 430 | if (i++ % 2) | ||
| 431 | printf("p\nkduplicatekey\nd%s\n", $0); | ||
| 432 | else | ||
| 433 | printf("p\nkunique%dkey\nd%s\n", i, $0); | ||
| 434 | } | ||
| 435 | END { | ||
| 436 | printf("o\n"); | ||
| 437 | }' > $TMP2 | ||
| 438 | $PROG -iflags=1 -o $TMP3 $type $TMP2 | ||
| 439 | sort -o $TMP3 $TMP3 | ||
| 440 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 441 | else | ||
| 442 | echo "test9: type $type: failed" | ||
| 443 | exit 1 | ||
| 444 | fi | ||
| 445 | done | ||
| 446 | } | ||
| 447 | |||
| 448 | # Test use of cursor flags without initialization | ||
| 449 | test10() | ||
| 450 | { | ||
| 451 | echo "Test 10: btree, recno: test cursor flag use" | ||
| 452 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 453 | awk '{ | ||
| 454 | for (i = 1; i <= 20; ++i) | ||
| 455 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 456 | exit; | ||
| 457 | }' > $TMP1 | ||
| 458 | rm -f $TMP2 $TMP3 | ||
| 459 | |||
| 460 | # Test that R_CURSOR doesn't succeed before cursor initialized | ||
| 461 | for type in btree recno; do | ||
| 462 | cat $TMP1 | | ||
| 463 | awk '{ | ||
| 464 | if (i == 10) | ||
| 465 | exit; | ||
| 466 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 467 | } | ||
| 468 | END { | ||
| 469 | printf("fR_CURSOR\nr\n"); | ||
| 470 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
| 471 | }' > $TMP2 | ||
| 472 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
| 473 | if [ -s $TMP3 ] ; then | ||
| 474 | echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED" | ||
| 475 | exit 1 | ||
| 476 | fi | ||
| 477 | done | ||
| 478 | for type in btree recno; do | ||
| 479 | cat $TMP1 | | ||
| 480 | awk '{ | ||
| 481 | if (i == 10) | ||
| 482 | exit; | ||
| 483 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
| 484 | } | ||
| 485 | END { | ||
| 486 | printf("fR_CURSOR\np\nk1\ndsome data\n"); | ||
| 487 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
| 488 | }' > $TMP2 | ||
| 489 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
| 490 | if [ -s $TMP3 ] ; then | ||
| 491 | echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED" | ||
| 492 | exit 1 | ||
| 493 | fi | ||
| 494 | done | ||
| 495 | } | ||
| 496 | |||
| 497 | # Test insert in reverse order. | ||
| 498 | test11() | ||
| 499 | { | ||
| 500 | echo "Test 11: recno: reverse order insert" | ||
| 501 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 502 | awk '{ | ||
| 503 | for (i = 1; i <= 779; ++i) | ||
| 504 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
| 505 | exit; | ||
| 506 | }' > $TMP1 | ||
| 507 | rm -f $TMP2 $TMP3 | ||
| 508 | |||
| 509 | for type in recno; do | ||
| 510 | cat $TMP1 | | ||
| 511 | awk '{ | ||
| 512 | if (i == 0) { | ||
| 513 | i = 1; | ||
| 514 | printf("p\nk1\nd%s\n", $0); | ||
| 515 | printf("%s\n", "fR_IBEFORE"); | ||
| 516 | } else | ||
| 517 | printf("p\nk1\nd%s\n", $0); | ||
| 518 | } | ||
| 519 | END { | ||
| 520 | printf("or\n"); | ||
| 521 | }' > $TMP2 | ||
| 522 | $PROG -o $TMP3 $type $TMP2 | ||
| 523 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 524 | else | ||
| 525 | echo "test11: type $type: failed" | ||
| 526 | exit 1 | ||
| 527 | fi | ||
| 528 | done | ||
| 529 | } | ||
| 530 | |||
| 531 | # Take the first 20000 entries in the dictionary, reverse them, and give | ||
| 532 | # them each a small size data entry. Use a small page size to make sure | ||
| 533 | # the btree split code gets hammered. | ||
| 534 | test12() | ||
| 535 | { | ||
| 536 | echo "Test 12: btree: lots of keys, small page size" | ||
| 537 | mdata=abcdefghijklmnopqrstuvwxy | ||
| 538 | echo $mdata | | ||
| 539 | awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1 | ||
| 540 | for type in btree; do | ||
| 541 | rm -f $TMP2 $TMP3 | ||
| 542 | for i in `sed 20000q $DICT | rev`; do | ||
| 543 | echo p | ||
| 544 | echo k$i | ||
| 545 | echo d$mdata | ||
| 546 | echo g | ||
| 547 | echo k$i | ||
| 548 | done > $TMP2 | ||
| 549 | $PROG -i psize=512 -o $TMP3 $type $TMP2 | ||
| 550 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 551 | else | ||
| 552 | echo "test12: type $type: failed" | ||
| 553 | exit 1 | ||
| 554 | fi | ||
| 555 | done | ||
| 556 | } | ||
| 557 | |||
| 558 | # Test different byte orders. | ||
| 559 | test13() | ||
| 560 | { | ||
| 561 | echo "Test 13: btree, hash: differing byte orders" | ||
| 562 | sed 50q $DICT > $TMP1 | ||
| 563 | for order in 1234 4321; do | ||
| 564 | for type in btree hash; do | ||
| 565 | rm -f byte.file $TMP2 $TMP3 | ||
| 566 | for i in `sed 50q $DICT`; do | ||
| 567 | echo p | ||
| 568 | echo k$i | ||
| 569 | echo d$i | ||
| 570 | echo g | ||
| 571 | echo k$i | ||
| 572 | done > $TMP2 | ||
| 573 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
| 574 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 575 | else | ||
| 576 | echo "test13: $type/$order put failed" | ||
| 577 | exit 1 | ||
| 578 | fi | ||
| 579 | for i in `sed 50q $DICT`; do | ||
| 580 | echo g | ||
| 581 | echo k$i | ||
| 582 | done > $TMP2 | ||
| 583 | $PROG -s \ | ||
| 584 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
| 585 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 586 | else | ||
| 587 | echo "test13: $type/$order get failed" | ||
| 588 | exit 1 | ||
| 589 | fi | ||
| 590 | done | ||
| 591 | done | ||
| 592 | rm -f byte.file | ||
| 593 | } | ||
| 594 | |||
| 595 | # Try a variety of bucketsizes and fill factors for hashing | ||
| 596 | test20() | ||
| 597 | { | ||
| 598 | echo\ | ||
| 599 | "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536" | ||
| 600 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
| 601 | awk '{ | ||
| 602 | for (i = 1; i <= 10000; ++i) { | ||
| 603 | if (i % 34) | ||
| 604 | s = substr($0, 1, i % 34); | ||
| 605 | else | ||
| 606 | s = substr($0, 1); | ||
| 607 | printf("%s\n", s); | ||
| 608 | } | ||
| 609 | exit; | ||
| 610 | }' > $TMP1 | ||
| 611 | sed 10000q $DICT | | ||
| 612 | awk 'BEGIN { | ||
| 613 | ds="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | ||
| 614 | } | ||
| 615 | { | ||
| 616 | if (++i % 34) | ||
| 617 | s = substr(ds, 1, i % 34); | ||
| 618 | else | ||
| 619 | s = substr(ds, 1); | ||
| 620 | printf("p\nk%s\nd%s\n", $0, s); | ||
| 621 | }' > $TMP2 | ||
| 622 | sed 10000q $DICT | | ||
| 623 | awk '{ | ||
| 624 | ++i; | ||
| 625 | printf("g\nk%s\n", $0); | ||
| 626 | }' >> $TMP2 | ||
| 627 | bsize=256 | ||
| 628 | for ffactor in 11 14 21; do | ||
| 629 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 630 | $PROG -o$TMP3 \ | ||
| 631 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 632 | hash $TMP2 | ||
| 633 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 634 | else | ||
| 635 | echo "test20: type hash:\ | ||
| 636 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 637 | exit 1 | ||
| 638 | fi | ||
| 639 | done | ||
| 640 | bsize=512 | ||
| 641 | for ffactor in 21 28 43; do | ||
| 642 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 643 | $PROG -o$TMP3 \ | ||
| 644 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 645 | hash $TMP2 | ||
| 646 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 647 | else | ||
| 648 | echo "test20: type hash:\ | ||
| 649 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 650 | exit 1 | ||
| 651 | fi | ||
| 652 | done | ||
| 653 | bsize=1024 | ||
| 654 | for ffactor in 43 57 85; do | ||
| 655 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 656 | $PROG -o$TMP3 \ | ||
| 657 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 658 | hash $TMP2 | ||
| 659 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 660 | else | ||
| 661 | echo "test20: type hash:\ | ||
| 662 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 663 | exit 1 | ||
| 664 | fi | ||
| 665 | done | ||
| 666 | bsize=2048 | ||
| 667 | for ffactor in 85 114 171; do | ||
| 668 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 669 | $PROG -o$TMP3 \ | ||
| 670 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 671 | hash $TMP2 | ||
| 672 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 673 | else | ||
| 674 | echo "test20: type hash:\ | ||
| 675 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 676 | exit 1 | ||
| 677 | fi | ||
| 678 | done | ||
| 679 | bsize=4096 | ||
| 680 | for ffactor in 171 228 341; do | ||
| 681 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 682 | $PROG -o$TMP3 \ | ||
| 683 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 684 | hash $TMP2 | ||
| 685 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 686 | else | ||
| 687 | echo "test20: type hash:\ | ||
| 688 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 689 | exit 1 | ||
| 690 | fi | ||
| 691 | done | ||
| 692 | bsize=8192 | ||
| 693 | for ffactor in 341 455 683; do | ||
| 694 | echo " bucketsize $bsize, fill factor $ffactor" | ||
| 695 | $PROG -o$TMP3 \ | ||
| 696 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
| 697 | hash $TMP2 | ||
| 698 | if (cmp -s $TMP1 $TMP3) ; then : | ||
| 699 | else | ||
| 700 | echo "test20: type hash:\ | ||
| 701 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
| 702 | exit 1 | ||
| 703 | fi | ||
| 704 | done | ||
| 705 | } | ||
| 706 | |||
| 707 | main $* | ||
diff --git a/src/regress/lib/libc/dirname/Makefile b/src/regress/lib/libc/dirname/Makefile deleted file mode 100644 index fc152df954..0000000000 --- a/src/regress/lib/libc/dirname/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | PROG=dirname_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/dirname/dirname_test.c b/src/regress/lib/libc/dirname/dirname_test.c deleted file mode 100644 index 27d32b6eda..0000000000 --- a/src/regress/lib/libc/dirname/dirname_test.c +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <sys/param.h> | ||
| 8 | |||
| 9 | #include <libgen.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <errno.h> | ||
| 14 | #include <err.h> | ||
| 15 | |||
| 16 | int | ||
| 17 | main(void) | ||
| 18 | { | ||
| 19 | char path[2 * MAXPATHLEN]; | ||
| 20 | char dname[128]; | ||
| 21 | const char *dir = "junk"; | ||
| 22 | const char *fname = "/file.name.ext"; | ||
| 23 | char *str; | ||
| 24 | int i; | ||
| 25 | |||
| 26 | /* Test normal functioning */ | ||
| 27 | strlcpy(path, "/", sizeof(path)); | ||
| 28 | strlcpy(dname, "/", sizeof(dname)); | ||
| 29 | strlcat(path, dir, sizeof(path)); | ||
| 30 | strlcat(dname, dir, sizeof(dname)); | ||
| 31 | strlcat(path, fname, sizeof(path)); | ||
| 32 | str = dirname(path); | ||
| 33 | if (strcmp(str, dname) != 0) | ||
| 34 | errx(1, "0: dirname(%s) = %s != %s", path, str, dname); | ||
| 35 | |||
| 36 | /* | ||
| 37 | * There are four states that require special handling: | ||
| 38 | * | ||
| 39 | * 1) path is NULL | ||
| 40 | * 2) path is the empty string | ||
| 41 | * 3) path is composed entirely of slashes | ||
| 42 | * 4) the resulting name is larger than MAXPATHLEN | ||
| 43 | * | ||
| 44 | * The first two cases require that a pointer | ||
| 45 | * to the string "." be returned. | ||
| 46 | * | ||
| 47 | * The third case requires that a pointer | ||
| 48 | * to the string "/" be returned. | ||
| 49 | * | ||
| 50 | * The final case requires that NULL be returned | ||
| 51 | * and errno * be set to ENAMETOOLONG. | ||
| 52 | */ | ||
| 53 | /* Case 1 */ | ||
| 54 | str = dirname(NULL); | ||
| 55 | if (strcmp(str, ".") != 0) | ||
| 56 | errx(1, "1: dirname(NULL) = %s != .", str); | ||
| 57 | |||
| 58 | /* Case 2 */ | ||
| 59 | strlcpy(path, "", sizeof(path)); | ||
| 60 | str = dirname(path); | ||
| 61 | if (strcmp(str, ".") != 0) | ||
| 62 | errx(1, "2: dirname(%s) = %s != .", path, str); | ||
| 63 | |||
| 64 | /* Case 3 */ | ||
| 65 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
| 66 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
| 67 | str = dirname(path); | ||
| 68 | if (strcmp(str, "/") != 0) | ||
| 69 | errx(1, "3: dirname(%s) = %s != /", path, str); | ||
| 70 | |||
| 71 | /* Case 4 */ | ||
| 72 | strlcpy(path, "/", sizeof(path)); /* reset path */ | ||
| 73 | for (i = 0; i <= MAXPATHLEN; i += strlen(dir)) | ||
| 74 | strlcat(path, dir, sizeof(path)); | ||
| 75 | strlcat(path, fname, sizeof(path)); | ||
| 76 | str = dirname(path); | ||
| 77 | if (str != NULL) | ||
| 78 | errx(1, "4: dirname(%s) = %s != NULL", path, str); | ||
| 79 | if (errno != ENAMETOOLONG) | ||
| 80 | errx(1, "4: dirname(%s) sets errno to %d", path, errno); | ||
| 81 | |||
| 82 | return (0); | ||
| 83 | } | ||
diff --git a/src/regress/lib/libc/env/Makefile b/src/regress/lib/libc/env/Makefile deleted file mode 100644 index 92e04369f4..0000000000 --- a/src/regress/lib/libc/env/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/08/23 22:34:37 millert Exp $ | ||
| 2 | |||
| 3 | PROG= envtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/env/envtest.c b/src/regress/lib/libc/env/envtest.c deleted file mode 100644 index 33fc463404..0000000000 --- a/src/regress/lib/libc/env/envtest.c +++ /dev/null | |||
| @@ -1,125 +0,0 @@ | |||
| 1 | /* $OpenBSD: envtest.c,v 1.1 2010/08/23 22:34:37 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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 <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | extern char **environ; | ||
| 27 | |||
| 28 | static int | ||
| 29 | count_instances(const char *name) | ||
| 30 | { | ||
| 31 | int count = 0; | ||
| 32 | size_t namelen; | ||
| 33 | char **ep; | ||
| 34 | |||
| 35 | namelen = strlen(name); | ||
| 36 | for (ep = environ; *ep != NULL; ep++) { | ||
| 37 | if (strncmp(name, *ep, namelen) == 0 && (*ep)[namelen] == '=') | ||
| 38 | count++; | ||
| 39 | } | ||
| 40 | |||
| 41 | return count; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void | ||
| 45 | fake_env(void) | ||
| 46 | { | ||
| 47 | static char *fakenv[7]; | ||
| 48 | |||
| 49 | fakenv[0] = "HOME=/root"; | ||
| 50 | fakenv[1] = "USER=root"; | ||
| 51 | fakenv[2] = "LOGNAME=root"; | ||
| 52 | fakenv[3] = "SHELL=/bin/sh"; | ||
| 53 | fakenv[4] = "USER=root"; | ||
| 54 | fakenv[5] = NULL; | ||
| 55 | |||
| 56 | environ = fakenv; | ||
| 57 | } | ||
| 58 | |||
| 59 | int | ||
| 60 | main(int argc, char *argv[]) | ||
| 61 | { | ||
| 62 | char *buf; | ||
| 63 | int n, failures = 0; | ||
| 64 | size_t len, bufsize; | ||
| 65 | |||
| 66 | /* Enable malloc security options. */ | ||
| 67 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 68 | |||
| 69 | fake_env(); | ||
| 70 | n = count_instances("USER"); | ||
| 71 | if (n != 2) { | ||
| 72 | fprintf(stderr, "initial: %d instances of USER, expected %d\n", | ||
| 73 | n, 2); | ||
| 74 | failures++; | ||
| 75 | } | ||
| 76 | |||
| 77 | if (unsetenv("USER") != 0) { | ||
| 78 | fprintf(stderr, "unsetenv: failed to remove USER\n"); | ||
| 79 | failures++; | ||
| 80 | } | ||
| 81 | n = count_instances("USER"); | ||
| 82 | if (n != 0) { | ||
| 83 | fprintf(stderr, "unsetenv: %d instances of USER, expected %d\n", | ||
| 84 | n, 0); | ||
| 85 | failures++; | ||
| 86 | } | ||
| 87 | |||
| 88 | fake_env(); | ||
| 89 | if (setenv("USER", "nobody", 0) != 0) { | ||
| 90 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
| 91 | failures++; | ||
| 92 | } | ||
| 93 | n = count_instances("USER"); | ||
| 94 | if (n != 2) { | ||
| 95 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
| 96 | n, 2); | ||
| 97 | failures++; | ||
| 98 | } | ||
| 99 | |||
| 100 | fake_env(); | ||
| 101 | if (setenv("USER", "nobody", 1) != 0) { | ||
| 102 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
| 103 | failures++; | ||
| 104 | } | ||
| 105 | n = count_instances("USER"); | ||
| 106 | if (n != 1) { | ||
| 107 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
| 108 | n, 1); | ||
| 109 | failures++; | ||
| 110 | } | ||
| 111 | |||
| 112 | fake_env(); | ||
| 113 | if (putenv("USER=nobody") != 0) { | ||
| 114 | fprintf(stderr, "putenv: failed to set USER\n"); | ||
| 115 | failures++; | ||
| 116 | } | ||
| 117 | n = count_instances("USER"); | ||
| 118 | if (n != 1) { | ||
| 119 | fprintf(stderr, "putenv: %d instances of USER, expected %d\n", | ||
| 120 | n, 1); | ||
| 121 | failures++; | ||
| 122 | } | ||
| 123 | |||
| 124 | return failures; | ||
| 125 | } | ||
diff --git a/src/regress/lib/libc/explicit_bzero/Makefile b/src/regress/lib/libc/explicit_bzero/Makefile deleted file mode 100644 index cd514a43a1..0000000000 --- a/src/regress/lib/libc/explicit_bzero/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/06/12 22:01:55 matthew Exp $ | ||
| 2 | |||
| 3 | PROG= explicit_bzero | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c b/src/regress/lib/libc/explicit_bzero/explicit_bzero.c deleted file mode 100644 index 34c60baa8a..0000000000 --- a/src/regress/lib/libc/explicit_bzero/explicit_bzero.c +++ /dev/null | |||
| @@ -1,197 +0,0 @@ | |||
| 1 | /* $OpenBSD: explicit_bzero.c,v 1.6 2014/07/11 01:10:35 matthew Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Google Inc. | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <assert.h> | ||
| 19 | #include <errno.h> | ||
| 20 | #include <signal.h> | ||
| 21 | #include <string.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | |||
| 24 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
| 25 | #define ASSERT_NE(a, b) assert((a) != (b)) | ||
| 26 | #define ASSERT_GE(a, b) assert((a) >= (b)) | ||
| 27 | |||
| 28 | /* 128 bits of random data. */ | ||
| 29 | static const char secret[16] = { | ||
| 30 | 0xa0, 0x6c, 0x0c, 0x81, 0xba, 0xd8, 0x5b, 0x0c, | ||
| 31 | 0xb0, 0xd6, 0xd4, 0xe3, 0xeb, 0x52, 0x5f, 0x96, | ||
| 32 | }; | ||
| 33 | |||
| 34 | enum { | ||
| 35 | SECRETCOUNT = 64, | ||
| 36 | SECRETBYTES = SECRETCOUNT * sizeof(secret) | ||
| 37 | }; | ||
| 38 | |||
| 39 | static char altstack[SIGSTKSZ + SECRETBYTES]; | ||
| 40 | |||
| 41 | static void | ||
| 42 | setup_stack(void) | ||
| 43 | { | ||
| 44 | const stack_t sigstk = { | ||
| 45 | .ss_sp = altstack, | ||
| 46 | .ss_size = sizeof(altstack), | ||
| 47 | }; | ||
| 48 | |||
| 49 | ASSERT_EQ(0, sigaltstack(&sigstk, NULL)); | ||
| 50 | } | ||
| 51 | |||
| 52 | static void | ||
| 53 | assert_on_stack(void) | ||
| 54 | { | ||
| 55 | stack_t cursigstk; | ||
| 56 | ASSERT_EQ(0, sigaltstack(NULL, &cursigstk)); | ||
| 57 | ASSERT_EQ(SS_ONSTACK, cursigstk.ss_flags & (SS_DISABLE|SS_ONSTACK)); | ||
| 58 | } | ||
| 59 | |||
| 60 | static void | ||
| 61 | call_on_stack(void (*fn)(int)) | ||
| 62 | { | ||
| 63 | /* | ||
| 64 | * This is a bit more complicated than strictly necessary, but | ||
| 65 | * it ensures we don't have any flaky test failures due to | ||
| 66 | * inherited signal masks/actions/etc. | ||
| 67 | * | ||
| 68 | * On systems where SA_ONSTACK is not supported, this could | ||
| 69 | * alternatively be implemented using makecontext() or | ||
| 70 | * pthread_attr_setstack(). | ||
| 71 | */ | ||
| 72 | |||
| 73 | const struct sigaction sigact = { | ||
| 74 | .sa_handler = fn, | ||
| 75 | .sa_flags = SA_ONSTACK, | ||
| 76 | }; | ||
| 77 | struct sigaction oldsigact; | ||
| 78 | sigset_t sigset, oldsigset; | ||
| 79 | |||
| 80 | /* First, block all signals. */ | ||
| 81 | ASSERT_EQ(0, sigemptyset(&sigset)); | ||
| 82 | ASSERT_EQ(0, sigfillset(&sigset)); | ||
| 83 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigset, &oldsigset)); | ||
| 84 | |||
| 85 | /* Next setup the signal handler for SIGUSR1. */ | ||
| 86 | ASSERT_EQ(0, sigaction(SIGUSR1, &sigact, &oldsigact)); | ||
| 87 | |||
| 88 | /* Raise SIGUSR1 and momentarily unblock it to run the handler. */ | ||
| 89 | ASSERT_EQ(0, raise(SIGUSR1)); | ||
| 90 | ASSERT_EQ(0, sigdelset(&sigset, SIGUSR1)); | ||
| 91 | ASSERT_EQ(-1, sigsuspend(&sigset)); | ||
| 92 | ASSERT_EQ(EINTR, errno); | ||
| 93 | |||
| 94 | /* Restore the original signal action, stack, and mask. */ | ||
| 95 | ASSERT_EQ(0, sigaction(SIGUSR1, &oldsigact, NULL)); | ||
| 96 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &oldsigset, NULL)); | ||
| 97 | } | ||
| 98 | |||
| 99 | static void | ||
| 100 | populate_secret(char *buf, size_t len) | ||
| 101 | { | ||
| 102 | int i, fds[2]; | ||
| 103 | ASSERT_EQ(0, pipe(fds)); | ||
| 104 | |||
| 105 | for (i = 0; i < SECRETCOUNT; i++) | ||
| 106 | ASSERT_EQ(sizeof(secret), write(fds[1], secret, sizeof(secret))); | ||
| 107 | ASSERT_EQ(0, close(fds[1])); | ||
| 108 | |||
| 109 | ASSERT_EQ(len, read(fds[0], buf, len)); | ||
| 110 | ASSERT_EQ(0, close(fds[0])); | ||
| 111 | } | ||
| 112 | |||
| 113 | static int | ||
| 114 | count_secrets(const char *buf) | ||
| 115 | { | ||
| 116 | int res = 0; | ||
| 117 | size_t i; | ||
| 118 | for (i = 0; i < SECRETCOUNT; i++) { | ||
| 119 | if (memcmp(buf + i * sizeof(secret), secret, | ||
| 120 | sizeof(secret)) == 0) | ||
| 121 | res += 1; | ||
| 122 | } | ||
| 123 | return (res); | ||
| 124 | } | ||
| 125 | |||
| 126 | static char * | ||
| 127 | test_without_bzero() | ||
| 128 | { | ||
| 129 | char buf[SECRETBYTES]; | ||
| 130 | assert_on_stack(); | ||
| 131 | populate_secret(buf, sizeof(buf)); | ||
| 132 | char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf)); | ||
| 133 | ASSERT_NE(NULL, res); | ||
| 134 | return (res); | ||
| 135 | } | ||
| 136 | |||
| 137 | static char * | ||
| 138 | test_with_bzero() | ||
| 139 | { | ||
| 140 | char buf[SECRETBYTES]; | ||
| 141 | assert_on_stack(); | ||
| 142 | populate_secret(buf, sizeof(buf)); | ||
| 143 | char *res = memmem(altstack, sizeof(altstack), buf, sizeof(buf)); | ||
| 144 | ASSERT_NE(NULL, res); | ||
| 145 | explicit_bzero(buf, sizeof(buf)); | ||
| 146 | return (res); | ||
| 147 | } | ||
| 148 | |||
| 149 | static void | ||
| 150 | do_test_without_bzero(int signo) | ||
| 151 | { | ||
| 152 | char *buf = test_without_bzero(); | ||
| 153 | ASSERT_GE(count_secrets(buf), 1); | ||
| 154 | } | ||
| 155 | |||
| 156 | static void | ||
| 157 | do_test_with_bzero(int signo) | ||
| 158 | { | ||
| 159 | char *buf = test_with_bzero(); | ||
| 160 | ASSERT_EQ(count_secrets(buf), 0); | ||
| 161 | } | ||
| 162 | |||
| 163 | int | ||
| 164 | main() | ||
| 165 | { | ||
| 166 | setup_stack(); | ||
| 167 | |||
| 168 | /* | ||
| 169 | * Solaris and OS X clobber the signal stack after returning to the | ||
| 170 | * normal stack, so we need to inspect altstack while we're still | ||
| 171 | * running on it. Unfortunately, this means we risk clobbering the | ||
| 172 | * buffer ourselves. | ||
| 173 | * | ||
| 174 | * To minimize this risk, test_with{,out}_bzero() are responsible for | ||
| 175 | * locating the offset of their buf variable within altstack, and | ||
| 176 | * and returning that address. Then we can simply memcmp() repeatedly | ||
| 177 | * to count how many instances of secret we found. | ||
| 178 | */ | ||
| 179 | |||
| 180 | /* | ||
| 181 | * First, test that if we *don't* call explicit_bzero, that we | ||
| 182 | * *are* able to find at least one instance of the secret data still | ||
| 183 | * on the stack. This sanity checks that call_on_stack() and | ||
| 184 | * populate_secret() work as intended. | ||
| 185 | */ | ||
| 186 | memset(altstack, 0, sizeof(altstack)); | ||
| 187 | call_on_stack(do_test_without_bzero); | ||
| 188 | |||
| 189 | /* | ||
| 190 | * Now test with a call to explicit_bzero() and check that we | ||
| 191 | * *don't* find any instances of the secret data. | ||
| 192 | */ | ||
| 193 | memset(altstack, 0, sizeof(altstack)); | ||
| 194 | call_on_stack(do_test_with_bzero); | ||
| 195 | |||
| 196 | return (0); | ||
| 197 | } | ||
diff --git a/src/regress/lib/libc/fmemopen/Makefile b/src/regress/lib/libc/fmemopen/Makefile deleted file mode 100644 index 9cfbfaa99c..0000000000 --- a/src/regress/lib/libc/fmemopen/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2013/01/01 17:43:07 mpi Exp $ | ||
| 2 | |||
| 3 | PROG= fmemopentest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fmemopen/fmemopentest.c b/src/regress/lib/libc/fmemopen/fmemopentest.c deleted file mode 100644 index 203c93be65..0000000000 --- a/src/regress/lib/libc/fmemopen/fmemopentest.c +++ /dev/null | |||
| @@ -1,212 +0,0 @@ | |||
| 1 | /* $OpenBSD: fmemopentest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
| 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 <err.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include <unistd.h> | ||
| 24 | |||
| 25 | int | ||
| 26 | simpletest(void) | ||
| 27 | { | ||
| 28 | FILE *s1, *s2; | ||
| 29 | char string[] = "fmemopen test string!"; | ||
| 30 | char buffer[1024], *buf = NULL; | ||
| 31 | size_t len; | ||
| 32 | int c, failures = 0; | ||
| 33 | |||
| 34 | s1 = fmemopen(string, strlen(string) + 1, "r"); | ||
| 35 | if (s1 == NULL) { | ||
| 36 | warn("unable to open a stream s1"); | ||
| 37 | return (1); | ||
| 38 | } | ||
| 39 | |||
| 40 | s2 = fmemopen(buf, 22, "w+"); | ||
| 41 | if (s2 == NULL) { | ||
| 42 | warn("unable to create a stream s2"); | ||
| 43 | fclose(s1); | ||
| 44 | return (1); | ||
| 45 | } | ||
| 46 | |||
| 47 | while ((c = fgetc(s1)) != EOF) | ||
| 48 | fputc(c, s2); | ||
| 49 | |||
| 50 | if (ftell(s2) != strlen(string) + 1) { | ||
| 51 | warnx("failed copy test (1)"); | ||
| 52 | failures++; | ||
| 53 | } | ||
| 54 | fclose(s1); | ||
| 55 | |||
| 56 | fseek(s2, 0, SEEK_SET); | ||
| 57 | if (ftell(s2) != 0) { | ||
| 58 | warnx("failed seek test (2)"); | ||
| 59 | failures++; | ||
| 60 | } | ||
| 61 | |||
| 62 | len = fread(buffer, 1, sizeof(buffer) - 1, s2); | ||
| 63 | if (len != strlen(string) + 1) { | ||
| 64 | warnx("failed read test (3) %zu != %zu", | ||
| 65 | len, strlen(string) + 1); | ||
| 66 | failures++; | ||
| 67 | } | ||
| 68 | |||
| 69 | return (failures); | ||
| 70 | } | ||
| 71 | |||
| 72 | int | ||
| 73 | updatetest(void) | ||
| 74 | { | ||
| 75 | FILE *s1; | ||
| 76 | char string[] = "hello\0 test number 2"; | ||
| 77 | char buffer[256]; | ||
| 78 | size_t len; | ||
| 79 | int failures = 0; | ||
| 80 | |||
| 81 | s1 = fmemopen(string, 19, "a+"); | ||
| 82 | if (s1 == NULL) | ||
| 83 | return (1); | ||
| 84 | |||
| 85 | len = fwrite(" world", 1, 6, s1); | ||
| 86 | if (len != 6) { | ||
| 87 | warnx("failed write test (4)"); | ||
| 88 | failures++; | ||
| 89 | } | ||
| 90 | |||
| 91 | fseek(s1, 0, SEEK_SET); | ||
| 92 | if (ftell(s1) != 0) { | ||
| 93 | warnx("failed seek test (5)"); | ||
| 94 | failures++; | ||
| 95 | } | ||
| 96 | |||
| 97 | len = fread(buffer, 1, sizeof(buffer) - 1, s1); | ||
| 98 | if (strncmp(string, buffer, len)) { | ||
| 99 | warnx("failed compare test (6)"); | ||
| 100 | failures++; | ||
| 101 | } | ||
| 102 | |||
| 103 | if (strcmp(string, "hello world")) { | ||
| 104 | warnx("failed compare test (7)"); | ||
| 105 | failures++; | ||
| 106 | } | ||
| 107 | |||
| 108 | if (strcmp(string + strlen(string) + 1, "number 2")) { | ||
| 109 | warnx("failed compare test (8)"); | ||
| 110 | failures++; | ||
| 111 | } | ||
| 112 | |||
| 113 | return (failures); | ||
| 114 | } | ||
| 115 | |||
| 116 | int | ||
| 117 | writetest(void) | ||
| 118 | { | ||
| 119 | FILE *s1; | ||
| 120 | char string[] = "super test number 3"; | ||
| 121 | char buffer[256]; | ||
| 122 | size_t len, slen; | ||
| 123 | int failures = 0; | ||
| 124 | |||
| 125 | slen = strlen(string) + 1; | ||
| 126 | |||
| 127 | s1 = fmemopen(string, slen, "w"); | ||
| 128 | if (s1 == NULL) | ||
| 129 | return (1); | ||
| 130 | |||
| 131 | len = fwrite("short", 1, 5, s1); | ||
| 132 | if (len != strlen("short")) { | ||
| 133 | warnx("failed write test (9)"); | ||
| 134 | failures++; | ||
| 135 | } | ||
| 136 | fclose(s1); | ||
| 137 | |||
| 138 | s1 = fmemopen(string, slen, "r"); | ||
| 139 | if (s1 == NULL) { | ||
| 140 | warnx("failed open test (10)"); | ||
| 141 | failures++; | ||
| 142 | } | ||
| 143 | |||
| 144 | len = fread(buffer, 1, sizeof(buffer) - 1, s1); | ||
| 145 | if (strncmp(string, buffer, len)) { | ||
| 146 | warnx("failed compare test (11)"); | ||
| 147 | failures++; | ||
| 148 | } | ||
| 149 | |||
| 150 | if (strcmp(string, "short")) { | ||
| 151 | warnx("failed compare test (12)"); | ||
| 152 | failures++; | ||
| 153 | } | ||
| 154 | |||
| 155 | if (strcmp(string + strlen(string) + 1, "test number 3")) { | ||
| 156 | warnx("failed compare test (13)"); | ||
| 157 | failures++; | ||
| 158 | } | ||
| 159 | |||
| 160 | return (failures); | ||
| 161 | } | ||
| 162 | |||
| 163 | int | ||
| 164 | seektest(void) | ||
| 165 | { | ||
| 166 | FILE *s1; | ||
| 167 | char string[] = "long string for testing seek"; | ||
| 168 | size_t len, slen; | ||
| 169 | int failures = 0; | ||
| 170 | |||
| 171 | slen = strlen(string) + 1; | ||
| 172 | |||
| 173 | s1 = fmemopen(string, slen, "r"); | ||
| 174 | if (s1 == NULL) | ||
| 175 | return (1); | ||
| 176 | |||
| 177 | if (fseek(s1, 8, SEEK_SET) != 0) { | ||
| 178 | warnx("failed to fseek. (14)"); | ||
| 179 | failures++; | ||
| 180 | } | ||
| 181 | |||
| 182 | if (ftell(s1) != 8) { | ||
| 183 | warnx("failed seek test. (15)"); | ||
| 184 | failures++; | ||
| 185 | } | ||
| 186 | |||
| 187 | /* Try to seek backward */ | ||
| 188 | if (fseek(s1, -1, SEEK_CUR) != 0) { | ||
| 189 | warnx("failed to fseek. (16)"); | ||
| 190 | failures++; | ||
| 191 | } | ||
| 192 | |||
| 193 | if (ftell(s1) != 7) { | ||
| 194 | warnx("failed seeking backward. (17)"); | ||
| 195 | failures++; | ||
| 196 | } | ||
| 197 | |||
| 198 | return (failures); | ||
| 199 | } | ||
| 200 | |||
| 201 | int | ||
| 202 | main(void) | ||
| 203 | { | ||
| 204 | int failures = 0; | ||
| 205 | |||
| 206 | failures += simpletest(); | ||
| 207 | failures += updatetest(); | ||
| 208 | failures += writetest(); | ||
| 209 | failures += seektest(); | ||
| 210 | |||
| 211 | return (failures); | ||
| 212 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile deleted file mode 100644 index 4acdd351bc..0000000000 --- a/src/regress/lib/libc/fnmatch/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2011/09/17 15:12:38 stsp Exp $ | ||
| 2 | |||
| 3 | PROG= fnm_test | ||
| 4 | LDADD+= -lutil | ||
| 5 | DPADD+= ${LIBUTIL} | ||
| 6 | |||
| 7 | run-regress-${PROG}: | ||
| 8 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c deleted file mode 100644 index f5958837e2..0000000000 --- a/src/regress/lib/libc/fnmatch/fnm_test.c +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | /* $OpenBSD: fnm_test.c,v 1.2 2011/09/17 15:12:38 stsp Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <fnmatch.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <util.h> | ||
| 12 | |||
| 13 | int | ||
| 14 | main(int argc, char **argv) | ||
| 15 | { | ||
| 16 | FILE *fp = stdin; | ||
| 17 | char pattern[1024], string[1024]; | ||
| 18 | char *line; | ||
| 19 | const char delim[3] = {'\0', '\0', '#'}; | ||
| 20 | int errors = 0, flags, got, want; | ||
| 21 | |||
| 22 | if (argc > 1) { | ||
| 23 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
| 24 | err(1, "%s", argv[1]); | ||
| 25 | } | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Read in test file, which is formatted thusly: | ||
| 29 | * | ||
| 30 | * pattern string flags expected_result | ||
| 31 | * | ||
| 32 | * lines starting with '#' are comments | ||
| 33 | */ | ||
| 34 | for (;;) { | ||
| 35 | line = fparseln(fp, NULL, NULL, delim, 0); | ||
| 36 | if (!line) | ||
| 37 | break; | ||
| 38 | got = sscanf(line, "%s %s 0x%x %d", pattern, string, &flags, | ||
| 39 | &want); | ||
| 40 | if (got == EOF) { | ||
| 41 | free(line); | ||
| 42 | break; | ||
| 43 | } | ||
| 44 | if (pattern[0] == '#') { | ||
| 45 | free(line); | ||
| 46 | continue; | ||
| 47 | } | ||
| 48 | if (got == 4) { | ||
| 49 | got = fnmatch(pattern, string, flags); | ||
| 50 | if (got != want) { | ||
| 51 | warnx("%s %s %d: want %d, got %d", pattern, | ||
| 52 | string, flags, want, got); | ||
| 53 | errors++; | ||
| 54 | } | ||
| 55 | } else { | ||
| 56 | warnx("unrecognized line '%s'\n", line); | ||
| 57 | errors++; | ||
| 58 | } | ||
| 59 | free(line); | ||
| 60 | } | ||
| 61 | exit(errors); | ||
| 62 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in deleted file mode 100644 index c2f218ae1b..0000000000 --- a/src/regress/lib/libc/fnmatch/fnm_test.in +++ /dev/null | |||
| @@ -1,260 +0,0 @@ | |||
| 1 | /bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 | ||
| 2 | /bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 | ||
| 3 | /bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 | ||
| 4 | [[:alpha:][:alnum:]]*.c foo1.c 0x4 0 | ||
| 5 | [[:upper:]]* FOO 0x0 0 | ||
| 6 | [![:space:]]* bar 0x0 0 | ||
| 7 | # 'te\st' 'test'; no match if FNM_NOESCAPE | ||
| 8 | te\st test 0x0 0 | ||
| 9 | te\st test 0x1 1 | ||
| 10 | te\st test 0x1e 0 | ||
| 11 | # 'te\\st' 'te\st'; no match if FNM_NOESCAPE | ||
| 12 | te\\st te\st 0x0 0 | ||
| 13 | te\\st te\st 0x1 1 | ||
| 14 | te\\st te\st 0x1e 0 | ||
| 15 | # 'te\*t' 'te*t'; no match if FNM_NOESCAPE | ||
| 16 | te\*t te*t 0x0 0 | ||
| 17 | te\*t te*t 0x1 1 | ||
| 18 | te\*t te*t 0x1e 0 | ||
| 19 | # 'te\*t' 'test'; no match | ||
| 20 | te\*t test 0x0 1 | ||
| 21 | te\*t test 0x1f 1 | ||
| 22 | # 'te\?t' 'te?t'; no match if FNM_NOESCAPE | ||
| 23 | te\?t te?t 0x0 0 | ||
| 24 | te\?t te?t 0x1 1 | ||
| 25 | te\?t te?t 0x1e 0 | ||
| 26 | # 'te\?t' 'test'; no match | ||
| 27 | te\?t test 0x0 1 | ||
| 28 | te\?t test 0x1f 1 | ||
| 29 | # 'tesT' 'test'; match if FNM_CASEFOLD | ||
| 30 | tesT test 0x0 1 | ||
| 31 | tesT test 0xf 1 | ||
| 32 | tesT test 0x10 0 | ||
| 33 | # 'test' 'Test'; match if FNM_CASEFOLD | ||
| 34 | test Test 0x0 1 | ||
| 35 | test Test 0xf 1 | ||
| 36 | test Test 0x10 0 | ||
| 37 | # 'tEst' 'teSt'; match if FNM_CASEFOLD | ||
| 38 | tEst teSt 0x0 1 | ||
| 39 | tEst teSt 0xf 1 | ||
| 40 | tEst teSt 0x10 0 | ||
| 41 | # '?est' 'test'; match always | ||
| 42 | ?est test 0x0 0 | ||
| 43 | ?est test 0x1f 0 | ||
| 44 | # 'te?t' 'test'; match always | ||
| 45 | te?t test 0x0 0 | ||
| 46 | te?t test 0x1f 0 | ||
| 47 | # 'tes?' 'test'; match always | ||
| 48 | tes? test 0x0 0 | ||
| 49 | tes? test 0x1f 0 | ||
| 50 | # 'test?' 'test'; no match | ||
| 51 | test? test 0x0 1 | ||
| 52 | test? test 0x1f 1 | ||
| 53 | # '*' always matches anything | ||
| 54 | * test 0x0 0 | ||
| 55 | * test 0x1f 0 | ||
| 56 | # '*test' 'test'; match always | ||
| 57 | *test test 0x0 0 | ||
| 58 | *test test 0x1f 0 | ||
| 59 | # '*est' 'test'; match always | ||
| 60 | *est test 0x0 0 | ||
| 61 | *est test 0x1f 0 | ||
| 62 | # '*st' 'test'; match always | ||
| 63 | *st test 0x0 0 | ||
| 64 | *st test 0x1f 0 | ||
| 65 | # 't*t' 'test'; match always | ||
| 66 | t*t test 0x0 0 | ||
| 67 | t*t test 0x1f 0 | ||
| 68 | # 'te*t' 'test'; match always | ||
| 69 | te*t test 0x0 0 | ||
| 70 | te*t test 0x1f 0 | ||
| 71 | # 'te*st' 'test'; match always | ||
| 72 | te*st test 0x0 0 | ||
| 73 | te*st test 0x1f 0 | ||
| 74 | # 'te*' 'test'; match always | ||
| 75 | te* test 0x0 0 | ||
| 76 | te* test 0x1f 0 | ||
| 77 | # 'tes*' 'test'; match always | ||
| 78 | tes* test 0x0 0 | ||
| 79 | tes* test 0x1f 0 | ||
| 80 | # 'test*' 'test'; match always | ||
| 81 | test* test 0x0 0 | ||
| 82 | test* test 0x1f 0 | ||
| 83 | # '.[\-\t]' '.t'; match always | ||
| 84 | .[\-\t] .t 0x0 0 | ||
| 85 | .[\-\t] .t 0x1f 0 | ||
| 86 | # 'test*?*[a-z]*' 'testgoop'; match always | ||
| 87 | test*?*[a-z]* testgoop 0x0 0 | ||
| 88 | test*?*[a-z]* testgoop 0x1f 0 | ||
| 89 | # 'te[^abc]t' 'test'; match always | ||
| 90 | te[^abc]t test 0x0 0 | ||
| 91 | te[^abc]t test 0x1f 0 | ||
| 92 | # 'te[^x]t' 'test'; match always | ||
| 93 | te[^x]t test 0x0 0 | ||
| 94 | te[^x]t test 0x1f 0 | ||
| 95 | # 'te[!x]t' 'test'; match always | ||
| 96 | te[!x]t test 0x0 0 | ||
| 97 | te[^x]t test 0x1f 0 | ||
| 98 | # 'te[^x]t' 'text'; no match | ||
| 99 | te[^x]t text 0x0 1 | ||
| 100 | te[^x]t text 0x1f 1 | ||
| 101 | # 'te[^\x]t' 'text'; no match | ||
| 102 | te[^\x]t text 0x0 1 | ||
| 103 | te[^\x]t text 0x1f 1 | ||
| 104 | # 'te[^\x' 'text'; no match | ||
| 105 | te[^\x text 0x0 1 | ||
| 106 | te[^\x text 0x1f 1 | ||
| 107 | # 'te[/]t' 'text'; no match | ||
| 108 | te[/]t text 0x0 1 | ||
| 109 | te[/]t text 0x1f 1 | ||
| 110 | # 'te[S]t' 'test'; match if FNM_CASEFOLD | ||
| 111 | te[S]t test 0x0 1 | ||
| 112 | te[S]t test 0xf 1 | ||
| 113 | te[S]t test 0x10 0 | ||
| 114 | # 'te[r-t]t' 'test'; match always | ||
| 115 | te[r-t]t test 0x0 0 | ||
| 116 | te[r-t]t test 0x1f 0 | ||
| 117 | # 'te[r-t]t' 'teSt'; match if FNM_CASEFOLD | ||
| 118 | te[r-t]t teSt 0x0 1 | ||
| 119 | te[r-t]t teSt 0xf 1 | ||
| 120 | te[r-t]t teSt 0x10 0 | ||
| 121 | # 'te[r-T]t' 'test'; match if FNM_CASEFOLD | ||
| 122 | te[r-T]t test 0x0 1 | ||
| 123 | te[r-T]t test 0xf 1 | ||
| 124 | te[r-T]t test 0x10 0 | ||
| 125 | # 'te[R-T]t' 'test'; match if FNM_CASEFOLD | ||
| 126 | te[R-T]t test 0x0 1 | ||
| 127 | te[R-T]t test 0xf 1 | ||
| 128 | te[R-T]t test 0x10 0 | ||
| 129 | # 'te[r-Tz]t' 'tezt'; match always | ||
| 130 | te[r-Tz]t tezt 0x0 0 | ||
| 131 | te[r-Tz]t tezt 0x1f 0 | ||
| 132 | # 'te[R-T]t' 'tent'; no match | ||
| 133 | te[R-T]t tent 0x0 1 | ||
| 134 | te[R-T]t tent 0x1f 1 | ||
| 135 | # 'tes[]t]' 'test'; match always | ||
| 136 | tes[]t] test 0x0 0 | ||
| 137 | tes[]t] test 0x1f 0 | ||
| 138 | # 'tes[t-]' 'test'; match always | ||
| 139 | tes[t-] test 0x0 0 | ||
| 140 | tes[t-] test 0x1f 0 | ||
| 141 | # 'tes[t-]]' 'test]'; match always | ||
| 142 | tes[t-]] test] 0x0 0 | ||
| 143 | tes[t-]] test] 0x1f 0 | ||
| 144 | # 'tes[t-]]' 'test'; no match | ||
| 145 | tes[t-]] test 0x0 1 | ||
| 146 | tes[t-]] test 0x1f 1 | ||
| 147 | # 'tes[u-]' 'test'; no match | ||
| 148 | tes[u-] test 0x0 1 | ||
| 149 | tes[u-] test 0x1f 1 | ||
| 150 | # 'tes[t-]' 'tes[t-]'; no match | ||
| 151 | tes[t-] test[t-] 0x0 1 | ||
| 152 | tes[t-] test[t-] 0x1f 1 | ||
| 153 | # 'test[/-/]' 'test[/-/]'; no match | ||
| 154 | test[/-/] test/-/ 0x0 1 | ||
| 155 | test[/-/] test/-/ 0x1f 1 | ||
| 156 | # 'test[\/-/]' 'test[/-/]'; no match | ||
| 157 | test[\/-/] test/-/ 0x0 1 | ||
| 158 | test[\/-/] test/-/ 0x1f 1 | ||
| 159 | # 'test[/-\/]' 'test[/-/]'; no match | ||
| 160 | test[/-\/] test/-/ 0x0 1 | ||
| 161 | test[/-\/] test/-/ 0x1f 1 | ||
| 162 | # 'test[/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
| 163 | test[/-/] test/ 0x0 0 | ||
| 164 | test[/-/] test/ 0x2 1 | ||
| 165 | test[/-/] test/ 0x1d 0 | ||
| 166 | # 'test[\/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
| 167 | test[\/-/] test/ 0x0 0 | ||
| 168 | test[\/-/] test/ 0x2 1 | ||
| 169 | test[\/-/] test/ 0x1d 0 | ||
| 170 | # 'test[/-\/]' 'test/'; no match if APR_FNM_PATHNAME | ||
| 171 | test[/-\/] test/ 0x0 0 | ||
| 172 | test[/-\/] test/ 0x2 1 | ||
| 173 | test[/-\/] test/ 0x1d 0 | ||
| 174 | # '/test' 'test'; no match | ||
| 175 | /test test 0x0 1 | ||
| 176 | /test test 0x1f 1 | ||
| 177 | # 'test' '/test'; no match | ||
| 178 | test /test 0x0 1 | ||
| 179 | test /test 0x1f 1 | ||
| 180 | # 'test/' 'test'; no match | ||
| 181 | test/ test 0x0 1 | ||
| 182 | test/ test 0x1f 1 | ||
| 183 | # 'test' 'test/'; match if FNM_LEADING_DIR | ||
| 184 | test test/ 0x0 1 | ||
| 185 | test test/ 0x17 1 | ||
| 186 | test test/ 0x8 0 | ||
| 187 | # '\/test' '/test'; match unless FNM_NOESCAPE | ||
| 188 | \/test /test 0x0 0 | ||
| 189 | \/test /test 0x1 1 | ||
| 190 | \/test /test 0x1e 0 | ||
| 191 | # '*test' '/test'; match unless FNM_PATHNAME | ||
| 192 | *test /test 0x0 0 | ||
| 193 | *test /test 0x2 1 | ||
| 194 | *test /test 0x1d 0 | ||
| 195 | # '/*/test' '/test'; no match | ||
| 196 | /*/test /test 0x0 1 | ||
| 197 | /*/test /test 0x1f 1 | ||
| 198 | # '/*/test' '/test/test'; match always | ||
| 199 | /*/test /test/test 0x0 0 | ||
| 200 | /*/test /test/test 0x1f 0 | ||
| 201 | # 'test/this' 'test/'; match never | ||
| 202 | test/this test/ 0x0 1 | ||
| 203 | test/this test/ 0x1f 1 | ||
| 204 | # 'test/' 'test/this'; match never | ||
| 205 | test/ test/this 0x0 1 | ||
| 206 | test/ test/this 0x1f 1 | ||
| 207 | # 'test*/this' 'test/this'; match always | ||
| 208 | test*/this test/this 0x0 0 | ||
| 209 | test*/this test/this 0x1f 0 | ||
| 210 | # 'test*/this' 'test/that'; match never | ||
| 211 | test*/this test/that 0x0 1 | ||
| 212 | test*/this test/that 0x1f 1 | ||
| 213 | # 'test/*this' 'test/this'; match always | ||
| 214 | test/*this test/this 0x0 0 | ||
| 215 | test/*this test/this 0x1f 0 | ||
| 216 | # '.*' '.this'; match always | ||
| 217 | .* .this 0x0 0 | ||
| 218 | .* .this 0x1f 0 | ||
| 219 | # '*' '.this'; fails if FNM_PERIOD | ||
| 220 | * .this 0x0 0 | ||
| 221 | * .this 0x4 1 | ||
| 222 | * .this 0x1b 0 | ||
| 223 | # '?this' '.this'; fails if FNM_PERIOD | ||
| 224 | ?this .this 0x0 0 | ||
| 225 | ?this .this 0x4 1 | ||
| 226 | ?this .this 0x1b 0 | ||
| 227 | # '[.]this' '.this'; fails if FNM_PERIOD | ||
| 228 | [.]this .this 0x0 0 | ||
| 229 | [.]this .this 0x4 1 | ||
| 230 | [.]this .this 0x1b 0 | ||
| 231 | # 'test/this' 'test/this'; match always | ||
| 232 | test/this test/this 0x0 0 | ||
| 233 | test/this test/this 0x1f 0 | ||
| 234 | # 'test?this' 'test/this'; fails if FNM_PATHNAME | ||
| 235 | test?this test/this 0x0 0 | ||
| 236 | test?this test/this 0x2 1 | ||
| 237 | test?this test/this 0x1d 0 | ||
| 238 | # 'test*this' 'test/this'; fails if FNM_PATHNAME | ||
| 239 | test*this test/this 0x0 0 | ||
| 240 | test*this test/this 0x2 1 | ||
| 241 | test*this test/this 0x1d 0 | ||
| 242 | # 'test[/]this' 'test/this'; fails if FNM_PATHNAME | ||
| 243 | test[/]this test/this 0x0 0 | ||
| 244 | test[/]this test/this 0x2 1 | ||
| 245 | test[/]this test/this 0x1d 0 | ||
| 246 | # 'test/.*' 'test/.this'; match always | ||
| 247 | test/.* test/.this 0x0 0 | ||
| 248 | test/.* test/.this 0x1f 0 | ||
| 249 | # 'test/*' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
| 250 | test/* test/.this 0x0 0 | ||
| 251 | test/* test/.this 0x6 1 | ||
| 252 | test/* test/.this 0x19 0 | ||
| 253 | # 'test/?' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
| 254 | test/?this test/.this 0x0 0 | ||
| 255 | test/?this test/.this 0x6 1 | ||
| 256 | test/?this test/.this 0x19 0 | ||
| 257 | # 'test/[.]this' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
| 258 | test/[.]this test/.this 0x0 0 | ||
| 259 | test/[.]this test/.this 0x6 1 | ||
| 260 | test/[.]this test/.this 0x19 0 | ||
diff --git a/src/regress/lib/libc/fpclassify/Makefile b/src/regress/lib/libc/fpclassify/Makefile deleted file mode 100644 index 96916d20e7..0000000000 --- a/src/regress/lib/libc/fpclassify/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
| 2 | |||
| 3 | PROG= fpclassify | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fpclassify/fpclassify.c b/src/regress/lib/libc/fpclassify/fpclassify.c deleted file mode 100644 index 174c04d983..0000000000 --- a/src/regress/lib/libc/fpclassify/fpclassify.c +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | /* $OpenBSD: fpclassify.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | * | ||
| 27 | * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $ | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include <assert.h> | ||
| 31 | #include <float.h> | ||
| 32 | #include <math.h> | ||
| 33 | #include <stdlib.h> | ||
| 34 | |||
| 35 | int | ||
| 36 | main(void) | ||
| 37 | { | ||
| 38 | |||
| 39 | assert(fpclassify((float)0) == FP_ZERO); | ||
| 40 | assert(fpclassify((float)-0.0) == FP_ZERO); | ||
| 41 | assert(fpclassify((float)1) == FP_NORMAL); | ||
| 42 | assert(fpclassify((float)1000) == FP_NORMAL); | ||
| 43 | #ifndef __alpha__ | ||
| 44 | assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); | ||
| 45 | #endif /* !__alpha__ */ | ||
| 46 | assert(fpclassify(HUGE_VALF) == FP_INFINITE); | ||
| 47 | assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); | ||
| 48 | assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); | ||
| 49 | assert(fpclassify(NAN) == FP_NAN); | ||
| 50 | |||
| 51 | assert(fpclassify((double)0) == FP_ZERO); | ||
| 52 | assert(fpclassify((double)-0) == FP_ZERO); | ||
| 53 | assert(fpclassify((double)1) == FP_NORMAL); | ||
| 54 | assert(fpclassify((double)1000) == FP_NORMAL); | ||
| 55 | #ifndef __alpha__ | ||
| 56 | assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); | ||
| 57 | #endif /* !__alpha__ */ | ||
| 58 | assert(fpclassify(HUGE_VAL) == FP_INFINITE); | ||
| 59 | assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); | ||
| 60 | assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); | ||
| 61 | assert(fpclassify((double)NAN) == FP_NAN); | ||
| 62 | |||
| 63 | assert(fpclassify((long double)0) == FP_ZERO); | ||
| 64 | assert(fpclassify((long double)-0.0) == FP_ZERO); | ||
| 65 | assert(fpclassify((long double)1) == FP_NORMAL); | ||
| 66 | assert(fpclassify((long double)1000) == FP_NORMAL); | ||
| 67 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) | ||
| 68 | assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); | ||
| 69 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */ | ||
| 70 | assert(fpclassify(HUGE_VALL) == FP_INFINITE); | ||
| 71 | assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); | ||
| 72 | assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); | ||
| 73 | assert(fpclassify((long double)NAN) == FP_NAN); | ||
| 74 | |||
| 75 | return (0); | ||
| 76 | } | ||
diff --git a/src/regress/lib/libc/gcvt/Makefile b/src/regress/lib/libc/gcvt/Makefile deleted file mode 100644 index d8efaa9362..0000000000 --- a/src/regress/lib/libc/gcvt/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $ | ||
| 2 | |||
| 3 | PROG= gcvt_test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c deleted file mode 100644 index 164d600cd2..0000000000 --- a/src/regress/lib/libc/gcvt/gcvt_test.c +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | /* $OpenBSD: gcvt_test.c,v 1.4 2010/09/18 20:29:15 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2010, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | static struct test_vector { | ||
| 12 | double d; | ||
| 13 | int ndig; | ||
| 14 | char *expect; | ||
| 15 | } test_vectors[] = { | ||
| 16 | /* adapted from perl's Configure test */ | ||
| 17 | { 0.1, 8, "0.1" }, | ||
| 18 | { 0.01, 8, "0.01" }, | ||
| 19 | { 0.001, 8, "0.001" }, | ||
| 20 | { 0.0001, 8, "0.0001" }, | ||
| 21 | { 0.00009, 8, "9e-05" }, | ||
| 22 | { 1.0, 8, "1" }, | ||
| 23 | { 1.1, 8, "1.1" }, | ||
| 24 | { 1.01, 8, "1.01" }, | ||
| 25 | { 1.001, 8, "1.001" }, | ||
| 26 | { 1.0001, 8, "1.0001" }, | ||
| 27 | { 1.00001, 8, "1.00001" }, | ||
| 28 | { 1.000001, 8, "1.000001" }, | ||
| 29 | { 0.0, 8, "0" }, | ||
| 30 | { -1.0, 8, "-1" }, | ||
| 31 | { 100000.0, 8, "100000" }, | ||
| 32 | { -100000.0, 8, "-100000" }, | ||
| 33 | { 123.456, 8, "123.456" }, | ||
| 34 | { 1e34, 8, "1e+34" }, | ||
| 35 | /* adapted from emx */ | ||
| 36 | { 0.0, -1, "0" }, | ||
| 37 | { 0.0, 0, "0" }, | ||
| 38 | { 0.0, 1, "0" }, | ||
| 39 | { 0.0, 2, "0" }, | ||
| 40 | { 1.0, -1, "1" }, | ||
| 41 | { 1.0, 0, "1" }, | ||
| 42 | { 1.0, 2, "1" }, | ||
| 43 | { 1.0, 10, "1" }, | ||
| 44 | { 1.236, -1, "1.236" }, | ||
| 45 | { 1.236, 0, "1" }, | ||
| 46 | { 1.236, 1, "1" }, | ||
| 47 | { 1.236, 2, "1.2" }, | ||
| 48 | { 1.236, 3, "1.24" }, | ||
| 49 | { 1.236, 4, "1.236" }, | ||
| 50 | { 1.236, 5, "1.236" }, | ||
| 51 | { 1.236, 6, "1.236" }, | ||
| 52 | { 12.36, -1, "12.36" }, | ||
| 53 | { 12.36, 0, "1e+01" }, | ||
| 54 | { 12.36, 1, "1e+01" }, | ||
| 55 | { 12.36, 2, "12" }, | ||
| 56 | { 12.36, 3, "12.4" }, | ||
| 57 | { 12.36, 4, "12.36" }, | ||
| 58 | { 12.36, 5, "12.36" }, | ||
| 59 | { 12.36, 6, "12.36" }, | ||
| 60 | { 123.6, -1, "123.6" }, | ||
| 61 | { 123.6, 0, "1e+02" }, | ||
| 62 | { 123.6, 1, "1e+02" }, | ||
| 63 | { 123.6, 2, "1.2e+02" }, | ||
| 64 | { 123.6, 3, "124" }, | ||
| 65 | { 123.6, 4, "123.6" }, | ||
| 66 | { 123.6, 5, "123.6" }, | ||
| 67 | { 123.6, 6, "123.6" }, | ||
| 68 | { 1236.0, -1, "1236" }, | ||
| 69 | { 1236.0, 0, "1e+03" }, | ||
| 70 | { 1236.0, 1, "1e+03" }, | ||
| 71 | { 1236.0, 2, "1.2e+03" }, | ||
| 72 | { 1236.0, 3, "1.24e+03" }, | ||
| 73 | { 1236.0, 4, "1236" }, | ||
| 74 | { 1236.0, 5, "1236" }, | ||
| 75 | { 1236.0, 6, "1236" }, | ||
| 76 | { 1e100, 10, "1e+100" }, | ||
| 77 | { 1e100, 20, "1.0000000000000000159e+100" }, | ||
| 78 | { 0.01236, -1, "0.01236" }, | ||
| 79 | { 0.01236, 0, "0.01" }, | ||
| 80 | { 0.01236, 1, "0.01" }, | ||
| 81 | { 0.01236, 2, "0.012" }, | ||
| 82 | { 0.01236, 3, "0.0124" }, | ||
| 83 | { 0.01236, 4, "0.01236" }, | ||
| 84 | { 1e-100, 20, "1.00000000000000002e-100" }, | ||
| 85 | { 1e-100, -1, "1e-100" }, | ||
| 86 | { -1.2, 5, "-1.2" }, | ||
| 87 | { -0.03, 5, "-0.03" }, | ||
| 88 | { 0.1, 1, "0.1" }, | ||
| 89 | { 0.1, 0, "0.1" }, | ||
| 90 | { 0.099999, 10, "0.099999" }, | ||
| 91 | { 0.99999, 10, "0.99999" }, | ||
| 92 | }; | ||
| 93 | |||
| 94 | #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) | ||
| 95 | |||
| 96 | static int | ||
| 97 | dotest(struct test_vector *tv) | ||
| 98 | { | ||
| 99 | char buf[256], *got; | ||
| 100 | |||
| 101 | got = gcvt(tv->d, tv->ndig, buf); | ||
| 102 | if (strcmp(tv->expect, got) != 0) { | ||
| 103 | fprintf(stderr, "%g @ %d: expected %s, got %s\n", | ||
| 104 | tv->d, tv->ndig, tv->expect, got); | ||
| 105 | return 1; | ||
| 106 | } | ||
| 107 | return 0; | ||
| 108 | } | ||
| 109 | |||
| 110 | int | ||
| 111 | main(int argc, char *argv[]) | ||
| 112 | { | ||
| 113 | int i, failures = 0; | ||
| 114 | |||
| 115 | for (i = 0; i < NTESTVEC; i++) { | ||
| 116 | failures += dotest(&test_vectors[i]); | ||
| 117 | } | ||
| 118 | |||
| 119 | return failures; | ||
| 120 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile deleted file mode 100644 index 7a78438a12..0000000000 --- a/src/regress/lib/libc/getaddrinfo/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2017/07/27 17:43:24 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = gaitest | ||
| 4 | CLEANFILES = out | ||
| 5 | |||
| 6 | run-regress-${PROG}: ${PROG} | ||
| 7 | sh ${.CURDIR}/testsuite.sh >out 2>&1 | ||
| 8 | diff -u10 out ${.CURDIR}/answer | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getaddrinfo/answer b/src/regress/lib/libc/getaddrinfo/answer deleted file mode 100644 index af6d069bbe..0000000000 --- a/src/regress/lib/libc/getaddrinfo/answer +++ /dev/null | |||
| @@ -1,110 +0,0 @@ | |||
| 1 | == basic ones | ||
| 2 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http | ||
| 3 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 4 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http | ||
| 5 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 6 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 7 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 8 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 9 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp | ||
| 10 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 11 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp | ||
| 12 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 13 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp | ||
| 14 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 15 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 16 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo | ||
| 17 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 18 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 19 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo | ||
| 20 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 21 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 22 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo | ||
| 23 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 24 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 25 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 26 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 27 | |||
| 28 | == specific address family | ||
| 29 | arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 30 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 31 | arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
| 32 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 33 | |||
| 34 | == empty hostname | ||
| 35 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
| 36 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 37 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 38 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
| 39 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
| 40 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
| 41 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
| 42 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
| 43 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
| 44 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
| 45 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
| 46 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 47 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
| 48 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 49 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
| 50 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 51 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
| 52 | ai1: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
| 53 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
| 54 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
| 55 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7 | ||
| 56 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7 | ||
| 57 | ai3: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7 | ||
| 58 | ai4: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7 | ||
| 59 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
| 60 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69 | ||
| 61 | ai2: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69 | ||
| 62 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 63 | ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 80 | ||
| 64 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
| 65 | ai3: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 80 | ||
| 66 | ai4: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
| 67 | arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 68 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
| 69 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
| 70 | arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 | ||
| 71 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
| 72 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
| 73 | |||
| 74 | == empty servname | ||
| 75 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) | ||
| 76 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
| 77 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
| 78 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) | ||
| 79 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
| 80 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
| 81 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 82 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
| 83 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
| 84 | ai3: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
| 85 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
| 86 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) | ||
| 87 | name or service is not known | ||
| 88 | |||
| 89 | == sock_raw | ||
| 90 | arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 91 | ai1: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 | ||
| 92 | ai2: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 | ||
| 93 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) | ||
| 94 | ai1: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 | ||
| 95 | ai2: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
| 96 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 | ||
| 97 | service not supported for ai_socktype | ||
| 98 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www | ||
| 99 | service not supported for ai_socktype | ||
| 100 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) | ||
| 101 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
| 102 | |||
| 103 | == unsupported family | ||
| 104 | arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
| 105 | ai_family not supported | ||
| 106 | |||
| 107 | == the following items are specified in jinmei scopeaddr format doc. | ||
| 108 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http | ||
| 109 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80 | ||
| 110 | |||
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c deleted file mode 100644 index 12a4498459..0000000000 --- a/src/regress/lib/libc/getaddrinfo/gaitest.c +++ /dev/null | |||
| @@ -1,195 +0,0 @@ | |||
| 1 | /* $OpenBSD: gaitest.c,v 1.6 2009/06/09 18:15:08 phessler Exp $ */ | ||
| 2 | /* $NetBSD: gaitest.c,v 1.3 2002/07/05 15:47:43 itojun Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. Neither the name of the project nor the names of its contributors | ||
| 17 | * may be used to endorse or promote products derived from this software | ||
| 18 | * without specific prior written permission. | ||
| 19 | * | ||
| 20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | * SUCH DAMAGE. | ||
| 31 | */ | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Please note: the order of the responses (and the regress test) | ||
| 35 | * is dependent on the "family" keywords in resolv.conf. | ||
| 36 | * | ||
| 37 | * This expects the default behaviour of "family inet4 inet6" | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <sys/types.h> | ||
| 41 | #include <sys/socket.h> | ||
| 42 | #include <netinet/in.h> | ||
| 43 | #include <arpa/inet.h> | ||
| 44 | #include <netdb.h> | ||
| 45 | #include <stdio.h> | ||
| 46 | #include <stdlib.h> | ||
| 47 | #include <string.h> | ||
| 48 | #include <unistd.h> | ||
| 49 | |||
| 50 | struct addrinfo ai; | ||
| 51 | |||
| 52 | char host[NI_MAXHOST]; | ||
| 53 | char serv[NI_MAXSERV]; | ||
| 54 | int vflag = 0; | ||
| 55 | |||
| 56 | static void usage(void); | ||
| 57 | static void print1(const char *, const struct addrinfo *, char *, char *); | ||
| 58 | int main(int, char *[]); | ||
| 59 | |||
| 60 | static void | ||
| 61 | usage() | ||
| 62 | { | ||
| 63 | fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); | ||
| 64 | } | ||
| 65 | |||
| 66 | static void | ||
| 67 | print1(title, res, h, s) | ||
| 68 | const char *title; | ||
| 69 | const struct addrinfo *res; | ||
| 70 | char *h; | ||
| 71 | char *s; | ||
| 72 | { | ||
| 73 | char *start, *end; | ||
| 74 | int error; | ||
| 75 | const int niflag = NI_NUMERICHOST | NI_NUMERICSERV; | ||
| 76 | |||
| 77 | if (res->ai_addr) { | ||
| 78 | error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, | ||
| 79 | host, sizeof(host), serv, sizeof(serv), | ||
| 80 | niflag); | ||
| 81 | h = host; | ||
| 82 | s = serv; | ||
| 83 | } else | ||
| 84 | error = 0; | ||
| 85 | |||
| 86 | if (vflag) { | ||
| 87 | start = "\t"; | ||
| 88 | end = "\n"; | ||
| 89 | } else { | ||
| 90 | start = " "; | ||
| 91 | end = ""; | ||
| 92 | } | ||
| 93 | printf("%s%s", title, end); | ||
| 94 | printf("%sflags 0x%x%s", start, res->ai_flags, end); | ||
| 95 | printf("%sfamily %d%s", start, res->ai_family, end); | ||
| 96 | printf("%ssocktype %d%s", start, res->ai_socktype, end); | ||
| 97 | printf("%sprotocol %d%s", start, res->ai_protocol, end); | ||
| 98 | printf("%saddrlen %d%s", start, res->ai_addrlen, end); | ||
| 99 | if (error) | ||
| 100 | printf("%serror %d%s", start, error, end); | ||
| 101 | else { | ||
| 102 | printf("%shost %s%s", start, h, end); | ||
| 103 | printf("%sserv %s%s", start, s, end); | ||
| 104 | } | ||
| 105 | #if 0 | ||
| 106 | if (res->ai_canonname) | ||
| 107 | printf("%scname \"%s\"%s", start, res->ai_canonname, end); | ||
| 108 | #endif | ||
| 109 | if (!vflag) | ||
| 110 | printf("\n"); | ||
| 111 | |||
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | main(argc, argv) | ||
| 116 | int argc; | ||
| 117 | char *argv[]; | ||
| 118 | { | ||
| 119 | struct addrinfo *res; | ||
| 120 | int error, i; | ||
| 121 | char *p, *q; | ||
| 122 | extern int optind; | ||
| 123 | extern char *optarg; | ||
| 124 | int c; | ||
| 125 | char nbuf[10]; | ||
| 126 | |||
| 127 | memset(&ai, 0, sizeof(ai)); | ||
| 128 | ai.ai_family = PF_UNSPEC; | ||
| 129 | ai.ai_flags |= AI_CANONNAME; | ||
| 130 | while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { | ||
| 131 | switch (c) { | ||
| 132 | case 'D': | ||
| 133 | ai.ai_socktype = SOCK_DGRAM; | ||
| 134 | break; | ||
| 135 | case 'f': | ||
| 136 | ai.ai_family = atoi(optarg); | ||
| 137 | break; | ||
| 138 | case 'p': | ||
| 139 | ai.ai_protocol = atoi(optarg); | ||
| 140 | break; | ||
| 141 | case 'P': | ||
| 142 | ai.ai_flags |= AI_PASSIVE; | ||
| 143 | break; | ||
| 144 | case 'R': | ||
| 145 | ai.ai_socktype = SOCK_RAW; | ||
| 146 | break; | ||
| 147 | case 's': | ||
| 148 | ai.ai_socktype = atoi(optarg); | ||
| 149 | break; | ||
| 150 | case 'S': | ||
| 151 | ai.ai_socktype = SOCK_STREAM; | ||
| 152 | break; | ||
| 153 | case 'v': | ||
| 154 | vflag++; | ||
| 155 | break; | ||
| 156 | case '4': | ||
| 157 | ai.ai_family = PF_INET; | ||
| 158 | break; | ||
| 159 | case '6': | ||
| 160 | ai.ai_family = PF_INET6; | ||
| 161 | break; | ||
| 162 | default: | ||
| 163 | usage(); | ||
| 164 | exit(1); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | argc -= optind; | ||
| 168 | argv += optind; | ||
| 169 | |||
| 170 | if (argc != 2){ | ||
| 171 | usage(); | ||
| 172 | exit(1); | ||
| 173 | } | ||
| 174 | |||
| 175 | p = *argv[0] ? argv[0] : NULL; | ||
| 176 | q = *argv[1] ? argv[1] : NULL; | ||
| 177 | |||
| 178 | print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)"); | ||
| 179 | |||
| 180 | error = getaddrinfo(p, q, &ai, &res); | ||
| 181 | if (error) { | ||
| 182 | printf("%s\n", gai_strerror(error)); | ||
| 183 | exit(1); | ||
| 184 | } | ||
| 185 | |||
| 186 | i = 1; | ||
| 187 | do { | ||
| 188 | snprintf(nbuf, sizeof(nbuf), "ai%d:", i); | ||
| 189 | print1(nbuf, res, NULL, NULL); | ||
| 190 | |||
| 191 | i++; | ||
| 192 | } while ((res = res->ai_next) != NULL); | ||
| 193 | |||
| 194 | exit(0); | ||
| 195 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/testsuite.sh b/src/regress/lib/libc/getaddrinfo/testsuite.sh deleted file mode 100644 index 1e4e524054..0000000000 --- a/src/regress/lib/libc/getaddrinfo/testsuite.sh +++ /dev/null | |||
| @@ -1,89 +0,0 @@ | |||
| 1 | # $OpenBSD: testsuite.sh,v 1.1 2002/07/05 15:54:30 itojun Exp $ | ||
| 2 | # $NetBSD: testsuite.sh,v 1.3 2002/07/05 15:49:11 itojun Exp $ | ||
| 3 | |||
| 4 | # | ||
| 5 | # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
| 6 | # All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions | ||
| 10 | # are met: | ||
| 11 | # 1. Redistributions of source code must retain the above copyright | ||
| 12 | # notice, this list of conditions and the following disclaimer. | ||
| 13 | # 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | # notice, this list of conditions and the following disclaimer in the | ||
| 15 | # documentation and/or other materials provided with the distribution. | ||
| 16 | # 3. Neither the name of the project nor the names of its contributors | ||
| 17 | # may be used to endorse or promote products derived from this software | ||
| 18 | # without specific prior written permission. | ||
| 19 | # | ||
| 20 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
| 21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
| 24 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 26 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 28 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 29 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 30 | # SUCH DAMAGE. | ||
| 31 | # | ||
| 32 | |||
| 33 | TEST=./gaitest | ||
| 34 | #TEST='./test -v' | ||
| 35 | #IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'` | ||
| 36 | |||
| 37 | echo '== basic ones' | ||
| 38 | $TEST ::1 http | ||
| 39 | $TEST 127.0.0.1 http | ||
| 40 | $TEST localhost http | ||
| 41 | $TEST ::1 tftp | ||
| 42 | $TEST 127.0.0.1 tftp | ||
| 43 | $TEST localhost tftp | ||
| 44 | $TEST ::1 echo | ||
| 45 | $TEST 127.0.0.1 echo | ||
| 46 | $TEST localhost echo | ||
| 47 | echo | ||
| 48 | |||
| 49 | echo '== specific address family' | ||
| 50 | $TEST -4 localhost http | ||
| 51 | $TEST -6 localhost http | ||
| 52 | echo | ||
| 53 | |||
| 54 | echo '== empty hostname' | ||
| 55 | $TEST '' http | ||
| 56 | $TEST '' echo | ||
| 57 | $TEST '' tftp | ||
| 58 | $TEST '' 80 | ||
| 59 | $TEST -P '' http | ||
| 60 | $TEST -P '' echo | ||
| 61 | $TEST -P '' tftp | ||
| 62 | $TEST -P '' 80 | ||
| 63 | $TEST -S '' 80 | ||
| 64 | $TEST -D '' 80 | ||
| 65 | echo | ||
| 66 | |||
| 67 | echo '== empty servname' | ||
| 68 | $TEST ::1 '' | ||
| 69 | $TEST 127.0.0.1 '' | ||
| 70 | $TEST localhost '' | ||
| 71 | $TEST '' '' | ||
| 72 | echo | ||
| 73 | |||
| 74 | echo '== sock_raw' | ||
| 75 | $TEST -R -p 0 localhost '' | ||
| 76 | $TEST -R -p 59 localhost '' | ||
| 77 | $TEST -R -p 59 localhost 80 | ||
| 78 | $TEST -R -p 59 localhost www | ||
| 79 | $TEST -R -p 59 ::1 '' | ||
| 80 | echo | ||
| 81 | |||
| 82 | echo '== unsupported family' | ||
| 83 | $TEST -f 99 localhost '' | ||
| 84 | echo | ||
| 85 | |||
| 86 | echo '== the following items are specified in jinmei scopeaddr format doc.' | ||
| 87 | $TEST fe80::1%lo0 http | ||
| 88 | #$TEST fe80::1%$IF http | ||
| 89 | echo | ||
diff --git a/src/regress/lib/libc/getcap/Makefile b/src/regress/lib/libc/getcap/Makefile deleted file mode 100644 index 7b7ae394ff..0000000000 --- a/src/regress/lib/libc/getcap/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2009/06/09 18:16:40 phessler Exp $ | ||
| 2 | |||
| 3 | PROG= getcaptest | ||
| 4 | |||
| 5 | REGRESS_TARGETS=shortcap | ||
| 6 | |||
| 7 | shortcap: getcaptest | ||
| 8 | ./getcaptest ${.CURDIR}/shortcap.in | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getcap/getcaptest.c b/src/regress/lib/libc/getcap/getcaptest.c deleted file mode 100644 index 0f4464b6c5..0000000000 --- a/src/regress/lib/libc/getcap/getcaptest.c +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | /* $OpenBSD: getcaptest.c,v 1.1 2006/03/10 05:28:57 ray Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Written by Raymond Lai <ray@cyth.net>. | ||
| 5 | * Public domain. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | |||
| 11 | int | ||
| 12 | main(int argc, char *argv[]) | ||
| 13 | { | ||
| 14 | char *buf, *db_array[2]; | ||
| 15 | |||
| 16 | if (argc != 2) | ||
| 17 | return (1); | ||
| 18 | |||
| 19 | db_array[0] = argv[1]; | ||
| 20 | db_array[1] = NULL; | ||
| 21 | |||
| 22 | while (cgetnext(&buf, db_array) > 0) | ||
| 23 | puts(buf); | ||
| 24 | |||
| 25 | return (0); | ||
| 26 | } | ||
diff --git a/src/regress/lib/libc/getcap/shortcap.in b/src/regress/lib/libc/getcap/shortcap.in deleted file mode 100644 index 573541ac97..0000000000 --- a/src/regress/lib/libc/getcap/shortcap.in +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | 0 | ||
diff --git a/src/regress/lib/libc/getopt_long/Makefile b/src/regress/lib/libc/getopt_long/Makefile deleted file mode 100644 index 13a187e190..0000000000 --- a/src/regress/lib/libc/getopt_long/Makefile +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/12/08 19:25:08 millert Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=getopt_long_test | ||
| 5 | CLEANFILES+=test.out | ||
| 6 | |||
| 7 | # test getopt_long and getopt_long_only | ||
| 8 | run-regress-${PROG}: ${PROG} | ||
| 9 | @( test -n "$$POSIXLY_CORRECT" && unset POSIXLY_CORRECT; \ | ||
| 10 | test -n "$$LONG_ONLY" && unset LONG_ONLY; \ | ||
| 11 | ./${PROG} myfile --force -f infile -9 ; \ | ||
| 12 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
| 13 | ./${PROG} -1bfast - ; \ | ||
| 14 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
| 15 | export POSIXLY_CORRECT=1 ; \ | ||
| 16 | ./${PROG} myfile --force -f infile -9 ; \ | ||
| 17 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
| 18 | ./${PROG} -1bfast - ; \ | ||
| 19 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
| 20 | unset POSIXLY_CORRECT ; export LONG_ONLY=1 ; \ | ||
| 21 | ./${PROG} myfile -force -f infile -9 ; \ | ||
| 22 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
| 23 | ./${PROG} -1bfast - ; \ | ||
| 24 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ; \ | ||
| 25 | export POSIXLY_CORRECT=1 ; \ | ||
| 26 | ./${PROG} myfile -force -f infile -9 ; \ | ||
| 27 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
| 28 | ./${PROG} -1bfast - ; \ | ||
| 29 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ) >test.out 2>&1 | ||
| 30 | cmp -s ${.OBJDIR}/test.out ${.CURDIR}/test.ok | ||
| 31 | |||
| 32 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt_long/getopt_long_test.c b/src/regress/lib/libc/getopt_long/getopt_long_test.c deleted file mode 100644 index 9f6f603702..0000000000 --- a/src/regress/lib/libc/getopt_long/getopt_long_test.c +++ /dev/null | |||
| @@ -1,114 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | * | ||
| 16 | * Sponsored in part by the Defense Advanced Research Projects | ||
| 17 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
| 18 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <getopt.h> | ||
| 24 | |||
| 25 | /* | ||
| 26 | * Simple getopt_long() and getopt_long_only() excerciser. | ||
| 27 | * ENVIRONMENT: | ||
| 28 | * LONG_ONLY : use getopt_long_only() (default is getopt_long()) | ||
| 29 | * POSIXLY_CORRECT : don't permute args | ||
| 30 | */ | ||
| 31 | |||
| 32 | int | ||
| 33 | main(int argc, char **argv) | ||
| 34 | { | ||
| 35 | int ch, idx, goggles; | ||
| 36 | int (*gl)(int, char * const *, const char *, const struct option *, int *); | ||
| 37 | struct option longopts[] = { | ||
| 38 | { "force", no_argument, 0, 0 }, | ||
| 39 | { "fast", no_argument, 0, '1' }, | ||
| 40 | { "best", no_argument, 0, '9' }, | ||
| 41 | { "input", required_argument, 0, 'i' }, | ||
| 42 | { "illiterate", no_argument, 0, 0 }, | ||
| 43 | { "drinking", required_argument, &goggles, 42 }, | ||
| 44 | { "help", no_argument, 0, 'h' }, | ||
| 45 | { 0, 0, 0, 0 }, | ||
| 46 | }; | ||
| 47 | |||
| 48 | if (getenv("LONG_ONLY")) { | ||
| 49 | gl = getopt_long_only; | ||
| 50 | printf("getopt_long_only"); | ||
| 51 | } else { | ||
| 52 | gl = getopt_long; | ||
| 53 | printf("getopt_long"); | ||
| 54 | } | ||
| 55 | if (getenv("POSIXLY_CORRECT")) | ||
| 56 | printf(" (POSIXLY_CORRECT)"); | ||
| 57 | printf(": "); | ||
| 58 | for (idx = 1; idx < argc; idx++) | ||
| 59 | printf("%s ", argv[idx]); | ||
| 60 | printf("\n"); | ||
| 61 | |||
| 62 | goggles = 0; | ||
| 63 | for (;;) { | ||
| 64 | idx = -1; | ||
| 65 | ch = gl(argc, argv, "19bf:i:hW;-", longopts, &idx); | ||
| 66 | if (ch == -1) | ||
| 67 | break; | ||
| 68 | switch (ch) { | ||
| 69 | case 0: | ||
| 70 | case '1': | ||
| 71 | case '9': | ||
| 72 | case 'h': | ||
| 73 | case 'b': | ||
| 74 | case '-': | ||
| 75 | if (idx != -1) { | ||
| 76 | if (goggles == 42) | ||
| 77 | printf("option %s, arg %s\n", | ||
| 78 | longopts[idx].name, optarg); | ||
| 79 | else | ||
| 80 | printf("option %s\n", | ||
| 81 | longopts[idx].name); | ||
| 82 | } else | ||
| 83 | printf("option %c\n", ch); | ||
| 84 | break; | ||
| 85 | case 'f': | ||
| 86 | case 'i': | ||
| 87 | if (idx != -1) | ||
| 88 | printf("option %s, arg %s\n", | ||
| 89 | longopts[idx].name, optarg); | ||
| 90 | else | ||
| 91 | printf("option %c, arg %s\n", ch, optarg); | ||
| 92 | break; | ||
| 93 | |||
| 94 | case '?': | ||
| 95 | break; | ||
| 96 | |||
| 97 | default: | ||
| 98 | printf("unexpected return value: %c\n", ch); | ||
| 99 | break; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | argc -= optind; | ||
| 103 | argv += optind; | ||
| 104 | |||
| 105 | if (argc > 0) { | ||
| 106 | printf("remaining ARGV: "); | ||
| 107 | while (argc--) | ||
| 108 | printf("%s ", *argv++); | ||
| 109 | printf("\n"); | ||
| 110 | } | ||
| 111 | printf("\n"); | ||
| 112 | |||
| 113 | exit (0); | ||
| 114 | } | ||
diff --git a/src/regress/lib/libc/getopt_long/test.ok b/src/regress/lib/libc/getopt_long/test.ok deleted file mode 100644 index 9782087f40..0000000000 --- a/src/regress/lib/libc/getopt_long/test.ok +++ /dev/null | |||
| @@ -1,84 +0,0 @@ | |||
| 1 | getopt_long: myfile --force -f infile -9 | ||
| 2 | option force | ||
| 3 | option f, arg infile | ||
| 4 | option 9 | ||
| 5 | remaining ARGV: myfile | ||
| 6 | |||
| 7 | getopt_long: onefile twofile --best -Williterate -i foo.in threefile | ||
| 8 | option best | ||
| 9 | option illiterate | ||
| 10 | option i, arg foo.in | ||
| 11 | remaining ARGV: onefile twofile threefile | ||
| 12 | |||
| 13 | getopt_long: -1bfast - | ||
| 14 | option 1 | ||
| 15 | option b | ||
| 16 | option f, arg ast | ||
| 17 | option - | ||
| 18 | |||
| 19 | getopt_long: --fast --drinking=guiness -i foo.in somefile | ||
| 20 | option fast | ||
| 21 | option drinking, arg guiness | ||
| 22 | option i, arg foo.in | ||
| 23 | remaining ARGV: somefile | ||
| 24 | |||
| 25 | getopt_long (POSIXLY_CORRECT): myfile --force -f infile -9 | ||
| 26 | remaining ARGV: myfile --force -f infile -9 | ||
| 27 | |||
| 28 | getopt_long (POSIXLY_CORRECT): onefile twofile --best -Williterate -i foo.in threefile | ||
| 29 | remaining ARGV: onefile twofile --best -Williterate -i foo.in threefile | ||
| 30 | |||
| 31 | getopt_long (POSIXLY_CORRECT): -1bfast - | ||
| 32 | option 1 | ||
| 33 | option b | ||
| 34 | option f, arg ast | ||
| 35 | option - | ||
| 36 | |||
| 37 | getopt_long (POSIXLY_CORRECT): --fast --drinking=guiness -i foo.in somefile | ||
| 38 | option fast | ||
| 39 | option drinking, arg guiness | ||
| 40 | option i, arg foo.in | ||
| 41 | remaining ARGV: somefile | ||
| 42 | |||
| 43 | getopt_long_only: myfile -force -f infile -9 | ||
| 44 | option force | ||
| 45 | option f, arg infile | ||
| 46 | option 9 | ||
| 47 | remaining ARGV: myfile | ||
| 48 | |||
| 49 | getopt_long_only: onefile twofile -best -Williterate -i foo.in threefile | ||
| 50 | option best | ||
| 51 | option illiterate | ||
| 52 | option i, arg foo.in | ||
| 53 | remaining ARGV: onefile twofile threefile | ||
| 54 | |||
| 55 | getopt_long_only: -1bfast - | ||
| 56 | option 1 | ||
| 57 | option b | ||
| 58 | option fast | ||
| 59 | option - | ||
| 60 | |||
| 61 | getopt_long_only: --fast -drinking=guiness -i foo.in somefile | ||
| 62 | option fast | ||
| 63 | option drinking, arg guiness | ||
| 64 | option i, arg foo.in | ||
| 65 | remaining ARGV: somefile | ||
| 66 | |||
| 67 | getopt_long_only (POSIXLY_CORRECT): myfile -force -f infile -9 | ||
| 68 | remaining ARGV: myfile -force -f infile -9 | ||
| 69 | |||
| 70 | getopt_long_only (POSIXLY_CORRECT): onefile twofile -best -Williterate -i foo.in threefile | ||
| 71 | remaining ARGV: onefile twofile -best -Williterate -i foo.in threefile | ||
| 72 | |||
| 73 | getopt_long_only (POSIXLY_CORRECT): -1bfast - | ||
| 74 | option 1 | ||
| 75 | option b | ||
| 76 | option fast | ||
| 77 | option - | ||
| 78 | |||
| 79 | getopt_long_only (POSIXLY_CORRECT): --fast -drinking=guiness -i foo.in somefile | ||
| 80 | option fast | ||
| 81 | option drinking, arg guiness | ||
| 82 | option i, arg foo.in | ||
| 83 | remaining ARGV: somefile | ||
| 84 | |||
diff --git a/src/regress/lib/libc/glob/Makefile b/src/regress/lib/libc/glob/Makefile deleted file mode 100644 index b3f9567833..0000000000 --- a/src/regress/lib/libc/glob/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2011/05/01 04:25:40 guenther Exp $ | ||
| 2 | |||
| 3 | PROG= globtest | ||
| 4 | |||
| 5 | run-regress-${PROG}: | ||
| 6 | mkdir -m 755 -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` | ||
| 7 | umask 022; touch `cat ${.CURDIR}/files` | ||
| 8 | chmod 0755 `grep '/r[^/]*$$' ${.CURDIR}/files` | ||
| 9 | chmod 0444 `grep '/s[^/]*$$' ${.CURDIR}/files` | ||
| 10 | chmod 0711 `grep '/t[^/]*$$' ${.CURDIR}/files` | ||
| 11 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
| 12 | |||
| 13 | clean: | ||
| 14 | rm -rf fake ${PROG} ${OBJS} *.core | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/glob/files b/src/regress/lib/libc/glob/files deleted file mode 100644 index c5e92aacd5..0000000000 --- a/src/regress/lib/libc/glob/files +++ /dev/null | |||
| @@ -1,47 +0,0 @@ | |||
| 1 | fake/bin/[ | ||
| 2 | fake/bin/cat | ||
| 3 | fake/bin/chgrp | ||
| 4 | fake/bin/chio | ||
| 5 | fake/bin/chmod | ||
| 6 | fake/bin/cksum | ||
| 7 | fake/bin/cp | ||
| 8 | fake/bin/cpio | ||
| 9 | fake/bin/csh | ||
| 10 | fake/bin/date | ||
| 11 | fake/bin/dd | ||
| 12 | fake/bin/df | ||
| 13 | fake/bin/domainname | ||
| 14 | fake/bin/echo | ||
| 15 | fake/bin/ed | ||
| 16 | fake/bin/eject | ||
| 17 | fake/bin/expr | ||
| 18 | fake/bin/hostname | ||
| 19 | fake/bin/kill | ||
| 20 | fake/bin/ksh | ||
| 21 | fake/bin/ln | ||
| 22 | fake/bin/ls | ||
| 23 | fake/bin/md5 | ||
| 24 | fake/bin/mkdir | ||
| 25 | fake/bin/mt | ||
| 26 | fake/bin/mv | ||
| 27 | fake/bin/pax | ||
| 28 | fake/bin/ps | ||
| 29 | fake/bin/pwd | ||
| 30 | fake/bin/rcp | ||
| 31 | fake/bin/rksh | ||
| 32 | fake/bin/rm | ||
| 33 | fake/bin/rmail | ||
| 34 | fake/bin/rmd160 | ||
| 35 | fake/bin/rmdir | ||
| 36 | fake/bin/sh | ||
| 37 | fake/bin/sha1 | ||
| 38 | fake/bin/sha256 | ||
| 39 | fake/bin/sha384 | ||
| 40 | fake/bin/sha512 | ||
| 41 | fake/bin/sleep | ||
| 42 | fake/bin/stty | ||
| 43 | fake/bin/sum | ||
| 44 | fake/bin/sync | ||
| 45 | fake/bin/systrace | ||
| 46 | fake/bin/tar | ||
| 47 | fake/bin/test | ||
diff --git a/src/regress/lib/libc/glob/globtest.c b/src/regress/lib/libc/glob/globtest.c deleted file mode 100644 index 325a7750f0..0000000000 --- a/src/regress/lib/libc/glob/globtest.c +++ /dev/null | |||
| @@ -1,142 +0,0 @@ | |||
| 1 | /* $OpenBSD: globtest.c,v 1.3 2011/01/07 19:45:44 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <glob.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #define MAX_RESULTS 256 | ||
| 14 | |||
| 15 | struct gl_entry { | ||
| 16 | int flags; | ||
| 17 | int nresults; | ||
| 18 | char pattern[1024]; | ||
| 19 | char *results[MAX_RESULTS]; | ||
| 20 | mode_t modes[MAX_RESULTS]; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int test_glob(struct gl_entry *); | ||
| 24 | |||
| 25 | int | ||
| 26 | main(int argc, char **argv) | ||
| 27 | { | ||
| 28 | FILE *fp = stdin; | ||
| 29 | char *buf, *cp; | ||
| 30 | int errors = 0, lineno, mode; | ||
| 31 | struct gl_entry entry; | ||
| 32 | size_t len; | ||
| 33 | |||
| 34 | if (argc > 1) { | ||
| 35 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
| 36 | err(1, "%s", argv[1]); | ||
| 37 | } | ||
| 38 | |||
| 39 | /* | ||
| 40 | * Read in test file, which is formatted thusly: | ||
| 41 | * | ||
| 42 | * [pattern] <flags> | ||
| 43 | * result1 [mode] | ||
| 44 | * result2 [mode] | ||
| 45 | * result3 [mode] | ||
| 46 | * ... | ||
| 47 | * | ||
| 48 | */ | ||
| 49 | lineno = 0; | ||
| 50 | memset(&entry, 0, sizeof(entry)); | ||
| 51 | while ((buf = fgetln(fp, &len)) != NULL) { | ||
| 52 | lineno++; | ||
| 53 | if (buf[len - 1] != '\n') | ||
| 54 | errx(1, "missing newline at EOF"); | ||
| 55 | buf[--len] = '\0'; | ||
| 56 | if (len == 0) | ||
| 57 | continue; /* blank line */ | ||
| 58 | |||
| 59 | if (buf[0] == '[') { | ||
| 60 | /* check previous pattern */ | ||
| 61 | if (entry.pattern[0]) | ||
| 62 | errors += test_glob(&entry); | ||
| 63 | |||
| 64 | /* start new entry */ | ||
| 65 | if ((cp = strrchr(buf + 1, ']')) == NULL) | ||
| 66 | errx(1, "invalid entry on line %d", lineno); | ||
| 67 | len = cp - buf - 1; | ||
| 68 | if (len >= sizeof(entry.pattern)) | ||
| 69 | errx(1, "pattern too big on line %d", lineno); | ||
| 70 | memcpy(entry.pattern, buf + 1, len); | ||
| 71 | entry.pattern[len] = '\0'; | ||
| 72 | |||
| 73 | buf = cp + 2; | ||
| 74 | if (*buf++ != '<') | ||
| 75 | errx(1, "invalid entry on line %d", lineno); | ||
| 76 | if ((cp = strchr(buf, '>')) == NULL) | ||
| 77 | errx(1, "invalid entry on line %d", lineno); | ||
| 78 | entry.flags = (int)strtol(buf, &cp, 0); | ||
| 79 | if (*cp != '>' || entry.flags < 0 || entry.flags > 0x4000) | ||
| 80 | errx(1, "invalid flags: %s", buf); | ||
| 81 | entry.nresults = 0; | ||
| 82 | continue; | ||
| 83 | } | ||
| 84 | if (!entry.pattern[0]) | ||
| 85 | errx(1, "missing entry on line %d", lineno); | ||
| 86 | |||
| 87 | if (entry.nresults + 1 > MAX_RESULTS) { | ||
| 88 | errx(1, "too many results for %s, max %d", | ||
| 89 | entry.pattern, MAX_RESULTS); | ||
| 90 | } | ||
| 91 | if ((cp = strchr(buf, ' ')) != NULL) { | ||
| 92 | *cp++ = '\0'; | ||
| 93 | mode = strtol(cp, NULL, 8); | ||
| 94 | } else | ||
| 95 | mode = -1; | ||
| 96 | entry.modes[entry.nresults] = (mode_t)mode; | ||
| 97 | entry.results[entry.nresults++] = strdup(buf); | ||
| 98 | } | ||
| 99 | if (entry.pattern[0]) | ||
| 100 | errors += test_glob(&entry); /* test last pattern */ | ||
| 101 | exit(errors); | ||
| 102 | } | ||
| 103 | |||
| 104 | int test_glob(struct gl_entry *entry) | ||
| 105 | { | ||
| 106 | glob_t gl; | ||
| 107 | int i = 0; | ||
| 108 | |||
| 109 | if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) | ||
| 110 | errx(1, "glob failed: %s", entry->pattern); | ||
| 111 | |||
| 112 | if (gl.gl_matchc != entry->nresults) | ||
| 113 | goto mismatch; | ||
| 114 | |||
| 115 | for (i = 0; i < gl.gl_matchc; i++) { | ||
| 116 | if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) | ||
| 117 | goto mismatch; | ||
| 118 | if ((entry->flags & GLOB_KEEPSTAT) != 0) { | ||
| 119 | if (entry->modes[i] == -1 || | ||
| 120 | gl.gl_statv[i] == NULL || | ||
| 121 | entry->modes[i] != gl.gl_statv[i]->st_mode) | ||
| 122 | goto badmode; | ||
| 123 | } | ||
| 124 | free(entry->results[i]); | ||
| 125 | } | ||
| 126 | return (0); | ||
| 127 | badmode: | ||
| 128 | warnx("mismatch mode for pattern %s, flags 0x%x, file \"%s\" " | ||
| 129 | "(found %07o, expected %07o)", entry->pattern, entry->flags, | ||
| 130 | gl.gl_pathv[i], gl.gl_statv[i] ? gl.gl_statv[i]->st_mode : 0, | ||
| 131 | entry->modes[i]); | ||
| 132 | goto cleanup; | ||
| 133 | mismatch: | ||
| 134 | warnx("mismatch for pattern %s, flags 0x%x " | ||
| 135 | "(found \"%s\", expected \"%s\")", entry->pattern, entry->flags, | ||
| 136 | gl.gl_pathv[i], entry->results[i]); | ||
| 137 | cleanup: | ||
| 138 | while (i < gl.gl_matchc) { | ||
| 139 | free(entry->results[i++]); | ||
| 140 | } | ||
| 141 | return (1); | ||
| 142 | } | ||
diff --git a/src/regress/lib/libc/glob/globtest.in b/src/regress/lib/libc/glob/globtest.in deleted file mode 100644 index 2ae3b4dfb2..0000000000 --- a/src/regress/lib/libc/glob/globtest.in +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | [fake/bin/[[:alpha:]]*] <0x0> | ||
| 2 | fake/bin/cat | ||
| 3 | fake/bin/chgrp | ||
| 4 | fake/bin/chio | ||
| 5 | fake/bin/chmod | ||
| 6 | fake/bin/cksum | ||
| 7 | fake/bin/cp | ||
| 8 | fake/bin/cpio | ||
| 9 | fake/bin/csh | ||
| 10 | fake/bin/date | ||
| 11 | fake/bin/dd | ||
| 12 | fake/bin/df | ||
| 13 | fake/bin/domainname | ||
| 14 | fake/bin/echo | ||
| 15 | fake/bin/ed | ||
| 16 | fake/bin/eject | ||
| 17 | fake/bin/expr | ||
| 18 | fake/bin/hostname | ||
| 19 | fake/bin/kill | ||
| 20 | fake/bin/ksh | ||
| 21 | fake/bin/ln | ||
| 22 | fake/bin/ls | ||
| 23 | fake/bin/md5 | ||
| 24 | fake/bin/mkdir | ||
| 25 | fake/bin/mt | ||
| 26 | fake/bin/mv | ||
| 27 | fake/bin/pax | ||
| 28 | fake/bin/ps | ||
| 29 | fake/bin/pwd | ||
| 30 | fake/bin/rcp | ||
| 31 | fake/bin/rksh | ||
| 32 | fake/bin/rm | ||
| 33 | fake/bin/rmail | ||
| 34 | fake/bin/rmd160 | ||
| 35 | fake/bin/rmdir | ||
| 36 | fake/bin/sh | ||
| 37 | fake/bin/sha1 | ||
| 38 | fake/bin/sha256 | ||
| 39 | fake/bin/sha384 | ||
| 40 | fake/bin/sha512 | ||
| 41 | fake/bin/sleep | ||
| 42 | fake/bin/stty | ||
| 43 | fake/bin/sum | ||
| 44 | fake/bin/sync | ||
| 45 | fake/bin/systrace | ||
| 46 | fake/bin/tar | ||
| 47 | fake/bin/test | ||
| 48 | |||
| 49 | [fake/bin/[[:alpha:]]*] <0x4000> | ||
| 50 | fake/bin/cat 0100644 | ||
| 51 | fake/bin/chgrp 0100644 | ||
| 52 | fake/bin/chio 0100644 | ||
| 53 | fake/bin/chmod 0100644 | ||
| 54 | fake/bin/cksum 0100644 | ||
| 55 | fake/bin/cp 0100644 | ||
| 56 | fake/bin/cpio 0100644 | ||
| 57 | fake/bin/csh 0100644 | ||
| 58 | fake/bin/date 0100644 | ||
| 59 | fake/bin/dd 0100644 | ||
| 60 | fake/bin/df 0100644 | ||
| 61 | fake/bin/domainname 0100644 | ||
| 62 | fake/bin/echo 0100644 | ||
| 63 | fake/bin/ed 0100644 | ||
| 64 | fake/bin/eject 0100644 | ||
| 65 | fake/bin/expr 0100644 | ||
| 66 | fake/bin/hostname 0100644 | ||
| 67 | fake/bin/kill 0100644 | ||
| 68 | fake/bin/ksh 0100644 | ||
| 69 | fake/bin/ln 0100644 | ||
| 70 | fake/bin/ls 0100644 | ||
| 71 | fake/bin/md5 0100644 | ||
| 72 | fake/bin/mkdir 0100644 | ||
| 73 | fake/bin/mt 0100644 | ||
| 74 | fake/bin/mv 0100644 | ||
| 75 | fake/bin/pax 0100644 | ||
| 76 | fake/bin/ps 0100644 | ||
| 77 | fake/bin/pwd 0100644 | ||
| 78 | fake/bin/rcp 0100755 | ||
| 79 | fake/bin/rksh 0100755 | ||
| 80 | fake/bin/rm 0100755 | ||
| 81 | fake/bin/rmail 0100755 | ||
| 82 | fake/bin/rmd160 0100755 | ||
| 83 | fake/bin/rmdir 0100755 | ||
| 84 | fake/bin/sh 0100444 | ||
| 85 | fake/bin/sha1 0100444 | ||
| 86 | fake/bin/sha256 0100444 | ||
| 87 | fake/bin/sha384 0100444 | ||
| 88 | fake/bin/sha512 0100444 | ||
| 89 | fake/bin/sleep 0100444 | ||
| 90 | fake/bin/stty 0100444 | ||
| 91 | fake/bin/sum 0100444 | ||
| 92 | fake/bin/sync 0100444 | ||
| 93 | fake/bin/systrace 0100444 | ||
| 94 | fake/bin/tar 0100711 | ||
| 95 | fake/bin/test 0100711 | ||
| 96 | |||
| 97 | [fake/bin/rm{,dir,ail}] <0x80> | ||
| 98 | fake/bin/rm | ||
| 99 | fake/bin/rmdir | ||
| 100 | fake/bin/rmail | ||
| 101 | |||
| 102 | [fake/bin/sha[[:digit:]]] <0x0> | ||
| 103 | fake/bin/sha1 | ||
| 104 | |||
| 105 | [fake/bin/sha[[:digit:]]*] <0x0> | ||
| 106 | fake/bin/sha1 | ||
| 107 | fake/bin/sha256 | ||
| 108 | fake/bin/sha384 | ||
| 109 | fake/bin/sha512 | ||
| 110 | |||
| 111 | [fake/bin/ca[a-z]] <0x0> | ||
| 112 | fake/bin/cat | ||
| 113 | |||
| 114 | [fake/b[a-z]*] <0x4000> | ||
| 115 | fake/bin 0040755 | ||
| 116 | |||
diff --git a/src/regress/lib/libc/hsearch/Makefile b/src/regress/lib/libc/hsearch/Makefile deleted file mode 100644 index cddc8ac0c4..0000000000 --- a/src/regress/lib/libc/hsearch/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/06/24 04:33:07 millert Exp $ | ||
| 2 | |||
| 3 | PROG= hsearchtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/hsearch/hsearchtest.c b/src/regress/lib/libc/hsearch/hsearchtest.c deleted file mode 100644 index 8659ef7e77..0000000000 --- a/src/regress/lib/libc/hsearch/hsearchtest.c +++ /dev/null | |||
| @@ -1,122 +0,0 @@ | |||
| 1 | /* $OpenBSD: hsearchtest.c,v 1.2 2009/10/27 23:59:32 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: hsearchtest.c,v 1.5 2003/07/26 19:38:46 salo Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 2001 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed for the | ||
| 19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
| 20 | * information about NetBSD. | ||
| 21 | * 4. The name of the author may not be used to endorse or promote products | ||
| 22 | * derived from this software without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 34 | * | ||
| 35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
| 36 | */ | ||
| 37 | |||
| 38 | /* | ||
| 39 | * Test program for hsearch() et al. | ||
| 40 | */ | ||
| 41 | |||
| 42 | #include <search.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <stdio.h> | ||
| 45 | #include <string.h> | ||
| 46 | |||
| 47 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)) | ||
| 48 | |||
| 49 | static void | ||
| 50 | testfail(const char *file, unsigned long line, const char *expression) | ||
| 51 | { | ||
| 52 | |||
| 53 | fprintf(stderr, "TEST FAILED: %s: file %s, line %ld\n", | ||
| 54 | expression, file, line); | ||
| 55 | exit(1); | ||
| 56 | } | ||
| 57 | |||
| 58 | int | ||
| 59 | main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | ENTRY e, *ep, *ep2; | ||
| 62 | int created_ok; | ||
| 63 | char ch[2]; | ||
| 64 | int i; | ||
| 65 | |||
| 66 | created_ok = hcreate(16); | ||
| 67 | TEST(created_ok); | ||
| 68 | |||
| 69 | /* ch[1] should be constant from here on down. */ | ||
| 70 | ch[1] = '\0'; | ||
| 71 | |||
| 72 | /* Basic insertions. Check enough that there'll be collisions. */ | ||
| 73 | for (i = 0; i < 26; i++) { | ||
| 74 | ch[0] = 'a' + i; | ||
| 75 | e.key = strdup(ch); /* ptr to provided key is kept! */ | ||
| 76 | TEST(e.key != NULL); | ||
| 77 | e.data = (void *)(long)i; | ||
| 78 | ep = hsearch(e, ENTER); | ||
| 79 | TEST(ep != NULL); | ||
| 80 | TEST(strcmp(ep->key, ch) == 0); | ||
| 81 | TEST((long)ep->data == i); | ||
| 82 | } | ||
| 83 | |||
| 84 | /* e.key should be constant from here on down. */ | ||
| 85 | e.key = ch; | ||
| 86 | |||
| 87 | /* Basic lookups. */ | ||
| 88 | for (i = 0; i < 26; i++) { | ||
| 89 | ch[0] = 'a' + i; | ||
| 90 | ep = hsearch(e, FIND); | ||
| 91 | TEST(ep != NULL); | ||
| 92 | TEST(strcmp(ep->key, ch) == 0); | ||
| 93 | TEST((long)ep->data == i); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* Check duplicate entry. Should _not_ overwrite existing data. */ | ||
| 97 | ch[0] = 'a'; | ||
| 98 | e.data = (void *)(long)12345; | ||
| 99 | ep = hsearch(e, FIND); | ||
| 100 | TEST(ep != NULL); | ||
| 101 | TEST(strcmp(ep->key, ch) == 0); | ||
| 102 | TEST((long)ep->data == 0); | ||
| 103 | |||
| 104 | /* Check for something that's not there. */ | ||
| 105 | ch[0] = 'A'; | ||
| 106 | ep = hsearch(e, FIND); | ||
| 107 | TEST(ep == NULL); | ||
| 108 | |||
| 109 | /* Check two at once. */ | ||
| 110 | ch[0] = 'a'; | ||
| 111 | ep = hsearch(e, FIND); | ||
| 112 | ch[0] = 'b'; | ||
| 113 | ep2 = hsearch(e, FIND); | ||
| 114 | TEST(ep != NULL); | ||
| 115 | TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); | ||
| 116 | TEST(ep2 != NULL); | ||
| 117 | TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); | ||
| 118 | |||
| 119 | hdestroy(); | ||
| 120 | |||
| 121 | exit(0); | ||
| 122 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile deleted file mode 100644 index 89ff51a2e7..0000000000 --- a/src/regress/lib/libc/ieeefp/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2004/01/15 18:53:23 miod Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
| 3 | |||
| 4 | SUBDIR+= except inf infinity round | ||
| 5 | |||
| 6 | install: | ||
| 7 | |||
| 8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile deleted file mode 100644 index 205331548f..0000000000 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ | ||
| 2 | |||
| 3 | PROG=except | ||
| 4 | |||
| 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund | ||
| 6 | |||
| 7 | fltdiv: ${PROG} | ||
| 8 | ./${PROG} fltdiv | ||
| 9 | |||
| 10 | fltinv: ${PROG} | ||
| 11 | ./${PROG} fltinv | ||
| 12 | |||
| 13 | fltovf: ${PROG} | ||
| 14 | ./${PROG} fltovf | ||
| 15 | |||
| 16 | fltund: ${PROG} | ||
| 17 | ./${PROG} fltund | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c deleted file mode 100644 index cc3dcf8e44..0000000000 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ /dev/null | |||
| @@ -1,110 +0,0 @@ | |||
| 1 | /* $OpenBSD: except.c,v 1.12 2010/05/08 19:16:33 naddy Exp $ */ | ||
| 2 | |||
| 3 | #include <sys/types.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <signal.h> | ||
| 9 | #include <assert.h> | ||
| 10 | #include <ieeefp.h> | ||
| 11 | #include <float.h> | ||
| 12 | #include <err.h> | ||
| 13 | |||
| 14 | volatile sig_atomic_t signal_status; | ||
| 15 | |||
| 16 | volatile const double one = 1.0; | ||
| 17 | volatile const double zero = 0.0; | ||
| 18 | volatile const double huge = DBL_MAX; | ||
| 19 | volatile const double tiny = DBL_MIN; | ||
| 20 | |||
| 21 | void | ||
| 22 | sigfpe(int sig, siginfo_t *si, void *v) | ||
| 23 | { | ||
| 24 | char buf[132]; | ||
| 25 | |||
| 26 | if (si) { | ||
| 27 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
| 28 | si->si_addr, si->si_code); | ||
| 29 | write(1, buf, strlen(buf)); | ||
| 30 | } | ||
| 31 | _exit(signal_status); | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | int | ||
| 36 | main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | struct sigaction sa; | ||
| 39 | volatile double x; | ||
| 40 | |||
| 41 | if (argc != 2) { | ||
| 42 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
| 43 | exit(1); | ||
| 44 | } | ||
| 45 | |||
| 46 | /* | ||
| 47 | * check to make sure that all exceptions are masked and | ||
| 48 | * that the accumulated exception status is clear. | ||
| 49 | */ | ||
| 50 | assert(fpgetmask() == 0); | ||
| 51 | assert(fpgetsticky() == 0); | ||
| 52 | |||
| 53 | memset(&sa, 0, sizeof(sa)); | ||
| 54 | sa.sa_sigaction = sigfpe; | ||
| 55 | sa.sa_flags = SA_SIGINFO; | ||
| 56 | sigaction(SIGFPE, &sa, NULL); | ||
| 57 | signal_status = 1; | ||
| 58 | |||
| 59 | if (strcmp(argv[1], "fltdiv") == 0) { | ||
| 60 | /* trip divide by zero */ | ||
| 61 | x = one / zero; | ||
| 62 | assert(fpgetsticky() & FP_X_DZ); | ||
| 63 | fpsetsticky(0); | ||
| 64 | |||
| 65 | /* and now unmask to get a signal */ | ||
| 66 | signal_status = 0; | ||
| 67 | fpsetmask(FP_X_DZ); | ||
| 68 | x = one / zero; | ||
| 69 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
| 70 | /* trip invalid operation */ | ||
| 71 | x = zero / zero; | ||
| 72 | assert(fpgetsticky() & FP_X_INV); | ||
| 73 | fpsetsticky(0); | ||
| 74 | |||
| 75 | /* and now unmask to get a signal */ | ||
| 76 | signal_status = 0; | ||
| 77 | fpsetmask(FP_X_INV); | ||
| 78 | x = zero / zero; | ||
| 79 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
| 80 | /* trip overflow */ | ||
| 81 | x = huge * huge; | ||
| 82 | assert(fpgetsticky() & FP_X_OFL); | ||
| 83 | fpsetsticky(0); | ||
| 84 | |||
| 85 | /* and now unmask to get a signal */ | ||
| 86 | signal_status = 0; | ||
| 87 | fpsetmask(FP_X_OFL); | ||
| 88 | x = huge * huge; | ||
| 89 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
| 90 | /* trip underflow */ | ||
| 91 | x = tiny * tiny; | ||
| 92 | assert(fpgetsticky() & FP_X_UFL); | ||
| 93 | fpsetsticky(0); | ||
| 94 | |||
| 95 | /* and now unmask to get a signal */ | ||
| 96 | signal_status = 0; | ||
| 97 | fpsetmask(FP_X_UFL); | ||
| 98 | x = tiny * tiny; | ||
| 99 | } else { | ||
| 100 | errx(1, "unrecognized condition %s", argv[1]); | ||
| 101 | } | ||
| 102 | |||
| 103 | /* | ||
| 104 | * attempt to trigger the exception on machines where | ||
| 105 | * floating-point exceptions are deferred. | ||
| 106 | */ | ||
| 107 | x = one * one; | ||
| 108 | |||
| 109 | errx(1, "signal wasn't caught"); | ||
| 110 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/Makefile b/src/regress/lib/libc/ieeefp/inf/Makefile deleted file mode 100644 index b9a50e0ce6..0000000000 --- a/src/regress/lib/libc/ieeefp/inf/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 17:22:16 pvalchev Exp $ | ||
| 2 | |||
| 3 | PROG= inf | ||
| 4 | SRCS= inf.c | ||
| 5 | |||
| 6 | LDADD+= -lm | ||
| 7 | DPADD+= ${LIBM} | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/inf.c b/src/regress/lib/libc/ieeefp/inf/inf.c deleted file mode 100644 index a1956145a6..0000000000 --- a/src/regress/lib/libc/ieeefp/inf/inf.c +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | /* $OpenBSD: inf.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | |||
| 9 | int | ||
| 10 | main(int argc, char *argv[]) | ||
| 11 | { | ||
| 12 | if (isinf(HUGE_VAL)) | ||
| 13 | return 0; | ||
| 14 | |||
| 15 | return 1; | ||
| 16 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile deleted file mode 100644 index ac102d8a63..0000000000 --- a/src/regress/lib/libc/ieeefp/infinity/Makefile +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ | ||
| 2 | |||
| 3 | PROG= infinity | ||
| 4 | |||
| 5 | DPADD+= ${LIBM} | ||
| 6 | LDADD+= -lm | ||
| 7 | |||
| 8 | REGRESS_TARGETS+= add mult neg pumpkin | ||
| 9 | |||
| 10 | add: ${PROG} | ||
| 11 | ./${PROG} -a | ||
| 12 | |||
| 13 | mult: ${PROG} | ||
| 14 | ./${PROG} -m | ||
| 15 | |||
| 16 | neg: ${PROG} | ||
| 17 | ./${PROG} -n | ||
| 18 | |||
| 19 | pumpkin: ${PROG} | ||
| 20 | ./${PROG} -p | ||
| 21 | |||
| 22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/infinity.c b/src/regress/lib/libc/ieeefp/infinity/infinity.c deleted file mode 100644 index 3b1b71ec90..0000000000 --- a/src/regress/lib/libc/ieeefp/infinity/infinity.c +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Miodrag Vallat, 2004 - Public Domain | ||
| 4 | * Inspired from Perl's t/op/arith test #134 | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <math.h> | ||
| 8 | #include <signal.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | void | ||
| 12 | sigfpe(int signum) | ||
| 13 | { | ||
| 14 | /* looks like we don't handle fp overflow correctly... */ | ||
| 15 | _exit(1); | ||
| 16 | } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(int argc, char *argv[]) | ||
| 20 | { | ||
| 21 | int opt; | ||
| 22 | double d, two; | ||
| 23 | int i; | ||
| 24 | char method = 'a'; | ||
| 25 | |||
| 26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
| 27 | method = (char)opt; | ||
| 28 | |||
| 29 | signal(SIGFPE, sigfpe); | ||
| 30 | |||
| 31 | switch (method) { | ||
| 32 | case 'a': | ||
| 33 | /* try to produce +Inf through addition */ | ||
| 34 | d = 1.0; | ||
| 35 | for (i = 2000; i != 0; i--) { | ||
| 36 | d = d + d; | ||
| 37 | } | ||
| 38 | /* result should be _positive_ infinity */ | ||
| 39 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 40 | return (1); | ||
| 41 | break; | ||
| 42 | case 'm': | ||
| 43 | /* try to produce +Inf through multiplication */ | ||
| 44 | d = 1.0; | ||
| 45 | two = 2.0; | ||
| 46 | for (i = 2000; i != 0; i--) { | ||
| 47 | d = d * two; | ||
| 48 | } | ||
| 49 | /* result should be _positive_ infinity */ | ||
| 50 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
| 51 | return (1); | ||
| 52 | break; | ||
| 53 | case 'n': | ||
| 54 | /* try to produce -Inf through subtraction */ | ||
| 55 | d = -1.0; | ||
| 56 | for (i = 2000; i != 0; i--) { | ||
| 57 | d = d + d; | ||
| 58 | } | ||
| 59 | /* result should be _negative_ infinity */ | ||
| 60 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 61 | return (1); | ||
| 62 | break; | ||
| 63 | case 'p': | ||
| 64 | /* try to produce -Inf through multiplication */ | ||
| 65 | d = -1.0; | ||
| 66 | two = 2.0; | ||
| 67 | for (i = 2000; i != 0; i--) { | ||
| 68 | d = d * two; | ||
| 69 | } | ||
| 70 | /* result should be _negative_ infinity */ | ||
| 71 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
| 72 | return (1); | ||
| 73 | break; | ||
| 74 | } | ||
| 75 | |||
| 76 | return (0); | ||
| 77 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/round/Makefile b/src/regress/lib/libc/ieeefp/round/Makefile deleted file mode 100644 index 9ea6dd8c39..0000000000 --- a/src/regress/lib/libc/ieeefp/round/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ | ||
| 2 | |||
| 3 | PROG= round | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c deleted file mode 100644 index 807941ea56..0000000000 --- a/src/regress/lib/libc/ieeefp/round/round.c +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Written by J.T. Conklin, Apr 18, 1995 | ||
| 6 | * Public domain. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <ieeefp.h> | ||
| 12 | #include <float.h> | ||
| 13 | |||
| 14 | int | ||
| 15 | main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | /* | ||
| 18 | * This test would be better if it actually performed some | ||
| 19 | * calculations to verify the selected rounding mode. But | ||
| 20 | * this is probably acceptable since the fp{get,set}round | ||
| 21 | * functions usually just get or set the processors fpu | ||
| 22 | * control word. | ||
| 23 | */ | ||
| 24 | |||
| 25 | assert(fpgetround() == FP_RN); | ||
| 26 | assert(FLT_ROUNDS == 1); | ||
| 27 | |||
| 28 | assert(fpsetround(FP_RP) == FP_RN); | ||
| 29 | assert(fpgetround() == FP_RP); | ||
| 30 | assert(FLT_ROUNDS == 2); | ||
| 31 | |||
| 32 | assert(fpsetround(FP_RM) == FP_RP); | ||
| 33 | assert(fpgetround() == FP_RM); | ||
| 34 | assert(FLT_ROUNDS == 3); | ||
| 35 | |||
| 36 | assert(fpsetround(FP_RZ) == FP_RM); | ||
| 37 | assert(fpgetround() == FP_RZ); | ||
| 38 | assert(FLT_ROUNDS == 0); | ||
| 39 | |||
| 40 | assert(fpsetround(FP_RN) == FP_RZ); | ||
| 41 | assert(fpgetround() == FP_RN); | ||
| 42 | assert(FLT_ROUNDS == 1); | ||
| 43 | |||
| 44 | exit(0); | ||
| 45 | } | ||
diff --git a/src/regress/lib/libc/ifnameindex/Makefile b/src/regress/lib/libc/ifnameindex/Makefile deleted file mode 100644 index 1f21973a10..0000000000 --- a/src/regress/lib/libc/ifnameindex/Makefile +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2015/10/22 15:47:00 claudio Exp $ | ||
| 2 | |||
| 3 | PROG= ifnitest | ||
| 4 | SRCS= ifnitest.c | ||
| 5 | NOMAN= # defined | ||
| 6 | |||
| 7 | REGRESS_TARGETS=do-test | ||
| 8 | |||
| 9 | do-test: ${PROG} | ||
| 10 | ./${PROG} | ||
| 11 | |||
| 12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ifnameindex/ifnitest.c b/src/regress/lib/libc/ifnameindex/ifnitest.c deleted file mode 100644 index fb7ed3704f..0000000000 --- a/src/regress/lib/libc/ifnameindex/ifnitest.c +++ /dev/null | |||
| @@ -1,32 +0,0 @@ | |||
| 1 | /* $OpenBSD: ifnitest.c,v 1.3 2017/02/25 07:28:32 jsg Exp $ */ | ||
| 2 | |||
| 3 | /* Public domain. 2015, Claudio Jeker */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/socket.h> | ||
| 7 | #include <net/if.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | int | ||
| 13 | main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | char name[IF_NAMESIZE], *ifname; | ||
| 16 | unsigned int lo0index; | ||
| 17 | |||
| 18 | lo0index = if_nametoindex("lo0"); | ||
| 19 | if (lo0index == 0) | ||
| 20 | err(1, "if_nametoindex(lo0)"); | ||
| 21 | ifname = if_indextoname(lo0index, name); | ||
| 22 | if (ifname == NULL || strcmp("lo0", ifname) != 0) | ||
| 23 | err(1, "if_indextoname(%u)", lo0index); | ||
| 24 | |||
| 25 | /* test failures */ | ||
| 26 | if (if_nametoindex("4kingbula") != 0) | ||
| 27 | err(1, "if_nametoindex(4kingbula)"); | ||
| 28 | if (if_indextoname(65536, name) != NULL) | ||
| 29 | err(1, "if_indextoname(%u)", 65536); | ||
| 30 | |||
| 31 | return 0; | ||
| 32 | } | ||
diff --git a/src/regress/lib/libc/ldexp/Makefile b/src/regress/lib/libc/ldexp/Makefile deleted file mode 100644 index bfe79ac679..0000000000 --- a/src/regress/lib/libc/ldexp/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/10/15 12:15:30 visa Exp $ | ||
| 2 | |||
| 3 | PROG=ldexp_test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ldexp/ldexp_test.c b/src/regress/lib/libc/ldexp/ldexp_test.c deleted file mode 100644 index 75031e3083..0000000000 --- a/src/regress/lib/libc/ldexp/ldexp_test.c +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | /* $OpenBSD: ldexp_test.c,v 1.1 2017/10/15 12:15:30 visa Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2017 Visa Hankala | ||
| 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 <assert.h> | ||
| 20 | #include <math.h> | ||
| 21 | |||
| 22 | int | ||
| 23 | main(int argc, char *argv[]) | ||
| 24 | { | ||
| 25 | double f; | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Test that the result has the correct sign. | ||
| 29 | * Assumes IEEE 754 double-precision arithmetics. | ||
| 30 | */ | ||
| 31 | |||
| 32 | assert(ldexp(1.0, -1022) > 0.0); /* IEEE 754 minimum normal positive */ | ||
| 33 | assert(ldexp(1.0, -1023) > 0.0); /* subnormal positive */ | ||
| 34 | assert(ldexp(1.0, -1024) > 0.0); /* subnormal positive */ | ||
| 35 | assert(ldexp(1.0, -1074) > 0.0); /* minimum subnormal positive */ | ||
| 36 | assert(ldexp(1.0, -1075) >= 0.0); /* zero */ | ||
| 37 | assert(ldexp(ldexp(1.0, -1022), -53) >= 0.0); /* zero */ | ||
| 38 | |||
| 39 | assert(ldexp(1.0, 1023) > 0.0); /* normal positive */ | ||
| 40 | |||
| 41 | f = ldexp(1.0, 1024); /* infinite positive */ | ||
| 42 | assert(isinf(f)); | ||
| 43 | assert(!signbit(f)); | ||
| 44 | |||
| 45 | f = ldexp(ldexp(1.0, 1023), 1); /* infinite positive */ | ||
| 46 | assert(isinf(f)); | ||
| 47 | assert(!signbit(f)); | ||
| 48 | |||
| 49 | assert(ldexp(-1.0, -1022) < 0.0); /* IEEE 754 maximum normal negative */ | ||
| 50 | assert(ldexp(-1.0, -1023) < 0.0); /* subnormal negative */ | ||
| 51 | assert(ldexp(-1.0, -1024) < 0.0); /* subnormal negative */ | ||
| 52 | assert(ldexp(-1.0, -1074) < 0.0); /* maximum subnormal negative */ | ||
| 53 | assert(ldexp(-1.0, -1075) <= 0.0); /* zero */ | ||
| 54 | assert(ldexp(ldexp(-1.0, -1022), -53) <= 0.0); /* zero */ | ||
| 55 | |||
| 56 | assert(ldexp(-1.0, 1023) < 0.0); /* normal negative */ | ||
| 57 | |||
| 58 | f = ldexp(-1.0, 1024); /* infinite negative */ | ||
| 59 | assert(isinf(f)); | ||
| 60 | assert(signbit(f)); | ||
| 61 | |||
| 62 | f = ldexp(ldexp(-1.0, 1023), 1); /* infinite negative */ | ||
| 63 | assert(isinf(f)); | ||
| 64 | assert(signbit(f)); | ||
| 65 | |||
| 66 | f = ldexp(NAN, 0); | ||
| 67 | assert(isnan(f)); | ||
| 68 | assert(!signbit(f)); | ||
| 69 | |||
| 70 | f = ldexp(-NAN, 0); | ||
| 71 | assert(isnan(f)); | ||
| 72 | assert(signbit(f)); | ||
| 73 | |||
| 74 | return 0; | ||
| 75 | } | ||
diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile deleted file mode 100644 index b3ca6bad85..0000000000 --- a/src/regress/lib/libc/locale/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | SUBDIR = check_isw mbrtowc setlocale wcrtomb | ||
| 4 | |||
| 5 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile deleted file mode 100644 index cd79d6cb7f..0000000000 --- a/src/regress/lib/libc/locale/check_isw/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = check_isw | ||
| 4 | |||
| 5 | run-regress-${PROG}: ${PROG} | ||
| 6 | ./${PROG} >/dev/null | ||
| 7 | |||
| 8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c deleted file mode 100644 index 718f387883..0000000000 --- a/src/regress/lib/libc/locale/check_isw/check_isw.c +++ /dev/null | |||
| @@ -1,147 +0,0 @@ | |||
| 1 | /* $OpenBSD: check_isw.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2005 Marc Espie <espie@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* This checks consistency of the isw* functions with the default <ctype> | ||
| 19 | * functions. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <ctype.h> | ||
| 25 | #include <wchar.h> | ||
| 26 | #include <wctype.h> | ||
| 27 | |||
| 28 | int bad = 0; | ||
| 29 | |||
| 30 | void | ||
| 31 | check_bool(int v1, int v2, char msg) | ||
| 32 | { | ||
| 33 | if (!v1 != !v2) { | ||
| 34 | printf("%c", msg); | ||
| 35 | bad++; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | void | ||
| 40 | check_value(int v1, int v2, char msg) | ||
| 41 | { | ||
| 42 | if (v1 != v2) { | ||
| 43 | printf("%c", msg); | ||
| 44 | bad++; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | void | ||
| 49 | test1() | ||
| 50 | { | ||
| 51 | int i; | ||
| 52 | |||
| 53 | for (i = 0; i < 256; i++) { | ||
| 54 | printf(" %02x: ", i); | ||
| 55 | check_bool(isalnum(i), iswalnum(i), '1'); | ||
| 56 | check_bool(isalpha(i), iswalpha(i), '2'); | ||
| 57 | check_bool(isblank(i), iswblank(i), '3'); | ||
| 58 | check_bool(iscntrl(i), iswcntrl(i), '4'); | ||
| 59 | check_bool(isdigit(i), iswdigit(i), '5'); | ||
| 60 | check_bool(isgraph(i), iswgraph(i), '6'); | ||
| 61 | check_bool(islower(i), iswlower(i), '6'); | ||
| 62 | check_bool(isprint(i), iswprint(i), '7'); | ||
| 63 | check_bool(ispunct(i), iswpunct(i), '8'); | ||
| 64 | check_bool(isspace(i), iswspace(i), '9'); | ||
| 65 | check_bool(isupper(i), iswupper(i), 'a'); | ||
| 66 | check_bool(isxdigit(i), iswxdigit(i), 'b'); | ||
| 67 | check_value(tolower(i), towlower(i), 'c'); | ||
| 68 | check_value(toupper(i), towupper(i), 'd'); | ||
| 69 | if (i % 8 == 7) | ||
| 70 | printf("\n"); | ||
| 71 | } | ||
| 72 | printf("\n"); | ||
| 73 | } | ||
| 74 | |||
| 75 | void | ||
| 76 | test2() | ||
| 77 | { | ||
| 78 | unsigned char *s; | ||
| 79 | unsigned char *buf; | ||
| 80 | int i, j; | ||
| 81 | size_t n; | ||
| 82 | wchar_t c, d; | ||
| 83 | mbstate_t state; | ||
| 84 | |||
| 85 | s = malloc(256); | ||
| 86 | if (!s) { | ||
| 87 | bad++; | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | buf = malloc(MB_CUR_MAX); | ||
| 91 | if (!buf) { | ||
| 92 | bad++; | ||
| 93 | free(s); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | for (i = 0; i < 256; i++) | ||
| 97 | s[i] = i+1; | ||
| 98 | |||
| 99 | j = 0; | ||
| 100 | mbrtowc(NULL, NULL, 1, &state); | ||
| 101 | printf(" %02x: ", 0); | ||
| 102 | |||
| 103 | while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { | ||
| 104 | printf(" %02x: ", s[j]); | ||
| 105 | check_bool(isalnum(s[j]), iswalnum(c), '1'); | ||
| 106 | check_bool(isalpha(s[j]), iswalpha(c), '2'); | ||
| 107 | check_bool(isblank(s[j]), iswblank(c), '3'); | ||
| 108 | check_bool(iscntrl(s[j]), iswcntrl(c), '4'); | ||
| 109 | check_bool(isdigit(s[j]), iswdigit(c), '5'); | ||
| 110 | check_bool(isgraph(s[j]), iswgraph(c), '6'); | ||
| 111 | check_bool(islower(s[j]), iswlower(c), '6'); | ||
| 112 | check_bool(isprint(s[j]), iswprint(c), '7'); | ||
| 113 | check_bool(ispunct(s[j]), iswpunct(c), '8'); | ||
| 114 | check_bool(isspace(s[j]), iswspace(c), '9'); | ||
| 115 | check_bool(isupper(s[j]), iswupper(c), 'a'); | ||
| 116 | check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); | ||
| 117 | d = towlower(c); | ||
| 118 | if (wctomb(buf, d) == 1) { | ||
| 119 | check_value(tolower(s[j]), buf[0], 'c'); | ||
| 120 | } else { | ||
| 121 | bad++; | ||
| 122 | } | ||
| 123 | d = towupper(c); | ||
| 124 | if (wctomb(buf, d) == 1) { | ||
| 125 | check_value(toupper(s[j]), buf[0], 'c'); | ||
| 126 | } else { | ||
| 127 | bad++; | ||
| 128 | } | ||
| 129 | if (s[j] % 8 == 7) | ||
| 130 | printf("\n"); | ||
| 131 | j++; | ||
| 132 | } | ||
| 133 | if (n != 0 || j != 255) { | ||
| 134 | bad++; | ||
| 135 | } | ||
| 136 | free(s); | ||
| 137 | free(buf); | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | int | ||
| 142 | main() | ||
| 143 | { | ||
| 144 | test1(); | ||
| 145 | test2(); | ||
| 146 | return bad !=0; | ||
| 147 | } | ||
diff --git a/src/regress/lib/libc/locale/mbrtowc/Makefile b/src/regress/lib/libc/locale/mbrtowc/Makefile deleted file mode 100644 index 5436383911..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = test_mbrtowc | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c b/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c deleted file mode 100644 index 5926d25fd0..0000000000 --- a/src/regress/lib/libc/locale/mbrtowc/test_mbrtowc.c +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | /* $OpenBSD: test_mbrtowc.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | #include <err.h> | ||
| 20 | #include <errno.h> | ||
| 21 | #include <locale.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <wchar.h> | ||
| 25 | |||
| 26 | static mbstate_t mbs; | ||
| 27 | |||
| 28 | void | ||
| 29 | onetest(const char *name, const char *in, size_t insz, | ||
| 30 | int outerr, size_t outsz, wint_t out) | ||
| 31 | { | ||
| 32 | wchar_t wc; | ||
| 33 | size_t sz; | ||
| 34 | |||
| 35 | sz = mbrtowc(&wc, in, insz, &mbs); | ||
| 36 | if (errno != outerr) | ||
| 37 | err(1, "%zu %s(%zd)", MB_CUR_MAX, name, insz); | ||
| 38 | if (sz != outsz || (out != WEOF && wc != out)) | ||
| 39 | errx(1, "%zu %s(%zd) = (%zd, %d) != (%zd, %d)", | ||
| 40 | MB_CUR_MAX, name, insz, sz, wc, outsz, out); | ||
| 41 | if (mbsinit(&mbs) == (insz && outsz == (size_t)-2)) | ||
| 42 | errx(1, "%zu %s(%zd) mbsinit", MB_CUR_MAX, name, insz); | ||
| 43 | if (errno == 0 && outerr == 0) | ||
| 44 | return; | ||
| 45 | errno = 0; | ||
| 46 | memset(&mbs, 0, sizeof(mbs)); | ||
| 47 | } | ||
| 48 | |||
| 49 | int | ||
| 50 | main(void) | ||
| 51 | { | ||
| 52 | onetest("NUL", "", 0, 0, -2, WEOF); | ||
| 53 | onetest("NUL", "", 2, 0, 0, L'\0'); | ||
| 54 | onetest("BEL", "\a", 2, 0, 1, L'\a'); | ||
| 55 | onetest("A", "A", 2, 0, 1, L'A'); | ||
| 56 | onetest("DEL", "\177", 2, 0, 1, L'\177'); | ||
| 57 | onetest("CSI", "\233", 2, 0, 1, L'\233'); | ||
| 58 | |||
| 59 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
| 60 | errx(1, "setlocale(UTF-8) failed"), | ||
| 61 | |||
| 62 | onetest("NUL", "", 0, 0, -2, WEOF); | ||
| 63 | onetest("NUL", "", 8, 0, 0, L'\0'); | ||
| 64 | onetest("BEL", "\a", 8, 0, 1, L'\a'); | ||
| 65 | onetest("A", "A", 8, 0, 1, L'A'); | ||
| 66 | onetest("DEL", "\177", 8, 0, 1, L'\177'); | ||
| 67 | onetest("0x80", "\200", 8, EILSEQ, -1, WEOF); | ||
| 68 | onetest("0xc3", "\303", 1, 0, -2, WEOF); | ||
| 69 | onetest("U+00E9", "\251", 8, 0, 1, 0xe9); | ||
| 70 | onetest("0xec", "\354", 1, 0, -2, WEOF); | ||
| 71 | onetest("0xecbf", "\277", 1, 0, -2, WEOF); | ||
| 72 | onetest("U+CFFF", "\277", 8, 0, 1, 0xcfff); | ||
| 73 | |||
| 74 | if (setlocale(LC_CTYPE, "POSIX") == NULL) | ||
| 75 | errx(1, "setlocale(POSIX) failed"), | ||
| 76 | |||
| 77 | onetest("0xff", "\277", 2, 0, 1, L'\277'); | ||
| 78 | |||
| 79 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
| 80 | errx(1, "second setlocale(UTF-8) failed"), | ||
| 81 | |||
| 82 | onetest("U+13000", "\360\223\200\200", 8, 0, 4, 0x13000); | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
diff --git a/src/regress/lib/libc/locale/setlocale/Makefile b/src/regress/lib/libc/locale/setlocale/Makefile deleted file mode 100644 index 966f7926e5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = setlocale | ||
| 4 | |||
| 5 | run-regress-${PROG}: ${PROG} | ||
| 6 | env -i LC_ALL=fr_FR.UTF-8 ./${PROG} | ||
| 7 | |||
| 8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/setlocale/setlocale.c b/src/regress/lib/libc/locale/setlocale/setlocale.c deleted file mode 100644 index 82245df5c5..0000000000 --- a/src/regress/lib/libc/locale/setlocale/setlocale.c +++ /dev/null | |||
| @@ -1,125 +0,0 @@ | |||
| 1 | /* $OpenBSD: setlocale.c,v 1.4 2018/03/29 16:34:25 schwarze Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Sebastien Marie <semarie@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <locale.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include <ctype.h> | ||
| 24 | |||
| 25 | /* | ||
| 26 | * test helpers for __LINE__ | ||
| 27 | */ | ||
| 28 | #define test_setlocale(_e, _c, _l) _test_setlocale(_e, _c, _l, __LINE__) | ||
| 29 | #define test_MB_CUR_MAX(_e) _test_MB_CUR_MAX(_e, __LINE__) | ||
| 30 | #define test_isalpha(_e, _c) _test_isalpha(_e, _c, __LINE__) | ||
| 31 | |||
| 32 | |||
| 33 | static void | ||
| 34 | _test_setlocale(char *expected, int category, char *locale, int line) | ||
| 35 | { | ||
| 36 | char *result = setlocale(category, locale); | ||
| 37 | |||
| 38 | if ((expected == NULL) || (result == NULL)) { | ||
| 39 | if (expected == result) | ||
| 40 | return; | ||
| 41 | |||
| 42 | errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", | ||
| 43 | line, category, locale, result, expected); | ||
| 44 | } | ||
| 45 | |||
| 46 | if (strcmp(expected, result) != 0) | ||
| 47 | errx(1, "[%d] setlocale(%d, \"%s\")=\"%s\" [expected: \"%s\"]", | ||
| 48 | line, category, locale, result, expected); | ||
| 49 | } | ||
| 50 | |||
| 51 | static void | ||
| 52 | _test_MB_CUR_MAX(size_t expected, int line) | ||
| 53 | { | ||
| 54 | if (MB_CUR_MAX != expected) | ||
| 55 | errx(1, "[%d] MB_CUR_MAX=%ld [expected %ld]", | ||
| 56 | line, MB_CUR_MAX, expected); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void | ||
| 60 | _test_isalpha(int expected, int c, int line) | ||
| 61 | { | ||
| 62 | int result = isalpha(c); | ||
| 63 | if (!!result != expected) | ||
| 64 | errx(1, "[%d] isalpha(%d)=%d [expected %d]", | ||
| 65 | line, c, result, expected); | ||
| 66 | } | ||
| 67 | |||
| 68 | int | ||
| 69 | main(int argc, char *argv[]) | ||
| 70 | { | ||
| 71 | /* check initial state (should be "C") */ | ||
| 72 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
| 73 | test_MB_CUR_MAX(1); | ||
| 74 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
| 75 | |||
| 76 | /* load from env */ | ||
| 77 | /* NOTE: we don't support non-C locales for some categories */ | ||
| 78 | test_setlocale("fr_FR.UTF-8", LC_CTYPE, ""); /* set */ | ||
| 79 | test_setlocale("fr_FR.UTF-8", LC_MESSAGES, ""); /* set */ | ||
| 80 | test_MB_CUR_MAX(4); | ||
| 81 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
| 82 | |||
| 83 | test_setlocale("C", LC_MESSAGES, "C"); /* set */ | ||
| 84 | test_MB_CUR_MAX(4); | ||
| 85 | test_setlocale("C/fr_FR.UTF-8/C/C/C/C", LC_ALL, NULL); /* check */ | ||
| 86 | |||
| 87 | test_setlocale("C", LC_CTYPE, "C"); /* set */ | ||
| 88 | test_MB_CUR_MAX(1); | ||
| 89 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
| 90 | |||
| 91 | /* check for errors on checking */ | ||
| 92 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
| 93 | test_setlocale(NULL, -1, NULL); | ||
| 94 | test_setlocale(NULL, _LC_LAST, NULL); | ||
| 95 | test_setlocale(NULL, _LC_LAST+0xff, NULL); | ||
| 96 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
| 97 | |||
| 98 | /* check for errors on setting */ | ||
| 99 | test_setlocale(NULL, -1, ""); | ||
| 100 | test_setlocale(NULL, _LC_LAST, ""); | ||
| 101 | test_setlocale(NULL, _LC_LAST+0xff, ""); | ||
| 102 | test_setlocale("C", LC_ALL, NULL); /* check */ | ||
| 103 | |||
| 104 | /* no codeset, fallback to ASCII */ | ||
| 105 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
| 106 | test_setlocale("invalid", LC_CTYPE, "invalid"); /* set */ | ||
| 107 | test_setlocale("invalid", LC_CTYPE, NULL); | ||
| 108 | test_MB_CUR_MAX(1); | ||
| 109 | test_isalpha(0, 0xe9); /* iso-8859-1 eacute */ | ||
| 110 | |||
| 111 | /* with codeset */ | ||
| 112 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
| 113 | test_setlocale("invalid.UTF-8", LC_CTYPE, "invalid.UTF-8"); /* set */ | ||
| 114 | test_setlocale("invalid.UTF-8", LC_CTYPE, NULL); | ||
| 115 | test_setlocale("C/invalid.UTF-8/C/C/C/C", LC_ALL, NULL); | ||
| 116 | test_MB_CUR_MAX(4); | ||
| 117 | |||
| 118 | /* with invalid codeset (is an error) */ | ||
| 119 | test_setlocale("C", LC_ALL, "C"); /* reset */ | ||
| 120 | test_setlocale(NULL, LC_CTYPE, "fr_FR.invalid"); /* set */ | ||
| 121 | test_setlocale("C", LC_CTYPE, NULL); | ||
| 122 | test_MB_CUR_MAX(1); | ||
| 123 | |||
| 124 | return (EXIT_SUCCESS); | ||
| 125 | } | ||
diff --git a/src/regress/lib/libc/locale/uselocale/Makefile b/src/regress/lib/libc/locale/uselocale/Makefile deleted file mode 100644 index a10471bcf6..0000000000 --- a/src/regress/lib/libc/locale/uselocale/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2017/08/16 01:40:30 schwarze Exp $ | ||
| 2 | |||
| 3 | PROG = uselocale | ||
| 4 | CFLAGS += -Wno-macro-redefined -Wno-int-to-pointer-cast | ||
| 5 | LDFLAGS += -pthread | ||
| 6 | |||
| 7 | run-regress-${PROG}: ${PROG} | ||
| 8 | ./${PROG} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/uselocale/uselocale.c b/src/regress/lib/libc/locale/uselocale/uselocale.c deleted file mode 100644 index 445bb64876..0000000000 --- a/src/regress/lib/libc/locale/uselocale/uselocale.c +++ /dev/null | |||
| @@ -1,482 +0,0 @@ | |||
| 1 | /* $OpenBSD: uselocale.c,v 1.5 2017/08/16 13:52:50 schwarze Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <ctype.h> | ||
| 19 | #include <err.h> | ||
| 20 | #include <errno.h> | ||
| 21 | #include <langinfo.h> | ||
| 22 | #include <locale.h> | ||
| 23 | #include <pthread.h> | ||
| 24 | #include <stdlib.h> | ||
| 25 | #include <string.h> | ||
| 26 | #include <wchar.h> | ||
| 27 | #include <wctype.h> | ||
| 28 | |||
| 29 | /* Keep in sync with /usr/src/lib/libc/locale/rune.h. */ | ||
| 30 | #define _LOCALE_NONE (locale_t)0 | ||
| 31 | #define _LOCALE_C (locale_t)1 | ||
| 32 | #define _LOCALE_UTF8 (locale_t)2 | ||
| 33 | #define _LOCALE_BAD (locale_t)3 | ||
| 34 | |||
| 35 | /* Options for switch_thread() below. */ | ||
| 36 | #define SWITCH_SIGNAL 1 /* Call pthread_cond_signal(3). */ | ||
| 37 | #define SWITCH_WAIT 2 /* Call pthread_cond_timedwait(3). */ | ||
| 38 | |||
| 39 | /* Options for TESTFUNC(). */ | ||
| 40 | #define TOPT_ERR (1 << 0) | ||
| 41 | #define TOPT_STR (1 << 1) | ||
| 42 | |||
| 43 | /* | ||
| 44 | * Generate one test function for a specific interface. | ||
| 45 | * Fn = function name | ||
| 46 | * Ft = function return type | ||
| 47 | * FUNCPARA = function parameter list with types and names | ||
| 48 | * FUNCARGS = function argument list, names only, no types | ||
| 49 | * Af = format string to print the arguments | ||
| 50 | * Rf = format string to print the return value | ||
| 51 | * Op = options for the test function, see above | ||
| 52 | * line = source code line number in this test file | ||
| 53 | * ee = expected error number | ||
| 54 | * er = expected return value | ||
| 55 | * ar = actual return value | ||
| 56 | * errno = actual error number (global) | ||
| 57 | */ | ||
| 58 | #define TESTFUNC(Fn, Ft, Af, Rf, Op) \ | ||
| 59 | static void \ | ||
| 60 | _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ | ||
| 61 | { \ | ||
| 62 | Ft ar; \ | ||
| 63 | errno = 0; \ | ||
| 64 | ar = Fn(FUNCARGS); \ | ||
| 65 | if (Op & TOPT_STR) { \ | ||
| 66 | if (er == (Ft)NULL) \ | ||
| 67 | er = (Ft)"NULL"; \ | ||
| 68 | if (ar == (Ft)NULL) \ | ||
| 69 | ar = (Ft)"NULL"; \ | ||
| 70 | } \ | ||
| 71 | if (Op & TOPT_STR ? strcmp((const char *)er, (const char *)ar) \ | ||
| 72 | : ar != er) \ | ||
| 73 | errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ | ||
| 74 | line, #Fn, FUNCARGS, ar, er); \ | ||
| 75 | if (Op & TOPT_ERR && errno != ee) \ | ||
| 76 | errx(1, "[%d] %s(" Af ") errno=%d [exp: %d]", \ | ||
| 77 | line, #Fn, FUNCARGS, errno, ee); \ | ||
| 78 | } | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Test functions for all tested interfaces. | ||
| 82 | */ | ||
| 83 | #define FUNCPARA int mask, const char *locname | ||
| 84 | #define FUNCARGS mask, locname, _LOCALE_NONE | ||
| 85 | TESTFUNC(newlocale, locale_t, "%d, %s, %p", "%p", TOPT_ERR) | ||
| 86 | |||
| 87 | #define FUNCPARA locale_t locale | ||
| 88 | #define FUNCARGS locale | ||
| 89 | TESTFUNC(duplocale, locale_t, "%p", "%p", TOPT_ERR) | ||
| 90 | TESTFUNC(uselocale, locale_t, "%p", "%p", TOPT_ERR) | ||
| 91 | |||
| 92 | #define FUNCPARA int category, char *locname | ||
| 93 | #define FUNCARGS category, locname | ||
| 94 | TESTFUNC(setlocale, const char *, "%d, %s", "%s", TOPT_STR) | ||
| 95 | |||
| 96 | #define FUNCPARA nl_item item | ||
| 97 | #define FUNCARGS item | ||
| 98 | TESTFUNC(nl_langinfo, const char *, "%ld", "%s", TOPT_STR) | ||
| 99 | |||
| 100 | #define FUNCPARA nl_item item, locale_t locale | ||
| 101 | #define FUNCARGS item, locale | ||
| 102 | TESTFUNC(nl_langinfo_l, const char *, "%ld, %p", "%s", TOPT_STR) | ||
| 103 | |||
| 104 | #define FUNCPARA int c | ||
| 105 | #define FUNCARGS c | ||
| 106 | TESTFUNC(isalpha, int, "0x%.2x", "%d", 0) | ||
| 107 | TESTFUNC(tolower, int, "0x%.2x", "0x%.2x", 0) | ||
| 108 | |||
| 109 | #define FUNCPARA int c, locale_t locale | ||
| 110 | #define FUNCARGS c, locale | ||
| 111 | TESTFUNC(isalpha_l, int, "0x%.2x, %p", "%d", 0) | ||
| 112 | TESTFUNC(tolower_l, int, "0x%.2x, %p", "0x%.2x", 0) | ||
| 113 | |||
| 114 | #define FUNCPARA wint_t wc | ||
| 115 | #define FUNCARGS wc | ||
| 116 | TESTFUNC(iswalpha, int, "U+%.4X", "%d", 0) | ||
| 117 | TESTFUNC(towupper, wint_t, "U+%.4X", "U+%.4X", 0) | ||
| 118 | |||
| 119 | #define FUNCPARA wint_t wc, locale_t locale | ||
| 120 | #define FUNCARGS wc, locale | ||
| 121 | TESTFUNC(iswalpha_l, int, "U+%.4X, %p", "%d", 0) | ||
| 122 | TESTFUNC(towupper_l, wint_t, "U+%.4X, %p", "U+%.4X", 0) | ||
| 123 | |||
| 124 | #define FUNCPARA wint_t wc, wctype_t charclass | ||
| 125 | #define FUNCARGS wc, charclass | ||
| 126 | TESTFUNC(iswctype, int, "U+%.4X, %p", "%d", 0) | ||
| 127 | |||
| 128 | #define FUNCPARA wint_t wc, wctype_t charclass, locale_t locale | ||
| 129 | #define FUNCARGS wc, charclass, locale | ||
| 130 | TESTFUNC(iswctype_l, int, "U+%.4X, %p, %p", "%d", 0) | ||
| 131 | |||
| 132 | #define FUNCPARA wint_t wc, wctrans_t charmap | ||
| 133 | #define FUNCARGS wc, charmap | ||
| 134 | TESTFUNC(towctrans, wint_t, "U+%.4X, %p", "U+%.4X", 0) | ||
| 135 | |||
| 136 | #define FUNCPARA wint_t wc, wctrans_t charmap, locale_t locale | ||
| 137 | #define FUNCARGS wc, charmap, locale | ||
| 138 | TESTFUNC(towctrans_l, wint_t, "U+%.4X, %p, %p", "U+%.4X", 0) | ||
| 139 | |||
| 140 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2 | ||
| 141 | #define FUNCARGS s1, s2 | ||
| 142 | TESTFUNC(wcscasecmp, int, "%ls, %ls", "%d", 0) | ||
| 143 | |||
| 144 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, locale_t locale | ||
| 145 | #define FUNCARGS s1, s2, locale | ||
| 146 | TESTFUNC(wcscasecmp_l, int, "%ls, %ls, %p", "%d", 0) | ||
| 147 | |||
| 148 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len | ||
| 149 | #define FUNCARGS s1, s2, len | ||
| 150 | TESTFUNC(wcsncasecmp, int, "%ls, %ls, %zu", "%d", 0) | ||
| 151 | |||
| 152 | #define FUNCPARA const wchar_t *s1, const wchar_t *s2, size_t len, \ | ||
| 153 | locale_t locale | ||
| 154 | #define FUNCARGS s1, s2, len, locale | ||
| 155 | TESTFUNC(wcsncasecmp_l, int, "%ls, %ls, %zu, %p", "%d", 0) | ||
| 156 | |||
| 157 | static void | ||
| 158 | _test_MB_CUR_MAX(int line, int ee, size_t ar) | ||
| 159 | { | ||
| 160 | if (MB_CUR_MAX != ar) | ||
| 161 | errx(1, "[%d] MB_CUR_MAX=%zd [exp: %zd]", | ||
| 162 | line, MB_CUR_MAX, ar); | ||
| 163 | } | ||
| 164 | |||
| 165 | /* | ||
| 166 | * Test macros: | ||
| 167 | * TEST_R(funcname, er, arguments) if you expect errno == 0. | ||
| 168 | * TEST_ER(funcname, ee, er, arguments) otherwise. | ||
| 169 | */ | ||
| 170 | #define TEST_R(Fn, ...) _test_##Fn(__LINE__, 0, __VA_ARGS__) | ||
| 171 | #define TEST_ER(Fn, ...) _test_##Fn(__LINE__, __VA_ARGS__) | ||
| 172 | |||
| 173 | /* | ||
| 174 | * SWITCH_SIGNAL wakes the other thread. | ||
| 175 | * SWITCH_WAIT goes to sleep. | ||
| 176 | * Both can be combined. | ||
| 177 | * The step argument is used for error reporting only. | ||
| 178 | */ | ||
| 179 | static void | ||
| 180 | switch_thread(int step, int flags) | ||
| 181 | { | ||
| 182 | static pthread_mutexattr_t ma; | ||
| 183 | static struct timespec t; | ||
| 184 | static pthread_cond_t *c; | ||
| 185 | static pthread_mutex_t *m; | ||
| 186 | int irc; | ||
| 187 | |||
| 188 | if (m == NULL) { | ||
| 189 | if ((m = malloc(sizeof(*m))) == NULL) | ||
| 190 | err(1, NULL); | ||
| 191 | if ((irc = pthread_mutexattr_init(&ma)) != 0) | ||
| 192 | errc(1, irc, "pthread_mutexattr_init"); | ||
| 193 | if ((irc = pthread_mutexattr_settype(&ma, | ||
| 194 | PTHREAD_MUTEX_STRICT_NP)) != 0) | ||
| 195 | errc(1, irc, "pthread_mutexattr_settype"); | ||
| 196 | if ((irc = pthread_mutex_init(m, &ma)) != 0) | ||
| 197 | errc(1, irc, "pthread_mutex_init"); | ||
| 198 | } | ||
| 199 | if (c == NULL) { | ||
| 200 | if ((c = malloc(sizeof(*c))) == NULL) | ||
| 201 | err(1, NULL); | ||
| 202 | if ((irc = pthread_cond_init(c, NULL)) != 0) | ||
| 203 | errc(1, irc, "pthread_cond_init"); | ||
| 204 | } | ||
| 205 | if (flags & SWITCH_SIGNAL) { | ||
| 206 | if ((irc = pthread_cond_signal(c)) != 0) | ||
| 207 | errc(1, irc, "pthread_cond_signal(%d)", step); | ||
| 208 | } | ||
| 209 | if (flags & SWITCH_WAIT) { | ||
| 210 | if ((irc = pthread_mutex_trylock(m)) != 0) | ||
| 211 | errc(1, irc, "pthread_mutex_trylock(%d)", step); | ||
| 212 | t.tv_sec = time(NULL) + 2; | ||
| 213 | if ((irc = pthread_cond_timedwait(c, m, &t)) != 0) | ||
| 214 | errc(1, irc, "pthread_cond_timedwait(%d)", step); | ||
| 215 | if ((irc = pthread_mutex_unlock(m)) != 0) | ||
| 216 | errc(1, irc, "pthread_mutex_unlock(%d)", step); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | static void * | ||
| 221 | child_func(void *arg) | ||
| 222 | { | ||
| 223 | const wchar_t s1[] = { 0x00C7, 0x00E0, 0x0000 }; | ||
| 224 | const wchar_t s2[] = { 0x00E7, 0x00C0, 0x0000 }; | ||
| 225 | const wchar_t s3[] = { 0x00C9, 0x0074, 0x00C9, 0x0000 }; | ||
| 226 | const wchar_t s4[] = { 0x00E9, 0x0054, 0x00CC, 0x0000 }; | ||
| 227 | wctype_t wctyg, wctyu, wctyc; | ||
| 228 | wctrans_t wctrg, wctru, wctrc; | ||
| 229 | char *sego, *segc, *selo, *selc; | ||
| 230 | |||
| 231 | /* Test invalid newlocale(3) arguments. */ | ||
| 232 | TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_CTYPE_MASK, NULL); | ||
| 233 | TEST_R(MB_CUR_MAX, 1); | ||
| 234 | TEST_ER(newlocale, EINVAL, _LOCALE_NONE, LC_ALL_MASK + 1, "C.UTF-8"); | ||
| 235 | TEST_R(MB_CUR_MAX, 1); | ||
| 236 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_COLLATE_MASK, "C.INV"); | ||
| 237 | TEST_R(MB_CUR_MAX, 1); | ||
| 238 | setenv("LC_TIME", "C.INV", 1); | ||
| 239 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_TIME_MASK, ""); | ||
| 240 | unsetenv("LC_TIME"); | ||
| 241 | TEST_R(MB_CUR_MAX, 1); | ||
| 242 | setenv("LC_CTYPE", "C.INV", 1); | ||
| 243 | TEST_ER(newlocale, ENOENT, _LOCALE_NONE, LC_CTYPE_MASK, ""); | ||
| 244 | TEST_R(MB_CUR_MAX, 1); | ||
| 245 | |||
| 246 | /* Test duplocale(3). */ | ||
| 247 | TEST_ER(duplocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); | ||
| 248 | TEST_R(duplocale, _LOCALE_C, _LOCALE_C); | ||
| 249 | TEST_R(duplocale, _LOCALE_C, LC_GLOBAL_LOCALE); | ||
| 250 | |||
| 251 | /* Test premature UTF-8 uselocale(3). */ | ||
| 252 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_UTF8); | ||
| 253 | TEST_R(MB_CUR_MAX, 1); | ||
| 254 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
| 255 | |||
| 256 | /* Test UTF-8 initialization. */ | ||
| 257 | setenv("LC_CTYPE", "C.UTF-8", 1); | ||
| 258 | TEST_R(newlocale, _LOCALE_UTF8, LC_CTYPE_MASK, ""); | ||
| 259 | unsetenv("LC_CTYPE"); | ||
| 260 | TEST_R(MB_CUR_MAX, 1); | ||
| 261 | TEST_R(duplocale, _LOCALE_UTF8, _LOCALE_UTF8); | ||
| 262 | |||
| 263 | /* Test invalid uselocale(3) argument. */ | ||
| 264 | TEST_ER(uselocale, EINVAL, _LOCALE_NONE, _LOCALE_BAD); | ||
| 265 | TEST_R(MB_CUR_MAX, 1); | ||
| 266 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
| 267 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
| 268 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 269 | TEST_R(iswalpha, 0, 0x00E9); | ||
| 270 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
| 271 | TEST_R(towupper, 0x00E9, 0x00E9); | ||
| 272 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
| 273 | TEST_R(wcscasecmp, *s1 - *s2, s1, s2); | ||
| 274 | TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); | ||
| 275 | |||
| 276 | /* Test switching the thread locale. */ | ||
| 277 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_UTF8); | ||
| 278 | TEST_R(MB_CUR_MAX, 4); | ||
| 279 | TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_NONE); | ||
| 280 | TEST_R(nl_langinfo, "UTF-8", CODESET); | ||
| 281 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 282 | TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); | ||
| 283 | TEST_R(isalpha, _L, 0x65); /* e */ | ||
| 284 | TEST_R(isalpha_l, _L, 0x65, _LOCALE_UTF8); | ||
| 285 | TEST_R(isalpha_l, _L, 0x65, _LOCALE_C); | ||
| 286 | TEST_R(isalpha_l, _L, 0x65, _LOCALE_C); | ||
| 287 | TEST_R(isalpha, 0, 0x30); /* 0 */ | ||
| 288 | TEST_R(isalpha_l, 0, 0x30, _LOCALE_UTF8); | ||
| 289 | TEST_R(isalpha_l, 0, 0x30, _LOCALE_C); | ||
| 290 | TEST_R(tolower, 0x61, 0x41); /* A */ | ||
| 291 | TEST_R(tolower_l, 0x61, 0x41, _LOCALE_UTF8); | ||
| 292 | TEST_R(tolower_l, 0x61, 0x41, _LOCALE_C); | ||
| 293 | TEST_R(tolower, 0x40, 0x40); /* @ */ | ||
| 294 | TEST_R(tolower_l, 0x40, 0x40, _LOCALE_UTF8); | ||
| 295 | TEST_R(tolower_l, 0x40, 0x40, _LOCALE_C); | ||
| 296 | TEST_R(iswalpha, 1, 0x00E9); /* e accent aigu */ | ||
| 297 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
| 298 | TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); | ||
| 299 | TEST_R(iswalpha, 1, 0x0153); /* ligature oe */ | ||
| 300 | TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); | ||
| 301 | TEST_R(iswalpha_l, 0, 0x0153, _LOCALE_C); | ||
| 302 | TEST_R(iswalpha, 0, 0x2200); /* for all */ | ||
| 303 | TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_UTF8); | ||
| 304 | TEST_R(iswalpha_l, 0, 0x2200, _LOCALE_C); | ||
| 305 | TEST_R(towupper, 0x00C9, 0x00E9); | ||
| 306 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
| 307 | TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); | ||
| 308 | TEST_R(towupper, 0x0152, 0x0153); | ||
| 309 | TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); | ||
| 310 | TEST_R(towupper_l, 0x0153, 0x0153, _LOCALE_C); | ||
| 311 | TEST_R(towupper, 0x2205, 0x2205); | ||
| 312 | TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_UTF8); | ||
| 313 | TEST_R(towupper_l, 0x2205, 0x2205, _LOCALE_C); | ||
| 314 | wctyg = wctype("upper"); | ||
| 315 | if (wctyg == NULL) | ||
| 316 | errx(1, "wctype(upper) == NULL"); | ||
| 317 | wctyu = wctype_l("upper", _LOCALE_UTF8); | ||
| 318 | if (wctyu == NULL) | ||
| 319 | errx(1, "wctype_l(upper, UTF-8) == NULL"); | ||
| 320 | if (wctyg != wctyu) | ||
| 321 | errx(1, "wctype global != UTF-8"); | ||
| 322 | wctyc = wctype_l("upper", _LOCALE_C); | ||
| 323 | if (wctyc == NULL) | ||
| 324 | errx(1, "wctype_l(upper, C) == NULL"); | ||
| 325 | if (wctyg == wctyc) | ||
| 326 | errx(1, "wctype global == C"); | ||
| 327 | TEST_R(iswctype, 1, 0x00D0, wctyg); /* Eth */ | ||
| 328 | TEST_R(iswctype_l, 1, 0x00D0, wctyu, _LOCALE_UTF8); | ||
| 329 | TEST_R(iswctype_l, 0, 0x00D0, wctyc, _LOCALE_C); | ||
| 330 | TEST_R(iswctype, 1, 0x0393, wctyg); /* Gamma */ | ||
| 331 | TEST_R(iswctype_l, 1, 0x0393, wctyu, _LOCALE_UTF8); | ||
| 332 | TEST_R(iswctype_l, 0, 0x0393, wctyc, _LOCALE_C); | ||
| 333 | TEST_R(iswctype, 0, 0x2205, wctyg); /* empty set */ | ||
| 334 | TEST_R(iswctype_l, 0, 0x2205, wctyu, _LOCALE_UTF8); | ||
| 335 | TEST_R(iswctype_l, 0, 0x2205, wctyc, _LOCALE_C); | ||
| 336 | wctrg = wctrans("tolower"); | ||
| 337 | if (wctrg == NULL) | ||
| 338 | errx(1, "wctrans(tolower) == NULL"); | ||
| 339 | wctru = wctrans_l("tolower", _LOCALE_UTF8); | ||
| 340 | if (wctru == NULL) | ||
| 341 | errx(1, "wctrans(tolower, UTF-8) == NULL"); | ||
| 342 | if (wctrg != wctru) | ||
| 343 | errx(1, "wctrans global != UTF-8"); | ||
| 344 | wctrc = wctrans_l("tolower", _LOCALE_C); | ||
| 345 | if (wctrc == NULL) | ||
| 346 | errx(1, "wctrans(tolower, C) == NULL"); | ||
| 347 | if (wctrg == wctrc) | ||
| 348 | errx(1, "wctrans global == C"); | ||
| 349 | TEST_R(towctrans, 0x00FE, 0x00DE, wctrg); /* Thorn */ | ||
| 350 | TEST_R(towctrans_l, 0x00FE, 0x00DE, wctru, _LOCALE_UTF8); | ||
| 351 | TEST_R(towctrans_l, 0x00DE, 0x00DE, wctrc, _LOCALE_C); | ||
| 352 | TEST_R(towctrans, 0x03C6, 0x03A6, wctrg); /* Phi */ | ||
| 353 | TEST_R(towctrans_l, 0x03C6, 0x03A6, wctru, _LOCALE_UTF8); | ||
| 354 | TEST_R(towctrans_l, 0x03A6, 0x03A6, wctrc, _LOCALE_C); | ||
| 355 | TEST_R(towctrans, 0x2207, 0x2207, wctrg); /* Nabla */ | ||
| 356 | TEST_R(towctrans_l, 0x2207, 0x2207, wctru, _LOCALE_UTF8); | ||
| 357 | TEST_R(towctrans_l, 0x2207, 0x2207, wctrc, _LOCALE_C); | ||
| 358 | TEST_R(wcscasecmp, 0, s1, s2); | ||
| 359 | TEST_R(wcscasecmp_l, 0, s1, s2, _LOCALE_UTF8); | ||
| 360 | TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); | ||
| 361 | TEST_R(wcsncasecmp, 0, s3, s4, 2); | ||
| 362 | TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); | ||
| 363 | TEST_R(wcsncasecmp_l, *s3 - *s4, s3, s4, 2, _LOCALE_C); | ||
| 364 | |||
| 365 | /* Test non-ctype newlocale(3). */ | ||
| 366 | TEST_R(newlocale, _LOCALE_C, LC_MESSAGES_MASK, "en_US.UTF-8"); | ||
| 367 | |||
| 368 | /* Test strerror(3). */ | ||
| 369 | sego = strerror(EPERM); | ||
| 370 | segc = strdup(sego); | ||
| 371 | selo = strerror_l(ENOENT, _LOCALE_C); | ||
| 372 | selc = strdup(selo); | ||
| 373 | if (strcmp(sego, segc) != 0) | ||
| 374 | errx(1, "child: strerror_l clobbered strerror"); | ||
| 375 | free(segc); | ||
| 376 | sego = strerror(ESRCH); | ||
| 377 | if (strcmp(selo, selc) != 0) | ||
| 378 | errx(1, "child: strerror clobbered strerror_l"); | ||
| 379 | |||
| 380 | /* Temporarily switch to the main thread. */ | ||
| 381 | switch_thread(2, SWITCH_SIGNAL | SWITCH_WAIT); | ||
| 382 | if (strcmp(selo, selc) != 0) | ||
| 383 | errx(1, "child: main clobbered strerror_l"); | ||
| 384 | free(selc); | ||
| 385 | |||
| 386 | /* Check that the C locale works even while all is set to UTF-8. */ | ||
| 387 | TEST_R(nl_langinfo_l, "US-ASCII", CODESET, _LOCALE_C); | ||
| 388 | TEST_R(iswalpha_l, 0, 0x00E9, _LOCALE_C); | ||
| 389 | TEST_R(towupper_l, 0x00E9, 0x00E9, _LOCALE_C); | ||
| 390 | TEST_R(wcscasecmp_l, *s1 - *s2, s1, s2, _LOCALE_C); | ||
| 391 | |||
| 392 | /* Test displaying the global locale while a local one is set. */ | ||
| 393 | TEST_R(setlocale, "C/C.UTF-8/C/C/C/C", LC_ALL, NULL); | ||
| 394 | |||
| 395 | /* Test switching the thread locale back. */ | ||
| 396 | TEST_R(MB_CUR_MAX, 4); | ||
| 397 | TEST_R(duplocale, _LOCALE_UTF8, LC_GLOBAL_LOCALE); | ||
| 398 | TEST_R(uselocale, _LOCALE_UTF8, _LOCALE_C); | ||
| 399 | TEST_R(MB_CUR_MAX, 1); | ||
| 400 | TEST_R(uselocale, _LOCALE_C, _LOCALE_NONE); | ||
| 401 | |||
| 402 | /* Check that UTF-8 works even with a C thread locale. */ | ||
| 403 | TEST_R(nl_langinfo, "US-ASCII", CODESET); | ||
| 404 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 405 | TEST_R(iswalpha, 0, 0x0153); | ||
| 406 | TEST_R(iswalpha_l, 1, 0x0153, _LOCALE_UTF8); | ||
| 407 | TEST_R(towupper, 0x0153, 0x0153); | ||
| 408 | TEST_R(towupper_l, 0x0152, 0x0153, _LOCALE_UTF8); | ||
| 409 | TEST_R(wcsncasecmp, *s3 - *s4, s3, s4, 2); | ||
| 410 | TEST_R(wcsncasecmp_l, 0, s3, s4, 2, _LOCALE_UTF8); | ||
| 411 | |||
| 412 | /* Test switching back to the global locale. */ | ||
| 413 | TEST_R(uselocale, _LOCALE_C, LC_GLOBAL_LOCALE); | ||
| 414 | TEST_R(MB_CUR_MAX, 4); | ||
| 415 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
| 416 | |||
| 417 | /* Check that the global locale takes effect even in a thread. */ | ||
| 418 | TEST_R(nl_langinfo, "UTF-8", CODESET); | ||
| 419 | TEST_R(iswalpha, 1, 0x0153); | ||
| 420 | TEST_R(towupper, 0x0152, 0x0153); | ||
| 421 | TEST_R(wcscasecmp, 0, s1, s2); | ||
| 422 | |||
| 423 | /* Hand control back to the main thread. */ | ||
| 424 | switch_thread(4, SWITCH_SIGNAL); | ||
| 425 | return NULL; | ||
| 426 | } | ||
| 427 | |||
| 428 | int | ||
| 429 | main(void) | ||
| 430 | { | ||
| 431 | pthread_t child_thread; | ||
| 432 | char *sego, *segc, *selo, *selc; | ||
| 433 | int irc; | ||
| 434 | |||
| 435 | /* Initialize environment. */ | ||
| 436 | unsetenv("LC_ALL"); | ||
| 437 | unsetenv("LC_COLLATE"); | ||
| 438 | unsetenv("LC_CTYPE"); | ||
| 439 | unsetenv("LC_MONETARY"); | ||
| 440 | unsetenv("LC_NUMERIC"); | ||
| 441 | unsetenv("LC_TIME"); | ||
| 442 | unsetenv("LC_MESSAGES"); | ||
| 443 | unsetenv("LANG"); | ||
| 444 | |||
| 445 | /* First let the child do some tests. */ | ||
| 446 | if ((irc = pthread_create(&child_thread, NULL, child_func, NULL)) != 0) | ||
| 447 | errc(1, irc, "pthread_create"); | ||
| 448 | switch_thread(1, SWITCH_WAIT); | ||
| 449 | |||
| 450 | /* Check that the global locale is undisturbed. */ | ||
| 451 | TEST_R(setlocale, "C", LC_ALL, NULL); | ||
| 452 | TEST_R(MB_CUR_MAX, 1); | ||
| 453 | |||
| 454 | /* Check that *_l(3) works without any locale installed. */ | ||
| 455 | TEST_R(nl_langinfo_l, "UTF-8", CODESET, _LOCALE_UTF8); | ||
| 456 | TEST_R(iswalpha_l, 1, 0x00E9, _LOCALE_UTF8); | ||
| 457 | TEST_R(towupper_l, 0x00C9, 0x00E9, _LOCALE_UTF8); | ||
| 458 | |||
| 459 | /* Test setting the globale locale. */ | ||
| 460 | TEST_R(setlocale, "C.UTF-8", LC_CTYPE, "C.UTF-8"); | ||
| 461 | TEST_R(MB_CUR_MAX, 4); | ||
| 462 | TEST_R(uselocale, LC_GLOBAL_LOCALE, _LOCALE_NONE); | ||
| 463 | |||
| 464 | /* Test strerror(3). */ | ||
| 465 | sego = strerror(EINTR); | ||
| 466 | segc = strdup(sego); | ||
| 467 | selo = strerror_l(EIO, _LOCALE_C); | ||
| 468 | selc = strdup(selo); | ||
| 469 | if (strcmp(sego, segc) != 0) | ||
| 470 | errx(1, "main: strerror_l clobbered strerror"); | ||
| 471 | free(segc); | ||
| 472 | sego = strerror(ENXIO); | ||
| 473 | if (strcmp(selo, selc) != 0) | ||
| 474 | errx(1, "main: strerror clobbered strerror_l"); | ||
| 475 | free(selc); | ||
| 476 | |||
| 477 | /* Let the child do some more tests, then clean up. */ | ||
| 478 | switch_thread(3, SWITCH_SIGNAL); | ||
| 479 | if ((irc = pthread_join(child_thread, NULL)) != 0) | ||
| 480 | errc(1, irc, "pthread_join"); | ||
| 481 | return 0; | ||
| 482 | } | ||
diff --git a/src/regress/lib/libc/locale/wcrtomb/Makefile b/src/regress/lib/libc/locale/wcrtomb/Makefile deleted file mode 100644 index b09cecc454..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = test_wcrtomb | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c b/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c deleted file mode 100644 index 26b21fdd5b..0000000000 --- a/src/regress/lib/libc/locale/wcrtomb/test_wcrtomb.c +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | /* $OpenBSD: test_wcrtomb.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | #include <err.h> | ||
| 20 | #include <errno.h> | ||
| 21 | #include <limits.h> | ||
| 22 | #include <locale.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <wchar.h> | ||
| 26 | |||
| 27 | static mbstate_t mbs; | ||
| 28 | |||
| 29 | void | ||
| 30 | onetest(const char *name, const wchar_t wcin, int outerr, const char *out) | ||
| 31 | { | ||
| 32 | char buf[MB_LEN_MAX]; | ||
| 33 | size_t sz, outsz; | ||
| 34 | |||
| 35 | memset(buf, 0, MB_LEN_MAX); | ||
| 36 | outsz = out == NULL ? (size_t)-1 : *out == '\0' ? 1 : strlen(out); | ||
| 37 | sz = wcrtomb(buf, wcin, &mbs); | ||
| 38 | if (errno != outerr) | ||
| 39 | err(1, "%zu %s U+%04X", MB_CUR_MAX, name, wcin); | ||
| 40 | if (sz != outsz || (out != NULL && strncmp(buf, out, sz))) | ||
| 41 | errx(1, "%zu %s U+%04X: %4.4s(%zd) != %4.4s(%zd)", | ||
| 42 | MB_CUR_MAX, name, wcin, buf, sz, | ||
| 43 | out == NULL ? "(NULL)" : out, outsz); | ||
| 44 | if (mbsinit(&mbs) == 0) | ||
| 45 | errx(1, "%zu %s U+%04X mbsinit", MB_CUR_MAX, name, wcin); | ||
| 46 | if (errno == 0 && outerr == 0) | ||
| 47 | return; | ||
| 48 | errno = 0; | ||
| 49 | memset(&mbs, 0, sizeof(mbs)); | ||
| 50 | } | ||
| 51 | |||
| 52 | int | ||
| 53 | main(void) | ||
| 54 | { | ||
| 55 | onetest("NUL", L'\0', 0, ""); | ||
| 56 | onetest("BEL", L'\a', 0, "\a"); | ||
| 57 | onetest("A", L'A', 0, "A"); | ||
| 58 | onetest("DEL", L'\177', 0, "\177"); | ||
| 59 | onetest("CSI", L'\233', 0, "\233"); | ||
| 60 | onetest("0x100", 0x100, EILSEQ, NULL); | ||
| 61 | |||
| 62 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
| 63 | errx(1, "setlocale(UTF-8) failed"), | ||
| 64 | |||
| 65 | onetest("NUL", L'\0', 0, ""); | ||
| 66 | onetest("BEL", L'\a', 0, "\a"); | ||
| 67 | onetest("A", L'A', 0, "A"); | ||
| 68 | onetest("DEL", L'\177', 0, "\177"); | ||
| 69 | onetest("CSI", L'\233', 0, "\302\233"); | ||
| 70 | onetest("0xe9", 0xe9, 0, "\303\251"); | ||
| 71 | onetest("0xcfff", 0xcfff, 0, "\354\277\277"); | ||
| 72 | onetest("0xd800", 0xd800, EILSEQ, NULL); | ||
| 73 | |||
| 74 | if (setlocale(LC_CTYPE, "POSIX") == NULL) | ||
| 75 | errx(1, "setlocale(POSIX) failed"), | ||
| 76 | |||
| 77 | onetest("0xff", L'\377', 0, "\377"); | ||
| 78 | |||
| 79 | if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) | ||
| 80 | errx(1, "second setlocale(UTF-8) failed"), | ||
| 81 | |||
| 82 | onetest("U+13000", 0x13000, 0, "\360\223\200\200"); | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
diff --git a/src/regress/lib/libc/longjmp/Makefile b/src/regress/lib/libc/longjmp/Makefile deleted file mode 100644 index 825e0f86d9..0000000000 --- a/src/regress/lib/libc/longjmp/Makefile +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | PROG= longjmp | ||
| 3 | |||
| 4 | do-longjmp: ${PROG} | ||
| 5 | ./longjmp | ||
| 6 | |||
| 7 | do-_longjmp: ${PROG} | ||
| 8 | ./longjmp -_ | ||
| 9 | |||
| 10 | REGRESS_TARGETS=do-longjmp do-_longjmp | ||
| 11 | .PHONY: ${REGRESS_TARGETS} | ||
| 12 | |||
| 13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/longjmp/longjmp.c b/src/regress/lib/libc/longjmp/longjmp.c deleted file mode 100644 index 7dea5bd97c..0000000000 --- a/src/regress/lib/libc/longjmp/longjmp.c +++ /dev/null | |||
| @@ -1,71 +0,0 @@ | |||
| 1 | /* $OpenBSD: longjmp.c,v 1.4 2002/02/18 11:27:45 art Exp $ */ | ||
| 2 | /* | ||
| 3 | * Artur Grabowski <art@openbsd.org>, 2002 Public Domain. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include <setjmp.h> | ||
| 10 | #include <err.h> | ||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/time.h> | ||
| 13 | #include <sys/resource.h> | ||
| 14 | |||
| 15 | |||
| 16 | jmp_buf buf; | ||
| 17 | |||
| 18 | /* | ||
| 19 | * When longjmp is passed the incorrect arg (0), it should translate it into | ||
| 20 | * something better. | ||
| 21 | * | ||
| 22 | * The rlimit is here in case we start spinning. | ||
| 23 | */ | ||
| 24 | int | ||
| 25 | main(int argc, char **argv) | ||
| 26 | { | ||
| 27 | struct rlimit rl; | ||
| 28 | volatile int i, expect; | ||
| 29 | int (*sj)(jmp_buf); | ||
| 30 | void (*lj)(jmp_buf, int); | ||
| 31 | int ch; | ||
| 32 | extern char *__progname; | ||
| 33 | |||
| 34 | sj = setjmp; | ||
| 35 | lj = longjmp; | ||
| 36 | |||
| 37 | while ((ch = getopt(argc, argv, "_")) != -1) { | ||
| 38 | switch (ch) { | ||
| 39 | case '_': | ||
| 40 | sj = _setjmp; | ||
| 41 | lj = _longjmp; | ||
| 42 | break; | ||
| 43 | default: | ||
| 44 | fprintf(stderr, "Usage: %s [-_]\n", __progname); | ||
| 45 | exit(1); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | rl.rlim_cur = 2; | ||
| 50 | rl.rlim_max = 2; | ||
| 51 | if (setrlimit(RLIMIT_CPU, &rl) < 0) | ||
| 52 | err(1, "setrlimit"); | ||
| 53 | |||
| 54 | expect = 0; | ||
| 55 | i = (*sj)(buf); | ||
| 56 | if (i == 0 && expect != 0) | ||
| 57 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); | ||
| 58 | if (expect == 0) { | ||
| 59 | expect = -1; | ||
| 60 | (*lj)(buf, 0); | ||
| 61 | } | ||
| 62 | |||
| 63 | expect = 0; | ||
| 64 | i = (*sj)(buf); | ||
| 65 | if (i != expect) | ||
| 66 | errx(1, "bad return from setjmp %d/%d", expect, i); | ||
| 67 | if (expect < 1000) | ||
| 68 | (*lj)(buf, expect += 2); | ||
| 69 | |||
| 70 | return 0; | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile deleted file mode 100644 index 7eb84f6a6c..0000000000 --- a/src/regress/lib/libc/malloc/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.7 2018/01/28 13:42:17 otto Exp $ | ||
| 2 | |||
| 3 | SUBDIR+= malloc_general malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
| 4 | SUBDIR+= malloc_threaderr | ||
| 5 | |||
| 6 | install: | ||
| 7 | |||
| 8 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/Makefile b/src/regress/lib/libc/malloc/malloc0test/Makefile deleted file mode 100644 index fc2295c091..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/08 00:08:26 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG= malloc0test | ||
| 4 | |||
| 5 | .for m in C D F G J j R S U X << >>> | ||
| 6 | REGRESS_TARGETS += run-regress-${PROG}-${m:S/</-/g:S/>/+/g} | ||
| 7 | run-regress-${PROG}-${m:S/</-/g:S/>/+/g}: ${PROG} | ||
| 8 | MALLOC_OPTIONS='${m}' ./${PROG} | ||
| 9 | .endfor | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c deleted file mode 100644 index 06ff0996ee..0000000000 --- a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc0test.c,v 1.5 2008/04/13 00:22:17 djm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2001, Theo de Raadt | ||
| 4 | */ | ||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/signal.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <setjmp.h> | ||
| 11 | #include <limits.h> | ||
| 12 | #include <errno.h> | ||
| 13 | |||
| 14 | volatile sig_atomic_t got; | ||
| 15 | jmp_buf jmp; | ||
| 16 | |||
| 17 | static void | ||
| 18 | catch(int signo) | ||
| 19 | { | ||
| 20 | got++; | ||
| 21 | longjmp(jmp, 1); | ||
| 22 | } | ||
| 23 | |||
| 24 | static int | ||
| 25 | test(char *p, int size) | ||
| 26 | { | ||
| 27 | signal(SIGSEGV, catch); | ||
| 28 | got = 0; | ||
| 29 | if (setjmp(jmp) == 0) | ||
| 30 | *p = 0; | ||
| 31 | if (setjmp(jmp) == 0) | ||
| 32 | *(p+size-1) = 0; | ||
| 33 | return (got); | ||
| 34 | } | ||
| 35 | |||
| 36 | char *prot_table[] = { | ||
| 37 | "unprotected", | ||
| 38 | "fuckup", | ||
| 39 | "protected" | ||
| 40 | }; | ||
| 41 | |||
| 42 | #define SIZE 10 | ||
| 43 | |||
| 44 | /* | ||
| 45 | * Do random memory allocations. | ||
| 46 | * | ||
| 47 | * For each one, ensure that it is at least 16 bytes in size (that | ||
| 48 | * being what our current malloc returns for the minsize of an | ||
| 49 | * object, alignment wise); | ||
| 50 | * | ||
| 51 | * For zero-byte allocations, check that they are still aligned. | ||
| 52 | * | ||
| 53 | * For each object, ensure that they are correctly protected or not | ||
| 54 | * protected. | ||
| 55 | * | ||
| 56 | * Does not regress test malloc + free combinations ... it should. | ||
| 57 | */ | ||
| 58 | int | ||
| 59 | main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | caddr_t blob; | ||
| 62 | int size, tsize; | ||
| 63 | int prot; | ||
| 64 | int rval = 0, fuckup = 0; | ||
| 65 | long limit = 200000, count; | ||
| 66 | int ch, silent = 0; | ||
| 67 | char *ep; | ||
| 68 | extern char *__progname; | ||
| 69 | |||
| 70 | while ((ch = getopt(argc, argv, "sn:")) != -1) { | ||
| 71 | switch (ch) { | ||
| 72 | case 's': | ||
| 73 | silent = 1; | ||
| 74 | break; | ||
| 75 | case 'n': | ||
| 76 | errno = 0; | ||
| 77 | limit = strtol(optarg, &ep, 10); | ||
| 78 | if (optarg[0] == '\0' || *ep != '\0' || | ||
| 79 | (errno == ERANGE && | ||
| 80 | (limit == LONG_MAX || limit == LONG_MIN))) | ||
| 81 | goto usage; | ||
| 82 | break; | ||
| 83 | default: | ||
| 84 | usage: | ||
| 85 | fprintf(stderr, "Usage: %s [-s][-n <count>]\n", | ||
| 86 | __progname); | ||
| 87 | exit(1); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | if (limit == 0) | ||
| 92 | limit = LONG_MAX; | ||
| 93 | |||
| 94 | for (count = 0; count < limit; count++) { | ||
| 95 | size = arc4random_uniform(SIZE); | ||
| 96 | blob = malloc(size); | ||
| 97 | if (blob == NULL) { | ||
| 98 | fprintf(stderr, "success: out of memory\n"); | ||
| 99 | exit(rval); | ||
| 100 | } | ||
| 101 | |||
| 102 | tsize = size == 0 ? 16 : size; | ||
| 103 | fuckup = 0; | ||
| 104 | prot = test(blob, tsize); | ||
| 105 | |||
| 106 | if (size == 0 && prot < 2) | ||
| 107 | fuckup = 1; | ||
| 108 | |||
| 109 | if (fuckup) { | ||
| 110 | printf("%8p %6d %20s %10s\n", blob, size, | ||
| 111 | prot_table[prot], fuckup ? "fuckup" : ""); | ||
| 112 | rval = 1; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (!silent && count % 100000 == 0 && count != 0) | ||
| 116 | fprintf(stderr, "count = %ld\n", count); | ||
| 117 | } | ||
| 118 | |||
| 119 | return rval; | ||
| 120 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile deleted file mode 100644 index 73ebe37491..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_errno | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c deleted file mode 100644 index 896ea3c900..0000000000 --- a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_errno.c,v 1.4 2003/12/25 18:49:57 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public domain. 2003, Otto Moerbeek | ||
| 4 | */ | ||
| 5 | #include <err.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | static void | ||
| 11 | testerrno(size_t sz) | ||
| 12 | { | ||
| 13 | void *p; | ||
| 14 | |||
| 15 | errno = -1; | ||
| 16 | p = malloc(sz); | ||
| 17 | |||
| 18 | if (p == NULL && errno != ENOMEM) | ||
| 19 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 20 | |||
| 21 | /* if alloc succeeded, test if errno did not change */ | ||
| 22 | if (p != NULL && errno != -1) | ||
| 23 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
| 24 | |||
| 25 | free(p); | ||
| 26 | } | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
| 30 | * correctly. | ||
| 31 | */ | ||
| 32 | int | ||
| 33 | main(int argc, char *argv[]) | ||
| 34 | { | ||
| 35 | size_t i; | ||
| 36 | |||
| 37 | testerrno(1); | ||
| 38 | testerrno(100000); | ||
| 39 | testerrno(-1); | ||
| 40 | testerrno(-1000); | ||
| 41 | testerrno(-10000); | ||
| 42 | testerrno(-10000000); | ||
| 43 | for (i = 0; i < 0x10; i++) | ||
| 44 | testerrno(i * 0x10000000); | ||
| 45 | return 0; | ||
| 46 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_general/Makefile b/src/regress/lib/libc/malloc/malloc_general/Makefile deleted file mode 100644 index a0ee823bbe..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/Makefile +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2017/01/24 16:03:28 otto Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7 | ||
| 4 | PROG= malloc_general | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
| 7 | |||
| 8 | t1: malloc_general | ||
| 9 | ${.OBJDIR}/malloc_general "" | ||
| 10 | |||
| 11 | t2: malloc_general | ||
| 12 | ${.OBJDIR}//malloc_general C | ||
| 13 | |||
| 14 | t3: malloc_general | ||
| 15 | ${.OBJDIR}//malloc_general J | ||
| 16 | |||
| 17 | t4: malloc_general | ||
| 18 | ${.OBJDIR}//malloc_general F | ||
| 19 | |||
| 20 | t5: malloc_general | ||
| 21 | ${.OBJDIR}//malloc_general G | ||
| 22 | |||
| 23 | t6: malloc_general | ||
| 24 | ${.OBJDIR}//malloc_general S | ||
| 25 | |||
| 26 | t7: malloc_general | ||
| 27 | ${.OBJDIR}//malloc_general FGJ | ||
diff --git a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c b/src/regress/lib/libc/malloc/malloc_general/malloc_general.c deleted file mode 100644 index 51bfb03a34..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c +++ /dev/null | |||
| @@ -1,125 +0,0 @@ | |||
| 1 | /* $OpenBSD */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | /* $define VERBOSE */ | ||
| 24 | |||
| 25 | #define N 1000 | ||
| 26 | |||
| 27 | size_t | ||
| 28 | size(void) | ||
| 29 | { | ||
| 30 | int p = arc4random_uniform(13) + 3; | ||
| 31 | return arc4random_uniform(1 << p); | ||
| 32 | } | ||
| 33 | |||
| 34 | struct { void *p; size_t sz; } a[N]; | ||
| 35 | |||
| 36 | extern char *malloc_options; | ||
| 37 | |||
| 38 | void | ||
| 39 | fill(u_char *p, size_t sz) | ||
| 40 | { | ||
| 41 | size_t i; | ||
| 42 | |||
| 43 | for (i = 0; i < sz; i++) | ||
| 44 | p[i] = i % 256; | ||
| 45 | } | ||
| 46 | |||
| 47 | void | ||
| 48 | check(u_char *p, size_t sz) | ||
| 49 | { | ||
| 50 | size_t i; | ||
| 51 | |||
| 52 | for (i = 0; i < sz; i++) | ||
| 53 | if (p[i] != i % 256) | ||
| 54 | errx(1, "check"); | ||
| 55 | } | ||
| 56 | |||
| 57 | int | ||
| 58 | main(int argc, char *argv[]) | ||
| 59 | { | ||
| 60 | int count, p, i; | ||
| 61 | void * q; | ||
| 62 | size_t sz; | ||
| 63 | |||
| 64 | if (argc == 1) | ||
| 65 | errx(1, "usage: malloc_options"); | ||
| 66 | |||
| 67 | malloc_options = argv[1]; | ||
| 68 | |||
| 69 | for (count = 0; count < 800000; count++) { | ||
| 70 | if (count % 10000 == 0) { | ||
| 71 | printf("."); | ||
| 72 | fflush(stdout); | ||
| 73 | } | ||
| 74 | p = arc4random_uniform(2); | ||
| 75 | i = arc4random_uniform(N); | ||
| 76 | switch (p) { | ||
| 77 | case 0: | ||
| 78 | if (a[i].p) { | ||
| 79 | #ifdef VERBOSE | ||
| 80 | printf("F %p\n", a[i].p); | ||
| 81 | #endif | ||
| 82 | if (a[i].p) | ||
| 83 | check(a[i].p, a[i].sz); | ||
| 84 | free(a[i].p); | ||
| 85 | a[i].p = NULL; | ||
| 86 | } | ||
| 87 | sz = size(); | ||
| 88 | #ifdef VERBOSE | ||
| 89 | printf("M %zu=", sz); | ||
| 90 | #endif | ||
| 91 | a[i].p = malloc(sz); | ||
| 92 | a[i].sz = sz; | ||
| 93 | #ifdef VERBOSE | ||
| 94 | printf("%p\n", a[i].p); | ||
| 95 | #endif | ||
| 96 | if (a[i].p) | ||
| 97 | fill(a[i].p, sz); | ||
| 98 | break; | ||
| 99 | case 1: | ||
| 100 | sz = size(); | ||
| 101 | #ifdef VERBOSE | ||
| 102 | printf("R %p %zu=", a[i].p, sz); | ||
| 103 | #endif | ||
| 104 | q = realloc(a[i].p, sz); | ||
| 105 | #ifdef VERBOSE | ||
| 106 | printf("%p\n", q); | ||
| 107 | #endif | ||
| 108 | if (a[i].p && q) | ||
| 109 | check(q, a[i].sz < sz ? a[i].sz : sz); | ||
| 110 | if (q) { | ||
| 111 | a[i].p = q; | ||
| 112 | a[i].sz = sz; | ||
| 113 | fill(a[i].p, sz); | ||
| 114 | } | ||
| 115 | break; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | for (i = 0; i < N; i++) { | ||
| 119 | if (a[i].p) | ||
| 120 | check(a[i].p, a[i].sz); | ||
| 121 | free(a[i].p); | ||
| 122 | } | ||
| 123 | printf("\n"); | ||
| 124 | return 0; | ||
| 125 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile b/src/regress/lib/libc/malloc/malloc_threaderr/Makefile deleted file mode 100644 index 2d715af58b..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/Makefile +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2018/01/28 14:55:24 otto Exp $ | ||
| 2 | |||
| 3 | # This test is supposed to print a malloc error and create a core dump | ||
| 4 | |||
| 5 | REGRESS_TARGETS= t1 | ||
| 6 | PROG= malloc_threaderr | ||
| 7 | LDADD+= -pthread | ||
| 8 | DPADD+= ${LIBPTHREAD} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
| 11 | |||
| 12 | t1: malloc_threaderr | ||
| 13 | ${.OBJDIR}/malloc_threaderr 2>&1 | fgrep 'in free(): bogus pointer (double free?)' | ||
diff --git a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c b/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c deleted file mode 100644 index f34f37fc93..0000000000 --- a/src/regress/lib/libc/malloc/malloc_threaderr/malloc_threaderr.c +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2018 Otto Moerbeek <otto@drijf.net> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <err.h> | ||
| 18 | #include <stdio.h> | ||
| 19 | #include <stdlib.h> | ||
| 20 | #include <pthread.h> | ||
| 21 | |||
| 22 | pthread_cond_t cond; | ||
| 23 | pthread_mutex_t mutex; | ||
| 24 | |||
| 25 | void *p; | ||
| 26 | |||
| 27 | void *m(void *arg) | ||
| 28 | { | ||
| 29 | p = malloc(100000); | ||
| 30 | if (p == NULL) | ||
| 31 | err(1, NULL); | ||
| 32 | return NULL; | ||
| 33 | } | ||
| 34 | |||
| 35 | void *f(void *arg) | ||
| 36 | { | ||
| 37 | free(p); | ||
| 38 | free(p); | ||
| 39 | return NULL; | ||
| 40 | } | ||
| 41 | |||
| 42 | int | ||
| 43 | main(void) | ||
| 44 | { | ||
| 45 | pthread_t t1, t2; | ||
| 46 | |||
| 47 | printf("This test is supposed to print a malloc error and create a core dump\n"); | ||
| 48 | |||
| 49 | if (pthread_create(&t1, NULL, m, NULL)) | ||
| 50 | err(1, "pthread_create"); | ||
| 51 | pthread_join(t1, NULL); | ||
| 52 | |||
| 53 | if (pthread_create(&t2, NULL, f, NULL)) | ||
| 54 | err(1, "pthread_create"); | ||
| 55 | pthread_join(t2, NULL); | ||
| 56 | |||
| 57 | return 0; | ||
| 58 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile deleted file mode 100644 index 46ced27a98..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit1 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c deleted file mode 100644 index 94f7eb16b5..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit1.c,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | /* | ||
| 13 | * This code tries to trigger the case present in -current as of April | ||
| 14 | * 2006) where the allocation of the region itself succeeds, but the | ||
| 15 | * page dir entry pages fails. | ||
| 16 | * This in turn trips a "hole in directories" error. | ||
| 17 | * Having a large (512M) ulimit -m helps a lot in triggering the | ||
| 18 | * problem. Note that you may need to run this test multiple times to | ||
| 19 | * see the error. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define STARTI 1300 | ||
| 23 | #define FACTOR 1024 | ||
| 24 | |||
| 25 | int | ||
| 26 | main() | ||
| 27 | { | ||
| 28 | struct rlimit lim; | ||
| 29 | size_t sz; | ||
| 30 | int i; | ||
| 31 | void *p; | ||
| 32 | |||
| 33 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 34 | err(1, "getrlimit"); | ||
| 35 | |||
| 36 | sz = lim.rlim_cur / FACTOR; | ||
| 37 | |||
| 38 | for (i = STARTI; i >= 0; i--) { | ||
| 39 | size_t len = (sz-i) * FACTOR; | ||
| 40 | p = malloc(len); | ||
| 41 | free(p); | ||
| 42 | free(malloc(4096)); | ||
| 43 | } | ||
| 44 | return (0); | ||
| 45 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile deleted file mode 100644 index bc83666415..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
| 2 | |||
| 3 | PROG= malloc_ulimit2 | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c deleted file mode 100644 index 9510649090..0000000000 --- a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_ulimit2.c,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/time.h> | ||
| 7 | #include <sys/resource.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | #define FACTOR 1024 | ||
| 13 | |||
| 14 | int | ||
| 15 | main() | ||
| 16 | { | ||
| 17 | struct rlimit lim; | ||
| 18 | size_t sz; | ||
| 19 | int i; | ||
| 20 | void *p; | ||
| 21 | |||
| 22 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
| 23 | err(1, "getrlimit"); | ||
| 24 | |||
| 25 | sz = lim.rlim_cur / FACTOR; | ||
| 26 | |||
| 27 | for (i = 0; ; i++) { | ||
| 28 | size_t len = (sz-i) * FACTOR; | ||
| 29 | p = malloc(len); | ||
| 30 | if (p != NULL) { | ||
| 31 | free(p); | ||
| 32 | break; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | i += 10; | ||
| 36 | for (; i >= 0; i--) { | ||
| 37 | size_t len = (sz-i) * FACTOR; | ||
| 38 | p = malloc(len); | ||
| 39 | free(p); | ||
| 40 | free(malloc(4096)); | ||
| 41 | } | ||
| 42 | return (0); | ||
| 43 | } | ||
diff --git a/src/regress/lib/libc/mkstemp/Makefile b/src/regress/lib/libc/mkstemp/Makefile deleted file mode 100644 index dc7eb281a9..0000000000 --- a/src/regress/lib/libc/mkstemp/Makefile +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/02/11 07:35:38 guenther Exp $ | ||
| 2 | |||
| 3 | PROG=mkstemp_test | ||
| 4 | CLEANFILES+= ; rm -rf output | ||
| 5 | |||
| 6 | O = output | ||
| 7 | |||
| 8 | # The ktrace/kdump/perl combo verifies that all open() calls that | ||
| 9 | # were passed O_CREAT were also passed O_EXCL | ||
| 10 | run-regress-${PROG}: ${PROG} | ||
| 11 | mkdir -p $O && cd $O && ktrace ../${PROG} | ||
| 12 | cd $O && kdump | perl -mFcntl -nl \ | ||
| 13 | -e '/ open\([^,]*,([^,]+)/ or next;' \ | ||
| 14 | -e '$$f = oct($$1);' \ | ||
| 15 | -e 'if ($$f & O_CREAT && !($$f & O_EXCL)) {' \ | ||
| 16 | -e ' print "FAIL"; exit 1' \ | ||
| 17 | -e '}' | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/mkstemp/mkstemp_test.c b/src/regress/lib/libc/mkstemp/mkstemp_test.c deleted file mode 100644 index c1c05eae39..0000000000 --- a/src/regress/lib/libc/mkstemp/mkstemp_test.c +++ /dev/null | |||
| @@ -1,165 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2010 Philip Guenther <guenther@openbsd.org> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | * | ||
| 6 | * Verify that mkstemp() and mkstemps() doesn't overrun or underrun | ||
| 7 | * the template buffer and that it can generate names that don't | ||
| 8 | * contain any X's | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <sys/param.h> | ||
| 12 | #include <sys/mman.h> | ||
| 13 | #include <sys/stat.h> | ||
| 14 | |||
| 15 | #include <err.h> | ||
| 16 | #include <errno.h> | ||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | #include <unistd.h> | ||
| 21 | |||
| 22 | #define MAX_TEMPLATE_LEN 10 | ||
| 23 | #define MAX_TRIES 100 | ||
| 24 | #define MIN_Xs 6 | ||
| 25 | |||
| 26 | #define SUFFIX ".suff" | ||
| 27 | #define SLEN (sizeof SUFFIX - 1) | ||
| 28 | |||
| 29 | long pg; | ||
| 30 | |||
| 31 | /* | ||
| 32 | * verify that a path generated by mkstemp() or mkstemp() looks like a | ||
| 33 | * reasonable expansion of the template and matches the fd. Returns true | ||
| 34 | * if all the X's were replaced with non-X's | ||
| 35 | */ | ||
| 36 | int | ||
| 37 | check(int fd, char const *path, char const *prefix, size_t plen, | ||
| 38 | char const *suffix, size_t slen, int tlen) | ||
| 39 | { | ||
| 40 | struct stat sb, fsb; | ||
| 41 | char const *p; | ||
| 42 | |||
| 43 | if (tlen < MIN_Xs) { | ||
| 44 | if (fd >= 0) | ||
| 45 | errx(1, "mkstemp(%s) succeed with too few Xs", path); | ||
| 46 | if (errno != EINVAL) | ||
| 47 | err(1, "mkstemp(%s) failed with wrong errno", path); | ||
| 48 | return 1; | ||
| 49 | } | ||
| 50 | if (fd < 0) | ||
| 51 | err(1, "mkstemp(%s)", path); | ||
| 52 | if (stat(path, &sb)) | ||
| 53 | err(1, "stat(%s)", path); | ||
| 54 | if (fstat(fd, &fsb)) | ||
| 55 | err(1, "fstat(%d==%s)", fd, path); | ||
| 56 | if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) | ||
| 57 | errx(1, "stat mismatch"); | ||
| 58 | close(fd); | ||
| 59 | if (memcmp(path, prefix, plen) != 0) | ||
| 60 | errx(1, "prefix changed! %s vs %s", prefix, path); | ||
| 61 | if (memcmp(path + plen + tlen, suffix, slen + 1) != 0) | ||
| 62 | errx(1, "suffix changed! %s vs %s", suffix, path); | ||
| 63 | for (p = path + plen; p < path + plen + tlen; p++) | ||
| 64 | if (*p == '\0') | ||
| 65 | errx(1, "unexpected truncation"); | ||
| 66 | else if (*p == 'X') | ||
| 67 | return 0; | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | void | ||
| 73 | try_mkstemp(char *p, char const *prefix, int len) | ||
| 74 | { | ||
| 75 | char *q; | ||
| 76 | size_t plen = strlen(prefix); | ||
| 77 | int tries, fd; | ||
| 78 | |||
| 79 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
| 80 | memcpy(p, prefix, plen); | ||
| 81 | memset(p + plen, 'X', len); | ||
| 82 | p[plen + len] = '\0'; | ||
| 83 | fd = mkstemp(p); | ||
| 84 | if (check(fd, p, prefix, plen, "", 0, len)) | ||
| 85 | return; | ||
| 86 | } | ||
| 87 | errx(1, "exceeded MAX_TRIES"); | ||
| 88 | } | ||
| 89 | |||
| 90 | void | ||
| 91 | try_mkstemps(char *p, char const *prefix, int len, char const *suffix) | ||
| 92 | { | ||
| 93 | char *q; | ||
| 94 | size_t plen = strlen(prefix); | ||
| 95 | size_t slen = strlen(suffix); | ||
| 96 | int tries, fd; | ||
| 97 | |||
| 98 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
| 99 | memcpy(p, prefix, plen); | ||
| 100 | memset(p + plen, 'X', len); | ||
| 101 | memcpy(p + plen + len, suffix, slen + 1); | ||
| 102 | fd = mkstemps(p, slen); | ||
| 103 | if (check(fd, p, prefix, plen, suffix, slen, len)) | ||
| 104 | return; | ||
| 105 | } | ||
| 106 | errx(1, "exceeded MAX_TRIES"); | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | main(void) | ||
| 111 | { | ||
| 112 | struct stat sb, fsb; | ||
| 113 | char cwd[MAXPATHLEN + 1]; | ||
| 114 | char *p; | ||
| 115 | size_t clen; | ||
| 116 | int i; | ||
| 117 | |||
| 118 | pg = sysconf(_SC_PAGESIZE); | ||
| 119 | if (getcwd(cwd, sizeof cwd - 1) == NULL) | ||
| 120 | err(1, "getcwd"); | ||
| 121 | clen = strlen(cwd); | ||
| 122 | cwd[clen++] = '/'; | ||
| 123 | cwd[clen] = '\0'; | ||
| 124 | p = mmap(NULL, pg * 3, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | ||
| 125 | if (p == MAP_FAILED) | ||
| 126 | err(1, "mmap"); | ||
| 127 | if (mprotect(p, pg, PROT_NONE) || mprotect(p + pg * 2, pg, PROT_NONE)) | ||
| 128 | err(1, "mprotect"); | ||
| 129 | p += pg; | ||
| 130 | |||
| 131 | i = MAX_TEMPLATE_LEN + 1; | ||
| 132 | while (i-- > 0) { | ||
| 133 | /* try first at the start of a page, no prefix */ | ||
| 134 | try_mkstemp(p, "", i); | ||
| 135 | /* now at the end of the page, no prefix */ | ||
| 136 | try_mkstemp(p + pg - i - 1, "", i); | ||
| 137 | /* start of the page, prefixed with the cwd */ | ||
| 138 | try_mkstemp(p, cwd, i); | ||
| 139 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 140 | try_mkstemp(p + pg - clen - i - 1, cwd, i); | ||
| 141 | |||
| 142 | /* again, with mkstemps() and an empty suffix */ | ||
| 143 | /* try first at the start of a page, no prefix */ | ||
| 144 | try_mkstemps(p, "", i, ""); | ||
| 145 | /* now at the end of the page, no prefix */ | ||
| 146 | try_mkstemps(p + pg - i - 1, "", i, ""); | ||
| 147 | /* start of the page, prefixed with the cwd */ | ||
| 148 | try_mkstemps(p, cwd, i, ""); | ||
| 149 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 150 | try_mkstemps(p + pg - clen - i - 1, cwd, i, ""); | ||
| 151 | |||
| 152 | /* mkstemps() and a non-empty suffix */ | ||
| 153 | /* try first at the start of a page, no prefix */ | ||
| 154 | try_mkstemps(p, "", i, SUFFIX); | ||
| 155 | /* now at the end of the page, no prefix */ | ||
| 156 | try_mkstemps(p + pg - i - SLEN - 1, "", i, SUFFIX); | ||
| 157 | /* start of the page, prefixed with the cwd */ | ||
| 158 | try_mkstemps(p, cwd, i, SUFFIX); | ||
| 159 | /* how about at the end of the page, prefixed with cwd? */ | ||
| 160 | try_mkstemps(p + pg - clen - i - SLEN - 1, cwd, i, SUFFIX); | ||
| 161 | |||
| 162 | } | ||
| 163 | |||
| 164 | return 0; | ||
| 165 | } | ||
diff --git a/src/regress/lib/libc/modf/Makefile b/src/regress/lib/libc/modf/Makefile deleted file mode 100644 index 587c595f12..0000000000 --- a/src/regress/lib/libc/modf/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | PROG=modf_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/modf/modf_test.c b/src/regress/lib/libc/modf/modf_test.c deleted file mode 100644 index f732533635..0000000000 --- a/src/regress/lib/libc/modf/modf_test.c +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* Public domain, 2014, Tobias Ulmer <tobiasu@tmux.org> */ | ||
| 2 | |||
| 3 | /* Test for bug introduced in 4.4BSD modf() on sparc */ | ||
| 4 | |||
| 5 | #include <math.h> | ||
| 6 | |||
| 7 | #define BIGFLOAT (5e15) /* Number large enough to trigger the "big" case */ | ||
| 8 | |||
| 9 | int | ||
| 10 | main(void) | ||
| 11 | { | ||
| 12 | double f, i; | ||
| 13 | |||
| 14 | f = modf(BIGFLOAT, &i); | ||
| 15 | if (i != BIGFLOAT) | ||
| 16 | return 1; | ||
| 17 | if (f != 0.0) | ||
| 18 | return 1; | ||
| 19 | |||
| 20 | /* Repeat, maybe we were lucky */ | ||
| 21 | f = modf(BIGFLOAT, &i); | ||
| 22 | if (i != BIGFLOAT) | ||
| 23 | return 1; | ||
| 24 | if (f != 0.0) | ||
| 25 | return 1; | ||
| 26 | |||
| 27 | /* With negative number, for good measure */ | ||
| 28 | f = modf(-BIGFLOAT, &i); | ||
| 29 | if (i != -BIGFLOAT) | ||
| 30 | return 1; | ||
| 31 | if (f != 0.0) | ||
| 32 | return 1; | ||
| 33 | |||
| 34 | return 0; | ||
| 35 | } | ||
diff --git a/src/regress/lib/libc/netdb/Makefile b/src/regress/lib/libc/netdb/Makefile deleted file mode 100644 index 8254607227..0000000000 --- a/src/regress/lib/libc/netdb/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/10/25 15:10:36 otto Exp $ | ||
| 2 | |||
| 3 | PROG= netdb | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/netdb/netdb.c b/src/regress/lib/libc/netdb/netdb.c deleted file mode 100644 index fabb3ee4e1..0000000000 --- a/src/regress/lib/libc/netdb/netdb.c +++ /dev/null | |||
| @@ -1,183 +0,0 @@ | |||
| 1 | /* $OpenBSD: netdb.c,v 1.2 2011/05/01 04:27:07 guenther Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2004, Otto Moerbeek <otto@drijf.net> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <err.h> | ||
| 8 | #include <netdb.h> | ||
| 9 | #include <stdarg.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | int ret = 0; | ||
| 13 | |||
| 14 | void | ||
| 15 | checkp(int n, struct protoent *p, int proto, const char *name, ...) | ||
| 16 | { | ||
| 17 | va_list va; | ||
| 18 | char *a; | ||
| 19 | int i; | ||
| 20 | |||
| 21 | if (p == NULL) { | ||
| 22 | warnx("%d proto struct is NULL", n); | ||
| 23 | ret = 1; | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | if (p->p_proto != proto) { | ||
| 27 | warnx("%d proto num mismatch %d %d", n, p->p_proto, proto); | ||
| 28 | ret = 1; | ||
| 29 | } | ||
| 30 | if (strcmp(p->p_name, name) != 0) { | ||
| 31 | warnx("%d proto name mismatch %s %s", n, p->p_name, name); | ||
| 32 | ret = 1; | ||
| 33 | } | ||
| 34 | va_start(va, name); | ||
| 35 | a = va_arg(va, char *); | ||
| 36 | i = 0; | ||
| 37 | while (a != NULL) { | ||
| 38 | if (strcmp(p->p_aliases[i], a) != 0) { | ||
| 39 | warnx("%d proto alias mismatch %s %s", n, | ||
| 40 | p->p_aliases[i], a); | ||
| 41 | ret = 1; | ||
| 42 | } | ||
| 43 | i++; | ||
| 44 | a = va_arg(va, char *); | ||
| 45 | } | ||
| 46 | if (p->p_aliases[i] != NULL) { | ||
| 47 | warnx("%d proto alias list does not end with NULL", n); | ||
| 48 | ret = 1; | ||
| 49 | } | ||
| 50 | va_end(va); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | void | ||
| 55 | checks(int n, struct servent *s, int port, const char *proto, | ||
| 56 | const char *name, ...) | ||
| 57 | { | ||
| 58 | va_list va; | ||
| 59 | char *a; | ||
| 60 | int i; | ||
| 61 | |||
| 62 | if (s == NULL) { | ||
| 63 | warnx("%d serv struct is NULL", n); | ||
| 64 | ret = 1; | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | if (s->s_port != ntohs(port)) { | ||
| 68 | warnx("%d port num mismatch %d %d", n, s->s_port, port); | ||
| 69 | ret = 1; | ||
| 70 | } | ||
| 71 | if (strcmp(s->s_name, name) != 0) { | ||
| 72 | warnx("%d serv name mismatch %s %s", n, s->s_name, name); | ||
| 73 | ret = 1; | ||
| 74 | } | ||
| 75 | if (strcmp(s->s_proto, proto) != 0) { | ||
| 76 | warnx("%d serv proto mismatch %s %s", n, s->s_proto, proto); | ||
| 77 | ret = 1; | ||
| 78 | } | ||
| 79 | va_start(va, name); | ||
| 80 | a = va_arg(va, char *); | ||
| 81 | i = 0; | ||
| 82 | while (a != NULL) { | ||
| 83 | if (strcmp(s->s_aliases[i], a) != 0) { | ||
| 84 | warnx("%d serv alias mismatch %s %s", n, | ||
| 85 | s->s_aliases[i], a); | ||
| 86 | ret = 1; | ||
| 87 | } | ||
| 88 | i++; | ||
| 89 | a = va_arg(va, char *); | ||
| 90 | } | ||
| 91 | if (s->s_aliases[i] != NULL) { | ||
| 92 | warnx("%d serv alias list does not end with NULL", n); | ||
| 93 | ret = 1; | ||
| 94 | } | ||
| 95 | va_end(va); | ||
| 96 | } | ||
| 97 | |||
| 98 | int | ||
| 99 | main() | ||
| 100 | { | ||
| 101 | struct protoent *p; | ||
| 102 | struct protoent protoent; | ||
| 103 | struct protoent_data protoent_data; | ||
| 104 | struct servent *s; | ||
| 105 | struct servent servent; | ||
| 106 | struct servent_data servent_data; | ||
| 107 | int r; | ||
| 108 | |||
| 109 | p = getprotobynumber(35); | ||
| 110 | checkp(1, p, 35, "idpr", "IDPR", (char *)NULL); | ||
| 111 | |||
| 112 | p = getprotobyname("igp"); | ||
| 113 | checkp(2, p, 9, "igp", "IGP", (char *) NULL); | ||
| 114 | |||
| 115 | p = getprotobyname("RDP"); | ||
| 116 | checkp(3, p, 27, "rdp", "RDP", (char *) NULL); | ||
| 117 | |||
| 118 | p = getprotobyname("vrrp"); | ||
| 119 | checkp(4, p, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
| 120 | |||
| 121 | p = getprotobyname("nonexistent"); | ||
| 122 | if (p != NULL) | ||
| 123 | err(1, "nonexistent proto found"); | ||
| 124 | |||
| 125 | memset(&protoent_data, 0, sizeof(protoent_data)); | ||
| 126 | r = getprotobynumber_r(35, &protoent, &protoent_data); | ||
| 127 | if (r != 0) | ||
| 128 | err(1, "proto not found"); | ||
| 129 | |||
| 130 | checkp(5, &protoent, 35, "idpr", "IDPR", (char *)NULL); | ||
| 131 | |||
| 132 | r = getprotobyname_r("vrrp", &protoent, &protoent_data); | ||
| 133 | if (r != 0) | ||
| 134 | err(1, "proto not found"); | ||
| 135 | checkp(6, &protoent, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
| 136 | |||
| 137 | r = getprotobyname_r("nonexistent", &protoent, &protoent_data); | ||
| 138 | if (r != -1) | ||
| 139 | err(1, "nonexistent proto found"); | ||
| 140 | |||
| 141 | r = getprotobyname_r("", &protoent, &protoent_data); | ||
| 142 | if (r != -1) | ||
| 143 | err(1, "nonexistent proto found"); | ||
| 144 | |||
| 145 | |||
| 146 | r = getprotobynumber_r(256, &protoent, &protoent_data); | ||
| 147 | if (r != -1) | ||
| 148 | err(1, "nonexistent proto found"); | ||
| 149 | |||
| 150 | s = getservbyname("zip", NULL); | ||
| 151 | checks(7, s, 6, "ddp", "zip", (char *)NULL); | ||
| 152 | |||
| 153 | s = getservbyname("nicname", "tcp"); | ||
| 154 | checks(8, s, 43, "tcp", "whois", "nicname", (char *)NULL); | ||
| 155 | |||
| 156 | s = getservbyport(htons(42), "tcp"); | ||
| 157 | checks(9, s, 42, "tcp", "nameserver", "name", (char *)NULL); | ||
| 158 | |||
| 159 | memset(&servent_data, 0, sizeof(servent_data)); | ||
| 160 | r = getservbyname_r("zip", "ddp", &servent, &servent_data); | ||
| 161 | if (r != 0) | ||
| 162 | err(1, "servent not found"); | ||
| 163 | checks(10, &servent, 6, "ddp", "zip", (char *)NULL); | ||
| 164 | |||
| 165 | r = getservbyport_r(htons(520), NULL, &servent, &servent_data); | ||
| 166 | if (r != 0) | ||
| 167 | err(1, "servent not found"); | ||
| 168 | checks(11, &servent, 520, "udp", "route", "router", "routed", (char *)NULL); | ||
| 169 | |||
| 170 | r = getservbyname_r("nonexistent", NULL, &servent, &servent_data); | ||
| 171 | if (r != -1) | ||
| 172 | err(1, "nonexiststent servent found"); | ||
| 173 | |||
| 174 | r = getservbyport_r(htons(50000), NULL, &servent, &servent_data); | ||
| 175 | if (r != -1) | ||
| 176 | err(1, "nonexistent servent found"); | ||
| 177 | |||
| 178 | r = getservbyport_r(htons(520), "tcp", &servent, &servent_data); | ||
| 179 | if (r != -1) | ||
| 180 | err(1, "nonexistent servent found"); | ||
| 181 | |||
| 182 | return ret; | ||
| 183 | } | ||
diff --git a/src/regress/lib/libc/open_memstream/Makefile b/src/regress/lib/libc/open_memstream/Makefile deleted file mode 100644 index ab7d194232..0000000000 --- a/src/regress/lib/libc/open_memstream/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2013/06/02 15:33:53 dtucker Exp $ | ||
| 2 | |||
| 3 | PROG= open_memstreamtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/open_memstream/open_memstreamtest.c b/src/regress/lib/libc/open_memstream/open_memstreamtest.c deleted file mode 100644 index 0608bddeba..0000000000 --- a/src/regress/lib/libc/open_memstream/open_memstreamtest.c +++ /dev/null | |||
| @@ -1,181 +0,0 @@ | |||
| 1 | /* $OpenBSD: open_memstreamtest.c,v 1.4 2014/07/20 01:58:37 guenther Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | ||
| 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 <err.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include <unistd.h> | ||
| 24 | |||
| 25 | #define OFFSET 16384 | ||
| 26 | |||
| 27 | const char start[] = "start"; | ||
| 28 | const char hello[] = "hello"; | ||
| 29 | |||
| 30 | int | ||
| 31 | main(void) | ||
| 32 | { | ||
| 33 | FILE *fp; | ||
| 34 | char *buf = (char *)0xff; | ||
| 35 | size_t size = 0; | ||
| 36 | off_t off; | ||
| 37 | int i, failures = 0; | ||
| 38 | |||
| 39 | if ((fp = open_memstream(&buf, &size)) == NULL) { | ||
| 40 | warn("open_memstream failed"); | ||
| 41 | return (1); | ||
| 42 | } | ||
| 43 | |||
| 44 | off = ftello(fp); | ||
| 45 | if (off != 0) { | ||
| 46 | warnx("ftello failed. (1)"); | ||
| 47 | failures++; | ||
| 48 | } | ||
| 49 | |||
| 50 | if (fflush(fp) != 0) { | ||
| 51 | warnx("fflush failed. (2)"); | ||
| 52 | failures++; | ||
| 53 | } | ||
| 54 | |||
| 55 | if (size != 0) { | ||
| 56 | warnx("string should be empty. (3)"); | ||
| 57 | failures++; | ||
| 58 | } | ||
| 59 | |||
| 60 | if (buf == (char *)0xff) { | ||
| 61 | warnx("buf not updated. (4)"); | ||
| 62 | failures++; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (fseek(fp, OFFSET, SEEK_SET) != 0) { | ||
| 66 | warnx("failed to fseek. (5)"); | ||
| 67 | failures++; | ||
| 68 | } | ||
| 69 | |||
| 70 | if (fprintf(fp, hello) == EOF) { | ||
| 71 | warnx("fprintf failed. (6)"); | ||
| 72 | failures++; | ||
| 73 | } | ||
| 74 | |||
| 75 | if (fflush(fp) == EOF) { | ||
| 76 | warnx("fflush failed. (7)"); | ||
| 77 | failures++; | ||
| 78 | } | ||
| 79 | |||
| 80 | if (size != OFFSET + sizeof(hello)-1) { | ||
| 81 | warnx("failed, size %zu should be %zu. (8)", | ||
| 82 | size, OFFSET + sizeof(hello)-1); | ||
| 83 | failures++; | ||
| 84 | } | ||
| 85 | |||
| 86 | if (fseek(fp, 0, SEEK_SET) != 0) { | ||
| 87 | warnx("failed to fseek. (9)"); | ||
| 88 | failures++; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (fprintf(fp, start) == EOF) { | ||
| 92 | warnx("fprintf failed. (10)"); | ||
| 93 | failures++; | ||
| 94 | } | ||
| 95 | |||
| 96 | if (fflush(fp) == EOF) { | ||
| 97 | warnx("fflush failed. (11)"); | ||
| 98 | failures++; | ||
| 99 | } | ||
| 100 | |||
| 101 | if (size != sizeof(start)-1) { | ||
| 102 | warnx("failed, size %zu should be %zu. (12)", | ||
| 103 | size, sizeof(start)-1); | ||
| 104 | failures++; | ||
| 105 | } | ||
| 106 | |||
| 107 | /* Needed for sparse files */ | ||
| 108 | if (strncmp(buf, start, sizeof(start)-1) != 0) { | ||
| 109 | warnx("failed, buffer didn't start with '%s'. (13)", start); | ||
| 110 | failures++; | ||
| 111 | } | ||
| 112 | for (i = sizeof(start)-1; i < OFFSET; i++) | ||
| 113 | if (buf[i] != '\0') { | ||
| 114 | warnx("failed, buffer non zero (offset %d). (14)", i); | ||
| 115 | failures++; | ||
| 116 | break; | ||
| 117 | } | ||
| 118 | |||
| 119 | if (memcmp(buf + OFFSET, hello, sizeof(hello)-1) != 0) { | ||
| 120 | warnx("written string incorrect. (15)"); | ||
| 121 | failures++; | ||
| 122 | } | ||
| 123 | |||
| 124 | /* verify that simply seeking past the end doesn't increase the size */ | ||
| 125 | if (fseek(fp, 100, SEEK_END) != 0) { | ||
| 126 | warnx("failed to fseek. (16)"); | ||
| 127 | failures++; | ||
| 128 | } | ||
| 129 | |||
| 130 | if (fflush(fp) == EOF) { | ||
| 131 | warnx("fflush failed. (17)"); | ||
| 132 | failures++; | ||
| 133 | } | ||
| 134 | |||
| 135 | if (size != OFFSET + sizeof(hello)-1) { | ||
| 136 | warnx("failed, size %zu should be %zu. (18)", | ||
| 137 | size, OFFSET + sizeof(hello)-1); | ||
| 138 | failures++; | ||
| 139 | } | ||
| 140 | |||
| 141 | if (fseek(fp, 8, SEEK_SET) != 0) { | ||
| 142 | warnx("failed to fseek. (19)"); | ||
| 143 | failures++; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (ftell(fp) != 8) { | ||
| 147 | warnx("failed seek test. (20)"); | ||
| 148 | failures++; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* Try to seek backward */ | ||
| 152 | if (fseek(fp, -1, SEEK_CUR) != 0) { | ||
| 153 | warnx("failed to fseek. (21)"); | ||
| 154 | failures++; | ||
| 155 | } | ||
| 156 | |||
| 157 | if (ftell(fp) != 7) { | ||
| 158 | warnx("failed seeking backward. (22)"); | ||
| 159 | failures++; | ||
| 160 | } | ||
| 161 | |||
| 162 | if (fseek(fp, 5, SEEK_CUR) != 0) { | ||
| 163 | warnx("failed to fseek. (23)"); | ||
| 164 | failures++; | ||
| 165 | } | ||
| 166 | |||
| 167 | if (fclose(fp) == EOF) { | ||
| 168 | warnx("fclose failed. (24)"); | ||
| 169 | failures++; | ||
| 170 | } | ||
| 171 | |||
| 172 | if (size != 12) { | ||
| 173 | warnx("failed, size %zu should be %u. (25)", | ||
| 174 | size, 12); | ||
| 175 | failures++; | ||
| 176 | } | ||
| 177 | |||
| 178 | free(buf); | ||
| 179 | |||
| 180 | return (failures); | ||
| 181 | } | ||
diff --git a/src/regress/lib/libc/orientation/Makefile b/src/regress/lib/libc/orientation/Makefile deleted file mode 100644 index 5c73702abe..0000000000 --- a/src/regress/lib/libc/orientation/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2010/06/29 16:20:28 guenther Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=orientation_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | run-regress-${PROG}: ${PROG} | ||
| 8 | ./${PROG} | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/orientation/orientation_test.c b/src/regress/lib/libc/orientation/orientation_test.c deleted file mode 100644 index 4d713f80bf..0000000000 --- a/src/regress/lib/libc/orientation/orientation_test.c +++ /dev/null | |||
| @@ -1,264 +0,0 @@ | |||
| 1 | /* $OpenBSD: orientation_test.c,v 1.5 2014/04/22 02:29:52 lteo Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2009 Philip Guenther | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /* | ||
| 33 | * Test whether the various stdio functions set the stream orientation | ||
| 34 | * ("width") as they should | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <sys/types.h> | ||
| 38 | #include <err.h> | ||
| 39 | #include <stddef.h> | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <unistd.h> | ||
| 44 | #include <wchar.h> | ||
| 45 | |||
| 46 | char filename[] = "/tmp/fwide.XXXXXXXXXX"; | ||
| 47 | |||
| 48 | FILE *dup_stdout = NULL; | ||
| 49 | int failures = 0; | ||
| 50 | |||
| 51 | void | ||
| 52 | fail(int line, int r, char const *expect, char const *test) | ||
| 53 | { | ||
| 54 | failures++; | ||
| 55 | fprintf(dup_stdout, | ||
| 56 | "FAIL: %d: fwide returned %d, expected %s 0 after %s\n", | ||
| 57 | line, r, expect, test); | ||
| 58 | } | ||
| 59 | |||
| 60 | FILE * | ||
| 61 | setup(int line) | ||
| 62 | { | ||
| 63 | FILE *f; | ||
| 64 | int r; | ||
| 65 | |||
| 66 | if ((f = fopen(filename, "r+")) == NULL) | ||
| 67 | err(2, "fopen"); | ||
| 68 | if ((r = fwide(f, 0)) != 0) | ||
| 69 | fail(line, r, "==", "fopen"); | ||
| 70 | return (f); | ||
| 71 | } | ||
| 72 | |||
| 73 | FILE * | ||
| 74 | setup_std(FILE *std, int line) | ||
| 75 | { | ||
| 76 | int r; | ||
| 77 | |||
| 78 | if (freopen(filename, "r+", std) == NULL) | ||
| 79 | err(2, "freopen"); | ||
| 80 | if ((r = fwide(std, 0)) != 0) | ||
| 81 | fail(line, r, "==", "freopen"); | ||
| 82 | return (std); | ||
| 83 | } | ||
| 84 | |||
| 85 | #define TEST_(x, op) \ | ||
| 86 | do { \ | ||
| 87 | f = setup(__LINE__); \ | ||
| 88 | x; \ | ||
| 89 | if (!((r = fwide(f, 0)) op 0)) \ | ||
| 90 | fail(__LINE__, r, #op, #x); \ | ||
| 91 | fclose(f); \ | ||
| 92 | } while (0) | ||
| 93 | |||
| 94 | #define TEST_STD_(std, x, op) \ | ||
| 95 | do { \ | ||
| 96 | f = setup_std(std, __LINE__); \ | ||
| 97 | x; \ | ||
| 98 | if (!((r = fwide(f, 0)) op 0)) \ | ||
| 99 | fail(__LINE__, r, #op, #x); \ | ||
| 100 | } while (0) | ||
| 101 | |||
| 102 | #define TEST_UNCHANGED(x) TEST_(x, ==) | ||
| 103 | #define TEST_NARROW(x) TEST_(x, <) | ||
| 104 | #define TEST_WIDE(x) TEST_(x, >) | ||
| 105 | #define TEST_UNCHANGED_STD(std, x) TEST_STD_(std, x, ==) | ||
| 106 | #define TEST_NARROW_STD(std, x) TEST_STD_(std, x, <) | ||
| 107 | #define TEST_WIDE_STD(std, x) TEST_STD_(std, x, >) | ||
| 108 | |||
| 109 | int | ||
| 110 | main(int argc, char *argv[]) | ||
| 111 | { | ||
| 112 | char buffer[BUFSIZ]; | ||
| 113 | wchar_t wbuffer[BUFSIZ]; | ||
| 114 | char *buf; | ||
| 115 | wchar_t *wbuf; | ||
| 116 | FILE *f; | ||
| 117 | off_t off; | ||
| 118 | fpos_t pos; | ||
| 119 | size_t size; | ||
| 120 | int fd, r; | ||
| 121 | char c; | ||
| 122 | wchar_t wc; | ||
| 123 | |||
| 124 | if ((fd = dup(1)) == -1) | ||
| 125 | err(2, "dup"); | ||
| 126 | if ((dup_stdout = fdopen(fd, "w")) == NULL) | ||
| 127 | err(2, "fdopen"); | ||
| 128 | if ((fd = mkstemp(filename)) == -1) | ||
| 129 | err(2, "mkstemp"); | ||
| 130 | if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) | ||
| 131 | err(2, "write + close"); | ||
| 132 | |||
| 133 | /* status */ | ||
| 134 | TEST_UNCHANGED(fwide(f, 0)); | ||
| 135 | TEST_NARROW(fwide(f, -1)); | ||
| 136 | TEST_WIDE(fwide(f, 1)); | ||
| 137 | TEST_UNCHANGED(feof(f)); | ||
| 138 | TEST_UNCHANGED(ferror(f)); | ||
| 139 | TEST_UNCHANGED(fileno(f)); | ||
| 140 | TEST_UNCHANGED(clearerr(f)); | ||
| 141 | |||
| 142 | /* flush and purge */ | ||
| 143 | TEST_UNCHANGED(fflush(f)); | ||
| 144 | TEST_UNCHANGED(fpurge(f)); | ||
| 145 | |||
| 146 | /* positioning */ | ||
| 147 | TEST_UNCHANGED(fgetpos(f, &pos)); | ||
| 148 | TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); | ||
| 149 | TEST_UNCHANGED(ftell(f)); | ||
| 150 | TEST_UNCHANGED(ftello(f)); | ||
| 151 | TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); | ||
| 152 | TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); | ||
| 153 | TEST_UNCHANGED(fseek(f, 1, SEEK_END)); | ||
| 154 | TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); | ||
| 155 | TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); | ||
| 156 | TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); | ||
| 157 | TEST_UNCHANGED(rewind(f)); | ||
| 158 | |||
| 159 | /* buffering */ | ||
| 160 | TEST_UNCHANGED(setbuf(f, NULL)); | ||
| 161 | TEST_UNCHANGED(setbuf(f, buffer)); | ||
| 162 | TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); | ||
| 163 | TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); | ||
| 164 | TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); | ||
| 165 | TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); | ||
| 166 | TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); | ||
| 167 | TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); | ||
| 168 | TEST_UNCHANGED(setbuffer(f, NULL, 0)); | ||
| 169 | TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); | ||
| 170 | TEST_UNCHANGED(setlinebuf(f)); | ||
| 171 | |||
| 172 | /* locking */ | ||
| 173 | TEST_UNCHANGED(flockfile(f);funlockfile(f)); | ||
| 174 | TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); | ||
| 175 | |||
| 176 | /* input */ | ||
| 177 | TEST_NARROW(getc(f)); | ||
| 178 | TEST_NARROW(getc_unlocked(f)); | ||
| 179 | TEST_NARROW(fgetc(f)); | ||
| 180 | TEST_NARROW(c = fgetc(f); ungetc(c, f)); | ||
| 181 | TEST_NARROW(fgets(buffer, BUFSIZ, f)); | ||
| 182 | TEST_NARROW(fscanf(f, "%s\n", buffer)); | ||
| 183 | TEST_NARROW(fgetln(f, &size)); | ||
| 184 | |||
| 185 | /* output */ | ||
| 186 | TEST_NARROW(putc('c', f)); | ||
| 187 | TEST_NARROW(putc_unlocked('c', f)); | ||
| 188 | TEST_NARROW(fputc('c', f)); | ||
| 189 | TEST_NARROW(fputs("foo", f)); | ||
| 190 | TEST_NARROW(fprintf(f, "%s\n", "foo")); | ||
| 191 | |||
| 192 | /* input from stdin */ | ||
| 193 | TEST_NARROW_STD(stdin, getchar()); | ||
| 194 | TEST_NARROW_STD(stdin, getchar_unlocked()); | ||
| 195 | TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); | ||
| 196 | |||
| 197 | /* output to stdout */ | ||
| 198 | TEST_NARROW_STD(stdout, putchar('c')); | ||
| 199 | TEST_NARROW_STD(stdout, putchar_unlocked('c')); | ||
| 200 | TEST_NARROW_STD(stdout, puts("foo")); | ||
| 201 | TEST_NARROW_STD(stdout, printf("foo")); | ||
| 202 | |||
| 203 | /* word-size ops */ | ||
| 204 | /* | ||
| 205 | * fread and fwrite are specified as being implemented in | ||
| 206 | * terms of fgetc() and fputc() and therefore must set the | ||
| 207 | * stream orientation to narrow. | ||
| 208 | */ | ||
| 209 | TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); | ||
| 210 | TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); | ||
| 211 | |||
| 212 | /* | ||
| 213 | * getw() and putw() aren't specified anywhere but logically | ||
| 214 | * should behave the same as fread/fwrite. Not all OSes agree: | ||
| 215 | * Solaris 10 has them not changing the orientation. | ||
| 216 | */ | ||
| 217 | TEST_NARROW(getw(f)); | ||
| 218 | TEST_NARROW(putw(1234, f)); | ||
| 219 | |||
| 220 | |||
| 221 | /* WIDE CHAR TIME! */ | ||
| 222 | |||
| 223 | /* input */ | ||
| 224 | TEST_WIDE(getwc(f)); | ||
| 225 | TEST_WIDE(fgetwc(f)); | ||
| 226 | TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); | ||
| 227 | TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); | ||
| 228 | TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); | ||
| 229 | |||
| 230 | /* output */ | ||
| 231 | TEST_WIDE(putwc(L'c', f)); | ||
| 232 | TEST_WIDE(fputwc(L'c', f)); | ||
| 233 | TEST_WIDE(fputws(L"foo", f)); | ||
| 234 | TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); | ||
| 235 | |||
| 236 | /* input from stdin */ | ||
| 237 | TEST_WIDE_STD(stdin, getwchar()); | ||
| 238 | TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); | ||
| 239 | |||
| 240 | /* output to stdout */ | ||
| 241 | TEST_WIDE_STD(stdout, putwchar(L'c')); | ||
| 242 | TEST_WIDE_STD(stdout, wprintf(L"foo")); | ||
| 243 | |||
| 244 | |||
| 245 | /* memory streams */ | ||
| 246 | f = open_memstream(&buf, &size); | ||
| 247 | if (!((r = fwide(f, 0)) < 0)) | ||
| 248 | fail(__LINE__, r, "<", "open_memstream()"); | ||
| 249 | fclose(f); | ||
| 250 | f = open_wmemstream(&wbuf, &size); | ||
| 251 | if (!((r = fwide(f, 0)) > 0)) | ||
| 252 | fail(__LINE__, r, ">", "open_wmemstream()"); | ||
| 253 | fclose(f); | ||
| 254 | |||
| 255 | |||
| 256 | /* random stuff? */ | ||
| 257 | TEST_UNCHANGED_STD(stderr, perror("foo")); | ||
| 258 | |||
| 259 | remove(filename); | ||
| 260 | if (failures) | ||
| 261 | exit(1); | ||
| 262 | exit(0); | ||
| 263 | } | ||
| 264 | |||
diff --git a/src/regress/lib/libc/popen/Makefile b/src/regress/lib/libc/popen/Makefile deleted file mode 100644 index 25b8668a7a..0000000000 --- a/src/regress/lib/libc/popen/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 01:55:09 art Exp $ | ||
| 2 | |||
| 3 | PROG=popen | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/popen/popen.c b/src/regress/lib/libc/popen/popen.c deleted file mode 100644 index 916cb71b03..0000000000 --- a/src/regress/lib/libc/popen/popen.c +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | /* $NetBSD: popen.c,v 1.1 1999/09/30 09:23:23 tron Exp $ */ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 8 | * by Matthias Scheler. | ||
| 9 | * | ||
| 10 | * Redistribution and use in source and binary forms, with or without | ||
| 11 | * modification, are permitted provided that the following conditions | ||
| 12 | * are met: | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in the | ||
| 17 | * documentation and/or other materials provided with the distribution. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <sys/param.h> | ||
| 33 | |||
| 34 | #include <err.h> | ||
| 35 | #include <errno.h> | ||
| 36 | #include <paths.h> | ||
| 37 | #include <stdio.h> | ||
| 38 | #include <stdlib.h> | ||
| 39 | #include <time.h> | ||
| 40 | #include <unistd.h> | ||
| 41 | |||
| 42 | #define _PATH_CAT "/bin/cat" | ||
| 43 | #define BUFSIZE (640*1024) | ||
| 44 | /* 640KB ought to be enough for everyone. */ | ||
| 45 | #define DATAFILE "popen.data" | ||
| 46 | |||
| 47 | int | ||
| 48 | main(int argc, char **argv) | ||
| 49 | { | ||
| 50 | char *buffer, command[MAXPATHLEN]; | ||
| 51 | int index, in; | ||
| 52 | FILE *pipe; | ||
| 53 | |||
| 54 | if ((buffer = malloc(BUFSIZE*sizeof(char))) == NULL) | ||
| 55 | err(1, NULL); | ||
| 56 | |||
| 57 | for (index=0; index<BUFSIZE; index++) | ||
| 58 | buffer[index]=arc4random(); | ||
| 59 | |||
| 60 | (void)snprintf(command, sizeof(command), "%s >%s", | ||
| 61 | _PATH_CAT, DATAFILE); | ||
| 62 | if ((pipe = popen(command, "w")) == NULL) | ||
| 63 | err(1, "popen write"); | ||
| 64 | |||
| 65 | if (fwrite(buffer, sizeof(char), BUFSIZE, pipe) != BUFSIZE) | ||
| 66 | err(1, "write"); | ||
| 67 | |||
| 68 | if (pclose(pipe) == -1) | ||
| 69 | err(1, "pclose"); | ||
| 70 | |||
| 71 | (void)snprintf(command, sizeof(command), "%s %s", | ||
| 72 | _PATH_CAT, DATAFILE); | ||
| 73 | if ((pipe = popen(command, "r")) == NULL) | ||
| 74 | err(1, "popen read"); | ||
| 75 | |||
| 76 | index = 0; | ||
| 77 | while ((in = fgetc(pipe)) != EOF) | ||
| 78 | if (index == BUFSIZE) { | ||
| 79 | errno = EFBIG; | ||
| 80 | err(1, "read"); | ||
| 81 | } | ||
| 82 | else | ||
| 83 | if ((char)in != buffer[index++]) { | ||
| 84 | errno = EINVAL; | ||
| 85 | err(1, "read"); | ||
| 86 | } | ||
| 87 | |||
| 88 | if (index < BUFSIZE) { | ||
| 89 | errno = EIO; | ||
| 90 | err(1, "read"); | ||
| 91 | } | ||
| 92 | |||
| 93 | if (pclose(pipe) == -1) | ||
| 94 | err(1, "pclose"); | ||
| 95 | |||
| 96 | (void)unlink(DATAFILE); | ||
| 97 | return 0; | ||
| 98 | } | ||
diff --git a/src/regress/lib/libc/printf/Makefile b/src/regress/lib/libc/printf/Makefile deleted file mode 100644 index c2e2732d6e..0000000000 --- a/src/regress/lib/libc/printf/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
| 2 | |||
| 3 | PROG= fp | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/printf/fp.c b/src/regress/lib/libc/printf/fp.c deleted file mode 100644 index 6ed52fdb49..0000000000 --- a/src/regress/lib/libc/printf/fp.c +++ /dev/null | |||
| @@ -1,217 +0,0 @@ | |||
| 1 | /* $OpenBSD: fp.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Test for printf() floating point formats. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <assert.h> | ||
| 33 | #include <err.h> | ||
| 34 | #include <float.h> | ||
| 35 | #include <math.h> | ||
| 36 | #include <stdio.h> | ||
| 37 | #include <stdarg.h> | ||
| 38 | #include <stdint.h> | ||
| 39 | #include <stdlib.h> | ||
| 40 | #include <string.h> | ||
| 41 | |||
| 42 | #define testfmt(result, fmt, ...) \ | ||
| 43 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
| 44 | void _testfmt(const char *, int, const char *, const char *, ...); | ||
| 45 | void smash_stack(void); | ||
| 46 | |||
| 47 | int | ||
| 48 | main(int argc, char *argv[]) | ||
| 49 | { | ||
| 50 | /* | ||
| 51 | * Basic tests of decimal output functionality. | ||
| 52 | */ | ||
| 53 | testfmt(" 1.000000E+00", "%13E", 1.0); | ||
| 54 | testfmt(" 1.000000", "%13f", 1.0); | ||
| 55 | testfmt(" 1", "%13G", 1.0); | ||
| 56 | testfmt(" 1.000000E+00", "%13LE", 1.0L); | ||
| 57 | testfmt(" 1.000000", "%13Lf", 1.0L); | ||
| 58 | testfmt(" 1", "%13LG", 1.0L); | ||
| 59 | |||
| 60 | testfmt("2.718282", "%.*f", -2, 2.7182818); | ||
| 61 | |||
| 62 | testfmt("1.234568e+06", "%e", 1234567.8); | ||
| 63 | testfmt("1234567.800000", "%f", 1234567.8); | ||
| 64 | testfmt("1.23457E+06", "%G", 1234567.8); | ||
| 65 | testfmt("1.234568e+06", "%Le", 1234567.8L); | ||
| 66 | testfmt("1234567.800000", "%Lf", 1234567.8L); | ||
| 67 | testfmt("1.23457E+06", "%LG", 1234567.8L); | ||
| 68 | |||
| 69 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
| 70 | testfmt("123456789.864210", "%Lf", 123456789.8642097531L); | ||
| 71 | testfmt("-1.23457E+08", "%LG", -123456789.8642097531L); | ||
| 72 | testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L); | ||
| 73 | testfmt(" 3.141592653589793238e-4000", "%L27.18Le", | ||
| 74 | 3.14159265358979323846e-4000L); | ||
| 75 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Infinities and NaNs | ||
| 79 | */ | ||
| 80 | #ifdef NAN | ||
| 81 | testfmt("nan", "%e", NAN); | ||
| 82 | testfmt("NAN", "%F", NAN); | ||
| 83 | testfmt("nan", "%g", NAN); | ||
| 84 | testfmt("NAN", "%LE", (long double)NAN); | ||
| 85 | testfmt(" nan", "%05e", NAN); | ||
| 86 | #endif /* NAN */ | ||
| 87 | |||
| 88 | testfmt("INF", "%E", HUGE_VAL); | ||
| 89 | testfmt("-inf", "%f", -HUGE_VAL); | ||
| 90 | testfmt("+inf", "%+g", HUGE_VAL); | ||
| 91 | testfmt(" inf", "%4.2Le", HUGE_VALL); | ||
| 92 | testfmt("-inf", "%Lf", -HUGE_VALL); | ||
| 93 | testfmt(" inf", "%05e", HUGE_VAL); | ||
| 94 | testfmt(" -inf", "%05e", -HUGE_VAL); | ||
| 95 | |||
| 96 | /* | ||
| 97 | * Padding | ||
| 98 | */ | ||
| 99 | testfmt("0.000000e+00", "%e", 0.0); | ||
| 100 | testfmt("0.000000", "%F", (double)0.0); | ||
| 101 | testfmt("0", "%G", 0.0); | ||
| 102 | testfmt(" 0", "%3.0Lg", 0.0L); | ||
| 103 | testfmt(" 0", "%5.0f", 0.001); | ||
| 104 | |||
| 105 | /* | ||
| 106 | * Precision specifiers | ||
| 107 | */ | ||
| 108 | testfmt("1.0123e+00", "%.4e", 1.0123456789); | ||
| 109 | testfmt("1.0123", "%.4f", 1.0123456789); | ||
| 110 | testfmt("1.012", "%.4g", 1.0123456789); | ||
| 111 | testfmt("1.2346e-02", "%.4e", 0.0123456789); | ||
| 112 | testfmt("0.0123", "%.4f", 0.0123456789); | ||
| 113 | testfmt("0.01235", "%.4g", 0.0123456789); | ||
| 114 | |||
| 115 | /* | ||
| 116 | * Signed conversions | ||
| 117 | */ | ||
| 118 | testfmt("+2.500000e-01", "%+e", 0.25); | ||
| 119 | testfmt("+0.000000", "%+F", 0.0); | ||
| 120 | testfmt("-1", "%+g", -1.0); | ||
| 121 | |||
| 122 | testfmt("-1.000000e+00", "% e", -1.0); | ||
| 123 | testfmt("+1.000000", "% +f", 1.0); | ||
| 124 | testfmt(" 1", "% g", 1.0); | ||
| 125 | testfmt(" 0", "% g", 0.0); | ||
| 126 | |||
| 127 | /* | ||
| 128 | * ``Alternate form'' | ||
| 129 | */ | ||
| 130 | testfmt("1.250e+00", "%#.3e", 1.25); | ||
| 131 | testfmt("123.000000", "%#f", 123.0); | ||
| 132 | testfmt(" 12345.", "%#7.5g", 12345.0); | ||
| 133 | testfmt(" 1.00000", "%#8g", 1.0); | ||
| 134 | testfmt("0.0", "%#.2g", 0.0); | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Padding and decimal point placement | ||
| 138 | */ | ||
| 139 | testfmt("03.2E+00", "%08.1E", 3.25); | ||
| 140 | testfmt("003.25", "%06.2F", 3.25); | ||
| 141 | testfmt("0003.25", "%07.4G", 3.25); | ||
| 142 | |||
| 143 | testfmt("3.14159e-05", "%g", 3.14159e-5); | ||
| 144 | testfmt("0.000314159", "%g", 3.14159e-4); | ||
| 145 | testfmt("3.14159e+06", "%g", 3.14159e6); | ||
| 146 | testfmt("314159", "%g", 3.14159e5); | ||
| 147 | testfmt("314159.", "%#g", 3.14159e5); | ||
| 148 | |||
| 149 | testfmt(" 9.000000e+03", "%13e", 9000.0); | ||
| 150 | testfmt(" 9000.000000", "%12f", 9000.0); | ||
| 151 | testfmt(" 9000", "%5g", 9000.0); | ||
| 152 | testfmt(" 900000.", "%#8g", 900000.0); | ||
| 153 | testfmt(" 9e+06", "%6g", 9000000.0); | ||
| 154 | testfmt(" 9.000000e-04", "%13e", 0.0009); | ||
| 155 | testfmt(" 0.000900", "%9f", 0.0009); | ||
| 156 | testfmt(" 0.0009", "%7g", 0.0009); | ||
| 157 | testfmt(" 9e-05", "%6g", 0.00009); | ||
| 158 | testfmt(" 9.00000e-05", "%#12g", 0.00009); | ||
| 159 | testfmt(" 9.e-05", "%#7.1g", 0.00009); | ||
| 160 | |||
| 161 | testfmt(" 0.0", "%4.1f", 0.0); | ||
| 162 | testfmt("90.0", "%4.1f", 90.0); | ||
| 163 | testfmt(" 100", "%4.0f", 100.0); | ||
| 164 | testfmt("9.0e+01", "%4.1e", 90.0); | ||
| 165 | testfmt("1e+02", "%4.0e", 100.0); | ||
| 166 | |||
| 167 | /* | ||
| 168 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
| 169 | * are only valid if the implementation converts to hex digits | ||
| 170 | * on nibble boundaries. | ||
| 171 | */ | ||
| 172 | testfmt("0x0p+0", "%a", 0x0.0p0); | ||
| 173 | testfmt("0X0.P+0", "%#LA", 0x0.0p0L); | ||
| 174 | #ifdef NAN | ||
| 175 | testfmt("inf", "%La", (long double)INFINITY); | ||
| 176 | testfmt("+INF", "%+A", INFINITY); | ||
| 177 | testfmt("nan", "%La", (long double)NAN); | ||
| 178 | testfmt("NAN", "%A", NAN); | ||
| 179 | #endif /* NAN */ | ||
| 180 | |||
| 181 | testfmt(" 0x1.23p+0", "%10a", 0x1.23p0); | ||
| 182 | testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500); | ||
| 183 | testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40); | ||
| 184 | testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4); | ||
| 185 | testfmt("0x1p-1074", "%a", 0x1p-1074); | ||
| 186 | testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); | ||
| 187 | |||
| 188 | return (0); | ||
| 189 | } | ||
| 190 | |||
| 191 | void | ||
| 192 | smash_stack(void) | ||
| 193 | { | ||
| 194 | static uint32_t junk = 0xdeadbeef; | ||
| 195 | uint32_t buf[512]; | ||
| 196 | int i; | ||
| 197 | |||
| 198 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
| 199 | buf[i] = junk; | ||
| 200 | } | ||
| 201 | |||
| 202 | void | ||
| 203 | _testfmt(const char *result, int line, const char *argstr, const char *fmt,...) | ||
| 204 | { | ||
| 205 | char s[100]; | ||
| 206 | va_list ap; | ||
| 207 | |||
| 208 | va_start(ap, fmt); | ||
| 209 | smash_stack(); | ||
| 210 | vsnprintf(s, sizeof(s), fmt, ap); | ||
| 211 | if (strcmp(result, s) != 0) { | ||
| 212 | fprintf(stderr, | ||
| 213 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
| 214 | line, fmt, argstr, s, result); | ||
| 215 | abort(); | ||
| 216 | } | ||
| 217 | } | ||
diff --git a/src/regress/lib/libc/qsort/Makefile b/src/regress/lib/libc/qsort/Makefile deleted file mode 100644 index 473432f423..0000000000 --- a/src/regress/lib/libc/qsort/Makefile +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2017/05/22 17:16:43 millert Exp $ | ||
| 2 | |||
| 3 | PROG= qsort_test | ||
| 4 | SRCS= qsort_test.c antiqsort.c | ||
| 5 | CFLAGS+=-Wall | ||
| 6 | |||
| 7 | qsort-regress: ${PROG} | ||
| 8 | ./${PROG} | ||
| 9 | |||
| 10 | REGRESS_TARGETS=qsort-regress | ||
| 11 | .PHONY: ${REGRESS_TARGETS} | ||
| 12 | |||
| 13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/qsort/antiqsort.c b/src/regress/lib/libc/qsort/antiqsort.c deleted file mode 100644 index cb3b7b2525..0000000000 --- a/src/regress/lib/libc/qsort/antiqsort.c +++ /dev/null | |||
| @@ -1,58 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * A Killer Adversary for Quicksort | ||
| 3 | * M. D. MCILROY | ||
| 4 | * http://www.cs.dartmouth.edu/~doug/mdmspe.pdf | ||
| 5 | * | ||
| 6 | * For comparison: | ||
| 7 | * Bentley & McIlroy: 4096 items, 1645585 compares | ||
| 8 | * random pivot: 4096 items, 8388649 compares | ||
| 9 | * introsort: 4096 items, 151580 compares | ||
| 10 | * heapsort: 4096 items, 48233 compares | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <stdio.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | |||
| 16 | static int *val; /* item values */ | ||
| 17 | static int ncmp; /* number of comparisons */ | ||
| 18 | static int nsolid; /* number of solid items */ | ||
| 19 | static int candidate; /* pivot candidate */ | ||
| 20 | static int gas; /* gas value */ | ||
| 21 | |||
| 22 | #define freeze(x) (val[(x)] = nsolid++) | ||
| 23 | |||
| 24 | static int | ||
| 25 | cmp(const void *px, const void *py) | ||
| 26 | { | ||
| 27 | const int x = *(const int *)px; | ||
| 28 | const int y = *(const int *)py; | ||
| 29 | |||
| 30 | ncmp++; | ||
| 31 | if (val[x] == gas && val[y] == gas) { | ||
| 32 | if (x == candidate) | ||
| 33 | freeze(x); | ||
| 34 | else | ||
| 35 | freeze(y); | ||
| 36 | } | ||
| 37 | if (val[x] == gas) | ||
| 38 | candidate = x; | ||
| 39 | else if (val[y] == gas) | ||
| 40 | candidate = y; | ||
| 41 | return val[x] > val[y] ? 1 : val[x] < val[y] ? -1 : 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | int | ||
| 45 | antiqsort(int n, int *a, int *ptr) | ||
| 46 | { | ||
| 47 | int i; | ||
| 48 | |||
| 49 | val = a; | ||
| 50 | gas = n - 1; | ||
| 51 | nsolid = ncmp = candidate = 0; | ||
| 52 | for (i = 0; i < n; i++) { | ||
| 53 | ptr[i] = i; | ||
| 54 | val[i] = gas; | ||
| 55 | } | ||
| 56 | qsort(ptr, n, sizeof(*ptr), cmp); | ||
| 57 | return ncmp; | ||
| 58 | } | ||
diff --git a/src/regress/lib/libc/qsort/qsort_test.c b/src/regress/lib/libc/qsort/qsort_test.c deleted file mode 100644 index 8ab3d9f50d..0000000000 --- a/src/regress/lib/libc/qsort/qsort_test.c +++ /dev/null | |||
| @@ -1,777 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2017 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <sys/time.h> | ||
| 18 | |||
| 19 | #include <stdbool.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <string.h> | ||
| 23 | #include <setjmp.h> | ||
| 24 | #include <time.h> | ||
| 25 | #include <unistd.h> | ||
| 26 | #include <err.h> | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Test program based on Bentley & McIlroy's "Engineering a Sort Function". | ||
| 30 | * Uses mergesort(3) to check the results. | ||
| 31 | * | ||
| 32 | * Additional "killer" input taken from: | ||
| 33 | * David R. Musser's "Introspective Sorting and Selection Algorithms" | ||
| 34 | * http://calmerthanyouare.org/2014/06/11/algorithmic-complexity-attacks-and-libc-qsort.html | ||
| 35 | * M. D. McIlroy's "A Killer Adversary for Quicksort" | ||
| 36 | */ | ||
| 37 | |||
| 38 | /* | ||
| 39 | * TODO: | ||
| 40 | * test with unaligned elements (char[]?) | ||
| 41 | */ | ||
| 42 | struct test_distribution { | ||
| 43 | const char *name; | ||
| 44 | void (*fill)(void *x, int n, int m); | ||
| 45 | int (*test)(struct test_distribution *d, int n, void *x, void *y, void *z); | ||
| 46 | int (*cmp)(const void *v1, const void *v2); | ||
| 47 | int (*cmp_checked)(const void *v1, const void *v2); | ||
| 48 | }; | ||
| 49 | |||
| 50 | #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) | ||
| 51 | #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) | ||
| 52 | |||
| 53 | static size_t compares; | ||
| 54 | static size_t max_compares; | ||
| 55 | static size_t abrt_compares; | ||
| 56 | static sigjmp_buf cmpjmp; | ||
| 57 | static bool dump_table, timing, verbose; | ||
| 58 | |||
| 59 | extern int antiqsort(int n, int *a, int *ptr); | ||
| 60 | |||
| 61 | static int | ||
| 62 | cmp_i(const void *v1, const void *v2) | ||
| 63 | { | ||
| 64 | const int a = *(const int *)v1; | ||
| 65 | const int b = *(const int *)v2; | ||
| 66 | |||
| 67 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | static int | ||
| 71 | cmp_checked_i(const void *v1, const void *v2) | ||
| 72 | { | ||
| 73 | const int a = *(const int *)v1; | ||
| 74 | const int b = *(const int *)v2; | ||
| 75 | |||
| 76 | compares++; | ||
| 77 | if (compares > abrt_compares) | ||
| 78 | siglongjmp(cmpjmp, 1); | ||
| 79 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | static int | ||
| 83 | cmp_ll(const void *v1, const void *v2) | ||
| 84 | { | ||
| 85 | const long long a = *(const long long *)v1; | ||
| 86 | const long long b = *(const long long *)v2; | ||
| 87 | |||
| 88 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 89 | } | ||
| 90 | |||
| 91 | static int | ||
| 92 | cmp_checked_ll(const void *v1, const void *v2) | ||
| 93 | { | ||
| 94 | const long long a = *(const long long *)v1; | ||
| 95 | const long long b = *(const long long *)v2; | ||
| 96 | |||
| 97 | compares++; | ||
| 98 | if (compares > abrt_compares) | ||
| 99 | siglongjmp(cmpjmp, 1); | ||
| 100 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | static int | ||
| 104 | cmp_d(const void *v1, const void *v2) | ||
| 105 | { | ||
| 106 | const double a = *(const double *)v1; | ||
| 107 | const double b = *(const double *)v2; | ||
| 108 | |||
| 109 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | static int | ||
| 113 | cmp_checked_d(const void *v1, const void *v2) | ||
| 114 | { | ||
| 115 | const double a = *(const double *)v1; | ||
| 116 | const double b = *(const double *)v2; | ||
| 117 | |||
| 118 | compares++; | ||
| 119 | if (compares > abrt_compares) | ||
| 120 | siglongjmp(cmpjmp, 1); | ||
| 121 | return a > b ? 1 : a < b ? -1 : 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | static int | ||
| 125 | check_result(char *sub, size_t es, char *got, char *expected, struct test_distribution *d, | ||
| 126 | int m, int n) | ||
| 127 | { | ||
| 128 | int i; | ||
| 129 | |||
| 130 | if (verbose || compares > max_compares) { | ||
| 131 | if (sub != NULL) { | ||
| 132 | if (m != 0) { | ||
| 133 | warnx("%s (%s): m: %d, n: %d, %zu compares, " | ||
| 134 | "max %zu(%zu)", d->name, sub, m, n, | ||
| 135 | compares, max_compares, abrt_compares); | ||
| 136 | } else { | ||
| 137 | warnx("%s (%s): n: %d, %zu compares, " | ||
| 138 | "max %zu(%zu)", d->name, sub, n, | ||
| 139 | compares, max_compares, abrt_compares); | ||
| 140 | } | ||
| 141 | } else { | ||
| 142 | if (m != 0) { | ||
| 143 | warnx("%s: m: %d, n: %d, %zu compares, " | ||
| 144 | "max %zu(%zu)", d->name, m, n, | ||
| 145 | compares, max_compares, abrt_compares); | ||
| 146 | } else { | ||
| 147 | warnx("%s: n: %d, %zu compares, " | ||
| 148 | "max %zu(%zu)", d->name, n, | ||
| 149 | compares, max_compares, abrt_compares); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | for (i = 0; i < n; i++) { | ||
| 155 | if (memcmp(got, expected, es) != 0) | ||
| 156 | break; | ||
| 157 | got += es; | ||
| 158 | expected += es; | ||
| 159 | } | ||
| 160 | if (i == n) | ||
| 161 | return 0; | ||
| 162 | |||
| 163 | if (sub != NULL) { | ||
| 164 | warnx("%s (%s): failure at %d, m: %d, n: %d", | ||
| 165 | d->name, sub, i, m, n); | ||
| 166 | } else { | ||
| 167 | warnx("%s: failure at %d, m: %d, n: %d", | ||
| 168 | d->name, i, m, n); | ||
| 169 | } | ||
| 170 | return 1; | ||
| 171 | } | ||
| 172 | |||
| 173 | #define FILL_SAWTOOTH(x, n, m) do { \ | ||
| 174 | int i; \ | ||
| 175 | \ | ||
| 176 | for (i = 0; i < n; i++) \ | ||
| 177 | x[i] = i % m; \ | ||
| 178 | } while (0) | ||
| 179 | |||
| 180 | static void | ||
| 181 | fill_sawtooth_i(void *v, int n, int m) | ||
| 182 | { | ||
| 183 | int *x = v; | ||
| 184 | FILL_SAWTOOTH(x, n, m); | ||
| 185 | } | ||
| 186 | |||
| 187 | static void | ||
| 188 | fill_sawtooth_ll(void *v, int n, int m) | ||
| 189 | { | ||
| 190 | long long *x = v; | ||
| 191 | FILL_SAWTOOTH(x, n, m); | ||
| 192 | } | ||
| 193 | |||
| 194 | static void | ||
| 195 | fill_sawtooth_double(void *v, int n, int m) | ||
| 196 | { | ||
| 197 | double *x = v; | ||
| 198 | FILL_SAWTOOTH(x, n, m); | ||
| 199 | } | ||
| 200 | |||
| 201 | #define FILL_RANDOM(x, n, m) do { \ | ||
| 202 | int i; \ | ||
| 203 | \ | ||
| 204 | for (i = 0; i < n; i++) \ | ||
| 205 | x[i] = arc4random_uniform(m); \ | ||
| 206 | } while (0) | ||
| 207 | |||
| 208 | |||
| 209 | static void | ||
| 210 | fill_random_i(void *v, int n, int m) | ||
| 211 | { | ||
| 212 | int *x = v; | ||
| 213 | FILL_RANDOM(x, n, m); | ||
| 214 | } | ||
| 215 | |||
| 216 | static void | ||
| 217 | fill_random_ll(void *v, int n, int m) | ||
| 218 | { | ||
| 219 | long long *x = v; | ||
| 220 | FILL_RANDOM(x, n, m); | ||
| 221 | } | ||
| 222 | |||
| 223 | static void | ||
| 224 | fill_random_double(void *v, int n, int m) | ||
| 225 | { | ||
| 226 | double *x = v; | ||
| 227 | FILL_RANDOM(x, n, m); | ||
| 228 | } | ||
| 229 | |||
| 230 | #define FILL_STAGGER(x, n, m) do { \ | ||
| 231 | int i; \ | ||
| 232 | \ | ||
| 233 | for (i = 0; i < n; i++) \ | ||
| 234 | x[i] = (i * m + i) % n; \ | ||
| 235 | } while (0) | ||
| 236 | |||
| 237 | |||
| 238 | static void | ||
| 239 | fill_stagger_i(void *v, int n, int m) | ||
| 240 | { | ||
| 241 | int *x = v; | ||
| 242 | FILL_STAGGER(x, n, m); | ||
| 243 | } | ||
| 244 | |||
| 245 | static void | ||
| 246 | fill_stagger_ll(void *v, int n, int m) | ||
| 247 | { | ||
| 248 | long long *x = v; | ||
| 249 | FILL_STAGGER(x, n, m); | ||
| 250 | } | ||
| 251 | |||
| 252 | static void | ||
| 253 | fill_stagger_double(void *v, int n, int m) | ||
| 254 | { | ||
| 255 | double *x = v; | ||
| 256 | FILL_STAGGER(x, n, m); | ||
| 257 | } | ||
| 258 | |||
| 259 | #define FILL_PLATEAU(x, n, m) do { \ | ||
| 260 | int i; \ | ||
| 261 | \ | ||
| 262 | for (i = 0; i < n; i++) \ | ||
| 263 | x[i] = MINIMUM(i, m); \ | ||
| 264 | } while (0) | ||
| 265 | |||
| 266 | static void | ||
| 267 | fill_plateau_i(void *v, int n, int m) | ||
| 268 | { | ||
| 269 | int *x = v; | ||
| 270 | FILL_PLATEAU(x, n, m); | ||
| 271 | } | ||
| 272 | |||
| 273 | static void | ||
| 274 | fill_plateau_ll(void *v, int n, int m) | ||
| 275 | { | ||
| 276 | long long *x = v; | ||
| 277 | FILL_PLATEAU(x, n, m); | ||
| 278 | } | ||
| 279 | |||
| 280 | static void | ||
| 281 | fill_plateau_double(void *v, int n, int m) | ||
| 282 | { | ||
| 283 | double *x = v; | ||
| 284 | FILL_PLATEAU(x, n, m); | ||
| 285 | } | ||
| 286 | |||
| 287 | #define FILL_SHUFFLE(x, n, m) do { \ | ||
| 288 | int i, j, k; \ | ||
| 289 | \ | ||
| 290 | for (i = 0, j = 0, k = 1; i < n; i++) \ | ||
| 291 | x[i] = arc4random_uniform(m) ? (j += 2) : (k += 2); \ | ||
| 292 | } while (0) | ||
| 293 | |||
| 294 | static void | ||
| 295 | fill_shuffle_i(void *v, int n, int m) | ||
| 296 | { | ||
| 297 | int *x = v; | ||
| 298 | FILL_SHUFFLE(x, n, m); | ||
| 299 | } | ||
| 300 | |||
| 301 | static void | ||
| 302 | fill_shuffle_ll(void *v, int n, int m) | ||
| 303 | { | ||
| 304 | long long *x = v; | ||
| 305 | FILL_SHUFFLE(x, n, m); | ||
| 306 | } | ||
| 307 | |||
| 308 | static void | ||
| 309 | fill_shuffle_double(void *v, int n, int m) | ||
| 310 | { | ||
| 311 | double *x = v; | ||
| 312 | FILL_SHUFFLE(x, n, m); | ||
| 313 | } | ||
| 314 | |||
| 315 | #define FILL_BSD_KILLER(x, n, m) do { \ | ||
| 316 | int i, k; \ | ||
| 317 | \ | ||
| 318 | /* 4.4BSD insertion sort optimization killer, Mats Linander */ \ | ||
| 319 | k = n / 2; \ | ||
| 320 | for (i = 0; i < n; i++) { \ | ||
| 321 | if (i < k) \ | ||
| 322 | x[i] = k - i; \ | ||
| 323 | else if (i > k) \ | ||
| 324 | x[i] = n + k + 1 - i; \ | ||
| 325 | else \ | ||
| 326 | x[i] = k + 1; \ | ||
| 327 | } \ | ||
| 328 | } while (0) | ||
| 329 | |||
| 330 | static void | ||
| 331 | fill_bsd_killer_i(void *v, int n, int m) | ||
| 332 | { | ||
| 333 | int *x = v; | ||
| 334 | FILL_BSD_KILLER(x, n, m); | ||
| 335 | |||
| 336 | } | ||
| 337 | |||
| 338 | static void | ||
| 339 | fill_bsd_killer_ll(void *v, int n, int m) | ||
| 340 | { | ||
| 341 | long long *x = v; | ||
| 342 | FILL_BSD_KILLER(x, n, m); | ||
| 343 | |||
| 344 | } | ||
| 345 | |||
| 346 | static void | ||
| 347 | fill_bsd_killer_double(void *v, int n, int m) | ||
| 348 | { | ||
| 349 | double *x = v; | ||
| 350 | FILL_BSD_KILLER(x, n, m); | ||
| 351 | |||
| 352 | } | ||
| 353 | |||
| 354 | #define FILL_MED3_KILLER(x, n, m) do { \ | ||
| 355 | int i, k; \ | ||
| 356 | \ | ||
| 357 | /* \ | ||
| 358 | * Median of 3 killer, as seen in David R Musser's \ | ||
| 359 | * "Introspective Sorting and Selection Algorithms" \ | ||
| 360 | */ \ | ||
| 361 | if (n & 1) { \ | ||
| 362 | /* odd size, store last at end and make even. */ \ | ||
| 363 | x[n - 1] = n; \ | ||
| 364 | n--; \ | ||
| 365 | } \ | ||
| 366 | k = n / 2; \ | ||
| 367 | for (i = 0; i < n; i++) { \ | ||
| 368 | if (i & 1) { \ | ||
| 369 | x[i] = k + x[i - 1]; \ | ||
| 370 | } else { \ | ||
| 371 | x[i] = i + 1; \ | ||
| 372 | } \ | ||
| 373 | } \ | ||
| 374 | } while (0) | ||
| 375 | |||
| 376 | static void | ||
| 377 | fill_med3_killer_i(void *v, int n, int m) | ||
| 378 | { | ||
| 379 | int *x = v; | ||
| 380 | FILL_MED3_KILLER(x, n, m); | ||
| 381 | } | ||
| 382 | |||
| 383 | static void | ||
| 384 | fill_med3_killer_ll(void *v, int n, int m) | ||
| 385 | { | ||
| 386 | long long *x = v; | ||
| 387 | FILL_MED3_KILLER(x, n, m); | ||
| 388 | } | ||
| 389 | |||
| 390 | static void | ||
| 391 | fill_med3_killer_double(void *v, int n, int m) | ||
| 392 | { | ||
| 393 | double *x = v; | ||
| 394 | FILL_MED3_KILLER(x, n, m); | ||
| 395 | } | ||
| 396 | |||
| 397 | static void | ||
| 398 | print_timing(struct test_distribution *d, char *sub, int m, int n, double elapsed) | ||
| 399 | { | ||
| 400 | if (sub != NULL) { | ||
| 401 | if (m != 0) { | ||
| 402 | warnx("%s (%s): m: %d, n: %d, %f seconds", | ||
| 403 | d->name, sub, m, n, elapsed); | ||
| 404 | } else { | ||
| 405 | warnx("%s (%s): n: %d, %f seconds", | ||
| 406 | d->name, sub, n, elapsed); | ||
| 407 | } | ||
| 408 | } else { | ||
| 409 | if (m != 0) { | ||
| 410 | warnx("%s: m: %d, n: %d, %f seconds", | ||
| 411 | d->name, m, n, elapsed); | ||
| 412 | } else { | ||
| 413 | warnx("%s: n: %d, %f seconds", | ||
| 414 | d->name, n, elapsed); | ||
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | static int | ||
| 420 | do_test(struct test_distribution *d, char *sub, int m, int n, size_t es, void *y, void *z) | ||
| 421 | { | ||
| 422 | int ret = 0; | ||
| 423 | struct timespec before, after; | ||
| 424 | |||
| 425 | compares = 0; | ||
| 426 | if (sigsetjmp(cmpjmp, 1) != 0) { | ||
| 427 | if (sub != NULL) { | ||
| 428 | warnx("%s (%s): qsort aborted after %zu compares, m: %d, n: %d", | ||
| 429 | d->name, sub, compares, m, n); | ||
| 430 | } else { | ||
| 431 | warnx("%s: qsort aborted after %zu compares, m: %d, n: %d", | ||
| 432 | d->name, compares, m, n); | ||
| 433 | } | ||
| 434 | ret = 1; | ||
| 435 | } else { | ||
| 436 | if (timing) | ||
| 437 | clock_gettime(CLOCK_MONOTONIC, &before); | ||
| 438 | qsort(y, n, es, d->cmp_checked); | ||
| 439 | if (timing) { | ||
| 440 | double elapsed; | ||
| 441 | clock_gettime(CLOCK_MONOTONIC, &after); | ||
| 442 | timespecsub(&after, &before, &after); | ||
| 443 | elapsed = after.tv_sec + after.tv_nsec / 1000000000.0; | ||
| 444 | print_timing(d, sub, m, n, elapsed); | ||
| 445 | } | ||
| 446 | if (check_result(sub, es, y, z, d, m, n) != 0) | ||
| 447 | ret = 1; | ||
| 448 | } | ||
| 449 | return ret; | ||
| 450 | } | ||
| 451 | |||
| 452 | #define TEST_PERTURBED(d, n, x, y, z) do { \ | ||
| 453 | int i, j, m; \ | ||
| 454 | const int es = sizeof(x[0]); \ | ||
| 455 | \ | ||
| 456 | for (m = 1; m < 2 * n; m *= 2) { \ | ||
| 457 | /* Fill in x[n] modified by m */ \ | ||
| 458 | d->fill(x, n, m); \ | ||
| 459 | \ | ||
| 460 | /* Test on copy of x[] */ \ | ||
| 461 | for (i = 0; i < n; i++) \ | ||
| 462 | y[i] = z[i] = x[i]; \ | ||
| 463 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
| 464 | err(1, NULL); \ | ||
| 465 | if (do_test(d, "copy", m, n, es, y, z) != 0) \ | ||
| 466 | ret = 1; \ | ||
| 467 | \ | ||
| 468 | /* Test on reversed copy of x[] */ \ | ||
| 469 | for (i = 0, j = n - 1; i < n; i++, j--) \ | ||
| 470 | y[i] = z[i] = x[j]; \ | ||
| 471 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
| 472 | err(1, NULL); \ | ||
| 473 | if (do_test(d, "reversed", m, n, es, y, z) != 0) \ | ||
| 474 | ret = 1; \ | ||
| 475 | \ | ||
| 476 | /* Test with front half of x[] reversed */ \ | ||
| 477 | for (i = 0, j = (n / 2) - 1; i < n / 2; i++, j--) \ | ||
| 478 | y[i] = z[i] = x[j]; \ | ||
| 479 | for (; i < n; i++) \ | ||
| 480 | y[i] = z[i] = x[i]; \ | ||
| 481 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
| 482 | err(1, NULL); \ | ||
| 483 | if (do_test(d, "front reversed", m, n, es, y, z) != 0) \ | ||
| 484 | ret = 1; \ | ||
| 485 | \ | ||
| 486 | /* Test with back half of x[] reversed */ \ | ||
| 487 | for (i = 0; i < n / 2; i++) \ | ||
| 488 | y[i] = z[i] = x[i]; \ | ||
| 489 | for (j = n - 1; i < n; i++, j--) \ | ||
| 490 | y[i] = z[i] = x[j]; \ | ||
| 491 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
| 492 | err(1, NULL); \ | ||
| 493 | if (do_test(d, "back reversed", m, n, es, y, z) != 0) \ | ||
| 494 | ret = 1; \ | ||
| 495 | \ | ||
| 496 | /* Test on sorted copy of x[] */ \ | ||
| 497 | if (mergesort(x, n, es, d->cmp) != 0) \ | ||
| 498 | err(1, NULL); \ | ||
| 499 | for (i = 0; i < n; i++) \ | ||
| 500 | y[i] = x[i]; \ | ||
| 501 | if (do_test(d, "sorted", m, n, es, y, x) != 0) \ | ||
| 502 | ret = 1; \ | ||
| 503 | \ | ||
| 504 | /* Test with i%5 added to x[i] (dither) */ \ | ||
| 505 | for (i = 0, j = n - 1; i < n; i++, j--) \ | ||
| 506 | y[i] = z[i] = x[j] + (i % 5); \ | ||
| 507 | if (mergesort(z, n, es, d->cmp) != 0) \ | ||
| 508 | err(1, NULL); \ | ||
| 509 | if (do_test(d, "dithered", m, n, es, y, z) != 0) \ | ||
| 510 | ret = 1; \ | ||
| 511 | } \ | ||
| 512 | } while (0) | ||
| 513 | |||
| 514 | static int | ||
| 515 | test_perturbed_i(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 516 | { | ||
| 517 | int *x = vx; | ||
| 518 | int *y = vx; | ||
| 519 | int *z = vz; | ||
| 520 | int ret = 0; | ||
| 521 | |||
| 522 | TEST_PERTURBED(d, n, x, y, z); | ||
| 523 | return ret; | ||
| 524 | } | ||
| 525 | |||
| 526 | static int | ||
| 527 | test_perturbed_ll(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 528 | { | ||
| 529 | long long *x = vx; | ||
| 530 | long long *y = vx; | ||
| 531 | long long *z = vz; | ||
| 532 | int ret = 0; | ||
| 533 | |||
| 534 | TEST_PERTURBED(d, n, x, y, z); | ||
| 535 | return ret; | ||
| 536 | } | ||
| 537 | |||
| 538 | static int | ||
| 539 | test_perturbed_double(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 540 | { | ||
| 541 | double *x = vx; | ||
| 542 | double *y = vx; | ||
| 543 | double *z = vz; | ||
| 544 | int ret = 0; | ||
| 545 | |||
| 546 | TEST_PERTURBED(d, n, x, y, z); | ||
| 547 | return ret; | ||
| 548 | } | ||
| 549 | |||
| 550 | /* | ||
| 551 | * Like TEST_PERTURBED but because the input is tailored to cause | ||
| 552 | * quicksort to go quadratic we don't perturb the input. | ||
| 553 | */ | ||
| 554 | #define TEST_SIMPLE(d, n, x, y, z) do { \ | ||
| 555 | int i, ret = 0; \ | ||
| 556 | \ | ||
| 557 | /* Fill in x[n] */ \ | ||
| 558 | d->fill(x, n, 0); \ | ||
| 559 | \ | ||
| 560 | /* Make a copy of x[] */ \ | ||
| 561 | for (i = 0; i < n; i++) \ | ||
| 562 | y[i] = z[i] = x[i]; \ | ||
| 563 | if (mergesort(z, n, sizeof(z[0]), d->cmp) != 0) \ | ||
| 564 | err(1, NULL); \ | ||
| 565 | if (do_test(d, NULL, 0, n, sizeof(x[0]), y, z) != 0) \ | ||
| 566 | ret = 1; \ | ||
| 567 | } while (0) | ||
| 568 | |||
| 569 | static int | ||
| 570 | test_simple_i(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 571 | { | ||
| 572 | int *x = vx; | ||
| 573 | int *y = vx; | ||
| 574 | int *z = vz; | ||
| 575 | int ret = 0; | ||
| 576 | |||
| 577 | TEST_SIMPLE(d, n, x, y, z); | ||
| 578 | return ret; | ||
| 579 | } | ||
| 580 | |||
| 581 | static int | ||
| 582 | test_simple_ll(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 583 | { | ||
| 584 | long long *x = vx; | ||
| 585 | long long *y = vx; | ||
| 586 | long long *z = vz; | ||
| 587 | int ret = 0; | ||
| 588 | |||
| 589 | TEST_SIMPLE(d, n, x, y, z); | ||
| 590 | return ret; | ||
| 591 | } | ||
| 592 | |||
| 593 | static int | ||
| 594 | test_simple_double(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 595 | { | ||
| 596 | double *x = vx; | ||
| 597 | double *y = vx; | ||
| 598 | double *z = vz; | ||
| 599 | int ret = 0; | ||
| 600 | |||
| 601 | TEST_SIMPLE(d, n, x, y, z); | ||
| 602 | return ret; | ||
| 603 | } | ||
| 604 | |||
| 605 | /* | ||
| 606 | * Use D. McIlroy's "Killer Adversary for Quicksort" | ||
| 607 | * We don't compare the results in this case. | ||
| 608 | */ | ||
| 609 | static int | ||
| 610 | test_antiqsort(struct test_distribution *d, int n, void *vx, void *vy, void *vz) | ||
| 611 | { | ||
| 612 | struct timespec before, after; | ||
| 613 | int *x = vx; | ||
| 614 | int *y = vx; | ||
| 615 | int i, ret = 0; | ||
| 616 | |||
| 617 | /* | ||
| 618 | * We expect antiqsort to generate > 1.5 * nlgn compares. | ||
| 619 | * If introspection is not used, it will be > 10 * nlgn compares. | ||
| 620 | */ | ||
| 621 | if (timing) | ||
| 622 | clock_gettime(CLOCK_MONOTONIC, &before); | ||
| 623 | i = antiqsort(n, x, y); | ||
| 624 | if (timing) | ||
| 625 | clock_gettime(CLOCK_MONOTONIC, &after); | ||
| 626 | if (i > abrt_compares) | ||
| 627 | ret = 1; | ||
| 628 | if (dump_table) { | ||
| 629 | printf("/* %d items, %d compares */\n", n, i); | ||
| 630 | printf("static const int table_%d[] = {", n); | ||
| 631 | for (i = 0; i < n - 1; i++) { | ||
| 632 | if ((i % 12) == 0) | ||
| 633 | printf("\n\t"); | ||
| 634 | printf("%4d, ", x[i]); | ||
| 635 | } | ||
| 636 | printf("%4d\n};\n", x[i]); | ||
| 637 | } else { | ||
| 638 | if (timing) { | ||
| 639 | double elapsed; | ||
| 640 | timespecsub(&after, &before, &after); | ||
| 641 | elapsed = after.tv_sec + after.tv_nsec / 1000000000.0; | ||
| 642 | print_timing(d, NULL, 0, n, elapsed); | ||
| 643 | } | ||
| 644 | if (verbose || ret != 0) { | ||
| 645 | warnx("%s: n: %d, %d compares, max %zu(%zu)", | ||
| 646 | d->name, n, i, max_compares, abrt_compares); | ||
| 647 | } | ||
| 648 | } | ||
| 649 | |||
| 650 | return ret; | ||
| 651 | } | ||
| 652 | |||
| 653 | static struct test_distribution distributions[] = { | ||
| 654 | { "sawtooth_i", fill_sawtooth_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
| 655 | { "sawtooth_ll", fill_sawtooth_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
| 656 | { "sawtooth_d", fill_sawtooth_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
| 657 | { "random_i", fill_random_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
| 658 | { "random_ll", fill_random_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
| 659 | { "random_d", fill_random_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
| 660 | { "stagger_i", fill_stagger_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
| 661 | { "stagger_ll", fill_stagger_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
| 662 | { "stagger_d", fill_stagger_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
| 663 | { "plateau_i", fill_plateau_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
| 664 | { "plateau_ll", fill_plateau_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
| 665 | { "plateau_d", fill_plateau_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
| 666 | { "shuffle_i", fill_shuffle_i, test_perturbed_i, cmp_i, cmp_checked_i }, | ||
| 667 | { "shuffle_ll", fill_shuffle_ll, test_perturbed_ll, cmp_ll, cmp_checked_ll }, | ||
| 668 | { "shuffle_d", fill_shuffle_double, test_perturbed_double, cmp_d, cmp_checked_d }, | ||
| 669 | { "bsd_killer_i", fill_bsd_killer_i, test_simple_i, cmp_i, cmp_checked_i }, | ||
| 670 | { "bsd_killer_ll", fill_bsd_killer_ll, test_simple_ll, cmp_ll, cmp_checked_ll }, | ||
| 671 | { "bsd_killer_d", fill_bsd_killer_double, test_simple_double, cmp_d, cmp_checked_d }, | ||
| 672 | { "med3_killer_i", fill_med3_killer_i, test_simple_i, cmp_i, cmp_checked_i }, | ||
| 673 | { "med3_killer_ll", fill_med3_killer_ll, test_simple_ll, cmp_ll, cmp_checked_ll }, | ||
| 674 | { "med3_killer_d", fill_med3_killer_double, test_simple_double, cmp_d, cmp_checked_d }, | ||
| 675 | { "antiqsort", NULL, test_antiqsort, cmp_i, cmp_checked_i }, | ||
| 676 | { NULL } | ||
| 677 | }; | ||
| 678 | |||
| 679 | static int | ||
| 680 | run_tests(int n, const char *name) | ||
| 681 | { | ||
| 682 | void *x, *y, *z; | ||
| 683 | int i, nlgn = 0; | ||
| 684 | int ret = 0; | ||
| 685 | size_t es; | ||
| 686 | struct test_distribution *d; | ||
| 687 | |||
| 688 | /* | ||
| 689 | * We expect A*n*lg(n) compares where A is between 1 and 2. | ||
| 690 | * For A > 1.5, print a warning. | ||
| 691 | * For A > 10 abort the test since qsort has probably gone quadratic. | ||
| 692 | */ | ||
| 693 | for (i = n - 1; i > 0; i >>= 1) | ||
| 694 | nlgn++; | ||
| 695 | nlgn *= n; | ||
| 696 | max_compares = nlgn * 1.5; | ||
| 697 | abrt_compares = nlgn * 10; | ||
| 698 | |||
| 699 | /* Allocate enough space to store ints or doubles. */ | ||
| 700 | es = MAXIMUM(sizeof(int), sizeof(double)); | ||
| 701 | x = reallocarray(NULL, n, es); | ||
| 702 | y = reallocarray(NULL, n, es); | ||
| 703 | z = reallocarray(NULL, n, es); | ||
| 704 | if (x == NULL || y == NULL || z == NULL) | ||
| 705 | err(1, NULL); | ||
| 706 | |||
| 707 | for (d = distributions; d->name != NULL; d++) { | ||
| 708 | if (name != NULL && strncmp(name, d->name, strlen(name)) != 0) | ||
| 709 | continue; | ||
| 710 | if (d->test(d, n, x, y, z) != 0) | ||
| 711 | ret = 1; | ||
| 712 | } | ||
| 713 | |||
| 714 | free(x); | ||
| 715 | free(y); | ||
| 716 | free(z); | ||
| 717 | return ret; | ||
| 718 | } | ||
| 719 | |||
| 720 | __dead void | ||
| 721 | usage(void) | ||
| 722 | { | ||
| 723 | fprintf(stderr, "usage: qsort_test [-dvt] [-n test_name] [num ...]\n"); | ||
| 724 | exit(1); | ||
| 725 | } | ||
| 726 | |||
| 727 | int | ||
| 728 | main(int argc, char *argv[]) | ||
| 729 | { | ||
| 730 | char *nums[] = { "100", "1023", "1024", "1025", "4095", "4096", "4097" }; | ||
| 731 | struct test_distribution *d; | ||
| 732 | int ch, n, ret = 0; | ||
| 733 | char *name = NULL; | ||
| 734 | |||
| 735 | while ((ch = getopt(argc, argv, "dn:tv")) != -1) { | ||
| 736 | switch (ch) { | ||
| 737 | case 'd': | ||
| 738 | dump_table = true; | ||
| 739 | break; | ||
| 740 | case 'n': | ||
| 741 | for (d = distributions; d->name != NULL; d++) { | ||
| 742 | if (strncmp(optarg, d->name, strlen(optarg)) == 0) | ||
| 743 | break; | ||
| 744 | } | ||
| 745 | if (d->name == NULL) | ||
| 746 | errx(1, "unknown test %s", optarg); | ||
| 747 | name = optarg; | ||
| 748 | break; | ||
| 749 | case 't': | ||
| 750 | timing = true; | ||
| 751 | break; | ||
| 752 | case 'v': | ||
| 753 | verbose = true; | ||
| 754 | break; | ||
| 755 | default: | ||
| 756 | usage(); | ||
| 757 | break; | ||
| 758 | } | ||
| 759 | } | ||
| 760 | argc -= optind; | ||
| 761 | argv += optind; | ||
| 762 | |||
| 763 | if (argc == 0) { | ||
| 764 | argv = nums; | ||
| 765 | argc = sizeof(nums) / sizeof(nums[0]); | ||
| 766 | } | ||
| 767 | |||
| 768 | while (argc > 0) { | ||
| 769 | n = atoi(*argv); | ||
| 770 | if (run_tests(n, name) != 0) | ||
| 771 | ret = 1; | ||
| 772 | argc--; | ||
| 773 | argv++; | ||
| 774 | } | ||
| 775 | |||
| 776 | return ret; | ||
| 777 | } | ||
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile deleted file mode 100644 index 5b9a080209..0000000000 --- a/src/regress/lib/libc/regex/Makefile +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.11 2017/04/16 16:01:05 kettenis Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= re | ||
| 5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c | ||
| 6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex | ||
| 7 | CLEANFILES += t_exhaust | ||
| 8 | |||
| 9 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE | ||
| 10 | CFLAGS+= -D'DEF_WEAK(x)=asm("")' | ||
| 11 | |||
| 12 | TESTS= ${.CURDIR}/tests | ||
| 13 | |||
| 14 | REGRESS_TARGETS = do-reg do-reg-long do-reg-backref | ||
| 15 | # cannot run with large limits | ||
| 16 | #REGRESS_TARGETS += do-t_exhaust | ||
| 17 | |||
| 18 | do-reg: ${PROG} | ||
| 19 | ./re < ${TESTS} | ||
| 20 | do-reg-long: ${PROG} | ||
| 21 | ./re -el < ${TESTS} | ||
| 22 | do-reg-backref: ${PROG} | ||
| 23 | ./re -er < ${TESTS} | ||
| 24 | #do-t_exhaust: t_exhaust | ||
| 25 | # ./t_exhaust | ||
| 26 | |||
| 27 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c deleted file mode 100644 index 11129e7249..0000000000 --- a/src/regress/lib/libc/regex/debug.c +++ /dev/null | |||
| @@ -1,245 +0,0 @@ | |||
| 1 | /* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <regex.h> | ||
| 11 | |||
| 12 | #include "utils.h" | ||
| 13 | #include "regex2.h" | ||
| 14 | #include "debug.ih" | ||
| 15 | |||
| 16 | /* | ||
| 17 | - regprint - print a regexp for debugging | ||
| 18 | == void regprint(regex_t *r, FILE *d); | ||
| 19 | */ | ||
| 20 | void | ||
| 21 | regprint(r, d) | ||
| 22 | regex_t *r; | ||
| 23 | FILE *d; | ||
| 24 | { | ||
| 25 | register struct re_guts *g = r->re_g; | ||
| 26 | register int i; | ||
| 27 | register int c; | ||
| 28 | register int last; | ||
| 29 | int nincat[NC]; | ||
| 30 | |||
| 31 | fprintf(d, "%ld states, %d categories", (long)g->nstates, | ||
| 32 | g->ncategories); | ||
| 33 | fprintf(d, ", first %ld last %ld", (long)g->firststate, | ||
| 34 | (long)g->laststate); | ||
| 35 | if (g->iflags&USEBOL) | ||
| 36 | fprintf(d, ", USEBOL"); | ||
| 37 | if (g->iflags&USEEOL) | ||
| 38 | fprintf(d, ", USEEOL"); | ||
| 39 | if (g->iflags&BAD) | ||
| 40 | fprintf(d, ", BAD"); | ||
| 41 | if (g->nsub > 0) | ||
| 42 | fprintf(d, ", nsub=%ld", (long)g->nsub); | ||
| 43 | if (g->must != NULL) | ||
| 44 | fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, | ||
| 45 | g->must); | ||
| 46 | if (g->backrefs) | ||
| 47 | fprintf(d, ", backrefs"); | ||
| 48 | if (g->nplus > 0) | ||
| 49 | fprintf(d, ", nplus %ld", (long)g->nplus); | ||
| 50 | fprintf(d, "\n"); | ||
| 51 | s_print(g, d); | ||
| 52 | for (i = 0; i < g->ncategories; i++) { | ||
| 53 | nincat[i] = 0; | ||
| 54 | for (c = CHAR_MIN; c <= CHAR_MAX; c++) | ||
| 55 | if (g->categories[c] == i) | ||
| 56 | nincat[i]++; | ||
| 57 | } | ||
| 58 | fprintf(d, "cc0#%d", nincat[0]); | ||
| 59 | for (i = 1; i < g->ncategories; i++) | ||
| 60 | if (nincat[i] == 1) { | ||
| 61 | for (c = CHAR_MIN; c <= CHAR_MAX; c++) | ||
| 62 | if (g->categories[c] == i) | ||
| 63 | break; | ||
| 64 | fprintf(d, ", %d=%s", i, regchar(c)); | ||
| 65 | } | ||
| 66 | fprintf(d, "\n"); | ||
| 67 | for (i = 1; i < g->ncategories; i++) | ||
| 68 | if (nincat[i] != 1) { | ||
| 69 | fprintf(d, "cc%d\t", i); | ||
| 70 | last = -1; | ||
| 71 | for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ | ||
| 72 | if (c <= CHAR_MAX && g->categories[c] == i) { | ||
| 73 | if (last < 0) { | ||
| 74 | fprintf(d, "%s", regchar(c)); | ||
| 75 | last = c; | ||
| 76 | } | ||
| 77 | } else { | ||
| 78 | if (last >= 0) { | ||
| 79 | if (last != c-1) | ||
| 80 | fprintf(d, "-%s", | ||
| 81 | regchar(c-1)); | ||
| 82 | last = -1; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | fprintf(d, "\n"); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | - s_print - print the strip for debugging | ||
| 91 | == static void s_print(register struct re_guts *g, FILE *d); | ||
| 92 | */ | ||
| 93 | static void | ||
| 94 | s_print(g, d) | ||
| 95 | register struct re_guts *g; | ||
| 96 | FILE *d; | ||
| 97 | { | ||
| 98 | register sop *s; | ||
| 99 | register cset *cs; | ||
| 100 | register int i; | ||
| 101 | register int done = 0; | ||
| 102 | register sop opnd; | ||
| 103 | register int col = 0; | ||
| 104 | register int last; | ||
| 105 | register sopno offset = 2; | ||
| 106 | # define GAP() { if (offset % 5 == 0) { \ | ||
| 107 | if (col > 40) { \ | ||
| 108 | fprintf(d, "\n\t"); \ | ||
| 109 | col = 0; \ | ||
| 110 | } else { \ | ||
| 111 | fprintf(d, " "); \ | ||
| 112 | col++; \ | ||
| 113 | } \ | ||
| 114 | } else \ | ||
| 115 | col++; \ | ||
| 116 | offset++; \ | ||
| 117 | } | ||
| 118 | |||
| 119 | if (OP(g->strip[0]) != OEND) | ||
| 120 | fprintf(d, "missing initial OEND!\n"); | ||
| 121 | for (s = &g->strip[1]; !done; s++) { | ||
| 122 | opnd = OPND(*s); | ||
| 123 | switch (OP(*s)) { | ||
| 124 | case OEND: | ||
| 125 | fprintf(d, "\n"); | ||
| 126 | done = 1; | ||
| 127 | break; | ||
| 128 | case OCHAR: | ||
| 129 | if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) | ||
| 130 | fprintf(d, "\\%c", (char)opnd); | ||
| 131 | else | ||
| 132 | fprintf(d, "%s", regchar((char)opnd)); | ||
| 133 | break; | ||
| 134 | case OBOL: | ||
| 135 | fprintf(d, "^"); | ||
| 136 | break; | ||
| 137 | case OEOL: | ||
| 138 | fprintf(d, "$"); | ||
| 139 | break; | ||
| 140 | case OBOW: | ||
| 141 | fprintf(d, "\\{"); | ||
| 142 | break; | ||
| 143 | case OEOW: | ||
| 144 | fprintf(d, "\\}"); | ||
| 145 | break; | ||
| 146 | case OANY: | ||
| 147 | fprintf(d, "."); | ||
| 148 | break; | ||
| 149 | case OANYOF: | ||
| 150 | fprintf(d, "[(%ld)", (long)opnd); | ||
| 151 | cs = &g->sets[opnd]; | ||
| 152 | last = -1; | ||
| 153 | for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ | ||
| 154 | if (CHIN(cs, i) && i < g->csetsize) { | ||
| 155 | if (last < 0) { | ||
| 156 | fprintf(d, "%s", regchar(i)); | ||
| 157 | last = i; | ||
| 158 | } | ||
| 159 | } else { | ||
| 160 | if (last >= 0) { | ||
| 161 | if (last != i-1) | ||
| 162 | fprintf(d, "-%s", | ||
| 163 | regchar(i-1)); | ||
| 164 | last = -1; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | fprintf(d, "]"); | ||
| 168 | break; | ||
| 169 | case OBACK_: | ||
| 170 | fprintf(d, "(\\<%ld>", (long)opnd); | ||
| 171 | break; | ||
| 172 | case O_BACK: | ||
| 173 | fprintf(d, "<%ld>\\)", (long)opnd); | ||
| 174 | break; | ||
| 175 | case OPLUS_: | ||
| 176 | fprintf(d, "(+"); | ||
| 177 | if (OP(*(s+opnd)) != O_PLUS) | ||
| 178 | fprintf(d, "<%ld>", (long)opnd); | ||
| 179 | break; | ||
| 180 | case O_PLUS: | ||
| 181 | if (OP(*(s-opnd)) != OPLUS_) | ||
| 182 | fprintf(d, "<%ld>", (long)opnd); | ||
| 183 | fprintf(d, "+)"); | ||
| 184 | break; | ||
| 185 | case OQUEST_: | ||
| 186 | fprintf(d, "(?"); | ||
| 187 | if (OP(*(s+opnd)) != O_QUEST) | ||
| 188 | fprintf(d, "<%ld>", (long)opnd); | ||
| 189 | break; | ||
| 190 | case O_QUEST: | ||
| 191 | if (OP(*(s-opnd)) != OQUEST_) | ||
| 192 | fprintf(d, "<%ld>", (long)opnd); | ||
| 193 | fprintf(d, "?)"); | ||
| 194 | break; | ||
| 195 | case OLPAREN: | ||
| 196 | fprintf(d, "((<%ld>", (long)opnd); | ||
| 197 | break; | ||
| 198 | case ORPAREN: | ||
| 199 | fprintf(d, "<%ld>))", (long)opnd); | ||
| 200 | break; | ||
| 201 | case OCH_: | ||
| 202 | fprintf(d, "<"); | ||
| 203 | if (OP(*(s+opnd)) != OOR2) | ||
| 204 | fprintf(d, "<%ld>", (long)opnd); | ||
| 205 | break; | ||
| 206 | case OOR1: | ||
| 207 | if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) | ||
| 208 | fprintf(d, "<%ld>", (long)opnd); | ||
| 209 | fprintf(d, "|"); | ||
| 210 | break; | ||
| 211 | case OOR2: | ||
| 212 | fprintf(d, "|"); | ||
| 213 | if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) | ||
| 214 | fprintf(d, "<%ld>", (long)opnd); | ||
| 215 | break; | ||
| 216 | case O_CH: | ||
| 217 | if (OP(*(s-opnd)) != OOR1) | ||
| 218 | fprintf(d, "<%ld>", (long)opnd); | ||
| 219 | fprintf(d, ">"); | ||
| 220 | break; | ||
| 221 | default: | ||
| 222 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | if (!done) | ||
| 226 | GAP(); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | /* | ||
| 231 | - regchar - make a character printable | ||
| 232 | == static char *regchar(int ch); | ||
| 233 | */ | ||
| 234 | static char * /* -> representation */ | ||
| 235 | regchar(ch) | ||
| 236 | int ch; | ||
| 237 | { | ||
| 238 | static char buf[10]; | ||
| 239 | |||
| 240 | if (isprint(ch) || ch == ' ') | ||
| 241 | snprintf(buf, sizeof buf, "%c", ch); | ||
| 242 | else | ||
| 243 | snprintf(buf, sizeof buf, "\\%o", ch); | ||
| 244 | return(buf); | ||
| 245 | } | ||
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih deleted file mode 100644 index 9eb313af23..0000000000 --- a/src/regress/lib/libc/regex/debug.ih +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* ========= begin header generated by ./mkh ========= */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | /* === debug.c === */ | ||
| 10 | void regprint(regex_t *r, FILE *d); | ||
| 11 | static void s_print(register struct re_guts *g, FILE *d); | ||
| 12 | static char *regchar(int ch); | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c deleted file mode 100644 index d6787d88fc..0000000000 --- a/src/regress/lib/libc/regex/main.c +++ /dev/null | |||
| @@ -1,519 +0,0 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.10 2016/07/13 06:17:11 guenther Exp $ */ | ||
| 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <sys/types.h> | ||
| 8 | #include <regex.h> | ||
| 9 | #include <assert.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | #include "main.ih" | ||
| 13 | |||
| 14 | char *progname; | ||
| 15 | int debug = 0; | ||
| 16 | int line = 0; | ||
| 17 | int status = 0; | ||
| 18 | |||
| 19 | int copts = REG_EXTENDED; | ||
| 20 | int eopts = 0; | ||
| 21 | regoff_t startoff = 0; | ||
| 22 | regoff_t endoff = 0; | ||
| 23 | |||
| 24 | |||
| 25 | extern int split(char *, char *[], int, char *); | ||
| 26 | extern void regprint(regex_t *, FILE *); | ||
| 27 | |||
| 28 | /* | ||
| 29 | - main - do the simple case, hand off to regress() for regression | ||
| 30 | */ | ||
| 31 | int | ||
| 32 | main(int argc, char *argv[]) | ||
| 33 | |||
| 34 | { | ||
| 35 | regex_t re; | ||
| 36 | # define NS 10 | ||
| 37 | regmatch_t subs[NS]; | ||
| 38 | char erbuf[100]; | ||
| 39 | int err; | ||
| 40 | size_t len; | ||
| 41 | int c; | ||
| 42 | int errflg = 0; | ||
| 43 | register int i; | ||
| 44 | extern int optind; | ||
| 45 | extern char *optarg; | ||
| 46 | |||
| 47 | progname = argv[0]; | ||
| 48 | |||
| 49 | while ((c = getopt(argc, argv, "c:E:e:S:x")) != -1) | ||
| 50 | switch (c) { | ||
| 51 | case 'c': /* compile options */ | ||
| 52 | copts = options('c', optarg); | ||
| 53 | break; | ||
| 54 | case 'E': /* end offset */ | ||
| 55 | endoff = (regoff_t)atoi(optarg); | ||
| 56 | break; | ||
| 57 | case 'e': /* execute options */ | ||
| 58 | eopts = options('e', optarg); | ||
| 59 | break; | ||
| 60 | case 'S': /* start offset */ | ||
| 61 | startoff = (regoff_t)atoi(optarg); | ||
| 62 | break; | ||
| 63 | case 'x': /* Debugging. */ | ||
| 64 | debug++; | ||
| 65 | break; | ||
| 66 | case '?': | ||
| 67 | default: | ||
| 68 | errflg++; | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | if (errflg) { | ||
| 72 | fprintf(stderr, "usage: %s ", progname); | ||
| 73 | fprintf(stderr, "[-x] [-c copt] [-E endoff] [-e eopt] [-S startoff] [re]\n"); | ||
| 74 | exit(2); | ||
| 75 | } | ||
| 76 | |||
| 77 | if (optind >= argc) { | ||
| 78 | regress(stdin); | ||
| 79 | exit(status); | ||
| 80 | } | ||
| 81 | |||
| 82 | err = regcomp(&re, argv[optind++], copts); | ||
| 83 | if (err) { | ||
| 84 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 85 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
| 86 | eprint(err), len, sizeof(erbuf), erbuf); | ||
| 87 | exit(status); | ||
| 88 | } | ||
| 89 | regprint(&re, stdout); | ||
| 90 | |||
| 91 | if (optind >= argc) { | ||
| 92 | regfree(&re); | ||
| 93 | exit(status); | ||
| 94 | } | ||
| 95 | |||
| 96 | if (eopts®_STARTEND) { | ||
| 97 | subs[0].rm_so = startoff; | ||
| 98 | subs[0].rm_eo = strlen(argv[optind]) - endoff; | ||
| 99 | } | ||
| 100 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | ||
| 101 | if (err) { | ||
| 102 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 103 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
| 104 | eprint(err), len, sizeof(erbuf), erbuf); | ||
| 105 | exit(status); | ||
| 106 | } | ||
| 107 | if (!(copts®_NOSUB)) { | ||
| 108 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); | ||
| 109 | if (subs[0].rm_so != -1) { | ||
| 110 | if (len != 0) | ||
| 111 | printf("match `%.*s'\n", (int)len, | ||
| 112 | argv[optind] + subs[0].rm_so); | ||
| 113 | else | ||
| 114 | printf("match `'@%.1s\n", | ||
| 115 | argv[optind] + subs[0].rm_so); | ||
| 116 | } | ||
| 117 | for (i = 1; i < NS; i++) | ||
| 118 | if (subs[i].rm_so != -1) | ||
| 119 | printf("(%d) `%.*s'\n", i, | ||
| 120 | (int)(subs[i].rm_eo - subs[i].rm_so), | ||
| 121 | argv[optind] + subs[i].rm_so); | ||
| 122 | } | ||
| 123 | exit(status); | ||
| 124 | } | ||
| 125 | |||
| 126 | /* | ||
| 127 | - regress - main loop of regression test | ||
| 128 | == void regress(FILE *in); | ||
| 129 | */ | ||
| 130 | void | ||
| 131 | regress(in) | ||
| 132 | FILE *in; | ||
| 133 | { | ||
| 134 | char inbuf[1000]; | ||
| 135 | # define MAXF 10 | ||
| 136 | char *f[MAXF]; | ||
| 137 | int nf; | ||
| 138 | int i; | ||
| 139 | char erbuf[100]; | ||
| 140 | size_t ne; | ||
| 141 | char *badpat = "invalid regular expression"; | ||
| 142 | # define SHORT 10 | ||
| 143 | char *bpname = "REG_BADPAT"; | ||
| 144 | regex_t re; | ||
| 145 | |||
| 146 | while (fgets(inbuf, sizeof(inbuf), in) != NULL) { | ||
| 147 | line++; | ||
| 148 | if (inbuf[0] == '#' || inbuf[0] == '\n') | ||
| 149 | continue; /* NOTE CONTINUE */ | ||
| 150 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ | ||
| 151 | if (debug) | ||
| 152 | fprintf(stdout, "%d:\n", line); | ||
| 153 | nf = split(inbuf, f, MAXF, "\t\t"); | ||
| 154 | if (nf < 3) { | ||
| 155 | fprintf(stderr, "bad input, line %d\n", line); | ||
| 156 | exit(1); | ||
| 157 | } | ||
| 158 | for (i = 0; i < nf; i++) | ||
| 159 | if (strcmp(f[i], "\"\"") == 0) | ||
| 160 | f[i] = ""; | ||
| 161 | if (nf <= 3) | ||
| 162 | f[3] = NULL; | ||
| 163 | if (nf <= 4) | ||
| 164 | f[4] = NULL; | ||
| 165 | try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); | ||
| 166 | if (opt('&', f[1])) /* try with either type of RE */ | ||
| 167 | try(f[0], f[1], f[2], f[3], f[4], | ||
| 168 | options('c', f[1]) &~ REG_EXTENDED); | ||
| 169 | } | ||
| 170 | |||
| 171 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
| 172 | if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { | ||
| 173 | fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", | ||
| 174 | erbuf, badpat); | ||
| 175 | status = 1; | ||
| 176 | } | ||
| 177 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); | ||
| 178 | if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || | ||
| 179 | ne != strlen(badpat)+1) { | ||
| 180 | fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", | ||
| 181 | erbuf, SHORT-1, badpat); | ||
| 182 | status = 1; | ||
| 183 | } | ||
| 184 | ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
| 185 | if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { | ||
| 186 | fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", | ||
| 187 | erbuf, bpname); | ||
| 188 | status = 1; | ||
| 189 | } | ||
| 190 | re.re_endp = bpname; | ||
| 191 | ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); | ||
| 192 | if (atoi(erbuf) != (int)REG_BADPAT) { | ||
| 193 | fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", | ||
| 194 | erbuf, (long)REG_BADPAT); | ||
| 195 | status = 1; | ||
| 196 | } else if (ne != strlen(erbuf)+1) { | ||
| 197 | fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", | ||
| 198 | erbuf, (long)REG_BADPAT); | ||
| 199 | status = 1; | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | /* | ||
| 204 | - try - try it, and report on problems | ||
| 205 | == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
| 206 | */ | ||
| 207 | void | ||
| 208 | try(f0, f1, f2, f3, f4, opts) | ||
| 209 | char *f0; | ||
| 210 | char *f1; | ||
| 211 | char *f2; | ||
| 212 | char *f3; | ||
| 213 | char *f4; | ||
| 214 | int opts; /* may not match f1 */ | ||
| 215 | { | ||
| 216 | regex_t re; | ||
| 217 | # define NSUBS 10 | ||
| 218 | regmatch_t subs[NSUBS]; | ||
| 219 | # define NSHOULD 15 | ||
| 220 | char *should[NSHOULD]; | ||
| 221 | int nshould; | ||
| 222 | char erbuf[100]; | ||
| 223 | int err; | ||
| 224 | int len; | ||
| 225 | char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; | ||
| 226 | register int i; | ||
| 227 | char *grump; | ||
| 228 | char f0copy[1000]; | ||
| 229 | char f2copy[1000]; | ||
| 230 | |||
| 231 | strlcpy(f0copy, f0, sizeof f0copy); | ||
| 232 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | ||
| 233 | fixstr(f0copy); | ||
| 234 | err = regcomp(&re, f0copy, opts); | ||
| 235 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | ||
| 236 | /* unexpected error or wrong error */ | ||
| 237 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 238 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", | ||
| 239 | line, type, eprint(err), len, | ||
| 240 | sizeof(erbuf), erbuf); | ||
| 241 | status = 1; | ||
| 242 | } else if (err == 0 && opt('C', f1)) { | ||
| 243 | /* unexpected success */ | ||
| 244 | fprintf(stderr, "%d: %s should have given REG_%s\n", | ||
| 245 | line, type, f2); | ||
| 246 | status = 1; | ||
| 247 | err = 1; /* so we won't try regexec */ | ||
| 248 | } | ||
| 249 | |||
| 250 | if (err != 0) { | ||
| 251 | regfree(&re); | ||
| 252 | return; | ||
| 253 | } | ||
| 254 | |||
| 255 | strlcpy(f2copy, f2, sizeof f2copy); | ||
| 256 | fixstr(f2copy); | ||
| 257 | |||
| 258 | if (options('e', f1)®_STARTEND) { | ||
| 259 | if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) | ||
| 260 | fprintf(stderr, "%d: bad STARTEND syntax\n", line); | ||
| 261 | subs[0].rm_so = strchr(f2, '(') - f2 + 1; | ||
| 262 | subs[0].rm_eo = strchr(f2, ')') - f2; | ||
| 263 | /* the preceding character is relevant with REG_NOTBOL */ | ||
| 264 | f2copy[subs[0].rm_so - 1] = subs[0].rm_so > 1 ? | ||
| 265 | f2copy[subs[0].rm_so - 2] : 'X'; | ||
| 266 | } | ||
| 267 | err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); | ||
| 268 | |||
| 269 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | ||
| 270 | /* unexpected error or wrong error */ | ||
| 271 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
| 272 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", | ||
| 273 | line, type, eprint(err), len, | ||
| 274 | sizeof(erbuf), erbuf); | ||
| 275 | status = 1; | ||
| 276 | } else if (err != 0) { | ||
| 277 | /* nothing more to check */ | ||
| 278 | } else if (f3 == NULL) { | ||
| 279 | /* unexpected success */ | ||
| 280 | fprintf(stderr, "%d: %s exec should have failed\n", | ||
| 281 | line, type); | ||
| 282 | status = 1; | ||
| 283 | err = 1; /* just on principle */ | ||
| 284 | } else if (opts®_NOSUB) { | ||
| 285 | /* nothing more to check */ | ||
| 286 | } else if ((grump = check(f2, subs[0], f3)) != NULL) { | ||
| 287 | fprintf(stderr, "%d: %s %s\n", line, type, grump); | ||
| 288 | status = 1; | ||
| 289 | err = 1; | ||
| 290 | } | ||
| 291 | |||
| 292 | if (err != 0 || f4 == NULL) { | ||
| 293 | regfree(&re); | ||
| 294 | return; | ||
| 295 | } | ||
| 296 | |||
| 297 | for (i = 1; i < NSHOULD; i++) | ||
| 298 | should[i] = NULL; | ||
| 299 | nshould = split(f4, should+1, NSHOULD-1, ","); | ||
| 300 | if (nshould == 0) { | ||
| 301 | nshould = 1; | ||
| 302 | should[1] = ""; | ||
| 303 | } | ||
| 304 | for (i = 1; i < NSUBS; i++) { | ||
| 305 | grump = check(f2, subs[i], should[i]); | ||
| 306 | if (grump != NULL) { | ||
| 307 | fprintf(stderr, "%d: %s $%d %s\n", line, | ||
| 308 | type, i, grump); | ||
| 309 | status = 1; | ||
| 310 | err = 1; | ||
| 311 | } | ||
| 312 | } | ||
| 313 | |||
| 314 | regfree(&re); | ||
| 315 | } | ||
| 316 | |||
| 317 | /* | ||
| 318 | - options - pick options out of a regression-test string | ||
| 319 | == int options(int type, char *s); | ||
| 320 | */ | ||
| 321 | int | ||
| 322 | options(type, s) | ||
| 323 | int type; /* 'c' compile, 'e' exec */ | ||
| 324 | char *s; | ||
| 325 | { | ||
| 326 | register char *p; | ||
| 327 | register int o = (type == 'c') ? copts : eopts; | ||
| 328 | register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; | ||
| 329 | |||
| 330 | for (p = s; *p != '\0'; p++) | ||
| 331 | if (strchr(legal, *p) != NULL) | ||
| 332 | switch (*p) { | ||
| 333 | case 'b': | ||
| 334 | o &= ~REG_EXTENDED; | ||
| 335 | break; | ||
| 336 | case 'i': | ||
| 337 | o |= REG_ICASE; | ||
| 338 | break; | ||
| 339 | case 's': | ||
| 340 | o |= REG_NOSUB; | ||
| 341 | break; | ||
| 342 | case 'n': | ||
| 343 | o |= REG_NEWLINE; | ||
| 344 | break; | ||
| 345 | case 'm': | ||
| 346 | o &= ~REG_EXTENDED; | ||
| 347 | o |= REG_NOSPEC; | ||
| 348 | break; | ||
| 349 | case 'p': | ||
| 350 | o |= REG_PEND; | ||
| 351 | break; | ||
| 352 | case '^': | ||
| 353 | o |= REG_NOTBOL; | ||
| 354 | break; | ||
| 355 | case '$': | ||
| 356 | o |= REG_NOTEOL; | ||
| 357 | break; | ||
| 358 | case '#': | ||
| 359 | o |= REG_STARTEND; | ||
| 360 | break; | ||
| 361 | case 't': /* trace */ | ||
| 362 | o |= REG_TRACE; | ||
| 363 | break; | ||
| 364 | case 'l': /* force long representation */ | ||
| 365 | o |= REG_LARGE; | ||
| 366 | break; | ||
| 367 | case 'r': /* force backref use */ | ||
| 368 | o |= REG_BACKR; | ||
| 369 | break; | ||
| 370 | } | ||
| 371 | return(o); | ||
| 372 | } | ||
| 373 | |||
| 374 | /* | ||
| 375 | - opt - is a particular option in a regression string? | ||
| 376 | == int opt(int c, char *s); | ||
| 377 | */ | ||
| 378 | int /* predicate */ | ||
| 379 | opt(c, s) | ||
| 380 | int c; | ||
| 381 | char *s; | ||
| 382 | { | ||
| 383 | return(strchr(s, c) != NULL); | ||
| 384 | } | ||
| 385 | |||
| 386 | /* | ||
| 387 | - fixstr - transform magic characters in strings | ||
| 388 | == void fixstr(register char *p); | ||
| 389 | */ | ||
| 390 | void | ||
| 391 | fixstr(p) | ||
| 392 | register char *p; | ||
| 393 | { | ||
| 394 | if (p == NULL) | ||
| 395 | return; | ||
| 396 | |||
| 397 | for (; *p != '\0'; p++) | ||
| 398 | if (*p == 'N') | ||
| 399 | *p = '\n'; | ||
| 400 | else if (*p == 'T') | ||
| 401 | *p = '\t'; | ||
| 402 | else if (*p == 'S') | ||
| 403 | *p = ' '; | ||
| 404 | else if (*p == 'Z') | ||
| 405 | *p = '\0'; | ||
| 406 | } | ||
| 407 | |||
| 408 | /* | ||
| 409 | - check - check a substring match | ||
| 410 | == char *check(char *str, regmatch_t sub, char *should); | ||
| 411 | */ | ||
| 412 | char * /* NULL or complaint */ | ||
| 413 | check(str, sub, should) | ||
| 414 | char *str; | ||
| 415 | regmatch_t sub; | ||
| 416 | char *should; | ||
| 417 | { | ||
| 418 | register int len; | ||
| 419 | register int shlen; | ||
| 420 | register char *p; | ||
| 421 | static char grump[500]; | ||
| 422 | register char *at = NULL; | ||
| 423 | |||
| 424 | if (should != NULL && strcmp(should, "-") == 0) | ||
| 425 | should = NULL; | ||
| 426 | if (should != NULL && should[0] == '@') { | ||
| 427 | at = should + 1; | ||
| 428 | should = ""; | ||
| 429 | } | ||
| 430 | |||
| 431 | /* check rm_so and rm_eo for consistency */ | ||
| 432 | if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || | ||
| 433 | (sub.rm_so != -1 && sub.rm_eo == -1) || | ||
| 434 | (sub.rm_so != -1 && sub.rm_so < 0) || | ||
| 435 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | ||
| 436 | snprintf(grump, sizeof grump, | ||
| 437 | "start %ld end %ld", (long)sub.rm_so, | ||
| 438 | (long)sub.rm_eo); | ||
| 439 | return(grump); | ||
| 440 | } | ||
| 441 | |||
| 442 | /* check for no match */ | ||
| 443 | if (sub.rm_so == -1 && should == NULL) | ||
| 444 | return(NULL); | ||
| 445 | if (sub.rm_so == -1) | ||
| 446 | return("did not match"); | ||
| 447 | |||
| 448 | /* check for in range */ | ||
| 449 | if (sub.rm_eo > strlen(str)) { | ||
| 450 | snprintf(grump, sizeof grump, | ||
| 451 | "start %ld end %ld, past end of string", | ||
| 452 | (long)sub.rm_so, (long)sub.rm_eo); | ||
| 453 | return(grump); | ||
| 454 | } | ||
| 455 | |||
| 456 | len = (int)(sub.rm_eo - sub.rm_so); | ||
| 457 | p = str + sub.rm_so; | ||
| 458 | |||
| 459 | /* check for not supposed to match */ | ||
| 460 | if (should == NULL) { | ||
| 461 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); | ||
| 462 | return(grump); | ||
| 463 | } | ||
| 464 | |||
| 465 | /* check for wrong match */ | ||
| 466 | shlen = (int)strlen(should); | ||
| 467 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | ||
| 468 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); | ||
| 469 | return(grump); | ||
| 470 | } | ||
| 471 | if (shlen > 0) | ||
| 472 | return(NULL); | ||
| 473 | |||
| 474 | /* check null match in right place */ | ||
| 475 | if (at == NULL) | ||
| 476 | return(NULL); | ||
| 477 | shlen = strlen(at); | ||
| 478 | if (shlen == 0) | ||
| 479 | shlen = 1; /* force check for end-of-string */ | ||
| 480 | if (strncmp(p, at, shlen) != 0) { | ||
| 481 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); | ||
| 482 | return(grump); | ||
| 483 | } | ||
| 484 | return(NULL); | ||
| 485 | } | ||
| 486 | |||
| 487 | /* | ||
| 488 | - eprint - convert error number to name | ||
| 489 | == static char *eprint(int err); | ||
| 490 | */ | ||
| 491 | static char * | ||
| 492 | eprint(err) | ||
| 493 | int err; | ||
| 494 | { | ||
| 495 | static char epbuf[100]; | ||
| 496 | size_t len; | ||
| 497 | |||
| 498 | len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); | ||
| 499 | assert(len <= sizeof(epbuf)); | ||
| 500 | return(epbuf); | ||
| 501 | } | ||
| 502 | |||
| 503 | /* | ||
| 504 | - efind - convert error name to number | ||
| 505 | == static int efind(char *name); | ||
| 506 | */ | ||
| 507 | static int | ||
| 508 | efind(name) | ||
| 509 | char *name; | ||
| 510 | { | ||
| 511 | static char efbuf[100]; | ||
| 512 | regex_t re; | ||
| 513 | |||
| 514 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); | ||
| 515 | assert(strlen(efbuf) < sizeof(efbuf)); | ||
| 516 | re.re_endp = efbuf; | ||
| 517 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | ||
| 518 | return(atoi(efbuf)); | ||
| 519 | } | ||
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih deleted file mode 100644 index 0860e26333..0000000000 --- a/src/regress/lib/libc/regex/main.ih +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* ========= begin header generated by ./mkh ========= */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | /* === main.c === */ | ||
| 10 | void regress(FILE *in); | ||
| 11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
| 12 | int options(int type, char *s); | ||
| 13 | int opt(int c, char *s); | ||
| 14 | void fixstr(register char *p); | ||
| 15 | char *check(char *str, regmatch_t sub, char *should); | ||
| 16 | static char *eprint(int err); | ||
| 17 | static int efind(char *name); | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c deleted file mode 100644 index fcd81a3503..0000000000 --- a/src/regress/lib/libc/regex/split.c +++ /dev/null | |||
| @@ -1,317 +0,0 @@ | |||
| 1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
| 2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
| 8 | |||
| 9 | /* | ||
| 10 | - split - divide a string into fields, like awk split() | ||
| 11 | = int split(char *string, char *fields[], int nfields, char *sep); | ||
| 12 | */ | ||
| 13 | int /* number of fields, including overflow */ | ||
| 14 | split(char *string, char *fields[], int nfields, char *sep) | ||
| 15 | { | ||
| 16 | register char *p = string; | ||
| 17 | register char c; /* latest character */ | ||
| 18 | register char sepc = sep[0]; | ||
| 19 | register char sepc2; | ||
| 20 | register int fn; | ||
| 21 | register char **fp = fields; | ||
| 22 | register char *sepp; | ||
| 23 | register int trimtrail; | ||
| 24 | |||
| 25 | /* white space */ | ||
| 26 | if (sepc == '\0') { | ||
| 27 | while ((c = *p++) == ' ' || c == '\t') | ||
| 28 | continue; | ||
| 29 | p--; | ||
| 30 | trimtrail = 1; | ||
| 31 | sep = " \t"; /* note, code below knows this is 2 long */ | ||
| 32 | sepc = ' '; | ||
| 33 | } else | ||
| 34 | trimtrail = 0; | ||
| 35 | sepc2 = sep[1]; /* now we can safely pick this up */ | ||
| 36 | |||
| 37 | /* catch empties */ | ||
| 38 | if (*p == '\0') | ||
| 39 | return(0); | ||
| 40 | |||
| 41 | /* single separator */ | ||
| 42 | if (sepc2 == '\0') { | ||
| 43 | fn = nfields; | ||
| 44 | for (;;) { | ||
| 45 | *fp++ = p; | ||
| 46 | fn--; | ||
| 47 | if (fn == 0) | ||
| 48 | break; | ||
| 49 | while ((c = *p++) != sepc) | ||
| 50 | if (c == '\0') | ||
| 51 | return(nfields - fn); | ||
| 52 | *(p-1) = '\0'; | ||
| 53 | } | ||
| 54 | /* we have overflowed the fields vector -- just count them */ | ||
| 55 | fn = nfields; | ||
| 56 | for (;;) { | ||
| 57 | while ((c = *p++) != sepc) | ||
| 58 | if (c == '\0') | ||
| 59 | return(fn); | ||
| 60 | fn++; | ||
| 61 | } | ||
| 62 | /* not reached */ | ||
| 63 | } | ||
| 64 | |||
| 65 | /* two separators */ | ||
| 66 | if (sep[2] == '\0') { | ||
| 67 | fn = nfields; | ||
| 68 | for (;;) { | ||
| 69 | *fp++ = p; | ||
| 70 | fn--; | ||
| 71 | while ((c = *p++) != sepc && c != sepc2) | ||
| 72 | if (c == '\0') { | ||
| 73 | if (trimtrail && **(fp-1) == '\0') | ||
| 74 | fn++; | ||
| 75 | return(nfields - fn); | ||
| 76 | } | ||
| 77 | if (fn == 0) | ||
| 78 | break; | ||
| 79 | *(p-1) = '\0'; | ||
| 80 | while ((c = *p++) == sepc || c == sepc2) | ||
| 81 | continue; | ||
| 82 | p--; | ||
| 83 | } | ||
| 84 | /* we have overflowed the fields vector -- just count them */ | ||
| 85 | fn = nfields; | ||
| 86 | while (c != '\0') { | ||
| 87 | while ((c = *p++) == sepc || c == sepc2) | ||
| 88 | continue; | ||
| 89 | p--; | ||
| 90 | fn++; | ||
| 91 | while ((c = *p++) != '\0' && c != sepc && c != sepc2) | ||
| 92 | continue; | ||
| 93 | } | ||
| 94 | /* might have to trim trailing white space */ | ||
| 95 | if (trimtrail) { | ||
| 96 | p--; | ||
| 97 | while ((c = *--p) == sepc || c == sepc2) | ||
| 98 | continue; | ||
| 99 | p++; | ||
| 100 | if (*p != '\0') { | ||
| 101 | if (fn == nfields+1) | ||
| 102 | *p = '\0'; | ||
| 103 | fn--; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | return(fn); | ||
| 107 | } | ||
| 108 | |||
| 109 | /* n separators */ | ||
| 110 | fn = 0; | ||
| 111 | for (;;) { | ||
| 112 | if (fn < nfields) | ||
| 113 | *fp++ = p; | ||
| 114 | fn++; | ||
| 115 | for (;;) { | ||
| 116 | c = *p++; | ||
| 117 | if (c == '\0') | ||
| 118 | return(fn); | ||
| 119 | sepp = sep; | ||
| 120 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
| 121 | continue; | ||
| 122 | if (sepc != '\0') /* it was a separator */ | ||
| 123 | break; | ||
| 124 | } | ||
| 125 | if (fn < nfields) | ||
| 126 | *(p-1) = '\0'; | ||
| 127 | for (;;) { | ||
| 128 | c = *p++; | ||
| 129 | sepp = sep; | ||
| 130 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
| 131 | continue; | ||
| 132 | if (sepc == '\0') /* it wasn't a separator */ | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | p--; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* not reached */ | ||
| 139 | } | ||
| 140 | |||
| 141 | #ifdef TEST_SPLIT | ||
| 142 | |||
| 143 | |||
| 144 | /* | ||
| 145 | * test program | ||
| 146 | * pgm runs regression | ||
| 147 | * pgm sep splits stdin lines by sep | ||
| 148 | * pgm str sep splits str by sep | ||
| 149 | * pgm str sep n splits str by sep n times | ||
| 150 | */ | ||
| 151 | int | ||
| 152 | main(argc, argv) | ||
| 153 | int argc; | ||
| 154 | char *argv[]; | ||
| 155 | { | ||
| 156 | char buf[512]; | ||
| 157 | register int n; | ||
| 158 | # define MNF 10 | ||
| 159 | char *fields[MNF]; | ||
| 160 | |||
| 161 | if (argc > 4) | ||
| 162 | for (n = atoi(argv[3]); n > 0; n--) { | ||
| 163 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
| 164 | } | ||
| 165 | else if (argc > 3) | ||
| 166 | for (n = atoi(argv[3]); n > 0; n--) { | ||
| 167 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
| 168 | (void) split(buf, fields, MNF, argv[2]); | ||
| 169 | } | ||
| 170 | else if (argc > 2) | ||
| 171 | dosplit(argv[1], argv[2]); | ||
| 172 | else if (argc > 1) | ||
| 173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | ||
| 174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ | ||
| 175 | dosplit(buf, argv[1]); | ||
| 176 | } | ||
| 177 | else | ||
| 178 | regress(); | ||
| 179 | |||
| 180 | exit(0); | ||
| 181 | } | ||
| 182 | |||
| 183 | dosplit(string, seps) | ||
| 184 | char *string; | ||
| 185 | char *seps; | ||
| 186 | { | ||
| 187 | # define NF 5 | ||
| 188 | char *fields[NF]; | ||
| 189 | register int nf; | ||
| 190 | |||
| 191 | nf = split(string, fields, NF, seps); | ||
| 192 | print(nf, NF, fields); | ||
| 193 | } | ||
| 194 | |||
| 195 | print(nf, nfp, fields) | ||
| 196 | int nf; | ||
| 197 | int nfp; | ||
| 198 | char *fields[]; | ||
| 199 | { | ||
| 200 | register int fn; | ||
| 201 | register int bound; | ||
| 202 | |||
| 203 | bound = (nf > nfp) ? nfp : nf; | ||
| 204 | printf("%d:\t", nf); | ||
| 205 | for (fn = 0; fn < bound; fn++) | ||
| 206 | printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); | ||
| 207 | } | ||
| 208 | |||
| 209 | #define RNF 5 /* some table entries know this */ | ||
| 210 | struct { | ||
| 211 | char *str; | ||
| 212 | char *seps; | ||
| 213 | int nf; | ||
| 214 | char *fi[RNF]; | ||
| 215 | } tests[] = { | ||
| 216 | "", " ", 0, { "" }, | ||
| 217 | " ", " ", 2, { "", "" }, | ||
| 218 | "x", " ", 1, { "x" }, | ||
| 219 | "xy", " ", 1, { "xy" }, | ||
| 220 | "x y", " ", 2, { "x", "y" }, | ||
| 221 | "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, | ||
| 222 | " a bcd", " ", 4, { "", "", "a", "bcd" }, | ||
| 223 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
| 224 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
| 225 | |||
| 226 | "", " _", 0, { "" }, | ||
| 227 | " ", " _", 2, { "", "" }, | ||
| 228 | "x", " _", 1, { "x" }, | ||
| 229 | "x y", " _", 2, { "x", "y" }, | ||
| 230 | "ab _ cd", " _", 2, { "ab", "cd" }, | ||
| 231 | " a_b c ", " _", 5, { "", "a", "b", "c", "" }, | ||
| 232 | "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, | ||
| 233 | " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, | ||
| 234 | |||
| 235 | "", " _~", 0, { "" }, | ||
| 236 | " ", " _~", 2, { "", "" }, | ||
| 237 | "x", " _~", 1, { "x" }, | ||
| 238 | "x y", " _~", 2, { "x", "y" }, | ||
| 239 | "ab _~ cd", " _~", 2, { "ab", "cd" }, | ||
| 240 | " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, | ||
| 241 | "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, | ||
| 242 | "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, | ||
| 243 | |||
| 244 | "", " _~-", 0, { "" }, | ||
| 245 | " ", " _~-", 2, { "", "" }, | ||
| 246 | "x", " _~-", 1, { "x" }, | ||
| 247 | "x y", " _~-", 2, { "x", "y" }, | ||
| 248 | "ab _~- cd", " _~-", 2, { "ab", "cd" }, | ||
| 249 | " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, | ||
| 250 | "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, | ||
| 251 | "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, | ||
| 252 | |||
| 253 | "", " ", 0, { "" }, | ||
| 254 | " ", " ", 2, { "", "" }, | ||
| 255 | "x", " ", 1, { "x" }, | ||
| 256 | "xy", " ", 1, { "xy" }, | ||
| 257 | "x y", " ", 2, { "x", "y" }, | ||
| 258 | "abc def g ", " ", 4, { "abc", "def", "g", "" }, | ||
| 259 | " a bcd", " ", 3, { "", "a", "bcd" }, | ||
| 260 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
| 261 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
| 262 | |||
| 263 | "", "", 0, { "" }, | ||
| 264 | " ", "", 0, { "" }, | ||
| 265 | "x", "", 1, { "x" }, | ||
| 266 | "xy", "", 1, { "xy" }, | ||
| 267 | "x y", "", 2, { "x", "y" }, | ||
| 268 | "abc def g ", "", 3, { "abc", "def", "g" }, | ||
| 269 | "\t a bcd", "", 2, { "a", "bcd" }, | ||
| 270 | " a \tb\t c ", "", 3, { "a", "b", "c" }, | ||
| 271 | "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, | ||
| 272 | "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, | ||
| 273 | " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, | ||
| 274 | |||
| 275 | NULL, NULL, 0, { NULL }, | ||
| 276 | }; | ||
| 277 | |||
| 278 | regress() | ||
| 279 | { | ||
| 280 | char buf[512]; | ||
| 281 | register int n; | ||
| 282 | char *fields[RNF+1]; | ||
| 283 | register int nf; | ||
| 284 | register int i; | ||
| 285 | register int printit; | ||
| 286 | register char *f; | ||
| 287 | |||
| 288 | for (n = 0; tests[n].str != NULL; n++) { | ||
| 289 | (void) strlcpy(buf, tests[n].str, sizeof buf); | ||
| 290 | fields[RNF] = NULL; | ||
| 291 | nf = split(buf, fields, RNF, tests[n].seps); | ||
| 292 | printit = 0; | ||
| 293 | if (nf != tests[n].nf) { | ||
| 294 | printf("split `%s' by `%s' gave %d fields, not %d\n", | ||
| 295 | tests[n].str, tests[n].seps, nf, tests[n].nf); | ||
| 296 | printit = 1; | ||
| 297 | } else if (fields[RNF] != NULL) { | ||
| 298 | printf("split() went beyond array end\n"); | ||
| 299 | printit = 1; | ||
| 300 | } else { | ||
| 301 | for (i = 0; i < nf && i < RNF; i++) { | ||
| 302 | f = fields[i]; | ||
| 303 | if (f == NULL) | ||
| 304 | f = "(NULL)"; | ||
| 305 | if (strcmp(f, tests[n].fi[i]) != 0) { | ||
| 306 | printf("split `%s' by `%s', field %d is `%s', not `%s'\n", | ||
| 307 | tests[n].str, tests[n].seps, | ||
| 308 | i, fields[i], tests[n].fi[i]); | ||
| 309 | printit = 1; | ||
| 310 | } | ||
| 311 | } | ||
| 312 | } | ||
| 313 | if (printit) | ||
| 314 | print(nf, RNF, fields); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | #endif | ||
diff --git a/src/regress/lib/libc/regex/t_exhaust.c b/src/regress/lib/libc/regex/t_exhaust.c deleted file mode 100644 index 58ac8007f2..0000000000 --- a/src/regress/lib/libc/regex/t_exhaust.c +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | /* $OpenBSD: t_exhaust.c,v 1.3 2012/12/05 23:20:07 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 9 | * by Christos Zoulas. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * 3. All advertising materials mentioning features or use of this software | ||
| 20 | * must display the following acknowledgement: | ||
| 21 | * This product includes software developed by the NetBSD | ||
| 22 | * Foundation, Inc. and its contributors. | ||
| 23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
| 24 | * contributors may be used to endorse or promote products derived | ||
| 25 | * from this software without specific prior written permission. | ||
| 26 | * | ||
| 27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 37 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <stdio.h> | ||
| 41 | #include <regex.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <err.h> | ||
| 45 | //#include <atf-c.h> | ||
| 46 | |||
| 47 | |||
| 48 | static char * | ||
| 49 | mkstr(const char *str, size_t len) | ||
| 50 | { | ||
| 51 | size_t i, slen = strlen(str); | ||
| 52 | char *p = malloc(slen * len + 1); | ||
| 53 | if (p == NULL) | ||
| 54 | err(1, "malloc"); | ||
| 55 | for (i = 0; i < len; i++) | ||
| 56 | strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen)); | ||
| 57 | return p; | ||
| 58 | } | ||
| 59 | |||
| 60 | static char * | ||
| 61 | concat(const char *d, const char *s) | ||
| 62 | { | ||
| 63 | size_t dlen = strlen(d); | ||
| 64 | size_t slen = strlen(s); | ||
| 65 | char *p = malloc(dlen + slen + 1); | ||
| 66 | strlcpy(p, d, dlen + slen + 1); | ||
| 67 | strlcat(p, s, dlen + slen + 1); | ||
| 68 | return p; | ||
| 69 | } | ||
| 70 | |||
| 71 | static char * | ||
| 72 | p0(size_t len) | ||
| 73 | { | ||
| 74 | char *d, *s1, *s2; | ||
| 75 | s1 = mkstr("\\(", len); | ||
| 76 | s2 = concat(s1, ")"); | ||
| 77 | free(s1); | ||
| 78 | d = concat("(", s2); | ||
| 79 | free(s2); | ||
| 80 | return d; | ||
| 81 | } | ||
| 82 | |||
| 83 | static char * | ||
| 84 | p1(size_t len) | ||
| 85 | { | ||
| 86 | char *d, *s1, *s2, *s3; | ||
| 87 | s1 = mkstr("\\(", 60); | ||
| 88 | s2 = mkstr("(.*)", len); | ||
| 89 | s3 = concat(s1, s2); | ||
| 90 | free(s2); | ||
| 91 | free(s1); | ||
| 92 | s1 = concat(s3, ")"); | ||
| 93 | free(s3); | ||
| 94 | d = concat("(", s1); | ||
| 95 | free(s1); | ||
| 96 | return d; | ||
| 97 | } | ||
| 98 | |||
| 99 | static char * | ||
| 100 | ps(const char *m, const char *s, size_t len) | ||
| 101 | { | ||
| 102 | char *d, *s1, *s2, *s3; | ||
| 103 | s1 = mkstr(m, len); | ||
| 104 | s2 = mkstr(s, len); | ||
| 105 | s3 = concat(s1, s2); | ||
| 106 | free(s2); | ||
| 107 | free(s1); | ||
| 108 | d = concat("(.?)", s3); | ||
| 109 | free(s3); | ||
| 110 | return d; | ||
| 111 | } | ||
| 112 | |||
| 113 | static char * | ||
| 114 | p2(size_t len) | ||
| 115 | { | ||
| 116 | return ps("((.*){0,255}", ")", len); | ||
| 117 | } | ||
| 118 | |||
| 119 | static char * | ||
| 120 | p3(size_t len) | ||
| 121 | { | ||
| 122 | return ps("(.\\{0,}", ")", len); | ||
| 123 | } | ||
| 124 | |||
| 125 | static char * | ||
| 126 | p4(size_t len) | ||
| 127 | { | ||
| 128 | return ps("((.*){1,255}", ")", len); | ||
| 129 | } | ||
| 130 | |||
| 131 | static char * | ||
| 132 | p5(size_t len) | ||
| 133 | { | ||
| 134 | return ps("(", "){1,100}", len); | ||
| 135 | } | ||
| 136 | |||
| 137 | static char * | ||
| 138 | p6(size_t len) | ||
| 139 | { | ||
| 140 | char *d, *s1, *s2; | ||
| 141 | s1 = mkstr("(?:(.*)|", len); | ||
| 142 | s2 = concat(s1, "(.*)"); | ||
| 143 | free(s1); | ||
| 144 | s1 = mkstr(")", len); | ||
| 145 | d = concat(s2, s1); | ||
| 146 | free(s1); | ||
| 147 | free(s2); | ||
| 148 | return d; | ||
| 149 | } | ||
| 150 | |||
| 151 | static char *(*patterns[])(size_t) = { | ||
| 152 | p0, | ||
| 153 | p1, | ||
| 154 | p2, | ||
| 155 | p3, | ||
| 156 | p4, | ||
| 157 | p5, | ||
| 158 | p6, | ||
| 159 | }; | ||
| 160 | |||
| 161 | |||
| 162 | main() | ||
| 163 | { | ||
| 164 | regex_t re; | ||
| 165 | int e, ret = 0; | ||
| 166 | size_t i; | ||
| 167 | |||
| 168 | for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { | ||
| 169 | char *d = (*patterns[i])(9999); | ||
| 170 | e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); | ||
| 171 | free(d); | ||
| 172 | if (e) { | ||
| 173 | if (e != REG_ESPACE) { | ||
| 174 | printf("regcomp returned %d for pattern %zu", e, i); | ||
| 175 | ret = 1; | ||
| 176 | } | ||
| 177 | continue; | ||
| 178 | } | ||
| 179 | (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); | ||
| 180 | regfree(&re); | ||
| 181 | } | ||
| 182 | return ret; | ||
| 183 | } | ||
| 184 | |||
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests deleted file mode 100644 index ee019f0a04..0000000000 --- a/src/regress/lib/libc/regex/tests +++ /dev/null | |||
| @@ -1,594 +0,0 @@ | |||
| 1 | # $OpenBSD: tests,v 1.8 2016/05/26 14:23:55 schwarze Exp $ | ||
| 2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | ||
| 3 | |||
| 4 | # regular expression test set | ||
| 5 | # Lines are at least three fields, separated by one or more tabs. "" stands | ||
| 6 | # for an empty field. First field is an RE. Second field is flags. If | ||
| 7 | # C flag given, regcomp() is expected to fail, and the third field is the | ||
| 8 | # error name (minus the leading REG_). | ||
| 9 | # | ||
| 10 | # Otherwise it is expected to succeed, and the third field is the string to | ||
| 11 | # try matching it against. If there is no fourth field, the match is | ||
| 12 | # expected to fail. If there is a fourth field, it is the substring that | ||
| 13 | # the RE is expected to match. If there is a fifth field, it is a comma- | ||
| 14 | # separated list of what the subexpressions should match, with - indicating | ||
| 15 | # no match for that one. In both the fourth and fifth fields, a (sub)field | ||
| 16 | # starting with @ indicates that the (sub)expression is expected to match | ||
| 17 | # a null string followed by the stuff after the @; this provides a way to | ||
| 18 | # test where null strings match. The character `N' in REs and strings | ||
| 19 | # is newline, `S' is space, `T' is tab, `Z' is NUL. | ||
| 20 | # | ||
| 21 | # The full list of flags: | ||
| 22 | # - placeholder, does nothing | ||
| 23 | # b RE is a BRE, not an ERE | ||
| 24 | # & try it as both an ERE and a BRE | ||
| 25 | # C regcomp() error expected, third field is error name | ||
| 26 | # i REG_ICASE | ||
| 27 | # m ("mundane") REG_NOSPEC | ||
| 28 | # s REG_NOSUB (not really testable) | ||
| 29 | # n REG_NEWLINE | ||
| 30 | # ^ REG_NOTBOL | ||
| 31 | # $ REG_NOTEOL | ||
| 32 | # # REG_STARTEND (see below) | ||
| 33 | # p REG_PEND | ||
| 34 | # | ||
| 35 | # For REG_STARTEND, the start/end offsets are those of the substring | ||
| 36 | # enclosed in (). | ||
| 37 | |||
| 38 | # basics | ||
| 39 | a & a a | ||
| 40 | abc & abc abc | ||
| 41 | abc|de - abc abc | ||
| 42 | a|b|c - abc a | ||
| 43 | |||
| 44 | # parentheses and perversions thereof | ||
| 45 | a(b)c - abc abc | ||
| 46 | a\(b\)c b abc abc | ||
| 47 | a( C EPAREN | ||
| 48 | a( b a( a( | ||
| 49 | a\( - a( a( | ||
| 50 | a\( bC EPAREN | ||
| 51 | a\(b bC EPAREN | ||
| 52 | a(b C EPAREN | ||
| 53 | a(b b a(b a(b | ||
| 54 | # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly) | ||
| 55 | a) - a) a) | ||
| 56 | ) - ) ) | ||
| 57 | # end gagging (in a just world, those *should* give EPAREN) | ||
| 58 | a) b a) a) | ||
| 59 | a\) bC EPAREN | ||
| 60 | \) bC EPAREN | ||
| 61 | a()b - ab ab | ||
| 62 | a\(\)b b ab ab | ||
| 63 | |||
| 64 | # anchoring and REG_NEWLINE | ||
| 65 | ^abc$ & abc abc | ||
| 66 | ^b & abc | ||
| 67 | a^b - a^b | ||
| 68 | a^b b a^b a^b | ||
| 69 | a$b - a$b | ||
| 70 | a$b b a$b a$b | ||
| 71 | ^ & abc @abc | ||
| 72 | $ & abc @ | ||
| 73 | ^$ & "" @ | ||
| 74 | $^ - "" @ | ||
| 75 | \($\)\(^\) b "" @ | ||
| 76 | # stop retching, those are legitimate (although disgusting) | ||
| 77 | ^^ - "" @ | ||
| 78 | $$ - "" @ | ||
| 79 | b$ & abNc | ||
| 80 | b$ &n abNc b | ||
| 81 | ^b & aNbNc | ||
| 82 | b$ & aNbNc | ||
| 83 | ^a &n aNb a | ||
| 84 | ^b &n abc | ||
| 85 | ^b$ &n aNbNc b | ||
| 86 | ^$ &n aNNb @Nb | ||
| 87 | ^$ n abc | ||
| 88 | ^$ n abcN @ | ||
| 89 | $^ n aNNb @Nb | ||
| 90 | \($\)\(^\) bn aNNb @Nb | ||
| 91 | ^^ n^ aNNb @Nb | ||
| 92 | $$ n aNNb @NN | ||
| 93 | ^a &^ a | ||
| 94 | a$ &$ a | ||
| 95 | ^b &^ abc | ||
| 96 | ^b &^ aNb | ||
| 97 | ^a &^n aNb | ||
| 98 | ^b &^n abc | ||
| 99 | ^b &^n aNb b | ||
| 100 | a$ &$n bNa | ||
| 101 | b$ &$n bNa b | ||
| 102 | a*(^b$)c* - b b | ||
| 103 | a*\(^b$\)c* b b b | ||
| 104 | |||
| 105 | # certain syntax errors and non-errors | ||
| 106 | | C EMPTY | ||
| 107 | | b | | | ||
| 108 | * C BADRPT | ||
| 109 | * b * * | ||
| 110 | + C BADRPT | ||
| 111 | ? C BADRPT | ||
| 112 | "" &C EMPTY | ||
| 113 | () - abc @abc | ||
| 114 | \(\) b abc @abc | ||
| 115 | a||b C EMPTY | ||
| 116 | |ab C EMPTY | ||
| 117 | ab| C EMPTY | ||
| 118 | (|a)b C EMPTY | ||
| 119 | (a|)b C EMPTY | ||
| 120 | (*a) C BADRPT | ||
| 121 | (+a) C BADRPT | ||
| 122 | (?a) C BADRPT | ||
| 123 | ({1}a) C BADRPT | ||
| 124 | \(\{1\}a\) bC BADRPT | ||
| 125 | (a|*b) C BADRPT | ||
| 126 | (a|+b) C BADRPT | ||
| 127 | (a|?b) C BADRPT | ||
| 128 | (a|{1}b) C BADRPT | ||
| 129 | ^* C BADRPT | ||
| 130 | ^* b * * | ||
| 131 | ^+ C BADRPT | ||
| 132 | ^? C BADRPT | ||
| 133 | ^{1} C BADRPT | ||
| 134 | ^\{1\} bC BADRPT | ||
| 135 | |||
| 136 | # metacharacters, backslashes | ||
| 137 | a.c & abc abc | ||
| 138 | a[bc]d & abd abd | ||
| 139 | a\*c & a*c a*c | ||
| 140 | a\\b & a\b a\b | ||
| 141 | a\\\*b & a\*b a\*b | ||
| 142 | a\bc & abc abc | ||
| 143 | a\ &C EESCAPE | ||
| 144 | a\\bc & a\bc a\bc | ||
| 145 | \{ bC BADRPT | ||
| 146 | a\[b & a[b a[b | ||
| 147 | a[b &C EBRACK | ||
| 148 | # trailing $ is a peculiar special case for the BRE code | ||
| 149 | a$ & a a | ||
| 150 | a$ & a$ | ||
| 151 | a\$ & a | ||
| 152 | a\$ & a$ a$ | ||
| 153 | a\\$ & a | ||
| 154 | a\\$ & a$ | ||
| 155 | a\\$ & a\$ | ||
| 156 | a\\$ & a\ a\ | ||
| 157 | |||
| 158 | # back references, ugh | ||
| 159 | a\(b\)\2c bC ESUBREG | ||
| 160 | a\(b\1\)c bC ESUBREG | ||
| 161 | a\(b*\)c\1d b abbcbbd abbcbbd bb | ||
| 162 | a\(b*\)c\1d b abbcbd | ||
| 163 | a\(b*\)c\1d b abbcbbbd | ||
| 164 | ^\(.\)\1 b abc | ||
| 165 | a\([bc]\)\1d b abcdabbd abbd b | ||
| 166 | a\(\([bc]\)\2\)*d b abbccd abbccd | ||
| 167 | a\(\([bc]\)\2\)*d b abbcbd | ||
| 168 | # actually, this next one probably ought to fail, but the spec is unclear | ||
| 169 | a\(\(b\)*\2\)*d b abbbd abbbd | ||
| 170 | # here is a case that no NFA implementation does right | ||
| 171 | \(ab*\)[ab]*\1 b ababaaa ababaaa a | ||
| 172 | # check out normal matching in the presence of back refs | ||
| 173 | \(a\)\1bcd b aabcd aabcd | ||
| 174 | \(a\)\1bc*d b aabcd aabcd | ||
| 175 | \(a\)\1bc*d b aabd aabd | ||
| 176 | \(a\)\1bc*d b aabcccd aabcccd | ||
| 177 | \(a\)\1bc*[ce]d b aabcccd aabcccd | ||
| 178 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | ||
| 179 | \(b*\)\(a*\1\)* b ab a | ||
| 180 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
| 181 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
| 182 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
| 183 | \(.*\)\1 b "" "" | ||
| 184 | \(.*\)\1 b a "" | ||
| 185 | \(.*\)\1 b aa aa | ||
| 186 | \(.*\)\1 b aaa aa | ||
| 187 | \(.*\)\1 b aaaa aaaa | ||
| 188 | \([^_]*\)\1 b "" "" | ||
| 189 | \([^_]*\)\1 b a "" | ||
| 190 | \([^_]*\)\1 b aa aa | ||
| 191 | \([^_]*\)\1 b aaa aa | ||
| 192 | \([^_]*\)\1 b aaaa aaaa | ||
| 193 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
| 194 | foo\(.*\)bar\1 b foobar foobar "" | ||
| 195 | \(\(.\)b\)*\1 b aba | ||
| 196 | \(\(.\)b\)*\1 b abba | ||
| 197 | \(\(.\)b\)*\1 b abbba | ||
| 198 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
| 199 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
| 200 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
| 201 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
| 202 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
| 203 | # these used to segfault, buffer underflow in engine.c, backref() | ||
| 204 | \(^a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
| 205 | \([[:<:]]a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
| 206 | |||
| 207 | # ordinary repetitions | ||
| 208 | ab*c & abc abc | ||
| 209 | ab+c - abc abc | ||
| 210 | ab?c - abc abc | ||
| 211 | a\(*\)b b a*b a*b | ||
| 212 | a\(**\)b b ab ab | ||
| 213 | a\(***\)b bC BADRPT | ||
| 214 | *a b *a *a | ||
| 215 | **a b a a | ||
| 216 | ***a bC BADRPT | ||
| 217 | |||
| 218 | # the dreaded bounded repetitions | ||
| 219 | { & { { | ||
| 220 | {abc & {abc {abc | ||
| 221 | {1 C BADRPT | ||
| 222 | {1} C BADRPT | ||
| 223 | a{b & a{b a{b | ||
| 224 | a{1}b - ab ab | ||
| 225 | a\{1\}b b ab ab | ||
| 226 | a{1,}b - ab ab | ||
| 227 | a\{1,\}b b ab ab | ||
| 228 | a{1,2}b - aab aab | ||
| 229 | a\{1,2\}b b aab aab | ||
| 230 | a{1 C EBRACE | ||
| 231 | a\{1 bC EBRACE | ||
| 232 | a{1a C EBRACE | ||
| 233 | a\{1a bC EBRACE | ||
| 234 | a{1a} C BADBR | ||
| 235 | a\{1a\} bC BADBR | ||
| 236 | a{,2} - a{,2} a{,2} | ||
| 237 | a\{,2\} bC BADBR | ||
| 238 | a{,} - a{,} a{,} | ||
| 239 | a\{,\} bC BADBR | ||
| 240 | a{1,x} C BADBR | ||
| 241 | a\{1,x\} bC BADBR | ||
| 242 | a{1,x C EBRACE | ||
| 243 | a\{1,x bC EBRACE | ||
| 244 | a{300} C BADBR | ||
| 245 | a\{300\} bC BADBR | ||
| 246 | a{1,0} C BADBR | ||
| 247 | a\{1,0\} bC BADBR | ||
| 248 | ab{0,0}c - abcac ac | ||
| 249 | ab\{0,0\}c b abcac ac | ||
| 250 | ab{0,1}c - abcac abc | ||
| 251 | ab\{0,1\}c b abcac abc | ||
| 252 | ab{0,3}c - abbcac abbc | ||
| 253 | ab\{0,3\}c b abbcac abbc | ||
| 254 | ab{1,1}c - acabc abc | ||
| 255 | ab\{1,1\}c b acabc abc | ||
| 256 | ab{1,3}c - acabc abc | ||
| 257 | ab\{1,3\}c b acabc abc | ||
| 258 | ab{2,2}c - abcabbc abbc | ||
| 259 | ab\{2,2\}c b abcabbc abbc | ||
| 260 | ab{2,4}c - abcabbc abbc | ||
| 261 | ab\{2,4\}c b abcabbc abbc | ||
| 262 | ((a{1,10}){1,10}){1,10} - a a a,a | ||
| 263 | |||
| 264 | # multiple repetitions | ||
| 265 | a** &C BADRPT | ||
| 266 | a++ C BADRPT | ||
| 267 | a?? C BADRPT | ||
| 268 | a*+ C BADRPT | ||
| 269 | a*? C BADRPT | ||
| 270 | a+* C BADRPT | ||
| 271 | a+? C BADRPT | ||
| 272 | a?* C BADRPT | ||
| 273 | a?+ C BADRPT | ||
| 274 | a{1}{1} C BADRPT | ||
| 275 | a*{1} C BADRPT | ||
| 276 | a+{1} C BADRPT | ||
| 277 | a?{1} C BADRPT | ||
| 278 | a{1}* C BADRPT | ||
| 279 | a{1}+ C BADRPT | ||
| 280 | a{1}? C BADRPT | ||
| 281 | a*{b} - a{b} a{b} | ||
| 282 | a\{1\}\{1\} bC BADRPT | ||
| 283 | a*\{1\} bC BADRPT | ||
| 284 | a\{1\}* bC BADRPT | ||
| 285 | |||
| 286 | # brackets, and numerous perversions thereof | ||
| 287 | a[b]c & abc abc | ||
| 288 | a[ab]c & abc abc | ||
| 289 | a[^ab]c & adc adc | ||
| 290 | a[]b]c & a]c a]c | ||
| 291 | a[[b]c & a[c a[c | ||
| 292 | a[-b]c & a-c a-c | ||
| 293 | a[^]b]c & adc adc | ||
| 294 | a[^-b]c & adc adc | ||
| 295 | a[b-]c & a-c a-c | ||
| 296 | a[b &C EBRACK | ||
| 297 | a[] &C EBRACK | ||
| 298 | a[1-3]c & a2c a2c | ||
| 299 | a[3-1]c &C ERANGE | ||
| 300 | a[1-3-5]c &C ERANGE | ||
| 301 | a[[.-.]--]c & a-c a-c | ||
| 302 | a[1- &C ERANGE | ||
| 303 | a[[. &C EBRACK | ||
| 304 | a[[.x &C EBRACK | ||
| 305 | a[[.x. &C EBRACK | ||
| 306 | a[[.x.] &C EBRACK | ||
| 307 | a[[.x.]] & ax ax | ||
| 308 | a[[.x,.]] &C ECOLLATE | ||
| 309 | a[[.one.]]b & a1b a1b | ||
| 310 | a[[.notdef.]]b &C ECOLLATE | ||
| 311 | a[[.].]]b & a]b a]b | ||
| 312 | a[[:alpha:]]c & abc abc | ||
| 313 | a[[:notdef:]]c &C ECTYPE | ||
| 314 | a[[: &C EBRACK | ||
| 315 | a[[:alpha &C EBRACK | ||
| 316 | a[[:alpha:] &C EBRACK | ||
| 317 | a[[:alpha,:] &C ECTYPE | ||
| 318 | a[[:]:]]b &C ECTYPE | ||
| 319 | a[[:-:]]b &C ECTYPE | ||
| 320 | a[[:alph:]] &C ECTYPE | ||
| 321 | a[[:alphabet:]] &C ECTYPE | ||
| 322 | [[:alnum:]]+ - -%@a0X- a0X | ||
| 323 | [[:alpha:]]+ - -%@aX0- aX | ||
| 324 | [[:blank:]]+ - aSSTb SST | ||
| 325 | [[:cntrl:]]+ - aNTb NT | ||
| 326 | [[:digit:]]+ - a019b 019 | ||
| 327 | [[:graph:]]+ - Sa%bS a%b | ||
| 328 | [[:lower:]]+ - AabC ab | ||
| 329 | [[:print:]]+ - NaSbN aSb | ||
| 330 | [[:punct:]]+ - S%-&T %-& | ||
| 331 | [[:space:]]+ - aSNTb SNT | ||
| 332 | [[:upper:]]+ - aBCd BC | ||
| 333 | [[:xdigit:]]+ - p0f3Cq 0f3C | ||
| 334 | a[[=b=]]c & abc abc | ||
| 335 | a[[= &C EBRACK | ||
| 336 | a[[=b &C EBRACK | ||
| 337 | a[[=b= &C EBRACK | ||
| 338 | a[[=b=] &C EBRACK | ||
| 339 | a[[=b,=]] &C ECOLLATE | ||
| 340 | a[[=one=]]b & a1b a1b | ||
| 341 | |||
| 342 | # complexities | ||
| 343 | a(((b)))c - abc abc | ||
| 344 | a(b|(c))d - abd abd | ||
| 345 | a(b*|c)d - abbd abbd | ||
| 346 | # just gotta have one DFA-buster, of course | ||
| 347 | a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
| 348 | # and an inline expansion in case somebody gets tricky | ||
| 349 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
| 350 | # and in case somebody just slips in an NFA... | ||
| 351 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights | ||
| 352 | # fish for anomalies as the number of states passes 32 | ||
| 353 | 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789 | ||
| 354 | 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890 | ||
| 355 | 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901 | ||
| 356 | 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012 | ||
| 357 | 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123 | ||
| 358 | # and one really big one, beyond any plausible word width | ||
| 359 | 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890 | ||
| 360 | # fish for problems as brackets go past 8 | ||
| 361 | [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm | ||
| 362 | [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo | ||
| 363 | [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq | ||
| 364 | [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq | ||
| 365 | |||
| 366 | # subtleties of matching | ||
| 367 | abc & xabcy abc | ||
| 368 | a\(b\)?c\1d b acd | ||
| 369 | aBc i Abc Abc | ||
| 370 | a[Bc]*d i abBCcd abBCcd | ||
| 371 | 0[[:upper:]]1 &i 0a1 0a1 | ||
| 372 | 0[[:lower:]]1 &i 0A1 0A1 | ||
| 373 | a[^b]c &i abc | ||
| 374 | a[^b]c &i aBc | ||
| 375 | a[^b]c &i adc adc | ||
| 376 | [a]b[c] - abc abc | ||
| 377 | [a]b[a] - aba aba | ||
| 378 | [abc]b[abc] - abc abc | ||
| 379 | [abc]b[abd] - abd abd | ||
| 380 | a(b?c)+d - accd accd | ||
| 381 | (wee|week)(knights|night) - weeknights weeknights | ||
| 382 | (we|wee|week|frob)(knights|night|day) - weeknights weeknights | ||
| 383 | a[bc]d - xyzaaabcaababdacd abd | ||
| 384 | a[ab]c - aaabc abc | ||
| 385 | abc s abc abc | ||
| 386 | a* & b @b | ||
| 387 | |||
| 388 | # Let's have some fun -- try to match a C comment. | ||
| 389 | # first the obvious, which looks okay at first glance... | ||
| 390 | /\*.*\*/ - /*x*/ /*x*/ | ||
| 391 | # but... | ||
| 392 | /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/ | ||
| 393 | # okay, we must not match */ inside; try to do that... | ||
| 394 | /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/ | ||
| 395 | /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/ | ||
| 396 | # but... | ||
| 397 | /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/ | ||
| 398 | # and a still fancier version, which does it right (I think)... | ||
| 399 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/ | ||
| 400 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/ | ||
| 401 | /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/ | ||
| 402 | /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/ | ||
| 403 | /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/ | ||
| 404 | /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/ | ||
| 405 | |||
| 406 | # subexpressions | ||
| 407 | a(b)(c)d - abcd abcd b,c | ||
| 408 | a(((b)))c - abc abc b,b,b | ||
| 409 | a(b|(c))d - abd abd b,- | ||
| 410 | a(b*|c|e)d - abbd abbd bb | ||
| 411 | a(b*|c|e)d - acd acd c | ||
| 412 | a(b*|c|e)d - ad ad @d | ||
| 413 | a(b?)c - abc abc b | ||
| 414 | a(b?)c - ac ac @c | ||
| 415 | a(b+)c - abc abc b | ||
| 416 | a(b+)c - abbbc abbbc bbb | ||
| 417 | a(b*)c - ac ac @c | ||
| 418 | (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de | ||
| 419 | # the regression tester only asks for 9 subexpressions | ||
| 420 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j | ||
| 421 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k | ||
| 422 | a([bc]?)c - abc abc b | ||
| 423 | a([bc]?)c - ac ac @c | ||
| 424 | a([bc]+)c - abc abc b | ||
| 425 | a([bc]+)c - abcc abcc bc | ||
| 426 | a([bc]+)bc - abcbc abcbc bc | ||
| 427 | a(bb+|b)b - abb abb b | ||
| 428 | a(bbb+|bb+|b)b - abb abb b | ||
| 429 | a(bbb+|bb+|b)b - abbb abbb bb | ||
| 430 | a(bbb+|bb+|b)bb - abbb abbb b | ||
| 431 | (.*).* - abcdef abcdef abcdef | ||
| 432 | (a*)* - bc @b @b | ||
| 433 | |||
| 434 | # do we get the right subexpression when it is used more than once? | ||
| 435 | a(b|c)*d - ad ad - | ||
| 436 | a(b|c)*d - abcd abcd c | ||
| 437 | a(b|c)+d - abd abd b | ||
| 438 | a(b|c)+d - abcd abcd c | ||
| 439 | a(b|c?)+d - ad ad @d | ||
| 440 | a(b|c?)+d - abcd abcd @d | ||
| 441 | a(b|c){0,0}d - ad ad - | ||
| 442 | a(b|c){0,1}d - ad ad - | ||
| 443 | a(b|c){0,1}d - abd abd b | ||
| 444 | a(b|c){0,2}d - ad ad - | ||
| 445 | a(b|c){0,2}d - abcd abcd c | ||
| 446 | a(b|c){0,}d - ad ad - | ||
| 447 | a(b|c){0,}d - abcd abcd c | ||
| 448 | a(b|c){1,1}d - abd abd b | ||
| 449 | a(b|c){1,1}d - acd acd c | ||
| 450 | a(b|c){1,2}d - abd abd b | ||
| 451 | a(b|c){1,2}d - abcd abcd c | ||
| 452 | a(b|c){1,}d - abd abd b | ||
| 453 | a(b|c){1,}d - abcd abcd c | ||
| 454 | a(b|c){2,2}d - acbd acbd b | ||
| 455 | a(b|c){2,2}d - abcd abcd c | ||
| 456 | a(b|c){2,4}d - abcd abcd c | ||
| 457 | a(b|c){2,4}d - abcbd abcbd b | ||
| 458 | a(b|c){2,4}d - abcbcd abcbcd c | ||
| 459 | a(b|c){2,}d - abcd abcd c | ||
| 460 | a(b|c){2,}d - abcbd abcbd b | ||
| 461 | a(b+|((c)*))+d - abd abd @d,@d,- | ||
| 462 | a(b+|((c)*))+d - abcd abcd @d,@d,- | ||
| 463 | |||
| 464 | # check out the STARTEND option | ||
| 465 | ^[abc] &# a(b)c b | ||
| 466 | ^[abc] &# a(xb)c | ||
| 467 | ^[abc] &# aN(b)c b | ||
| 468 | ^[abc] &n# a(b)c b | ||
| 469 | ^[abc] &n# a(xb)c | ||
| 470 | ^[abc] &n# aN(b)c b | ||
| 471 | ^[abc] &^# a(b)c | ||
| 472 | ^[abc] &^# a(xb)c | ||
| 473 | ^[abc] &^# aN(b)c | ||
| 474 | ^[abc] &n^# a(b)c | ||
| 475 | ^[abc] &n^# a(xb)c | ||
| 476 | ^[abc] &n^# aN(b)c b | ||
| 477 | [abc] &# a(d)c | ||
| 478 | [abc] &# a(bc)d b | ||
| 479 | [abc] &# a(dc)d c | ||
| 480 | . &# a()c | ||
| 481 | b.*c &# b(bc)c bc | ||
| 482 | b.* &# b(bc)c bc | ||
| 483 | .*c &# b(bc)c bc | ||
| 484 | |||
| 485 | # plain strings, with the NOSPEC flag | ||
| 486 | abc m abc abc | ||
| 487 | abc m xabcy abc | ||
| 488 | abc m xyz | ||
| 489 | a*b m aba*b a*b | ||
| 490 | a*b m ab | ||
| 491 | "" mC EMPTY | ||
| 492 | |||
| 493 | # cases involving NULs | ||
| 494 | aZb & a a | ||
| 495 | aZb &p a | ||
| 496 | aZb &p# (aZb) aZb | ||
| 497 | aZ*b &p# (ab) ab | ||
| 498 | a.b &# (aZb) aZb | ||
| 499 | a.* &# (aZb)c aZb | ||
| 500 | |||
| 501 | # word boundaries (ick) | ||
| 502 | [[:<:]]a & a a | ||
| 503 | \<a & a a | ||
| 504 | [[:<:]]a & ba | ||
| 505 | \<a & ba | ||
| 506 | [[:<:]]a & -a a | ||
| 507 | \<a & -a a | ||
| 508 | [[:<:]]a & Na a | ||
| 509 | \<a & Na a | ||
| 510 | [[:<:]]a &n a a | ||
| 511 | \<a &n a a | ||
| 512 | [[:<:]]a &n ba | ||
| 513 | \<a &n ba | ||
| 514 | [[:<:]]a &n -a a | ||
| 515 | \<a &n -a a | ||
| 516 | [[:<:]]a &n Na a | ||
| 517 | \<a &n Na a | ||
| 518 | [[:<:]]a &^ a | ||
| 519 | \<a &^ a | ||
| 520 | [[:<:]]a &^ ba | ||
| 521 | \<a &^ ba | ||
| 522 | [[:<:]]a &^ -a a | ||
| 523 | \<a &^ -a a | ||
| 524 | [[:<:]]a &^ Na a | ||
| 525 | \<a &^ Na a | ||
| 526 | [[:<:]]a &n^ a | ||
| 527 | \<a &n^ a | ||
| 528 | [[:<:]]a &n^ ba | ||
| 529 | \<a &n^ ba | ||
| 530 | [[:<:]]a &n^ -a a | ||
| 531 | \<a &n^ -a a | ||
| 532 | [[:<:]]a &n^ Na a | ||
| 533 | \<a &n^ Na a | ||
| 534 | [[:<:]]b &# a(b)c b | ||
| 535 | \<b &# a(b)c b | ||
| 536 | [[:<:]]b &# a(xb)c | ||
| 537 | \<b &# a(xb)c | ||
| 538 | [[:<:]]b &# -(b)c b | ||
| 539 | \<b &# -(b)c b | ||
| 540 | [[:<:]]b &# aN(b)c b | ||
| 541 | \<b &# aN(b)c b | ||
| 542 | [[:<:]]b &n# a(b)c b | ||
| 543 | \<b &n# a(b)c b | ||
| 544 | [[:<:]]b &n# a(xb)c | ||
| 545 | \<b &n# a(xb)c | ||
| 546 | [[:<:]]b &n# -(b)c b | ||
| 547 | \<b &n# -(b)c b | ||
| 548 | [[:<:]]b &n# aN(b)c b | ||
| 549 | \<b &n# aN(b)c b | ||
| 550 | [[:<:]]b &^# a(b)c | ||
| 551 | \<b &^# a(b)c | ||
| 552 | [[:<:]]b &^# a(xb)c | ||
| 553 | \<b &^# a(xb)c | ||
| 554 | [[:<:]]b &^# -(b)c b | ||
| 555 | \<b &^# -(b)c b | ||
| 556 | [[:<:]]b &^# aN(b)c b | ||
| 557 | \<b &^# aN(b)c b | ||
| 558 | [[:<:]]b &n^# a(b)c | ||
| 559 | \<b &n^# a(b)c | ||
| 560 | [[:<:]]b &n^# a(xb)c | ||
| 561 | \<b &n^# a(xb)c | ||
| 562 | [[:<:]]b &n^# -(b)c b | ||
| 563 | \<b &n^# -(b)c b | ||
| 564 | [[:<:]]b &n^# aN(b)c b | ||
| 565 | \<b &n^# aN(b)c b | ||
| 566 | a[[:>:]] & a a | ||
| 567 | a\> & a a | ||
| 568 | a[[:>:]] & ab | ||
| 569 | a\> & ab | ||
| 570 | a[[:>:]] & a- a | ||
| 571 | a\> & a- a | ||
| 572 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc | ||
| 573 | \<a.c\> & axcd-dayc-dazce-abc abc | ||
| 574 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc | ||
| 575 | \<a.c\> & axcd-dayc-dazce-abc-q abc | ||
| 576 | [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc | ||
| 577 | \<a.c\> & axc-dayc-dazce-abc axc | ||
| 578 | [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc | ||
| 579 | \<b.c\> & a_bxc-byc_d-bzc-q bzc | ||
| 580 | [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
| 581 | \<.x..\> & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
| 582 | [[:<:]]a_b[[:>:]] & x_a_b | ||
| 583 | \<a_b\> & x_a_b | ||
| 584 | |||
| 585 | # past problems, and suspected problems | ||
| 586 | (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1 | ||
| 587 | abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop | ||
| 588 | abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv | ||
| 589 | (ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11 | ||
| 590 | CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | ||
| 591 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | ||
| 592 | a?b - ab ab | ||
| 593 | -\{0,1\}[0-9]*$ b -5 -5 | ||
| 594 | |||
diff --git a/src/regress/lib/libc/setjmp-fpu/Makefile b/src/regress/lib/libc/setjmp-fpu/Makefile deleted file mode 100644 index 33d0f7e88a..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/Makefile +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2013/12/29 05:46:43 martynas Exp $ | ||
| 2 | |||
| 3 | PROG= setjmp-fpu | ||
| 4 | SRCS= _setjmp.c main.c setjmp.c sigsetjmp.c | ||
| 5 | |||
| 6 | LDADD= -lm | ||
| 7 | |||
| 8 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/_setjmp.c b/src/regress/lib/libc/setjmp-fpu/_setjmp.c deleted file mode 100644 index a2195a5ff8..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/_setjmp.c +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | /* $OpenBSD: _setjmp.c,v 1.3 2015/11/08 18:10:14 miod Exp $ */ | ||
| 2 | #define SETJMP(env, savemask) _setjmp(env) | ||
| 3 | #define LONGJMP(env, val) _longjmp(env, val) | ||
| 4 | #define TEST_SETJMP test__setjmp | ||
| 5 | #define JMP_BUF jmp_buf | ||
| 6 | |||
| 7 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/main.c b/src/regress/lib/libc/setjmp-fpu/main.c deleted file mode 100644 index 5050fee855..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/main.c +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.2 2015/01/20 04:41:01 krw Exp $ */ | ||
| 2 | int test__setjmp(void); | ||
| 3 | int test_setjmp(void); | ||
| 4 | int test_sigsetjmp(void); | ||
| 5 | |||
| 6 | int | ||
| 7 | main(int argc, char *argv[]) | ||
| 8 | { | ||
| 9 | return (test__setjmp() | ||
| 10 | | test_setjmp() | ||
| 11 | | test_sigsetjmp()); | ||
| 12 | } | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c deleted file mode 100644 index 694061dcbb..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | #include <fenv.h> | ||
| 2 | #include <setjmp.h> | ||
| 3 | |||
| 4 | int | ||
| 5 | TEST_SETJMP(int argc, char *argv[]) | ||
| 6 | { | ||
| 7 | JMP_BUF env; | ||
| 8 | int rv; | ||
| 9 | |||
| 10 | /* Set up the FPU control word register. */ | ||
| 11 | fesetround(FE_UPWARD); | ||
| 12 | fedisableexcept(FE_ALL_EXCEPT); | ||
| 13 | feenableexcept(FE_DIVBYZERO); | ||
| 14 | |||
| 15 | rv = SETJMP(env, 0); | ||
| 16 | |||
| 17 | if (rv == 0) { | ||
| 18 | fexcept_t flag = FE_OVERFLOW; | ||
| 19 | |||
| 20 | /* Mess with the FPU control word. */ | ||
| 21 | fesetround(FE_DOWNWARD); | ||
| 22 | fedisableexcept(FE_DIVBYZERO); | ||
| 23 | |||
| 24 | /* Set the FPU exception flags. */ | ||
| 25 | fesetexceptflag(&flag, FE_ALL_EXCEPT); | ||
| 26 | |||
| 27 | LONGJMP(env, 1); | ||
| 28 | } else if (rv == 1) { | ||
| 29 | fexcept_t flag = 0; | ||
| 30 | |||
| 31 | /* Verify that the FPU control word is preserved. */ | ||
| 32 | if (fegetround() != FE_UPWARD | ||
| 33 | || fegetexcept() != FE_DIVBYZERO) | ||
| 34 | return (1); | ||
| 35 | |||
| 36 | /* Verify that the FPU exception flags weren't clobbered. */ | ||
| 37 | fegetexceptflag(&flag, FE_ALL_EXCEPT); | ||
| 38 | if (flag != FE_OVERFLOW) | ||
| 39 | return (1); | ||
| 40 | |||
| 41 | return (0); | ||
| 42 | } | ||
| 43 | |||
| 44 | /* This is not supposed to happen. */ | ||
| 45 | return (1); | ||
| 46 | } | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp.c b/src/regress/lib/libc/setjmp-fpu/setjmp.c deleted file mode 100644 index 48d72056d0..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/setjmp.c +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | /* $OpenBSD: setjmp.c,v 1.3 2015/11/08 18:10:14 miod Exp $ */ | ||
| 2 | #define SETJMP(env, savemask) setjmp(env) | ||
| 3 | #define LONGJMP(env, val) longjmp(env, val) | ||
| 4 | #define TEST_SETJMP test_setjmp | ||
| 5 | #define JMP_BUF jmp_buf | ||
| 6 | |||
| 7 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c b/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c deleted file mode 100644 index 158fd83296..0000000000 --- a/src/regress/lib/libc/setjmp-fpu/sigsetjmp.c +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | /* $OpenBSD: sigsetjmp.c,v 1.3 2015/11/08 18:10:14 miod Exp $ */ | ||
| 2 | #define SETJMP(env, savemask) sigsetjmp(env, savemask) | ||
| 3 | #define LONGJMP(env, val) siglongjmp(env, val) | ||
| 4 | #define TEST_SETJMP test_sigsetjmp | ||
| 5 | #define JMP_BUF sigjmp_buf | ||
| 6 | |||
| 7 | #include "setjmp-fpu.c" | ||
diff --git a/src/regress/lib/libc/setjmp-signal/Makefile b/src/regress/lib/libc/setjmp-signal/Makefile deleted file mode 100644 index a9649a8abe..0000000000 --- a/src/regress/lib/libc/setjmp-signal/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2002/07/31 05:18:24 art Exp $ | ||
| 2 | |||
| 3 | PROG= setjmp-signal | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c deleted file mode 100644 index b50f6b27c5..0000000000 --- a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | /* $OpenBSD: setjmp-signal.c,v 1.4 2017/07/27 12:31:09 bluhm Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <setjmp.h> | ||
| 7 | #include <signal.h> | ||
| 8 | |||
| 9 | jmp_buf jb; | ||
| 10 | |||
| 11 | void | ||
| 12 | segv_handler(int signum) | ||
| 13 | { | ||
| 14 | longjmp(jb, 1); | ||
| 15 | } | ||
| 16 | |||
| 17 | int | ||
| 18 | main() | ||
| 19 | { | ||
| 20 | signal(SIGSEGV, segv_handler); | ||
| 21 | if (setjmp(jb) == 0) { | ||
| 22 | *((volatile int *)0L) = 0; | ||
| 23 | return (1); | ||
| 24 | } | ||
| 25 | return (0); | ||
| 26 | } | ||
diff --git a/src/regress/lib/libc/setjmp/Makefile b/src/regress/lib/libc/setjmp/Makefile deleted file mode 100644 index fc68e8d44c..0000000000 --- a/src/regress/lib/libc/setjmp/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
| 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ | ||
| 3 | |||
| 4 | PROG= setjmptest | ||
| 5 | SRCS= jmptest.c | ||
| 6 | |||
| 7 | CFLAGS+= -DTEST_SETJMP | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c deleted file mode 100644 index 9512c9ee34..0000000000 --- a/src/regress/lib/libc/setjmp/jmptest.c +++ /dev/null | |||
| @@ -1,136 +0,0 @@ | |||
| 1 | /* $OpenBSD: jmptest.c,v 1.7 2003/09/02 23:52:16 david Exp $ */ | ||
| 2 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1994 Christopher G. Demetriou | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * 3. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by Christopher G. Demetriou | ||
| 19 | * for the NetBSD Project. | ||
| 20 | * 4. The name of the author may not be used to endorse or promote products | ||
| 21 | * derived from this software without specific prior written permission | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <sys/types.h> | ||
| 36 | #include <err.h> | ||
| 37 | #include <setjmp.h> | ||
| 38 | #include <signal.h> | ||
| 39 | #include <stdio.h> | ||
| 40 | #include <stdlib.h> | ||
| 41 | #include <string.h> | ||
| 42 | #include <unistd.h> | ||
| 43 | |||
| 44 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | ||
| 45 | #error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifdef TEST_SETJMP | ||
| 49 | #define BUF jmp_buf | ||
| 50 | #define SET(b, m) setjmp(b) | ||
| 51 | #define JMP(b, v) longjmp(b, v) | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifdef TEST_U_SETJMP | ||
| 55 | #define BUF jmp_buf | ||
| 56 | #define SET(b, m) _setjmp(b) | ||
| 57 | #define JMP(b, v) _longjmp(b, v) | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #ifdef TEST_SIGSETJMP | ||
| 61 | #define BUF sigjmp_buf | ||
| 62 | #define SET(b, m) sigsetjmp(b, m) | ||
| 63 | #define JMP(b, v) siglongjmp(b, v) | ||
| 64 | #endif | ||
| 65 | |||
| 66 | int expectsignal; | ||
| 67 | |||
| 68 | static void | ||
| 69 | aborthandler(int signo) | ||
| 70 | { | ||
| 71 | |||
| 72 | if (expectsignal) | ||
| 73 | _exit(0); | ||
| 74 | else { | ||
| 75 | warnx("kill(SIGABRT) succeeded"); | ||
| 76 | _exit(1); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | int | ||
| 81 | main(int argc, char *argv[]) | ||
| 82 | { | ||
| 83 | struct sigaction sa; | ||
| 84 | BUF jb; | ||
| 85 | sigset_t ss; | ||
| 86 | int i, x; | ||
| 87 | |||
| 88 | i = getpid(); | ||
| 89 | |||
| 90 | #ifdef TEST_SETJMP | ||
| 91 | expectsignal = 0; | ||
| 92 | #endif | ||
| 93 | #ifdef TEST_U_SETJMP | ||
| 94 | expectsignal = 1; | ||
| 95 | #endif | ||
| 96 | #ifdef TEST_SIGSETJMP | ||
| 97 | if (argc != 2 || | ||
| 98 | (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) { | ||
| 99 | fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]); | ||
| 100 | exit(1); | ||
| 101 | } | ||
| 102 | expectsignal = (strcmp(argv[1], "save") != 0); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | sa.sa_handler = aborthandler; | ||
| 106 | sigemptyset(&sa.sa_mask); | ||
| 107 | sa.sa_flags = 0; | ||
| 108 | if (sigaction(SIGABRT, &sa, NULL) == -1) | ||
| 109 | err(1, "sigaction failed"); | ||
| 110 | |||
| 111 | if (sigemptyset(&ss) == -1) | ||
| 112 | err(1, "sigemptyset failed"); | ||
| 113 | if (sigaddset(&ss, SIGABRT) == -1) | ||
| 114 | err(1, "sigaddset failed"); | ||
| 115 | if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1) | ||
| 116 | err(1, "sigprocmask (1) failed"); | ||
| 117 | |||
| 118 | x = SET(jb, !expectsignal); | ||
| 119 | if (x != 0) { | ||
| 120 | if (x != i) | ||
| 121 | errx(1, "setjmp returned wrong value"); | ||
| 122 | |||
| 123 | kill(i, SIGABRT); | ||
| 124 | if (expectsignal) | ||
| 125 | errx(1, "kill(SIGABRT) failed"); | ||
| 126 | else | ||
| 127 | exit(0); | ||
| 128 | } | ||
| 129 | |||
| 130 | if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) | ||
| 131 | err(1, "sigprocmask (2) failed"); | ||
| 132 | |||
| 133 | JMP(jb, i); | ||
| 134 | |||
| 135 | errx(1, "jmp failed"); | ||
| 136 | } | ||
diff --git a/src/regress/lib/libc/sigsetjmp/Makefile b/src/regress/lib/libc/sigsetjmp/Makefile deleted file mode 100644 index f88bea3b47..0000000000 --- a/src/regress/lib/libc/sigsetjmp/Makefile +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
| 2 | |||
| 3 | PROG= sigsetjmptest | ||
| 4 | SRCS= jmptest.c | ||
| 5 | |||
| 6 | CFLAGS+= -DTEST_SIGSETJMP | ||
| 7 | |||
| 8 | .PATH: ${.CURDIR}/../setjmp | ||
| 9 | |||
| 10 | REGRESS_TARGETS=sigsetjmp-save sigsetjmp-nosave | ||
| 11 | |||
| 12 | sigsetjmp-save: ${PROG} | ||
| 13 | ./${PROG} save | ||
| 14 | sigsetjmp-nosave: ${PROG} | ||
| 15 | ./${PROG} nosave | ||
| 16 | |||
| 17 | .PHONY: ${REGRESS_TARGETS} | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigthr/Makefile b/src/regress/lib/libc/sigthr/Makefile deleted file mode 100644 index 8ae4643e1e..0000000000 --- a/src/regress/lib/libc/sigthr/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2015/10/22 05:30:18 guenther Exp $ | ||
| 2 | |||
| 3 | PROG=sigthr_test | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigthr/sigthr_test.c b/src/regress/lib/libc/sigthr/sigthr_test.c deleted file mode 100644 index c2eaa1f779..0000000000 --- a/src/regress/lib/libc/sigthr/sigthr_test.c +++ /dev/null | |||
| @@ -1,66 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> | ||
| 3 | * | ||
| 4 | * Public domain. | ||
| 5 | * | ||
| 6 | * Verify that SIGTHR can't be blocked or caught by applications. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <err.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <signal.h> | ||
| 15 | |||
| 16 | void sighandler(int sig) { } | ||
| 17 | |||
| 18 | int | ||
| 19 | main(void) | ||
| 20 | { | ||
| 21 | struct sigaction sa; | ||
| 22 | sigset_t set, oset; | ||
| 23 | |||
| 24 | /* | ||
| 25 | * check sigprocmask | ||
| 26 | */ | ||
| 27 | if (sigprocmask(SIG_BLOCK, NULL, &set)) | ||
| 28 | err(1, "sigprocmask"); | ||
| 29 | if (sigismember(&set, SIGTHR)) | ||
| 30 | errx(1, "SIGTHR already blocked"); | ||
| 31 | sigaddset(&set, SIGTHR); | ||
| 32 | if (sigprocmask(SIG_BLOCK, &set, NULL)) | ||
| 33 | err(1, "sigprocmask"); | ||
| 34 | if (sigprocmask(SIG_SETMASK, &set, &oset)) | ||
| 35 | err(1, "sigprocmask"); | ||
| 36 | if (sigismember(&oset, SIGTHR)) | ||
| 37 | errx(1, "SIGTHR blocked with SIG_BLOCK"); | ||
| 38 | if (sigprocmask(SIG_BLOCK, NULL, &oset)) | ||
| 39 | err(1, "sigprocmask"); | ||
| 40 | if (sigismember(&oset, SIGTHR)) | ||
| 41 | errx(1, "SIGTHR blocked with SIG_SETMASK"); | ||
| 42 | |||
| 43 | /* | ||
| 44 | * check sigaction | ||
| 45 | */ | ||
| 46 | if (sigaction(SIGTHR, NULL, &sa) == 0) | ||
| 47 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
| 48 | else if (errno != EINVAL) | ||
| 49 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
| 50 | memset(&sa, 0, sizeof sa); | ||
| 51 | sa.sa_handler = sighandler; | ||
| 52 | sigfillset(&sa.sa_mask); | ||
| 53 | sa.sa_flags = 0; | ||
| 54 | if (sigaction(SIGTHR, &sa, NULL) == 0) | ||
| 55 | errx(1, "sigaction(SIGTHR) succeeded"); | ||
| 56 | else if (errno != EINVAL) | ||
| 57 | err(1, "sigaction(SIGTHR) didn't fail with EINVAL"); | ||
| 58 | if (sigaction(SIGUSR1, &sa, NULL)) | ||
| 59 | err(1, "sigaction(SIGUSR1)"); | ||
| 60 | if (sigaction(SIGUSR1, NULL, &sa)) | ||
| 61 | err(1, "sigaction(SIGUSR1)"); | ||
| 62 | if (sigismember(&sa.sa_mask, SIGTHR)) | ||
| 63 | errx(1, "SIGTHR blocked with sigaction"); | ||
| 64 | |||
| 65 | return 0; | ||
| 66 | } | ||
diff --git a/src/regress/lib/libc/sleep/Makefile b/src/regress/lib/libc/sleep/Makefile deleted file mode 100644 index 3700b1662a..0000000000 --- a/src/regress/lib/libc/sleep/Makefile +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2009/12/14 05:08:19 guenther Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=sleep_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | run-regress-${PROG}: ${PROG} | ||
| 8 | [ x$$(./${PROG} 1) = x0 ] || exit 1 | ||
| 9 | file=$$(mktemp -t sleep.XXXXXXXXXX); ./${PROG} 4 >$$file & pid=$$!; \ | ||
| 10 | sleep 1; kill $$pid; sleep 1; v=$$(cat $$file); rm -f $$file; \ | ||
| 11 | { [ $$v -gt 0 ] && [ $$v -lt 4 ] ; } || exit 2 | ||
| 12 | |||
| 13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/sleep_test.c b/src/regress/lib/libc/sleep/sleep_test.c deleted file mode 100644 index 4c7764375d..0000000000 --- a/src/regress/lib/libc/sleep/sleep_test.c +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | /* $OpenBSD: sleep_test.c,v 1.2 2015/10/18 23:27:43 guenther Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2009 Philip Guenther | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | /* | ||
| 33 | * Test whether sleep returns the correct value | ||
| 34 | */ | ||
| 35 | |||
| 36 | #include <sys/types.h> | ||
| 37 | #include <err.h> | ||
| 38 | #include <errno.h> | ||
| 39 | #include <limits.h> | ||
| 40 | #include <signal.h> | ||
| 41 | #include <stddef.h> | ||
| 42 | #include <stdio.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <string.h> | ||
| 45 | #include <unistd.h> | ||
| 46 | |||
| 47 | static void | ||
| 48 | handler(int sig) | ||
| 49 | { | ||
| 50 | return; | ||
| 51 | } | ||
| 52 | |||
| 53 | static void * | ||
| 54 | garbage(void) | ||
| 55 | { | ||
| 56 | char buf[20]; | ||
| 57 | strlcpy(buf, "012354678901235467890123546789", sizeof buf); | ||
| 58 | return buf; | ||
| 59 | } | ||
| 60 | |||
| 61 | int | ||
| 62 | main(int argc, char *argv[]) | ||
| 63 | { | ||
| 64 | struct sigaction sa; | ||
| 65 | char const *errstr; | ||
| 66 | int i; | ||
| 67 | |||
| 68 | if (argc != 2) | ||
| 69 | return (1); | ||
| 70 | errno = 0; | ||
| 71 | i = strtonum(argv[1], 0, INT_MAX, &errstr); | ||
| 72 | if (i == 0 && errno != 0) { | ||
| 73 | fprintf(stderr, "%s\n", errstr); | ||
| 74 | return (1); | ||
| 75 | } | ||
| 76 | |||
| 77 | memset(&sa, 0, sizeof sa); | ||
| 78 | sa.sa_handler = &handler; | ||
| 79 | if (sigaction(SIGTERM, &sa, NULL)) | ||
| 80 | err(3, "sigaction"); | ||
| 81 | garbage(); | ||
| 82 | printf("%d\n", sleep(i)); | ||
| 83 | return (0); | ||
| 84 | } | ||
| 85 | |||
diff --git a/src/regress/lib/libc/sprintf/Makefile b/src/regress/lib/libc/sprintf/Makefile deleted file mode 100644 index 514d795f2f..0000000000 --- a/src/regress/lib/libc/sprintf/Makefile +++ /dev/null | |||
| @@ -1,7 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/07/27 15:08:37 bluhm Exp $ | ||
| 2 | |||
| 3 | PROG = sprintf_test | ||
| 4 | CFLAGS = -Wno-format | ||
| 5 | CPPFLAGS = -I${.CURDIR}/../../../../lib/libc | ||
| 6 | |||
| 7 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sprintf/sprintf_test.c b/src/regress/lib/libc/sprintf/sprintf_test.c deleted file mode 100644 index 61c58f2f09..0000000000 --- a/src/regress/lib/libc/sprintf/sprintf_test.c +++ /dev/null | |||
| @@ -1,102 +0,0 @@ | |||
| 1 | /* $OpenBSD: sprintf_test.c,v 1.4 2004/09/18 19:31:32 otto Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2003 Theo de Raadt | ||
| 5 | * All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * | ||
| 11 | * - Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * - Redistributions in binary form must reproduce the above | ||
| 14 | * copyright notice, this list of conditions and the following | ||
| 15 | * disclaimer in the documentation and/or other materials provided | ||
| 16 | * with the distribution. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
| 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 29 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <stddef.h> | ||
| 33 | #include <stdio.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <string.h> | ||
| 36 | #include <signal.h> | ||
| 37 | |||
| 38 | char correct[] = | ||
| 39 | "|xx 01 02 03 04\n" | ||
| 40 | "|xx 05 06 07 08\n" | ||
| 41 | "|xx 09 10 11 12\n" | ||
| 42 | "|xx 13 14 15 16\n" | ||
| 43 | "|xx 17 18 19 20\n" | ||
| 44 | "|xx 21 22 23 24\n" | ||
| 45 | "|xx 25 26 27 28\n" | ||
| 46 | "|xx 29 30 31 32\n" | ||
| 47 | "|xx 33 34 35 36\n" | ||
| 48 | "|xx 37 38 39 40\n" | ||
| 49 | "|xx 41 42 43 44\n" | ||
| 50 | "|xx 45 -1 1 -1 1\n"; | ||
| 51 | |||
| 52 | char correct2[] = | ||
| 53 | "1 0 -1 1 1 2 1 3 -1 4 1 \n" | ||
| 54 | "1 -1 1 1 -1 1 \n"; | ||
| 55 | |||
| 56 | int | ||
| 57 | main(int argc, char *argv[]) | ||
| 58 | { | ||
| 59 | char buf[1024]; | ||
| 60 | size_t sz1, sz2, sz3, sz4; | ||
| 61 | ptrdiff_t p1, p2, p3, p4; | ||
| 62 | |||
| 63 | /* Test positional arguments */ | ||
| 64 | snprintf(buf, sizeof buf, | ||
| 65 | "|xx %1$s %2$s %3$s %4$s\n" | ||
| 66 | "|xx %5$s %6$s %7$s %8$s\n" | ||
| 67 | "|xx %9$s %10$s %11$s %12$s\n" | ||
| 68 | "|xx %13$s %14$s %15$s %16$s\n" | ||
| 69 | "|xx %17$s %18$s %19$s %20$s\n" | ||
| 70 | "|xx %21$s %22$s %23$s %24$s\n" | ||
| 71 | "|xx %25$s %26$s %27$s %28$s\n" | ||
| 72 | "|xx %29$s %30$s %31$s %32$s\n" | ||
| 73 | "|xx %33$s %34$s %35$s %36$s\n" | ||
| 74 | "|xx %37$s %38$s %39$s %40$s\n" | ||
| 75 | "|xx %41$s %42$s %43$s %44$s\n" | ||
| 76 | "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", | ||
| 77 | "01", "02", "03", "04", "05", "06", | ||
| 78 | "07", "08", "09", "10", "11", "12", | ||
| 79 | "13", "14", "15", "16", "17", "18", | ||
| 80 | "19", "20", "21", "22", "23", "24", | ||
| 81 | "25", "26", "27", "28", "29", "30", | ||
| 82 | "31", "32", "33", "34", "35", "36", | ||
| 83 | "37", "38", "39", "40", "41", "42", | ||
| 84 | "43", "44", 45, -1L, 1LL, -1, 1LL | ||
| 85 | ); | ||
| 86 | |||
| 87 | if (strcmp(buf, correct) != 0) | ||
| 88 | exit(1); | ||
| 89 | |||
| 90 | sz1 = (size_t)1; | ||
| 91 | sz2 = (size_t)-1; | ||
| 92 | p1 = (ptrdiff_t)1; | ||
| 93 | p2 = (ptrdiff_t)-1; | ||
| 94 | snprintf(buf, sizeof buf, | ||
| 95 | "%zx %d %zd %d %zu %d %tx %d %td %d %tu %zn %tn\n" | ||
| 96 | "%1$zx %3$zd %5$zu %7$tx %9$td %11$tu %14$zn %15$tn\n", | ||
| 97 | sz1, 0, sz2, 1, sz1, 2, p1, 3, p2, 4, p1, &sz3, &p3, &sz4, &p4); | ||
| 98 | if (strcmp(buf, correct2) != 0 || sz3 != 24 || p3 != 25 || | ||
| 99 | sz4 != 40 || p4 != 41) | ||
| 100 | exit(1); | ||
| 101 | exit(0); | ||
| 102 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/Makefile b/src/regress/lib/libc/stdio_threading/Makefile deleted file mode 100644 index e42481afc2..0000000000 --- a/src/regress/lib/libc/stdio_threading/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | SUBDIR += fopen fread fwrite fgetln fgets fputs | ||
| 2 | |||
| 3 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/Makefile b/src/regress/lib/libc/stdio_threading/fgetln/Makefile deleted file mode 100644 index cad51e2b23..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgetln_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c deleted file mode 100755 index 76d154bb2a..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c +++ /dev/null | |||
| @@ -1,70 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgetln_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | size_t len; | ||
| 24 | char *buf; | ||
| 25 | int i; | ||
| 26 | |||
| 27 | for (i = 0; i < 4096; i++) { | ||
| 28 | if ((buf = fgetln(file, &len)) == NULL) { | ||
| 29 | |||
| 30 | if (feof(file)) | ||
| 31 | break; | ||
| 32 | |||
| 33 | printf("OMG!!!\n"); | ||
| 34 | fflush(stdout); | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | if (strncmp(buf, TEXT_N, sizeof(TEXT_N))) | ||
| 38 | err(1, "fgetln not atomic!!!"); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int | ||
| 43 | main(void) | ||
| 44 | { | ||
| 45 | char sfn[24]; | ||
| 46 | FILE *sfp; | ||
| 47 | int fd, i; | ||
| 48 | |||
| 49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 50 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 51 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 52 | int saved_errno = errno; | ||
| 53 | if (fd != -1) { | ||
| 54 | unlink(sfn); | ||
| 55 | close(fd); | ||
| 56 | } | ||
| 57 | errc(1, saved_errno, "could not open temporary file"); | ||
| 58 | } | ||
| 59 | |||
| 60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 61 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 62 | err(1, "Could not populate test file"); | ||
| 63 | |||
| 64 | run_threads(fgetln_thread, sfp); | ||
| 65 | |||
| 66 | unlink(sfn); | ||
| 67 | close(fd); | ||
| 68 | |||
| 69 | exit(0); | ||
| 70 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/Makefile b/src/regress/lib/libc/stdio_threading/fgets/Makefile deleted file mode 100644 index 52310fd429..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fgets_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c deleted file mode 100755 index 7c5008e2ad..0000000000 --- a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fgets_thread(void *v) | ||
| 21 | { | ||
| 22 | char buf[sizeof(TEXT_N) + 1]; | ||
| 23 | FILE *file = v; | ||
| 24 | int i; | ||
| 25 | |||
| 26 | for (i = 0; i < 4096; i++) { | ||
| 27 | if (fgets(buf, sizeof(buf), file) == NULL) { | ||
| 28 | |||
| 29 | if (feof(file)) | ||
| 30 | break; | ||
| 31 | |||
| 32 | printf("OMG!!!\n"); | ||
| 33 | fflush(stdout); | ||
| 34 | break; | ||
| 35 | } | ||
| 36 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 37 | err(1, "Read not atomic!!!"); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | int | ||
| 42 | main(void) | ||
| 43 | { | ||
| 44 | char sfn[24]; | ||
| 45 | FILE *sfp; | ||
| 46 | int fd, i; | ||
| 47 | |||
| 48 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 49 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 50 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 51 | int saved_errno = errno; | ||
| 52 | if (fd != -1) { | ||
| 53 | unlink(sfn); | ||
| 54 | close(fd); | ||
| 55 | } | ||
| 56 | errc(1, saved_errno, "could not open temporary file"); | ||
| 57 | } | ||
| 58 | |||
| 59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 60 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
| 61 | err(1, "Could not populate test file"); | ||
| 62 | |||
| 63 | run_threads(fgets_thread, sfp); | ||
| 64 | |||
| 65 | unlink(sfn); | ||
| 66 | close(fd); | ||
| 67 | |||
| 68 | exit(0); | ||
| 69 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/Makefile b/src/regress/lib/libc/stdio_threading/fopen/Makefile deleted file mode 100644 index e51deeff1d..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fopen_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c deleted file mode 100755 index 89172d9fb7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | /* $OpenBSD: fopen_test.c,v 1.2 2015/01/20 04:41:01 krw Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdio.h> | ||
| 19 | #include <pthread.h> | ||
| 20 | #include "local.h" | ||
| 21 | |||
| 22 | int | ||
| 23 | writefn(void *cookie, const char *buf, int size) | ||
| 24 | { | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | void | ||
| 29 | fopen_thread(void *v) | ||
| 30 | { | ||
| 31 | FILE *file; | ||
| 32 | int i; | ||
| 33 | |||
| 34 | for (i = 0; i < 4096; i++) { | ||
| 35 | file = fwopen(&i, writefn); | ||
| 36 | if (file != NULL) { | ||
| 37 | fputc('0', file); | ||
| 38 | pthread_yield(); | ||
| 39 | fclose(file); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | int | ||
| 45 | main(void) | ||
| 46 | { | ||
| 47 | run_threads(fopen_thread, NULL); | ||
| 48 | exit(0); | ||
| 49 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/Makefile b/src/regress/lib/libc/stdio_threading/fputs/Makefile deleted file mode 100644 index e561745581..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fputs_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c deleted file mode 100755 index 93d0f0b6c7..0000000000 --- a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fputs_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fputs(TEXT, file) != 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | int saved_errno = errno; | ||
| 50 | if (fd != -1) { | ||
| 51 | unlink(sfn); | ||
| 52 | close(fd); | ||
| 53 | } | ||
| 54 | errc(1, saved_errno, "could not open temporary file"); | ||
| 55 | } | ||
| 56 | |||
| 57 | run_threads(fputs_thread, sfp); | ||
| 58 | |||
| 59 | while (fgets(buf, sizeof(buf), sfp) != NULL) /* verify */ | ||
| 60 | if (strcmp(buf, TEXT)) | ||
| 61 | err(1, "Thread writes were not atomic!!!"); | ||
| 62 | |||
| 63 | unlink(sfn); | ||
| 64 | close(fd); | ||
| 65 | |||
| 66 | exit(0); | ||
| 67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile deleted file mode 100644 index 25196dd7ab..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fread_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c deleted file mode 100755 index 6bd734b470..0000000000 --- a/src/regress/lib/libc/stdio_threading/fread/fread_test.c +++ /dev/null | |||
| @@ -1,71 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <pthread.h> | ||
| 19 | #include "local.h" | ||
| 20 | |||
| 21 | void | ||
| 22 | fread_thread(void *v) | ||
| 23 | { | ||
| 24 | char buf[sizeof(TEXT)]; | ||
| 25 | FILE *file = v; | ||
| 26 | int i; | ||
| 27 | |||
| 28 | for (i = 0; i < 4096; i++) { | ||
| 29 | if (fread(buf, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 30 | |||
| 31 | if (feof(file)) | ||
| 32 | break; | ||
| 33 | |||
| 34 | printf("OMG!!!\n"); | ||
| 35 | fflush(stdout); | ||
| 36 | break; | ||
| 37 | } | ||
| 38 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 39 | err(1, "Read not atomic!!!"); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | int | ||
| 44 | main(void) | ||
| 45 | { | ||
| 46 | char sfn[24]; | ||
| 47 | FILE *sfp; | ||
| 48 | int fd, i; | ||
| 49 | |||
| 50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 51 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 52 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 53 | int saved_errno = errno; | ||
| 54 | if (fd != -1) { | ||
| 55 | unlink(sfn); | ||
| 56 | close(fd); | ||
| 57 | } | ||
| 58 | errc(1, saved_errno, "could not open temporary file"); | ||
| 59 | } | ||
| 60 | |||
| 61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
| 62 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), sfp) == 0) | ||
| 63 | err(1, "Could not populate test file"); | ||
| 64 | |||
| 65 | run_threads(fread_thread, sfp); | ||
| 66 | |||
| 67 | unlink(sfn); | ||
| 68 | close(fd); | ||
| 69 | |||
| 70 | exit(0); | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/Makefile b/src/regress/lib/libc/stdio_threading/fwrite/Makefile deleted file mode 100644 index e79899c475..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/Makefile +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | TOPDIR=${.CURDIR} | ||
| 2 | PROG=fwrite_test | ||
| 3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
| 4 | LDFLAGS+=-lpthread | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c deleted file mode 100755 index 86c450cbc9..0000000000 --- a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "local.h" | ||
| 18 | |||
| 19 | void | ||
| 20 | fwrite_thread(void *v) | ||
| 21 | { | ||
| 22 | FILE *file = v; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | for (i = 0; i < 4096; i++) { | ||
| 26 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), file) == 0) { | ||
| 27 | |||
| 28 | if (feof(file)) | ||
| 29 | break; | ||
| 30 | |||
| 31 | printf("OMG!!!\n"); | ||
| 32 | fflush(stdout); | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | char sfn[24]; | ||
| 42 | char buf[sizeof(TEXT)]; | ||
| 43 | FILE *sfp; | ||
| 44 | int fd; | ||
| 45 | |||
| 46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
| 47 | if ((fd = mkstemp(sfn)) == -1 || | ||
| 48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
| 49 | int saved_errno = errno; | ||
| 50 | if (fd != -1) { | ||
| 51 | unlink(sfn); | ||
| 52 | close(fd); | ||
| 53 | } | ||
| 54 | errc(1, saved_errno, "could not open temporary file"); | ||
| 55 | } | ||
| 56 | |||
| 57 | run_threads(fwrite_thread, sfp); | ||
| 58 | |||
| 59 | while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */ | ||
| 60 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
| 61 | err(1, "Thread writes were not atomic!!!"); | ||
| 62 | |||
| 63 | unlink(sfn); | ||
| 64 | close(fd); | ||
| 65 | |||
| 66 | exit(0); | ||
| 67 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h deleted file mode 100644 index 7a7822a452..0000000000 --- a/src/regress/lib/libc/stdio_threading/include/local.h +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <err.h> | ||
| 18 | #include <errno.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | #include <pthread.h> | ||
| 24 | |||
| 25 | #define THREAD_COUNT 64 | ||
| 26 | |||
| 27 | #define TEXT "barnacles" | ||
| 28 | #define TEXT_N "barnacles\n" | ||
| 29 | |||
| 30 | void run_threads(void (*)(void *), void *); | ||
| 31 | |||
| 32 | static pthread_rwlock_t start; | ||
| 33 | static void (*real_func)(void *); | ||
| 34 | |||
| 35 | static void * | ||
| 36 | thread(void *arg) | ||
| 37 | { | ||
| 38 | int r; | ||
| 39 | |||
| 40 | if ((r = pthread_rwlock_rdlock(&start))) | ||
| 41 | errc(1, r, "could not obtain lock in thread"); | ||
| 42 | real_func(arg); | ||
| 43 | if ((r = pthread_rwlock_unlock(&start))) | ||
| 44 | errc(1, r, "could not release lock in thread"); | ||
| 45 | return NULL; | ||
| 46 | } | ||
| 47 | |||
| 48 | void | ||
| 49 | run_threads(void (*func)(void *), void *arg) | ||
| 50 | { | ||
| 51 | pthread_t self, pthread[THREAD_COUNT]; | ||
| 52 | int i, r; | ||
| 53 | |||
| 54 | self = pthread_self(); | ||
| 55 | real_func = func; | ||
| 56 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
| 57 | errc(1, r, "could not initialize lock"); | ||
| 58 | |||
| 59 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
| 60 | errc(1, r, "could not lock lock"); | ||
| 61 | |||
| 62 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 63 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
| 64 | warnc(r, "could not create thread"); | ||
| 65 | pthread[i] = self; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
| 70 | errc(1, r, "could not release lock"); | ||
| 71 | |||
| 72 | sleep(1); | ||
| 73 | |||
| 74 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
| 75 | errx(1, "parent could not sync with children: %s", | ||
| 76 | strerror(r)); | ||
| 77 | |||
| 78 | for (i = 0; i < THREAD_COUNT; i++) | ||
| 79 | if (! pthread_equal(pthread[i], self) && | ||
| 80 | (r = pthread_join(pthread[i], NULL))) | ||
| 81 | warnc(r, "could not join thread"); | ||
| 82 | } | ||
| 83 | |||
diff --git a/src/regress/lib/libc/stpncpy/Makefile b/src/regress/lib/libc/stpncpy/Makefile deleted file mode 100644 index 9333934da6..0000000000 --- a/src/regress/lib/libc/stpncpy/Makefile +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | PROG=stpncpy_test | ||
| 2 | |||
| 3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stpncpy/stpncpy_test.c b/src/regress/lib/libc/stpncpy/stpncpy_test.c deleted file mode 100644 index 63b7d25e53..0000000000 --- a/src/regress/lib/libc/stpncpy/stpncpy_test.c +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | /* $OpenBSD: stpncpy_test.c,v 1.1 2012/07/11 10:46:23 naddy Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain, 2012, Christian Weisgerber <naddy@openbsd.org> | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | int main(void) | ||
| 10 | { | ||
| 11 | char dst[8]; | ||
| 12 | char *src = "abcdef"; | ||
| 13 | |||
| 14 | if (stpncpy(dst, src, 5) != dst + 5) | ||
| 15 | return 1; | ||
| 16 | if (stpncpy(dst, src, 6) != dst + 6) | ||
| 17 | return 1; | ||
| 18 | if (stpncpy(dst, src, 7) != dst + 6) | ||
| 19 | return 1; | ||
| 20 | if (stpncpy(dst, src, 8) != dst + 6) | ||
| 21 | return 1; | ||
| 22 | |||
| 23 | return 0; | ||
| 24 | } | ||
diff --git a/src/regress/lib/libc/strerror/Makefile b/src/regress/lib/libc/strerror/Makefile deleted file mode 100644 index 448b6da903..0000000000 --- a/src/regress/lib/libc/strerror/Makefile +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/04/30 17:15:12 espie Exp $ | ||
| 2 | |||
| 3 | NOMAN= | ||
| 4 | PROG=strerror_test | ||
| 5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
| 6 | CLEANFILES+= invalid.out valid.out | ||
| 7 | |||
| 8 | run-regress-strerror_test: ${PROG} | ||
| 9 | ./${PROG} >${.OBJDIR}/valid.out | ||
| 10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 11 | |||
| 12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strerror/strerror_test.c b/src/regress/lib/libc/strerror/strerror_test.c deleted file mode 100644 index 23b542f1ee..0000000000 --- a/src/regress/lib/libc/strerror/strerror_test.c +++ /dev/null | |||
| @@ -1,65 +0,0 @@ | |||
| 1 | /* $OpenBSD: strerror_test.c,v 1.5 2015/09/14 06:31:25 guenther Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <signal.h> | ||
| 18 | #include <string.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <limits.h> | ||
| 21 | #include <errno.h> | ||
| 22 | |||
| 23 | void | ||
| 24 | check_strerror_r(int val) | ||
| 25 | { | ||
| 26 | char buffer[NL_TEXTMAX + 1]; | ||
| 27 | int i, r; | ||
| 28 | |||
| 29 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
| 30 | buffer[sizeof(buffer) - 1] = '\0'; | ||
| 31 | (void)strerror_r(val, NULL, 0); /* XXX */ | ||
| 32 | for (i = 0; i < 25; i++) { | ||
| 33 | r = strerror_r(val, buffer, i); | ||
| 34 | printf("%d %d %zu: %s\n", i, r, strlen(buffer), buffer); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void | ||
| 39 | check_strsignal(int val) | ||
| 40 | { | ||
| 41 | printf("%s\n", strsignal(val)); | ||
| 42 | } | ||
| 43 | |||
| 44 | int | ||
| 45 | main() | ||
| 46 | { | ||
| 47 | printf("%s\n", strerror(21345)); | ||
| 48 | printf("%s\n", strerror(-21345)); | ||
| 49 | printf("%s\n", strerror(0)); | ||
| 50 | printf("%s\n", strerror(INT_MAX)); | ||
| 51 | printf("%s\n", strerror(INT_MIN)); | ||
| 52 | printf("%s\n", strerror(EPERM)); | ||
| 53 | check_strerror_r(EPERM); | ||
| 54 | check_strerror_r(21345); | ||
| 55 | check_strsignal(-1); | ||
| 56 | check_strsignal(0); | ||
| 57 | check_strsignal(10); | ||
| 58 | check_strsignal(NSIG-1); | ||
| 59 | check_strsignal(NSIG); | ||
| 60 | check_strsignal(100); | ||
| 61 | check_strsignal(INT_MAX); | ||
| 62 | check_strsignal(INT_MIN); | ||
| 63 | check_strsignal(UINT_MAX); | ||
| 64 | return 0; | ||
| 65 | } | ||
diff --git a/src/regress/lib/libc/strerror/valid.ok b/src/regress/lib/libc/strerror/valid.ok deleted file mode 100644 index cbc365c598..0000000000 --- a/src/regress/lib/libc/strerror/valid.ok +++ /dev/null | |||
| @@ -1,65 +0,0 @@ | |||
| 1 | Unknown error: 21345 | ||
| 2 | Unknown error: -21345 | ||
| 3 | Undefined error: 0 | ||
| 4 | Unknown error: 2147483647 | ||
| 5 | Unknown error: -2147483648 | ||
| 6 | Operation not permitted | ||
| 7 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
| 8 | 1 34 0: | ||
| 9 | 2 34 1: O | ||
| 10 | 3 34 2: Op | ||
| 11 | 4 34 3: Ope | ||
| 12 | 5 34 4: Oper | ||
| 13 | 6 34 5: Opera | ||
| 14 | 7 34 6: Operat | ||
| 15 | 8 34 7: Operati | ||
| 16 | 9 34 8: Operatio | ||
| 17 | 10 34 9: Operation | ||
| 18 | 11 34 10: Operation | ||
| 19 | 12 34 11: Operation n | ||
| 20 | 13 34 12: Operation no | ||
| 21 | 14 34 13: Operation not | ||
| 22 | 15 34 14: Operation not | ||
| 23 | 16 34 15: Operation not p | ||
| 24 | 17 34 16: Operation not pe | ||
| 25 | 18 34 17: Operation not per | ||
| 26 | 19 34 18: Operation not perm | ||
| 27 | 20 34 19: Operation not permi | ||
| 28 | 21 34 20: Operation not permit | ||
| 29 | 22 34 21: Operation not permitt | ||
| 30 | 23 34 22: Operation not permitte | ||
| 31 | 24 0 23: Operation not permitted | ||
| 32 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
| 33 | 1 34 0: | ||
| 34 | 2 34 1: U | ||
| 35 | 3 34 2: Un | ||
| 36 | 4 34 3: Unk | ||
| 37 | 5 34 4: Unkn | ||
| 38 | 6 34 5: Unkno | ||
| 39 | 7 34 6: Unknow | ||
| 40 | 8 34 7: Unknown | ||
| 41 | 9 34 8: Unknown | ||
| 42 | 10 34 9: Unknown e | ||
| 43 | 11 34 10: Unknown er | ||
| 44 | 12 34 11: Unknown err | ||
| 45 | 13 34 12: Unknown erro | ||
| 46 | 14 34 13: Unknown error | ||
| 47 | 15 34 14: Unknown error: | ||
| 48 | 16 34 15: Unknown error: | ||
| 49 | 17 34 15: Unknown error: | ||
| 50 | 18 34 15: Unknown error: | ||
| 51 | 19 34 15: Unknown error: | ||
| 52 | 20 34 15: Unknown error: | ||
| 53 | 21 22 20: Unknown error: 21345 | ||
| 54 | 22 22 20: Unknown error: 21345 | ||
| 55 | 23 22 20: Unknown error: 21345 | ||
| 56 | 24 22 20: Unknown error: 21345 | ||
| 57 | Unknown signal: 4294967295 | ||
| 58 | Signal 0 | ||
| 59 | Bus error | ||
| 60 | Thread AST | ||
| 61 | Unknown signal: 33 | ||
| 62 | Unknown signal: 100 | ||
| 63 | Unknown signal: 2147483647 | ||
| 64 | Unknown signal: 2147483648 | ||
| 65 | Unknown signal: 4294967295 | ||
diff --git a/src/regress/lib/libc/strlcat/Makefile b/src/regress/lib/libc/strlcat/Makefile deleted file mode 100644 index 858cb22696..0000000000 --- a/src/regress/lib/libc/strlcat/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/12/02 17:48:34 millert Exp $ | ||
| 2 | |||
| 3 | PROG= strlcattest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strlcat/strlcattest.c b/src/regress/lib/libc/strlcat/strlcattest.c deleted file mode 100644 index 155aa6f727..0000000000 --- a/src/regress/lib/libc/strlcat/strlcattest.c +++ /dev/null | |||
| @@ -1,174 +0,0 @@ | |||
| 1 | /* $OpenBSD: strlcattest.c,v 1.2 2014/12/03 18:25:18 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2014 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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 <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <setjmp.h> | ||
| 25 | #include <signal.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | |||
| 28 | volatile sig_atomic_t got_signal; | ||
| 29 | sigjmp_buf jmpenv; | ||
| 30 | |||
| 31 | void | ||
| 32 | handler(int signo) | ||
| 33 | { | ||
| 34 | got_signal = signo; | ||
| 35 | siglongjmp(jmpenv, 1); | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(int argc, char *argv[]) | ||
| 40 | { | ||
| 41 | char *buf, *cp, *ep; | ||
| 42 | struct sigaction sa; | ||
| 43 | size_t len, bufsize; | ||
| 44 | int failures = 0; | ||
| 45 | |||
| 46 | /* Enable malloc security options. */ | ||
| 47 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 48 | |||
| 49 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
| 50 | buf = malloc(bufsize); | ||
| 51 | if (buf == NULL) { | ||
| 52 | fprintf(stderr, "unable to allocate memory\n"); | ||
| 53 | return 1; | ||
| 54 | } | ||
| 55 | memset(buf, 'z', bufsize); | ||
| 56 | ep = buf + bufsize; | ||
| 57 | |||
| 58 | /* Test appending to an unterminated string. */ | ||
| 59 | len = strlcat(buf, "abcd", bufsize); | ||
| 60 | if (len != 4 + bufsize) { | ||
| 61 | fprintf(stderr, | ||
| 62 | "strlcat: failed unterminated buffer test (1a)\n"); | ||
| 63 | failures++; | ||
| 64 | } | ||
| 65 | /* Make sure we only wrote where expected. */ | ||
| 66 | for (cp = buf; cp < ep; cp++) { | ||
| 67 | if (*cp != 'z') { | ||
| 68 | fprintf(stderr, | ||
| 69 | "strlcat: failed unterminated buffer test (1b)\n"); | ||
| 70 | failures++; | ||
| 71 | break; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | /* Test appending to a full string. */ | ||
| 76 | ep[-1] = '\0'; | ||
| 77 | len = strlcat(buf, "abcd", bufsize); | ||
| 78 | if (len != 4 + bufsize - 1) { | ||
| 79 | fprintf(stderr, "strlcat: failed full buffer test (2a)\n"); | ||
| 80 | failures++; | ||
| 81 | } | ||
| 82 | /* Make sure we only wrote where expected. */ | ||
| 83 | for (cp = buf; cp < ep - 1; cp++) { | ||
| 84 | if (*cp != 'z') { | ||
| 85 | fprintf(stderr, | ||
| 86 | "strlcat: failed full buffer test (2b)\n"); | ||
| 87 | failures++; | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | /* Test appending to an empty string. */ | ||
| 93 | ep[-1] = 'z'; | ||
| 94 | buf[0] = '\0'; | ||
| 95 | len = strlcat(buf, "abcd", bufsize); | ||
| 96 | if (len != 4) { | ||
| 97 | fprintf(stderr, "strlcat: failed empty buffer test (3a)\n"); | ||
| 98 | failures++; | ||
| 99 | } | ||
| 100 | /* Make sure we only wrote where expected. */ | ||
| 101 | if (memcmp(buf, "abcd", sizeof("abcd")) != 0) { | ||
| 102 | fprintf(stderr, "strlcat: failed empty buffer test (3b)\n"); | ||
| 103 | failures++; | ||
| 104 | } | ||
| 105 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
| 106 | if (*cp != 'z') { | ||
| 107 | fprintf(stderr, | ||
| 108 | "strlcat: failed empty buffer test (3c)\n"); | ||
| 109 | failures++; | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | /* Test appending to a NUL-terminated string. */ | ||
| 115 | memcpy(buf, "abcd", sizeof("abcd")); | ||
| 116 | len = strlcat(buf, "efgh", bufsize); | ||
| 117 | if (len != 8) { | ||
| 118 | fprintf(stderr, "strlcat: failed empty buffer test (4a)\n"); | ||
| 119 | failures++; | ||
| 120 | } | ||
| 121 | /* Make sure we only wrote where expected. */ | ||
| 122 | if (memcmp(buf, "abcdefgh", sizeof("abcdefgh")) != 0) { | ||
| 123 | fprintf(stderr, "strlcat: failed empty buffer test (4b)\n"); | ||
| 124 | failures++; | ||
| 125 | } | ||
| 126 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
| 127 | if (*cp != 'z') { | ||
| 128 | fprintf(stderr, | ||
| 129 | "strlcat: failed empty buffer test (4c)\n"); | ||
| 130 | failures++; | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | /* | ||
| 136 | * The following tests should result in SIGSEGV, however some | ||
| 137 | * systems may erroneously report SIGBUS. | ||
| 138 | * These tests assume that strlcat() is signal-safe. | ||
| 139 | */ | ||
| 140 | memset(&sa, 0, sizeof(sa)); | ||
| 141 | sigemptyset(&sa.sa_mask); | ||
| 142 | sa.sa_handler = handler; | ||
| 143 | sigaction(SIGSEGV, &sa, NULL); | ||
| 144 | sigaction(SIGBUS, &sa, NULL); | ||
| 145 | |||
| 146 | /* Test copying to a NULL buffer with non-zero size. */ | ||
| 147 | got_signal = 0; | ||
| 148 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
| 149 | len = strlcat(NULL, "abcd", sizeof(buf)); | ||
| 150 | fprintf(stderr, "strlcat: failed NULL dst test (5a), " | ||
| 151 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
| 152 | failures++; | ||
| 153 | } else if (got_signal != SIGSEGV) { | ||
| 154 | fprintf(stderr, "strlcat: failed NULL dst test (5b), " | ||
| 155 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
| 156 | failures++; | ||
| 157 | } | ||
| 158 | |||
| 159 | /* Test copying from a NULL src. */ | ||
| 160 | memcpy(buf, "abcd", sizeof("abcd")); | ||
| 161 | got_signal = 0; | ||
| 162 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
| 163 | len = strlcat(buf, NULL, sizeof(buf)); | ||
| 164 | fprintf(stderr, "strlcat: failed NULL src test (6a), " | ||
| 165 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
| 166 | failures++; | ||
| 167 | } else if (got_signal != SIGSEGV) { | ||
| 168 | fprintf(stderr, "strlcat: failed NULL src test (6b), " | ||
| 169 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
| 170 | failures++; | ||
| 171 | } | ||
| 172 | |||
| 173 | return failures; | ||
| 174 | } | ||
diff --git a/src/regress/lib/libc/strlcpy/Makefile b/src/regress/lib/libc/strlcpy/Makefile deleted file mode 100644 index 921354432b..0000000000 --- a/src/regress/lib/libc/strlcpy/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/12/02 20:23:05 millert Exp $ | ||
| 2 | |||
| 3 | PROG= strlcpytest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strlcpy/strlcpytest.c b/src/regress/lib/libc/strlcpy/strlcpytest.c deleted file mode 100644 index df5d36366c..0000000000 --- a/src/regress/lib/libc/strlcpy/strlcpytest.c +++ /dev/null | |||
| @@ -1,170 +0,0 @@ | |||
| 1 | /* $OpenBSD: strlcpytest.c,v 1.2 2014/12/03 18:25:18 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2014 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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 <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <signal.h> | ||
| 25 | #include <setjmp.h> | ||
| 26 | #include <unistd.h> | ||
| 27 | |||
| 28 | volatile sig_atomic_t got_signal; | ||
| 29 | sigjmp_buf jmpenv; | ||
| 30 | |||
| 31 | void | ||
| 32 | handler(int signo) | ||
| 33 | { | ||
| 34 | got_signal = signo; | ||
| 35 | siglongjmp(jmpenv, 1); | ||
| 36 | } | ||
| 37 | |||
| 38 | int | ||
| 39 | main(int argc, char *argv[]) | ||
| 40 | { | ||
| 41 | char *buf, *buf2, *cp, *ep; | ||
| 42 | struct sigaction sa; | ||
| 43 | size_t len, bufsize; | ||
| 44 | int failures = 0; | ||
| 45 | |||
| 46 | /* Enable malloc security options. */ | ||
| 47 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 48 | |||
| 49 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
| 50 | buf = malloc(bufsize); | ||
| 51 | buf2 = malloc(bufsize); | ||
| 52 | if (buf == NULL || buf2 == NULL) { | ||
| 53 | fprintf(stderr, "unable to allocate memory\n"); | ||
| 54 | return 1; | ||
| 55 | } | ||
| 56 | memset(buf, 'z', bufsize); | ||
| 57 | ep = buf + bufsize; | ||
| 58 | |||
| 59 | /* Test copying to a zero-length NULL buffer. */ | ||
| 60 | len = strlcpy(NULL, "abcd", 0); | ||
| 61 | if (len != 4) { | ||
| 62 | fprintf(stderr, | ||
| 63 | "strlcpy: failed zero-length buffer test (1a)\n"); | ||
| 64 | failures++; | ||
| 65 | } | ||
| 66 | |||
| 67 | /* Test copying small string to a large buffer. */ | ||
| 68 | len = strlcpy(buf, "abcd", bufsize); | ||
| 69 | if (len != 4) { | ||
| 70 | fprintf(stderr, "strlcpy: failed large buffer test (2a)\n"); | ||
| 71 | failures++; | ||
| 72 | } | ||
| 73 | /* Make sure we only wrote where expected. */ | ||
| 74 | if (memcmp(buf, "abcd", sizeof("abcd")) != 0) { | ||
| 75 | fprintf(stderr, "strlcpy: failed large buffer test (2b)\n"); | ||
| 76 | failures++; | ||
| 77 | } | ||
| 78 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
| 79 | if (*cp != 'z') { | ||
| 80 | fprintf(stderr, | ||
| 81 | "strlcpy: failed large buffer test (2c)\n"); | ||
| 82 | failures++; | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | /* Test copying large string to a small buffer. */ | ||
| 88 | memset(buf, 'z', bufsize); | ||
| 89 | memset(buf2, 'x', bufsize - 1); | ||
| 90 | buf2[bufsize - 1] = '\0'; | ||
| 91 | len = strlcpy(buf, buf2, bufsize / 2); | ||
| 92 | if (len != bufsize - 1) { | ||
| 93 | fprintf(stderr, "strlcpy: failed small buffer test (3a)\n"); | ||
| 94 | failures++; | ||
| 95 | } | ||
| 96 | /* Make sure we only wrote where expected. */ | ||
| 97 | len = (bufsize / 2) - 1; | ||
| 98 | if (memcmp(buf, buf2, len) != 0 || buf[len] != '\0') { | ||
| 99 | fprintf(stderr, "strlcpy: failed small buffer test (3b)\n"); | ||
| 100 | failures++; | ||
| 101 | } | ||
| 102 | for (cp = buf + len + 1; cp < ep; cp++) { | ||
| 103 | if (*cp != 'z') { | ||
| 104 | fprintf(stderr, | ||
| 105 | "strlcpy: failed small buffer test (3c)\n"); | ||
| 106 | failures++; | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | /* Test copying to a 1-byte buffer. */ | ||
| 112 | memset(buf, 'z', bufsize); | ||
| 113 | len = strlcpy(buf, "abcd", 1); | ||
| 114 | if (len != 4) { | ||
| 115 | fprintf(stderr, "strlcpy: failed 1-byte buffer test (4a)\n"); | ||
| 116 | failures++; | ||
| 117 | } | ||
| 118 | /* Make sure we only wrote where expected. */ | ||
| 119 | if (buf[0] != '\0') { | ||
| 120 | fprintf(stderr, "strlcpy: failed 1-byte buffer test (4b)\n"); | ||
| 121 | failures++; | ||
| 122 | } | ||
| 123 | for (cp = buf + 1; cp < ep; cp++) { | ||
| 124 | if (*cp != 'z') { | ||
| 125 | fprintf(stderr, | ||
| 126 | "strlcpy: failed 1-byte buffer test (4c)\n"); | ||
| 127 | failures++; | ||
| 128 | break; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | /* | ||
| 133 | * The following tests should result in SIGSEGV, however some | ||
| 134 | * systems may erroneously report SIGBUS. | ||
| 135 | * These tests assume that strlcpy() is signal-safe. | ||
| 136 | */ | ||
| 137 | memset(&sa, 0, sizeof(sa)); | ||
| 138 | sigemptyset(&sa.sa_mask); | ||
| 139 | sa.sa_handler = handler; | ||
| 140 | sigaction(SIGSEGV, &sa, NULL); | ||
| 141 | sigaction(SIGBUS, &sa, NULL); | ||
| 142 | |||
| 143 | /* Test copying to a NULL buffer with non-zero size. */ | ||
| 144 | got_signal = 0; | ||
| 145 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
| 146 | len = strlcpy(NULL, "abcd", sizeof(buf)); | ||
| 147 | fprintf(stderr, "strlcpy: failed NULL dst test (5a), " | ||
| 148 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
| 149 | failures++; | ||
| 150 | } else if (got_signal != SIGSEGV) { | ||
| 151 | fprintf(stderr, "strlcpy: failed NULL dst test (5b), " | ||
| 152 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
| 153 | failures++; | ||
| 154 | } | ||
| 155 | |||
| 156 | /* Test copying from a NULL src. */ | ||
| 157 | got_signal = 0; | ||
| 158 | if (sigsetjmp(jmpenv, 1) == 0) { | ||
| 159 | len = strlcpy(buf, NULL, sizeof(buf)); | ||
| 160 | fprintf(stderr, "strlcpy: failed NULL src test (6a), " | ||
| 161 | "expected signal %d, got len %zu\n", SIGSEGV, len); | ||
| 162 | failures++; | ||
| 163 | } else if (got_signal != SIGSEGV) { | ||
| 164 | fprintf(stderr, "strlcpy: failed NULL src test (6b), " | ||
| 165 | "expected signal %d, got %d\n", SIGSEGV, got_signal); | ||
| 166 | failures++; | ||
| 167 | } | ||
| 168 | |||
| 169 | return failures; | ||
| 170 | } | ||
diff --git a/src/regress/lib/libc/strnlen/Makefile b/src/regress/lib/libc/strnlen/Makefile deleted file mode 100644 index e7c74972e1..0000000000 --- a/src/regress/lib/libc/strnlen/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2010/06/02 12:20:47 millert Exp $ | ||
| 2 | |||
| 3 | PROG= strnlentest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strnlen/strnlentest.c b/src/regress/lib/libc/strnlen/strnlentest.c deleted file mode 100644 index e67e6adfb8..0000000000 --- a/src/regress/lib/libc/strnlen/strnlentest.c +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | /* $OpenBSD: strnlentest.c,v 1.1 2010/06/02 12:20:47 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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 <sys/types.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | int main(int argc, char *argv[]) | ||
| 27 | { | ||
| 28 | char *buf; | ||
| 29 | int failures = 0; | ||
| 30 | size_t len, bufsize; | ||
| 31 | |||
| 32 | /* Enable malloc security options. */ | ||
| 33 | setenv("MALLOC_OPTIONS", "S", 0); | ||
| 34 | |||
| 35 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
| 36 | buf = malloc(bufsize); | ||
| 37 | if (buf == NULL) { | ||
| 38 | fprintf(stderr, "unable to allocate memory\n"); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | memset(buf, 'a', bufsize); | ||
| 42 | |||
| 43 | len = strnlen(buf, bufsize); | ||
| 44 | if (len != bufsize) { | ||
| 45 | fprintf(stderr, "strnlen: failed unterminated buffer test (1)"); | ||
| 46 | failures++; | ||
| 47 | } | ||
| 48 | |||
| 49 | len = strnlen(buf, bufsize / 2); | ||
| 50 | if (len != bufsize / 2) { | ||
| 51 | fprintf(stderr, "strnlen: failed unterminated buffer test (2)"); | ||
| 52 | failures++; | ||
| 53 | } | ||
| 54 | |||
| 55 | buf[bufsize - 1] = '\0'; | ||
| 56 | len = strnlen(buf, bufsize); | ||
| 57 | if (len != bufsize - 1) { | ||
| 58 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (1)"); | ||
| 59 | failures++; | ||
| 60 | } | ||
| 61 | |||
| 62 | len = strnlen(buf, (size_t)-1); | ||
| 63 | if (len != bufsize - 1) { | ||
| 64 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (2)"); | ||
| 65 | failures++; | ||
| 66 | } | ||
| 67 | |||
| 68 | return failures; | ||
| 69 | } | ||
diff --git a/src/regress/lib/libc/strtod/Makefile b/src/regress/lib/libc/strtod/Makefile deleted file mode 100644 index 030c0e7f56..0000000000 --- a/src/regress/lib/libc/strtod/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2006/09/29 11:00:24 otto Exp $ | ||
| 2 | |||
| 3 | PROG= strtodtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtod/strtodtest.c b/src/regress/lib/libc/strtod/strtodtest.c deleted file mode 100644 index 570a002b18..0000000000 --- a/src/regress/lib/libc/strtod/strtodtest.c +++ /dev/null | |||
| @@ -1,23 +0,0 @@ | |||
| 1 | /* $OpenBSD: strtodtest.c,v 1.2 2017/02/25 07:28:32 jsg Exp $ */ | ||
| 2 | /* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */ | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <err.h> | ||
| 8 | |||
| 9 | /* | ||
| 10 | * Checks if strtod() reports underflow. | ||
| 11 | */ | ||
| 12 | |||
| 13 | int | ||
| 14 | main() | ||
| 15 | { | ||
| 16 | char *tmp="0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"; | ||
| 17 | double d; | ||
| 18 | |||
| 19 | d = strtod(tmp, NULL); | ||
| 20 | if (errno != ERANGE) | ||
| 21 | errx(1, "errno = %d", errno); | ||
| 22 | return (0); | ||
| 23 | } | ||
diff --git a/src/regress/lib/libc/strtol/Makefile b/src/regress/lib/libc/strtol/Makefile deleted file mode 100644 index 3e2f4c746d..0000000000 --- a/src/regress/lib/libc/strtol/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2012/11/18 04:11:09 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= strtoltest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtol/strtoltest.c b/src/regress/lib/libc/strtol/strtoltest.c deleted file mode 100644 index 2efd7b3ad1..0000000000 --- a/src/regress/lib/libc/strtol/strtoltest.c +++ /dev/null | |||
| @@ -1,81 +0,0 @@ | |||
| 1 | /* $OpenBSD: strtoltest.c,v 1.4 2017/07/15 17:08:26 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <errno.h> | ||
| 19 | #include <limits.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <string.h> | ||
| 23 | |||
| 24 | struct strtol_test { | ||
| 25 | char *input; | ||
| 26 | long output; | ||
| 27 | char end; | ||
| 28 | int base; | ||
| 29 | int err; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct strtol_test strtol_tests[] = { | ||
| 33 | {"1234567890", 1234567890L, '\0', 0, 0}, | ||
| 34 | {"0755", 493L, '\0', 0, 0}, | ||
| 35 | {"0x7fFFffFf", 2147483647L, '\0', 0, 0}, | ||
| 36 | {"1234567890", 0L, '1', 1, EINVAL}, | ||
| 37 | {"10101010", 170L, '\0', 2, 0}, | ||
| 38 | {"755", 493L, '\0', 8, 0}, | ||
| 39 | {"1234567890", 1234567890L, '\0', 10, 0}, | ||
| 40 | {"abc", 0L, 'a', 10, 0}, | ||
| 41 | {"123xyz", 123L, 'x', 10, 0}, | ||
| 42 | {"-080000000", -2147483648L, '\0', 16, 0}, | ||
| 43 | {"deadbeefdeadbeef", LONG_MAX, '\0', 16, ERANGE}, | ||
| 44 | {"deadzbeef", 57005L, 'z', 16, 0}, | ||
| 45 | {"0xy", 0L, 'x', 16, 0}, | ||
| 46 | {"-quitebigmchuge", LONG_MIN, '\0', 32, ERANGE}, | ||
| 47 | {"zzz", 46655L, '\0', 36, 0}, | ||
| 48 | {"1234567890", 0L, '1', 37, EINVAL}, | ||
| 49 | {"1234567890", 0L, '1', 123, EINVAL}, | ||
| 50 | }; | ||
| 51 | |||
| 52 | int | ||
| 53 | main(int argc, char **argv) | ||
| 54 | { | ||
| 55 | struct strtol_test *test; | ||
| 56 | int failure = 0; | ||
| 57 | char *end; | ||
| 58 | u_int i; | ||
| 59 | long n; | ||
| 60 | |||
| 61 | for (i = 0; i < (sizeof(strtol_tests) / sizeof(strtol_tests[0])); i++) { | ||
| 62 | test = &strtol_tests[i]; | ||
| 63 | errno = 0; | ||
| 64 | n = strtol(test->input, &end, test->base); | ||
| 65 | if (n != test->output) { | ||
| 66 | fprintf(stderr, "TEST %i FAILED: %s base %i: %li\n", | ||
| 67 | i, test->input, test->base, n); | ||
| 68 | failure = 1; | ||
| 69 | } else if (*end != test->end) { | ||
| 70 | fprintf(stderr, "TEST %i FAILED: end is not %c: %c\n", | ||
| 71 | i, test->end, *end); | ||
| 72 | failure = 1; | ||
| 73 | } else if (errno != test->err) { | ||
| 74 | fprintf(stderr, "TEST %i FAILED: errno is not %i: %i\n", | ||
| 75 | i, test->err, errno); | ||
| 76 | failure = 1; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | return failure; | ||
| 81 | } | ||
diff --git a/src/regress/lib/libc/strtonum/Makefile b/src/regress/lib/libc/strtonum/Makefile deleted file mode 100644 index e0e8ecd139..0000000000 --- a/src/regress/lib/libc/strtonum/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/08/03 20:38:36 otto Exp $ | ||
| 2 | |||
| 3 | PROG= strtonumtest | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtonum/strtonumtest.c b/src/regress/lib/libc/strtonum/strtonumtest.c deleted file mode 100644 index 7e82a007fe..0000000000 --- a/src/regress/lib/libc/strtonum/strtonumtest.c +++ /dev/null | |||
| @@ -1,64 +0,0 @@ | |||
| 1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <limits.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | |||
| 22 | int fail; | ||
| 23 | |||
| 24 | void | ||
| 25 | test(const char *p, long long lb, long long ub, int ok) | ||
| 26 | { | ||
| 27 | long long val; | ||
| 28 | const char *q; | ||
| 29 | |||
| 30 | val = strtonum(p, lb, ub, &q); | ||
| 31 | if (ok && q != NULL) { | ||
| 32 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
| 33 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
| 34 | fail = 1; | ||
| 35 | } else if (!ok && q == NULL) { | ||
| 36 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
| 37 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
| 38 | fail = 1; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | int main(int argc, char *argv[]) | ||
| 43 | { | ||
| 44 | test("1", 0, 10, 1); | ||
| 45 | test("0", -2, 5, 1); | ||
| 46 | test("0", 2, 5, 0); | ||
| 47 | test("0", 2, LLONG_MAX, 0); | ||
| 48 | test("-2", 0, LLONG_MAX, 0); | ||
| 49 | test("0", -5, LLONG_MAX, 1); | ||
| 50 | test("-3", -3, LLONG_MAX, 1); | ||
| 51 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
| 52 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
| 53 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
| 54 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
| 55 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 56 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
| 57 | test("-2", 10, -1, 0); | ||
| 58 | test("-2", -10, -1, 1); | ||
| 59 | test("-20", -10, -1, 0); | ||
| 60 | test("20", -10, -1, 0); | ||
| 61 | |||
| 62 | return (fail); | ||
| 63 | } | ||
| 64 | |||
diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile deleted file mode 100644 index 728ae90e1e..0000000000 --- a/src/regress/lib/libc/telldir/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2013/11/03 00:20:24 schwarze Exp $ | ||
| 2 | |||
| 3 | PROG = telldir | ||
| 4 | SRCS = utils.c shortseek.c telldir.c main.c | ||
| 5 | |||
| 6 | cleandir: | ||
| 7 | rm -rf d | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/telldir/main.c b/src/regress/lib/libc/telldir/main.c deleted file mode 100644 index 23ffa65dbf..0000000000 --- a/src/regress/lib/libc/telldir/main.c +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
| 4 | |||
| 5 | void shortseek(void); | ||
| 6 | void longseek(void); | ||
| 7 | |||
| 8 | int | ||
| 9 | main(void) | ||
| 10 | { | ||
| 11 | shortseek(); | ||
| 12 | longseek(); | ||
| 13 | return(0); | ||
| 14 | } | ||
diff --git a/src/regress/lib/libc/telldir/shortseek.c b/src/regress/lib/libc/telldir/shortseek.c deleted file mode 100644 index 9b2141ab4c..0000000000 --- a/src/regress/lib/libc/telldir/shortseek.c +++ /dev/null | |||
| @@ -1,91 +0,0 @@ | |||
| 1 | /* $OpenBSD: shortseek.c,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | /* Modified by Ingo Schwarze, 2013, Public domain. */ | ||
| 5 | |||
| 6 | #include <sys/types.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #include "utils.h" | ||
| 14 | |||
| 15 | #define NFILES 5 | ||
| 16 | |||
| 17 | static void | ||
| 18 | shortloop(DIR *dp, int iend, int iback) | ||
| 19 | { | ||
| 20 | struct dirent *f; | ||
| 21 | char fend[PATH_MAX], fback[PATH_MAX]; | ||
| 22 | long pos, t, remember = -1; | ||
| 23 | int i; | ||
| 24 | |||
| 25 | rewinddir(dp); | ||
| 26 | snprintf(fend, sizeof fend, "%d", iend); | ||
| 27 | snprintf(fback, sizeof fback, "%d", iback); | ||
| 28 | |||
| 29 | /* Scan to iend, remember where iback is. */ | ||
| 30 | |||
| 31 | for (;;) { | ||
| 32 | pos = telldir(dp); | ||
| 33 | f = readdir(dp); | ||
| 34 | if (f == NULL) | ||
| 35 | errx(1, "file %s not found", fend); | ||
| 36 | if (strcmp(fback, f->d_name) == 0) | ||
| 37 | remember = pos; | ||
| 38 | if (strcmp(fend, f->d_name) == 0) | ||
| 39 | break; | ||
| 40 | } | ||
| 41 | if (remember == -1) | ||
| 42 | errx(1, "file %s not found", fback); | ||
| 43 | |||
| 44 | /* Go back to iback, checking seekdir, telldir and readdir. */ | ||
| 45 | |||
| 46 | seekdir(dp, remember); | ||
| 47 | if ((t = telldir(dp)) != remember) | ||
| 48 | errx(1, "tell after seek %s %ld != %ld", fback, t, remember); | ||
| 49 | if ((t = telldir(dp)) != remember) | ||
| 50 | errx(1, "tell after tell %s %ld != %ld", fback, t, remember); | ||
| 51 | f = readdir(dp); | ||
| 52 | if (f == NULL) | ||
| 53 | errx(1, "readdir %s at %ld", fback, remember); | ||
| 54 | |||
| 55 | if (strcmp(f->d_name, fback)) | ||
| 56 | errx(1, "name mismatch: %s != %s", f->d_name, fback); | ||
| 57 | |||
| 58 | /* Check that readdir can iterate the remaining files. */ | ||
| 59 | |||
| 60 | for (i = iback + 1; i < NFILES; i++) { | ||
| 61 | f = readdir(dp); | ||
| 62 | if (f == NULL) | ||
| 63 | errx(1, "readdir %i failed", i); | ||
| 64 | } | ||
| 65 | |||
| 66 | /* Check that readdir stops at the right place. */ | ||
| 67 | |||
| 68 | f = readdir(dp); | ||
| 69 | if (f != NULL) | ||
| 70 | errx(1, "readdir %i returned %s", NFILES, f->d_name); | ||
| 71 | } | ||
| 72 | |||
| 73 | void | ||
| 74 | shortseek(void) | ||
| 75 | { | ||
| 76 | DIR *dp; | ||
| 77 | int iend, iback; | ||
| 78 | |||
| 79 | createfiles(NFILES); | ||
| 80 | |||
| 81 | dp = opendir("d"); | ||
| 82 | if (dp == NULL) | ||
| 83 | err(1, "shortseek: opendir"); | ||
| 84 | |||
| 85 | for (iend = 0; iend < NFILES; iend++) | ||
| 86 | for (iback = 0; iback <= iend; iback++) | ||
| 87 | shortloop(dp, iend, iback); | ||
| 88 | |||
| 89 | closedir(dp); | ||
| 90 | delfiles(); | ||
| 91 | } | ||
diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c deleted file mode 100644 index d2879cc701..0000000000 --- a/src/regress/lib/libc/telldir/telldir.c +++ /dev/null | |||
| @@ -1,71 +0,0 @@ | |||
| 1 | /* $OpenBSD: telldir.c,v 1.4 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <dirent.h> | ||
| 7 | #include <err.h> | ||
| 8 | #include <limits.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | #include "utils.h" | ||
| 13 | |||
| 14 | #define NFILES 1000 | ||
| 15 | |||
| 16 | static void | ||
| 17 | longloop(DIR *dp, int i) | ||
| 18 | { | ||
| 19 | struct dirent *f; | ||
| 20 | char file[PATH_MAX]; | ||
| 21 | long pos, t, remember = -1; | ||
| 22 | |||
| 23 | rewinddir(dp); | ||
| 24 | snprintf(file, sizeof file, "%d", i); | ||
| 25 | |||
| 26 | /* Scan through all files, remember where file i is. */ | ||
| 27 | |||
| 28 | for (;;) { | ||
| 29 | pos = telldir(dp); | ||
| 30 | f = readdir(dp); | ||
| 31 | if (f == NULL) | ||
| 32 | break; | ||
| 33 | if (strcmp(file, f->d_name) == 0) | ||
| 34 | remember = pos; | ||
| 35 | } | ||
| 36 | if (remember == -1) | ||
| 37 | errx(1, "remember %s", file); | ||
| 38 | |||
| 39 | /* Go back to i, checking seekdir, telldir and readdir. */ | ||
| 40 | |||
| 41 | seekdir(dp, remember); | ||
| 42 | if ((t = telldir(dp)) != remember) | ||
| 43 | errx(1, "tell after seek %s %ld != %ld", file, t, remember); | ||
| 44 | if ((t = telldir(dp)) != remember) | ||
| 45 | errx(1, "tell after tell %s %ld != %ld", file, t, remember); | ||
| 46 | f = readdir(dp); | ||
| 47 | if (f == NULL) | ||
| 48 | errx(1, "readdir %s at %ld", file, remember); | ||
| 49 | |||
| 50 | if (strcmp(f->d_name, file) != 0) | ||
| 51 | errx(1, "name mismatch: %s != %s", f->d_name, file); | ||
| 52 | } | ||
| 53 | |||
| 54 | void | ||
| 55 | longseek(void) | ||
| 56 | { | ||
| 57 | DIR *dp; | ||
| 58 | int i; | ||
| 59 | |||
| 60 | createfiles(NFILES); | ||
| 61 | |||
| 62 | dp = opendir("d"); | ||
| 63 | if (dp == NULL) | ||
| 64 | err(1, "longseek: opendir"); | ||
| 65 | |||
| 66 | for (i = 0; i < NFILES; i++) | ||
| 67 | longloop(dp, (i + NFILES/2) % NFILES); | ||
| 68 | |||
| 69 | closedir(dp); | ||
| 70 | delfiles(); | ||
| 71 | } | ||
diff --git a/src/regress/lib/libc/telldir/utils.c b/src/regress/lib/libc/telldir/utils.c deleted file mode 100644 index 7fb0401d70..0000000000 --- a/src/regress/lib/libc/telldir/utils.c +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | /* $OpenBSD: utils.c,v 1.2 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <err.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <limits.h> | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | |||
| 15 | #include "utils.h" | ||
| 16 | |||
| 17 | void | ||
| 18 | createfiles(int nfiles) | ||
| 19 | { | ||
| 20 | int i, fd; | ||
| 21 | char file[PATH_MAX]; | ||
| 22 | |||
| 23 | mkdir("d", 0755); | ||
| 24 | for (i = 0; i < nfiles; i++) { | ||
| 25 | snprintf(file, sizeof file, "d/%d", i); | ||
| 26 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
| 27 | err(1, "open %s", file); | ||
| 28 | close(fd); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | void | ||
| 33 | delfiles(void) | ||
| 34 | { | ||
| 35 | DIR *dp; | ||
| 36 | struct dirent *f; | ||
| 37 | char file[PATH_MAX]; | ||
| 38 | |||
| 39 | dp = opendir("d"); | ||
| 40 | if (dp == NULL) | ||
| 41 | err(1, "opendir"); | ||
| 42 | while ((f = readdir(dp))) { | ||
| 43 | if (strcmp(f->d_name, ".") == 0 || | ||
| 44 | strcmp(f->d_name, "..") == 0) | ||
| 45 | continue; | ||
| 46 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
| 47 | if (unlink(file) == -1) | ||
| 48 | err(1, "unlink %s", f->d_name); | ||
| 49 | } | ||
| 50 | closedir(dp); | ||
| 51 | if (rmdir("d") == -1) | ||
| 52 | err(1, "rmdir"); | ||
| 53 | } | ||
diff --git a/src/regress/lib/libc/telldir/utils.h b/src/regress/lib/libc/telldir/utils.h deleted file mode 100644 index 74ffcd4641..0000000000 --- a/src/regress/lib/libc/telldir/utils.h +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | /* $OpenBSD: utils.h,v 1.1 2013/11/03 00:20:24 schwarze Exp $ */ | ||
| 2 | |||
| 3 | /* Written by Ingo Schwarze, 2013, Public domain. */ | ||
| 4 | |||
| 5 | void createfiles(int); | ||
| 6 | void delfiles(void); | ||
diff --git a/src/regress/lib/libc/time/Makefile b/src/regress/lib/libc/time/Makefile deleted file mode 100644 index 28b5556027..0000000000 --- a/src/regress/lib/libc/time/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2004/01/20 16:47:55 millert Exp $ | ||
| 2 | |||
| 3 | SUBDIR+=strptime | ||
| 4 | |||
| 5 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/Makefile b/src/regress/lib/libc/time/strptime/Makefile deleted file mode 100644 index 1e1565ced4..0000000000 --- a/src/regress/lib/libc/time/strptime/Makefile +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2012/12/16 18:28:53 jasper Exp $ | ||
| 2 | |||
| 3 | PROG= strptime_test | ||
| 4 | SRCS= main.c | ||
| 5 | CLEANFILES+= got | ||
| 6 | |||
| 7 | REGRESS_TARGETS=do-reg | ||
| 8 | do-reg: ${PROG} | ||
| 9 | ./${PROG} < ${.CURDIR}/tests > got | ||
| 10 | diff -u ${.CURDIR}/expected got | ||
| 11 | |||
| 12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/expected b/src/regress/lib/libc/time/strptime/expected deleted file mode 100644 index 21c95de7f9..0000000000 --- a/src/regress/lib/libc/time/strptime/expected +++ /dev/null | |||
| @@ -1,346 +0,0 @@ | |||
| 1 | --- ctime --- 1 | ||
| 2 | succeeded | ||
| 3 | 46 27 23 20 0 98 2 19 | ||
| 4 | |||
| 5 | --- ctime --- 2 | ||
| 6 | succeeded | ||
| 7 | 46 27 23 20 0 98 2 19 | ||
| 8 | |||
| 9 | --- ctime --- 3 | ||
| 10 | succeeded | ||
| 11 | 46 27 23 20 0 98 2 19 | ||
| 12 | |||
| 13 | --- %a --- 1 | ||
| 14 | succeeded | ||
| 15 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 16 | |||
| 17 | --- %a --- 2 | ||
| 18 | succeeded | ||
| 19 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 20 | |||
| 21 | --- %a --- 3 | ||
| 22 | succeeded | ||
| 23 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 24 | |||
| 25 | --- %a --- 4 | ||
| 26 | succeeded | ||
| 27 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 28 | |||
| 29 | --- %a --- 5 | ||
| 30 | succeeded | ||
| 31 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 32 | |||
| 33 | --- %a --- 6 | ||
| 34 | succeeded | ||
| 35 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 36 | |||
| 37 | --- %a --- 7 | ||
| 38 | succeeded | ||
| 39 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 40 | |||
| 41 | --- %a --- 8 | ||
| 42 | succeeded | ||
| 43 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 44 | |||
| 45 | --- %a --- 9 | ||
| 46 | succeeded | ||
| 47 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 48 | |||
| 49 | --- %a --- 10 | ||
| 50 | succeeded | ||
| 51 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 52 | |||
| 53 | --- %a --- 11 | ||
| 54 | succeeded | ||
| 55 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 56 | |||
| 57 | --- %a --- 12 | ||
| 58 | succeeded | ||
| 59 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 60 | |||
| 61 | --- %a --- 13 | ||
| 62 | succeeded | ||
| 63 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 64 | |||
| 65 | --- %a --- 14 | ||
| 66 | succeeded | ||
| 67 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 68 | |||
| 69 | --- %a --- 15 | ||
| 70 | succeeded | ||
| 71 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 72 | urn | ||
| 73 | |||
| 74 | --- %a --- 16 | ||
| 75 | failed | ||
| 76 | --- %A --- 1 | ||
| 77 | succeeded | ||
| 78 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 79 | |||
| 80 | --- %A --- 2 | ||
| 81 | succeeded | ||
| 82 | -1 -1 -1 -1 -1 -1 0 -1 | ||
| 83 | |||
| 84 | --- %A --- 3 | ||
| 85 | succeeded | ||
| 86 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 87 | |||
| 88 | --- %A --- 4 | ||
| 89 | succeeded | ||
| 90 | -1 -1 -1 -1 -1 -1 1 -1 | ||
| 91 | |||
| 92 | --- %A --- 5 | ||
| 93 | succeeded | ||
| 94 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 95 | |||
| 96 | --- %A --- 6 | ||
| 97 | succeeded | ||
| 98 | -1 -1 -1 -1 -1 -1 2 -1 | ||
| 99 | |||
| 100 | --- %A --- 7 | ||
| 101 | succeeded | ||
| 102 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 103 | |||
| 104 | --- %A --- 8 | ||
| 105 | succeeded | ||
| 106 | -1 -1 -1 -1 -1 -1 3 -1 | ||
| 107 | |||
| 108 | --- %A --- 9 | ||
| 109 | succeeded | ||
| 110 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 111 | |||
| 112 | --- %A --- 10 | ||
| 113 | succeeded | ||
| 114 | -1 -1 -1 -1 -1 -1 4 -1 | ||
| 115 | |||
| 116 | --- %A --- 11 | ||
| 117 | succeeded | ||
| 118 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 119 | |||
| 120 | --- %A --- 12 | ||
| 121 | succeeded | ||
| 122 | -1 -1 -1 -1 -1 -1 5 -1 | ||
| 123 | |||
| 124 | --- %A --- 13 | ||
| 125 | succeeded | ||
| 126 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 127 | |||
| 128 | --- %A --- 14 | ||
| 129 | succeeded | ||
| 130 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 131 | |||
| 132 | --- %A --- 15 | ||
| 133 | succeeded | ||
| 134 | -1 -1 -1 -1 -1 -1 6 -1 | ||
| 135 | urn | ||
| 136 | |||
| 137 | --- %A --- 16 | ||
| 138 | failed | ||
| 139 | --- %b --- 1 | ||
| 140 | succeeded | ||
| 141 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 142 | |||
| 143 | --- %b --- 2 | ||
| 144 | succeeded | ||
| 145 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 146 | |||
| 147 | --- %b --- 3 | ||
| 148 | succeeded | ||
| 149 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 150 | |||
| 151 | --- %b --- 4 | ||
| 152 | succeeded | ||
| 153 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 154 | |||
| 155 | --- %b --- 5 | ||
| 156 | succeeded | ||
| 157 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 158 | |||
| 159 | --- %b --- 6 | ||
| 160 | succeeded | ||
| 161 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 162 | |||
| 163 | --- %b --- 7 | ||
| 164 | succeeded | ||
| 165 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 166 | |||
| 167 | --- %b --- 8 | ||
| 168 | succeeded | ||
| 169 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 170 | |||
| 171 | --- %b --- 9 | ||
| 172 | succeeded | ||
| 173 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 174 | |||
| 175 | --- %b --- 10 | ||
| 176 | succeeded | ||
| 177 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 178 | |||
| 179 | --- %b --- 11 | ||
| 180 | succeeded | ||
| 181 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 182 | |||
| 183 | --- %b --- 12 | ||
| 184 | succeeded | ||
| 185 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 186 | |||
| 187 | --- %b --- 13 | ||
| 188 | succeeded | ||
| 189 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 190 | |||
| 191 | --- %b --- 14 | ||
| 192 | succeeded | ||
| 193 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 194 | |||
| 195 | --- %b --- 15 | ||
| 196 | succeeded | ||
| 197 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 198 | |||
| 199 | --- %b --- 16 | ||
| 200 | succeeded | ||
| 201 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 202 | |||
| 203 | --- %b --- 17 | ||
| 204 | succeeded | ||
| 205 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 206 | |||
| 207 | --- %b --- 18 | ||
| 208 | succeeded | ||
| 209 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 210 | |||
| 211 | --- %b --- 19 | ||
| 212 | succeeded | ||
| 213 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 214 | |||
| 215 | --- %b --- 20 | ||
| 216 | succeeded | ||
| 217 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 218 | |||
| 219 | --- %b --- 21 | ||
| 220 | succeeded | ||
| 221 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 222 | |||
| 223 | --- %b --- 22 | ||
| 224 | succeeded | ||
| 225 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 226 | |||
| 227 | --- %b --- 23 | ||
| 228 | succeeded | ||
| 229 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 230 | |||
| 231 | --- %b --- 25 | ||
| 232 | succeeded | ||
| 233 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 234 | or | ||
| 235 | |||
| 236 | --- %b --- 24 | ||
| 237 | succeeded | ||
| 238 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 239 | s | ||
| 240 | |||
| 241 | --- %b --- 26 | ||
| 242 | failed | ||
| 243 | --- %B --- 1 | ||
| 244 | succeeded | ||
| 245 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 246 | |||
| 247 | --- %B --- 2 | ||
| 248 | succeeded | ||
| 249 | -1 -1 -1 -1 0 -1 -1 -1 | ||
| 250 | |||
| 251 | --- %B --- 3 | ||
| 252 | succeeded | ||
| 253 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 254 | |||
| 255 | --- %B --- 4 | ||
| 256 | succeeded | ||
| 257 | -1 -1 -1 -1 1 -1 -1 -1 | ||
| 258 | |||
| 259 | --- %B --- 5 | ||
| 260 | succeeded | ||
| 261 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 262 | |||
| 263 | --- %B --- 6 | ||
| 264 | succeeded | ||
| 265 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 266 | |||
| 267 | --- %B --- 7 | ||
| 268 | succeeded | ||
| 269 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 270 | |||
| 271 | --- %B --- 8 | ||
| 272 | succeeded | ||
| 273 | -1 -1 -1 -1 3 -1 -1 -1 | ||
| 274 | |||
| 275 | --- %B --- 9 | ||
| 276 | succeeded | ||
| 277 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 278 | |||
| 279 | --- %B --- 10 | ||
| 280 | succeeded | ||
| 281 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 282 | |||
| 283 | --- %B --- 11 | ||
| 284 | succeeded | ||
| 285 | -1 -1 -1 -1 5 -1 -1 -1 | ||
| 286 | |||
| 287 | --- %B --- 12 | ||
| 288 | succeeded | ||
| 289 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 290 | |||
| 291 | --- %B --- 13 | ||
| 292 | succeeded | ||
| 293 | -1 -1 -1 -1 6 -1 -1 -1 | ||
| 294 | |||
| 295 | --- %B --- 14 | ||
| 296 | succeeded | ||
| 297 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 298 | |||
| 299 | --- %B --- 15 | ||
| 300 | succeeded | ||
| 301 | -1 -1 -1 -1 7 -1 -1 -1 | ||
| 302 | |||
| 303 | --- %B --- 16 | ||
| 304 | succeeded | ||
| 305 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 306 | |||
| 307 | --- %B --- 17 | ||
| 308 | succeeded | ||
| 309 | -1 -1 -1 -1 8 -1 -1 -1 | ||
| 310 | |||
| 311 | --- %B --- 18 | ||
| 312 | succeeded | ||
| 313 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 314 | |||
| 315 | --- %B --- 19 | ||
| 316 | succeeded | ||
| 317 | -1 -1 -1 -1 9 -1 -1 -1 | ||
| 318 | |||
| 319 | --- %B --- 20 | ||
| 320 | succeeded | ||
| 321 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 322 | |||
| 323 | --- %B --- 21 | ||
| 324 | succeeded | ||
| 325 | -1 -1 -1 -1 10 -1 -1 -1 | ||
| 326 | |||
| 327 | --- %B --- 22 | ||
| 328 | succeeded | ||
| 329 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 330 | |||
| 331 | --- %B --- 23 | ||
| 332 | succeeded | ||
| 333 | -1 -1 -1 -1 11 -1 -1 -1 | ||
| 334 | |||
| 335 | --- %B --- 25 | ||
| 336 | succeeded | ||
| 337 | -1 -1 -1 -1 4 -1 -1 -1 | ||
| 338 | or | ||
| 339 | |||
| 340 | --- %B --- 24 | ||
| 341 | succeeded | ||
| 342 | -1 -1 -1 -1 2 -1 -1 -1 | ||
| 343 | s | ||
| 344 | |||
| 345 | --- %B --- 26 | ||
| 346 | failed | ||
diff --git a/src/regress/lib/libc/time/strptime/main.c b/src/regress/lib/libc/time/strptime/main.c deleted file mode 100644 index c4e06a9b59..0000000000 --- a/src/regress/lib/libc/time/strptime/main.c +++ /dev/null | |||
| @@ -1,110 +0,0 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.2 2008/06/26 05:42:05 ray Exp $ */ | ||
| 2 | /* $NetBSD: main.c,v 1.4 2002/02/21 07:38:18 itojun Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * 1. Redistributions of source code must retain the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer. | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in the | ||
| 15 | * documentation and/or other materials provided with the distribution. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | #include <err.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | #include <time.h> | ||
| 34 | |||
| 35 | int main(int, char *[]); | ||
| 36 | void die(void); | ||
| 37 | |||
| 38 | void | ||
| 39 | die(void) | ||
| 40 | { | ||
| 41 | |||
| 42 | if (ferror(stdin)) | ||
| 43 | err(1, "fgetln"); | ||
| 44 | else | ||
| 45 | errx(1, "input is truncated"); | ||
| 46 | } | ||
| 47 | |||
| 48 | int | ||
| 49 | main(int argc, char *argv[]) | ||
| 50 | { | ||
| 51 | char *p, *title, *buf, *format; | ||
| 52 | size_t len; | ||
| 53 | struct tm tm; | ||
| 54 | |||
| 55 | for (;;) { | ||
| 56 | p = fgetln(stdin, &len); | ||
| 57 | if (p == 0) | ||
| 58 | die(); | ||
| 59 | title = malloc(len + 1); | ||
| 60 | memcpy(title, p, len); | ||
| 61 | title[len] = '\0'; | ||
| 62 | |||
| 63 | if (!strcmp(title, "EOF\n")) | ||
| 64 | return(0); | ||
| 65 | if (title[0] == '#' || title[0] == '\n') { | ||
| 66 | free(title); | ||
| 67 | continue; | ||
| 68 | } | ||
| 69 | |||
| 70 | p = fgetln(stdin, &len); | ||
| 71 | if (p == 0) | ||
| 72 | die(); | ||
| 73 | buf = malloc(len + 1); | ||
| 74 | memcpy(buf, p, len); | ||
| 75 | buf[len] = '\0'; | ||
| 76 | |||
| 77 | p = fgetln(stdin, &len); | ||
| 78 | if (p == 0) | ||
| 79 | die(); | ||
| 80 | format = malloc(len + 1); | ||
| 81 | memcpy(format, p, len); | ||
| 82 | format[len] = '\0'; | ||
| 83 | |||
| 84 | tm.tm_sec = -1; | ||
| 85 | tm.tm_min = -1; | ||
| 86 | tm.tm_hour = -1; | ||
| 87 | tm.tm_mday = -1; | ||
| 88 | tm.tm_mon = -1; | ||
| 89 | tm.tm_year = -1; | ||
| 90 | tm.tm_wday = -1; | ||
| 91 | tm.tm_yday = -1; | ||
| 92 | |||
| 93 | p = strptime(buf, format, &tm); | ||
| 94 | |||
| 95 | printf("%s", title); | ||
| 96 | if (p) { | ||
| 97 | printf("succeeded\n"); | ||
| 98 | printf("%d %d %d %d %d %d %d %d\n", | ||
| 99 | tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, | ||
| 100 | tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday); | ||
| 101 | printf("%s\n", p); | ||
| 102 | } else { | ||
| 103 | printf("failed\n"); | ||
| 104 | } | ||
| 105 | |||
| 106 | free(title); | ||
| 107 | free(buf); | ||
| 108 | free(format); | ||
| 109 | } | ||
| 110 | } | ||
diff --git a/src/regress/lib/libc/time/strptime/tests b/src/regress/lib/libc/time/strptime/tests deleted file mode 100644 index d96393b2b7..0000000000 --- a/src/regress/lib/libc/time/strptime/tests +++ /dev/null | |||
| @@ -1,267 +0,0 @@ | |||
| 1 | # some intial checks to make sure common things work | ||
| 2 | --- ctime --- 1 | ||
| 3 | Tue Jan 20 23:27:46 1998 | ||
| 4 | %a %b %d %T %Y | ||
| 5 | --- ctime --- 2 | ||
| 6 | Tue Jan 20 23:27:46 1998 | ||
| 7 | %a %b %d %H:%M:%S %Y | ||
| 8 | --- ctime --- 3 | ||
| 9 | Tue Jan 20 23:27:46 1998 | ||
| 10 | %c | ||
| 11 | |||
| 12 | # test some valid and invalid day names | ||
| 13 | --- %a --- 1 | ||
| 14 | Sun | ||
| 15 | %a | ||
| 16 | --- %a --- 2 | ||
| 17 | Sunday | ||
| 18 | %a | ||
| 19 | --- %a --- 3 | ||
| 20 | Mon | ||
| 21 | %a | ||
| 22 | --- %a --- 4 | ||
| 23 | Monday | ||
| 24 | %a | ||
| 25 | --- %a --- 5 | ||
| 26 | Tue | ||
| 27 | %a | ||
| 28 | --- %a --- 6 | ||
| 29 | Tuesday | ||
| 30 | %a | ||
| 31 | --- %a --- 7 | ||
| 32 | Wed | ||
| 33 | %a | ||
| 34 | --- %a --- 8 | ||
| 35 | Wednesday | ||
| 36 | %a | ||
| 37 | --- %a --- 9 | ||
| 38 | Thu | ||
| 39 | %a | ||
| 40 | --- %a --- 10 | ||
| 41 | Thursday | ||
| 42 | %a | ||
| 43 | --- %a --- 11 | ||
| 44 | Fri | ||
| 45 | %a | ||
| 46 | --- %a --- 12 | ||
| 47 | Friday | ||
| 48 | %a | ||
| 49 | --- %a --- 13 | ||
| 50 | Sat | ||
| 51 | %a | ||
| 52 | --- %a --- 14 | ||
| 53 | Saturday | ||
| 54 | %a | ||
| 55 | --- %a --- 15 | ||
| 56 | Saturn | ||
| 57 | %a | ||
| 58 | --- %a --- 16 | ||
| 59 | Moon | ||
| 60 | %a | ||
| 61 | --- %A --- 1 | ||
| 62 | Sun | ||
| 63 | %A | ||
| 64 | --- %A --- 2 | ||
| 65 | Sunday | ||
| 66 | %A | ||
| 67 | --- %A --- 3 | ||
| 68 | Mon | ||
| 69 | %A | ||
| 70 | --- %A --- 4 | ||
| 71 | Monday | ||
| 72 | %A | ||
| 73 | --- %A --- 5 | ||
| 74 | Tue | ||
| 75 | %A | ||
| 76 | --- %A --- 6 | ||
| 77 | Tuesday | ||
| 78 | %A | ||
| 79 | --- %A --- 7 | ||
| 80 | Wed | ||
| 81 | %A | ||
| 82 | --- %A --- 8 | ||
| 83 | Wednesday | ||
| 84 | %A | ||
| 85 | --- %A --- 9 | ||
| 86 | Thu | ||
| 87 | %A | ||
| 88 | --- %A --- 10 | ||
| 89 | Thursday | ||
| 90 | %A | ||
| 91 | --- %A --- 11 | ||
| 92 | Fri | ||
| 93 | %A | ||
| 94 | --- %A --- 12 | ||
| 95 | Friday | ||
| 96 | %A | ||
| 97 | --- %A --- 13 | ||
| 98 | Sat | ||
| 99 | %A | ||
| 100 | --- %A --- 14 | ||
| 101 | Saturday | ||
| 102 | %A | ||
| 103 | --- %A --- 15 | ||
| 104 | Saturn | ||
| 105 | %A | ||
| 106 | --- %A --- 16 | ||
| 107 | Moon | ||
| 108 | %A | ||
| 109 | |||
| 110 | # test some valid and invalid month names | ||
| 111 | --- %b --- 1 | ||
| 112 | Jan | ||
| 113 | %b | ||
| 114 | --- %b --- 2 | ||
| 115 | January | ||
| 116 | %b | ||
| 117 | --- %b --- 3 | ||
| 118 | Feb | ||
| 119 | %b | ||
| 120 | --- %b --- 4 | ||
| 121 | February | ||
| 122 | %b | ||
| 123 | --- %b --- 5 | ||
| 124 | Mar | ||
| 125 | %b | ||
| 126 | --- %b --- 6 | ||
| 127 | March | ||
| 128 | %b | ||
| 129 | --- %b --- 7 | ||
| 130 | Apr | ||
| 131 | %b | ||
| 132 | --- %b --- 8 | ||
| 133 | April | ||
| 134 | %b | ||
| 135 | --- %b --- 9 | ||
| 136 | May | ||
| 137 | %b | ||
| 138 | --- %b --- 10 | ||
| 139 | Jun | ||
| 140 | %b | ||
| 141 | --- %b --- 11 | ||
| 142 | June | ||
| 143 | %b | ||
| 144 | --- %b --- 12 | ||
| 145 | Jul | ||
| 146 | %b | ||
| 147 | --- %b --- 13 | ||
| 148 | July | ||
| 149 | %b | ||
| 150 | --- %b --- 14 | ||
| 151 | Aug | ||
| 152 | %b | ||
| 153 | --- %b --- 15 | ||
| 154 | August | ||
| 155 | %b | ||
| 156 | --- %b --- 16 | ||
| 157 | Sep | ||
| 158 | %b | ||
| 159 | --- %b --- 17 | ||
| 160 | September | ||
| 161 | %b | ||
| 162 | --- %b --- 18 | ||
| 163 | Oct | ||
| 164 | %b | ||
| 165 | --- %b --- 19 | ||
| 166 | October | ||
| 167 | %b | ||
| 168 | --- %b --- 20 | ||
| 169 | Nov | ||
| 170 | %b | ||
| 171 | --- %b --- 21 | ||
| 172 | November | ||
| 173 | %b | ||
| 174 | --- %b --- 22 | ||
| 175 | Dec | ||
| 176 | %b | ||
| 177 | --- %b --- 23 | ||
| 178 | December | ||
| 179 | %b | ||
| 180 | --- %b --- 25 | ||
| 181 | Mayor | ||
| 182 | %b | ||
| 183 | --- %b --- 24 | ||
| 184 | Mars | ||
| 185 | %b | ||
| 186 | --- %b --- 26 | ||
| 187 | Rover | ||
| 188 | %b | ||
| 189 | --- %B --- 1 | ||
| 190 | Jan | ||
| 191 | %B | ||
| 192 | --- %B --- 2 | ||
| 193 | January | ||
| 194 | %B | ||
| 195 | --- %B --- 3 | ||
| 196 | Feb | ||
| 197 | %B | ||
| 198 | --- %B --- 4 | ||
| 199 | February | ||
| 200 | %B | ||
| 201 | --- %B --- 5 | ||
| 202 | Mar | ||
| 203 | %B | ||
| 204 | --- %B --- 6 | ||
| 205 | March | ||
| 206 | %B | ||
| 207 | --- %B --- 7 | ||
| 208 | Apr | ||
| 209 | %B | ||
| 210 | --- %B --- 8 | ||
| 211 | April | ||
| 212 | %B | ||
| 213 | --- %B --- 9 | ||
| 214 | May | ||
| 215 | %B | ||
| 216 | --- %B --- 10 | ||
| 217 | Jun | ||
| 218 | %B | ||
| 219 | --- %B --- 11 | ||
| 220 | June | ||
| 221 | %B | ||
| 222 | --- %B --- 12 | ||
| 223 | Jul | ||
| 224 | %B | ||
| 225 | --- %B --- 13 | ||
| 226 | July | ||
| 227 | %B | ||
| 228 | --- %B --- 14 | ||
| 229 | Aug | ||
| 230 | %B | ||
| 231 | --- %B --- 15 | ||
| 232 | August | ||
| 233 | %B | ||
| 234 | --- %B --- 16 | ||
| 235 | Sep | ||
| 236 | %B | ||
| 237 | --- %B --- 17 | ||
| 238 | September | ||
| 239 | %B | ||
| 240 | --- %B --- 18 | ||
| 241 | Oct | ||
| 242 | %B | ||
| 243 | --- %B --- 19 | ||
| 244 | October | ||
| 245 | %B | ||
| 246 | --- %B --- 20 | ||
| 247 | Nov | ||
| 248 | %B | ||
| 249 | --- %B --- 21 | ||
| 250 | November | ||
| 251 | %B | ||
| 252 | --- %B --- 22 | ||
| 253 | Dec | ||
| 254 | %B | ||
| 255 | --- %B --- 23 | ||
| 256 | December | ||
| 257 | %B | ||
| 258 | --- %B --- 25 | ||
| 259 | Mayor | ||
| 260 | %B | ||
| 261 | --- %B --- 24 | ||
| 262 | Mars | ||
| 263 | %B | ||
| 264 | --- %B --- 26 | ||
| 265 | Rover | ||
| 266 | %B | ||
| 267 | EOF | ||
diff --git a/src/regress/lib/libc/timingsafe/Makefile b/src/regress/lib/libc/timingsafe/Makefile deleted file mode 100644 index 9a679b61f8..0000000000 --- a/src/regress/lib/libc/timingsafe/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/06/13 01:55:02 matthew Exp $ | ||
| 2 | |||
| 3 | PROG= timingsafe | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/timingsafe/timingsafe.c b/src/regress/lib/libc/timingsafe/timingsafe.c deleted file mode 100644 index f6605f8696..0000000000 --- a/src/regress/lib/libc/timingsafe/timingsafe.c +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | /* $OpenBSD: timingsafe.c,v 1.3 2014/06/21 22:57:15 tedu Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Google Inc. | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <assert.h> | ||
| 19 | #include <stdlib.h> | ||
| 20 | #include <string.h> | ||
| 21 | |||
| 22 | #define ASSERT_EQ(a, b) assert((a) == (b)) | ||
| 23 | |||
| 24 | enum { | ||
| 25 | N = 8 | ||
| 26 | }; | ||
| 27 | |||
| 28 | static unsigned char bufone[N], buftwo[N]; | ||
| 29 | |||
| 30 | void | ||
| 31 | check() | ||
| 32 | { | ||
| 33 | int cmp = memcmp(bufone, buftwo, N); | ||
| 34 | |||
| 35 | /* Check for reflexivity. */ | ||
| 36 | ASSERT_EQ(0, timingsafe_bcmp(bufone, bufone, N)); | ||
| 37 | ASSERT_EQ(0, timingsafe_bcmp(buftwo, buftwo, N)); | ||
| 38 | ASSERT_EQ(0, timingsafe_memcmp(bufone, bufone, N)); | ||
| 39 | ASSERT_EQ(0, timingsafe_memcmp(buftwo, buftwo, N)); | ||
| 40 | |||
| 41 | /* Check that timingsafe_bcmp returns 0 iff memcmp returns 0. */ | ||
| 42 | ASSERT_EQ(cmp == 0, timingsafe_bcmp(bufone, buftwo, N) == 0); | ||
| 43 | |||
| 44 | /* Check that timingsafe_memcmp returns cmp... */ | ||
| 45 | ASSERT_EQ(cmp < 0, timingsafe_memcmp(bufone, buftwo, N) < 0); | ||
| 46 | |||
| 47 | /* ... or -cmp if the argument order is swapped. */ | ||
| 48 | ASSERT_EQ(-cmp < 0, timingsafe_memcmp(buftwo, bufone, N) < 0); | ||
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | main() | ||
| 53 | { | ||
| 54 | int i, j; | ||
| 55 | |||
| 56 | for (i = 0; i < 10000; i++) { | ||
| 57 | arc4random_buf(bufone, N); | ||
| 58 | arc4random_buf(buftwo, N); | ||
| 59 | |||
| 60 | check(); | ||
| 61 | for (j = 0; j < N; j++) { | ||
| 62 | buftwo[j] = bufone[j]; | ||
| 63 | check(); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | return (0); | ||
| 68 | } | ||
diff --git a/src/regress/lib/libc/vis/Makefile b/src/regress/lib/libc/vis/Makefile deleted file mode 100644 index 13e560bbf7..0000000000 --- a/src/regress/lib/libc/vis/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2005/08/29 18:41:56 otto Exp $ | ||
| 2 | |||
| 3 | PROG= vis_test | ||
| 4 | CLEANFILES+= valid.out | ||
| 5 | |||
| 6 | run-regress-vis_test: ${PROG} | ||
| 7 | ./${PROG} >${.OBJDIR}/valid.out | ||
| 8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/vis/valid.ok b/src/regress/lib/libc/vis/valid.ok deleted file mode 100644 index f8c0efa503..0000000000 --- a/src/regress/lib/libc/vis/valid.ok +++ /dev/null | |||
| @@ -1,2 +0,0 @@ | |||
| 1 | \^@\^A\^B\^C\^D\^E\^F\^G\^H | ||
| 2 | \^K\^L\^M\^N\^O\^P\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\^?\M^@\M^A\M^B\M^C\M^D\M^E\M^F\M^G\M^H\M^I\M^J\M^K\M^L\M^M\M^N\M^O\M^P\M^Q\M^R\M^S\M^T\M^U\M^V\M^W\M^X\M^Y\M^Z\M^[\M^\\M^]\M^^\M^_\240\M-!\M-"\M-#\M-$\M-%\M-&\M-'\M-(\M-)\M-*\M-+\M-,\M--\M-.\M-/\M-0\M-1\M-2\M-3\M-4\M-5\M-6\M-7\M-8\M-9\M-:\M-;\M-<\M-=\M->\M-?\M-@\M-A\M-B\M-C\M-D\M-E\M-F\M-G\M-H\M-I\M-J\M-K\M-L\M-M\M-N\M-O\M-P\M-Q\M-R\M-S\M-T\M-U\M-V\M-W\M-X\M-Y\M-Z\M-[\M-\\M-]\M-^\M-_\M-`\M-a\M-b\M-c\M-d\M-e\M-f\M-g\M-h\M-i\M-j\M-k\M-l\M-m\M-n\M-o\M-p\M-q\M-r\M-s\M-t\M-u\M-v\M-w\M-x\M-y\M-z\M-{\M-|\M-}\M-~\M^? | ||
diff --git a/src/regress/lib/libc/vis/vis_test.c b/src/regress/lib/libc/vis/vis_test.c deleted file mode 100644 index 92f2cee32d..0000000000 --- a/src/regress/lib/libc/vis/vis_test.c +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | /* $OpenBSD: vis_test.c,v 1.5 2017/07/27 15:08:37 bluhm Exp $ */ | ||
| 2 | |||
| 3 | /* Public domain. 2005, Otto Moerbeek */ | ||
| 4 | |||
| 5 | #include <limits.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdio.h> | ||
| 9 | #include <vis.h> | ||
| 10 | |||
| 11 | #define NTESTS 8000 | ||
| 12 | #define NCH 800 | ||
| 13 | |||
| 14 | char ibuf[NCH]; | ||
| 15 | char obuf[NCH * 4]; | ||
| 16 | char rbuf[NCH * 4]; | ||
| 17 | |||
| 18 | int flags[] = { | ||
| 19 | VIS_ALL, | ||
| 20 | VIS_GLOB, | ||
| 21 | VIS_TAB, | ||
| 22 | VIS_NL, | ||
| 23 | VIS_DQ, | ||
| 24 | VIS_WHITE, | ||
| 25 | VIS_SAFE | ||
| 26 | }; | ||
| 27 | |||
| 28 | char *flagname[] = { | ||
| 29 | "VIS_ALL", | ||
| 30 | "VIS_GLOB", | ||
| 31 | "VIS_TAB", | ||
| 32 | "VIS_NL", | ||
| 33 | "VIS_DQ", | ||
| 34 | "VIS_WHITE", | ||
| 35 | "VIS_SAFE" | ||
| 36 | }; | ||
| 37 | |||
| 38 | int title; | ||
| 39 | |||
| 40 | void | ||
| 41 | dotitle(int i, int j) | ||
| 42 | { | ||
| 43 | if (title == 0) | ||
| 44 | printf("%d %s:", i, flagname[j]); | ||
| 45 | title = 1; | ||
| 46 | } | ||
| 47 | |||
| 48 | int | ||
| 49 | main(int argc, char *argv[]) | ||
| 50 | { | ||
| 51 | |||
| 52 | char inp[UCHAR_MAX + 1]; | ||
| 53 | char out[4 * UCHAR_MAX + 1]; | ||
| 54 | int i, j, fail = 0; | ||
| 55 | ssize_t owant, o, r; | ||
| 56 | |||
| 57 | for (i = 0; i <= UCHAR_MAX; i++) { | ||
| 58 | inp[i] = i; | ||
| 59 | } | ||
| 60 | strvisx(out, inp, UCHAR_MAX + 1, 0); | ||
| 61 | printf("%s\n", out); | ||
| 62 | |||
| 63 | for (i = 0; i < NTESTS; i++) { | ||
| 64 | arc4random_buf(ibuf, sizeof(ibuf) - 1); | ||
| 65 | ibuf[sizeof(ibuf) - 1] = '\0'; | ||
| 66 | title = 0; | ||
| 67 | |||
| 68 | for (j = 0; j < sizeof(flags)/sizeof(flags[0]); j++) { | ||
| 69 | owant = sizeof(ibuf); | ||
| 70 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
| 71 | if (o >= owant) { | ||
| 72 | owant = o + 1; | ||
| 73 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
| 74 | if (o > owant) { | ||
| 75 | dotitle(i, j); | ||
| 76 | printf("HUGE overflow\n"); | ||
| 77 | } | ||
| 78 | if (o < owant - 1) { | ||
| 79 | dotitle(i, j); | ||
| 80 | printf("over-estimate of overflow\n"); | ||
| 81 | } | ||
| 82 | } else if (o > strlen(ibuf) * 4) { | ||
| 83 | dotitle(i, j); | ||
| 84 | printf("wants too much %zd %zu\n", | ||
| 85 | o, strlen(ibuf) * 4); | ||
| 86 | continue; | ||
| 87 | } | ||
| 88 | |||
| 89 | r = strnunvis(rbuf, obuf, sizeof rbuf); | ||
| 90 | |||
| 91 | if (r == -1) { | ||
| 92 | dotitle(i, j); | ||
| 93 | printf("cannot decode\n"); | ||
| 94 | printf("%s\n", obuf); | ||
| 95 | fail = 1; | ||
| 96 | } else if (r != strlen(ibuf)) { | ||
| 97 | dotitle(i, j); | ||
| 98 | printf("rlen %zd != inlen %zu\n", | ||
| 99 | r, strlen(ibuf)); | ||
| 100 | printf("%s\n", obuf); | ||
| 101 | printf("%s\n", rbuf); | ||
| 102 | fail = 1; | ||
| 103 | } else if (bcmp(ibuf, rbuf, r)) { | ||
| 104 | dotitle(i, j); | ||
| 105 | printf("strings are different\n"); | ||
| 106 | printf("%s\n", ibuf); | ||
| 107 | printf("%s\n", rbuf); | ||
| 108 | fail = 1; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | exit(fail); | ||
| 113 | } | ||
diff --git a/src/regress/lib/libc/wprintf/Makefile b/src/regress/lib/libc/wprintf/Makefile deleted file mode 100644 index 7b1897f2c4..0000000000 --- a/src/regress/lib/libc/wprintf/Makefile +++ /dev/null | |||
| @@ -1,5 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2011/04/24 08:00:22 stsp Exp $ | ||
| 2 | |||
| 3 | PROG= wfp | ||
| 4 | |||
| 5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/wprintf/wfp.c b/src/regress/lib/libc/wprintf/wfp.c deleted file mode 100644 index fc3120b53c..0000000000 --- a/src/regress/lib/libc/wprintf/wfp.c +++ /dev/null | |||
| @@ -1,218 +0,0 @@ | |||
| 1 | /* $OpenBSD: wfp.c,v 1.1 2011/04/24 08:00:22 stsp Exp $ */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Test for wprintf() floating point formats. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include <assert.h> | ||
| 33 | #include <err.h> | ||
| 34 | #include <float.h> | ||
| 35 | #include <math.h> | ||
| 36 | #include <stdio.h> | ||
| 37 | #include <stdarg.h> | ||
| 38 | #include <stdint.h> | ||
| 39 | #include <stdlib.h> | ||
| 40 | #include <string.h> | ||
| 41 | #include <wchar.h> | ||
| 42 | |||
| 43 | #define testfmt(result, fmt, ...) \ | ||
| 44 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
| 45 | void _testfmt(const wchar_t *, int, const char *, const wchar_t *, ...); | ||
| 46 | void smash_stack(void); | ||
| 47 | |||
| 48 | int | ||
| 49 | main(int argc, char *argv[]) | ||
| 50 | { | ||
| 51 | /* | ||
| 52 | * Basic tests of decimal output functionality. | ||
| 53 | */ | ||
| 54 | testfmt(L" 1.000000E+00", L"%13E", 1.0); | ||
| 55 | testfmt(L" 1.000000", L"%13f", 1.0); | ||
| 56 | testfmt(L" 1", L"%13G", 1.0); | ||
| 57 | testfmt(L" 1.000000E+00", L"%13LE", 1.0L); | ||
| 58 | testfmt(L" 1.000000", L"%13Lf", 1.0L); | ||
| 59 | testfmt(L" 1", L"%13LG", 1.0L); | ||
| 60 | |||
| 61 | testfmt(L"2.718282", L"%.*f", -2, 2.7182818); | ||
| 62 | |||
| 63 | testfmt(L"1.234568e+06", L"%e", 1234567.8); | ||
| 64 | testfmt(L"1234567.800000", L"%f", 1234567.8); | ||
| 65 | testfmt(L"1.23457E+06", L"%G", 1234567.8); | ||
| 66 | testfmt(L"1.234568e+06", L"%Le", 1234567.8L); | ||
| 67 | testfmt(L"1234567.800000", L"%Lf", 1234567.8L); | ||
| 68 | testfmt(L"1.23457E+06", L"%LG", 1234567.8L); | ||
| 69 | |||
| 70 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
| 71 | testfmt(L"123456789.864210", L"%Lf", 123456789.8642097531L); | ||
| 72 | testfmt(L"-1.23457E+08", L"%LG", -123456789.8642097531L); | ||
| 73 | testfmt(L"123456789.8642097531", L"%.10Lf", 123456789.8642097531L); | ||
| 74 | testfmt(L" 3.141592653589793238e-4000", L"%L27.18Le", | ||
| 75 | 3.14159265358979323846e-4000L); | ||
| 76 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Infinities and NaNs | ||
| 80 | */ | ||
| 81 | #ifdef NAN | ||
| 82 | testfmt(L"nan", L"%e", NAN); | ||
| 83 | testfmt(L"NAN", L"%F", NAN); | ||
| 84 | testfmt(L"nan", L"%g", NAN); | ||
| 85 | testfmt(L"NAN", L"%LE", (long double)NAN); | ||
| 86 | testfmt(L" nan", L"%05e", NAN); | ||
| 87 | #endif /* NAN */ | ||
| 88 | |||
| 89 | testfmt(L"INF", L"%E", HUGE_VAL); | ||
| 90 | testfmt(L"-inf", L"%f", -HUGE_VAL); | ||
| 91 | testfmt(L"+inf", L"%+g", HUGE_VAL); | ||
| 92 | testfmt(L" inf", L"%4.2Le", HUGE_VALL); | ||
| 93 | testfmt(L"-inf", L"%Lf", -HUGE_VALL); | ||
| 94 | testfmt(L" inf", L"%05e", HUGE_VAL); | ||
| 95 | testfmt(L" -inf", L"%05e", -HUGE_VAL); | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Padding | ||
| 99 | */ | ||
| 100 | testfmt(L"0.000000e+00", L"%e", 0.0); | ||
| 101 | testfmt(L"0.000000", L"%F", (double)0.0); | ||
| 102 | testfmt(L"0", L"%G", 0.0); | ||
| 103 | testfmt(L" 0", L"%3.0Lg", 0.0L); | ||
| 104 | testfmt(L" 0", L"%5.0f", 0.001); | ||
| 105 | |||
| 106 | /* | ||
| 107 | * Precision specifiers | ||
| 108 | */ | ||
| 109 | testfmt(L"1.0123e+00", L"%.4e", 1.0123456789); | ||
| 110 | testfmt(L"1.0123", L"%.4f", 1.0123456789); | ||
| 111 | testfmt(L"1.012", L"%.4g", 1.0123456789); | ||
| 112 | testfmt(L"1.2346e-02", L"%.4e", 0.0123456789); | ||
| 113 | testfmt(L"0.0123", L"%.4f", 0.0123456789); | ||
| 114 | testfmt(L"0.01235", L"%.4g", 0.0123456789); | ||
| 115 | |||
| 116 | /* | ||
| 117 | * Signed conversions | ||
| 118 | */ | ||
| 119 | testfmt(L"+2.500000e-01", L"%+e", 0.25); | ||
| 120 | testfmt(L"+0.000000", L"%+F", 0.0); | ||
| 121 | testfmt(L"-1", L"%+g", -1.0); | ||
| 122 | |||
| 123 | testfmt(L"-1.000000e+00", L"% e", -1.0); | ||
| 124 | testfmt(L"+1.000000", L"% +f", 1.0); | ||
| 125 | testfmt(L" 1", L"% g", 1.0); | ||
| 126 | testfmt(L" 0", L"% g", 0.0); | ||
| 127 | |||
| 128 | /* | ||
| 129 | * ``Alternate form'' | ||
| 130 | */ | ||
| 131 | testfmt(L"1.250e+00", L"%#.3e", 1.25); | ||
| 132 | testfmt(L"123.000000", L"%#f", 123.0); | ||
| 133 | testfmt(L" 12345.", L"%#7.5g", 12345.0); | ||
| 134 | testfmt(L" 1.00000", L"%#8g", 1.0); | ||
| 135 | testfmt(L"0.0", L"%#.2g", 0.0); | ||
| 136 | |||
| 137 | /* | ||
| 138 | * Padding and decimal point placement | ||
| 139 | */ | ||
| 140 | testfmt(L"03.2E+00", L"%08.1E", 3.25); | ||
| 141 | testfmt(L"003.25", L"%06.2F", 3.25); | ||
| 142 | testfmt(L"0003.25", L"%07.4G", 3.25); | ||
| 143 | |||
| 144 | testfmt(L"3.14159e-05", L"%g", 3.14159e-5); | ||
| 145 | testfmt(L"0.000314159", L"%g", 3.14159e-4); | ||
| 146 | testfmt(L"3.14159e+06", L"%g", 3.14159e6); | ||
| 147 | testfmt(L"314159", L"%g", 3.14159e5); | ||
| 148 | testfmt(L"314159.", L"%#g", 3.14159e5); | ||
| 149 | |||
| 150 | testfmt(L" 9.000000e+03", L"%13e", 9000.0); | ||
| 151 | testfmt(L" 9000.000000", L"%12f", 9000.0); | ||
| 152 | testfmt(L" 9000", L"%5g", 9000.0); | ||
| 153 | testfmt(L" 900000.", L"%#8g", 900000.0); | ||
| 154 | testfmt(L" 9e+06", L"%6g", 9000000.0); | ||
| 155 | testfmt(L" 9.000000e-04", L"%13e", 0.0009); | ||
| 156 | testfmt(L" 0.000900", L"%9f", 0.0009); | ||
| 157 | testfmt(L" 0.0009", L"%7g", 0.0009); | ||
| 158 | testfmt(L" 9e-05", L"%6g", 0.00009); | ||
| 159 | testfmt(L" 9.00000e-05", L"%#12g", 0.00009); | ||
| 160 | testfmt(L" 9.e-05", L"%#7.1g", 0.00009); | ||
| 161 | |||
| 162 | testfmt(L" 0.0", L"%4.1f", 0.0); | ||
| 163 | testfmt(L"90.0", L"%4.1f", 90.0); | ||
| 164 | testfmt(L" 100", L"%4.0f", 100.0); | ||
| 165 | testfmt(L"9.0e+01", L"%4.1e", 90.0); | ||
| 166 | testfmt(L"1e+02", L"%4.0e", 100.0); | ||
| 167 | |||
| 168 | /* | ||
| 169 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
| 170 | * are only valid if the implementation converts to hex digits | ||
| 171 | * on nibble boundaries. | ||
| 172 | */ | ||
| 173 | testfmt(L"0x0p+0", L"%a", 0x0.0p0); | ||
| 174 | testfmt(L"0X0.P+0", L"%#LA", 0x0.0p0L); | ||
| 175 | #ifdef NAN | ||
| 176 | testfmt(L"inf", L"%La", (long double)INFINITY); | ||
| 177 | testfmt(L"+INF", L"%+A", INFINITY); | ||
| 178 | testfmt(L"nan", L"%La", (long double)NAN); | ||
| 179 | testfmt(L"NAN", L"%A", NAN); | ||
| 180 | #endif /* NAN */ | ||
| 181 | |||
| 182 | testfmt(L" 0x1.23p+0", L"%10a", 0x1.23p0); | ||
| 183 | testfmt(L" 0x1.23p-500", L"%12a", 0x1.23p-500); | ||
| 184 | testfmt(L" 0x1.2p+40", L"%10.1a", 0x1.23p40); | ||
| 185 | testfmt(L" 0X1.230000000000000000000000P-4", L"%32.24A", 0x1.23p-4); | ||
| 186 | testfmt(L"0x1p-1074", L"%a", 0x1p-1074); | ||
| 187 | testfmt(L"0x1.2345p-1024", L"%a", 0x1.2345p-1024); | ||
| 188 | |||
| 189 | return (0); | ||
| 190 | } | ||
| 191 | |||
| 192 | void | ||
| 193 | smash_stack(void) | ||
| 194 | { | ||
| 195 | static uint32_t junk = 0xdeadbeef; | ||
| 196 | uint32_t buf[512]; | ||
| 197 | int i; | ||
| 198 | |||
| 199 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
| 200 | buf[i] = junk; | ||
| 201 | } | ||
| 202 | |||
| 203 | void | ||
| 204 | _testfmt(const wchar_t *result, int line, const char *argstr, const wchar_t *fmt,...) | ||
| 205 | { | ||
| 206 | wchar_t s[100]; | ||
| 207 | va_list ap; | ||
| 208 | |||
| 209 | va_start(ap, fmt); | ||
| 210 | smash_stack(); | ||
| 211 | vswprintf(s, sizeof(s), fmt, ap); | ||
| 212 | if (wcscmp(result, s) != 0) { | ||
| 213 | fprintf(stderr, | ||
| 214 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
| 215 | line, (char*)fmt, argstr, s, result); | ||
| 216 | abort(); | ||
| 217 | } | ||
| 218 | } | ||
diff --git a/src/regress/lib/libcrypto/CA/Makefile b/src/regress/lib/libcrypto/CA/Makefile deleted file mode 100644 index c31c99c946..0000000000 --- a/src/regress/lib/libcrypto/CA/Makefile +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/01/25 10:29:34 beck Exp $ | ||
| 2 | |||
| 3 | TESTS = \ | ||
| 4 | doit.sh | ||
| 5 | |||
| 6 | REGRESS_TARGETS= all_tests | ||
| 7 | |||
| 8 | CLEANFILES += \ | ||
| 9 | 1000.pem client.cert.pem intermediate.cert.pem root.cert.pem server.csr.pem \ | ||
| 10 | 1001.pem client.csr.pem intermediate.csr.pem root.key.pem server.key.pem \ | ||
| 11 | chain.pem client.key.pem intermediate.key.pem server.cert.pem \ | ||
| 12 | int.txt int.txt.attr int.txt.old int.txt.attr.old \ | ||
| 13 | root.txt root.txt.attr root.txt.old root.txt.attr.old \ | ||
| 14 | intserial rootserial intserial.old rootserial.old | ||
| 15 | |||
| 16 | all_tests: ${TESTS} | ||
| 17 | @for test in $>; do \ | ||
| 18 | ./$$test; \ | ||
| 19 | done | ||
| 20 | |||
| 21 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/CA/doit.sh b/src/regress/lib/libcrypto/CA/doit.sh deleted file mode 100755 index 110d89d67f..0000000000 --- a/src/regress/lib/libcrypto/CA/doit.sh +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # $OpenBSD: doit.sh,v 1.2 2018/07/17 17:06:49 tb Exp $ | ||
| 3 | |||
| 4 | rm -rf root intermediate certs | ||
| 5 | echo 1000 > rootserial | ||
| 6 | cat /dev/null > root.txt | ||
| 7 | echo 1000 > intserial | ||
| 8 | cat /dev/null > int.txt | ||
| 9 | |||
| 10 | # Vanna Vanna make me a root cert | ||
| 11 | openssl genrsa -out root.key.pem 4096 | ||
| 12 | if [ $? -ne 0 ]; then | ||
| 13 | echo "*** Fail; Can't generate root rsa 4096 key" | ||
| 14 | exit 1 | ||
| 15 | fi | ||
| 16 | |||
| 17 | openssl req -batch -config root.cnf -key root.key.pem -new -x509 -days 365 -sha256 -extensions v3_ca -out root.cert.pem | ||
| 18 | if [ $? -ne 0 ]; then | ||
| 19 | echo "*** Fail; Can't generate root req" | ||
| 20 | exit 1 | ||
| 21 | fi | ||
| 22 | |||
| 23 | # Make intermediate | ||
| 24 | openssl genrsa -out intermediate.key.pem 2048 | ||
| 25 | if [ $? -ne 0 ]; then | ||
| 26 | echo "*** Fail; Can't generate intermediate rsa 2048 key" | ||
| 27 | exit 1 | ||
| 28 | fi | ||
| 29 | |||
| 30 | openssl req -batch -config intermediate.cnf -new -sha256 \ | ||
| 31 | -key intermediate.key.pem \ | ||
| 32 | -out intermediate.csr.pem | ||
| 33 | if [ $? -ne 0 ]; then | ||
| 34 | echo "*** Fail; Can't generate intermediate req" | ||
| 35 | exit 1 | ||
| 36 | fi | ||
| 37 | |||
| 38 | # Sign intermediate | ||
| 39 | openssl ca -batch -config root.cnf -extensions v3_intermediate_ca -days 10 -notext -md sha256 -in intermediate.csr.pem -out intermediate.cert.pem | ||
| 40 | if [ $? -ne 0 ]; then | ||
| 41 | echo "*** Fail; Can't sign intermediate" | ||
| 42 | exit 1 | ||
| 43 | fi | ||
| 44 | |||
| 45 | # Verify Intermediate | ||
| 46 | openssl verify -CAfile ca.cert.pem intermediate.cert.pem | ||
| 47 | if [ $? -ne 0]; then | ||
| 48 | echo "*** Fail; Intermediate CA does not validate" | ||
| 49 | exit 1 | ||
| 50 | fi | ||
| 51 | |||
| 52 | cat intermediate.cert.pem root.cert.pem > chain.pem | ||
| 53 | |||
| 54 | # make a server certificate | ||
| 55 | |||
| 56 | openssl genrsa -out server.key.pem 2048 | ||
| 57 | if [ $? -ne 0]; then | ||
| 58 | echo "*** Fail; genrsa server" | ||
| 59 | exit 1 | ||
| 60 | fi | ||
| 61 | |||
| 62 | |||
| 63 | openssl req -batch -config intermediate.cnf \ | ||
| 64 | -key server.key.pem \ | ||
| 65 | -new -sha256 -out server.csr.pem \ | ||
| 66 | -subj '/CN=server/O=OpenBSD/OU=So and Sos/C=CA' | ||
| 67 | if [ $? -ne 0]; then | ||
| 68 | echo "*** Fail; server req" | ||
| 69 | exit 1 | ||
| 70 | fi | ||
| 71 | |||
| 72 | # sign server key | ||
| 73 | openssl ca -batch -config intermediate.cnf -extensions server_cert -days 5 -notext -md sha256 -in server.csr.pem -out server.cert.pem | ||
| 74 | if [ $? -ne 0 ]; then | ||
| 75 | echo "*** Fail; server sign" | ||
| 76 | exit 1 | ||
| 77 | fi | ||
| 78 | |||
| 79 | # make a client certificate | ||
| 80 | |||
| 81 | openssl genrsa -out client.key.pem 2048 | ||
| 82 | if [ $? -ne 0]; then | ||
| 83 | echo "*** Fail; genrsa client" | ||
| 84 | exit 1 | ||
| 85 | fi | ||
| 86 | |||
| 87 | openssl req -batch -config intermediate.cnf \ | ||
| 88 | -key client.key.pem \ | ||
| 89 | -new -sha256 -out client.csr.pem \ | ||
| 90 | -subj '/CN=client/O=OpenBSD/OU=So and Sos/C=CA' | ||
| 91 | if [ $? -ne 0]; then | ||
| 92 | echo "*** Fail; client req" | ||
| 93 | exit 1 | ||
| 94 | fi | ||
| 95 | |||
| 96 | # sign client key | ||
| 97 | openssl ca -batch -config intermediate.cnf -extensions usr_cert -days 5 -notext -md sha256 -in client.csr.pem -out client.cert.pem | ||
| 98 | if [ $? -ne 0 ]; then | ||
| 99 | echo "*** Fail; client sign" | ||
| 100 | exit 1 | ||
| 101 | fi | ||
| 102 | |||
| 103 | # Verify Intermediate | ||
| 104 | openssl verify -purpose sslserver -CAfile chain.pem server.cert.pem | ||
| 105 | if [ $? -ne 0 ]; then | ||
| 106 | echo "*** Fail; server cert does not validate" | ||
| 107 | exit 1 | ||
| 108 | fi | ||
| 109 | |||
| 110 | # Verify Intermediate | ||
| 111 | openssl verify -purpose sslclient -CAfile chain.pem client.cert.pem | ||
| 112 | if [ $? -ne 0 ]; then | ||
| 113 | echo "*** Fail; client cert does not validate" | ||
| 114 | exit 1 | ||
| 115 | fi | ||
| 116 | |||
diff --git a/src/regress/lib/libcrypto/CA/intermediate.cnf b/src/regress/lib/libcrypto/CA/intermediate.cnf deleted file mode 100644 index 9a95487c00..0000000000 --- a/src/regress/lib/libcrypto/CA/intermediate.cnf +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | # $OpenBSD: intermediate.cnf,v 1.2 2018/07/17 17:06:49 tb Exp $ | ||
| 2 | # For regression tests | ||
| 3 | default_ca = CA_regress | ||
| 4 | |||
| 5 | [ CA_regress ] | ||
| 6 | # Directory and file locations. | ||
| 7 | dir = . | ||
| 8 | certs = $dir | ||
| 9 | crl_dir = $dir | ||
| 10 | database = $dir/int.txt | ||
| 11 | serial = $dir/intserial | ||
| 12 | new_certs_dir = $dir | ||
| 13 | |||
| 14 | # The root key and root certificate. | ||
| 15 | private_key = $dir/intermediate.key.pem | ||
| 16 | certificate = $dir/intermediate.cert.pem | ||
| 17 | |||
| 18 | # For certificate revocation lists. | ||
| 19 | crlnumber = $dir/crlnumber | ||
| 20 | crl = $dir/ca.crl.pem | ||
| 21 | crl_extensions = crl_ext | ||
| 22 | default_crl_days = 30 | ||
| 23 | |||
| 24 | # SHA-1 is deprecated, so use SHA-2 instead. | ||
| 25 | default_md = sha256 | ||
| 26 | |||
| 27 | name_opt = ca_default | ||
| 28 | cert_opt = ca_default | ||
| 29 | default_days = 10 | ||
| 30 | preserve = no | ||
| 31 | policy = policy_loose | ||
| 32 | |||
| 33 | [ policy_strict ] | ||
| 34 | # The root CA should only sign intermediate certificates that match. | ||
| 35 | # See the POLICY FORMAT section of `man ca`. | ||
| 36 | countryName = match | ||
| 37 | stateOrProvinceName = match | ||
| 38 | organizationName = match | ||
| 39 | organizationalUnitName = optional | ||
| 40 | commonName = supplied | ||
| 41 | emailAddress = optional | ||
| 42 | |||
| 43 | [ policy_loose ] | ||
| 44 | # Allow the intermediate CA to sign a more diverse range of certificates. | ||
| 45 | # See the POLICY FORMAT section of the `ca` man page. | ||
| 46 | countryName = optional | ||
| 47 | stateOrProvinceName = optional | ||
| 48 | localityName = optional | ||
| 49 | organizationName = optional | ||
| 50 | organizationalUnitName = optional | ||
| 51 | commonName = supplied | ||
| 52 | emailAddress = optional | ||
| 53 | |||
| 54 | [ req ] | ||
| 55 | # Options for the `req` tool (`man req`). | ||
| 56 | default_bits = 2048 | ||
| 57 | distinguished_name = req_distinguished_name | ||
| 58 | string_mask = utf8only | ||
| 59 | |||
| 60 | # SHA-1 is deprecated, so use SHA-2 instead. | ||
| 61 | default_md = sha256 | ||
| 62 | |||
| 63 | # Extension to add when the -x509 option is used. | ||
| 64 | x509_extensions = v3_ca | ||
| 65 | |||
| 66 | [ req_distinguished_name ] | ||
| 67 | # See <https://en.wikipedia.org/wiki/Certificate_signing_request>. | ||
| 68 | countryName = Country Name (2 letter code) | ||
| 69 | stateOrProvinceName = State or Province Name | ||
| 70 | localityName = Locality Name | ||
| 71 | 0.organizationName = Organization Name | ||
| 72 | organizationalUnitName = Organizational Unit Name | ||
| 73 | commonName = Common Name | ||
| 74 | emailAddress = Email Address | ||
| 75 | |||
| 76 | # Optionally, specify some defaults. | ||
| 77 | countryName_default = CA | ||
| 78 | stateOrProvinceName_default = Alberta | ||
| 79 | localityName_default = Edmonton | ||
| 80 | 0.organizationName_default = OpenBSD | ||
| 81 | organizationalUnitName_default = So and Sos | ||
| 82 | emailAddress_default = evilsoandsos@openbsd.org | ||
| 83 | commonName_default = Regress Intermediate CA | ||
| 84 | |||
| 85 | [ v3_ca ] | ||
| 86 | # Extensions for a typical CA (`man x509v3_config`). | ||
| 87 | subjectKeyIdentifier = hash | ||
| 88 | authorityKeyIdentifier = keyid:always,issuer | ||
| 89 | basicConstraints = critical, CA:true | ||
| 90 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign | ||
| 91 | |||
| 92 | [ v3_intermediate_ca ] | ||
| 93 | # Extensions for a typical intermediate CA (`man x509v3_config`). | ||
| 94 | subjectKeyIdentifier = hash | ||
| 95 | authorityKeyIdentifier = keyid:always,issuer | ||
| 96 | basicConstraints = critical, CA:true, pathlen:0 | ||
| 97 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign | ||
| 98 | |||
| 99 | [ usr_cert ] | ||
| 100 | # Extensions for client certificates (`man x509v3_config`). | ||
| 101 | basicConstraints = CA:FALSE | ||
| 102 | nsCertType = client, email | ||
| 103 | nsComment = "OpenSSL Generated Client Certificate" | ||
| 104 | subjectKeyIdentifier = hash | ||
| 105 | authorityKeyIdentifier = keyid,issuer | ||
| 106 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment | ||
| 107 | extendedKeyUsage = clientAuth, emailProtection | ||
| 108 | |||
| 109 | [ server_cert ] | ||
| 110 | # Extensions for server certificates (`man x509v3_config`). | ||
| 111 | basicConstraints = CA:FALSE | ||
| 112 | nsCertType = server | ||
| 113 | nsComment = "OpenSSL Generated Server Certificate" | ||
| 114 | subjectKeyIdentifier = hash | ||
| 115 | authorityKeyIdentifier = keyid,issuer:always | ||
| 116 | keyUsage = critical, digitalSignature, keyEncipherment | ||
| 117 | extendedKeyUsage = serverAuth | ||
| 118 | |||
| 119 | [ crl_ext ] | ||
| 120 | # Extension for CRLs (`man x509v3_config`). | ||
| 121 | authorityKeyIdentifier=keyid:always | ||
| 122 | |||
| 123 | [ ocsp ] | ||
| 124 | # Extension for OCSP signing certificates (`man ocsp`). | ||
| 125 | basicConstraints = CA:FALSE | ||
| 126 | subjectKeyIdentifier = hash | ||
| 127 | authorityKeyIdentifier = keyid,issuer | ||
| 128 | keyUsage = critical, digitalSignature | ||
| 129 | extendedKeyUsage = critical, OCSPSigning | ||
| 130 | |||
diff --git a/src/regress/lib/libcrypto/CA/root.cnf b/src/regress/lib/libcrypto/CA/root.cnf deleted file mode 100644 index b22e161476..0000000000 --- a/src/regress/lib/libcrypto/CA/root.cnf +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | # $OpenBSD: root.cnf,v 1.2 2018/07/17 17:06:49 tb Exp $ | ||
| 2 | # For regression tests | ||
| 3 | default_ca = CA_regress | ||
| 4 | |||
| 5 | [ CA_regress ] | ||
| 6 | # Directory and file locations. | ||
| 7 | dir = . | ||
| 8 | certs = $dir | ||
| 9 | crl_dir = $dir | ||
| 10 | database = $dir/root.txt | ||
| 11 | serial = $dir/rootserial | ||
| 12 | new_certs_dir = $dir | ||
| 13 | |||
| 14 | # The root key and root certificate. | ||
| 15 | private_key = $dir/root.key.pem | ||
| 16 | certificate = $dir/root.cert.pem | ||
| 17 | |||
| 18 | # For certificate revocation lists. | ||
| 19 | crlnumber = $dir/crlnumber | ||
| 20 | crl = $dir/ca.crl.pem | ||
| 21 | crl_extensions = crl_ext | ||
| 22 | default_crl_days = 30 | ||
| 23 | |||
| 24 | # SHA-1 is deprecated, so use SHA-2 instead. | ||
| 25 | default_md = sha256 | ||
| 26 | |||
| 27 | name_opt = ca_default | ||
| 28 | cert_opt = ca_default | ||
| 29 | default_days = 375 | ||
| 30 | preserve = no | ||
| 31 | policy = policy_strict | ||
| 32 | |||
| 33 | [ policy_strict ] | ||
| 34 | # The root CA should only sign intermediate certificates that match. | ||
| 35 | # See the POLICY FORMAT section of `man ca`. | ||
| 36 | countryName = match | ||
| 37 | stateOrProvinceName = match | ||
| 38 | organizationName = match | ||
| 39 | organizationalUnitName = optional | ||
| 40 | commonName = supplied | ||
| 41 | emailAddress = optional | ||
| 42 | |||
| 43 | [ policy_loose ] | ||
| 44 | # Allow the intermediate CA to sign a more diverse range of certificates. | ||
| 45 | # See the POLICY FORMAT section of the `ca` man page. | ||
| 46 | countryName = optional | ||
| 47 | stateOrProvinceName = optional | ||
| 48 | localityName = optional | ||
| 49 | organizationName = optional | ||
| 50 | organizationalUnitName = optional | ||
| 51 | commonName = supplied | ||
| 52 | emailAddress = optional | ||
| 53 | |||
| 54 | [ req ] | ||
| 55 | # Options for the `req` tool (`man req`). | ||
| 56 | default_bits = 2048 | ||
| 57 | distinguished_name = req_distinguished_name | ||
| 58 | string_mask = utf8only | ||
| 59 | |||
| 60 | # SHA-1 is deprecated, so use SHA-2 instead. | ||
| 61 | default_md = sha256 | ||
| 62 | |||
| 63 | # Extension to add when the -x509 option is used. | ||
| 64 | x509_extensions = v3_ca | ||
| 65 | |||
| 66 | [ req_distinguished_name ] | ||
| 67 | # See <https://en.wikipedia.org/wiki/Certificate_signing_request>. | ||
| 68 | countryName = Country Name (2 letter code) | ||
| 69 | stateOrProvinceName = State or Province Name | ||
| 70 | localityName = Locality Name | ||
| 71 | 0.organizationName = Organization Name | ||
| 72 | organizationalUnitName = Organizational Unit Name | ||
| 73 | commonName = Common Name | ||
| 74 | emailAddress = Email Address | ||
| 75 | |||
| 76 | # Optionally, specify some defaults. | ||
| 77 | countryName_default = CA | ||
| 78 | stateOrProvinceName_default = Alberta | ||
| 79 | localityName_default = Edmonton | ||
| 80 | 0.organizationName_default = OpenBSD | ||
| 81 | organizationalUnitName_default = So and Sos | ||
| 82 | emailAddress_default = evilsoandsos@openbsd.org | ||
| 83 | commonName_default = Regress Root CA | ||
| 84 | |||
| 85 | [ v3_ca ] | ||
| 86 | # Extensions for a typical CA (`man x509v3_config`). | ||
| 87 | subjectKeyIdentifier = hash | ||
| 88 | authorityKeyIdentifier = keyid:always,issuer | ||
| 89 | basicConstraints = critical, CA:true | ||
| 90 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign | ||
| 91 | |||
| 92 | [ v3_intermediate_ca ] | ||
| 93 | # Extensions for a typical intermediate CA (`man x509v3_config`). | ||
| 94 | subjectKeyIdentifier = hash | ||
| 95 | authorityKeyIdentifier = keyid:always,issuer | ||
| 96 | basicConstraints = critical, CA:true, pathlen:0 | ||
| 97 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign | ||
| 98 | |||
| 99 | [ usr_cert ] | ||
| 100 | # Extensions for client certificates (`man x509v3_config`). | ||
| 101 | basicConstraints = CA:FALSE | ||
| 102 | nsCertType = client, email | ||
| 103 | nsComment = "OpenSSL Generated Client Certificate" | ||
| 104 | subjectKeyIdentifier = hash | ||
| 105 | authorityKeyIdentifier = keyid,issuer | ||
| 106 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment | ||
| 107 | extendedKeyUsage = clientAuth, emailProtection | ||
| 108 | |||
| 109 | [ server_cert ] | ||
| 110 | # Extensions for server certificates (`man x509v3_config`). | ||
| 111 | basicConstraints = CA:FALSE | ||
| 112 | nsCertType = server | ||
| 113 | nsComment = "OpenSSL Generated Server Certificate" | ||
| 114 | subjectKeyIdentifier = hash | ||
| 115 | authorityKeyIdentifier = keyid,issuer:always | ||
| 116 | keyUsage = critical, digitalSignature, keyEncipherment | ||
| 117 | extendedKeyUsage = serverAuth | ||
| 118 | |||
| 119 | [ crl_ext ] | ||
| 120 | # Extension for CRLs (`man x509v3_config`). | ||
| 121 | authorityKeyIdentifier=keyid:always | ||
| 122 | |||
| 123 | [ ocsp ] | ||
| 124 | # Extension for OCSP signing certificates (`man ocsp`). | ||
| 125 | basicConstraints = CA:FALSE | ||
| 126 | subjectKeyIdentifier = hash | ||
| 127 | authorityKeyIdentifier = keyid,issuer | ||
| 128 | keyUsage = critical, digitalSignature | ||
| 129 | extendedKeyUsage = critical, OCSPSigning | ||
| 130 | |||
diff --git a/src/regress/lib/libcrypto/Makefile b/src/regress/lib/libcrypto/Makefile deleted file mode 100644 index 38e3304eb4..0000000000 --- a/src/regress/lib/libcrypto/Makefile +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.32 2018/07/25 18:04:09 jsing Exp $ | ||
| 2 | |||
| 3 | SUBDIR= \ | ||
| 4 | aead \ | ||
| 5 | aeswrap \ | ||
| 6 | asn1 \ | ||
| 7 | base64 \ | ||
| 8 | bf \ | ||
| 9 | bio \ | ||
| 10 | bn \ | ||
| 11 | cast \ | ||
| 12 | chacha \ | ||
| 13 | cts128 \ | ||
| 14 | curve25519 \ | ||
| 15 | des \ | ||
| 16 | dh \ | ||
| 17 | dsa \ | ||
| 18 | ec \ | ||
| 19 | ecdh \ | ||
| 20 | ecdsa \ | ||
| 21 | engine \ | ||
| 22 | evp \ | ||
| 23 | exp \ | ||
| 24 | free \ | ||
| 25 | gcm128 \ | ||
| 26 | gost \ | ||
| 27 | hkdf \ | ||
| 28 | hmac \ | ||
| 29 | idea \ | ||
| 30 | ige \ | ||
| 31 | init \ | ||
| 32 | md4 \ | ||
| 33 | md5 \ | ||
| 34 | pbkdf2 \ | ||
| 35 | pkcs7 \ | ||
| 36 | poly1305 \ | ||
| 37 | rand \ | ||
| 38 | rc2 \ | ||
| 39 | rc4 \ | ||
| 40 | rmd \ | ||
| 41 | rsa \ | ||
| 42 | sha1 \ | ||
| 43 | sha2 \ | ||
| 44 | sha256 \ | ||
| 45 | sha512 \ | ||
| 46 | utf8 \ | ||
| 47 | wycheproof \ | ||
| 48 | x509 | ||
| 49 | |||
| 50 | install: | ||
| 51 | |||
| 52 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libcrypto/Makefile.inc b/src/regress/lib/libcrypto/Makefile.inc deleted file mode 100644 index 88fe5aca41..0000000000 --- a/src/regress/lib/libcrypto/Makefile.inc +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.2 2018/07/17 17:06:49 tb Exp $ | ||
| 2 | # Use this variable when the test needs internal symbols from libcrypto | ||
| 3 | CRYPTO_INT= -Wl,-Bstatic -lcrypto -Wl,-Bdynamic | ||
diff --git a/src/regress/lib/libcrypto/aead/Makefile b/src/regress/lib/libcrypto/aead/Makefile deleted file mode 100644 index 344bdcbbf1..0000000000 --- a/src/regress/lib/libcrypto/aead/Makefile +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= aeadtest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-aeadtest | ||
| 10 | |||
| 11 | regress-aeadtest: ${PROG} | ||
| 12 | ./${PROG} ${.CURDIR}/aeadtests.txt | ||
| 13 | |||
| 14 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/aead/aeadtest.c b/src/regress/lib/libcrypto/aead/aeadtest.c deleted file mode 100644 index 4f0ab9fa3a..0000000000 --- a/src/regress/lib/libcrypto/aead/aeadtest.c +++ /dev/null | |||
| @@ -1,368 +0,0 @@ | |||
| 1 | /* $OpenBSD: aeadtest.c,v 1.11 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * licensing@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include <stdio.h> | ||
| 52 | #include <stdlib.h> | ||
| 53 | #include <string.h> | ||
| 54 | #include <stdint.h> | ||
| 55 | |||
| 56 | #include <openssl/evp.h> | ||
| 57 | |||
| 58 | /* This program tests an AEAD against a series of test vectors from a file. The | ||
| 59 | * test vector file consists of key-value lines where the key and value are | ||
| 60 | * separated by a colon and optional whitespace. The keys are listed in | ||
| 61 | * NAMES, below. The values are hex-encoded data. | ||
| 62 | * | ||
| 63 | * After a number of key-value lines, a blank line indicates the end of the | ||
| 64 | * test case. | ||
| 65 | * | ||
| 66 | * For example, here's a valid test case: | ||
| 67 | * | ||
| 68 | * AEAD: chacha20-poly1305 | ||
| 69 | * KEY: bcb2639bf989c6251b29bf38d39a9bdce7c55f4b2ac12a39c8a37b5d0a5cc2b5 | ||
| 70 | * NONCE: 1e8b4c510f5ca083 | ||
| 71 | * IN: 8c8419bc27 | ||
| 72 | * AD: 34ab88c265 | ||
| 73 | * CT: 1a7c2f33f5 | ||
| 74 | * TAG: 2875c659d0f2808de3a40027feff91a4 | ||
| 75 | */ | ||
| 76 | |||
| 77 | #define BUF_MAX 1024 | ||
| 78 | |||
| 79 | /* These are the different types of line that are found in the input file. */ | ||
| 80 | enum { | ||
| 81 | AEAD = 0, /* name of the AEAD algorithm. */ | ||
| 82 | KEY, /* hex encoded key. */ | ||
| 83 | NONCE, /* hex encoded nonce. */ | ||
| 84 | IN, /* hex encoded plaintext. */ | ||
| 85 | AD, /* hex encoded additional data. */ | ||
| 86 | CT, /* hex encoded ciphertext (not including the | ||
| 87 | * authenticator, which is next. */ | ||
| 88 | TAG, /* hex encoded authenticator. */ | ||
| 89 | NUM_TYPES | ||
| 90 | }; | ||
| 91 | |||
| 92 | static const char NAMES[NUM_TYPES][6] = { | ||
| 93 | "AEAD", | ||
| 94 | "KEY", | ||
| 95 | "NONCE", | ||
| 96 | "IN", | ||
| 97 | "AD", | ||
| 98 | "CT", | ||
| 99 | "TAG", | ||
| 100 | }; | ||
| 101 | |||
| 102 | static unsigned char | ||
| 103 | hex_digit(char h) | ||
| 104 | { | ||
| 105 | if (h >= '0' && h <= '9') | ||
| 106 | return h - '0'; | ||
| 107 | else if (h >= 'a' && h <= 'f') | ||
| 108 | return h - 'a' + 10; | ||
| 109 | else if (h >= 'A' && h <= 'F') | ||
| 110 | return h - 'A' + 10; | ||
| 111 | else | ||
| 112 | return 16; | ||
| 113 | } | ||
| 114 | |||
| 115 | static int | ||
| 116 | aead_from_name(const EVP_AEAD **aead, const char *name) | ||
| 117 | { | ||
| 118 | *aead = NULL; | ||
| 119 | |||
| 120 | if (strcmp(name, "aes-128-gcm") == 0) { | ||
| 121 | #ifndef OPENSSL_NO_AES | ||
| 122 | *aead = EVP_aead_aes_128_gcm(); | ||
| 123 | #else | ||
| 124 | fprintf(stderr, "No AES support.\n"); | ||
| 125 | #endif | ||
| 126 | } else if (strcmp(name, "aes-256-gcm") == 0) { | ||
| 127 | #ifndef OPENSSL_NO_AES | ||
| 128 | *aead = EVP_aead_aes_256_gcm(); | ||
| 129 | #else | ||
| 130 | fprintf(stderr, "No AES support.\n"); | ||
| 131 | #endif | ||
| 132 | } else if (strcmp(name, "chacha20-poly1305") == 0) { | ||
| 133 | #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) | ||
| 134 | *aead = EVP_aead_chacha20_poly1305(); | ||
| 135 | #else | ||
| 136 | fprintf(stderr, "No chacha20-poly1305 support.\n"); | ||
| 137 | #endif | ||
| 138 | } else { | ||
| 139 | fprintf(stderr, "Unknown AEAD: %s\n", name); | ||
| 140 | return -1; | ||
| 141 | } | ||
| 142 | |||
| 143 | if (*aead == NULL) | ||
| 144 | return 0; | ||
| 145 | |||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | |||
| 149 | static int | ||
| 150 | run_test_case(const EVP_AEAD* aead, unsigned char bufs[NUM_TYPES][BUF_MAX], | ||
| 151 | const unsigned int lengths[NUM_TYPES], unsigned int line_no) | ||
| 152 | { | ||
| 153 | EVP_AEAD_CTX ctx; | ||
| 154 | unsigned char out[BUF_MAX + EVP_AEAD_MAX_TAG_LENGTH], out2[BUF_MAX]; | ||
| 155 | size_t out_len, out_len2; | ||
| 156 | |||
| 157 | if (!EVP_AEAD_CTX_init(&ctx, aead, bufs[KEY], lengths[KEY], | ||
| 158 | lengths[TAG], NULL)) { | ||
| 159 | fprintf(stderr, "Failed to init AEAD on line %u\n", line_no); | ||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | |||
| 163 | if (!EVP_AEAD_CTX_seal(&ctx, out, &out_len, sizeof(out), bufs[NONCE], | ||
| 164 | lengths[NONCE], bufs[IN], lengths[IN], bufs[AD], lengths[AD])) { | ||
| 165 | fprintf(stderr, "Failed to run AEAD on line %u\n", line_no); | ||
| 166 | return 0; | ||
| 167 | } | ||
| 168 | |||
| 169 | if (out_len != lengths[CT] + lengths[TAG]) { | ||
| 170 | fprintf(stderr, "Bad output length on line %u: %zu vs %u\n", | ||
| 171 | line_no, out_len, (unsigned)(lengths[CT] + lengths[TAG])); | ||
| 172 | return 0; | ||
| 173 | } | ||
| 174 | |||
| 175 | if (memcmp(out, bufs[CT], lengths[CT]) != 0) { | ||
| 176 | fprintf(stderr, "Bad output on line %u\n", line_no); | ||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | if (memcmp(out + lengths[CT], bufs[TAG], lengths[TAG]) != 0) { | ||
| 181 | fprintf(stderr, "Bad tag on line %u\n", line_no); | ||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | |||
| 185 | if (!EVP_AEAD_CTX_open(&ctx, out2, &out_len2, lengths[IN], bufs[NONCE], | ||
| 186 | lengths[NONCE], out, out_len, bufs[AD], lengths[AD])) { | ||
| 187 | fprintf(stderr, "Failed to decrypt on line %u\n", line_no); | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (out_len2 != lengths[IN]) { | ||
| 192 | fprintf(stderr, "Bad decrypt on line %u: %zu\n", | ||
| 193 | line_no, out_len2); | ||
| 194 | return 0; | ||
| 195 | } | ||
| 196 | |||
| 197 | if (memcmp(out2, bufs[IN], out_len2) != 0) { | ||
| 198 | fprintf(stderr, "Plaintext mismatch on line %u\n", line_no); | ||
| 199 | return 0; | ||
| 200 | } | ||
| 201 | |||
| 202 | out[0] ^= 0x80; | ||
| 203 | if (EVP_AEAD_CTX_open(&ctx, out2, &out_len2, lengths[IN], bufs[NONCE], | ||
| 204 | lengths[NONCE], out, out_len, bufs[AD], lengths[AD])) { | ||
| 205 | fprintf(stderr, "Decrypted bad data on line %u\n", line_no); | ||
| 206 | return 0; | ||
| 207 | } | ||
| 208 | |||
| 209 | EVP_AEAD_CTX_cleanup(&ctx); | ||
| 210 | return 1; | ||
| 211 | } | ||
| 212 | |||
| 213 | int | ||
| 214 | main(int argc, char **argv) | ||
| 215 | { | ||
| 216 | FILE *f; | ||
| 217 | const EVP_AEAD *aead = NULL; | ||
| 218 | unsigned int line_no = 0, num_tests = 0, j; | ||
| 219 | |||
| 220 | unsigned char bufs[NUM_TYPES][BUF_MAX]; | ||
| 221 | unsigned int lengths[NUM_TYPES]; | ||
| 222 | |||
| 223 | if (argc != 2) { | ||
| 224 | fprintf(stderr, "%s <test file.txt>\n", argv[0]); | ||
| 225 | return 1; | ||
| 226 | } | ||
| 227 | |||
| 228 | f = fopen(argv[1], "r"); | ||
| 229 | if (f == NULL) { | ||
| 230 | perror("failed to open input"); | ||
| 231 | return 1; | ||
| 232 | } | ||
| 233 | |||
| 234 | for (j = 0; j < NUM_TYPES; j++) | ||
| 235 | lengths[j] = 0; | ||
| 236 | |||
| 237 | for (;;) { | ||
| 238 | char line[4096]; | ||
| 239 | unsigned int i, type_len = 0; | ||
| 240 | |||
| 241 | unsigned char *buf = NULL; | ||
| 242 | unsigned int *buf_len = NULL; | ||
| 243 | |||
| 244 | if (!fgets(line, sizeof(line), f)) | ||
| 245 | break; | ||
| 246 | |||
| 247 | line_no++; | ||
| 248 | if (line[0] == '#') | ||
| 249 | continue; | ||
| 250 | |||
| 251 | if (line[0] == '\n' || line[0] == 0) { | ||
| 252 | /* Run a test, if possible. */ | ||
| 253 | char any_values_set = 0; | ||
| 254 | for (j = 0; j < NUM_TYPES; j++) { | ||
| 255 | if (lengths[j] != 0) { | ||
| 256 | any_values_set = 1; | ||
| 257 | break; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | |||
| 261 | if (!any_values_set) | ||
| 262 | continue; | ||
| 263 | |||
| 264 | switch (aead_from_name(&aead, bufs[AEAD])) { | ||
| 265 | case 0: | ||
| 266 | fprintf(stderr, "Skipping test...\n"); | ||
| 267 | continue; | ||
| 268 | case -1: | ||
| 269 | fprintf(stderr, "Aborting...\n"); | ||
| 270 | return 4; | ||
| 271 | } | ||
| 272 | |||
| 273 | if (!run_test_case(aead, bufs, lengths, line_no)) | ||
| 274 | return 4; | ||
| 275 | |||
| 276 | for (j = 0; j < NUM_TYPES; j++) | ||
| 277 | lengths[j] = 0; | ||
| 278 | |||
| 279 | num_tests++; | ||
| 280 | continue; | ||
| 281 | } | ||
| 282 | |||
| 283 | /* Each line looks like: | ||
| 284 | * TYPE: 0123abc | ||
| 285 | * Where "TYPE" is the type of the data on the line, | ||
| 286 | * e.g. "KEY". */ | ||
| 287 | for (i = 0; line[i] != 0 && line[i] != '\n'; i++) { | ||
| 288 | if (line[i] == ':') { | ||
| 289 | type_len = i; | ||
| 290 | break; | ||
| 291 | } | ||
| 292 | } | ||
| 293 | i++; | ||
| 294 | |||
| 295 | if (type_len == 0) { | ||
| 296 | fprintf(stderr, "Parse error on line %u\n", line_no); | ||
| 297 | return 3; | ||
| 298 | } | ||
| 299 | |||
| 300 | /* After the colon, there's optional whitespace. */ | ||
| 301 | for (; line[i] != 0 && line[i] != '\n'; i++) { | ||
| 302 | if (line[i] != ' ' && line[i] != '\t') | ||
| 303 | break; | ||
| 304 | } | ||
| 305 | |||
| 306 | line[type_len] = 0; | ||
| 307 | for (j = 0; j < NUM_TYPES; j++) { | ||
| 308 | if (strcmp(line, NAMES[j]) != 0) | ||
| 309 | continue; | ||
| 310 | if (lengths[j] != 0) { | ||
| 311 | fprintf(stderr, "Duplicate value on line %u\n", | ||
| 312 | line_no); | ||
| 313 | return 3; | ||
| 314 | } | ||
| 315 | buf = bufs[j]; | ||
| 316 | buf_len = &lengths[j]; | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | |||
| 320 | if (buf == NULL) { | ||
| 321 | fprintf(stderr, "Unknown line type on line %u\n", | ||
| 322 | line_no); | ||
| 323 | return 3; | ||
| 324 | } | ||
| 325 | |||
| 326 | if (j == AEAD) { | ||
| 327 | *buf_len = strlcpy(buf, line + i, BUF_MAX); | ||
| 328 | for (j = 0; j < BUF_MAX; j++) { | ||
| 329 | if (buf[j] == '\n') | ||
| 330 | buf[j] = '\0'; | ||
| 331 | } | ||
| 332 | continue; | ||
| 333 | } | ||
| 334 | |||
| 335 | for (j = 0; line[i] != 0 && line[i] != '\n'; i++) { | ||
| 336 | unsigned char v, v2; | ||
| 337 | v = hex_digit(line[i++]); | ||
| 338 | if (line[i] == 0 || line[i] == '\n') { | ||
| 339 | fprintf(stderr, "Odd-length hex data on " | ||
| 340 | "line %u\n", line_no); | ||
| 341 | return 3; | ||
| 342 | } | ||
| 343 | v2 = hex_digit(line[i]); | ||
| 344 | if (v > 15 || v2 > 15) { | ||
| 345 | fprintf(stderr, "Invalid hex char on line %u\n", | ||
| 346 | line_no); | ||
| 347 | return 3; | ||
| 348 | } | ||
| 349 | v <<= 4; | ||
| 350 | v |= v2; | ||
| 351 | |||
| 352 | if (j == BUF_MAX) { | ||
| 353 | fprintf(stderr, "Too much hex data on line %u " | ||
| 354 | "(max is %u bytes)\n", | ||
| 355 | line_no, (unsigned) BUF_MAX); | ||
| 356 | return 3; | ||
| 357 | } | ||
| 358 | buf[j++] = v; | ||
| 359 | *buf_len = *buf_len + 1; | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | printf("Completed %u test cases\n", num_tests); | ||
| 364 | printf("PASS\n"); | ||
| 365 | fclose(f); | ||
| 366 | |||
| 367 | return 0; | ||
| 368 | } | ||
diff --git a/src/regress/lib/libcrypto/aead/aeadtests.txt b/src/regress/lib/libcrypto/aead/aeadtests.txt deleted file mode 100644 index 18cee7e579..0000000000 --- a/src/regress/lib/libcrypto/aead/aeadtests.txt +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 1 | # $OpenBSD: aeadtests.txt,v 1.7 2018/07/17 17:06:49 tb Exp $ | ||
| 2 | # | ||
| 3 | # MACsec GCM-AES Test Vectors (bn-randall-test-vectors-0511-v1.pdf) | ||
| 4 | # | ||
| 5 | |||
| 6 | # 2.5.1 65-byte Packet Authentication Using GCM-AES-128 | ||
| 7 | AEAD: aes-128-gcm | ||
| 8 | KEY: 013FE00B5F11BE7F866D0CBBC55A7A90 | ||
| 9 | NONCE: 7CFDE9F9E33724C68932D612 | ||
| 10 | IN: | ||
| 11 | AD: 84C5D513D2AAF6E5BBD2727788E523008932D6127CFDE9F9E33724C608000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F0005 | ||
| 12 | CT: | ||
| 13 | TAG: 217867E50C2DAD74C28C3B50ABDF695A | ||
| 14 | |||
| 15 | # 2.5.2 65-byte Packet Authentication Using GCM-AES-256 | ||
| 16 | AEAD: aes-256-gcm | ||
| 17 | KEY: 83C093B58DE7FFE1C0DA926AC43FB3609AC1C80FEE1B624497EF942E2F79A823 | ||
| 18 | NONCE: 7CFDE9F9E33724C68932D612 | ||
| 19 | IN: | ||
| 20 | AD: 84C5D513D2AAF6E5BBD2727788E523008932D6127CFDE9F9E33724C608000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F0005 | ||
| 21 | CT: | ||
| 22 | TAG: 6EE160E8FAECA4B36C86B234920CA975 | ||
| 23 | |||
| 24 | # 2.8.1 75-byte Packet Encryption Using GCM-AES-128 | ||
| 25 | AEAD: aes-128-gcm | ||
| 26 | KEY: 88EE087FD95DA9FBF6725AA9D757B0CD | ||
| 27 | NONCE: 7AE8E2CA4EC500012E58495C | ||
| 28 | IN: 08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748490008 | ||
| 29 | AD: 68F2E77696CE7AE8E2CA4EC588E54D002E58495C | ||
| 30 | CT: C31F53D99E5687F7365119B832D2AAE70741D593F1F9E2AB3455779B078EB8FEACDFEC1F8E3E5277F8180B43361F6512ADB16D2E38548A2C719DBA7228D840 | ||
| 31 | TAG: 88F8757ADB8AA788D8F65AD668BE70E7 | ||
| 32 | |||
| 33 | # 2.8.2 75-byte Packet Encryption Using GCM-AES-256 | ||
| 34 | AEAD: aes-256-gcm | ||
| 35 | KEY: 4C973DBC7364621674F8B5B89E5C15511FCED9216490FB1C1A2CAA0FFE0407E5 | ||
| 36 | NONCE: 7AE8E2CA4EC500012E58495C | ||
| 37 | IN: 08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748490008 | ||
| 38 | AD: 68F2E77696CE7AE8E2CA4EC588E54D002E58495C | ||
| 39 | CT: BA8AE31BC506486D6873E4FCE460E7DC57591FF00611F31C3834FE1C04AD80B66803AFCF5B27E6333FA67C99DA47C2F0CED68D531BD741A943CFF7A6713BD0 | ||
| 40 | TAG: 2611CD7DAA01D61C5C886DC1A8170107 | ||
| 41 | |||
| 42 | # Test vector from RFC7539 2.8.2 | ||
| 43 | AEAD: chacha20-poly1305 | ||
| 44 | KEY: 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f | ||
| 45 | NONCE: 070000004041424344454647 | ||
| 46 | IN: 4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e | ||
| 47 | AD: 50515253c0c1c2c3c4c5c6c7 | ||
| 48 | CT: d31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b6116 | ||
| 49 | TAG: 1ae10b594f09e26a7e902ecbd0600691 | ||
| 50 | |||
| 51 | # Test vector from RFC7539 Appendix A.5 | ||
| 52 | AEAD: chacha20-poly1305 | ||
| 53 | KEY: 1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0 | ||
| 54 | NONCE: 000000000102030405060708 | ||
| 55 | IN: 496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67726573732e2fe2809d | ||
| 56 | AD: f33388860000000000004e91 | ||
| 57 | CT: 64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c29a6ad5cb4022b02709b | ||
| 58 | TAG: eead9d67890cbb22392336fea1851f38 | ||
| 59 | |||
| 60 | # Test vector from RFC7634 Appendix A | ||
| 61 | AEAD: chacha20-poly1305 | ||
| 62 | KEY: 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f | ||
| 63 | NONCE: a0a1a2a31011121314151617 | ||
| 64 | IN: 45000054a6f200004001e778c6336405c000020508005b7a3a080000553bec100007362708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363701020204 | ||
| 65 | AD: 0102030400000005 | ||
| 66 | CT: 24039428b97f417e3c13753a4f05087b67c352e6a7fab1b982d466ef407ae5c614ee8099d52844eb61aa95dfab4c02f72aa71e7c4c4f64c9befe2facc638e8f3cbec163fac469b502773f6fb94e664da9165b82829f641e0 | ||
| 67 | TAG: 76aaa8266b7fb0f7b11b369907e1ad43 | ||
| 68 | |||
| 69 | # Test vector from RFC7634 Appendix B | ||
| 70 | AEAD: chacha20-poly1305 | ||
| 71 | KEY: 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f | ||
| 72 | NONCE: a0a1a2a31011121314151617 | ||
| 73 | IN: 0000000c000040010000000a00 | ||
| 74 | AD: c0c1c2c3c4c5c6c7d0d1d2d3d4d5d6d72e202500000000090000004529000029 | ||
| 75 | CT: 610394701f8d017f7c12924889 | ||
| 76 | TAG: 6b71bfe25236efd7cdc67066906315b2 | ||
| 77 | |||
diff --git a/src/regress/lib/libcrypto/aeswrap/Makefile b/src/regress/lib/libcrypto/aeswrap/Makefile deleted file mode 100644 index dbdf48d183..0000000000 --- a/src/regress/lib/libcrypto/aeswrap/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= aes_wrap | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/aeswrap/aes_wrap.c b/src/regress/lib/libcrypto/aeswrap/aes_wrap.c deleted file mode 100644 index b48c7ae6e0..0000000000 --- a/src/regress/lib/libcrypto/aeswrap/aes_wrap.c +++ /dev/null | |||
| @@ -1,185 +0,0 @@ | |||
| 1 | /* $OpenBSD: aes_wrap.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | */ | ||
| 53 | |||
| 54 | #include <stdio.h> | ||
| 55 | #include <stdlib.h> | ||
| 56 | #include <string.h> | ||
| 57 | |||
| 58 | #include <openssl/aes.h> | ||
| 59 | |||
| 60 | int AES_wrap_unwrap_test(const unsigned char *, int, const unsigned char *, | ||
| 61 | const unsigned char *, const unsigned char *, int); | ||
| 62 | |||
| 63 | int | ||
| 64 | AES_wrap_unwrap_test(const unsigned char *kek, int keybits, | ||
| 65 | const unsigned char *iv, const unsigned char *eout, | ||
| 66 | const unsigned char *key, int keylen) | ||
| 67 | { | ||
| 68 | unsigned char *otmp = NULL, *ptmp = NULL; | ||
| 69 | int r, ret = 0; | ||
| 70 | AES_KEY wctx; | ||
| 71 | |||
| 72 | otmp = malloc(keylen + 8); | ||
| 73 | ptmp = malloc(keylen); | ||
| 74 | if (otmp == NULL || ptmp == NULL) | ||
| 75 | goto err; | ||
| 76 | if (AES_set_encrypt_key(kek, keybits, &wctx)) | ||
| 77 | goto err; | ||
| 78 | r = AES_wrap_key(&wctx, iv, otmp, key, keylen); | ||
| 79 | if (r <= 0) | ||
| 80 | goto err; | ||
| 81 | |||
| 82 | if (eout && memcmp(eout, otmp, keylen)) | ||
| 83 | goto err; | ||
| 84 | |||
| 85 | if (AES_set_decrypt_key(kek, keybits, &wctx)) | ||
| 86 | goto err; | ||
| 87 | r = AES_unwrap_key(&wctx, iv, ptmp, otmp, r); | ||
| 88 | |||
| 89 | if (memcmp(key, ptmp, keylen)) | ||
| 90 | goto err; | ||
| 91 | |||
| 92 | ret = 1; | ||
| 93 | |||
| 94 | err: | ||
| 95 | free(otmp); | ||
| 96 | free(ptmp); | ||
| 97 | |||
| 98 | return ret; | ||
| 99 | } | ||
| 100 | |||
| 101 | int | ||
| 102 | main(int argc, char **argv) | ||
| 103 | { | ||
| 104 | static const unsigned char kek[] = { | ||
| 105 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 106 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
| 107 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 108 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f | ||
| 109 | }; | ||
| 110 | |||
| 111 | static const unsigned char key[] = { | ||
| 112 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 113 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 114 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 115 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f | ||
| 116 | }; | ||
| 117 | |||
| 118 | static const unsigned char e1[] = { | ||
| 119 | 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, | ||
| 120 | 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, | ||
| 121 | 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5 | ||
| 122 | }; | ||
| 123 | |||
| 124 | static const unsigned char e2[] = { | ||
| 125 | 0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35, | ||
| 126 | 0xf9, 0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2, | ||
| 127 | 0x46, 0x8a, 0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d | ||
| 128 | }; | ||
| 129 | |||
| 130 | static const unsigned char e3[] = { | ||
| 131 | 0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2, | ||
| 132 | 0x63, 0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a, | ||
| 133 | 0x93, 0xc8, 0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7 | ||
| 134 | }; | ||
| 135 | |||
| 136 | static const unsigned char e4[] = { | ||
| 137 | 0x03, 0x1d, 0x33, 0x26, 0x4e, 0x15, 0xd3, 0x32, | ||
| 138 | 0x68, 0xf2, 0x4e, 0xc2, 0x60, 0x74, 0x3e, 0xdc, | ||
| 139 | 0xe1, 0xc6, 0xc7, 0xdd, 0xee, 0x72, 0x5a, 0x93, | ||
| 140 | 0x6b, 0xa8, 0x14, 0x91, 0x5c, 0x67, 0x62, 0xd2 | ||
| 141 | }; | ||
| 142 | |||
| 143 | static const unsigned char e5[] = { | ||
| 144 | 0xa8, 0xf9, 0xbc, 0x16, 0x12, 0xc6, 0x8b, 0x3f, | ||
| 145 | 0xf6, 0xe6, 0xf4, 0xfb, 0xe3, 0x0e, 0x71, 0xe4, | ||
| 146 | 0x76, 0x9c, 0x8b, 0x80, 0xa3, 0x2c, 0xb8, 0x95, | ||
| 147 | 0x8c, 0xd5, 0xd1, 0x7d, 0x6b, 0x25, 0x4d, 0xa1 | ||
| 148 | }; | ||
| 149 | |||
| 150 | static const unsigned char e6[] = { | ||
| 151 | 0x28, 0xc9, 0xf4, 0x04, 0xc4, 0xb8, 0x10, 0xf4, | ||
| 152 | 0xcb, 0xcc, 0xb3, 0x5c, 0xfb, 0x87, 0xf8, 0x26, | ||
| 153 | 0x3f, 0x57, 0x86, 0xe2, 0xd8, 0x0e, 0xd3, 0x26, | ||
| 154 | 0xcb, 0xc7, 0xf0, 0xe7, 0x1a, 0x99, 0xf4, 0x3b, | ||
| 155 | 0xfb, 0x98, 0x8b, 0x9b, 0x7a, 0x02, 0xdd, 0x21 | ||
| 156 | }; | ||
| 157 | |||
| 158 | int ret, nfailures = 0; | ||
| 159 | ret = AES_wrap_unwrap_test(kek, 128, NULL, e1, key, 16); | ||
| 160 | if (ret == 0) | ||
| 161 | nfailures++; | ||
| 162 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 163 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e2, key, 16); | ||
| 164 | if (ret == 0) | ||
| 165 | nfailures++; | ||
| 166 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 167 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e3, key, 16); | ||
| 168 | if (ret == 0) | ||
| 169 | nfailures++; | ||
| 170 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 171 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); | ||
| 172 | if (ret == 0) | ||
| 173 | nfailures++; | ||
| 174 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 175 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); | ||
| 176 | if (ret == 0) | ||
| 177 | nfailures++; | ||
| 178 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 179 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); | ||
| 180 | if (ret == 0) | ||
| 181 | nfailures++; | ||
| 182 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 183 | |||
| 184 | return nfailures; | ||
| 185 | } | ||
diff --git a/src/regress/lib/libcrypto/asn1/Makefile b/src/regress/lib/libcrypto/asn1/Makefile deleted file mode 100644 index 2dae70e9e5..0000000000 --- a/src/regress/lib/libcrypto/asn1/Makefile +++ /dev/null | |||
| @@ -1,23 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2018/08/31 17:35:21 tb Exp $ | ||
| 2 | |||
| 3 | TESTS = \ | ||
| 4 | asn1evp \ | ||
| 5 | asn1time \ | ||
| 6 | rfc5280time | ||
| 7 | |||
| 8 | PROGS = ${TESTS} | ||
| 9 | |||
| 10 | REGRESS_TARGETS= all_tests | ||
| 11 | |||
| 12 | LDADD= -lcrypto | ||
| 13 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 14 | WARNINGS= Yes | ||
| 15 | LDFLAGS+= -lcrypto | ||
| 16 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
| 17 | |||
| 18 | all_tests: ${TESTS} | ||
| 19 | @for test in $>; do \ | ||
| 20 | ./$$test; \ | ||
| 21 | done | ||
| 22 | |||
| 23 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/asn1/asn1evp.c b/src/regress/lib/libcrypto/asn1/asn1evp.c deleted file mode 100644 index d1870f9acc..0000000000 --- a/src/regress/lib/libcrypto/asn1/asn1evp.c +++ /dev/null | |||
| @@ -1,145 +0,0 @@ | |||
| 1 | /* $OpenBSD: asn1evp.c,v 1.2 2017/12/09 14:34:09 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <limits.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <string.h> | ||
| 21 | |||
| 22 | #include <openssl/asn1.h> | ||
| 23 | |||
| 24 | #define TEST_NUM 0x7fffffffL | ||
| 25 | |||
| 26 | unsigned char asn1_atios[] = { | ||
| 27 | 0x30, 0x10, 0x02, 0x04, 0x7f, 0xff, 0xff, 0xff, | ||
| 28 | 0x04, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, | ||
| 29 | 0x06, 0x07, | ||
| 30 | }; | ||
| 31 | |||
| 32 | unsigned char test_octetstring[] = { | ||
| 33 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 34 | }; | ||
| 35 | |||
| 36 | static void | ||
| 37 | hexdump(const unsigned char *buf, size_t len) | ||
| 38 | { | ||
| 39 | size_t i; | ||
| 40 | |||
| 41 | for (i = 1; i <= len; i++) | ||
| 42 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 43 | |||
| 44 | fprintf(stderr, "\n"); | ||
| 45 | } | ||
| 46 | |||
| 47 | static int | ||
| 48 | compare_data(const char *label, const unsigned char *d1, size_t d1_len, | ||
| 49 | const unsigned char *d2, size_t d2_len) | ||
| 50 | { | ||
| 51 | if (d1_len != d2_len) { | ||
| 52 | fprintf(stderr, "FAIL: got %s with length %zu, want %zu\n", | ||
| 53 | label, d1_len, d2_len); | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | if (memcmp(d1, d2, d1_len) != 0) { | ||
| 57 | fprintf(stderr, "FAIL: %s differs\n", label); | ||
| 58 | fprintf(stderr, "got:\n"); | ||
| 59 | hexdump(d1, d1_len); | ||
| 60 | fprintf(stderr, "want:\n"); | ||
| 61 | hexdump(d2, d2_len); | ||
| 62 | return -1; | ||
| 63 | } | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | int | ||
| 68 | main(int argc, char **argv) | ||
| 69 | { | ||
| 70 | unsigned char data[16]; | ||
| 71 | long num = TEST_NUM; | ||
| 72 | int failed = 1; | ||
| 73 | ASN1_TYPE at; | ||
| 74 | int len; | ||
| 75 | |||
| 76 | memset(&at, 0, sizeof(at)); | ||
| 77 | |||
| 78 | if (!ASN1_TYPE_set_int_octetstring(&at, num, test_octetstring, | ||
| 79 | sizeof(test_octetstring))) { | ||
| 80 | fprintf(stderr, "FAIL: ASN1_TYPE_set_int_octetstring failed\n"); | ||
| 81 | goto done; | ||
| 82 | } | ||
| 83 | if (at.type != V_ASN1_SEQUENCE) { | ||
| 84 | fprintf(stderr, "FAIL: not a V_ASN1_SEQUENCE (%i != %i)\n", | ||
| 85 | at.type, V_ASN1_SEQUENCE); | ||
| 86 | goto done; | ||
| 87 | } | ||
| 88 | if (at.value.sequence->type != V_ASN1_OCTET_STRING) { | ||
| 89 | fprintf(stderr, "FAIL: not a V_ASN1_OCTET_STRING (%i != %i)\n", | ||
| 90 | at.type, V_ASN1_OCTET_STRING); | ||
| 91 | goto done; | ||
| 92 | } | ||
| 93 | if (compare_data("sequence", at.value.sequence->data, | ||
| 94 | at.value.sequence->length, asn1_atios, sizeof(asn1_atios)) == -1) | ||
| 95 | goto done; | ||
| 96 | |||
| 97 | memset(&data, 0, sizeof(data)); | ||
| 98 | num = 0; | ||
| 99 | |||
| 100 | if ((len = ASN1_TYPE_get_int_octetstring(&at, &num, data, | ||
| 101 | sizeof(data))) < 0) { | ||
| 102 | fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n"); | ||
| 103 | goto done; | ||
| 104 | } | ||
| 105 | if (num != TEST_NUM) { | ||
| 106 | fprintf(stderr, "FAIL: got num %li, want %li\n", num, TEST_NUM); | ||
| 107 | goto done; | ||
| 108 | } | ||
| 109 | if (compare_data("octet string", data, len, | ||
| 110 | test_octetstring, sizeof(test_octetstring)) == -1) | ||
| 111 | goto done; | ||
| 112 | if (data[len] != 0) { | ||
| 113 | fprintf(stderr, "FAIL: octet string overflowed buffer\n"); | ||
| 114 | goto done; | ||
| 115 | } | ||
| 116 | |||
| 117 | memset(&data, 0, sizeof(data)); | ||
| 118 | num = 0; | ||
| 119 | |||
| 120 | /* With a limit buffer, the output should be truncated... */ | ||
| 121 | if ((len = ASN1_TYPE_get_int_octetstring(&at, &num, data, 4)) < 0) { | ||
| 122 | fprintf(stderr, "FAIL: ASN1_TYPE_get_int_octetstring failed\n"); | ||
| 123 | goto done; | ||
| 124 | } | ||
| 125 | if (num != TEST_NUM) { | ||
| 126 | fprintf(stderr, "FAIL: got num %li, want %li\n", num, TEST_NUM); | ||
| 127 | goto done; | ||
| 128 | } | ||
| 129 | if (len != sizeof(test_octetstring)) { | ||
| 130 | fprintf(stderr, "FAIL: got length mismatch (%i != %zu)\n", | ||
| 131 | len, sizeof(test_octetstring)); | ||
| 132 | goto done; | ||
| 133 | } | ||
| 134 | if (compare_data("octet string", data, 4, test_octetstring, 4) == -1) | ||
| 135 | goto done; | ||
| 136 | if (data[4] != 0) { | ||
| 137 | fprintf(stderr, "FAIL: octet string overflowed buffer\n"); | ||
| 138 | goto done; | ||
| 139 | } | ||
| 140 | |||
| 141 | failed = 0; | ||
| 142 | |||
| 143 | done: | ||
| 144 | return failed; | ||
| 145 | } | ||
diff --git a/src/regress/lib/libcrypto/asn1/asn1time.c b/src/regress/lib/libcrypto/asn1/asn1time.c deleted file mode 100644 index 6a3921bd9c..0000000000 --- a/src/regress/lib/libcrypto/asn1/asn1time.c +++ /dev/null | |||
| @@ -1,428 +0,0 @@ | |||
| 1 | /* $OpenBSD: asn1time.c,v 1.8 2015/12/28 14:18:38 bcook Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <openssl/asn1.h> | ||
| 19 | |||
| 20 | #include <err.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <string.h> | ||
| 23 | |||
| 24 | struct asn1_time_test { | ||
| 25 | const char *str; | ||
| 26 | const char *data; | ||
| 27 | const unsigned char der[32]; | ||
| 28 | time_t time; | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct asn1_time_test asn1_invtime_tests[] = { | ||
| 32 | { | ||
| 33 | .str = "", | ||
| 34 | }, | ||
| 35 | { | ||
| 36 | .str = "2015", | ||
| 37 | }, | ||
| 38 | { | ||
| 39 | .str = "201509", | ||
| 40 | }, | ||
| 41 | { | ||
| 42 | .str = "20150923", | ||
| 43 | }, | ||
| 44 | { | ||
| 45 | .str = "20150923032700", | ||
| 46 | }, | ||
| 47 | { | ||
| 48 | .str = "20150923032700.Z", | ||
| 49 | }, | ||
| 50 | { | ||
| 51 | .str = "20150923032700.123", | ||
| 52 | }, | ||
| 53 | { | ||
| 54 | .str = "20150923032700+1.09", | ||
| 55 | }, | ||
| 56 | { | ||
| 57 | .str = "20150923032700+1100Z", | ||
| 58 | }, | ||
| 59 | { | ||
| 60 | .str = "20150923032700-11001", | ||
| 61 | }, | ||
| 62 | { | ||
| 63 | /* UTC time cannot have fractional seconds. */ | ||
| 64 | .str = "150923032700.123Z", | ||
| 65 | }, | ||
| 66 | { | ||
| 67 | .str = "aaaaaaaaaaaaaaZ", | ||
| 68 | }, | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct asn1_time_test asn1_gentime_tests[] = { | ||
| 72 | { | ||
| 73 | .str = "19700101000000Z", | ||
| 74 | .data = "19700101000000Z", | ||
| 75 | .time = 0, | ||
| 76 | .der = { | ||
| 77 | 0x18, 0x0f, 0x31, 0x39, 0x37, 0x30, 0x30, 0x31, | ||
| 78 | 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, | ||
| 79 | 0x5a, | ||
| 80 | }, | ||
| 81 | }, | ||
| 82 | { | ||
| 83 | .str = "20150923032700Z", | ||
| 84 | .data = "20150923032700Z", | ||
| 85 | .time = 1442978820, | ||
| 86 | .der = { | ||
| 87 | 0x18, 0x0f, 0x32, 0x30, 0x31, 0x35, 0x30, 0x39, | ||
| 88 | 0x32, 0x33, 0x30, 0x33, 0x32, 0x37, 0x30, 0x30, | ||
| 89 | 0x5a, | ||
| 90 | }, | ||
| 91 | }, | ||
| 92 | }; | ||
| 93 | |||
| 94 | struct asn1_time_test asn1_utctime_tests[] = { | ||
| 95 | { | ||
| 96 | .str = "700101000000Z", | ||
| 97 | .data = "700101000000Z", | ||
| 98 | .time = 0, | ||
| 99 | .der = { | ||
| 100 | 0x17, 0x0d, 0x37, 0x30, 0x30, 0x31, 0x30, 0x31, | ||
| 101 | 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, | ||
| 102 | }, | ||
| 103 | }, | ||
| 104 | { | ||
| 105 | .str = "150923032700Z", | ||
| 106 | .data = "150923032700Z", | ||
| 107 | .time = 1442978820, | ||
| 108 | .der = { | ||
| 109 | 0x17, 0x0d, 0x31, 0x35, 0x30, 0x39, 0x32, 0x33, | ||
| 110 | 0x30, 0x33, 0x32, 0x37, 0x30, 0x30, 0x5a, | ||
| 111 | }, | ||
| 112 | }, | ||
| 113 | { | ||
| 114 | .str = "140524144512Z", | ||
| 115 | .data = "140524144512Z", | ||
| 116 | .time = 1400942712, | ||
| 117 | .der = { | ||
| 118 | 0x17, 0x0d, 0x31, 0x34, 0x30, 0x35, 0x32, 0x34, | ||
| 119 | 0x31, 0x34, 0x34, 0x35, 0x31, 0x32, 0x5a, | ||
| 120 | }, | ||
| 121 | }, | ||
| 122 | { | ||
| 123 | .str = "240401144512Z", | ||
| 124 | .data = "240401144512Z", | ||
| 125 | .time = 1711982712, | ||
| 126 | .der = { | ||
| 127 | 0x17, 0x0d, 0x32, 0x34, 0x30, 0x34, 0x30, 0x31, | ||
| 128 | 0x31, 0x34, 0x34, 0x35, 0x31, 0x32, 0x5a | ||
| 129 | }, | ||
| 130 | }, | ||
| 131 | }; | ||
| 132 | |||
| 133 | #define N_INVTIME_TESTS \ | ||
| 134 | (sizeof(asn1_invtime_tests) / sizeof(*asn1_invtime_tests)) | ||
| 135 | #define N_GENTIME_TESTS \ | ||
| 136 | (sizeof(asn1_gentime_tests) / sizeof(*asn1_gentime_tests)) | ||
| 137 | #define N_UTCTIME_TESTS \ | ||
| 138 | (sizeof(asn1_utctime_tests) / sizeof(*asn1_utctime_tests)) | ||
| 139 | |||
| 140 | static void | ||
| 141 | hexdump(const unsigned char *buf, size_t len) | ||
| 142 | { | ||
| 143 | size_t i; | ||
| 144 | |||
| 145 | for (i = 1; i <= len; i++) | ||
| 146 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 147 | |||
| 148 | fprintf(stderr, "\n"); | ||
| 149 | } | ||
| 150 | |||
| 151 | static int | ||
| 152 | asn1_compare_bytes(int test_no, const unsigned char *d1, | ||
| 153 | const unsigned char *d2, int len1, int len2) | ||
| 154 | { | ||
| 155 | if (len1 != len2) { | ||
| 156 | fprintf(stderr, "FAIL: test %i - byte lengths differ " | ||
| 157 | "(%i != %i)\n", test_no, len1, len2); | ||
| 158 | return (1); | ||
| 159 | } | ||
| 160 | if (memcmp(d1, d2, len1) != 0) { | ||
| 161 | fprintf(stderr, "FAIL: test %i - bytes differ\n", test_no); | ||
| 162 | fprintf(stderr, "Got:\n"); | ||
| 163 | hexdump(d1, len1); | ||
| 164 | fprintf(stderr, "Want:\n"); | ||
| 165 | hexdump(d2, len2); | ||
| 166 | } | ||
| 167 | return (0); | ||
| 168 | } | ||
| 169 | |||
| 170 | static int | ||
| 171 | asn1_compare_str(int test_no, struct asn1_string_st *asn1str, const char *str) | ||
| 172 | { | ||
| 173 | int length = strlen(str); | ||
| 174 | |||
| 175 | if (asn1str->length != length) { | ||
| 176 | fprintf(stderr, "FAIL: test %i - string lengths differ " | ||
| 177 | "(%i != %i)\n", test_no, asn1str->length, length); | ||
| 178 | return (1); | ||
| 179 | } | ||
| 180 | if (strncmp(asn1str->data, str, length) != 0) { | ||
| 181 | fprintf(stderr, "FAIL: test %i - strings differ " | ||
| 182 | "('%s' != '%s')\n", test_no, asn1str->data, str); | ||
| 183 | return (1); | ||
| 184 | } | ||
| 185 | |||
| 186 | return (0); | ||
| 187 | } | ||
| 188 | |||
| 189 | static int | ||
| 190 | asn1_invtime_test(int test_no, struct asn1_time_test *att) | ||
| 191 | { | ||
| 192 | ASN1_GENERALIZEDTIME *gt = NULL; | ||
| 193 | ASN1_UTCTIME *ut = NULL; | ||
| 194 | ASN1_TIME *t = NULL; | ||
| 195 | int failure = 1; | ||
| 196 | |||
| 197 | if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) | ||
| 198 | goto done; | ||
| 199 | if ((ut = ASN1_UTCTIME_new()) == NULL) | ||
| 200 | goto done; | ||
| 201 | if ((t = ASN1_TIME_new()) == NULL) | ||
| 202 | goto done; | ||
| 203 | |||
| 204 | if (ASN1_GENERALIZEDTIME_set_string(gt, att->str) != 0) { | ||
| 205 | fprintf(stderr, "FAIL: test %i - successfully set " | ||
| 206 | "GENERALIZEDTIME string '%s'\n", test_no, att->str); | ||
| 207 | goto done; | ||
| 208 | } | ||
| 209 | if (ASN1_UTCTIME_set_string(ut, att->str) != 0) { | ||
| 210 | fprintf(stderr, "FAIL: test %i - successfully set UTCTIME " | ||
| 211 | "string '%s'\n", test_no, att->str); | ||
| 212 | goto done; | ||
| 213 | } | ||
| 214 | if (ASN1_TIME_set_string(t, att->str) != 0) { | ||
| 215 | fprintf(stderr, "FAIL: test %i - successfully set TIME " | ||
| 216 | "string '%s'\n", test_no, att->str); | ||
| 217 | goto done; | ||
| 218 | } | ||
| 219 | |||
| 220 | failure = 0; | ||
| 221 | |||
| 222 | done: | ||
| 223 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 224 | ASN1_UTCTIME_free(ut); | ||
| 225 | ASN1_TIME_free(t); | ||
| 226 | |||
| 227 | return (failure); | ||
| 228 | } | ||
| 229 | |||
| 230 | static int | ||
| 231 | asn1_gentime_test(int test_no, struct asn1_time_test *att) | ||
| 232 | { | ||
| 233 | const unsigned char *der; | ||
| 234 | unsigned char *p = NULL; | ||
| 235 | ASN1_GENERALIZEDTIME *gt = NULL; | ||
| 236 | int failure = 1; | ||
| 237 | int len; | ||
| 238 | |||
| 239 | if (ASN1_GENERALIZEDTIME_set_string(NULL, att->str) != 1) { | ||
| 240 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 241 | test_no, att->str); | ||
| 242 | goto done; | ||
| 243 | } | ||
| 244 | |||
| 245 | if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) | ||
| 246 | goto done; | ||
| 247 | |||
| 248 | if (ASN1_GENERALIZEDTIME_set_string(gt, att->str) != 1) { | ||
| 249 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 250 | test_no, att->str); | ||
| 251 | goto done; | ||
| 252 | } | ||
| 253 | if (asn1_compare_str(test_no, gt, att->str) != 0) | ||
| 254 | goto done; | ||
| 255 | |||
| 256 | if ((len = i2d_ASN1_GENERALIZEDTIME(gt, &p)) <= 0) { | ||
| 257 | fprintf(stderr, "FAIL: test %i - i2d_ASN1_GENERALIZEDTIME " | ||
| 258 | "failed\n", test_no); | ||
| 259 | goto done; | ||
| 260 | } | ||
| 261 | der = att->der; | ||
| 262 | if (asn1_compare_bytes(test_no, p, der, len, strlen(der)) != 0) | ||
| 263 | goto done; | ||
| 264 | |||
| 265 | len = strlen(att->der); | ||
| 266 | if (d2i_ASN1_GENERALIZEDTIME(>, &der, len) == NULL) { | ||
| 267 | fprintf(stderr, "FAIL: test %i - d2i_ASN1_GENERALIZEDTIME " | ||
| 268 | "failed\n", test_no); | ||
| 269 | goto done; | ||
| 270 | } | ||
| 271 | if (asn1_compare_str(test_no, gt, att->str) != 0) | ||
| 272 | goto done; | ||
| 273 | |||
| 274 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 275 | |||
| 276 | if ((gt = ASN1_GENERALIZEDTIME_set(NULL, att->time)) == NULL) { | ||
| 277 | fprintf(stderr, "FAIL: test %i - failed to set time %lli\n", | ||
| 278 | test_no, (long long)att->time); | ||
| 279 | goto done; | ||
| 280 | } | ||
| 281 | if (asn1_compare_str(test_no, gt, att->data) != 0) | ||
| 282 | goto done; | ||
| 283 | |||
| 284 | failure = 0; | ||
| 285 | |||
| 286 | done: | ||
| 287 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 288 | free(p); | ||
| 289 | |||
| 290 | return (failure); | ||
| 291 | } | ||
| 292 | |||
| 293 | static int | ||
| 294 | asn1_utctime_test(int test_no, struct asn1_time_test *att) | ||
| 295 | { | ||
| 296 | const unsigned char *der; | ||
| 297 | unsigned char *p = NULL; | ||
| 298 | ASN1_UTCTIME *ut = NULL; | ||
| 299 | int failure = 1; | ||
| 300 | int len; | ||
| 301 | |||
| 302 | if (ASN1_UTCTIME_set_string(NULL, att->str) != 1) { | ||
| 303 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 304 | test_no, att->str); | ||
| 305 | goto done; | ||
| 306 | } | ||
| 307 | |||
| 308 | if ((ut = ASN1_UTCTIME_new()) == NULL) | ||
| 309 | goto done; | ||
| 310 | |||
| 311 | if (ASN1_UTCTIME_set_string(ut, att->str) != 1) { | ||
| 312 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 313 | test_no, att->str); | ||
| 314 | goto done; | ||
| 315 | } | ||
| 316 | if (asn1_compare_str(test_no, ut, att->str) != 0) | ||
| 317 | goto done; | ||
| 318 | |||
| 319 | if ((len = i2d_ASN1_UTCTIME(ut, &p)) <= 0) { | ||
| 320 | fprintf(stderr, "FAIL: test %i - i2d_ASN1_UTCTIME failed\n", | ||
| 321 | test_no); | ||
| 322 | goto done; | ||
| 323 | } | ||
| 324 | der = att->der; | ||
| 325 | if (asn1_compare_bytes(test_no, p, der, len, strlen(der)) != 0) | ||
| 326 | goto done; | ||
| 327 | |||
| 328 | len = strlen(att->der); | ||
| 329 | if (d2i_ASN1_UTCTIME(&ut, &der, len) == NULL) { | ||
| 330 | fprintf(stderr, "FAIL: test %i - d2i_ASN1_UTCTIME failed\n", | ||
| 331 | test_no); | ||
| 332 | goto done; | ||
| 333 | } | ||
| 334 | if (asn1_compare_str(test_no, ut, att->str) != 0) | ||
| 335 | goto done; | ||
| 336 | |||
| 337 | ASN1_UTCTIME_free(ut); | ||
| 338 | |||
| 339 | if ((ut = ASN1_UTCTIME_set(NULL, att->time)) == NULL) { | ||
| 340 | fprintf(stderr, "FAIL: test %i - failed to set time %lli\n", | ||
| 341 | test_no, (long long)att->time); | ||
| 342 | goto done; | ||
| 343 | } | ||
| 344 | if (asn1_compare_str(test_no, ut, att->data) != 0) | ||
| 345 | goto done; | ||
| 346 | |||
| 347 | failure = 0; | ||
| 348 | |||
| 349 | done: | ||
| 350 | ASN1_UTCTIME_free(ut); | ||
| 351 | free(p); | ||
| 352 | |||
| 353 | return (failure); | ||
| 354 | } | ||
| 355 | |||
| 356 | static int | ||
| 357 | asn1_time_test(int test_no, struct asn1_time_test *att, int type) | ||
| 358 | { | ||
| 359 | ASN1_TIME *t = NULL; | ||
| 360 | int failure = 1; | ||
| 361 | |||
| 362 | if (ASN1_TIME_set_string(NULL, att->str) != 1) { | ||
| 363 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 364 | test_no, att->str); | ||
| 365 | goto done; | ||
| 366 | } | ||
| 367 | |||
| 368 | if ((t = ASN1_TIME_new()) == NULL) | ||
| 369 | goto done; | ||
| 370 | |||
| 371 | if (ASN1_TIME_set_string(t, att->str) != 1) { | ||
| 372 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 373 | test_no, att->str); | ||
| 374 | goto done; | ||
| 375 | } | ||
| 376 | |||
| 377 | if (t->type != type) { | ||
| 378 | fprintf(stderr, "FAIL: test %i - got type %i, want %i\n", | ||
| 379 | test_no, t->type, type); | ||
| 380 | goto done; | ||
| 381 | } | ||
| 382 | |||
| 383 | failure = 0; | ||
| 384 | |||
| 385 | done: | ||
| 386 | |||
| 387 | ASN1_TIME_free(t); | ||
| 388 | |||
| 389 | return (failure); | ||
| 390 | } | ||
| 391 | |||
| 392 | int | ||
| 393 | main(int argc, char **argv) | ||
| 394 | { | ||
| 395 | struct asn1_time_test *att; | ||
| 396 | int failed = 0; | ||
| 397 | size_t i; | ||
| 398 | |||
| 399 | fprintf(stderr, "Invalid time tests...\n"); | ||
| 400 | for (i = 0; i < N_INVTIME_TESTS; i++) { | ||
| 401 | att = &asn1_invtime_tests[i]; | ||
| 402 | failed |= asn1_invtime_test(i, att); | ||
| 403 | } | ||
| 404 | |||
| 405 | fprintf(stderr, "GENERALIZEDTIME tests...\n"); | ||
| 406 | for (i = 0; i < N_GENTIME_TESTS; i++) { | ||
| 407 | att = &asn1_gentime_tests[i]; | ||
| 408 | failed |= asn1_gentime_test(i, att); | ||
| 409 | } | ||
| 410 | |||
| 411 | fprintf(stderr, "UTCTIME tests...\n"); | ||
| 412 | for (i = 0; i < N_UTCTIME_TESTS; i++) { | ||
| 413 | att = &asn1_utctime_tests[i]; | ||
| 414 | failed |= asn1_utctime_test(i, att); | ||
| 415 | } | ||
| 416 | |||
| 417 | fprintf(stderr, "TIME tests...\n"); | ||
| 418 | for (i = 0; i < N_UTCTIME_TESTS; i++) { | ||
| 419 | att = &asn1_utctime_tests[i]; | ||
| 420 | failed |= asn1_time_test(i, att, V_ASN1_UTCTIME); | ||
| 421 | } | ||
| 422 | for (i = 0; i < N_GENTIME_TESTS; i++) { | ||
| 423 | att = &asn1_gentime_tests[i]; | ||
| 424 | failed |= asn1_time_test(i, att, V_ASN1_GENERALIZEDTIME); | ||
| 425 | } | ||
| 426 | |||
| 427 | return (failed); | ||
| 428 | } | ||
diff --git a/src/regress/lib/libcrypto/asn1/rfc5280time.c b/src/regress/lib/libcrypto/asn1/rfc5280time.c deleted file mode 100644 index 34e40439dc..0000000000 --- a/src/regress/lib/libcrypto/asn1/rfc5280time.c +++ /dev/null | |||
| @@ -1,384 +0,0 @@ | |||
| 1 | /* $OpenBSD: rfc5280time.c,v 1.4 2015/10/30 15:52:55 miod Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
| 4 | * Copyright (c) 2015 Bob Beck <beck@opebsd.org> | ||
| 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 <openssl/asn1.h> | ||
| 20 | #include <openssl/x509.h> | ||
| 21 | |||
| 22 | #include <err.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | struct rfc5280_time_test { | ||
| 27 | const char *str; | ||
| 28 | const char *data; | ||
| 29 | time_t time; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct rfc5280_time_test rfc5280_invtime_tests[] = { | ||
| 33 | { | ||
| 34 | .str = "", | ||
| 35 | }, | ||
| 36 | { | ||
| 37 | .str = "2015", | ||
| 38 | }, | ||
| 39 | { | ||
| 40 | .str = "201509", | ||
| 41 | }, | ||
| 42 | { | ||
| 43 | .str = "20150923", | ||
| 44 | }, | ||
| 45 | { | ||
| 46 | .str = "20150923032700", | ||
| 47 | }, | ||
| 48 | { | ||
| 49 | /* UTC time must have seconds */ | ||
| 50 | .str = "7001010000Z", | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | .str = "201509230327Z", | ||
| 54 | }, | ||
| 55 | { | ||
| 56 | .str = "20150923032700.Z", | ||
| 57 | }, | ||
| 58 | { | ||
| 59 | .str = "20150923032700.123", | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | .str = "20150923032700+1100Z", | ||
| 63 | }, | ||
| 64 | { | ||
| 65 | .str = "20150923032700-11001", | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | /* UTC time cannot have fractional seconds. */ | ||
| 69 | .str = "150923032700.123Z", | ||
| 70 | }, | ||
| 71 | { | ||
| 72 | /* Gen time cannot have +- TZ. */ | ||
| 73 | .str = "20150923032712+1115", | ||
| 74 | }, | ||
| 75 | { | ||
| 76 | /* Gen time cannot have fractional seconds */ | ||
| 77 | .str = "20150923032712.123Z", | ||
| 78 | }, | ||
| 79 | { | ||
| 80 | .str = "aaaaaaaaaaaaaaZ", | ||
| 81 | }, | ||
| 82 | { | ||
| 83 | /* Must be a UTC time per RFC 5280 */ | ||
| 84 | .str = "19700101000000Z", | ||
| 85 | .data = "19700101000000Z", | ||
| 86 | .time = 0, | ||
| 87 | }, | ||
| 88 | { | ||
| 89 | /* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */ | ||
| 90 | .str = "20150923032700Z", | ||
| 91 | .data = "20150923032700Z", | ||
| 92 | .time = 1442978820, | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | /* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */ | ||
| 96 | .str = "00000101000000Z", | ||
| 97 | .data = "00000101000000Z", | ||
| 98 | .time = -62167219200LL, | ||
| 99 | }, | ||
| 100 | { | ||
| 101 | /* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */ | ||
| 102 | .str = "20491231235959Z", | ||
| 103 | .data = "20491231235959Z", | ||
| 104 | .time = 2524607999LL, | ||
| 105 | }, | ||
| 106 | { | ||
| 107 | /* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */ | ||
| 108 | .str = "19500101000000Z", | ||
| 109 | .data = "19500101000000Z", | ||
| 110 | .time = -631152000LL, | ||
| 111 | }, | ||
| 112 | }; | ||
| 113 | |||
| 114 | struct rfc5280_time_test rfc5280_gentime_tests[] = { | ||
| 115 | { | ||
| 116 | /* Biggest RFC 5280 time */ | ||
| 117 | .str = "99991231235959Z", | ||
| 118 | .data = "99991231235959Z", | ||
| 119 | .time = 253402300799LL, | ||
| 120 | }, | ||
| 121 | { | ||
| 122 | .str = "21600218104000Z", | ||
| 123 | .data = "21600218104000Z", | ||
| 124 | .time = 6000000000LL, | ||
| 125 | }, | ||
| 126 | { | ||
| 127 | /* Smallest RFC 5280 gen time */ | ||
| 128 | .str = "20500101000000Z", | ||
| 129 | .data = "20500101000000Z", | ||
| 130 | .time = 2524608000LL, | ||
| 131 | }, | ||
| 132 | }; | ||
| 133 | struct rfc5280_time_test rfc5280_utctime_tests[] = { | ||
| 134 | { | ||
| 135 | .str = "500101000000Z", | ||
| 136 | .data = "500101000000Z", | ||
| 137 | .time = -631152000, | ||
| 138 | }, | ||
| 139 | { | ||
| 140 | .str = "540226230640Z", | ||
| 141 | .data = "540226230640Z", | ||
| 142 | .time = -500000000, | ||
| 143 | }, | ||
| 144 | { | ||
| 145 | .str = "491231235959Z", | ||
| 146 | .data = "491231235959Z", | ||
| 147 | .time = 2524607999LL, | ||
| 148 | }, | ||
| 149 | { | ||
| 150 | .str = "700101000000Z", | ||
| 151 | .data = "700101000000Z", | ||
| 152 | .time = 0, | ||
| 153 | }, | ||
| 154 | { | ||
| 155 | .str = "150923032700Z", | ||
| 156 | .data = "150923032700Z", | ||
| 157 | .time = 1442978820, | ||
| 158 | }, | ||
| 159 | { | ||
| 160 | .str = "150923102700Z", | ||
| 161 | .data = "150923102700Z", | ||
| 162 | .time = 1443004020, | ||
| 163 | }, | ||
| 164 | { | ||
| 165 | .str = "150922162712Z", | ||
| 166 | .data = "150922162712Z", | ||
| 167 | .time = 1442939232, | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | .str = "140524144512Z", | ||
| 171 | .data = "140524144512Z", | ||
| 172 | .time = 1400942712, | ||
| 173 | }, | ||
| 174 | { | ||
| 175 | .str = "240401144512Z", | ||
| 176 | .data = "240401144512Z", | ||
| 177 | .time = 1711982712, | ||
| 178 | }, | ||
| 179 | }; | ||
| 180 | |||
| 181 | #define N_INVTIME_TESTS \ | ||
| 182 | (sizeof(rfc5280_invtime_tests) / sizeof(*rfc5280_invtime_tests)) | ||
| 183 | #define N_GENTIME_TESTS \ | ||
| 184 | (sizeof(rfc5280_gentime_tests) / sizeof(*rfc5280_gentime_tests)) | ||
| 185 | #define N_UTCTIME_TESTS \ | ||
| 186 | (sizeof(rfc5280_utctime_tests) / sizeof(*rfc5280_utctime_tests)) | ||
| 187 | |||
| 188 | static int | ||
| 189 | asn1_compare_str(int test_no, struct asn1_string_st *asn1str, const char *str) | ||
| 190 | { | ||
| 191 | int length = strlen(str); | ||
| 192 | |||
| 193 | if (asn1str->length != length) { | ||
| 194 | fprintf(stderr, "FAIL: test %i - string lengths differ " | ||
| 195 | "(%i != %i)\n", test_no, asn1str->length, length); | ||
| 196 | return (1); | ||
| 197 | } | ||
| 198 | if (strncmp(asn1str->data, str, length) != 0) { | ||
| 199 | fprintf(stderr, "FAIL: test %i - strings differ " | ||
| 200 | "('%s' != '%s')\n", test_no, asn1str->data, str); | ||
| 201 | return (1); | ||
| 202 | } | ||
| 203 | |||
| 204 | return (0); | ||
| 205 | } | ||
| 206 | |||
| 207 | static int | ||
| 208 | rfc5280_invtime_test(int test_no, struct rfc5280_time_test *att) | ||
| 209 | { | ||
| 210 | ASN1_GENERALIZEDTIME *gt = NULL; | ||
| 211 | ASN1_UTCTIME *ut = NULL; | ||
| 212 | ASN1_TIME *t = NULL; | ||
| 213 | int failure = 1; | ||
| 214 | time_t now = time(NULL); | ||
| 215 | |||
| 216 | if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) | ||
| 217 | goto done; | ||
| 218 | if ((ut = ASN1_UTCTIME_new()) == NULL) | ||
| 219 | goto done; | ||
| 220 | if ((t = ASN1_TIME_new()) == NULL) | ||
| 221 | goto done; | ||
| 222 | |||
| 223 | if (ASN1_GENERALIZEDTIME_set_string(gt, att->str) != 0) { | ||
| 224 | if (X509_cmp_time(gt, &now) != 0) { | ||
| 225 | fprintf(stderr, "FAIL: test %i - successfully parsed as GENTIME " | ||
| 226 | "string '%s'\n", test_no, att->str); | ||
| 227 | goto done; | ||
| 228 | } | ||
| 229 | } | ||
| 230 | if (ASN1_UTCTIME_set_string(ut, att->str) != 0) { | ||
| 231 | if (X509_cmp_time(ut, &now) != 0) { | ||
| 232 | fprintf(stderr, "FAIL: test %i - successfully parsed as UTCTIME " | ||
| 233 | "string '%s'\n", test_no, att->str); | ||
| 234 | goto done; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | if (ASN1_TIME_set_string(t, att->str) != 0) { | ||
| 238 | if (X509_cmp_time(t, &now) != 0) { | ||
| 239 | fprintf(stderr, "FAIL: test %i - successfully parsed as UTCTIME " | ||
| 240 | "string '%s'\n", test_no, att->str); | ||
| 241 | goto done; | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | failure = 0; | ||
| 246 | |||
| 247 | done: | ||
| 248 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 249 | ASN1_UTCTIME_free(ut); | ||
| 250 | ASN1_TIME_free(t); | ||
| 251 | |||
| 252 | return (failure); | ||
| 253 | } | ||
| 254 | |||
| 255 | static int | ||
| 256 | rfc5280_gentime_test(int test_no, struct rfc5280_time_test *att) | ||
| 257 | { | ||
| 258 | unsigned char *p = NULL; | ||
| 259 | ASN1_GENERALIZEDTIME *gt; | ||
| 260 | int failure = 1; | ||
| 261 | int i; | ||
| 262 | |||
| 263 | if ((gt = ASN1_GENERALIZEDTIME_new()) == NULL) | ||
| 264 | goto done; | ||
| 265 | |||
| 266 | if (ASN1_GENERALIZEDTIME_set_string(gt, att->str) != 1) { | ||
| 267 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 268 | test_no, att->str); | ||
| 269 | goto done; | ||
| 270 | } | ||
| 271 | if (asn1_compare_str(test_no, gt, att->str) != 0) | ||
| 272 | goto done; | ||
| 273 | |||
| 274 | if ((i = X509_cmp_time(gt, &att->time)) != -1) { | ||
| 275 | fprintf(stderr, "FAIL: test %i - X509_cmp_time failed - returned %d compared to %lld\n", | ||
| 276 | test_no, i, att->time); | ||
| 277 | goto done; | ||
| 278 | } | ||
| 279 | |||
| 280 | att->time--; | ||
| 281 | if ((i = X509_cmp_time(gt, &att->time)) != 1) { | ||
| 282 | fprintf(stderr, "FAIL: test %i - X509_cmp_time failed - returned %d compared to %lld\n", | ||
| 283 | test_no, i, att->time); | ||
| 284 | goto done; | ||
| 285 | } | ||
| 286 | att->time++; | ||
| 287 | |||
| 288 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 289 | |||
| 290 | if ((gt = ASN1_GENERALIZEDTIME_set(NULL, att->time)) == NULL) { | ||
| 291 | fprintf(stderr, "FAIL: test %i - failed to set time %lli\n", | ||
| 292 | test_no, (long long)att->time); | ||
| 293 | goto done; | ||
| 294 | } | ||
| 295 | if (asn1_compare_str(test_no, gt, att->data) != 0) | ||
| 296 | goto done; | ||
| 297 | |||
| 298 | failure = 0; | ||
| 299 | |||
| 300 | done: | ||
| 301 | ASN1_GENERALIZEDTIME_free(gt); | ||
| 302 | free(p); | ||
| 303 | |||
| 304 | return (failure); | ||
| 305 | } | ||
| 306 | |||
| 307 | static int | ||
| 308 | rfc5280_utctime_test(int test_no, struct rfc5280_time_test *att) | ||
| 309 | { | ||
| 310 | unsigned char *p = NULL; | ||
| 311 | ASN1_UTCTIME *ut; | ||
| 312 | int failure = 1; | ||
| 313 | int i; | ||
| 314 | |||
| 315 | if ((ut = ASN1_UTCTIME_new()) == NULL) | ||
| 316 | goto done; | ||
| 317 | |||
| 318 | if (ASN1_UTCTIME_set_string(ut, att->str) != 1) { | ||
| 319 | fprintf(stderr, "FAIL: test %i - failed to set string '%s'\n", | ||
| 320 | test_no, att->str); | ||
| 321 | goto done; | ||
| 322 | } | ||
| 323 | if (asn1_compare_str(test_no, ut, att->str) != 0) | ||
| 324 | goto done; | ||
| 325 | |||
| 326 | if ((i = X509_cmp_time(ut, &att->time)) != -1) { | ||
| 327 | fprintf(stderr, "FAIL: test %i - X509_cmp_time failed - returned %d compared to %lld\n", | ||
| 328 | test_no, i, att->time); | ||
| 329 | goto done; | ||
| 330 | } | ||
| 331 | |||
| 332 | att->time--; | ||
| 333 | if ((i = X509_cmp_time(ut, &att->time)) != 1) { | ||
| 334 | fprintf(stderr, "FAIL: test %i - X509_cmp_time failed - returned %d compared to %lld\n", | ||
| 335 | test_no, i, att->time); | ||
| 336 | goto done; | ||
| 337 | } | ||
| 338 | att->time++; | ||
| 339 | |||
| 340 | ASN1_UTCTIME_free(ut); | ||
| 341 | |||
| 342 | if ((ut = ASN1_UTCTIME_set(NULL, att->time)) == NULL) { | ||
| 343 | fprintf(stderr, "FAIL: test %i - failed to set time %lli\n", | ||
| 344 | test_no, (long long)att->time); | ||
| 345 | goto done; | ||
| 346 | } | ||
| 347 | if (asn1_compare_str(test_no, ut, att->data) != 0) | ||
| 348 | goto done; | ||
| 349 | |||
| 350 | failure = 0; | ||
| 351 | |||
| 352 | done: | ||
| 353 | ASN1_UTCTIME_free(ut); | ||
| 354 | free(p); | ||
| 355 | |||
| 356 | return (failure); | ||
| 357 | } | ||
| 358 | |||
| 359 | int | ||
| 360 | main(int argc, char **argv) | ||
| 361 | { | ||
| 362 | struct rfc5280_time_test *att; | ||
| 363 | int failed = 0; | ||
| 364 | size_t i; | ||
| 365 | |||
| 366 | fprintf(stderr, "RFC5280 Invalid time tests...\n"); | ||
| 367 | for (i = 0; i < N_INVTIME_TESTS; i++) { | ||
| 368 | att = &rfc5280_invtime_tests[i]; | ||
| 369 | failed |= rfc5280_invtime_test(i, att); | ||
| 370 | } | ||
| 371 | |||
| 372 | fprintf(stderr, "RFC5280 GENERALIZEDTIME tests...\n"); | ||
| 373 | for (i = 0; i < N_GENTIME_TESTS; i++) { | ||
| 374 | att = &rfc5280_gentime_tests[i]; | ||
| 375 | failed |= rfc5280_gentime_test(i, att); | ||
| 376 | } | ||
| 377 | |||
| 378 | fprintf(stderr, "RFC5280 UTCTIME tests...\n"); | ||
| 379 | for (i = 0; i < N_UTCTIME_TESTS; i++) { | ||
| 380 | att = &rfc5280_utctime_tests[i]; | ||
| 381 | failed |= rfc5280_utctime_test(i, att); | ||
| 382 | } | ||
| 383 | return (failed); | ||
| 384 | } | ||
diff --git a/src/regress/lib/libcrypto/base64/Makefile b/src/regress/lib/libcrypto/base64/Makefile deleted file mode 100644 index 2cc004c530..0000000000 --- a/src/regress/lib/libcrypto/base64/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= base64test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/base64/base64test.c b/src/regress/lib/libcrypto/base64/base64test.c deleted file mode 100644 index d6874d41f8..0000000000 --- a/src/regress/lib/libcrypto/base64/base64test.c +++ /dev/null | |||
| @@ -1,385 +0,0 @@ | |||
| 1 | /* $OpenBSD: base64test.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <openssl/bio.h> | ||
| 19 | #include <openssl/evp.h> | ||
| 20 | |||
| 21 | #include <err.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <sys/types.h> | ||
| 25 | |||
| 26 | #define BUF_SIZE 128 | ||
| 27 | |||
| 28 | struct base64_test { | ||
| 29 | const unsigned char in[BUF_SIZE]; | ||
| 30 | const ssize_t in_len; | ||
| 31 | const unsigned char out[BUF_SIZE]; | ||
| 32 | const ssize_t out_len; | ||
| 33 | const ssize_t valid_len; | ||
| 34 | }; | ||
| 35 | |||
| 36 | /* | ||
| 37 | * Many of these tests are based on those found in Go's encoding/base64 tests. | ||
| 38 | */ | ||
| 39 | struct base64_test base64_tests[] = { | ||
| 40 | |||
| 41 | /* RFC3548 examples. */ | ||
| 42 | { "\x14\xfb\x9c\x03\xd9\x7e", 6, "FPucA9l+", 8, 6, }, | ||
| 43 | { "\x14\xfb\x9c\x03\xd9", 5, "FPucA9k=", 8, 5, }, | ||
| 44 | { "\x14\xfb\x9c\x03", 4, "FPucAw==", 8, 4, }, | ||
| 45 | |||
| 46 | /* RFC4648 examples. */ | ||
| 47 | { "", 0, "", 0, 0, }, | ||
| 48 | { "f", 1, "Zg==", 4, 1, }, | ||
| 49 | { "fo", 2, "Zm8=", 4, 2, }, | ||
| 50 | { "foo", 3, "Zm9v", 4, 3, }, | ||
| 51 | { "foob", 4, "Zm9vYg==", 8, 4, }, | ||
| 52 | { "fooba", 5, "Zm9vYmE=", 8, 5, }, | ||
| 53 | { "foobar", 6, "Zm9vYmFy", 8, 6, }, | ||
| 54 | |||
| 55 | /* Wikipedia examples. */ | ||
| 56 | { "sure.", 5, "c3VyZS4=", 8, 5, }, | ||
| 57 | { "sure", 4, "c3VyZQ==", 8, 4, }, | ||
| 58 | { "sur", 3, "c3Vy", 4, 3, }, | ||
| 59 | { "su", 2, "c3U=", 4, 2, }, | ||
| 60 | { "leasure.", 8, "bGVhc3VyZS4=", 12, 8, }, | ||
| 61 | { "easure.", 7, "ZWFzdXJlLg==", 12, 7, }, | ||
| 62 | { "asure.", 6, "YXN1cmUu", 8, 6, }, | ||
| 63 | |||
| 64 | { "abcd", 4, "YWJjZA==", 8, 4, }, | ||
| 65 | |||
| 66 | { | ||
| 67 | "Twas brillig, and the slithy toves", | ||
| 68 | 34, | ||
| 69 | "VHdhcyBicmlsbGlnLCBhbmQgdGhlIHNsaXRoeSB0b3Zlcw==", | ||
| 70 | 48, | ||
| 71 | 34, | ||
| 72 | }, | ||
| 73 | }; | ||
| 74 | |||
| 75 | #define N_TESTS (sizeof(base64_tests) / sizeof(*base64_tests)) | ||
| 76 | |||
| 77 | struct base64_test base64_nl_tests[] = { | ||
| 78 | |||
| 79 | /* Corrupt/invalid encodings. */ | ||
| 80 | { "", -1, "", 0, 0, }, | ||
| 81 | { "", -1, "!!!!", 4, 0, }, | ||
| 82 | { "", -1, "====", 4, 0, }, | ||
| 83 | { "", -1, "x===", 4, 0, }, | ||
| 84 | { "", -1, "=AAA", 4, 0, }, | ||
| 85 | { "", -1, "A=AA", 4, 0, }, | ||
| 86 | { "", -1, "AA=A", 4, 0, }, | ||
| 87 | { "", -1, "AA==A", 5, 0, }, | ||
| 88 | { "", -1, "AAA=AAAA", 8, 0, }, | ||
| 89 | { "", -1, "AAAAA", 5, 0, }, | ||
| 90 | { "", -1, "AAAAAA", 6, 0, }, | ||
| 91 | { "", -1, "A=", 2, 0, }, | ||
| 92 | { "", -1, "A==", 3, 0, }, | ||
| 93 | { "", -1, "AA=", 3, 0, }, | ||
| 94 | { "", -1, "AA==", 4, 1, }, /* XXX - output ix 0x0. */ | ||
| 95 | { "", -1, "AAA=", 4, 2, }, /* XXX - output ix 2x 0x0. */ | ||
| 96 | { "", -1, "AAAA", 4, 3, }, /* XXX - output ix 3x 0x0. */ | ||
| 97 | { "", -1, "AAAAAA=", 7, 0, }, | ||
| 98 | { "", -1, "YWJjZA=====", 11, 0, }, | ||
| 99 | |||
| 100 | |||
| 101 | /* Encodings with embedded CR/LF. */ | ||
| 102 | { "sure", 4, "c3VyZQ==", 8, 4, }, | ||
| 103 | { "sure", 4, "c3VyZQ==\r", 9, 4, }, | ||
| 104 | { "sure", 4, "c3VyZQ==\n", 9, 4, }, | ||
| 105 | { "sure", 4, "c3VyZQ==\r\n", 10, 4, }, | ||
| 106 | { "sure", 4, "c3VyZ\r\nQ==", 10, 4, }, | ||
| 107 | { "sure", 4, "c3V\ryZ\nQ==", 10, 4, }, | ||
| 108 | { "sure", 4, "c3V\nyZ\rQ==", 10, 4, }, | ||
| 109 | { "sure", 4, "c3VyZ\nQ==", 9, 4, }, | ||
| 110 | { "sure", 4, "c3VyZQ\n==", 9, 4, }, | ||
| 111 | { "sure", 4, "c3VyZQ=\n=", 9, 4, }, | ||
| 112 | { "sure", 4, "c3VyZQ=\r\n\r\n=", 12, 4, }, | ||
| 113 | |||
| 114 | { | ||
| 115 | "", | ||
| 116 | -1, | ||
| 117 | "YWJjZA======================================================" | ||
| 118 | "============", | ||
| 119 | 74, | ||
| 120 | 0, | ||
| 121 | }, | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define N_NL_TESTS (sizeof(base64_nl_tests) / sizeof(*base64_nl_tests)) | ||
| 125 | |||
| 126 | struct base64_test base64_no_nl_tests[] = { | ||
| 127 | |||
| 128 | /* | ||
| 129 | * In non-newline mode, the output resulting from corrupt/invalid | ||
| 130 | * encodings is completely crazy. A number of zero bytes is returned | ||
| 131 | * rather than nothing. | ||
| 132 | */ | ||
| 133 | |||
| 134 | /* Corrupt/invalid encodings. */ | ||
| 135 | { "", -1, "", 0, 0, }, | ||
| 136 | { "", -1, "!!!!", 4, 0, }, | ||
| 137 | { "", -1, "====", 4, 1, }, | ||
| 138 | { "", -1, "x===", 4, 1, }, | ||
| 139 | { "", -1, "=AAA", 4, 3, }, | ||
| 140 | { "", -1, "A=AA", 4, 3, }, | ||
| 141 | { "", -1, "AA=A", 4, 3, }, | ||
| 142 | { "", -1, "AA==A", 5, 1, }, | ||
| 143 | { "", -1, "AAA=AAAA", 8, 6, }, | ||
| 144 | { "", -1, "AAAAA", 5, 3, }, | ||
| 145 | { "", -1, "AAAAAA", 6, 3, }, | ||
| 146 | { "", -1, "A=", 2, 0, }, | ||
| 147 | { "", -1, "A==", 3, 0, }, | ||
| 148 | { "", -1, "AA=", 3, 0, }, | ||
| 149 | { "", -1, "AA==", 4, 1, }, | ||
| 150 | { "", -1, "AAA=", 4, 2, }, | ||
| 151 | { "", -1, "AAAA", 4, 3, }, | ||
| 152 | { "", -1, "AAAAAA=", 7, 3, }, | ||
| 153 | { "", -1, "YWJjZA=====", 11, 4, }, | ||
| 154 | |||
| 155 | /* Encodings with embedded CR/LF. */ | ||
| 156 | { "sure", 4, "c3VyZQ==", 8, 4, }, | ||
| 157 | { "sure", 4, "c3VyZQ==\r", 9, 4, }, | ||
| 158 | { "sure", 4, "c3VyZQ==\n", 9, 4, }, | ||
| 159 | { "sure", 4, "c3VyZQ==\r\n", 10, 4, }, | ||
| 160 | { "sure", -1, "c3VyZ\r\nQ==", 10, 0, }, | ||
| 161 | { "sure", -1, "c3V\ryZ\nQ==", 10, 0, }, | ||
| 162 | { "sure", -1, "c3V\nyZ\rQ==", 10, 0, }, | ||
| 163 | { "sure", -1, "c3VyZ\nQ==", 9, 0, }, | ||
| 164 | { "sure", -1, "c3VyZQ\n==", 9, 0, }, | ||
| 165 | { "sure", -1, "c3VyZQ=\n=", 9, 0, }, | ||
| 166 | { "sure", -1, "c3VyZQ=\r\n\r\n=", 12, 0, }, | ||
| 167 | |||
| 168 | /* | ||
| 169 | * This is invalid, yet results in 'abcd' followed by a stream of | ||
| 170 | * zero value bytes. | ||
| 171 | */ | ||
| 172 | { | ||
| 173 | "", | ||
| 174 | -1, | ||
| 175 | "YWJjZA======================================================" | ||
| 176 | "============", | ||
| 177 | 74, | ||
| 178 | 52, | ||
| 179 | }, | ||
| 180 | }; | ||
| 181 | |||
| 182 | #define N_NO_NL_TESTS (sizeof(base64_no_nl_tests) / sizeof(*base64_no_nl_tests)) | ||
| 183 | |||
| 184 | static int | ||
| 185 | base64_encoding_test(int test_no, struct base64_test *bt, int test_nl) | ||
| 186 | { | ||
| 187 | BIO *bio_b64, *bio_mem; | ||
| 188 | unsigned char *buf, *out; | ||
| 189 | ssize_t i, len, b64len; | ||
| 190 | int failure = 0; | ||
| 191 | |||
| 192 | buf = malloc(BUF_SIZE); | ||
| 193 | if (buf == NULL) | ||
| 194 | errx(1, "malloc"); | ||
| 195 | |||
| 196 | bio_b64 = BIO_new(BIO_f_base64()); | ||
| 197 | if (bio_b64 == NULL) | ||
| 198 | errx(1, "BIO_new failed for BIO_f_base64"); | ||
| 199 | |||
| 200 | bio_mem = BIO_new(BIO_s_mem()); | ||
| 201 | if (bio_mem == NULL) | ||
| 202 | errx(1, "BIO_new failed for BIO_s_mem"); | ||
| 203 | |||
| 204 | bio_mem = BIO_push(bio_b64, bio_mem); | ||
| 205 | |||
| 206 | if (!test_nl) | ||
| 207 | BIO_set_flags(bio_b64, BIO_FLAGS_BASE64_NO_NL); | ||
| 208 | |||
| 209 | len = BIO_write(bio_mem, bt->in, bt->in_len); | ||
| 210 | if (len != bt->in_len) { | ||
| 211 | fprintf(stderr, "FAIL: test %i - only wrote %zi out of %zi " | ||
| 212 | "characters\n", test_no, len, bt->in_len); | ||
| 213 | failure = 1; | ||
| 214 | goto done; | ||
| 215 | } | ||
| 216 | if (BIO_flush(bio_mem) < 0) { | ||
| 217 | fprintf(stderr, "FAIL: test %i - flush failed\n", test_no); | ||
| 218 | failure = 1; | ||
| 219 | goto done; | ||
| 220 | } | ||
| 221 | |||
| 222 | b64len = 0; | ||
| 223 | for (i = 0; i < bt->out_len; i++) { | ||
| 224 | if (bt->out[i] == '\r' || bt->out[i] == '\n') | ||
| 225 | continue; | ||
| 226 | buf[b64len++] = bt->out[i]; | ||
| 227 | } | ||
| 228 | if (test_nl) | ||
| 229 | buf[b64len++] = '\n'; | ||
| 230 | |||
| 231 | len = BIO_get_mem_data(bio_mem, &out); | ||
| 232 | |||
| 233 | /* An empty string with NL results in no output, rather than '\n'. */ | ||
| 234 | if (test_nl && b64len == 1 && len == 0) | ||
| 235 | goto done; | ||
| 236 | |||
| 237 | if (len != b64len) { | ||
| 238 | fprintf(stderr, "FAIL: test %i - encoding resulted in %zi " | ||
| 239 | "characters instead of %zi\n", test_no, len, b64len); | ||
| 240 | failure = 1; | ||
| 241 | goto done; | ||
| 242 | } | ||
| 243 | |||
| 244 | if (memcmp(buf, out, b64len) != 0) { | ||
| 245 | fprintf(stderr, "FAIL: test %i - encoding differs:\n", test_no); | ||
| 246 | fprintf(stderr, " encoding: "); | ||
| 247 | for (i = 0; i < len; i++) | ||
| 248 | fprintf(stderr, "%c", out[i]); | ||
| 249 | fprintf(stderr, "\n"); | ||
| 250 | fprintf(stderr, " test data: "); | ||
| 251 | for (i = 0; i < bt->out_len; i++) | ||
| 252 | fprintf(stderr, "%c", buf[i]); | ||
| 253 | fprintf(stderr, "\n"); | ||
| 254 | failure = 1; | ||
| 255 | } | ||
| 256 | |||
| 257 | done: | ||
| 258 | BIO_free_all(bio_mem); | ||
| 259 | free(buf); | ||
| 260 | |||
| 261 | return failure; | ||
| 262 | } | ||
| 263 | |||
| 264 | static int | ||
| 265 | base64_decoding_test(int test_no, struct base64_test *bt, int test_nl) | ||
| 266 | { | ||
| 267 | BIO *bio_b64, *bio_mem; | ||
| 268 | char *buf, *input; | ||
| 269 | ssize_t i, inlen, len; | ||
| 270 | int failure = 0; | ||
| 271 | |||
| 272 | buf = malloc(BUF_SIZE); | ||
| 273 | if (buf == NULL) | ||
| 274 | errx(1, "malloc"); | ||
| 275 | |||
| 276 | input = (char *)bt->out; | ||
| 277 | inlen = bt->out_len; | ||
| 278 | |||
| 279 | if (test_nl) | ||
| 280 | inlen = asprintf(&input, "%s\r\n", bt->out); | ||
| 281 | |||
| 282 | bio_mem = BIO_new_mem_buf(input, inlen); | ||
| 283 | if (bio_mem == NULL) | ||
| 284 | errx(1, "BIO_new_mem_buf failed"); | ||
| 285 | |||
| 286 | bio_b64 = BIO_new(BIO_f_base64()); | ||
| 287 | if (bio_b64 == NULL) | ||
| 288 | errx(1, "BIO_new failed for BIO_f_base64"); | ||
| 289 | |||
| 290 | if (!test_nl) | ||
| 291 | BIO_set_flags(bio_b64, BIO_FLAGS_BASE64_NO_NL); | ||
| 292 | |||
| 293 | bio_mem = BIO_push(bio_b64, bio_mem); | ||
| 294 | |||
| 295 | /* | ||
| 296 | * If we wrote zero characters then a BIO_read will result in a return | ||
| 297 | * value of -1, hence we need to handle this case. | ||
| 298 | */ | ||
| 299 | len = BIO_read(bio_mem, buf, BUF_SIZE); | ||
| 300 | if (len != bt->valid_len && (bt->in_len != 0 || len != -1)) { | ||
| 301 | fprintf(stderr, "FAIL: test %i - decoding resulted in %zi " | ||
| 302 | "characters instead of %zi\n", test_no, len, bt->valid_len); | ||
| 303 | fprintf(stderr, " input: "); | ||
| 304 | for (i = 0; i < inlen; i++) | ||
| 305 | fprintf(stderr, "%c", input[i]); | ||
| 306 | fprintf(stderr, "\n"); | ||
| 307 | fprintf(stderr, " decoding: "); | ||
| 308 | for (i = 0; i < len; i++) | ||
| 309 | fprintf(stderr, "0x%x ", buf[i]); | ||
| 310 | fprintf(stderr, "\n"); | ||
| 311 | failure = 1; | ||
| 312 | goto done; | ||
| 313 | } | ||
| 314 | |||
| 315 | /* See if we expect this to fail decoding. */ | ||
| 316 | if (bt->in_len == -1) | ||
| 317 | goto done; | ||
| 318 | |||
| 319 | if (memcmp(bt->in, buf, bt->in_len) != 0) { | ||
| 320 | fprintf(stderr, "FAIL: test %i - decoding differs:\n", test_no); | ||
| 321 | fprintf(stderr, " decoding: "); | ||
| 322 | for (i = 0; i < len; i++) | ||
| 323 | fprintf(stderr, "0x%x ", buf[i]); | ||
| 324 | fprintf(stderr, "\n"); | ||
| 325 | fprintf(stderr, " test data: "); | ||
| 326 | for (i = 0; i < inlen; i++) | ||
| 327 | fprintf(stderr, "0x%x ", input[i]); | ||
| 328 | fprintf(stderr, "\n"); | ||
| 329 | failure = 1; | ||
| 330 | } | ||
| 331 | |||
| 332 | done: | ||
| 333 | BIO_free_all(bio_mem); | ||
| 334 | free(buf); | ||
| 335 | if (test_nl) | ||
| 336 | free(input); | ||
| 337 | |||
| 338 | return failure; | ||
| 339 | } | ||
| 340 | |||
| 341 | int | ||
| 342 | main(int argc, char **argv) | ||
| 343 | { | ||
| 344 | struct base64_test *bt; | ||
| 345 | int failed = 0; | ||
| 346 | size_t i; | ||
| 347 | |||
| 348 | fprintf(stderr, "Starting combined tests...\n"); | ||
| 349 | |||
| 350 | for (i = 0; i < N_TESTS; i++) { | ||
| 351 | bt = &base64_tests[i]; | ||
| 352 | if (bt->in_len != -1) | ||
| 353 | failed += base64_encoding_test(i, bt, 0); | ||
| 354 | if (bt->out_len != -1) | ||
| 355 | failed += base64_decoding_test(i, bt, 0); | ||
| 356 | if (bt->in_len != -1) | ||
| 357 | failed += base64_encoding_test(i, bt, 1); | ||
| 358 | if (bt->out_len != -1) | ||
| 359 | failed += base64_decoding_test(i, bt, 1); | ||
| 360 | } | ||
| 361 | |||
| 362 | fprintf(stderr, "Starting NL tests...\n"); | ||
| 363 | |||
| 364 | for (i = 0; i < N_NL_TESTS; i++) { | ||
| 365 | bt = &base64_nl_tests[i]; | ||
| 366 | |||
| 367 | if (bt->in_len != -1) | ||
| 368 | failed += base64_encoding_test(i, bt, 1); | ||
| 369 | if (bt->out_len != -1) | ||
| 370 | failed += base64_decoding_test(i, bt, 1); | ||
| 371 | } | ||
| 372 | |||
| 373 | fprintf(stderr, "Starting NO NL tests...\n"); | ||
| 374 | |||
| 375 | for (i = 0; i < N_NO_NL_TESTS; i++) { | ||
| 376 | bt = &base64_no_nl_tests[i]; | ||
| 377 | |||
| 378 | if (bt->in_len != -1) | ||
| 379 | failed += base64_encoding_test(i, bt, 0); | ||
| 380 | if (bt->out_len != -1) | ||
| 381 | failed += base64_decoding_test(i, bt, 0); | ||
| 382 | } | ||
| 383 | |||
| 384 | return failed; | ||
| 385 | } | ||
diff --git a/src/regress/lib/libcrypto/bf/Makefile b/src/regress/lib/libcrypto/bf/Makefile deleted file mode 100644 index 989b3bb8f4..0000000000 --- a/src/regress/lib/libcrypto/bf/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= bftest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/bf/bftest.c b/src/regress/lib/libcrypto/bf/bftest.c deleted file mode 100644 index 5239ffb250..0000000000 --- a/src/regress/lib/libcrypto/bf/bftest.c +++ /dev/null | |||
| @@ -1,513 +0,0 @@ | |||
| 1 | /* $OpenBSD: bftest.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* This has been a quickly hacked 'ideatest.c'. When I add tests for other | ||
| 60 | * RC2 modes, more of the code will be uncommented. */ | ||
| 61 | |||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <stdlib.h> | ||
| 65 | |||
| 66 | #include <openssl/blowfish.h> | ||
| 67 | |||
| 68 | static char *bf_key[2]={ | ||
| 69 | "abcdefghijklmnopqrstuvwxyz", | ||
| 70 | "Who is John Galt?" | ||
| 71 | }; | ||
| 72 | |||
| 73 | /* big endian */ | ||
| 74 | static BF_LONG bf_plain[2][2]={ | ||
| 75 | {0x424c4f57L,0x46495348L}, | ||
| 76 | {0xfedcba98L,0x76543210L} | ||
| 77 | }; | ||
| 78 | |||
| 79 | static BF_LONG bf_cipher[2][2]={ | ||
| 80 | {0x324ed0feL,0xf413a203L}, | ||
| 81 | {0xcc91732bL,0x8022f684L} | ||
| 82 | }; | ||
| 83 | /************/ | ||
| 84 | |||
| 85 | /* Lets use the DES test vectors :-) */ | ||
| 86 | #define NUM_TESTS 34 | ||
| 87 | static unsigned char ecb_data[NUM_TESTS][8]={ | ||
| 88 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 89 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 90 | {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 91 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 92 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 93 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 94 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 95 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, | ||
| 96 | {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, | ||
| 97 | {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, | ||
| 98 | {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, | ||
| 99 | {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, | ||
| 100 | {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, | ||
| 101 | {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, | ||
| 102 | {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, | ||
| 103 | {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, | ||
| 104 | {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, | ||
| 105 | {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, | ||
| 106 | {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, | ||
| 107 | {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, | ||
| 108 | {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, | ||
| 109 | {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, | ||
| 110 | {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, | ||
| 111 | {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, | ||
| 112 | {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, | ||
| 113 | {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, | ||
| 114 | {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, | ||
| 115 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
| 116 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
| 117 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
| 118 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 119 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 120 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 121 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; | ||
| 122 | |||
| 123 | static unsigned char plain_data[NUM_TESTS][8]={ | ||
| 124 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 125 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 126 | {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
| 127 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 128 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 129 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 130 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 131 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 132 | {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, | ||
| 133 | {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, | ||
| 134 | {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, | ||
| 135 | {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, | ||
| 136 | {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, | ||
| 137 | {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, | ||
| 138 | {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, | ||
| 139 | {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, | ||
| 140 | {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, | ||
| 141 | {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, | ||
| 142 | {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, | ||
| 143 | {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, | ||
| 144 | {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, | ||
| 145 | {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, | ||
| 146 | {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, | ||
| 147 | {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, | ||
| 148 | {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, | ||
| 149 | {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, | ||
| 150 | {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, | ||
| 151 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 152 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 153 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 154 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 155 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 156 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 157 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; | ||
| 158 | |||
| 159 | static unsigned char cipher_data[NUM_TESTS][8]={ | ||
| 160 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
| 161 | {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A}, | ||
| 162 | {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2}, | ||
| 163 | {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D}, | ||
| 164 | {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96}, | ||
| 165 | {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7}, | ||
| 166 | {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78}, | ||
| 167 | {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D}, | ||
| 168 | {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B}, | ||
| 169 | {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0}, | ||
| 170 | {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4}, | ||
| 171 | {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB}, | ||
| 172 | {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A}, | ||
| 173 | {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18}, | ||
| 174 | {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98}, | ||
| 175 | {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5}, | ||
| 176 | {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79}, | ||
| 177 | {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3}, | ||
| 178 | {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69}, | ||
| 179 | {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B}, | ||
| 180 | {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E}, | ||
| 181 | {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD}, | ||
| 182 | {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19}, | ||
| 183 | {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3}, | ||
| 184 | {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5}, | ||
| 185 | {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78}, | ||
| 186 | {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01}, | ||
| 187 | {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2}, | ||
| 188 | {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE}, | ||
| 189 | {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D}, | ||
| 190 | {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4}, | ||
| 191 | {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC}, | ||
| 192 | {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A}, | ||
| 193 | {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A}, | ||
| 194 | }; | ||
| 195 | |||
| 196 | static unsigned char cbc_key [16]={ | ||
| 197 | 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, | ||
| 198 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
| 199 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
| 200 | static char cbc_data[40]="7654321 Now is the time for "; | ||
| 201 | static unsigned char cbc_ok[32]={ | ||
| 202 | 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6, | ||
| 203 | 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93, | ||
| 204 | 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9, | ||
| 205 | 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC}; | ||
| 206 | |||
| 207 | static unsigned char cfb64_ok[]={ | ||
| 208 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
| 209 | 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E, | ||
| 210 | 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00, | ||
| 211 | 0x51,0x9D,0x57,0xA6,0xC3}; | ||
| 212 | |||
| 213 | static unsigned char ofb64_ok[]={ | ||
| 214 | 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA, | ||
| 215 | 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73, | ||
| 216 | 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22, | ||
| 217 | 0x63,0xC2,0xCF,0x80,0xDA}; | ||
| 218 | |||
| 219 | #define KEY_TEST_NUM 25 | ||
| 220 | static unsigned char key_test[KEY_TEST_NUM]={ | ||
| 221 | 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87, | ||
| 222 | 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f, | ||
| 223 | 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77, | ||
| 224 | 0x88}; | ||
| 225 | |||
| 226 | static unsigned char key_data[8]= | ||
| 227 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}; | ||
| 228 | |||
| 229 | static unsigned char key_out[KEY_TEST_NUM][8]={ | ||
| 230 | {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E}, | ||
| 231 | {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6}, | ||
| 232 | {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3}, | ||
| 233 | {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05}, | ||
| 234 | {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E}, | ||
| 235 | {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D}, | ||
| 236 | {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D}, | ||
| 237 | {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82}, | ||
| 238 | {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77}, | ||
| 239 | {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0}, | ||
| 240 | {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6}, | ||
| 241 | {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2}, | ||
| 242 | {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4}, | ||
| 243 | {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68}, | ||
| 244 | {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F}, | ||
| 245 | {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C}, | ||
| 246 | {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B}, | ||
| 247 | {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B}, | ||
| 248 | {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8}, | ||
| 249 | {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F}, | ||
| 250 | {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F}, | ||
| 251 | {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F}, | ||
| 252 | {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD}, | ||
| 253 | {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, | ||
| 254 | }; | ||
| 255 | |||
| 256 | static int test(void ); | ||
| 257 | static int print_test_data(void ); | ||
| 258 | int main(int argc, char *argv[]) | ||
| 259 | { | ||
| 260 | int ret; | ||
| 261 | |||
| 262 | if (argc > 1) | ||
| 263 | ret=print_test_data(); | ||
| 264 | else | ||
| 265 | ret=test(); | ||
| 266 | |||
| 267 | return ret; | ||
| 268 | } | ||
| 269 | |||
| 270 | static int print_test_data(void) | ||
| 271 | { | ||
| 272 | unsigned int i,j; | ||
| 273 | |||
| 274 | printf("ecb test data\n"); | ||
| 275 | printf("key bytes\t\tclear bytes\t\tcipher bytes\n"); | ||
| 276 | for (i=0; i<NUM_TESTS; i++) | ||
| 277 | { | ||
| 278 | for (j=0; j<8; j++) | ||
| 279 | printf("%02X",ecb_data[i][j]); | ||
| 280 | printf("\t"); | ||
| 281 | for (j=0; j<8; j++) | ||
| 282 | printf("%02X",plain_data[i][j]); | ||
| 283 | printf("\t"); | ||
| 284 | for (j=0; j<8; j++) | ||
| 285 | printf("%02X",cipher_data[i][j]); | ||
| 286 | printf("\n"); | ||
| 287 | } | ||
| 288 | |||
| 289 | printf("set_key test data\n"); | ||
| 290 | printf("data[8]= "); | ||
| 291 | for (j=0; j<8; j++) | ||
| 292 | printf("%02X",key_data[j]); | ||
| 293 | printf("\n"); | ||
| 294 | for (i=0; i<KEY_TEST_NUM-1; i++) | ||
| 295 | { | ||
| 296 | printf("c="); | ||
| 297 | for (j=0; j<8; j++) | ||
| 298 | printf("%02X",key_out[i][j]); | ||
| 299 | printf(" k[%2u]=",i+1); | ||
| 300 | for (j=0; j<i+1; j++) | ||
| 301 | printf("%02X",key_test[j]); | ||
| 302 | printf("\n"); | ||
| 303 | } | ||
| 304 | |||
| 305 | printf("\nchaining mode test data\n"); | ||
| 306 | printf("key[16] = "); | ||
| 307 | for (j=0; j<16; j++) | ||
| 308 | printf("%02X",cbc_key[j]); | ||
| 309 | printf("\niv[8] = "); | ||
| 310 | for (j=0; j<8; j++) | ||
| 311 | printf("%02X",cbc_iv[j]); | ||
| 312 | printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data); | ||
| 313 | printf("\ndata[%d] = ",(int)strlen(cbc_data)+1); | ||
| 314 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
| 315 | printf("%02X",cbc_data[j]); | ||
| 316 | printf("\n"); | ||
| 317 | printf("cbc cipher text\n"); | ||
| 318 | printf("cipher[%d]= ",32); | ||
| 319 | for (j=0; j<32; j++) | ||
| 320 | printf("%02X",cbc_ok[j]); | ||
| 321 | printf("\n"); | ||
| 322 | |||
| 323 | printf("cfb64 cipher text\n"); | ||
| 324 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
| 325 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
| 326 | printf("%02X",cfb64_ok[j]); | ||
| 327 | printf("\n"); | ||
| 328 | |||
| 329 | printf("ofb64 cipher text\n"); | ||
| 330 | printf("cipher[%d]= ",(int)strlen(cbc_data)+1); | ||
| 331 | for (j=0; j<strlen(cbc_data)+1; j++) | ||
| 332 | printf("%02X",ofb64_ok[j]); | ||
| 333 | printf("\n"); | ||
| 334 | return(0); | ||
| 335 | } | ||
| 336 | |||
| 337 | static int test(void) | ||
| 338 | { | ||
| 339 | unsigned char cbc_in[40],cbc_out[40],iv[8]; | ||
| 340 | int i,n,err=0; | ||
| 341 | BF_KEY key; | ||
| 342 | BF_LONG data[2]; | ||
| 343 | unsigned char out[8]; | ||
| 344 | BF_LONG len; | ||
| 345 | |||
| 346 | printf("testing blowfish in raw ecb mode\n"); | ||
| 347 | for (n=0; n<2; n++) | ||
| 348 | { | ||
| 349 | BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]); | ||
| 350 | |||
| 351 | data[0]=bf_plain[n][0]; | ||
| 352 | data[1]=bf_plain[n][1]; | ||
| 353 | BF_encrypt(data,&key); | ||
| 354 | if (memcmp(&(bf_cipher[n][0]),&(data[0]), sizeof data) != 0) | ||
| 355 | { | ||
| 356 | printf("BF_encrypt error encrypting\n"); | ||
| 357 | printf("got :"); | ||
| 358 | for (i=0; i<2; i++) | ||
| 359 | printf("%08lX ",(unsigned long)data[i]); | ||
| 360 | printf("\n"); | ||
| 361 | printf("expected:"); | ||
| 362 | for (i=0; i<2; i++) | ||
| 363 | printf("%08lX ",(unsigned long)bf_cipher[n][i]); | ||
| 364 | err=1; | ||
| 365 | printf("\n"); | ||
| 366 | } | ||
| 367 | |||
| 368 | BF_decrypt(&(data[0]),&key); | ||
| 369 | if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0) | ||
| 370 | { | ||
| 371 | printf("BF_encrypt error decrypting\n"); | ||
| 372 | printf("got :"); | ||
| 373 | for (i=0; i<2; i++) | ||
| 374 | printf("%08lX ",(unsigned long)data[i]); | ||
| 375 | printf("\n"); | ||
| 376 | printf("expected:"); | ||
| 377 | for (i=0; i<2; i++) | ||
| 378 | printf("%08lX ",(unsigned long)bf_plain[n][i]); | ||
| 379 | printf("\n"); | ||
| 380 | err=1; | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | printf("testing blowfish in ecb mode\n"); | ||
| 385 | |||
| 386 | for (n=0; n<NUM_TESTS; n++) | ||
| 387 | { | ||
| 388 | BF_set_key(&key,8,ecb_data[n]); | ||
| 389 | |||
| 390 | BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT); | ||
| 391 | if (memcmp(&(cipher_data[n][0]),out,8) != 0) | ||
| 392 | { | ||
| 393 | printf("BF_ecb_encrypt blowfish error encrypting\n"); | ||
| 394 | printf("got :"); | ||
| 395 | for (i=0; i<8; i++) | ||
| 396 | printf("%02X ",out[i]); | ||
| 397 | printf("\n"); | ||
| 398 | printf("expected:"); | ||
| 399 | for (i=0; i<8; i++) | ||
| 400 | printf("%02X ",cipher_data[n][i]); | ||
| 401 | err=1; | ||
| 402 | printf("\n"); | ||
| 403 | } | ||
| 404 | |||
| 405 | BF_ecb_encrypt(out,out,&key,BF_DECRYPT); | ||
| 406 | if (memcmp(&(plain_data[n][0]),out,8) != 0) | ||
| 407 | { | ||
| 408 | printf("BF_ecb_encrypt error decrypting\n"); | ||
| 409 | printf("got :"); | ||
| 410 | for (i=0; i<8; i++) | ||
| 411 | printf("%02X ",out[i]); | ||
| 412 | printf("\n"); | ||
| 413 | printf("expected:"); | ||
| 414 | for (i=0; i<8; i++) | ||
| 415 | printf("%02X ",plain_data[n][i]); | ||
| 416 | printf("\n"); | ||
| 417 | err=1; | ||
| 418 | } | ||
| 419 | } | ||
| 420 | |||
| 421 | printf("testing blowfish set_key\n"); | ||
| 422 | for (n=1; n<KEY_TEST_NUM; n++) | ||
| 423 | { | ||
| 424 | BF_set_key(&key,n,key_test); | ||
| 425 | BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT); | ||
| 426 | if (memcmp(out,&(key_out[n-1][0]),8) != 0) | ||
| 427 | { | ||
| 428 | printf("blowfish setkey error\n"); | ||
| 429 | err=1; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | printf("testing blowfish in cbc mode\n"); | ||
| 434 | len=strlen(cbc_data)+1; | ||
| 435 | |||
| 436 | BF_set_key(&key,16,cbc_key); | ||
| 437 | memset(cbc_in,0,sizeof cbc_in); | ||
| 438 | memset(cbc_out,0,sizeof cbc_out); | ||
| 439 | memcpy(iv,cbc_iv,sizeof iv); | ||
| 440 | BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len, | ||
| 441 | &key,iv,BF_ENCRYPT); | ||
| 442 | if (memcmp(cbc_out,cbc_ok,32) != 0) | ||
| 443 | { | ||
| 444 | err=1; | ||
| 445 | printf("BF_cbc_encrypt encrypt error\n"); | ||
| 446 | for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]); | ||
| 447 | } | ||
| 448 | memcpy(iv,cbc_iv,8); | ||
| 449 | BF_cbc_encrypt(cbc_out,cbc_in,len, | ||
| 450 | &key,iv,BF_DECRYPT); | ||
| 451 | if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) | ||
| 452 | { | ||
| 453 | printf("BF_cbc_encrypt decrypt error\n"); | ||
| 454 | err=1; | ||
| 455 | } | ||
| 456 | |||
| 457 | printf("testing blowfish in cfb64 mode\n"); | ||
| 458 | |||
| 459 | BF_set_key(&key,16,cbc_key); | ||
| 460 | memset(cbc_in,0,40); | ||
| 461 | memset(cbc_out,0,40); | ||
| 462 | memcpy(iv,cbc_iv,8); | ||
| 463 | n=0; | ||
| 464 | BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13, | ||
| 465 | &key,iv,&n,BF_ENCRYPT); | ||
| 466 | BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13, | ||
| 467 | &key,iv,&n,BF_ENCRYPT); | ||
| 468 | if (memcmp(cbc_out,cfb64_ok,(int)len) != 0) | ||
| 469 | { | ||
| 470 | err=1; | ||
| 471 | printf("BF_cfb64_encrypt encrypt error\n"); | ||
| 472 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
| 473 | } | ||
| 474 | n=0; | ||
| 475 | memcpy(iv,cbc_iv,8); | ||
| 476 | BF_cfb64_encrypt(cbc_out,cbc_in,17, | ||
| 477 | &key,iv,&n,BF_DECRYPT); | ||
| 478 | BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17, | ||
| 479 | &key,iv,&n,BF_DECRYPT); | ||
| 480 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
| 481 | { | ||
| 482 | printf("BF_cfb64_encrypt decrypt error\n"); | ||
| 483 | err=1; | ||
| 484 | } | ||
| 485 | |||
| 486 | printf("testing blowfish in ofb64\n"); | ||
| 487 | |||
| 488 | BF_set_key(&key,16,cbc_key); | ||
| 489 | memset(cbc_in,0,40); | ||
| 490 | memset(cbc_out,0,40); | ||
| 491 | memcpy(iv,cbc_iv,8); | ||
| 492 | n=0; | ||
| 493 | BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n); | ||
| 494 | BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]), | ||
| 495 | &(cbc_out[13]),len-13,&key,iv,&n); | ||
| 496 | if (memcmp(cbc_out,ofb64_ok,(int)len) != 0) | ||
| 497 | { | ||
| 498 | err=1; | ||
| 499 | printf("BF_ofb64_encrypt encrypt error\n"); | ||
| 500 | for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]); | ||
| 501 | } | ||
| 502 | n=0; | ||
| 503 | memcpy(iv,cbc_iv,8); | ||
| 504 | BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n); | ||
| 505 | BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n); | ||
| 506 | if (memcmp(cbc_in,cbc_data,(int)len) != 0) | ||
| 507 | { | ||
| 508 | printf("BF_ofb64_encrypt decrypt error\n"); | ||
| 509 | err=1; | ||
| 510 | } | ||
| 511 | |||
| 512 | return(err); | ||
| 513 | } | ||
diff --git a/src/regress/lib/libcrypto/bio/Makefile b/src/regress/lib/libcrypto/bio/Makefile deleted file mode 100644 index fab7d44d50..0000000000 --- a/src/regress/lib/libcrypto/bio/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= biotest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c deleted file mode 100644 index 867305a904..0000000000 --- a/src/regress/lib/libcrypto/bio/biotest.c +++ /dev/null | |||
| @@ -1,155 +0,0 @@ | |||
| 1 | /* $OpenBSD: biotest.c,v 1.6 2017/04/30 17:46:27 beck Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/types.h> | ||
| 19 | |||
| 20 | #include <stdint.h> | ||
| 21 | #include <stdlib.h> | ||
| 22 | #include <string.h> | ||
| 23 | |||
| 24 | #include <netinet/in.h> | ||
| 25 | |||
| 26 | #include <openssl/bio.h> | ||
| 27 | #include <openssl/err.h> | ||
| 28 | |||
| 29 | struct bio_get_host_ip_test { | ||
| 30 | char *input; | ||
| 31 | uint32_t ip; | ||
| 32 | int ret; | ||
| 33 | }; | ||
| 34 | |||
| 35 | struct bio_get_host_ip_test bio_get_host_ip_tests[] = { | ||
| 36 | {"", 0, 0}, | ||
| 37 | {".", 0, 0}, | ||
| 38 | {"1", 0, 0}, | ||
| 39 | {"1.2", 0, 0}, | ||
| 40 | {"1.2.3", 0, 0}, | ||
| 41 | {"1.2.3.", 0, 0}, | ||
| 42 | {"1.2.3.4", 0x01020304, 1}, | ||
| 43 | {"1.2.3.256", 0, 0}, | ||
| 44 | {"1:2:3::4", 0, 0}, | ||
| 45 | {"0.0.0.0", INADDR_ANY, 1}, | ||
| 46 | {"127.0.0.1", INADDR_LOOPBACK, 1}, | ||
| 47 | {"localhost", INADDR_LOOPBACK, 1}, | ||
| 48 | {"255.255.255.255", INADDR_BROADCAST, 1}, | ||
| 49 | {"0xff.0xff.0xff.0xff", 0, 0}, | ||
| 50 | }; | ||
| 51 | |||
| 52 | #define N_BIO_GET_IP_TESTS \ | ||
| 53 | (sizeof(bio_get_host_ip_tests) / sizeof(*bio_get_host_ip_tests)) | ||
| 54 | |||
| 55 | struct bio_get_port_test { | ||
| 56 | char *input; | ||
| 57 | unsigned short port; | ||
| 58 | int ret; | ||
| 59 | }; | ||
| 60 | |||
| 61 | struct bio_get_port_test bio_get_port_tests[] = { | ||
| 62 | {NULL, 0, 0}, | ||
| 63 | {"", 0, 0}, | ||
| 64 | {"-1", 0, 0}, | ||
| 65 | {"0", 0, 1}, | ||
| 66 | {"1", 1, 1}, | ||
| 67 | {"12345", 12345, 1}, | ||
| 68 | {"65535", 65535, 1}, | ||
| 69 | {"65536", 0, 0}, | ||
| 70 | {"999999999999", 0, 0}, | ||
| 71 | {"xyzzy", 0, 0}, | ||
| 72 | {"https", 443, 1}, | ||
| 73 | {"imaps", 993, 1}, | ||
| 74 | {"telnet", 23, 1}, | ||
| 75 | }; | ||
| 76 | |||
| 77 | #define N_BIO_GET_PORT_TESTS \ | ||
| 78 | (sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests)) | ||
| 79 | |||
| 80 | static int | ||
| 81 | do_bio_get_host_ip_tests(void) | ||
| 82 | { | ||
| 83 | struct bio_get_host_ip_test *bgit; | ||
| 84 | union { | ||
| 85 | unsigned char c[4]; | ||
| 86 | uint32_t i; | ||
| 87 | } ip; | ||
| 88 | int failed = 0; | ||
| 89 | size_t i; | ||
| 90 | int ret; | ||
| 91 | |||
| 92 | for (i = 0; i < N_BIO_GET_IP_TESTS; i++) { | ||
| 93 | bgit = &bio_get_host_ip_tests[i]; | ||
| 94 | memset(&ip, 0, sizeof(ip)); | ||
| 95 | |||
| 96 | ret = BIO_get_host_ip(bgit->input, ip.c); | ||
| 97 | if (ret != bgit->ret) { | ||
| 98 | fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n", | ||
| 99 | i, bgit->input, ret ? "success" : "failure", | ||
| 100 | bgit->ret ? "success" : "failure"); | ||
| 101 | failed = 1; | ||
| 102 | continue; | ||
| 103 | } | ||
| 104 | if (ret && ntohl(ip.i) != bgit->ip) { | ||
| 105 | fprintf(stderr, "FAIL: test %zi (\"%s\") returned ip " | ||
| 106 | "%x != %x\n", i, bgit->input, | ||
| 107 | ntohl(ip.i), bgit->ip); | ||
| 108 | failed = 1; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | return failed; | ||
| 113 | } | ||
| 114 | |||
| 115 | static int | ||
| 116 | do_bio_get_port_tests(void) | ||
| 117 | { | ||
| 118 | struct bio_get_port_test *bgpt; | ||
| 119 | unsigned short port; | ||
| 120 | int failed = 0; | ||
| 121 | size_t i; | ||
| 122 | int ret; | ||
| 123 | |||
| 124 | for (i = 0; i < N_BIO_GET_PORT_TESTS; i++) { | ||
| 125 | bgpt = &bio_get_port_tests[i]; | ||
| 126 | port = 0; | ||
| 127 | |||
| 128 | ret = BIO_get_port(bgpt->input, &port); | ||
| 129 | if (ret != bgpt->ret) { | ||
| 130 | fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n", | ||
| 131 | i, bgpt->input, ret ? "success" : "failure", | ||
| 132 | bgpt->ret ? "success" : "failure"); | ||
| 133 | failed = 1; | ||
| 134 | continue; | ||
| 135 | } | ||
| 136 | if (ret && port != bgpt->port) { | ||
| 137 | fprintf(stderr, "FAIL: test %zi (\"%s\") returned port " | ||
| 138 | "%u != %u\n", i, bgpt->input, port, bgpt->port); | ||
| 139 | failed = 1; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | return failed; | ||
| 144 | } | ||
| 145 | |||
| 146 | int | ||
| 147 | main(int argc, char **argv) | ||
| 148 | { | ||
| 149 | int ret = 0; | ||
| 150 | |||
| 151 | ret |= do_bio_get_host_ip_tests(); | ||
| 152 | ret |= do_bio_get_port_tests(); | ||
| 153 | |||
| 154 | return (ret); | ||
| 155 | } | ||
diff --git a/src/regress/lib/libcrypto/bn/Makefile b/src/regress/lib/libcrypto/bn/Makefile deleted file mode 100644 index ed9298575b..0000000000 --- a/src/regress/lib/libcrypto/bn/Makefile +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2018/11/06 06:56:17 tb Exp $ | ||
| 2 | |||
| 3 | SUBDIR= \ | ||
| 4 | addsub \ | ||
| 5 | general \ | ||
| 6 | mont \ | ||
| 7 | rand | ||
| 8 | |||
| 9 | |||
| 10 | install: | ||
| 11 | |||
| 12 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libcrypto/bn/addsub/Makefile b/src/regress/lib/libcrypto/bn/addsub/Makefile deleted file mode 100644 index c35182db4f..0000000000 --- a/src/regress/lib/libcrypto/bn/addsub/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2018/07/10 16:57:50 tb Exp $ | ||
| 2 | |||
| 3 | .include "../../Makefile.inc" | ||
| 4 | |||
| 5 | PROG= bnaddsub | ||
| 6 | LDADD= ${CRYPTO_INT} | ||
| 7 | DPADD= ${LIBCRYPTO} | ||
| 8 | WARNINGS= Yes | ||
| 9 | CFLAGS+= -Werror | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/bn/addsub/bnaddsub.c b/src/regress/lib/libcrypto/bn/addsub/bnaddsub.c deleted file mode 100644 index e23821ed2b..0000000000 --- a/src/regress/lib/libcrypto/bn/addsub/bnaddsub.c +++ /dev/null | |||
| @@ -1,236 +0,0 @@ | |||
| 1 | /* $OpenBSD: bnaddsub.c,v 1.3 2018/07/23 17:15:21 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* Test basic functionality of BN_add(), BN_sub(), BN_uadd() and BN_usub() */ | ||
| 19 | |||
| 20 | #include <err.h> | ||
| 21 | #include <stdio.h> | ||
| 22 | |||
| 23 | #include <openssl/bio.h> | ||
| 24 | #include <openssl/bn.h> | ||
| 25 | #include <openssl/err.h> | ||
| 26 | |||
| 27 | #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) | ||
| 28 | |||
| 29 | BIO *bio_err; | ||
| 30 | |||
| 31 | struct hexinput_st { | ||
| 32 | const char *a_hex; | ||
| 33 | const char *b_hex; | ||
| 34 | const char *e_hex; /* expected result */ | ||
| 35 | const char ret; /* check return value */ | ||
| 36 | int compare; /* use BN_cmp() to verify results */ | ||
| 37 | }; | ||
| 38 | |||
| 39 | int bn_op_test(int (*)(BIGNUM *, const BIGNUM *, const BIGNUM *), | ||
| 40 | struct hexinput_st[], unsigned int, const char *); | ||
| 41 | void print_failure_case(BIGNUM *, BIGNUM *, BIGNUM *, BIGNUM *, int, | ||
| 42 | const char *); | ||
| 43 | |||
| 44 | struct hexinput_st test_bn_add[] = { | ||
| 45 | { | ||
| 46 | "F", | ||
| 47 | "F", | ||
| 48 | "1E", | ||
| 49 | 1, | ||
| 50 | 1, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | "FFFFFFFFFFFFFFFFFFF", | ||
| 54 | "1", | ||
| 55 | "10000000000000000000", | ||
| 56 | 1, | ||
| 57 | 1, | ||
| 58 | }, | ||
| 59 | { | ||
| 60 | "7878787878787878", | ||
| 61 | "1010101010101010", | ||
| 62 | "8888888888888888", | ||
| 63 | 1, | ||
| 64 | 1, | ||
| 65 | }, | ||
| 66 | { | ||
| 67 | "FFFFFFFFFFFFFFFF0000000000000000", | ||
| 68 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", | ||
| 69 | "1FFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", | ||
| 70 | 1, | ||
| 71 | 1, | ||
| 72 | }, | ||
| 73 | { | ||
| 74 | "F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0", | ||
| 75 | "10101010101010101010101010101010", | ||
| 76 | "101010101010101010101010101010100", | ||
| 77 | 1, | ||
| 78 | 1, | ||
| 79 | }, | ||
| 80 | }; | ||
| 81 | |||
| 82 | struct hexinput_st test_bn_sub[] = { | ||
| 83 | { | ||
| 84 | "10", | ||
| 85 | "1", | ||
| 86 | "F", | ||
| 87 | 1, | ||
| 88 | 1, | ||
| 89 | }, | ||
| 90 | { | ||
| 91 | "10", | ||
| 92 | "1", | ||
| 93 | "E", | ||
| 94 | 1, | ||
| 95 | 0, | ||
| 96 | }, | ||
| 97 | { | ||
| 98 | "100000000001000000000", | ||
| 99 | "11100000001", | ||
| 100 | "FFFFFFFFFEFEFFFFFFFF", | ||
| 101 | 1, | ||
| 102 | 1, | ||
| 103 | }, | ||
| 104 | { | ||
| 105 | "-FFFFFFFFFFFFFFFFFFFF", | ||
| 106 | "1", | ||
| 107 | "-100000000000000000000", | ||
| 108 | 1, | ||
| 109 | 1, | ||
| 110 | }, | ||
| 111 | }; | ||
| 112 | |||
| 113 | struct hexinput_st test_bn_usub[] = { | ||
| 114 | { | ||
| 115 | "10", | ||
| 116 | "1", | ||
| 117 | "F", | ||
| 118 | 1, | ||
| 119 | 1, | ||
| 120 | }, | ||
| 121 | { | ||
| 122 | "10", | ||
| 123 | "1", | ||
| 124 | "E", | ||
| 125 | 1, | ||
| 126 | 0, | ||
| 127 | }, | ||
| 128 | { | ||
| 129 | "100000000001000000000", | ||
| 130 | "11100000001", | ||
| 131 | "FFFFFFFFFEFEFFFFFFFF", | ||
| 132 | 1, | ||
| 133 | 1, | ||
| 134 | }, | ||
| 135 | { | ||
| 136 | "100000000000000000000", | ||
| 137 | "1", | ||
| 138 | "FFFFFFFFFFFFFFFFFFFF", | ||
| 139 | 1, | ||
| 140 | 1, | ||
| 141 | }, | ||
| 142 | { | ||
| 143 | "0", | ||
| 144 | "1", | ||
| 145 | "0", | ||
| 146 | 0, | ||
| 147 | 0, | ||
| 148 | }, | ||
| 149 | }; | ||
| 150 | |||
| 151 | void | ||
| 152 | print_failure_case(BIGNUM *a, BIGNUM *b, BIGNUM *e, BIGNUM *r, int i, | ||
| 153 | const char *testname) | ||
| 154 | { | ||
| 155 | BIO_printf(bio_err, "%s #%d failed:", testname, i); | ||
| 156 | BIO_printf(bio_err, "\na = "); | ||
| 157 | BN_print(bio_err, a); | ||
| 158 | BIO_printf(bio_err, "\nb = "); | ||
| 159 | BN_print(bio_err, b); | ||
| 160 | BIO_printf(bio_err, "\nexpected: e = "); | ||
| 161 | BN_print(bio_err, e); | ||
| 162 | BIO_printf(bio_err, "\nobtained: r = "); | ||
| 163 | BN_print(bio_err, r); | ||
| 164 | BIO_printf(bio_err, "\n"); | ||
| 165 | } | ||
| 166 | |||
| 167 | int | ||
| 168 | bn_op_test(int (*bn_op)(BIGNUM *, const BIGNUM *, const BIGNUM *), | ||
| 169 | struct hexinput_st tests[], unsigned int ntests, const char *testname) | ||
| 170 | { | ||
| 171 | BIGNUM *a = NULL, *b = NULL, *e = NULL, *r = NULL; | ||
| 172 | unsigned int i; | ||
| 173 | int failed = 0; | ||
| 174 | |||
| 175 | if (((a = BN_new()) == NULL) || | ||
| 176 | ((b = BN_new()) == NULL) || | ||
| 177 | ((e = BN_new()) == NULL) || | ||
| 178 | ((r = BN_new()) == NULL)) { | ||
| 179 | failed = 1; | ||
| 180 | ERR_print_errors(bio_err); | ||
| 181 | goto err; | ||
| 182 | } | ||
| 183 | |||
| 184 | for (i = 0; i < ntests; i++) { | ||
| 185 | int print = 0; | ||
| 186 | |||
| 187 | if (!BN_hex2bn(&a, tests[i].a_hex) || | ||
| 188 | !BN_hex2bn(&b, tests[i].b_hex) || | ||
| 189 | !BN_hex2bn(&e, tests[i].e_hex)) { | ||
| 190 | print = 1; | ||
| 191 | ERR_print_errors(bio_err); | ||
| 192 | } | ||
| 193 | |||
| 194 | if (tests[i].ret != bn_op(r, a, b)) | ||
| 195 | print = 1; | ||
| 196 | if (tests[i].compare == 1 && BN_cmp(e, r) != 0) | ||
| 197 | print = 1; | ||
| 198 | if (print) { | ||
| 199 | failed = 1; | ||
| 200 | print_failure_case(a, b, e, r, i, testname); | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | err: | ||
| 205 | BN_free(a); | ||
| 206 | BN_free(b); | ||
| 207 | BN_free(e); | ||
| 208 | BN_free(r); | ||
| 209 | return failed; | ||
| 210 | } | ||
| 211 | |||
| 212 | int | ||
| 213 | main(int argc, char *argv[]) | ||
| 214 | { | ||
| 215 | int failed = 0; | ||
| 216 | |||
| 217 | if ((bio_err = BIO_new_fp(stderr, BIO_NOCLOSE)) == NULL) { | ||
| 218 | fprintf(stderr, "bnaddsub: failed to initialize bio_err"); | ||
| 219 | return 1; | ||
| 220 | } | ||
| 221 | |||
| 222 | if (bn_op_test(BN_add, test_bn_add, nitems(test_bn_add), | ||
| 223 | "BN_add with test_bn_add[]")) | ||
| 224 | failed = 1; | ||
| 225 | if (bn_op_test(BN_uadd, test_bn_add, nitems(test_bn_add), | ||
| 226 | "BN_uadd with test_bn_add[]")) | ||
| 227 | failed = 1; | ||
| 228 | if (bn_op_test(BN_sub, test_bn_sub, nitems(test_bn_sub), | ||
| 229 | "BN_sub with test_bn_sub[]")) | ||
| 230 | failed = 1; | ||
| 231 | if (bn_op_test(BN_usub, test_bn_usub, nitems(test_bn_usub), | ||
| 232 | "BN_usub with test_bn_usub[]")) | ||
| 233 | failed = 1; | ||
| 234 | |||
| 235 | return failed; | ||
| 236 | } | ||
diff --git a/src/regress/lib/libcrypto/bn/general/Makefile b/src/regress/lib/libcrypto/bn/general/Makefile deleted file mode 100644 index d578d0fe12..0000000000 --- a/src/regress/lib/libcrypto/bn/general/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2017/01/21 09:38:58 beck Exp $ | ||
| 2 | |||
| 3 | .include "../../Makefile.inc" | ||
| 4 | |||
| 5 | PROG= bntest | ||
| 6 | LDADD= ${CRYPTO_INT} | ||
| 7 | DPADD= ${LIBCRYPTO} | ||
| 8 | WARNINGS= Yes | ||
| 9 | CFLAGS+= -Werror | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/bn/general/bntest.c b/src/regress/lib/libcrypto/bn/general/bntest.c deleted file mode 100644 index cff776068b..0000000000 --- a/src/regress/lib/libcrypto/bn/general/bntest.c +++ /dev/null | |||
| @@ -1,2467 +0,0 @@ | |||
| 1 | /* $OpenBSD: bntest.c,v 1.20 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * | ||
| 61 | * Portions of the attached software ("Contribution") are developed by | ||
| 62 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 63 | * | ||
| 64 | * The Contribution is licensed pursuant to the Eric Young open source | ||
| 65 | * license provided above. | ||
| 66 | * | ||
| 67 | * The binary polynomial arithmetic software is originally written by | ||
| 68 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. | ||
| 69 | * | ||
| 70 | */ | ||
| 71 | |||
| 72 | /* Until the key-gen callbacks are modified to use newer prototypes, we allow | ||
| 73 | * deprecated functions for openssl-internal code */ | ||
| 74 | #ifdef OPENSSL_NO_DEPRECATED | ||
| 75 | #undef OPENSSL_NO_DEPRECATED | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #include <stdio.h> | ||
| 79 | #include <stdlib.h> | ||
| 80 | #include <string.h> | ||
| 81 | |||
| 82 | #include <openssl/bio.h> | ||
| 83 | #include <openssl/bn.h> | ||
| 84 | #include <openssl/x509.h> | ||
| 85 | #include <openssl/err.h> | ||
| 86 | |||
| 87 | int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 88 | const BIGNUM *m, BN_CTX *ctx); | ||
| 89 | int BN_mod_exp_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 90 | const BIGNUM *m, BN_CTX *ctx); | ||
| 91 | int BN_mod_exp_mont_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 92 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 93 | int BN_mod_exp_mont_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 94 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 95 | |||
| 96 | int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom); | ||
| 97 | |||
| 98 | const int num0 = 100; /* number of tests */ | ||
| 99 | const int num1 = 50; /* additional tests for some functions */ | ||
| 100 | const int num2 = 5; /* number of tests for slow functions */ | ||
| 101 | |||
| 102 | int test_add(BIO *bp); | ||
| 103 | int test_sub(BIO *bp); | ||
| 104 | int test_lshift1(BIO *bp); | ||
| 105 | int test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_); | ||
| 106 | int test_rshift1(BIO *bp); | ||
| 107 | int test_rshift(BIO *bp, BN_CTX *ctx); | ||
| 108 | int test_div(BIO *bp, BN_CTX *ctx); | ||
| 109 | int test_div_word(BIO *bp); | ||
| 110 | int test_div_recp(BIO *bp, BN_CTX *ctx); | ||
| 111 | int test_mul(BIO *bp); | ||
| 112 | int test_sqr(BIO *bp, BN_CTX *ctx); | ||
| 113 | int test_mont(BIO *bp, BN_CTX *ctx); | ||
| 114 | int test_mod(BIO *bp, BN_CTX *ctx); | ||
| 115 | int test_mod_mul(BIO *bp, BN_CTX *ctx); | ||
| 116 | int test_mod_exp(BIO *bp, BN_CTX *ctx); | ||
| 117 | int test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx); | ||
| 118 | int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx); | ||
| 119 | int test_mod_exp_sizes(BIO *bp, BN_CTX *ctx); | ||
| 120 | int test_exp(BIO *bp, BN_CTX *ctx); | ||
| 121 | int test_gf2m_add(BIO *bp); | ||
| 122 | int test_gf2m_mod(BIO *bp); | ||
| 123 | int test_gf2m_mod_mul(BIO *bp, BN_CTX *ctx); | ||
| 124 | int test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx); | ||
| 125 | int test_gf2m_mod_inv(BIO *bp, BN_CTX *ctx); | ||
| 126 | int test_gf2m_mod_div(BIO *bp, BN_CTX *ctx); | ||
| 127 | int test_gf2m_mod_exp(BIO *bp, BN_CTX *ctx); | ||
| 128 | int test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx); | ||
| 129 | int test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx); | ||
| 130 | int test_kron(BIO *bp, BN_CTX *ctx); | ||
| 131 | int test_sqrt(BIO *bp, BN_CTX *ctx); | ||
| 132 | int rand_neg(void); | ||
| 133 | static int results = 0; | ||
| 134 | |||
| 135 | static unsigned char lst[] = | ||
| 136 | "\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" | ||
| 137 | "\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; | ||
| 138 | |||
| 139 | #define PRINT_ERROR printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
| 140 | __LINE__) | ||
| 141 | |||
| 142 | #define CHECK_GOTO(a) do { \ | ||
| 143 | if (!(a)) { \ | ||
| 144 | PRINT_ERROR; \ | ||
| 145 | rc = 0; \ | ||
| 146 | goto err; \ | ||
| 147 | } \ | ||
| 148 | } while (0) | ||
| 149 | |||
| 150 | static void | ||
| 151 | message(BIO *out, char *m) | ||
| 152 | { | ||
| 153 | fprintf(stderr, "test %s\n", m); | ||
| 154 | BIO_puts(out, "print \"test "); | ||
| 155 | BIO_puts(out, m); | ||
| 156 | BIO_puts(out, "\\n\"\n"); | ||
| 157 | } | ||
| 158 | |||
| 159 | int | ||
| 160 | main(int argc, char *argv[]) | ||
| 161 | { | ||
| 162 | BN_CTX *ctx; | ||
| 163 | BIO *out; | ||
| 164 | char *outfile = NULL; | ||
| 165 | |||
| 166 | results = 0; | ||
| 167 | |||
| 168 | argc--; | ||
| 169 | argv++; | ||
| 170 | while (argc >= 1) { | ||
| 171 | if (strcmp(*argv, "-results") == 0) | ||
| 172 | results = 1; | ||
| 173 | else if (strcmp(*argv, "-out") == 0) { | ||
| 174 | if (--argc < 1) | ||
| 175 | break; | ||
| 176 | outfile= *(++argv); | ||
| 177 | } | ||
| 178 | argc--; | ||
| 179 | argv++; | ||
| 180 | } | ||
| 181 | |||
| 182 | |||
| 183 | ctx = BN_CTX_new(); | ||
| 184 | if (ctx == NULL) | ||
| 185 | exit(1); | ||
| 186 | |||
| 187 | out = BIO_new(BIO_s_file()); | ||
| 188 | if (out == NULL) | ||
| 189 | exit(1); | ||
| 190 | if (outfile == NULL) { | ||
| 191 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | ||
| 192 | } else { | ||
| 193 | if (!BIO_write_filename(out, outfile)) { | ||
| 194 | perror(outfile); | ||
| 195 | exit(1); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | if (!results) | ||
| 200 | BIO_puts(out, "obase=16\nibase=16\n"); | ||
| 201 | |||
| 202 | message(out, "BN_add"); | ||
| 203 | if (!test_add(out)) | ||
| 204 | goto err; | ||
| 205 | (void)BIO_flush(out); | ||
| 206 | |||
| 207 | message(out, "BN_sub"); | ||
| 208 | if (!test_sub(out)) | ||
| 209 | goto err; | ||
| 210 | (void)BIO_flush(out); | ||
| 211 | |||
| 212 | message(out, "BN_lshift1"); | ||
| 213 | if (!test_lshift1(out)) | ||
| 214 | goto err; | ||
| 215 | (void)BIO_flush(out); | ||
| 216 | |||
| 217 | message(out, "BN_lshift (fixed)"); | ||
| 218 | if (!test_lshift(out, ctx, BN_bin2bn(lst, sizeof(lst) - 1, NULL))) | ||
| 219 | goto err; | ||
| 220 | (void)BIO_flush(out); | ||
| 221 | |||
| 222 | message(out, "BN_lshift"); | ||
| 223 | if (!test_lshift(out, ctx, NULL)) | ||
| 224 | goto err; | ||
| 225 | (void)BIO_flush(out); | ||
| 226 | |||
| 227 | message(out, "BN_rshift1"); | ||
| 228 | if (!test_rshift1(out)) | ||
| 229 | goto err; | ||
| 230 | (void)BIO_flush(out); | ||
| 231 | |||
| 232 | message(out, "BN_rshift"); | ||
| 233 | if (!test_rshift(out, ctx)) | ||
| 234 | goto err; | ||
| 235 | (void)BIO_flush(out); | ||
| 236 | |||
| 237 | message(out, "BN_sqr"); | ||
| 238 | if (!test_sqr(out, ctx)) | ||
| 239 | goto err; | ||
| 240 | (void)BIO_flush(out); | ||
| 241 | |||
| 242 | message(out, "BN_mul"); | ||
| 243 | if (!test_mul(out)) | ||
| 244 | goto err; | ||
| 245 | (void)BIO_flush(out); | ||
| 246 | |||
| 247 | message(out, "BN_div"); | ||
| 248 | if (!test_div(out, ctx)) | ||
| 249 | goto err; | ||
| 250 | (void)BIO_flush(out); | ||
| 251 | |||
| 252 | message(out, "BN_div_word"); | ||
| 253 | if (!test_div_word(out)) | ||
| 254 | goto err; | ||
| 255 | (void)BIO_flush(out); | ||
| 256 | |||
| 257 | message(out, "BN_div_recp"); | ||
| 258 | if (!test_div_recp(out, ctx)) | ||
| 259 | goto err; | ||
| 260 | (void)BIO_flush(out); | ||
| 261 | |||
| 262 | message(out, "BN_mod"); | ||
| 263 | if (!test_mod(out, ctx)) | ||
| 264 | goto err; | ||
| 265 | (void)BIO_flush(out); | ||
| 266 | |||
| 267 | message(out, "BN_mod_mul"); | ||
| 268 | if (!test_mod_mul(out, ctx)) | ||
| 269 | goto err; | ||
| 270 | (void)BIO_flush(out); | ||
| 271 | |||
| 272 | message(out, "BN_mont"); | ||
| 273 | if (!test_mont(out, ctx)) | ||
| 274 | goto err; | ||
| 275 | (void)BIO_flush(out); | ||
| 276 | |||
| 277 | message(out, "BN_mod_exp"); | ||
| 278 | if (!test_mod_exp(out, ctx)) | ||
| 279 | goto err; | ||
| 280 | (void)BIO_flush(out); | ||
| 281 | |||
| 282 | message(out, "BN_mod_exp_mont_consttime"); | ||
| 283 | if (!test_mod_exp_mont_consttime(out, ctx)) | ||
| 284 | goto err; | ||
| 285 | (void)BIO_flush(out); | ||
| 286 | |||
| 287 | message(out, "BN_mod_exp_mont5"); | ||
| 288 | if (!test_mod_exp_mont5(out, ctx)) | ||
| 289 | goto err; | ||
| 290 | (void)BIO_flush(out); | ||
| 291 | |||
| 292 | message(out, "BN_exp"); | ||
| 293 | if (!test_exp(out, ctx)) | ||
| 294 | goto err; | ||
| 295 | (void)BIO_flush(out); | ||
| 296 | |||
| 297 | message(out, "BN_kronecker"); | ||
| 298 | if (!test_kron(out, ctx)) | ||
| 299 | goto err; | ||
| 300 | (void)BIO_flush(out); | ||
| 301 | |||
| 302 | message(out, "BN_mod_sqrt"); | ||
| 303 | if (!test_sqrt(out, ctx)) | ||
| 304 | goto err; | ||
| 305 | (void)BIO_flush(out); | ||
| 306 | |||
| 307 | message(out, "Modexp with different sizes"); | ||
| 308 | if (!test_mod_exp_sizes(out, ctx)) | ||
| 309 | goto err; | ||
| 310 | (void)BIO_flush(out); | ||
| 311 | |||
| 312 | #ifndef OPENSSL_NO_EC2M | ||
| 313 | message(out, "BN_GF2m_add"); | ||
| 314 | if (!test_gf2m_add(out)) | ||
| 315 | goto err; | ||
| 316 | (void)BIO_flush(out); | ||
| 317 | |||
| 318 | message(out, "BN_GF2m_mod"); | ||
| 319 | if (!test_gf2m_mod(out)) | ||
| 320 | goto err; | ||
| 321 | (void)BIO_flush(out); | ||
| 322 | |||
| 323 | message(out, "BN_GF2m_mod_mul"); | ||
| 324 | if (!test_gf2m_mod_mul(out, ctx)) | ||
| 325 | goto err; | ||
| 326 | (void)BIO_flush(out); | ||
| 327 | |||
| 328 | message(out, "BN_GF2m_mod_sqr"); | ||
| 329 | if (!test_gf2m_mod_sqr(out, ctx)) | ||
| 330 | goto err; | ||
| 331 | (void)BIO_flush(out); | ||
| 332 | |||
| 333 | message(out, "BN_GF2m_mod_inv"); | ||
| 334 | if (!test_gf2m_mod_inv(out, ctx)) | ||
| 335 | goto err; | ||
| 336 | (void)BIO_flush(out); | ||
| 337 | |||
| 338 | message(out, "BN_GF2m_mod_div"); | ||
| 339 | if (!test_gf2m_mod_div(out, ctx)) | ||
| 340 | goto err; | ||
| 341 | (void)BIO_flush(out); | ||
| 342 | |||
| 343 | message(out, "BN_GF2m_mod_exp"); | ||
| 344 | if (!test_gf2m_mod_exp(out, ctx)) | ||
| 345 | goto err; | ||
| 346 | (void)BIO_flush(out); | ||
| 347 | |||
| 348 | message(out, "BN_GF2m_mod_sqrt"); | ||
| 349 | if (!test_gf2m_mod_sqrt(out, ctx)) | ||
| 350 | goto err; | ||
| 351 | (void)BIO_flush(out); | ||
| 352 | |||
| 353 | message(out, "BN_GF2m_mod_solve_quad"); | ||
| 354 | if (!test_gf2m_mod_solve_quad(out, ctx)) | ||
| 355 | goto err; | ||
| 356 | (void)BIO_flush(out); | ||
| 357 | #endif | ||
| 358 | BN_CTX_free(ctx); | ||
| 359 | BIO_free(out); | ||
| 360 | |||
| 361 | exit(0); | ||
| 362 | err: | ||
| 363 | BIO_puts(out, "1\n"); /* make sure the Perl script fed by bc notices | ||
| 364 | * the failure, see test_bn in test/Makefile.ssl*/ | ||
| 365 | |||
| 366 | (void)BIO_flush(out); | ||
| 367 | ERR_load_crypto_strings(); | ||
| 368 | ERR_print_errors_fp(stderr); | ||
| 369 | exit(1); | ||
| 370 | } | ||
| 371 | |||
| 372 | int | ||
| 373 | test_add(BIO *bp) | ||
| 374 | { | ||
| 375 | BIGNUM a, b, c; | ||
| 376 | int i; | ||
| 377 | int rc = 1; | ||
| 378 | |||
| 379 | BN_init(&a); | ||
| 380 | BN_init(&b); | ||
| 381 | BN_init(&c); | ||
| 382 | |||
| 383 | CHECK_GOTO(BN_bntest_rand(&a, 512, 0, 0)); | ||
| 384 | for (i = 0; i < num0; i++) { | ||
| 385 | CHECK_GOTO(BN_bntest_rand(&b, 450 + i, 0, 0)); | ||
| 386 | a.neg = rand_neg(); | ||
| 387 | b.neg = rand_neg(); | ||
| 388 | CHECK_GOTO(BN_add(&c, &a, &b)); | ||
| 389 | if (bp != NULL) { | ||
| 390 | if (!results) { | ||
| 391 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 392 | BIO_puts(bp, " + "); | ||
| 393 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 394 | BIO_puts(bp, " - "); | ||
| 395 | } | ||
| 396 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 397 | BIO_puts(bp, "\n"); | ||
| 398 | } | ||
| 399 | a.neg = !a.neg; | ||
| 400 | b.neg = !b.neg; | ||
| 401 | CHECK_GOTO(BN_add(&c, &c, &b)); | ||
| 402 | CHECK_GOTO(BN_add(&c, &c, &a)); | ||
| 403 | if (!BN_is_zero(&c)) { | ||
| 404 | fprintf(stderr, "Add test failed!\n"); | ||
| 405 | rc = 0; | ||
| 406 | break; | ||
| 407 | } | ||
| 408 | } | ||
| 409 | err: | ||
| 410 | BN_free(&a); | ||
| 411 | BN_free(&b); | ||
| 412 | BN_free(&c); | ||
| 413 | return (rc); | ||
| 414 | } | ||
| 415 | |||
| 416 | int | ||
| 417 | test_sub(BIO *bp) | ||
| 418 | { | ||
| 419 | BIGNUM a, b, c; | ||
| 420 | int i; | ||
| 421 | int rc = 1; | ||
| 422 | |||
| 423 | BN_init(&a); | ||
| 424 | BN_init(&b); | ||
| 425 | BN_init(&c); | ||
| 426 | |||
| 427 | for (i = 0; i < num0 + num1; i++) { | ||
| 428 | if (i < num1) { | ||
| 429 | CHECK_GOTO(BN_bntest_rand(&a, 512, 0, 0)); | ||
| 430 | CHECK_GOTO(BN_copy(&b, &a)); | ||
| 431 | if (BN_set_bit(&a, i) == 0) { | ||
| 432 | rc = 0; | ||
| 433 | break; | ||
| 434 | } | ||
| 435 | CHECK_GOTO(BN_add_word(&b, i)); | ||
| 436 | } else { | ||
| 437 | CHECK_GOTO(BN_bntest_rand(&b, 400 + i - num1, 0, 0)); | ||
| 438 | a.neg = rand_neg(); | ||
| 439 | b.neg = rand_neg(); | ||
| 440 | } | ||
| 441 | CHECK_GOTO(BN_sub(&c, &a, &b)); | ||
| 442 | if (bp != NULL) { | ||
| 443 | if (!results) { | ||
| 444 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 445 | BIO_puts(bp, " - "); | ||
| 446 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 447 | BIO_puts(bp, " - "); | ||
| 448 | } | ||
| 449 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 450 | BIO_puts(bp, "\n"); | ||
| 451 | } | ||
| 452 | CHECK_GOTO(BN_add(&c, &c, &b)); | ||
| 453 | CHECK_GOTO(BN_sub(&c, &c, &a)); | ||
| 454 | if (!BN_is_zero(&c)) { | ||
| 455 | fprintf(stderr, "Subtract test failed!\n"); | ||
| 456 | rc = 0; | ||
| 457 | break; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | err: | ||
| 461 | BN_free(&a); | ||
| 462 | BN_free(&b); | ||
| 463 | BN_free(&c); | ||
| 464 | return (rc); | ||
| 465 | } | ||
| 466 | |||
| 467 | int | ||
| 468 | test_div(BIO *bp, BN_CTX *ctx) | ||
| 469 | { | ||
| 470 | BIGNUM a, b, c, d, e; | ||
| 471 | int i; | ||
| 472 | int rc = 1; | ||
| 473 | |||
| 474 | BN_init(&a); | ||
| 475 | BN_init(&b); | ||
| 476 | BN_init(&c); | ||
| 477 | BN_init(&d); | ||
| 478 | BN_init(&e); | ||
| 479 | |||
| 480 | CHECK_GOTO(BN_one(&a)); | ||
| 481 | CHECK_GOTO(BN_zero(&b)); | ||
| 482 | |||
| 483 | if (BN_div(&d, &c, &a, &b, ctx)) { | ||
| 484 | fprintf(stderr, "Division by zero succeeded!\n"); | ||
| 485 | return (0); | ||
| 486 | } | ||
| 487 | |||
| 488 | for (i = 0; i < num0 + num1; i++) { | ||
| 489 | if (i < num1) { | ||
| 490 | CHECK_GOTO(BN_bntest_rand(&a, 400, 0, 0)); | ||
| 491 | CHECK_GOTO(BN_copy(&b, &a)); | ||
| 492 | CHECK_GOTO(BN_lshift(&a, &a, i)); | ||
| 493 | CHECK_GOTO(BN_add_word(&a, i)); | ||
| 494 | } else | ||
| 495 | CHECK_GOTO(BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0)); | ||
| 496 | a.neg = rand_neg(); | ||
| 497 | b.neg = rand_neg(); | ||
| 498 | CHECK_GOTO(BN_div(&d, &c, &a, &b, ctx)); | ||
| 499 | if (bp != NULL) { | ||
| 500 | if (!results) { | ||
| 501 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 502 | BIO_puts(bp, " / "); | ||
| 503 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 504 | BIO_puts(bp, " - "); | ||
| 505 | } | ||
| 506 | CHECK_GOTO(BN_print(bp, &d)); | ||
| 507 | BIO_puts(bp, "\n"); | ||
| 508 | |||
| 509 | if (!results) { | ||
| 510 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 511 | BIO_puts(bp, " % "); | ||
| 512 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 513 | BIO_puts(bp, " - "); | ||
| 514 | } | ||
| 515 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 516 | BIO_puts(bp, "\n"); | ||
| 517 | } | ||
| 518 | CHECK_GOTO(BN_mul(&e, &d, &b, ctx)); | ||
| 519 | CHECK_GOTO(BN_add(&d, &e, &c)); | ||
| 520 | CHECK_GOTO(BN_sub(&d, &d, &a)); | ||
| 521 | if (!BN_is_zero(&d)) { | ||
| 522 | fprintf(stderr, "Division test failed!\n"); | ||
| 523 | rc = 0; | ||
| 524 | break; | ||
| 525 | } | ||
| 526 | } | ||
| 527 | err: | ||
| 528 | BN_free(&a); | ||
| 529 | BN_free(&b); | ||
| 530 | BN_free(&c); | ||
| 531 | BN_free(&d); | ||
| 532 | BN_free(&e); | ||
| 533 | return (rc); | ||
| 534 | } | ||
| 535 | |||
| 536 | static void | ||
| 537 | print_word(BIO *bp, BN_ULONG w) | ||
| 538 | { | ||
| 539 | #ifdef SIXTY_FOUR_BIT | ||
| 540 | if (sizeof(w) > sizeof(unsigned long)) { | ||
| 541 | unsigned long h = (unsigned long)(w >> 32), l = (unsigned long)(w); | ||
| 542 | |||
| 543 | if (h) | ||
| 544 | BIO_printf(bp, "%lX%08lX", h, l); | ||
| 545 | else | ||
| 546 | BIO_printf(bp, "%lX", l); | ||
| 547 | return; | ||
| 548 | } | ||
| 549 | #endif | ||
| 550 | BIO_printf(bp, BN_HEX_FMT1, w); | ||
| 551 | } | ||
| 552 | |||
| 553 | int | ||
| 554 | test_div_word(BIO *bp) | ||
| 555 | { | ||
| 556 | BIGNUM a, b; | ||
| 557 | BN_ULONG r, rmod, s = 0; | ||
| 558 | int i; | ||
| 559 | int rc = 1; | ||
| 560 | |||
| 561 | BN_init(&a); | ||
| 562 | BN_init(&b); | ||
| 563 | |||
| 564 | for (i = 0; i < num0; i++) { | ||
| 565 | do { | ||
| 566 | if (!BN_bntest_rand(&a, 512, -1, 0) || | ||
| 567 | !BN_bntest_rand(&b, BN_BITS2, -1, 0)) { | ||
| 568 | rc = 0; | ||
| 569 | break; | ||
| 570 | } | ||
| 571 | s = b.d[0]; | ||
| 572 | } while (!s); | ||
| 573 | |||
| 574 | if (!BN_copy(&b, &a)) { | ||
| 575 | rc = 0; | ||
| 576 | break; | ||
| 577 | } | ||
| 578 | |||
| 579 | rmod = BN_mod_word(&b, s); | ||
| 580 | r = BN_div_word(&b, s); | ||
| 581 | |||
| 582 | if (r == (BN_ULONG)-1 || rmod == (BN_ULONG)-1) { | ||
| 583 | rc = 0; | ||
| 584 | break; | ||
| 585 | } | ||
| 586 | |||
| 587 | if (rmod != r) { | ||
| 588 | fprintf(stderr, "Mod (word) test failed!\n"); | ||
| 589 | rc = 0; | ||
| 590 | break; | ||
| 591 | } | ||
| 592 | |||
| 593 | if (bp != NULL) { | ||
| 594 | if (!results) { | ||
| 595 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 596 | BIO_puts(bp, " / "); | ||
| 597 | print_word(bp, s); | ||
| 598 | BIO_puts(bp, " - "); | ||
| 599 | } | ||
| 600 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 601 | BIO_puts(bp, "\n"); | ||
| 602 | |||
| 603 | if (!results) { | ||
| 604 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 605 | BIO_puts(bp, " % "); | ||
| 606 | print_word(bp, s); | ||
| 607 | BIO_puts(bp, " - "); | ||
| 608 | } | ||
| 609 | print_word(bp, r); | ||
| 610 | BIO_puts(bp, "\n"); | ||
| 611 | } | ||
| 612 | CHECK_GOTO(BN_mul_word(&b, s)); | ||
| 613 | CHECK_GOTO(BN_add_word(&b, r)); | ||
| 614 | CHECK_GOTO(BN_sub(&b, &a, &b)); | ||
| 615 | if (!BN_is_zero(&b)) { | ||
| 616 | fprintf(stderr, "Division (word) test failed!\n"); | ||
| 617 | rc = 0; | ||
| 618 | break; | ||
| 619 | } | ||
| 620 | } | ||
| 621 | err: | ||
| 622 | BN_free(&a); | ||
| 623 | BN_free(&b); | ||
| 624 | return (rc); | ||
| 625 | } | ||
| 626 | |||
| 627 | int | ||
| 628 | test_div_recp(BIO *bp, BN_CTX *ctx) | ||
| 629 | { | ||
| 630 | BIGNUM a, b, c, d, e; | ||
| 631 | BN_RECP_CTX recp; | ||
| 632 | int i; | ||
| 633 | int rc = 1; | ||
| 634 | |||
| 635 | BN_RECP_CTX_init(&recp); | ||
| 636 | BN_init(&a); | ||
| 637 | BN_init(&b); | ||
| 638 | BN_init(&c); | ||
| 639 | BN_init(&d); | ||
| 640 | BN_init(&e); | ||
| 641 | |||
| 642 | for (i = 0; i < num0 + num1; i++) { | ||
| 643 | if (i < num1) { | ||
| 644 | CHECK_GOTO(BN_bntest_rand(&a, 400, 0, 0)); | ||
| 645 | CHECK_GOTO(BN_copy(&b, &a)); | ||
| 646 | CHECK_GOTO(BN_lshift(&a, &a, i)); | ||
| 647 | CHECK_GOTO(BN_add_word(&a, i)); | ||
| 648 | } else | ||
| 649 | CHECK_GOTO(BN_bntest_rand(&b, 50 + 3 * (i - num1), 0, 0)); | ||
| 650 | a.neg = rand_neg(); | ||
| 651 | b.neg = rand_neg(); | ||
| 652 | CHECK_GOTO(BN_RECP_CTX_set(&recp, &b, ctx)); | ||
| 653 | CHECK_GOTO(BN_div_recp(&d, &c, &a, &recp, ctx)); | ||
| 654 | if (bp != NULL) { | ||
| 655 | if (!results) { | ||
| 656 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 657 | BIO_puts(bp, " / "); | ||
| 658 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 659 | BIO_puts(bp, " - "); | ||
| 660 | } | ||
| 661 | CHECK_GOTO(BN_print(bp, &d)); | ||
| 662 | BIO_puts(bp, "\n"); | ||
| 663 | |||
| 664 | if (!results) { | ||
| 665 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 666 | BIO_puts(bp, " % "); | ||
| 667 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 668 | BIO_puts(bp, " - "); | ||
| 669 | } | ||
| 670 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 671 | BIO_puts(bp, "\n"); | ||
| 672 | } | ||
| 673 | CHECK_GOTO(BN_mul(&e, &d, &b, ctx)); | ||
| 674 | CHECK_GOTO(BN_add(&d, &e, &c)); | ||
| 675 | CHECK_GOTO(BN_sub(&d, &d, &a)); | ||
| 676 | if (!BN_is_zero(&d)) { | ||
| 677 | fprintf(stderr, "Reciprocal division test failed!\n"); | ||
| 678 | fprintf(stderr, "a="); | ||
| 679 | CHECK_GOTO(BN_print_fp(stderr, &a)); | ||
| 680 | fprintf(stderr, "\nb="); | ||
| 681 | CHECK_GOTO(BN_print_fp(stderr, &b)); | ||
| 682 | fprintf(stderr, "\n"); | ||
| 683 | rc = 0; | ||
| 684 | break; | ||
| 685 | } | ||
| 686 | } | ||
| 687 | err: | ||
| 688 | BN_free(&a); | ||
| 689 | BN_free(&b); | ||
| 690 | BN_free(&c); | ||
| 691 | BN_free(&d); | ||
| 692 | BN_free(&e); | ||
| 693 | BN_RECP_CTX_free(&recp); | ||
| 694 | return (rc); | ||
| 695 | } | ||
| 696 | |||
| 697 | int | ||
| 698 | test_mul(BIO *bp) | ||
| 699 | { | ||
| 700 | BIGNUM a, b, c, d, e; | ||
| 701 | int i; | ||
| 702 | int rc = 1; | ||
| 703 | BN_CTX *ctx; | ||
| 704 | |||
| 705 | ctx = BN_CTX_new(); | ||
| 706 | if (ctx == NULL) | ||
| 707 | exit(1); | ||
| 708 | |||
| 709 | BN_init(&a); | ||
| 710 | BN_init(&b); | ||
| 711 | BN_init(&c); | ||
| 712 | BN_init(&d); | ||
| 713 | BN_init(&e); | ||
| 714 | |||
| 715 | for (i = 0; i < num0 + num1; i++) { | ||
| 716 | if (i <= num1) { | ||
| 717 | CHECK_GOTO(BN_bntest_rand(&a, 100, 0, 0)); | ||
| 718 | CHECK_GOTO(BN_bntest_rand(&b, 100, 0, 0)); | ||
| 719 | } else | ||
| 720 | CHECK_GOTO(BN_bntest_rand(&b, i - num1, 0, 0)); | ||
| 721 | a.neg = rand_neg(); | ||
| 722 | b.neg = rand_neg(); | ||
| 723 | CHECK_GOTO(BN_mul(&c, &a, &b, ctx)); | ||
| 724 | if (bp != NULL) { | ||
| 725 | if (!results) { | ||
| 726 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 727 | BIO_puts(bp, " * "); | ||
| 728 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 729 | BIO_puts(bp, " - "); | ||
| 730 | } | ||
| 731 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 732 | BIO_puts(bp, "\n"); | ||
| 733 | } | ||
| 734 | CHECK_GOTO(BN_div(&d, &e, &c, &a, ctx)); | ||
| 735 | CHECK_GOTO(BN_sub(&d, &d, &b)); | ||
| 736 | if (!BN_is_zero(&d) || !BN_is_zero(&e)) { | ||
| 737 | fprintf(stderr, "Multiplication test failed!\n"); | ||
| 738 | rc = 0; | ||
| 739 | break; | ||
| 740 | } | ||
| 741 | } | ||
| 742 | err: | ||
| 743 | BN_free(&a); | ||
| 744 | BN_free(&b); | ||
| 745 | BN_free(&c); | ||
| 746 | BN_free(&d); | ||
| 747 | BN_free(&e); | ||
| 748 | BN_CTX_free(ctx); | ||
| 749 | return (rc); | ||
| 750 | } | ||
| 751 | |||
| 752 | int | ||
| 753 | test_sqr(BIO *bp, BN_CTX *ctx) | ||
| 754 | { | ||
| 755 | BIGNUM *a, *c, *d, *e; | ||
| 756 | int i, rc = 0; | ||
| 757 | |||
| 758 | a = BN_new(); | ||
| 759 | c = BN_new(); | ||
| 760 | d = BN_new(); | ||
| 761 | e = BN_new(); | ||
| 762 | |||
| 763 | for (i = 0; i < num0; i++) { | ||
| 764 | CHECK_GOTO(BN_bntest_rand(a, 40 + i * 10, 0, 0)); | ||
| 765 | a->neg = rand_neg(); | ||
| 766 | CHECK_GOTO(BN_sqr(c, a, ctx)); | ||
| 767 | if (bp != NULL) { | ||
| 768 | if (!results) { | ||
| 769 | CHECK_GOTO(BN_print(bp, a)); | ||
| 770 | BIO_puts(bp, " * "); | ||
| 771 | CHECK_GOTO(BN_print(bp, a)); | ||
| 772 | BIO_puts(bp, " - "); | ||
| 773 | } | ||
| 774 | CHECK_GOTO(BN_print(bp, c)); | ||
| 775 | BIO_puts(bp, "\n"); | ||
| 776 | } | ||
| 777 | CHECK_GOTO(BN_div(d, e, c, a, ctx)); | ||
| 778 | CHECK_GOTO(BN_sub(d, d, a)); | ||
| 779 | if (!BN_is_zero(d) || !BN_is_zero(e)) { | ||
| 780 | fprintf(stderr, "Square test failed!\n"); | ||
| 781 | goto err; | ||
| 782 | } | ||
| 783 | } | ||
| 784 | |||
| 785 | /* Regression test for a BN_sqr overflow bug. */ | ||
| 786 | if (!BN_hex2bn(&a, "80000000000000008000000000000001" | ||
| 787 | "FFFFFFFFFFFFFFFE0000000000000000")) { | ||
| 788 | fprintf(stderr, "BN_hex2bn failed\n"); | ||
| 789 | goto err; | ||
| 790 | } | ||
| 791 | CHECK_GOTO(BN_sqr(c, a, ctx)); | ||
| 792 | if (bp != NULL) { | ||
| 793 | if (!results) { | ||
| 794 | CHECK_GOTO(BN_print(bp, a)); | ||
| 795 | BIO_puts(bp, " * "); | ||
| 796 | CHECK_GOTO(BN_print(bp, a)); | ||
| 797 | BIO_puts(bp, " - "); | ||
| 798 | } | ||
| 799 | CHECK_GOTO(BN_print(bp, c)); | ||
| 800 | BIO_puts(bp, "\n"); | ||
| 801 | } | ||
| 802 | CHECK_GOTO(BN_mul(d, a, a, ctx)); | ||
| 803 | if (BN_cmp(c, d)) { | ||
| 804 | fprintf(stderr, | ||
| 805 | "Square test failed: BN_sqr and BN_mul produce " | ||
| 806 | "different results!\n"); | ||
| 807 | goto err; | ||
| 808 | } | ||
| 809 | |||
| 810 | /* Regression test for a BN_sqr overflow bug. */ | ||
| 811 | if (!BN_hex2bn(&a, "80000000000000000000000080000001" | ||
| 812 | "FFFFFFFE000000000000000000000000")) { | ||
| 813 | fprintf(stderr, "BN_hex2bn failed\n"); | ||
| 814 | goto err; | ||
| 815 | } | ||
| 816 | CHECK_GOTO(BN_sqr(c, a, ctx)); | ||
| 817 | if (bp != NULL) { | ||
| 818 | if (!results) { | ||
| 819 | CHECK_GOTO(BN_print(bp, a)); | ||
| 820 | BIO_puts(bp, " * "); | ||
| 821 | CHECK_GOTO(BN_print(bp, a)); | ||
| 822 | BIO_puts(bp, " - "); | ||
| 823 | } | ||
| 824 | CHECK_GOTO(BN_print(bp, c)); | ||
| 825 | BIO_puts(bp, "\n"); | ||
| 826 | } | ||
| 827 | CHECK_GOTO(BN_mul(d, a, a, ctx)); | ||
| 828 | if (BN_cmp(c, d)) { | ||
| 829 | fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce " | ||
| 830 | "different results!\n"); | ||
| 831 | goto err; | ||
| 832 | } | ||
| 833 | rc = 1; | ||
| 834 | err: | ||
| 835 | BN_free(a); | ||
| 836 | BN_free(c); | ||
| 837 | BN_free(d); | ||
| 838 | BN_free(e); | ||
| 839 | return rc; | ||
| 840 | } | ||
| 841 | |||
| 842 | int | ||
| 843 | test_mont(BIO *bp, BN_CTX *ctx) | ||
| 844 | { | ||
| 845 | BIGNUM a, b, c, d, A, B; | ||
| 846 | BIGNUM n; | ||
| 847 | int i; | ||
| 848 | int rc = 1; | ||
| 849 | BN_MONT_CTX *mont; | ||
| 850 | |||
| 851 | mont = BN_MONT_CTX_new(); | ||
| 852 | if (mont == NULL) | ||
| 853 | return 0; | ||
| 854 | |||
| 855 | BN_init(&a); | ||
| 856 | BN_init(&b); | ||
| 857 | BN_init(&c); | ||
| 858 | BN_init(&d); | ||
| 859 | BN_init(&A); | ||
| 860 | BN_init(&B); | ||
| 861 | BN_init(&n); | ||
| 862 | |||
| 863 | CHECK_GOTO(BN_zero(&n)); | ||
| 864 | if (BN_MONT_CTX_set(mont, &n, ctx)) { | ||
| 865 | fprintf(stderr, "BN_MONT_CTX_set succeeded for zero modulus!\n"); | ||
| 866 | return (0); | ||
| 867 | } | ||
| 868 | |||
| 869 | CHECK_GOTO(BN_set_word(&n, 16)); | ||
| 870 | if (BN_MONT_CTX_set(mont, &n, ctx)) { | ||
| 871 | fprintf(stderr, "BN_MONT_CTX_set succeeded for even modulus!\n"); | ||
| 872 | return (0); | ||
| 873 | } | ||
| 874 | |||
| 875 | CHECK_GOTO(BN_bntest_rand(&a, 100, 0, 0)); | ||
| 876 | CHECK_GOTO(BN_bntest_rand(&b, 100, 0, 0)); | ||
| 877 | for (i = 0; i < num2; i++) { | ||
| 878 | int bits = (200 * (i + 1)) / num2; | ||
| 879 | |||
| 880 | if (bits == 0) | ||
| 881 | continue; | ||
| 882 | CHECK_GOTO(BN_bntest_rand(&n, bits, 0, 1)); | ||
| 883 | CHECK_GOTO(BN_MONT_CTX_set(mont, &n, ctx)); | ||
| 884 | |||
| 885 | CHECK_GOTO(BN_nnmod(&a, &a, &n, ctx)); | ||
| 886 | CHECK_GOTO(BN_nnmod(&b, &b, &n, ctx)); | ||
| 887 | |||
| 888 | CHECK_GOTO(BN_to_montgomery(&A, &a, mont, ctx)); | ||
| 889 | CHECK_GOTO(BN_to_montgomery(&B, &b, mont, ctx)); | ||
| 890 | |||
| 891 | CHECK_GOTO(BN_mod_mul_montgomery(&c, &A, &B, mont, ctx)); | ||
| 892 | CHECK_GOTO(BN_from_montgomery(&A, &c, mont, ctx)); | ||
| 893 | if (bp != NULL) { | ||
| 894 | if (!results) { | ||
| 895 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 896 | BIO_puts(bp, " * "); | ||
| 897 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 898 | BIO_puts(bp, " % "); | ||
| 899 | CHECK_GOTO(BN_print(bp, &(mont->N))); | ||
| 900 | BIO_puts(bp, " - "); | ||
| 901 | } | ||
| 902 | CHECK_GOTO(BN_print(bp, &A)); | ||
| 903 | BIO_puts(bp, "\n"); | ||
| 904 | } | ||
| 905 | CHECK_GOTO(BN_mod_mul(&d, &a, &b, &n, ctx)); | ||
| 906 | CHECK_GOTO(BN_sub(&d, &d, &A)); | ||
| 907 | if (!BN_is_zero(&d)) { | ||
| 908 | fprintf(stderr, "Montgomery multiplication test failed!\n"); | ||
| 909 | rc = 0; | ||
| 910 | break; | ||
| 911 | } | ||
| 912 | } | ||
| 913 | err: | ||
| 914 | BN_MONT_CTX_free(mont); | ||
| 915 | BN_free(&a); | ||
| 916 | BN_free(&b); | ||
| 917 | BN_free(&c); | ||
| 918 | BN_free(&d); | ||
| 919 | BN_free(&A); | ||
| 920 | BN_free(&B); | ||
| 921 | BN_free(&n); | ||
| 922 | return (rc); | ||
| 923 | } | ||
| 924 | |||
| 925 | int | ||
| 926 | test_mod(BIO *bp, BN_CTX *ctx) | ||
| 927 | { | ||
| 928 | BIGNUM *a, *b, *c, *d, *e; | ||
| 929 | int i; | ||
| 930 | int rc = 1; | ||
| 931 | |||
| 932 | a = BN_new(); | ||
| 933 | b = BN_new(); | ||
| 934 | c = BN_new(); | ||
| 935 | d = BN_new(); | ||
| 936 | e = BN_new(); | ||
| 937 | |||
| 938 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | ||
| 939 | for (i = 0; i < num0; i++) { | ||
| 940 | CHECK_GOTO(BN_bntest_rand(b, 450 + i * 10, 0, 0)); | ||
| 941 | a->neg = rand_neg(); | ||
| 942 | b->neg = rand_neg(); | ||
| 943 | CHECK_GOTO(BN_mod(c, a, b, ctx)); | ||
| 944 | if (bp != NULL) { | ||
| 945 | if (!results) { | ||
| 946 | CHECK_GOTO(BN_print(bp, a)); | ||
| 947 | BIO_puts(bp, " % "); | ||
| 948 | CHECK_GOTO(BN_print(bp, b)); | ||
| 949 | BIO_puts(bp, " - "); | ||
| 950 | } | ||
| 951 | CHECK_GOTO(BN_print(bp, c)); | ||
| 952 | BIO_puts(bp, "\n"); | ||
| 953 | } | ||
| 954 | CHECK_GOTO(BN_div(d, e, a, b, ctx)); | ||
| 955 | CHECK_GOTO(BN_sub(e, e, c)); | ||
| 956 | if (!BN_is_zero(e)) { | ||
| 957 | fprintf(stderr, "Modulo test failed!\n"); | ||
| 958 | rc = 0; | ||
| 959 | break; | ||
| 960 | } | ||
| 961 | } | ||
| 962 | err: | ||
| 963 | BN_free(a); | ||
| 964 | BN_free(b); | ||
| 965 | BN_free(c); | ||
| 966 | BN_free(d); | ||
| 967 | BN_free(e); | ||
| 968 | return (rc); | ||
| 969 | } | ||
| 970 | |||
| 971 | int | ||
| 972 | test_mod_mul(BIO *bp, BN_CTX *ctx) | ||
| 973 | { | ||
| 974 | BIGNUM *a, *b, *c, *d, *e; | ||
| 975 | int i, j; | ||
| 976 | int rc = 1; | ||
| 977 | |||
| 978 | a = BN_new(); | ||
| 979 | b = BN_new(); | ||
| 980 | c = BN_new(); | ||
| 981 | d = BN_new(); | ||
| 982 | e = BN_new(); | ||
| 983 | |||
| 984 | CHECK_GOTO(BN_one(a)); | ||
| 985 | CHECK_GOTO(BN_one(b)); | ||
| 986 | CHECK_GOTO(BN_zero(c)); | ||
| 987 | if (BN_mod_mul(e, a, b, c, ctx)) { | ||
| 988 | fprintf(stderr, "BN_mod_mul with zero modulus succeeded!\n"); | ||
| 989 | return (0); | ||
| 990 | } | ||
| 991 | |||
| 992 | for (j = 0; j < 3; j++) { | ||
| 993 | CHECK_GOTO(BN_bntest_rand(c, 1024, 0, 0)); | ||
| 994 | for (i = 0; i < num0; i++) { | ||
| 995 | CHECK_GOTO(BN_bntest_rand(a, 475 + i * 10, 0, 0)); | ||
| 996 | CHECK_GOTO(BN_bntest_rand(b, 425 + i * 11, 0, 0)); | ||
| 997 | a->neg = rand_neg(); | ||
| 998 | b->neg = rand_neg(); | ||
| 999 | if (!BN_mod_mul(e, a, b, c, ctx)) { | ||
| 1000 | unsigned long l; | ||
| 1001 | |||
| 1002 | while ((l = ERR_get_error())) | ||
| 1003 | fprintf(stderr, "ERROR:%s\n", | ||
| 1004 | ERR_error_string(l, NULL)); | ||
| 1005 | exit(1); | ||
| 1006 | } | ||
| 1007 | if (bp != NULL) { | ||
| 1008 | if (!results) { | ||
| 1009 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1010 | BIO_puts(bp, " * "); | ||
| 1011 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1012 | BIO_puts(bp, " % "); | ||
| 1013 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1014 | if ((a->neg ^ b->neg) && !BN_is_zero(e)) { | ||
| 1015 | /* If (a*b) % c is negative, c must be added | ||
| 1016 | * in order to obtain the normalized remainder | ||
| 1017 | * (new with OpenSSL 0.9.7, previous versions of | ||
| 1018 | * BN_mod_mul could generate negative results) | ||
| 1019 | */ | ||
| 1020 | BIO_puts(bp, " + "); | ||
| 1021 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1022 | } | ||
| 1023 | BIO_puts(bp, " - "); | ||
| 1024 | } | ||
| 1025 | CHECK_GOTO(BN_print(bp, e)); | ||
| 1026 | BIO_puts(bp, "\n"); | ||
| 1027 | } | ||
| 1028 | CHECK_GOTO(BN_mul(d, a, b, ctx)); | ||
| 1029 | CHECK_GOTO(BN_sub(d, d, e)); | ||
| 1030 | CHECK_GOTO(BN_div(a, b, d, c, ctx)); | ||
| 1031 | if (!BN_is_zero(b)) { | ||
| 1032 | fprintf(stderr, "Modulo multiply test failed!\n"); | ||
| 1033 | ERR_print_errors_fp(stderr); | ||
| 1034 | rc = 0; | ||
| 1035 | goto err; | ||
| 1036 | } | ||
| 1037 | } | ||
| 1038 | } | ||
| 1039 | err: | ||
| 1040 | BN_free(a); | ||
| 1041 | BN_free(b); | ||
| 1042 | BN_free(c); | ||
| 1043 | BN_free(d); | ||
| 1044 | BN_free(e); | ||
| 1045 | return (rc); | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | int | ||
| 1049 | test_mod_exp(BIO *bp, BN_CTX *ctx) | ||
| 1050 | { | ||
| 1051 | BIGNUM *a, *b, *c, *d, *e; | ||
| 1052 | int i; | ||
| 1053 | int rc = 1; | ||
| 1054 | |||
| 1055 | a = BN_new(); | ||
| 1056 | b = BN_new(); | ||
| 1057 | c = BN_new(); | ||
| 1058 | d = BN_new(); | ||
| 1059 | e = BN_new(); | ||
| 1060 | |||
| 1061 | CHECK_GOTO(BN_one(a)); | ||
| 1062 | CHECK_GOTO(BN_one(b)); | ||
| 1063 | CHECK_GOTO(BN_zero(c)); | ||
| 1064 | if (BN_mod_exp(d, a, b, c, ctx)) { | ||
| 1065 | fprintf(stderr, "BN_mod_exp with zero modulus succeeded!\n"); | ||
| 1066 | rc = 0; | ||
| 1067 | goto err; | ||
| 1068 | } | ||
| 1069 | if (BN_mod_exp_ct(d, a, b, c, ctx)) { | ||
| 1070 | fprintf(stderr, "BN_mod_exp_ct with zero modulus succeeded!\n"); | ||
| 1071 | rc = 0; | ||
| 1072 | goto err; | ||
| 1073 | } | ||
| 1074 | if (BN_mod_exp_nonct(d, a, b, c, ctx)) { | ||
| 1075 | fprintf(stderr, "BN_mod_exp_nonct with zero modulus succeeded!\n"); | ||
| 1076 | rc = 0; | ||
| 1077 | goto err; | ||
| 1078 | } | ||
| 1079 | |||
| 1080 | CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */ | ||
| 1081 | for (i = 0; i < num2; i++) { | ||
| 1082 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | ||
| 1083 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | ||
| 1084 | |||
| 1085 | if (!BN_mod_exp(d, a, b, c, ctx)) { | ||
| 1086 | rc = 0; | ||
| 1087 | break; | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | if (bp != NULL) { | ||
| 1091 | if (!results) { | ||
| 1092 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1093 | BIO_puts(bp, " ^ "); | ||
| 1094 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1095 | BIO_puts(bp, " % "); | ||
| 1096 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1097 | BIO_puts(bp, " - "); | ||
| 1098 | } | ||
| 1099 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1100 | BIO_puts(bp, "\n"); | ||
| 1101 | } | ||
| 1102 | CHECK_GOTO(BN_exp(e, a, b, ctx)); | ||
| 1103 | CHECK_GOTO(BN_sub(e, e, d)); | ||
| 1104 | CHECK_GOTO(BN_div(a, b, e, c, ctx)); | ||
| 1105 | if (!BN_is_zero(b)) { | ||
| 1106 | fprintf(stderr, "Modulo exponentiation test failed!\n"); | ||
| 1107 | rc = 0; | ||
| 1108 | break; | ||
| 1109 | } | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */ | ||
| 1113 | for (i = 0; i < num2; i++) { | ||
| 1114 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | ||
| 1115 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | ||
| 1116 | |||
| 1117 | if (!BN_mod_exp_ct(d, a, b, c, ctx)) { | ||
| 1118 | rc = 0; | ||
| 1119 | break; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | if (bp != NULL) { | ||
| 1123 | if (!results) { | ||
| 1124 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1125 | BIO_puts(bp, " ^ "); | ||
| 1126 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1127 | BIO_puts(bp, " % "); | ||
| 1128 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1129 | BIO_puts(bp, " - "); | ||
| 1130 | } | ||
| 1131 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1132 | BIO_puts(bp, "\n"); | ||
| 1133 | } | ||
| 1134 | CHECK_GOTO(BN_exp(e, a, b, ctx)); | ||
| 1135 | CHECK_GOTO(BN_sub(e, e, d)); | ||
| 1136 | CHECK_GOTO(BN_div(a, b, e, c, ctx)); | ||
| 1137 | if (!BN_is_zero(b)) { | ||
| 1138 | fprintf(stderr, "Modulo exponentiation test failed!\n"); | ||
| 1139 | rc = 0; | ||
| 1140 | break; | ||
| 1141 | } | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */ | ||
| 1145 | for (i = 0; i < num2; i++) { | ||
| 1146 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | ||
| 1147 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | ||
| 1148 | |||
| 1149 | if (!BN_mod_exp_nonct(d, a, b, c, ctx)) { | ||
| 1150 | rc = 0; | ||
| 1151 | break; | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | if (bp != NULL) { | ||
| 1155 | if (!results) { | ||
| 1156 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1157 | BIO_puts(bp, " ^ "); | ||
| 1158 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1159 | BIO_puts(bp, " % "); | ||
| 1160 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1161 | BIO_puts(bp, " - "); | ||
| 1162 | } | ||
| 1163 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1164 | BIO_puts(bp, "\n"); | ||
| 1165 | } | ||
| 1166 | CHECK_GOTO(BN_exp(e, a, b, ctx)); | ||
| 1167 | CHECK_GOTO(BN_sub(e, e, d)); | ||
| 1168 | CHECK_GOTO(BN_div(a, b, e, c, ctx)); | ||
| 1169 | if (!BN_is_zero(b)) { | ||
| 1170 | fprintf(stderr, "Modulo exponentiation test failed!\n"); | ||
| 1171 | rc = 0; | ||
| 1172 | break; | ||
| 1173 | } | ||
| 1174 | } | ||
| 1175 | err: | ||
| 1176 | BN_free(a); | ||
| 1177 | BN_free(b); | ||
| 1178 | BN_free(c); | ||
| 1179 | BN_free(d); | ||
| 1180 | BN_free(e); | ||
| 1181 | return (rc); | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | int | ||
| 1185 | test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx) | ||
| 1186 | { | ||
| 1187 | BIGNUM *a, *b, *c, *d, *e; | ||
| 1188 | int i; | ||
| 1189 | int rc = 1; | ||
| 1190 | |||
| 1191 | a = BN_new(); | ||
| 1192 | b = BN_new(); | ||
| 1193 | c = BN_new(); | ||
| 1194 | d = BN_new(); | ||
| 1195 | e = BN_new(); | ||
| 1196 | |||
| 1197 | CHECK_GOTO(BN_one(a)); | ||
| 1198 | CHECK_GOTO(BN_one(b)); | ||
| 1199 | CHECK_GOTO(BN_zero(c)); | ||
| 1200 | if (BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) { | ||
| 1201 | fprintf(stderr, "BN_mod_exp_mont_consttime with zero modulus " | ||
| 1202 | "succeeded\n"); | ||
| 1203 | rc = 0; | ||
| 1204 | goto err; | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | CHECK_GOTO(BN_set_word(c, 16)); | ||
| 1208 | if (BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) { | ||
| 1209 | fprintf(stderr, "BN_mod_exp_mont_consttime with even modulus " | ||
| 1210 | "succeeded\n"); | ||
| 1211 | rc = 0; | ||
| 1212 | goto err; | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | CHECK_GOTO(BN_bntest_rand(c, 30, 0, 1)); /* must be odd for montgomery */ | ||
| 1216 | for (i = 0; i < num2; i++) { | ||
| 1217 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | ||
| 1218 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | ||
| 1219 | |||
| 1220 | if (!BN_mod_exp_mont_consttime(d, a, b, c, ctx, NULL)) { | ||
| 1221 | rc = 0; | ||
| 1222 | break; | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | if (bp != NULL) { | ||
| 1226 | if (!results) { | ||
| 1227 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1228 | BIO_puts(bp, " ^ "); | ||
| 1229 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1230 | BIO_puts(bp, " % "); | ||
| 1231 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1232 | BIO_puts(bp, " - "); | ||
| 1233 | } | ||
| 1234 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1235 | BIO_puts(bp, "\n"); | ||
| 1236 | } | ||
| 1237 | CHECK_GOTO(BN_exp(e, a, b, ctx)); | ||
| 1238 | CHECK_GOTO(BN_sub(e, e, d)); | ||
| 1239 | CHECK_GOTO(BN_div(a, b, e, c, ctx)); | ||
| 1240 | if (!BN_is_zero(b)) { | ||
| 1241 | fprintf(stderr, "Modulo exponentiation test failed!\n"); | ||
| 1242 | rc = 0; | ||
| 1243 | break; | ||
| 1244 | } | ||
| 1245 | } | ||
| 1246 | err: | ||
| 1247 | BN_free(a); | ||
| 1248 | BN_free(b); | ||
| 1249 | BN_free(c); | ||
| 1250 | BN_free(d); | ||
| 1251 | BN_free(e); | ||
| 1252 | return (rc); | ||
| 1253 | } | ||
| 1254 | |||
| 1255 | /* | ||
| 1256 | * Test constant-time modular exponentiation with 1024-bit inputs, which on | ||
| 1257 | * x86_64 cause a different code branch to be taken. | ||
| 1258 | */ | ||
| 1259 | int | ||
| 1260 | test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) | ||
| 1261 | { | ||
| 1262 | BIGNUM *a, *p, *m, *d, *e, *b, *n, *c; | ||
| 1263 | int len, rc = 1; | ||
| 1264 | BN_MONT_CTX *mont; | ||
| 1265 | |||
| 1266 | a = BN_new(); | ||
| 1267 | p = BN_new(); | ||
| 1268 | m = BN_new(); | ||
| 1269 | d = BN_new(); | ||
| 1270 | e = BN_new(); | ||
| 1271 | b = BN_new(); | ||
| 1272 | n = BN_new(); | ||
| 1273 | c = BN_new(); | ||
| 1274 | |||
| 1275 | CHECK_GOTO(mont = BN_MONT_CTX_new()); | ||
| 1276 | |||
| 1277 | CHECK_GOTO(BN_bntest_rand(m, 1024, 0, 1)); /* must be odd for montgomery */ | ||
| 1278 | /* Zero exponent */ | ||
| 1279 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | ||
| 1280 | CHECK_GOTO(BN_zero(p)); | ||
| 1281 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) { | ||
| 1282 | rc = 0; | ||
| 1283 | goto err; | ||
| 1284 | } | ||
| 1285 | if (!BN_is_one(d)) { | ||
| 1286 | fprintf(stderr, "Modular exponentiation test failed!\n"); | ||
| 1287 | rc = 0; | ||
| 1288 | goto err; | ||
| 1289 | } | ||
| 1290 | /* Regression test for carry bug in mulx4x_mont */ | ||
| 1291 | len = BN_hex2bn(&a, | ||
| 1292 | "7878787878787878787878787878787878787878787878787878787878787878" | ||
| 1293 | "7878787878787878787878787878787878787878787878787878787878787878" | ||
| 1294 | "7878787878787878787878787878787878787878787878787878787878787878" | ||
| 1295 | "7878787878787878787878787878787878787878787878787878787878787878"); | ||
| 1296 | CHECK_GOTO(len); | ||
| 1297 | len = BN_hex2bn(&b, | ||
| 1298 | "095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744" | ||
| 1299 | "E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593" | ||
| 1300 | "9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03" | ||
| 1301 | "9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81"); | ||
| 1302 | CHECK_GOTO(len); | ||
| 1303 | len = BN_hex2bn(&n, | ||
| 1304 | "D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B" | ||
| 1305 | "91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5" | ||
| 1306 | "D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4" | ||
| 1307 | "2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF"); | ||
| 1308 | CHECK_GOTO(len); | ||
| 1309 | CHECK_GOTO(BN_MONT_CTX_set(mont, n, ctx)); | ||
| 1310 | CHECK_GOTO(BN_mod_mul_montgomery(c, a, b, mont, ctx)); | ||
| 1311 | CHECK_GOTO(BN_mod_mul_montgomery(d, b, a, mont, ctx)); | ||
| 1312 | if (BN_cmp(c, d)) { | ||
| 1313 | fprintf(stderr, "Montgomery multiplication test failed:" | ||
| 1314 | " a*b != b*a.\n"); | ||
| 1315 | rc = 0; | ||
| 1316 | goto err; | ||
| 1317 | } | ||
| 1318 | /* Regression test for carry bug in sqr[x]8x_mont */ | ||
| 1319 | len = BN_hex2bn(&n, | ||
| 1320 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1321 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1322 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1323 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1324 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1325 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1326 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1327 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000FFFFFFFF00" | ||
| 1328 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1329 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1330 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1331 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1332 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1333 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1334 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1335 | "00000000000000000000000000000000000000000000000000FFFFFFFFFFFFFF"); | ||
| 1336 | CHECK_GOTO(len); | ||
| 1337 | len = BN_hex2bn(&a, | ||
| 1338 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1339 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1340 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1341 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1342 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1343 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1344 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 1345 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000FFFFFFFF0000000000" | ||
| 1346 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1347 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1348 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1349 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1350 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1351 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1352 | "0000000000000000000000000000000000000000000000000000000000000000" | ||
| 1353 | "000000000000000000000000000000000000000000FFFFFFFFFFFFFF00000000"); | ||
| 1354 | CHECK_GOTO(len); | ||
| 1355 | BN_free(b); | ||
| 1356 | CHECK_GOTO(b = BN_dup(a)); | ||
| 1357 | CHECK_GOTO(BN_MONT_CTX_set(mont, n, ctx)); | ||
| 1358 | CHECK_GOTO(BN_mod_mul_montgomery(c, a, a, mont, ctx)); | ||
| 1359 | CHECK_GOTO(BN_mod_mul_montgomery(d, a, b, mont, ctx)); | ||
| 1360 | if (BN_cmp(c, d)) { | ||
| 1361 | fprintf(stderr, "Montgomery multiplication test failed:" | ||
| 1362 | " a**2 != a*a.\n"); | ||
| 1363 | rc = 0; | ||
| 1364 | goto err; | ||
| 1365 | } | ||
| 1366 | /* Zero input */ | ||
| 1367 | CHECK_GOTO(BN_bntest_rand(p, 1024, 0, 0)); | ||
| 1368 | CHECK_GOTO(BN_zero(a)); | ||
| 1369 | if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) { | ||
| 1370 | rc = 0; | ||
| 1371 | goto err; | ||
| 1372 | } | ||
| 1373 | if (!BN_is_zero(d)) { | ||
| 1374 | fprintf(stderr, "Modular exponentiation test failed!\n"); | ||
| 1375 | rc = 0; | ||
| 1376 | goto err; | ||
| 1377 | } | ||
| 1378 | /* | ||
| 1379 | * Craft an input whose Montgomery representation is 1, i.e., shorter | ||
| 1380 | * than the modulus m, in order to test the const time precomputation | ||
| 1381 | * scattering/gathering. | ||
| 1382 | */ | ||
| 1383 | CHECK_GOTO(BN_one(a)); | ||
| 1384 | CHECK_GOTO(BN_MONT_CTX_set(mont, m, ctx)); | ||
| 1385 | if (!BN_from_montgomery(e, a, mont, ctx)) { | ||
| 1386 | rc = 0; | ||
| 1387 | goto err; | ||
| 1388 | } | ||
| 1389 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) { | ||
| 1390 | rc = 0; | ||
| 1391 | goto err; | ||
| 1392 | } | ||
| 1393 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) { | ||
| 1394 | rc = 0; | ||
| 1395 | goto err; | ||
| 1396 | } | ||
| 1397 | if (BN_cmp(a, d) != 0) { | ||
| 1398 | fprintf(stderr, "Modular exponentiation test failed!\n"); | ||
| 1399 | rc = 0; | ||
| 1400 | goto err; | ||
| 1401 | } | ||
| 1402 | /* Finally, some regular test vectors. */ | ||
| 1403 | CHECK_GOTO(BN_bntest_rand(e, 1024, 0, 0)); | ||
| 1404 | if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) { | ||
| 1405 | rc = 0; | ||
| 1406 | goto err; | ||
| 1407 | } | ||
| 1408 | if (!BN_mod_exp_simple(a, e, p, m, ctx)) { | ||
| 1409 | rc = 0; | ||
| 1410 | goto err; | ||
| 1411 | } | ||
| 1412 | if (BN_cmp(a, d) != 0) { | ||
| 1413 | fprintf(stderr, "Modular exponentiation test failed!\n"); | ||
| 1414 | rc = 0; | ||
| 1415 | goto err; | ||
| 1416 | } | ||
| 1417 | err: | ||
| 1418 | BN_free(a); | ||
| 1419 | BN_free(p); | ||
| 1420 | BN_free(m); | ||
| 1421 | BN_free(d); | ||
| 1422 | BN_free(e); | ||
| 1423 | BN_free(b); | ||
| 1424 | BN_free(n); | ||
| 1425 | BN_free(c); | ||
| 1426 | BN_MONT_CTX_free(mont); | ||
| 1427 | return (rc); | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | int | ||
| 1431 | test_exp(BIO *bp, BN_CTX *ctx) | ||
| 1432 | { | ||
| 1433 | BIGNUM *a, *b, *d, *e, *one; | ||
| 1434 | int i; | ||
| 1435 | int rc = 1; | ||
| 1436 | |||
| 1437 | a = BN_new(); | ||
| 1438 | b = BN_new(); | ||
| 1439 | d = BN_new(); | ||
| 1440 | e = BN_new(); | ||
| 1441 | one = BN_new(); | ||
| 1442 | CHECK_GOTO(BN_one(one)); | ||
| 1443 | |||
| 1444 | for (i = 0; i < num2; i++) { | ||
| 1445 | CHECK_GOTO(BN_bntest_rand(a, 20 + i * 5, 0, 0)); | ||
| 1446 | CHECK_GOTO(BN_bntest_rand(b, 2 + i, 0, 0)); | ||
| 1447 | |||
| 1448 | if (BN_exp(d, a, b, ctx) <= 0) { | ||
| 1449 | rc = 0; | ||
| 1450 | break; | ||
| 1451 | } | ||
| 1452 | |||
| 1453 | if (bp != NULL) { | ||
| 1454 | if (!results) { | ||
| 1455 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1456 | BIO_puts(bp, " ^ "); | ||
| 1457 | CHECK_GOTO(BN_print(bp, b)); | ||
| 1458 | BIO_puts(bp, " - "); | ||
| 1459 | } | ||
| 1460 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1461 | BIO_puts(bp, "\n"); | ||
| 1462 | } | ||
| 1463 | CHECK_GOTO(BN_one(e)); | ||
| 1464 | for (; !BN_is_zero(b); BN_sub(b, b, one)) | ||
| 1465 | CHECK_GOTO(BN_mul(e, e, a, ctx)); | ||
| 1466 | CHECK_GOTO(BN_sub(e, e, d)); | ||
| 1467 | if (!BN_is_zero(e)) { | ||
| 1468 | fprintf(stderr, "Exponentiation test failed!\n"); | ||
| 1469 | rc = 0; | ||
| 1470 | break; | ||
| 1471 | } | ||
| 1472 | } | ||
| 1473 | err: | ||
| 1474 | BN_free(a); | ||
| 1475 | BN_free(b); | ||
| 1476 | BN_free(d); | ||
| 1477 | BN_free(e); | ||
| 1478 | BN_free(one); | ||
| 1479 | return (rc); | ||
| 1480 | } | ||
| 1481 | |||
| 1482 | #ifndef OPENSSL_NO_EC2M | ||
| 1483 | int | ||
| 1484 | test_gf2m_add(BIO *bp) | ||
| 1485 | { | ||
| 1486 | BIGNUM a, b, c; | ||
| 1487 | int i, rc = 0; | ||
| 1488 | |||
| 1489 | BN_init(&a); | ||
| 1490 | BN_init(&b); | ||
| 1491 | BN_init(&c); | ||
| 1492 | |||
| 1493 | for (i = 0; i < num0; i++) { | ||
| 1494 | CHECK_GOTO(BN_rand(&a, 512, 0, 0)); | ||
| 1495 | CHECK_GOTO(BN_copy(&b, BN_value_one())); | ||
| 1496 | a.neg = rand_neg(); | ||
| 1497 | b.neg = rand_neg(); | ||
| 1498 | CHECK_GOTO(BN_GF2m_add(&c, &a, &b)); | ||
| 1499 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1500 | if (bp != NULL) { | ||
| 1501 | if (!results) { | ||
| 1502 | CHECK_GOTO(BN_print(bp, &a)); | ||
| 1503 | BIO_puts(bp, " ^ "); | ||
| 1504 | CHECK_GOTO(BN_print(bp, &b)); | ||
| 1505 | BIO_puts(bp, " = "); | ||
| 1506 | } | ||
| 1507 | CHECK_GOTO(BN_print(bp, &c)); | ||
| 1508 | BIO_puts(bp, "\n"); | ||
| 1509 | } | ||
| 1510 | #endif | ||
| 1511 | /* Test that two added values have the correct parity. */ | ||
| 1512 | if ((BN_is_odd(&a) && BN_is_odd(&c)) | ||
| 1513 | || (!BN_is_odd(&a) && !BN_is_odd(&c))) { | ||
| 1514 | fprintf(stderr, "GF(2^m) addition test (a) failed!\n"); | ||
| 1515 | goto err; | ||
| 1516 | } | ||
| 1517 | CHECK_GOTO(BN_GF2m_add(&c, &c, &c)); | ||
| 1518 | /* Test that c + c = 0. */ | ||
| 1519 | if (!BN_is_zero(&c)) { | ||
| 1520 | fprintf(stderr, "GF(2^m) addition test (b) failed!\n"); | ||
| 1521 | goto err; | ||
| 1522 | } | ||
| 1523 | } | ||
| 1524 | rc = 1; | ||
| 1525 | err: | ||
| 1526 | BN_free(&a); | ||
| 1527 | BN_free(&b); | ||
| 1528 | BN_free(&c); | ||
| 1529 | return rc; | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | int | ||
| 1533 | test_gf2m_mod(BIO *bp) | ||
| 1534 | { | ||
| 1535 | BIGNUM *a, *b[2], *c, *d, *e; | ||
| 1536 | int i, j, rc = 0; | ||
| 1537 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1538 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1539 | |||
| 1540 | a = BN_new(); | ||
| 1541 | b[0] = BN_new(); | ||
| 1542 | b[1] = BN_new(); | ||
| 1543 | c = BN_new(); | ||
| 1544 | d = BN_new(); | ||
| 1545 | e = BN_new(); | ||
| 1546 | |||
| 1547 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1548 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1549 | |||
| 1550 | for (i = 0; i < num0; i++) { | ||
| 1551 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | ||
| 1552 | for (j = 0; j < 2; j++) { | ||
| 1553 | CHECK_GOTO(BN_GF2m_mod(c, a, b[j])); | ||
| 1554 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1555 | if (bp != NULL) { | ||
| 1556 | if (!results) { | ||
| 1557 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1558 | BIO_puts(bp, " % "); | ||
| 1559 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1560 | BIO_puts(bp, " - "); | ||
| 1561 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1562 | BIO_puts(bp, "\n"); | ||
| 1563 | } | ||
| 1564 | } | ||
| 1565 | #endif | ||
| 1566 | CHECK_GOTO(BN_GF2m_add(d, a, c)); | ||
| 1567 | CHECK_GOTO(BN_GF2m_mod(e, d, b[j])); | ||
| 1568 | /* Test that a + (a mod p) mod p == 0. */ | ||
| 1569 | if (!BN_is_zero(e)) { | ||
| 1570 | fprintf(stderr, "GF(2^m) modulo test failed!\n"); | ||
| 1571 | goto err; | ||
| 1572 | } | ||
| 1573 | } | ||
| 1574 | } | ||
| 1575 | rc = 1; | ||
| 1576 | err: | ||
| 1577 | BN_free(a); | ||
| 1578 | BN_free(b[0]); | ||
| 1579 | BN_free(b[1]); | ||
| 1580 | BN_free(c); | ||
| 1581 | BN_free(d); | ||
| 1582 | BN_free(e); | ||
| 1583 | return rc; | ||
| 1584 | } | ||
| 1585 | |||
| 1586 | int | ||
| 1587 | test_gf2m_mod_mul(BIO *bp, BN_CTX *ctx) | ||
| 1588 | { | ||
| 1589 | BIGNUM *a, *b[2], *c, *d, *e, *f, *g, *h; | ||
| 1590 | int i, j, rc = 0; | ||
| 1591 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1592 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1593 | |||
| 1594 | a = BN_new(); | ||
| 1595 | b[0] = BN_new(); | ||
| 1596 | b[1] = BN_new(); | ||
| 1597 | c = BN_new(); | ||
| 1598 | d = BN_new(); | ||
| 1599 | e = BN_new(); | ||
| 1600 | f = BN_new(); | ||
| 1601 | g = BN_new(); | ||
| 1602 | h = BN_new(); | ||
| 1603 | |||
| 1604 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1605 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1606 | |||
| 1607 | for (i = 0; i < num0; i++) { | ||
| 1608 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | ||
| 1609 | CHECK_GOTO(BN_bntest_rand(c, 1024, 0, 0)); | ||
| 1610 | CHECK_GOTO(BN_bntest_rand(d, 1024, 0, 0)); | ||
| 1611 | for (j = 0; j < 2; j++) { | ||
| 1612 | CHECK_GOTO(BN_GF2m_mod_mul(e, a, c, b[j], ctx)); | ||
| 1613 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1614 | if (bp != NULL) { | ||
| 1615 | if (!results) { | ||
| 1616 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1617 | BIO_puts(bp, " * "); | ||
| 1618 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1619 | BIO_puts(bp, " % "); | ||
| 1620 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1621 | BIO_puts(bp, " - "); | ||
| 1622 | CHECK_GOTO(BN_print(bp, e)); | ||
| 1623 | BIO_puts(bp, "\n"); | ||
| 1624 | } | ||
| 1625 | } | ||
| 1626 | #endif | ||
| 1627 | CHECK_GOTO(BN_GF2m_add(f, a, d)); | ||
| 1628 | CHECK_GOTO(BN_GF2m_mod_mul(g, f, c, b[j], ctx)); | ||
| 1629 | CHECK_GOTO(BN_GF2m_mod_mul(h, d, c, b[j], ctx)); | ||
| 1630 | CHECK_GOTO(BN_GF2m_add(f, e, g)); | ||
| 1631 | CHECK_GOTO(BN_GF2m_add(f, f, h)); | ||
| 1632 | /* Test that (a+d)*c = a*c + d*c. */ | ||
| 1633 | if (!BN_is_zero(f)) { | ||
| 1634 | fprintf(stderr, "GF(2^m) modular multiplication test failed!\n"); | ||
| 1635 | goto err; | ||
| 1636 | } | ||
| 1637 | } | ||
| 1638 | } | ||
| 1639 | rc = 1; | ||
| 1640 | err: | ||
| 1641 | BN_free(a); | ||
| 1642 | BN_free(b[0]); | ||
| 1643 | BN_free(b[1]); | ||
| 1644 | BN_free(c); | ||
| 1645 | BN_free(d); | ||
| 1646 | BN_free(e); | ||
| 1647 | BN_free(f); | ||
| 1648 | BN_free(g); | ||
| 1649 | BN_free(h); | ||
| 1650 | return rc; | ||
| 1651 | } | ||
| 1652 | |||
| 1653 | int | ||
| 1654 | test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx) | ||
| 1655 | { | ||
| 1656 | BIGNUM *a, *b[2], *c, *d; | ||
| 1657 | int i, j, rc = 0; | ||
| 1658 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1659 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1660 | |||
| 1661 | a = BN_new(); | ||
| 1662 | b[0] = BN_new(); | ||
| 1663 | b[1] = BN_new(); | ||
| 1664 | c = BN_new(); | ||
| 1665 | d = BN_new(); | ||
| 1666 | |||
| 1667 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1668 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1669 | |||
| 1670 | for (i = 0; i < num0; i++) { | ||
| 1671 | CHECK_GOTO(BN_bntest_rand(a, 1024, 0, 0)); | ||
| 1672 | for (j = 0; j < 2; j++) { | ||
| 1673 | CHECK_GOTO(BN_GF2m_mod_sqr(c, a, b[j], ctx)); | ||
| 1674 | CHECK_GOTO(BN_copy(d, a)); | ||
| 1675 | CHECK_GOTO(BN_GF2m_mod_mul(d, a, d, b[j], ctx)); | ||
| 1676 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1677 | if (bp != NULL) { | ||
| 1678 | if (!results) { | ||
| 1679 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1680 | BIO_puts(bp, " ^ 2 % "); | ||
| 1681 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1682 | BIO_puts(bp, " = "); | ||
| 1683 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1684 | BIO_puts(bp, "; a * a = "); | ||
| 1685 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1686 | BIO_puts(bp, "\n"); | ||
| 1687 | } | ||
| 1688 | } | ||
| 1689 | #endif | ||
| 1690 | CHECK_GOTO(BN_GF2m_add(d, c, d)); | ||
| 1691 | /* Test that a*a = a^2. */ | ||
| 1692 | if (!BN_is_zero(d)) { | ||
| 1693 | fprintf(stderr, "GF(2^m) modular squaring test failed!\n"); | ||
| 1694 | goto err; | ||
| 1695 | } | ||
| 1696 | } | ||
| 1697 | } | ||
| 1698 | rc = 1; | ||
| 1699 | err: | ||
| 1700 | BN_free(a); | ||
| 1701 | BN_free(b[0]); | ||
| 1702 | BN_free(b[1]); | ||
| 1703 | BN_free(c); | ||
| 1704 | BN_free(d); | ||
| 1705 | return rc; | ||
| 1706 | } | ||
| 1707 | |||
| 1708 | int | ||
| 1709 | test_gf2m_mod_inv(BIO *bp, BN_CTX *ctx) | ||
| 1710 | { | ||
| 1711 | BIGNUM *a, *b[2], *c, *d; | ||
| 1712 | int i, j, rc = 0; | ||
| 1713 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1714 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1715 | |||
| 1716 | a = BN_new(); | ||
| 1717 | b[0] = BN_new(); | ||
| 1718 | b[1] = BN_new(); | ||
| 1719 | c = BN_new(); | ||
| 1720 | d = BN_new(); | ||
| 1721 | |||
| 1722 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1723 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1724 | |||
| 1725 | for (i = 0; i < num0; i++) { | ||
| 1726 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | ||
| 1727 | for (j = 0; j < 2; j++) { | ||
| 1728 | CHECK_GOTO(BN_GF2m_mod_inv(c, a, b[j], ctx)); | ||
| 1729 | CHECK_GOTO(BN_GF2m_mod_mul(d, a, c, b[j], ctx)); | ||
| 1730 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1731 | if (bp != NULL) { | ||
| 1732 | if (!results) { | ||
| 1733 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1734 | BIO_puts(bp, " * "); | ||
| 1735 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1736 | BIO_puts(bp, " - 1 % "); | ||
| 1737 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1738 | BIO_puts(bp, "\n"); | ||
| 1739 | } | ||
| 1740 | } | ||
| 1741 | #endif | ||
| 1742 | /* Test that ((1/a)*a) = 1. */ | ||
| 1743 | if (!BN_is_one(d)) { | ||
| 1744 | fprintf(stderr, "GF(2^m) modular inversion test failed!\n"); | ||
| 1745 | goto err; | ||
| 1746 | } | ||
| 1747 | } | ||
| 1748 | } | ||
| 1749 | rc = 1; | ||
| 1750 | err: | ||
| 1751 | BN_free(a); | ||
| 1752 | BN_free(b[0]); | ||
| 1753 | BN_free(b[1]); | ||
| 1754 | BN_free(c); | ||
| 1755 | BN_free(d); | ||
| 1756 | return rc; | ||
| 1757 | } | ||
| 1758 | |||
| 1759 | int | ||
| 1760 | test_gf2m_mod_div(BIO *bp, BN_CTX *ctx) | ||
| 1761 | { | ||
| 1762 | BIGNUM *a, *b[2], *c, *d, *e, *f; | ||
| 1763 | int i, j, rc = 0; | ||
| 1764 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1765 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1766 | |||
| 1767 | a = BN_new(); | ||
| 1768 | b[0] = BN_new(); | ||
| 1769 | b[1] = BN_new(); | ||
| 1770 | c = BN_new(); | ||
| 1771 | d = BN_new(); | ||
| 1772 | e = BN_new(); | ||
| 1773 | f = BN_new(); | ||
| 1774 | |||
| 1775 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1776 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1777 | |||
| 1778 | for (i = 0; i < num0; i++) { | ||
| 1779 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | ||
| 1780 | CHECK_GOTO(BN_bntest_rand(c, 512, 0, 0)); | ||
| 1781 | for (j = 0; j < 2; j++) { | ||
| 1782 | CHECK_GOTO(BN_GF2m_mod_div(d, a, c, b[j], ctx)); | ||
| 1783 | CHECK_GOTO(BN_GF2m_mod_mul(e, d, c, b[j], ctx)); | ||
| 1784 | CHECK_GOTO(BN_GF2m_mod_div(f, a, e, b[j], ctx)); | ||
| 1785 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1786 | if (bp != NULL) { | ||
| 1787 | if (!results) { | ||
| 1788 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1789 | BIO_puts(bp, " = "); | ||
| 1790 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1791 | BIO_puts(bp, " * "); | ||
| 1792 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1793 | BIO_puts(bp, " % "); | ||
| 1794 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1795 | BIO_puts(bp, "\n"); | ||
| 1796 | } | ||
| 1797 | } | ||
| 1798 | #endif | ||
| 1799 | /* Test that ((a/c)*c)/a = 1. */ | ||
| 1800 | if (!BN_is_one(f)) { | ||
| 1801 | fprintf(stderr, "GF(2^m) modular division test failed!\n"); | ||
| 1802 | goto err; | ||
| 1803 | } | ||
| 1804 | } | ||
| 1805 | } | ||
| 1806 | rc = 1; | ||
| 1807 | err: | ||
| 1808 | BN_free(a); | ||
| 1809 | BN_free(b[0]); | ||
| 1810 | BN_free(b[1]); | ||
| 1811 | BN_free(c); | ||
| 1812 | BN_free(d); | ||
| 1813 | BN_free(e); | ||
| 1814 | BN_free(f); | ||
| 1815 | return rc; | ||
| 1816 | } | ||
| 1817 | |||
| 1818 | int | ||
| 1819 | test_gf2m_mod_exp(BIO *bp, BN_CTX *ctx) | ||
| 1820 | { | ||
| 1821 | BIGNUM *a, *b[2], *c, *d, *e, *f; | ||
| 1822 | int i, j, rc = 0; | ||
| 1823 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1824 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1825 | |||
| 1826 | a = BN_new(); | ||
| 1827 | b[0] = BN_new(); | ||
| 1828 | b[1] = BN_new(); | ||
| 1829 | c = BN_new(); | ||
| 1830 | d = BN_new(); | ||
| 1831 | e = BN_new(); | ||
| 1832 | f = BN_new(); | ||
| 1833 | |||
| 1834 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1835 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1836 | |||
| 1837 | for (i = 0; i < num0; i++) { | ||
| 1838 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | ||
| 1839 | CHECK_GOTO(BN_bntest_rand(c, 512, 0, 0)); | ||
| 1840 | CHECK_GOTO(BN_bntest_rand(d, 512, 0, 0)); | ||
| 1841 | for (j = 0; j < 2; j++) { | ||
| 1842 | CHECK_GOTO(BN_GF2m_mod_exp(e, a, c, b[j], ctx)); | ||
| 1843 | CHECK_GOTO(BN_GF2m_mod_exp(f, a, d, b[j], ctx)); | ||
| 1844 | CHECK_GOTO(BN_GF2m_mod_mul(e, e, f, b[j], ctx)); | ||
| 1845 | CHECK_GOTO(BN_add(f, c, d)); | ||
| 1846 | CHECK_GOTO(BN_GF2m_mod_exp(f, a, f, b[j], ctx)); | ||
| 1847 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1848 | if (bp != NULL) { | ||
| 1849 | if (!results) { | ||
| 1850 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1851 | BIO_puts(bp, " ^ ("); | ||
| 1852 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1853 | BIO_puts(bp, " + "); | ||
| 1854 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1855 | BIO_puts(bp, ") = "); | ||
| 1856 | CHECK_GOTO(BN_print(bp, e)); | ||
| 1857 | BIO_puts(bp, "; - "); | ||
| 1858 | CHECK_GOTO(BN_print(bp, f)); | ||
| 1859 | BIO_puts(bp, " % "); | ||
| 1860 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1861 | BIO_puts(bp, "\n"); | ||
| 1862 | } | ||
| 1863 | } | ||
| 1864 | #endif | ||
| 1865 | CHECK_GOTO(BN_GF2m_add(f, e, f)); | ||
| 1866 | /* Test that a^(c+d)=a^c*a^d. */ | ||
| 1867 | if (!BN_is_zero(f)) { | ||
| 1868 | fprintf(stderr, "GF(2^m) modular exponentiation test failed!\n"); | ||
| 1869 | goto err; | ||
| 1870 | } | ||
| 1871 | } | ||
| 1872 | } | ||
| 1873 | rc = 1; | ||
| 1874 | err: | ||
| 1875 | BN_free(a); | ||
| 1876 | BN_free(b[0]); | ||
| 1877 | BN_free(b[1]); | ||
| 1878 | BN_free(c); | ||
| 1879 | BN_free(d); | ||
| 1880 | BN_free(e); | ||
| 1881 | BN_free(f); | ||
| 1882 | return rc; | ||
| 1883 | } | ||
| 1884 | |||
| 1885 | int | ||
| 1886 | test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx) | ||
| 1887 | { | ||
| 1888 | BIGNUM *a, *b[2], *c, *d, *e, *f; | ||
| 1889 | int i, j, rc = 0; | ||
| 1890 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1891 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1892 | |||
| 1893 | a = BN_new(); | ||
| 1894 | b[0] = BN_new(); | ||
| 1895 | b[1] = BN_new(); | ||
| 1896 | c = BN_new(); | ||
| 1897 | d = BN_new(); | ||
| 1898 | e = BN_new(); | ||
| 1899 | f = BN_new(); | ||
| 1900 | |||
| 1901 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1902 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1903 | |||
| 1904 | for (i = 0; i < num0; i++) { | ||
| 1905 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | ||
| 1906 | for (j = 0; j < 2; j++) { | ||
| 1907 | CHECK_GOTO(BN_GF2m_mod(c, a, b[j])); | ||
| 1908 | CHECK_GOTO(BN_GF2m_mod_sqrt(d, a, b[j], ctx)); | ||
| 1909 | CHECK_GOTO(BN_GF2m_mod_sqr(e, d, b[j], ctx)); | ||
| 1910 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1911 | if (bp != NULL) { | ||
| 1912 | if (!results) { | ||
| 1913 | CHECK_GOTO(BN_print(bp, d)); | ||
| 1914 | BIO_puts(bp, " ^ 2 - "); | ||
| 1915 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1916 | BIO_puts(bp, "\n"); | ||
| 1917 | } | ||
| 1918 | } | ||
| 1919 | #endif | ||
| 1920 | CHECK_GOTO(BN_GF2m_add(f, c, e)); | ||
| 1921 | /* Test that d^2 = a, where d = sqrt(a). */ | ||
| 1922 | if (!BN_is_zero(f)) { | ||
| 1923 | fprintf(stderr, "GF(2^m) modular square root test failed!\n"); | ||
| 1924 | goto err; | ||
| 1925 | } | ||
| 1926 | } | ||
| 1927 | } | ||
| 1928 | rc = 1; | ||
| 1929 | err: | ||
| 1930 | BN_free(a); | ||
| 1931 | BN_free(b[0]); | ||
| 1932 | BN_free(b[1]); | ||
| 1933 | BN_free(c); | ||
| 1934 | BN_free(d); | ||
| 1935 | BN_free(e); | ||
| 1936 | BN_free(f); | ||
| 1937 | return rc; | ||
| 1938 | } | ||
| 1939 | |||
| 1940 | int | ||
| 1941 | test_gf2m_mod_solve_quad(BIO *bp, BN_CTX *ctx) | ||
| 1942 | { | ||
| 1943 | BIGNUM *a, *b[2], *c, *d, *e; | ||
| 1944 | int i, j, s = 0, t, rc = 0; | ||
| 1945 | int p0[] = { 163, 7, 6, 3, 0, -1 }; | ||
| 1946 | int p1[] = { 193, 15, 0, -1 }; | ||
| 1947 | |||
| 1948 | a = BN_new(); | ||
| 1949 | b[0] = BN_new(); | ||
| 1950 | b[1] = BN_new(); | ||
| 1951 | c = BN_new(); | ||
| 1952 | d = BN_new(); | ||
| 1953 | e = BN_new(); | ||
| 1954 | |||
| 1955 | CHECK_GOTO(BN_GF2m_arr2poly(p0, b[0])); | ||
| 1956 | CHECK_GOTO(BN_GF2m_arr2poly(p1, b[1])); | ||
| 1957 | |||
| 1958 | for (i = 0; i < num0; i++) { | ||
| 1959 | CHECK_GOTO(BN_bntest_rand(a, 512, 0, 0)); | ||
| 1960 | for (j = 0; j < 2; j++) { | ||
| 1961 | t = BN_GF2m_mod_solve_quad(c, a, b[j], ctx); | ||
| 1962 | if (t) { | ||
| 1963 | s++; | ||
| 1964 | CHECK_GOTO(BN_GF2m_mod_sqr(d, c, b[j], ctx)); | ||
| 1965 | CHECK_GOTO(BN_GF2m_add(d, c, d)); | ||
| 1966 | CHECK_GOTO(BN_GF2m_mod(e, a, b[j])); | ||
| 1967 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1968 | if (bp != NULL) { | ||
| 1969 | if (!results) { | ||
| 1970 | CHECK_GOTO(BN_print(bp, c)); | ||
| 1971 | BIO_puts(bp, " is root of z^2 + z = "); | ||
| 1972 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1973 | BIO_puts(bp, " % "); | ||
| 1974 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1975 | BIO_puts(bp, "\n"); | ||
| 1976 | } | ||
| 1977 | } | ||
| 1978 | #endif | ||
| 1979 | CHECK_GOTO(BN_GF2m_add(e, e, d)); | ||
| 1980 | /* Test that solution of quadratic c satisfies c^2 + c = a. */ | ||
| 1981 | if (!BN_is_zero(e)) { | ||
| 1982 | fprintf(stderr, "GF(2^m) modular solve quadratic test failed!\n"); | ||
| 1983 | goto err; | ||
| 1984 | } | ||
| 1985 | |||
| 1986 | } else { | ||
| 1987 | #if 0 /* make test uses ouput in bc but bc can't handle GF(2^m) arithmetic */ | ||
| 1988 | if (bp != NULL) { | ||
| 1989 | if (!results) { | ||
| 1990 | BIO_puts(bp, "There are no roots of z^2 + z = "); | ||
| 1991 | CHECK_GOTO(BN_print(bp, a)); | ||
| 1992 | BIO_puts(bp, " % "); | ||
| 1993 | CHECK_GOTO(BN_print(bp, b[j])); | ||
| 1994 | BIO_puts(bp, "\n"); | ||
| 1995 | } | ||
| 1996 | } | ||
| 1997 | #endif | ||
| 1998 | } | ||
| 1999 | } | ||
| 2000 | } | ||
| 2001 | if (s == 0) { | ||
| 2002 | fprintf(stderr, "All %i tests of GF(2^m) modular solve quadratic resulted in no roots;\n", num0); | ||
| 2003 | fprintf(stderr, "this is very unlikely and probably indicates an error.\n"); | ||
| 2004 | goto err; | ||
| 2005 | } | ||
| 2006 | rc = 1; | ||
| 2007 | err: | ||
| 2008 | BN_free(a); | ||
| 2009 | BN_free(b[0]); | ||
| 2010 | BN_free(b[1]); | ||
| 2011 | BN_free(c); | ||
| 2012 | BN_free(d); | ||
| 2013 | BN_free(e); | ||
| 2014 | return rc; | ||
| 2015 | } | ||
| 2016 | #endif | ||
| 2017 | static int | ||
| 2018 | genprime_cb(int p, int n, BN_GENCB *arg) | ||
| 2019 | { | ||
| 2020 | char c = '*'; | ||
| 2021 | |||
| 2022 | if (p == 0) | ||
| 2023 | c = '.'; | ||
| 2024 | if (p == 1) | ||
| 2025 | c = '+'; | ||
| 2026 | if (p == 2) | ||
| 2027 | c = '*'; | ||
| 2028 | if (p == 3) | ||
| 2029 | c = '\n'; | ||
| 2030 | putc(c, stderr); | ||
| 2031 | fflush(stderr); | ||
| 2032 | return (1); | ||
| 2033 | } | ||
| 2034 | |||
| 2035 | int | ||
| 2036 | test_kron(BIO *bp, BN_CTX *ctx) | ||
| 2037 | { | ||
| 2038 | BN_GENCB cb; | ||
| 2039 | BIGNUM *a, *b, *r, *t; | ||
| 2040 | int i; | ||
| 2041 | int legendre, kronecker; | ||
| 2042 | int rc = 0; | ||
| 2043 | |||
| 2044 | a = BN_new(); | ||
| 2045 | b = BN_new(); | ||
| 2046 | r = BN_new(); | ||
| 2047 | t = BN_new(); | ||
| 2048 | if (a == NULL || b == NULL || r == NULL || t == NULL) | ||
| 2049 | goto err; | ||
| 2050 | |||
| 2051 | BN_GENCB_set(&cb, genprime_cb, NULL); | ||
| 2052 | |||
| 2053 | /* | ||
| 2054 | * We test BN_kronecker(a, b, ctx) just for b odd (Jacobi symbol). In | ||
| 2055 | * this case we know that if b is prime, then BN_kronecker(a, b, ctx) is | ||
| 2056 | * congruent to $a^{(b-1)/2}$, modulo $b$ (Legendre symbol). So we | ||
| 2057 | * generate a random prime b and compare these values for a number of | ||
| 2058 | * random a's. (That is, we run the Solovay-Strassen primality test to | ||
| 2059 | * confirm that b is prime, except that we don't want to test whether b | ||
| 2060 | * is prime but whether BN_kronecker works.) | ||
| 2061 | */ | ||
| 2062 | |||
| 2063 | if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb)) | ||
| 2064 | goto err; | ||
| 2065 | b->neg = rand_neg(); | ||
| 2066 | putc('\n', stderr); | ||
| 2067 | |||
| 2068 | for (i = 0; i < num0; i++) { | ||
| 2069 | if (!BN_bntest_rand(a, 512, 0, 0)) | ||
| 2070 | goto err; | ||
| 2071 | a->neg = rand_neg(); | ||
| 2072 | |||
| 2073 | /* t := (|b|-1)/2 (note that b is odd) */ | ||
| 2074 | if (!BN_copy(t, b)) | ||
| 2075 | goto err; | ||
| 2076 | t->neg = 0; | ||
| 2077 | if (!BN_sub_word(t, 1)) | ||
| 2078 | goto err; | ||
| 2079 | if (!BN_rshift1(t, t)) | ||
| 2080 | goto err; | ||
| 2081 | /* r := a^t mod b */ | ||
| 2082 | b->neg = 0; | ||
| 2083 | |||
| 2084 | if (!BN_mod_exp_recp(r, a, t, b, ctx)) | ||
| 2085 | goto err; | ||
| 2086 | b->neg = 1; | ||
| 2087 | |||
| 2088 | if (BN_is_word(r, 1)) | ||
| 2089 | legendre = 1; | ||
| 2090 | else if (BN_is_zero(r)) | ||
| 2091 | legendre = 0; | ||
| 2092 | else { | ||
| 2093 | if (!BN_add_word(r, 1)) | ||
| 2094 | goto err; | ||
| 2095 | if (0 != BN_ucmp(r, b)) { | ||
| 2096 | fprintf(stderr, "Legendre symbol computation failed\n"); | ||
| 2097 | goto err; | ||
| 2098 | } | ||
| 2099 | legendre = -1; | ||
| 2100 | } | ||
| 2101 | |||
| 2102 | kronecker = BN_kronecker(a, b, ctx); | ||
| 2103 | if (kronecker < -1) | ||
| 2104 | goto err; | ||
| 2105 | /* we actually need BN_kronecker(a, |b|) */ | ||
| 2106 | if (a->neg && b->neg) | ||
| 2107 | kronecker = -kronecker; | ||
| 2108 | |||
| 2109 | if (legendre != kronecker) { | ||
| 2110 | fprintf(stderr, "legendre != kronecker; a = "); | ||
| 2111 | CHECK_GOTO(BN_print_fp(stderr, a)); | ||
| 2112 | fprintf(stderr, ", b = "); | ||
| 2113 | CHECK_GOTO(BN_print_fp(stderr, b)); | ||
| 2114 | fprintf(stderr, "\n"); | ||
| 2115 | goto err; | ||
| 2116 | } | ||
| 2117 | |||
| 2118 | putc('.', stderr); | ||
| 2119 | fflush(stderr); | ||
| 2120 | } | ||
| 2121 | |||
| 2122 | putc('\n', stderr); | ||
| 2123 | fflush(stderr); | ||
| 2124 | rc = 1; | ||
| 2125 | err: | ||
| 2126 | BN_free(a); | ||
| 2127 | BN_free(b); | ||
| 2128 | BN_free(r); | ||
| 2129 | BN_free(t); | ||
| 2130 | return rc; | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | int | ||
| 2134 | test_sqrt(BIO *bp, BN_CTX *ctx) | ||
| 2135 | { | ||
| 2136 | BN_GENCB cb; | ||
| 2137 | BIGNUM *a, *p, *r; | ||
| 2138 | int i, j; | ||
| 2139 | int rc = 0; | ||
| 2140 | |||
| 2141 | a = BN_new(); | ||
| 2142 | p = BN_new(); | ||
| 2143 | r = BN_new(); | ||
| 2144 | if (a == NULL || p == NULL || r == NULL) | ||
| 2145 | goto err; | ||
| 2146 | |||
| 2147 | BN_GENCB_set(&cb, genprime_cb, NULL); | ||
| 2148 | |||
| 2149 | for (i = 0; i < 16; i++) { | ||
| 2150 | if (i < 8) { | ||
| 2151 | unsigned primes[8] = { 2, 3, 5, 7, 11, 13, 17, 19 }; | ||
| 2152 | |||
| 2153 | if (!BN_set_word(p, primes[i])) | ||
| 2154 | goto err; | ||
| 2155 | } else { | ||
| 2156 | if (!BN_set_word(a, 32)) | ||
| 2157 | goto err; | ||
| 2158 | if (!BN_set_word(r, 2 * i + 1)) | ||
| 2159 | goto err; | ||
| 2160 | |||
| 2161 | if (!BN_generate_prime_ex(p, 256, 0, a, r, &cb)) | ||
| 2162 | goto err; | ||
| 2163 | putc('\n', stderr); | ||
| 2164 | } | ||
| 2165 | p->neg = rand_neg(); | ||
| 2166 | |||
| 2167 | for (j = 0; j < num2; j++) { | ||
| 2168 | /* | ||
| 2169 | * construct 'a' such that it is a square modulo p, but in | ||
| 2170 | * general not a proper square and not reduced modulo p | ||
| 2171 | */ | ||
| 2172 | if (!BN_bntest_rand(r, 256, 0, 3)) | ||
| 2173 | goto err; | ||
| 2174 | if (!BN_nnmod(r, r, p, ctx)) | ||
| 2175 | goto err; | ||
| 2176 | if (!BN_mod_sqr(r, r, p, ctx)) | ||
| 2177 | goto err; | ||
| 2178 | if (!BN_bntest_rand(a, 256, 0, 3)) | ||
| 2179 | goto err; | ||
| 2180 | if (!BN_nnmod(a, a, p, ctx)) | ||
| 2181 | goto err; | ||
| 2182 | if (!BN_mod_sqr(a, a, p, ctx)) | ||
| 2183 | goto err; | ||
| 2184 | if (!BN_mul(a, a, r, ctx)) | ||
| 2185 | goto err; | ||
| 2186 | if (rand_neg()) | ||
| 2187 | if (!BN_sub(a, a, p)) | ||
| 2188 | goto err; | ||
| 2189 | |||
| 2190 | if (!BN_mod_sqrt(r, a, p, ctx)) | ||
| 2191 | goto err; | ||
| 2192 | if (!BN_mod_sqr(r, r, p, ctx)) | ||
| 2193 | goto err; | ||
| 2194 | |||
| 2195 | if (!BN_nnmod(a, a, p, ctx)) | ||
| 2196 | goto err; | ||
| 2197 | |||
| 2198 | if (BN_cmp(a, r) != 0) { | ||
| 2199 | fprintf(stderr, "BN_mod_sqrt failed: a = "); | ||
| 2200 | CHECK_GOTO(BN_print_fp(stderr, a)); | ||
| 2201 | fprintf(stderr, ", r = "); | ||
| 2202 | CHECK_GOTO(BN_print_fp(stderr, r)); | ||
| 2203 | fprintf(stderr, ", p = "); | ||
| 2204 | CHECK_GOTO(BN_print_fp(stderr, p)); | ||
| 2205 | fprintf(stderr, "\n"); | ||
| 2206 | goto err; | ||
| 2207 | } | ||
| 2208 | |||
| 2209 | putc('.', stderr); | ||
| 2210 | fflush(stderr); | ||
| 2211 | } | ||
| 2212 | |||
| 2213 | putc('\n', stderr); | ||
| 2214 | fflush(stderr); | ||
| 2215 | } | ||
| 2216 | rc = 1; | ||
| 2217 | err: | ||
| 2218 | BN_free(a); | ||
| 2219 | BN_free(p); | ||
| 2220 | BN_free(r); | ||
| 2221 | return rc; | ||
| 2222 | } | ||
| 2223 | |||
| 2224 | int | ||
| 2225 | test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_) | ||
| 2226 | { | ||
| 2227 | BIGNUM *a = NULL, *b, *c, *d; | ||
| 2228 | int i; | ||
| 2229 | int rc = 1; | ||
| 2230 | |||
| 2231 | b = BN_new(); | ||
| 2232 | c = BN_new(); | ||
| 2233 | d = BN_new(); | ||
| 2234 | CHECK_GOTO(BN_one(c)); | ||
| 2235 | |||
| 2236 | if (a_) | ||
| 2237 | a = a_; | ||
| 2238 | else { | ||
| 2239 | a = BN_new(); | ||
| 2240 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); | ||
| 2241 | a->neg = rand_neg(); | ||
| 2242 | } | ||
| 2243 | for (i = 0; i < num0; i++) { | ||
| 2244 | CHECK_GOTO(BN_lshift(b, a, i + 1)); | ||
| 2245 | CHECK_GOTO(BN_add(c, c, c)); | ||
| 2246 | if (bp != NULL) { | ||
| 2247 | if (!results) { | ||
| 2248 | CHECK_GOTO(BN_print(bp, a)); | ||
| 2249 | BIO_puts(bp, " * "); | ||
| 2250 | CHECK_GOTO(BN_print(bp, c)); | ||
| 2251 | BIO_puts(bp, " - "); | ||
| 2252 | } | ||
| 2253 | CHECK_GOTO(BN_print(bp, b)); | ||
| 2254 | BIO_puts(bp, "\n"); | ||
| 2255 | } | ||
| 2256 | CHECK_GOTO(BN_mul(d, a, c, ctx)); | ||
| 2257 | CHECK_GOTO(BN_sub(d, d, b)); | ||
| 2258 | if (!BN_is_zero(d)) { | ||
| 2259 | fprintf(stderr, "Left shift test failed!\n"); | ||
| 2260 | fprintf(stderr, "a="); | ||
| 2261 | CHECK_GOTO(BN_print_fp(stderr, a)); | ||
| 2262 | fprintf(stderr, "\nb="); | ||
| 2263 | CHECK_GOTO(BN_print_fp(stderr, b)); | ||
| 2264 | fprintf(stderr, "\nc="); | ||
| 2265 | CHECK_GOTO(BN_print_fp(stderr, c)); | ||
| 2266 | fprintf(stderr, "\nd="); | ||
| 2267 | CHECK_GOTO(BN_print_fp(stderr, d)); | ||
| 2268 | fprintf(stderr, "\n"); | ||
| 2269 | rc = 0; | ||
| 2270 | break; | ||
| 2271 | } | ||
| 2272 | } | ||
| 2273 | err: | ||
| 2274 | BN_free(a); | ||
| 2275 | BN_free(b); | ||
| 2276 | BN_free(c); | ||
| 2277 | BN_free(d); | ||
| 2278 | return (rc); | ||
| 2279 | } | ||
| 2280 | |||
| 2281 | int | ||
| 2282 | test_lshift1(BIO *bp) | ||
| 2283 | { | ||
| 2284 | BIGNUM *a, *b, *c; | ||
| 2285 | int i; | ||
| 2286 | int rc = 1; | ||
| 2287 | |||
| 2288 | a = BN_new(); | ||
| 2289 | b = BN_new(); | ||
| 2290 | c = BN_new(); | ||
| 2291 | |||
| 2292 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); | ||
| 2293 | a->neg = rand_neg(); | ||
| 2294 | for (i = 0; i < num0; i++) { | ||
| 2295 | CHECK_GOTO(BN_lshift1(b, a)); | ||
| 2296 | if (bp != NULL) { | ||
| 2297 | if (!results) { | ||
| 2298 | CHECK_GOTO(BN_print(bp, a)); | ||
| 2299 | BIO_puts(bp, " * 2"); | ||
| 2300 | BIO_puts(bp, " - "); | ||
| 2301 | } | ||
| 2302 | CHECK_GOTO(BN_print(bp, b)); | ||
| 2303 | BIO_puts(bp, "\n"); | ||
| 2304 | } | ||
| 2305 | CHECK_GOTO(BN_add(c, a, a)); | ||
| 2306 | CHECK_GOTO(BN_sub(a, b, c)); | ||
| 2307 | if (!BN_is_zero(a)) { | ||
| 2308 | fprintf(stderr, "Left shift one test failed!\n"); | ||
| 2309 | rc = 0; | ||
| 2310 | break; | ||
| 2311 | } | ||
| 2312 | |||
| 2313 | CHECK_GOTO(BN_copy(a, b)); | ||
| 2314 | } | ||
| 2315 | err: | ||
| 2316 | BN_free(a); | ||
| 2317 | BN_free(b); | ||
| 2318 | BN_free(c); | ||
| 2319 | return (rc); | ||
| 2320 | } | ||
| 2321 | |||
| 2322 | int | ||
| 2323 | test_rshift(BIO *bp, BN_CTX *ctx) | ||
| 2324 | { | ||
| 2325 | BIGNUM *a, *b, *c, *d, *e; | ||
| 2326 | int i; | ||
| 2327 | int rc = 1; | ||
| 2328 | |||
| 2329 | a = BN_new(); | ||
| 2330 | b = BN_new(); | ||
| 2331 | c = BN_new(); | ||
| 2332 | d = BN_new(); | ||
| 2333 | e = BN_new(); | ||
| 2334 | CHECK_GOTO(BN_one(c)); | ||
| 2335 | |||
| 2336 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); | ||
| 2337 | a->neg = rand_neg(); | ||
| 2338 | for (i = 0; i < num0; i++) { | ||
| 2339 | CHECK_GOTO(BN_rshift(b, a, i + 1)); | ||
| 2340 | CHECK_GOTO(BN_add(c, c, c)); | ||
| 2341 | if (bp != NULL) { | ||
| 2342 | if (!results) { | ||
| 2343 | CHECK_GOTO(BN_print(bp, a)); | ||
| 2344 | BIO_puts(bp, " / "); | ||
| 2345 | CHECK_GOTO(BN_print(bp, c)); | ||
| 2346 | BIO_puts(bp, " - "); | ||
| 2347 | } | ||
| 2348 | CHECK_GOTO(BN_print(bp, b)); | ||
| 2349 | BIO_puts(bp, "\n"); | ||
| 2350 | } | ||
| 2351 | CHECK_GOTO(BN_div(d, e, a, c, ctx)); | ||
| 2352 | CHECK_GOTO(BN_sub(d, d, b)); | ||
| 2353 | if (!BN_is_zero(d)) { | ||
| 2354 | fprintf(stderr, "Right shift test failed!\n"); | ||
| 2355 | rc = 0; | ||
| 2356 | break; | ||
| 2357 | } | ||
| 2358 | } | ||
| 2359 | err: | ||
| 2360 | BN_free(a); | ||
| 2361 | BN_free(b); | ||
| 2362 | BN_free(c); | ||
| 2363 | BN_free(d); | ||
| 2364 | BN_free(e); | ||
| 2365 | return (rc); | ||
| 2366 | } | ||
| 2367 | |||
| 2368 | int | ||
| 2369 | test_rshift1(BIO *bp) | ||
| 2370 | { | ||
| 2371 | BIGNUM *a, *b, *c; | ||
| 2372 | int i; | ||
| 2373 | int rc = 1; | ||
| 2374 | |||
| 2375 | a = BN_new(); | ||
| 2376 | b = BN_new(); | ||
| 2377 | c = BN_new(); | ||
| 2378 | |||
| 2379 | CHECK_GOTO(BN_bntest_rand(a, 200, 0, 0)); | ||
| 2380 | a->neg = rand_neg(); | ||
| 2381 | for (i = 0; i < num0; i++) { | ||
| 2382 | CHECK_GOTO(BN_rshift1(b, a)); | ||
| 2383 | if (bp != NULL) { | ||
| 2384 | if (!results) { | ||
| 2385 | CHECK_GOTO(BN_print(bp, a)); | ||
| 2386 | BIO_puts(bp, " / 2"); | ||
| 2387 | BIO_puts(bp, " - "); | ||
| 2388 | } | ||
| 2389 | CHECK_GOTO(BN_print(bp, b)); | ||
| 2390 | BIO_puts(bp, "\n"); | ||
| 2391 | } | ||
| 2392 | CHECK_GOTO(BN_sub(c, a, b)); | ||
| 2393 | CHECK_GOTO(BN_sub(c, c, b)); | ||
| 2394 | if (!BN_is_zero(c) && !BN_abs_is_word(c, 1)) { | ||
| 2395 | fprintf(stderr, "Right shift one test failed!\n"); | ||
| 2396 | rc = 0; | ||
| 2397 | break; | ||
| 2398 | } | ||
| 2399 | CHECK_GOTO(BN_copy(a, b)); | ||
| 2400 | } | ||
| 2401 | err: | ||
| 2402 | BN_free(a); | ||
| 2403 | BN_free(b); | ||
| 2404 | BN_free(c); | ||
| 2405 | return (rc); | ||
| 2406 | } | ||
| 2407 | |||
| 2408 | int | ||
| 2409 | rand_neg(void) | ||
| 2410 | { | ||
| 2411 | static unsigned int neg = 0; | ||
| 2412 | static int sign[8] = { 0, 0, 0, 1, 1, 0, 1, 1 }; | ||
| 2413 | |||
| 2414 | return (sign[(neg++) % 8]); | ||
| 2415 | } | ||
| 2416 | |||
| 2417 | int | ||
| 2418 | test_mod_exp_sizes(BIO *bp, BN_CTX *ctx) | ||
| 2419 | { | ||
| 2420 | BN_MONT_CTX *mont_ctx = NULL; | ||
| 2421 | BIGNUM *p, *x, *y, *r, *r2; | ||
| 2422 | int size; | ||
| 2423 | int rc = 0; | ||
| 2424 | |||
| 2425 | BN_CTX_start(ctx); | ||
| 2426 | CHECK_GOTO(p = BN_CTX_get(ctx)); | ||
| 2427 | CHECK_GOTO(x = BN_CTX_get(ctx)); | ||
| 2428 | CHECK_GOTO(y = BN_CTX_get(ctx)); | ||
| 2429 | CHECK_GOTO(r = BN_CTX_get(ctx)); | ||
| 2430 | CHECK_GOTO(r2 = BN_CTX_get(ctx)); | ||
| 2431 | mont_ctx = BN_MONT_CTX_new(); | ||
| 2432 | |||
| 2433 | if (r2 == NULL || mont_ctx == NULL) | ||
| 2434 | goto err; | ||
| 2435 | |||
| 2436 | if (!BN_generate_prime_ex(p, 32, 0, NULL, NULL, NULL) || | ||
| 2437 | !BN_MONT_CTX_set(mont_ctx, p, ctx)) | ||
| 2438 | goto err; | ||
| 2439 | |||
| 2440 | for (size = 32; size < 1024; size += 8) { | ||
| 2441 | if (!BN_rand(x, size, -1, 0) || | ||
| 2442 | !BN_rand(y, size, -1, 0) || | ||
| 2443 | !BN_mod_exp_mont_consttime(r, x, y, p, ctx, mont_ctx) || | ||
| 2444 | !BN_mod_exp(r2, x, y, p, ctx)) | ||
| 2445 | goto err; | ||
| 2446 | |||
| 2447 | if (BN_cmp(r, r2) != 0) { | ||
| 2448 | char *r_str = NULL; | ||
| 2449 | char *r2_str = NULL; | ||
| 2450 | CHECK_GOTO(r_str = BN_bn2hex(r)); | ||
| 2451 | CHECK_GOTO(r2_str = BN_bn2hex(r2)); | ||
| 2452 | |||
| 2453 | printf("Incorrect answer at size %d: %s vs %s\n", | ||
| 2454 | size, r_str, r2_str); | ||
| 2455 | free(r_str); | ||
| 2456 | free(r2_str); | ||
| 2457 | goto err; | ||
| 2458 | } | ||
| 2459 | } | ||
| 2460 | |||
| 2461 | rc = 1; | ||
| 2462 | |||
| 2463 | err: | ||
| 2464 | BN_MONT_CTX_free(mont_ctx); | ||
| 2465 | BN_CTX_end(ctx); | ||
| 2466 | return rc; | ||
| 2467 | } | ||
diff --git a/src/regress/lib/libcrypto/bn/mont/Makefile b/src/regress/lib/libcrypto/bn/mont/Makefile deleted file mode 100644 index 55c48220d4..0000000000 --- a/src/regress/lib/libcrypto/bn/mont/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2017/01/21 09:38:58 beck 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 deleted file mode 100644 index 30d5317b64..0000000000 --- a/src/regress/lib/libcrypto/bn/mont/mont.c +++ /dev/null | |||
| @@ -1,73 +0,0 @@ | |||
| 1 | /* $OpenBSD: mont.c,v 1.2 2014/10/22 13:23:05 jsing 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 | |||
| 29 | /* | ||
| 30 | * Test for proper bn_mul_mont behaviour when operands are of vastly different | ||
| 31 | * sizes. | ||
| 32 | */ | ||
| 33 | |||
| 34 | int | ||
| 35 | main(int argc, char *argv[]) | ||
| 36 | { | ||
| 37 | DH *dh; | ||
| 38 | unsigned char *key, r[32 + 16 * 8]; | ||
| 39 | size_t privsz; | ||
| 40 | |||
| 41 | arc4random_buf(r, sizeof(r)); | ||
| 42 | |||
| 43 | for (privsz = 32; privsz <= sizeof(r); privsz += 8) { | ||
| 44 | dh = DH_new(); | ||
| 45 | if (dh == NULL) | ||
| 46 | goto err; | ||
| 47 | if (DH_generate_parameters_ex(dh, 32, DH_GENERATOR_2, | ||
| 48 | NULL) == 0) | ||
| 49 | goto err; | ||
| 50 | |||
| 51 | /* force private key to be much larger than public one */ | ||
| 52 | dh->priv_key = BN_bin2bn(r, privsz, NULL); | ||
| 53 | if (dh->priv_key == NULL) | ||
| 54 | goto err; | ||
| 55 | |||
| 56 | if (DH_generate_key(dh) == 0) | ||
| 57 | goto err; | ||
| 58 | key = malloc(DH_size(dh)); | ||
| 59 | if (key == NULL) | ||
| 60 | err(1, "malloc"); | ||
| 61 | if (DH_compute_key(key, dh->pub_key, dh) == -1) | ||
| 62 | goto err; | ||
| 63 | |||
| 64 | free(key); | ||
| 65 | DH_free(dh); | ||
| 66 | } | ||
| 67 | |||
| 68 | return 0; | ||
| 69 | |||
| 70 | err: | ||
| 71 | ERR_print_errors_fp(stderr); | ||
| 72 | return 1; | ||
| 73 | } | ||
diff --git a/src/regress/lib/libcrypto/bn/rand/Makefile b/src/regress/lib/libcrypto/bn/rand/Makefile deleted file mode 100644 index 52d0835df4..0000000000 --- a/src/regress/lib/libcrypto/bn/rand/Makefile +++ /dev/null | |||
| @@ -1,11 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2018/11/06 06:55:27 tb Exp $ | ||
| 2 | |||
| 3 | .include "../../Makefile.inc" | ||
| 4 | |||
| 5 | PROG= bn_rand_interval | ||
| 6 | LDADD= ${CRYPTO_INT} | ||
| 7 | DPADD= ${LIBCRYPTO} | ||
| 8 | WARNINGS= Yes | ||
| 9 | CFLAGS+= -Werror | ||
| 10 | |||
| 11 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c b/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c deleted file mode 100644 index 09b1a34eea..0000000000 --- a/src/regress/lib/libcrypto/bn/rand/bn_rand_interval.c +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | /* $OpenBSD: bn_rand_interval.c,v 1.2 2018/11/06 13:17:42 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | #include <openssl/bn.h> | ||
| 22 | |||
| 23 | #define NUM_TESTS 1000000 | ||
| 24 | |||
| 25 | int bn_rand_interval(BIGNUM *rnd, const BIGNUM *lower_incl, | ||
| 26 | const BIGNUM *upper_excl); | ||
| 27 | void print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x); | ||
| 28 | |||
| 29 | void | ||
| 30 | print_triple(BIGNUM *a, BIGNUM *b, BIGNUM *x) { | ||
| 31 | if (a != NULL) { | ||
| 32 | printf("a = "); | ||
| 33 | BN_print_fp(stdout, a); | ||
| 34 | printf("\n"); | ||
| 35 | } | ||
| 36 | |||
| 37 | if (b != NULL) { | ||
| 38 | printf("b = "); | ||
| 39 | BN_print_fp(stdout, b); | ||
| 40 | printf("\n"); | ||
| 41 | } | ||
| 42 | |||
| 43 | if (x != NULL) { | ||
| 44 | printf("x = "); | ||
| 45 | BN_print_fp(stdout, x); | ||
| 46 | printf("\n"); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | int | ||
| 51 | main(int argc, char *argv[]) | ||
| 52 | { | ||
| 53 | BIGNUM *a, *b, *x; | ||
| 54 | int i, success = 1; | ||
| 55 | |||
| 56 | if ((a = BN_new()) == NULL) | ||
| 57 | err(1, "BN_hex2bn"); | ||
| 58 | if ((b = BN_new()) == NULL) | ||
| 59 | err(1, "BN_hex2bn"); | ||
| 60 | if ((x = BN_new()) == NULL) | ||
| 61 | err(1, "BN_new()"); | ||
| 62 | |||
| 63 | for (i = 0; i < NUM_TESTS; i++) { | ||
| 64 | if (!BN_rand(a, 256, 0, 0)) | ||
| 65 | err(1, "BN_rand(a)"); | ||
| 66 | |||
| 67 | if (bn_rand_interval(x, a, a) != 0) { | ||
| 68 | success = 0; | ||
| 69 | |||
| 70 | printf("bn_rand_interval(a == a) succeeded\n"); | ||
| 71 | print_triple(a, NULL, x); | ||
| 72 | } | ||
| 73 | |||
| 74 | if (!BN_rand(b, 256, 0, 0)) | ||
| 75 | err(1, "BN_rand(b)"); | ||
| 76 | |||
| 77 | switch(BN_cmp(a, b)) { | ||
| 78 | case 0: /* a == b */ | ||
| 79 | continue; | ||
| 80 | |||
| 81 | case 1: /* a > b */ | ||
| 82 | BN_swap(a, b); | ||
| 83 | break; | ||
| 84 | |||
| 85 | default: /* a < b */ | ||
| 86 | break; | ||
| 87 | } | ||
| 88 | |||
| 89 | if (!bn_rand_interval(x, a, b)) | ||
| 90 | err(1, "bn_rand_interval() failed"); | ||
| 91 | |||
| 92 | if (BN_cmp(x, a) < 0 || BN_cmp(x, b) >= 0) { | ||
| 93 | success = 0; | ||
| 94 | |||
| 95 | printf("generated number x not inside [a,b)\n"); | ||
| 96 | print_triple(a, b, x); | ||
| 97 | } | ||
| 98 | |||
| 99 | if (bn_rand_interval(x, b, a) != 0) { | ||
| 100 | success = 0; | ||
| 101 | |||
| 102 | printf("bn_rand_interval(x, b, a) succeeded\n"); | ||
| 103 | print_triple(a, b, x); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | if (success == 1) | ||
| 108 | printf("success\n"); | ||
| 109 | else | ||
| 110 | printf("FAIL"); | ||
| 111 | |||
| 112 | return 1 - success; | ||
| 113 | } | ||
diff --git a/src/regress/lib/libcrypto/cast/Makefile b/src/regress/lib/libcrypto/cast/Makefile deleted file mode 100644 index cdb7da5312..0000000000 --- a/src/regress/lib/libcrypto/cast/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= casttest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/cast/casttest.c b/src/regress/lib/libcrypto/cast/casttest.c deleted file mode 100644 index 81b878ee7f..0000000000 --- a/src/regress/lib/libcrypto/cast/casttest.c +++ /dev/null | |||
| @@ -1,222 +0,0 @@ | |||
| 1 | /* $OpenBSD: casttest.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | #include <openssl/opensslconf.h> /* To see if OPENSSL_NO_CAST is defined */ | ||
| 63 | |||
| 64 | #include <openssl/cast.h> | ||
| 65 | |||
| 66 | #define FULL_TEST | ||
| 67 | |||
| 68 | static unsigned char k[16]={ | ||
| 69 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
| 70 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A | ||
| 71 | }; | ||
| 72 | |||
| 73 | static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; | ||
| 74 | |||
| 75 | static int k_len[3]={16,10,5}; | ||
| 76 | static unsigned char c[3][8]={ | ||
| 77 | {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, | ||
| 78 | {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, | ||
| 79 | {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E}, | ||
| 80 | }; | ||
| 81 | static unsigned char out[80]; | ||
| 82 | |||
| 83 | static unsigned char in_a[16]={ | ||
| 84 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
| 85 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; | ||
| 86 | static unsigned char in_b[16]={ | ||
| 87 | 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, | ||
| 88 | 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A}; | ||
| 89 | |||
| 90 | static unsigned char c_a[16]={ | ||
| 91 | 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6, | ||
| 92 | 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92}; | ||
| 93 | static unsigned char c_b[16]={ | ||
| 94 | 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71, | ||
| 95 | 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E}; | ||
| 96 | |||
| 97 | #if 0 | ||
| 98 | char *text="Hello to all people out there"; | ||
| 99 | |||
| 100 | static unsigned char cfb_key[16]={ | ||
| 101 | 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, | ||
| 102 | 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, | ||
| 103 | }; | ||
| 104 | static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; | ||
| 105 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
| 106 | #define CFB_TEST_SIZE 24 | ||
| 107 | static unsigned char plain[CFB_TEST_SIZE]= | ||
| 108 | { | ||
| 109 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
| 110 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
| 111 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
| 112 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
| 113 | }; | ||
| 114 | static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ | ||
| 115 | 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, | ||
| 116 | 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, | ||
| 117 | 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 | ||
| 118 | |||
| 119 | /* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, | ||
| 120 | 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, | ||
| 121 | 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ | ||
| 122 | }; | ||
| 123 | #endif | ||
| 124 | |||
| 125 | int main(int argc, char *argv[]) | ||
| 126 | { | ||
| 127 | #ifdef FULL_TEST | ||
| 128 | long l; | ||
| 129 | CAST_KEY key_b; | ||
| 130 | #endif | ||
| 131 | int i,z,err=0; | ||
| 132 | CAST_KEY key; | ||
| 133 | |||
| 134 | for (z=0; z<3; z++) | ||
| 135 | { | ||
| 136 | CAST_set_key(&key,k_len[z],k); | ||
| 137 | |||
| 138 | CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); | ||
| 139 | if (memcmp(out,&(c[z][0]),8) != 0) | ||
| 140 | { | ||
| 141 | printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8); | ||
| 142 | printf("got :"); | ||
| 143 | for (i=0; i<8; i++) | ||
| 144 | printf("%02X ",out[i]); | ||
| 145 | printf("\n"); | ||
| 146 | printf("expected:"); | ||
| 147 | for (i=0; i<8; i++) | ||
| 148 | printf("%02X ",c[z][i]); | ||
| 149 | err=20; | ||
| 150 | printf("\n"); | ||
| 151 | } | ||
| 152 | |||
| 153 | CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); | ||
| 154 | if (memcmp(out,in,8) != 0) | ||
| 155 | { | ||
| 156 | printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8); | ||
| 157 | printf("got :"); | ||
| 158 | for (i=0; i<8; i++) | ||
| 159 | printf("%02X ",out[i]); | ||
| 160 | printf("\n"); | ||
| 161 | printf("expected:"); | ||
| 162 | for (i=0; i<8; i++) | ||
| 163 | printf("%02X ",in[i]); | ||
| 164 | printf("\n"); | ||
| 165 | err=3; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | if (err == 0) | ||
| 169 | printf("ecb cast5 ok\n"); | ||
| 170 | |||
| 171 | #ifdef FULL_TEST | ||
| 172 | { | ||
| 173 | unsigned char out_a[16],out_b[16]; | ||
| 174 | static char *hex="0123456789ABCDEF"; | ||
| 175 | |||
| 176 | printf("This test will take some time...."); | ||
| 177 | fflush(stdout); | ||
| 178 | memcpy(out_a,in_a,sizeof(in_a)); | ||
| 179 | memcpy(out_b,in_b,sizeof(in_b)); | ||
| 180 | i=1; | ||
| 181 | |||
| 182 | for (l=0; l<1000000L; l++) | ||
| 183 | { | ||
| 184 | CAST_set_key(&key_b,16,out_b); | ||
| 185 | CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); | ||
| 186 | CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); | ||
| 187 | CAST_set_key(&key,16,out_a); | ||
| 188 | CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); | ||
| 189 | CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); | ||
| 190 | if ((l & 0xffff) == 0xffff) | ||
| 191 | { | ||
| 192 | printf("%c",hex[i&0x0f]); | ||
| 193 | fflush(stdout); | ||
| 194 | i++; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || | ||
| 199 | (memcmp(out_b,c_b,sizeof(c_b)) != 0)) | ||
| 200 | { | ||
| 201 | printf("\n"); | ||
| 202 | printf("Error\n"); | ||
| 203 | |||
| 204 | printf("A out ="); | ||
| 205 | for (i=0; i<16; i++) printf("%02X ",out_a[i]); | ||
| 206 | printf("\nactual="); | ||
| 207 | for (i=0; i<16; i++) printf("%02X ",c_a[i]); | ||
| 208 | printf("\n"); | ||
| 209 | |||
| 210 | printf("B out ="); | ||
| 211 | for (i=0; i<16; i++) printf("%02X ",out_b[i]); | ||
| 212 | printf("\nactual="); | ||
| 213 | for (i=0; i<16; i++) printf("%02X ",c_b[i]); | ||
| 214 | printf("\n"); | ||
| 215 | } | ||
| 216 | else | ||
| 217 | printf(" ok\n"); | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | |||
| 221 | exit(err); | ||
| 222 | } | ||
diff --git a/src/regress/lib/libcrypto/chacha/Makefile b/src/regress/lib/libcrypto/chacha/Makefile deleted file mode 100644 index 685cbdbab1..0000000000 --- a/src/regress/lib/libcrypto/chacha/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= chachatest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/chacha/chachatest.c b/src/regress/lib/libcrypto/chacha/chachatest.c deleted file mode 100644 index fe4cc40952..0000000000 --- a/src/regress/lib/libcrypto/chacha/chachatest.c +++ /dev/null | |||
| @@ -1,339 +0,0 @@ | |||
| 1 | /* $OpenBSD: chachatest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | #include <openssl/chacha.h> | ||
| 24 | |||
| 25 | struct chacha_tv { | ||
| 26 | const char *desc; | ||
| 27 | const unsigned char key[32]; | ||
| 28 | const unsigned char iv[8]; | ||
| 29 | const size_t len; | ||
| 30 | const unsigned char out[512]; | ||
| 31 | }; | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Test vectors from: | ||
| 35 | * http://tools.ietf.org/html/draft-strombergson-chacha-test-vectors-01 | ||
| 36 | */ | ||
| 37 | struct chacha_tv chacha_test_vectors[] = { | ||
| 38 | { | ||
| 39 | "TC1: All zero key and IV", | ||
| 40 | { | ||
| 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 48 | }, | ||
| 49 | 64, | ||
| 50 | { | ||
| 51 | 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, | ||
| 52 | 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, | ||
| 53 | 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, | ||
| 54 | 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, | ||
| 55 | 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, | ||
| 56 | 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, | ||
| 57 | 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, | ||
| 58 | 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, | ||
| 59 | }, | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | "TC2: Single bit in key set, all zero IV", | ||
| 63 | { | ||
| 64 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 65 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 66 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 67 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 68 | }, | ||
| 69 | { | ||
| 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 71 | }, | ||
| 72 | 64, | ||
| 73 | { | ||
| 74 | 0xc5, 0xd3, 0x0a, 0x7c, 0xe1, 0xec, 0x11, 0x93, | ||
| 75 | 0x78, 0xc8, 0x4f, 0x48, 0x7d, 0x77, 0x5a, 0x85, | ||
| 76 | 0x42, 0xf1, 0x3e, 0xce, 0x23, 0x8a, 0x94, 0x55, | ||
| 77 | 0xe8, 0x22, 0x9e, 0x88, 0x8d, 0xe8, 0x5b, 0xbd, | ||
| 78 | 0x29, 0xeb, 0x63, 0xd0, 0xa1, 0x7a, 0x5b, 0x99, | ||
| 79 | 0x9b, 0x52, 0xda, 0x22, 0xbe, 0x40, 0x23, 0xeb, | ||
| 80 | 0x07, 0x62, 0x0a, 0x54, 0xf6, 0xfa, 0x6a, 0xd8, | ||
| 81 | 0x73, 0x7b, 0x71, 0xeb, 0x04, 0x64, 0xda, 0xc0, | ||
| 82 | }, | ||
| 83 | }, | ||
| 84 | { | ||
| 85 | "TC3: Single bit in IV set, all zero key", | ||
| 86 | { | ||
| 87 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 88 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 89 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 90 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 94 | }, | ||
| 95 | 64, | ||
| 96 | { | ||
| 97 | 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, | ||
| 98 | 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, | ||
| 99 | 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, | ||
| 100 | 0x33, 0x96, 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, | ||
| 101 | 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, 0x3c, | ||
| 102 | 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, | ||
| 103 | 0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d, | ||
| 104 | 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b | ||
| 105 | }, | ||
| 106 | }, | ||
| 107 | { | ||
| 108 | "TC4: All bits in key and IV are set", | ||
| 109 | { | ||
| 110 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 111 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 112 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 113 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 114 | }, | ||
| 115 | { | ||
| 116 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 117 | }, | ||
| 118 | 64, | ||
| 119 | { | ||
| 120 | 0xd9, 0xbf, 0x3f, 0x6b, 0xce, 0x6e, 0xd0, 0xb5, | ||
| 121 | 0x42, 0x54, 0x55, 0x77, 0x67, 0xfb, 0x57, 0x44, | ||
| 122 | 0x3d, 0xd4, 0x77, 0x89, 0x11, 0xb6, 0x06, 0x05, | ||
| 123 | 0x5c, 0x39, 0xcc, 0x25, 0xe6, 0x74, 0xb8, 0x36, | ||
| 124 | 0x3f, 0xea, 0xbc, 0x57, 0xfd, 0xe5, 0x4f, 0x79, | ||
| 125 | 0x0c, 0x52, 0xc8, 0xae, 0x43, 0x24, 0x0b, 0x79, | ||
| 126 | 0xd4, 0x90, 0x42, 0xb7, 0x77, 0xbf, 0xd6, 0xcb, | ||
| 127 | 0x80, 0xe9, 0x31, 0x27, 0x0b, 0x7f, 0x50, 0xeb, | ||
| 128 | }, | ||
| 129 | }, | ||
| 130 | { | ||
| 131 | "TC5: Every even bit set in key and IV", | ||
| 132 | { | ||
| 133 | 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, | ||
| 134 | 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, | ||
| 135 | 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, | ||
| 136 | 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, | ||
| 137 | }, | ||
| 138 | { | ||
| 139 | 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, | ||
| 140 | }, | ||
| 141 | 64, | ||
| 142 | { | ||
| 143 | 0xbe, 0xa9, 0x41, 0x1a, 0xa4, 0x53, 0xc5, 0x43, | ||
| 144 | 0x4a, 0x5a, 0xe8, 0xc9, 0x28, 0x62, 0xf5, 0x64, | ||
| 145 | 0x39, 0x68, 0x55, 0xa9, 0xea, 0x6e, 0x22, 0xd6, | ||
| 146 | 0xd3, 0xb5, 0x0a, 0xe1, 0xb3, 0x66, 0x33, 0x11, | ||
| 147 | 0xa4, 0xa3, 0x60, 0x6c, 0x67, 0x1d, 0x60, 0x5c, | ||
| 148 | 0xe1, 0x6c, 0x3a, 0xec, 0xe8, 0xe6, 0x1e, 0xa1, | ||
| 149 | 0x45, 0xc5, 0x97, 0x75, 0x01, 0x7b, 0xee, 0x2f, | ||
| 150 | 0xa6, 0xf8, 0x8a, 0xfc, 0x75, 0x80, 0x69, 0xf7, | ||
| 151 | }, | ||
| 152 | }, | ||
| 153 | { | ||
| 154 | "TC6: Every odd bit set in key and IV", | ||
| 155 | { | ||
| 156 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 157 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 158 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 159 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 160 | }, | ||
| 161 | { | ||
| 162 | 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, | ||
| 163 | }, | ||
| 164 | 64, | ||
| 165 | { | ||
| 166 | 0x9a, 0xa2, 0xa9, 0xf6, 0x56, 0xef, 0xde, 0x5a, | ||
| 167 | 0xa7, 0x59, 0x1c, 0x5f, 0xed, 0x4b, 0x35, 0xae, | ||
| 168 | 0xa2, 0x89, 0x5d, 0xec, 0x7c, 0xb4, 0x54, 0x3b, | ||
| 169 | 0x9e, 0x9f, 0x21, 0xf5, 0xe7, 0xbc, 0xbc, 0xf3, | ||
| 170 | 0xc4, 0x3c, 0x74, 0x8a, 0x97, 0x08, 0x88, 0xf8, | ||
| 171 | 0x24, 0x83, 0x93, 0xa0, 0x9d, 0x43, 0xe0, 0xb7, | ||
| 172 | 0xe1, 0x64, 0xbc, 0x4d, 0x0b, 0x0f, 0xb2, 0x40, | ||
| 173 | 0xa2, 0xd7, 0x21, 0x15, 0xc4, 0x80, 0x89, 0x06, | ||
| 174 | }, | ||
| 175 | }, | ||
| 176 | { | ||
| 177 | "TC7: Sequence patterns in key and IV", | ||
| 178 | { | ||
| 179 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 180 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 181 | 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, | ||
| 182 | 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, | ||
| 183 | }, | ||
| 184 | { | ||
| 185 | 0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69, 0x78, | ||
| 186 | }, | ||
| 187 | 64, | ||
| 188 | { | ||
| 189 | 0x9f, 0xad, 0xf4, 0x09, 0xc0, 0x08, 0x11, 0xd0, | ||
| 190 | 0x04, 0x31, 0xd6, 0x7e, 0xfb, 0xd8, 0x8f, 0xba, | ||
| 191 | 0x59, 0x21, 0x8d, 0x5d, 0x67, 0x08, 0xb1, 0xd6, | ||
| 192 | 0x85, 0x86, 0x3f, 0xab, 0xbb, 0x0e, 0x96, 0x1e, | ||
| 193 | 0xea, 0x48, 0x0f, 0xd6, 0xfb, 0x53, 0x2b, 0xfd, | ||
| 194 | 0x49, 0x4b, 0x21, 0x51, 0x01, 0x50, 0x57, 0x42, | ||
| 195 | 0x3a, 0xb6, 0x0a, 0x63, 0xfe, 0x4f, 0x55, 0xf7, | ||
| 196 | 0xa2, 0x12, 0xe2, 0x16, 0x7c, 0xca, 0xb9, 0x31, | ||
| 197 | }, | ||
| 198 | }, | ||
| 199 | { | ||
| 200 | "TC8: key: 'All your base are belong to us!, IV: 'IETF2013'", | ||
| 201 | { | ||
| 202 | 0xc4, 0x6e, 0xc1, 0xb1, 0x8c, 0xe8, 0xa8, 0x78, | ||
| 203 | 0x72, 0x5a, 0x37, 0xe7, 0x80, 0xdf, 0xb7, 0x35, | ||
| 204 | 0x1f, 0x68, 0xed, 0x2e, 0x19, 0x4c, 0x79, 0xfb, | ||
| 205 | 0xc6, 0xae, 0xbe, 0xe1, 0xa6, 0x67, 0x97, 0x5d, | ||
| 206 | }, | ||
| 207 | { | ||
| 208 | 0x1a, 0xda, 0x31, 0xd5, 0xcf, 0x68, 0x82, 0x21, | ||
| 209 | }, | ||
| 210 | 64, | ||
| 211 | { | ||
| 212 | 0xf6, 0x3a, 0x89, 0xb7, 0x5c, 0x22, 0x71, 0xf9, | ||
| 213 | 0x36, 0x88, 0x16, 0x54, 0x2b, 0xa5, 0x2f, 0x06, | ||
| 214 | 0xed, 0x49, 0x24, 0x17, 0x92, 0x30, 0x2b, 0x00, | ||
| 215 | 0xb5, 0xe8, 0xf8, 0x0a, 0xe9, 0xa4, 0x73, 0xaf, | ||
| 216 | 0xc2, 0x5b, 0x21, 0x8f, 0x51, 0x9a, 0xf0, 0xfd, | ||
| 217 | 0xd4, 0x06, 0x36, 0x2e, 0x8d, 0x69, 0xde, 0x7f, | ||
| 218 | 0x54, 0xc6, 0x04, 0xa6, 0xe0, 0x0f, 0x35, 0x3f, | ||
| 219 | 0x11, 0x0f, 0x77, 0x1b, 0xdc, 0xa8, 0xab, 0x92, | ||
| 220 | }, | ||
| 221 | }, | ||
| 222 | }; | ||
| 223 | |||
| 224 | #define N_VECTORS (sizeof(chacha_test_vectors) / sizeof(*chacha_test_vectors)) | ||
| 225 | |||
| 226 | /* Single-shot ChaCha20 using CRYPTO_chacha_20 interface. */ | ||
| 227 | static void | ||
| 228 | crypto_chacha_20_test(struct chacha_tv *tv, unsigned char *out, | ||
| 229 | unsigned char *in) | ||
| 230 | { | ||
| 231 | CRYPTO_chacha_20(out, in, tv->len, tv->key, tv->iv, 0); | ||
| 232 | } | ||
| 233 | |||
| 234 | /* Single-shot ChaCha20 using the ChaCha interface. */ | ||
| 235 | static void | ||
| 236 | chacha_ctx_full_test(struct chacha_tv *tv, unsigned char *out, | ||
| 237 | unsigned char *in) | ||
| 238 | { | ||
| 239 | ChaCha_ctx ctx; | ||
| 240 | |||
| 241 | ChaCha_set_key(&ctx, tv->key, 256); | ||
| 242 | ChaCha_set_iv(&ctx, tv->iv, NULL); | ||
| 243 | ChaCha(&ctx, out, in, tv->len); | ||
| 244 | } | ||
| 245 | |||
| 246 | /* ChaCha20 with partial writes using the Chacha interface. */ | ||
| 247 | static void | ||
| 248 | chacha_ctx_partial_test(struct chacha_tv *tv, unsigned char *out, | ||
| 249 | unsigned char *in) | ||
| 250 | { | ||
| 251 | ChaCha_ctx ctx; | ||
| 252 | int len, size = 0; | ||
| 253 | |||
| 254 | ChaCha_set_key(&ctx, tv->key, 256); | ||
| 255 | ChaCha_set_iv(&ctx, tv->iv, NULL); | ||
| 256 | len = tv->len - 1; | ||
| 257 | while (len > 1) { | ||
| 258 | size = len / 2; | ||
| 259 | ChaCha(&ctx, out, in, size); | ||
| 260 | in += size; | ||
| 261 | out += size; | ||
| 262 | len -= size; | ||
| 263 | } | ||
| 264 | ChaCha(&ctx, out, in, len + 1); | ||
| 265 | } | ||
| 266 | |||
| 267 | /* ChaCha20 with single byte writes using the Chacha interface. */ | ||
| 268 | static void | ||
| 269 | chacha_ctx_single_test(struct chacha_tv *tv, unsigned char *out, | ||
| 270 | unsigned char *in) | ||
| 271 | { | ||
| 272 | ChaCha_ctx ctx; | ||
| 273 | size_t i; | ||
| 274 | |||
| 275 | ChaCha_set_key(&ctx, tv->key, 256); | ||
| 276 | ChaCha_set_iv(&ctx, tv->iv, NULL); | ||
| 277 | for (i = 0; i < tv->len; i++) | ||
| 278 | ChaCha(&ctx, out + i, in + i, 1); | ||
| 279 | } | ||
| 280 | |||
| 281 | struct chacha_test_function { | ||
| 282 | char *name; | ||
| 283 | void (*func)(struct chacha_tv *, unsigned char *, unsigned char *); | ||
| 284 | }; | ||
| 285 | |||
| 286 | struct chacha_test_function chacha_test_functions[] = { | ||
| 287 | {"crypto_chacha_20_test", crypto_chacha_20_test}, | ||
| 288 | {"chacha_ctx_full_test", chacha_ctx_full_test}, | ||
| 289 | {"chacha_ctx_partial_test", chacha_ctx_partial_test}, | ||
| 290 | {"chacha_ctx_single_test", chacha_ctx_single_test}, | ||
| 291 | }; | ||
| 292 | |||
| 293 | #define N_FUNCS (sizeof(chacha_test_functions) / sizeof(*chacha_test_functions)) | ||
| 294 | |||
| 295 | int | ||
| 296 | main(int argc, char **argv) | ||
| 297 | { | ||
| 298 | struct chacha_tv *tv; | ||
| 299 | unsigned char *in, *out; | ||
| 300 | size_t i, j, k; | ||
| 301 | int failed = 0; | ||
| 302 | |||
| 303 | for (i = 0; i < N_VECTORS; i++) { | ||
| 304 | tv = &chacha_test_vectors[i]; | ||
| 305 | |||
| 306 | for (j = 0; j < N_FUNCS; j++) { | ||
| 307 | in = calloc(1, tv->len); | ||
| 308 | if (in == NULL) | ||
| 309 | errx(1, "calloc in"); | ||
| 310 | out = calloc(1, tv->len); | ||
| 311 | if (out == NULL) | ||
| 312 | errx(1, "calloc out"); | ||
| 313 | |||
| 314 | chacha_test_functions[j].func(tv, out, in); | ||
| 315 | |||
| 316 | if (memcmp(out, tv->out, tv->len) != 0) { | ||
| 317 | printf("ChaCha %s failed for \"%s\"!\n", | ||
| 318 | chacha_test_functions[j].name, tv->desc); | ||
| 319 | |||
| 320 | printf("Got:\t"); | ||
| 321 | for (k = 0; k < tv->len; k++) | ||
| 322 | printf("%2.2x", out[k]); | ||
| 323 | printf("\n"); | ||
| 324 | |||
| 325 | printf("Want:\t"); | ||
| 326 | for (k = 0; k < tv->len; k++) | ||
| 327 | printf("%2.2x", tv->out[k]); | ||
| 328 | printf("\n"); | ||
| 329 | |||
| 330 | failed = 1; | ||
| 331 | } | ||
| 332 | |||
| 333 | free(in); | ||
| 334 | free(out); | ||
| 335 | } | ||
| 336 | } | ||
| 337 | |||
| 338 | return failed; | ||
| 339 | } | ||
diff --git a/src/regress/lib/libcrypto/cts128/Makefile b/src/regress/lib/libcrypto/cts128/Makefile deleted file mode 100644 index 801d1d7182..0000000000 --- a/src/regress/lib/libcrypto/cts128/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= cts128test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/cts128/cts128test.c b/src/regress/lib/libcrypto/cts128/cts128test.c deleted file mode 100644 index ca60808718..0000000000 --- a/src/regress/lib/libcrypto/cts128/cts128test.c +++ /dev/null | |||
| @@ -1,170 +0,0 @@ | |||
| 1 | /* $OpenBSD: cts128test.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Rights for redistribution and usage in source and binary | ||
| 6 | * forms are granted according to the OpenSSL license. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <stdio.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | #include <openssl/aes.h> | ||
| 14 | #include <openssl/modes.h> | ||
| 15 | |||
| 16 | void test_vector(const unsigned char *vector,size_t len); | ||
| 17 | void test_nistvector(const unsigned char *vector,size_t len); | ||
| 18 | |||
| 19 | /* test vectors from RFC 3962 */ | ||
| 20 | static const unsigned char test_key[16] = "chicken teriyaki"; | ||
| 21 | static const unsigned char test_input[64] = | ||
| 22 | "I would like the" " General Gau's C" | ||
| 23 | "hicken, please, " "and wonton soup."; | ||
| 24 | static const unsigned char test_iv[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | ||
| 25 | |||
| 26 | static const unsigned char vector_17[17] = | ||
| 27 | {0xc6,0x35,0x35,0x68,0xf2,0xbf,0x8c,0xb4, 0xd8,0xa5,0x80,0x36,0x2d,0xa7,0xff,0x7f, | ||
| 28 | 0x97}; | ||
| 29 | static const unsigned char vector_31[31] = | ||
| 30 | {0xfc,0x00,0x78,0x3e,0x0e,0xfd,0xb2,0xc1, 0xd4,0x45,0xd4,0xc8,0xef,0xf7,0xed,0x22, | ||
| 31 | 0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5}; | ||
| 32 | static const unsigned char vector_32[32] = | ||
| 33 | {0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8, | ||
| 34 | 0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84}; | ||
| 35 | static const unsigned char vector_47[47] = | ||
| 36 | {0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84, | ||
| 37 | 0xb3,0xff,0xfd,0x94,0x0c,0x16,0xa1,0x8c, 0x1b,0x55,0x49,0xd2,0xf8,0x38,0x02,0x9e, | ||
| 38 | 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5}; | ||
| 39 | static const unsigned char vector_48[48] = | ||
| 40 | {0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84, | ||
| 41 | 0x9d,0xad,0x8b,0xbb,0x96,0xc4,0xcd,0xc0, 0x3b,0xc1,0x03,0xe1,0xa1,0x94,0xbb,0xd8, | ||
| 42 | 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8}; | ||
| 43 | static const unsigned char vector_64[64] = | ||
| 44 | {0x97,0x68,0x72,0x68,0xd6,0xec,0xcc,0xc0, 0xc0,0x7b,0x25,0xe2,0x5e,0xcf,0xe5,0x84, | ||
| 45 | 0x39,0x31,0x25,0x23,0xa7,0x86,0x62,0xd5, 0xbe,0x7f,0xcb,0xcc,0x98,0xeb,0xf5,0xa8, | ||
| 46 | 0x48,0x07,0xef,0xe8,0x36,0xee,0x89,0xa5, 0x26,0x73,0x0d,0xbc,0x2f,0x7b,0xc8,0x40, | ||
| 47 | 0x9d,0xad,0x8b,0xbb,0x96,0xc4,0xcd,0xc0, 0x3b,0xc1,0x03,0xe1,0xa1,0x94,0xbb,0xd8}; | ||
| 48 | |||
| 49 | static AES_KEY encks, decks; | ||
| 50 | |||
| 51 | void | ||
| 52 | test_vector(const unsigned char *vector,size_t len) | ||
| 53 | { | ||
| 54 | unsigned char iv[sizeof(test_iv)]; | ||
| 55 | unsigned char cleartext[64],ciphertext[64]; | ||
| 56 | size_t tail; | ||
| 57 | |||
| 58 | printf("vector_%zu\n",len); | ||
| 59 | fflush(stdout); | ||
| 60 | |||
| 61 | if ((tail=len%16) == 0) tail = 16; | ||
| 62 | tail += 16; | ||
| 63 | |||
| 64 | /* test block-based encryption */ | ||
| 65 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 66 | CRYPTO_cts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); | ||
| 67 | if (memcmp(ciphertext,vector,len)) | ||
| 68 | fprintf(stderr,"output_%zu mismatch\n",len), exit(1); | ||
| 69 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | ||
| 70 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(1); | ||
| 71 | |||
| 72 | /* test block-based decryption */ | ||
| 73 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 74 | CRYPTO_cts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); | ||
| 75 | if (memcmp(cleartext,test_input,len)) | ||
| 76 | fprintf(stderr,"input_%zu mismatch\n",len), exit(2); | ||
| 77 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | ||
| 78 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(2); | ||
| 79 | |||
| 80 | /* test streamed encryption */ | ||
| 81 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 82 | CRYPTO_cts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); | ||
| 83 | if (memcmp(ciphertext,vector,len)) | ||
| 84 | fprintf(stderr,"output_%zu mismatch\n",len), exit(3); | ||
| 85 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | ||
| 86 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(3); | ||
| 87 | |||
| 88 | /* test streamed decryption */ | ||
| 89 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 90 | CRYPTO_cts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); | ||
| 91 | if (memcmp(cleartext,test_input,len)) | ||
| 92 | fprintf(stderr,"input_%zu mismatch\n",len), exit(4); | ||
| 93 | if (memcmp(iv,vector+len-tail,sizeof(iv))) | ||
| 94 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(4); | ||
| 95 | } | ||
| 96 | |||
| 97 | void | ||
| 98 | test_nistvector(const unsigned char *vector,size_t len) | ||
| 99 | { | ||
| 100 | unsigned char iv[sizeof(test_iv)]; | ||
| 101 | unsigned char cleartext[64],ciphertext[64],nistvector[64]; | ||
| 102 | size_t tail; | ||
| 103 | |||
| 104 | printf("nistvector_%zu\n",len); fflush(stdout); | ||
| 105 | |||
| 106 | if ((tail=len%16) == 0) tail = 16; | ||
| 107 | |||
| 108 | len -= 16 + tail; | ||
| 109 | memcpy(nistvector,vector,len); | ||
| 110 | /* flip two last blocks */ | ||
| 111 | memcpy(nistvector+len,vector+len+16,tail); | ||
| 112 | memcpy(nistvector+len+tail,vector+len,16); | ||
| 113 | len += 16 + tail; | ||
| 114 | tail = 16; | ||
| 115 | |||
| 116 | /* test block-based encryption */ | ||
| 117 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 118 | CRYPTO_nistcts128_encrypt_block(test_input,ciphertext,len,&encks,iv,(block128_f)AES_encrypt); | ||
| 119 | if (memcmp(ciphertext,nistvector,len)) | ||
| 120 | fprintf(stderr,"output_%zu mismatch\n",len), exit(1); | ||
| 121 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | ||
| 122 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(1); | ||
| 123 | |||
| 124 | /* test block-based decryption */ | ||
| 125 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 126 | CRYPTO_nistcts128_decrypt_block(ciphertext,cleartext,len,&decks,iv,(block128_f)AES_decrypt); | ||
| 127 | if (memcmp(cleartext,test_input,len)) | ||
| 128 | fprintf(stderr,"input_%zu mismatch\n",len), exit(2); | ||
| 129 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | ||
| 130 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(2); | ||
| 131 | |||
| 132 | /* test streamed encryption */ | ||
| 133 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 134 | CRYPTO_nistcts128_encrypt(test_input,ciphertext,len,&encks,iv,(cbc128_f)AES_cbc_encrypt); | ||
| 135 | if (memcmp(ciphertext,nistvector,len)) | ||
| 136 | fprintf(stderr,"output_%zu mismatch\n",len), exit(3); | ||
| 137 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | ||
| 138 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(3); | ||
| 139 | |||
| 140 | /* test streamed decryption */ | ||
| 141 | memcpy(iv,test_iv,sizeof(test_iv)); | ||
| 142 | CRYPTO_nistcts128_decrypt(ciphertext,cleartext,len,&decks,iv,(cbc128_f)AES_cbc_encrypt); | ||
| 143 | if (memcmp(cleartext,test_input,len)) | ||
| 144 | fprintf(stderr,"input_%zu mismatch\n",len), exit(4); | ||
| 145 | if (memcmp(iv,nistvector+len-tail,sizeof(iv))) | ||
| 146 | fprintf(stderr,"iv_%zu mismatch\n",len), exit(4); | ||
| 147 | } | ||
| 148 | |||
| 149 | int | ||
| 150 | main(int argc, char *argv[]) | ||
| 151 | { | ||
| 152 | AES_set_encrypt_key(test_key,128,&encks); | ||
| 153 | AES_set_decrypt_key(test_key,128,&decks); | ||
| 154 | |||
| 155 | test_vector(vector_17,sizeof(vector_17)); | ||
| 156 | test_vector(vector_31,sizeof(vector_31)); | ||
| 157 | test_vector(vector_32,sizeof(vector_32)); | ||
| 158 | test_vector(vector_47,sizeof(vector_47)); | ||
| 159 | test_vector(vector_48,sizeof(vector_48)); | ||
| 160 | test_vector(vector_64,sizeof(vector_64)); | ||
| 161 | |||
| 162 | test_nistvector(vector_17,sizeof(vector_17)); | ||
| 163 | test_nistvector(vector_31,sizeof(vector_31)); | ||
| 164 | test_nistvector(vector_32,sizeof(vector_32)); | ||
| 165 | test_nistvector(vector_47,sizeof(vector_47)); | ||
| 166 | test_nistvector(vector_48,sizeof(vector_48)); | ||
| 167 | test_nistvector(vector_64,sizeof(vector_64)); | ||
| 168 | |||
| 169 | return 0; | ||
| 170 | } | ||
diff --git a/src/regress/lib/libcrypto/curve25519/Makefile b/src/regress/lib/libcrypto/curve25519/Makefile deleted file mode 100644 index 1bc4965670..0000000000 --- a/src/regress/lib/libcrypto/curve25519/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2016/11/05 15:09:02 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= x25519test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/curve25519/x25519test.c b/src/regress/lib/libcrypto/curve25519/x25519test.c deleted file mode 100644 index 02da807bd9..0000000000 --- a/src/regress/lib/libcrypto/curve25519/x25519test.c +++ /dev/null | |||
| @@ -1,140 +0,0 @@ | |||
| 1 | /* $OpenBSD: x25519test.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015, Google Inc. | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
| 12 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
| 14 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
| 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <string.h> | ||
| 21 | |||
| 22 | #include <openssl/curve25519.h> | ||
| 23 | |||
| 24 | static int | ||
| 25 | x25519_test(void) | ||
| 26 | { | ||
| 27 | /* Taken from https://tools.ietf.org/html/rfc7748#section-5.2 */ | ||
| 28 | static const uint8_t kScalar1[32] = { | ||
| 29 | 0xa5, 0x46, 0xe3, 0x6b, 0xf0, 0x52, 0x7c, 0x9d, | ||
| 30 | 0x3b, 0x16, 0x15, 0x4b, 0x82, 0x46, 0x5e, 0xdd, | ||
| 31 | 0x62, 0x14, 0x4c, 0x0a, 0xc1, 0xfc, 0x5a, 0x18, | ||
| 32 | 0x50, 0x6a, 0x22, 0x44, 0xba, 0x44, 0x9a, 0xc4, | ||
| 33 | }; | ||
| 34 | static const uint8_t kPoint1[32] = { | ||
| 35 | 0xe6, 0xdb, 0x68, 0x67, 0x58, 0x30, 0x30, 0xdb, | ||
| 36 | 0x35, 0x94, 0xc1, 0xa4, 0x24, 0xb1, 0x5f, 0x7c, | ||
| 37 | 0x72, 0x66, 0x24, 0xec, 0x26, 0xb3, 0x35, 0x3b, | ||
| 38 | 0x10, 0xa9, 0x03, 0xa6, 0xd0, 0xab, 0x1c, 0x4c, | ||
| 39 | }; | ||
| 40 | static const uint8_t kExpected1[32] = { | ||
| 41 | 0xc3, 0xda, 0x55, 0x37, 0x9d, 0xe9, 0xc6, 0x90, | ||
| 42 | 0x8e, 0x94, 0xea, 0x4d, 0xf2, 0x8d, 0x08, 0x4f, | ||
| 43 | 0x32, 0xec, 0xcf, 0x03, 0x49, 0x1c, 0x71, 0xf7, | ||
| 44 | 0x54, 0xb4, 0x07, 0x55, 0x77, 0xa2, 0x85, 0x52, | ||
| 45 | }; | ||
| 46 | static const uint8_t kScalar2[32] = { | ||
| 47 | 0x4b, 0x66, 0xe9, 0xd4, 0xd1, 0xb4, 0x67, 0x3c, | ||
| 48 | 0x5a, 0xd2, 0x26, 0x91, 0x95, 0x7d, 0x6a, 0xf5, | ||
| 49 | 0xc1, 0x1b, 0x64, 0x21, 0xe0, 0xea, 0x01, 0xd4, | ||
| 50 | 0x2c, 0xa4, 0x16, 0x9e, 0x79, 0x18, 0xba, 0x0d, | ||
| 51 | }; | ||
| 52 | static const uint8_t kPoint2[32] = { | ||
| 53 | 0xe5, 0x21, 0x0f, 0x12, 0x78, 0x68, 0x11, 0xd3, | ||
| 54 | 0xf4, 0xb7, 0x95, 0x9d, 0x05, 0x38, 0xae, 0x2c, | ||
| 55 | 0x31, 0xdb, 0xe7, 0x10, 0x6f, 0xc0, 0x3c, 0x3e, | ||
| 56 | 0xfc, 0x4c, 0xd5, 0x49, 0xc7, 0x15, 0xa4, 0x93, | ||
| 57 | }; | ||
| 58 | static const uint8_t kExpected2[32] = { | ||
| 59 | 0x95, 0xcb, 0xde, 0x94, 0x76, 0xe8, 0x90, 0x7d, | ||
| 60 | 0x7a, 0xad, 0xe4, 0x5c, 0xb4, 0xb8, 0x73, 0xf8, | ||
| 61 | 0x8b, 0x59, 0x5a, 0x68, 0x79, 0x9f, 0xa1, 0x52, | ||
| 62 | 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57, | ||
| 63 | }; | ||
| 64 | |||
| 65 | uint8_t out[32]; | ||
| 66 | |||
| 67 | X25519(out, kScalar1, kPoint1); | ||
| 68 | if (memcmp(kExpected1, out, sizeof(out)) != 0) { | ||
| 69 | fprintf(stderr, "X25519 test one failed.\n"); | ||
| 70 | return 0; | ||
| 71 | } | ||
| 72 | |||
| 73 | X25519(out, kScalar2, kPoint2); | ||
| 74 | if (memcmp(kExpected2, out, sizeof(out)) != 0) { | ||
| 75 | fprintf(stderr, "X25519 test two failed.\n"); | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | return 1; | ||
| 80 | } | ||
| 81 | |||
| 82 | static int | ||
| 83 | x25519_iterated_test(void) | ||
| 84 | { | ||
| 85 | /* Taken from https://tools.ietf.org/html/rfc7748#section-5.2 */ | ||
| 86 | static const uint8_t kExpected[32] = { | ||
| 87 | 0x68, 0x4c, 0xf5, 0x9b, 0xa8, 0x33, 0x09, 0x55, | ||
| 88 | 0x28, 0x00, 0xef, 0x56, 0x6f, 0x2f, 0x4d, 0x3c, | ||
| 89 | 0x1c, 0x38, 0x87, 0xc4, 0x93, 0x60, 0xe3, 0x87, | ||
| 90 | 0x5f, 0x2e, 0xb9, 0x4d, 0x99, 0x53, 0x2c, 0x51, | ||
| 91 | }; | ||
| 92 | |||
| 93 | uint8_t scalar[32] = {9}, point[32] = {9}, out[32]; | ||
| 94 | unsigned i; | ||
| 95 | |||
| 96 | for (i = 0; i < 1000; i++) { | ||
| 97 | X25519(out, scalar, point); | ||
| 98 | memcpy(point, scalar, sizeof(point)); | ||
| 99 | memcpy(scalar, out, sizeof(scalar)); | ||
| 100 | } | ||
| 101 | |||
| 102 | if (memcmp(kExpected, scalar, sizeof(kExpected)) != 0) { | ||
| 103 | fprintf(stderr, "Iterated X25519 test failed\n"); | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | |||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | |||
| 110 | static int | ||
| 111 | x25519_small_order_test(void) | ||
| 112 | { | ||
| 113 | static const uint8_t kSmallOrderPoint[32] = { | ||
| 114 | 0xe0, 0xeb, 0x7a, 0x7c, 0x3b, 0x41, 0xb8, 0xae, | ||
| 115 | 0x16, 0x56, 0xe3, 0xfa, 0xf1, 0x9f, 0xc4, 0x6a, | ||
| 116 | 0xda, 0x09, 0x8d, 0xeb, 0x9c, 0x32, 0xb1, 0xfd, | ||
| 117 | 0x86, 0x62, 0x05, 0x16, 0x5f, 0x49, 0xb8, 0x00, | ||
| 118 | }; | ||
| 119 | |||
| 120 | uint8_t out[32], private_key[32]; | ||
| 121 | |||
| 122 | memset(private_key, 0x11, sizeof(private_key)); | ||
| 123 | if (X25519(out, private_key, kSmallOrderPoint)) { | ||
| 124 | fprintf(stderr, "X25519 returned success with a small-order input.\n"); | ||
| 125 | return 0; | ||
| 126 | } | ||
| 127 | |||
| 128 | return 1; | ||
| 129 | } | ||
| 130 | |||
| 131 | int | ||
| 132 | main(int argc, char **argv) { | ||
| 133 | if (!x25519_test() || | ||
| 134 | !x25519_iterated_test() || | ||
| 135 | !x25519_small_order_test()) | ||
| 136 | return 1; | ||
| 137 | |||
| 138 | printf("PASS\n"); | ||
| 139 | return 0; | ||
| 140 | } | ||
diff --git a/src/regress/lib/libcrypto/des/Makefile b/src/regress/lib/libcrypto/des/Makefile deleted file mode 100644 index 356346730a..0000000000 --- a/src/regress/lib/libcrypto/des/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= destest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/des/destest.c b/src/regress/lib/libcrypto/des/destest.c deleted file mode 100644 index ebc67f3107..0000000000 --- a/src/regress/lib/libcrypto/des/destest.c +++ /dev/null | |||
| @@ -1,884 +0,0 @@ | |||
| 1 | /* $OpenBSD: destest.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | |||
| 62 | #include <unistd.h> | ||
| 63 | #include <string.h> | ||
| 64 | |||
| 65 | #include <openssl/des.h> | ||
| 66 | |||
| 67 | #define crypt(c,s) (DES_crypt((c),(s))) | ||
| 68 | |||
| 69 | /* tisk tisk - the test keys don't all have odd parity :-( */ | ||
| 70 | /* test data */ | ||
| 71 | #define NUM_TESTS 34 | ||
| 72 | static unsigned char key_data[NUM_TESTS][8]={ | ||
| 73 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 74 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 75 | {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 76 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 77 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 78 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 79 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 80 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}, | ||
| 81 | {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57}, | ||
| 82 | {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E}, | ||
| 83 | {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86}, | ||
| 84 | {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E}, | ||
| 85 | {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6}, | ||
| 86 | {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE}, | ||
| 87 | {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6}, | ||
| 88 | {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE}, | ||
| 89 | {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16}, | ||
| 90 | {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F}, | ||
| 91 | {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46}, | ||
| 92 | {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E}, | ||
| 93 | {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76}, | ||
| 94 | {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07}, | ||
| 95 | {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F}, | ||
| 96 | {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7}, | ||
| 97 | {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF}, | ||
| 98 | {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6}, | ||
| 99 | {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF}, | ||
| 100 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
| 101 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
| 102 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
| 103 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 104 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 105 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 106 | {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}}; | ||
| 107 | |||
| 108 | static unsigned char plain_data[NUM_TESTS][8]={ | ||
| 109 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 110 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 111 | {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
| 112 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 113 | {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}, | ||
| 114 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 115 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 116 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 117 | {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42}, | ||
| 118 | {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA}, | ||
| 119 | {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72}, | ||
| 120 | {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A}, | ||
| 121 | {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2}, | ||
| 122 | {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A}, | ||
| 123 | {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2}, | ||
| 124 | {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A}, | ||
| 125 | {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02}, | ||
| 126 | {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A}, | ||
| 127 | {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32}, | ||
| 128 | {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA}, | ||
| 129 | {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62}, | ||
| 130 | {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2}, | ||
| 131 | {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA}, | ||
| 132 | {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92}, | ||
| 133 | {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A}, | ||
| 134 | {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2}, | ||
| 135 | {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A}, | ||
| 136 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 137 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 138 | {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}, | ||
| 139 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 140 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 141 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 142 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}}; | ||
| 143 | |||
| 144 | static unsigned char cipher_data[NUM_TESTS][8]={ | ||
| 145 | {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, | ||
| 146 | {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58}, | ||
| 147 | {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B}, | ||
| 148 | {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33}, | ||
| 149 | {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D}, | ||
| 150 | {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD}, | ||
| 151 | {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7}, | ||
| 152 | {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4}, | ||
| 153 | {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B}, | ||
| 154 | {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71}, | ||
| 155 | {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A}, | ||
| 156 | {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A}, | ||
| 157 | {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95}, | ||
| 158 | {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B}, | ||
| 159 | {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09}, | ||
| 160 | {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A}, | ||
| 161 | {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F}, | ||
| 162 | {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88}, | ||
| 163 | {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77}, | ||
| 164 | {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A}, | ||
| 165 | {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56}, | ||
| 166 | {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56}, | ||
| 167 | {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56}, | ||
| 168 | {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC}, | ||
| 169 | {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A}, | ||
| 170 | {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41}, | ||
| 171 | {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93}, | ||
| 172 | {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00}, | ||
| 173 | {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06}, | ||
| 174 | {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7}, | ||
| 175 | {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51}, | ||
| 176 | {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE}, | ||
| 177 | {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D}, | ||
| 178 | {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}}; | ||
| 179 | |||
| 180 | static unsigned char cipher_ecb2[NUM_TESTS-1][8]={ | ||
| 181 | {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E}, | ||
| 182 | {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16}, | ||
| 183 | {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27}, | ||
| 184 | {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6}, | ||
| 185 | {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25}, | ||
| 186 | {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A}, | ||
| 187 | {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74}, | ||
| 188 | {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6}, | ||
| 189 | {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67}, | ||
| 190 | {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10}, | ||
| 191 | {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85}, | ||
| 192 | {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA}, | ||
| 193 | {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3}, | ||
| 194 | {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3}, | ||
| 195 | {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A}, | ||
| 196 | {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69}, | ||
| 197 | {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1}, | ||
| 198 | {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7}, | ||
| 199 | {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F}, | ||
| 200 | {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87}, | ||
| 201 | {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A}, | ||
| 202 | {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE}, | ||
| 203 | {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3}, | ||
| 204 | {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD}, | ||
| 205 | {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84}, | ||
| 206 | {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85}, | ||
| 207 | {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC}, | ||
| 208 | {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89}, | ||
| 209 | {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E}, | ||
| 210 | {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89}, | ||
| 211 | {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7}, | ||
| 212 | {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8}, | ||
| 213 | {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}}; | ||
| 214 | |||
| 215 | static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
| 216 | static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86}; | ||
| 217 | static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
| 218 | static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; | ||
| 219 | /* Changed the following text constant to binary so it will work on ebcdic | ||
| 220 | * machines :-) */ | ||
| 221 | /* static char cbc_data[40]="7654321 Now is the time for \0001"; */ | ||
| 222 | static unsigned char cbc_data[40]={ | ||
| 223 | 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, | ||
| 224 | 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, | ||
| 225 | 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, | ||
| 226 | 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00, | ||
| 227 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 228 | }; | ||
| 229 | |||
| 230 | static unsigned char cbc_ok[32]={ | ||
| 231 | 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, | ||
| 232 | 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb, | ||
| 233 | 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68, | ||
| 234 | 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | ||
| 235 | |||
| 236 | #ifdef SCREW_THE_PARITY | ||
| 237 | #error "SCREW_THE_PARITY is not ment to be defined." | ||
| 238 | #error "Original vectors are preserved for reference only." | ||
| 239 | static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87}; | ||
| 240 | static unsigned char xcbc_ok[32]={ | ||
| 241 | 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48, | ||
| 242 | 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD, | ||
| 243 | 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76, | ||
| 244 | 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2, | ||
| 245 | }; | ||
| 246 | #else | ||
| 247 | static unsigned char xcbc_ok[32]={ | ||
| 248 | 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29, | ||
| 249 | 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1, | ||
| 250 | 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53, | ||
| 251 | 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4, | ||
| 252 | }; | ||
| 253 | #endif | ||
| 254 | |||
| 255 | static unsigned char cbc3_ok[32]={ | ||
| 256 | 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0, | ||
| 257 | 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC, | ||
| 258 | 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4, | ||
| 259 | 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75}; | ||
| 260 | |||
| 261 | static unsigned char pcbc_ok[32]={ | ||
| 262 | 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4, | ||
| 263 | 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15, | ||
| 264 | 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f, | ||
| 265 | 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88}; | ||
| 266 | |||
| 267 | static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
| 268 | static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; | ||
| 269 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
| 270 | static unsigned char plain[24]= | ||
| 271 | { | ||
| 272 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
| 273 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
| 274 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
| 275 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
| 276 | }; | ||
| 277 | static unsigned char cfb_cipher8[24]= { | ||
| 278 | 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8, | ||
| 279 | 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 }; | ||
| 280 | static unsigned char cfb_cipher16[24]={ | ||
| 281 | 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70, | ||
| 282 | 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B }; | ||
| 283 | static unsigned char cfb_cipher32[24]={ | ||
| 284 | 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD, | ||
| 285 | 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 }; | ||
| 286 | static unsigned char cfb_cipher48[24]={ | ||
| 287 | 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85, | ||
| 288 | 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F }; | ||
| 289 | static unsigned char cfb_cipher64[24]={ | ||
| 290 | 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B, | ||
| 291 | 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 }; | ||
| 292 | |||
| 293 | static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
| 294 | static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef}; | ||
| 295 | static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8]; | ||
| 296 | static unsigned char ofb_cipher[24]= | ||
| 297 | { | ||
| 298 | 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51, | ||
| 299 | 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f, | ||
| 300 | 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3 | ||
| 301 | }; | ||
| 302 | |||
| 303 | #if 0 | ||
| 304 | static DES_LONG cbc_cksum_ret=0xB462FEF7L; | ||
| 305 | #else | ||
| 306 | static DES_LONG cbc_cksum_ret=0xF7FE62B4L; | ||
| 307 | #endif | ||
| 308 | static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; | ||
| 309 | |||
| 310 | static char *pt(unsigned char *p); | ||
| 311 | static int cfb_test(int bits, unsigned char *cfb_cipher); | ||
| 312 | static int cfb64_test(unsigned char *cfb_cipher); | ||
| 313 | static int ede_cfb64_test(unsigned char *cfb_cipher); | ||
| 314 | int main(int argc, char *argv[]) | ||
| 315 | { | ||
| 316 | int j,err=0; | ||
| 317 | unsigned int i; | ||
| 318 | DES_cblock in,out,outin,iv3,iv2; | ||
| 319 | DES_key_schedule ks,ks2,ks3; | ||
| 320 | unsigned char cbc_in[40]; | ||
| 321 | unsigned char cbc_out[40]; | ||
| 322 | DES_LONG cs; | ||
| 323 | unsigned char cret[8]; | ||
| 324 | DES_LONG lqret[4]; | ||
| 325 | int num; | ||
| 326 | char *str; | ||
| 327 | |||
| 328 | #ifndef OPENSSL_NO_DESCBCM | ||
| 329 | printf("Doing cbcm\n"); | ||
| 330 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
| 331 | { | ||
| 332 | printf("Key error %d\n",j); | ||
| 333 | err=1; | ||
| 334 | } | ||
| 335 | if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) | ||
| 336 | { | ||
| 337 | printf("Key error %d\n",j); | ||
| 338 | err=1; | ||
| 339 | } | ||
| 340 | if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) | ||
| 341 | { | ||
| 342 | printf("Key error %d\n",j); | ||
| 343 | err=1; | ||
| 344 | } | ||
| 345 | memset(cbc_out,0,40); | ||
| 346 | memset(cbc_in,0,40); | ||
| 347 | i=strlen((char *)cbc_data)+1; | ||
| 348 | /* i=((i+7)/8)*8; */ | ||
| 349 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 350 | memset(iv2,'\0',sizeof iv2); | ||
| 351 | |||
| 352 | DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2, | ||
| 353 | DES_ENCRYPT); | ||
| 354 | DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3, | ||
| 355 | &iv3,&iv2,DES_ENCRYPT); | ||
| 356 | /* if (memcmp(cbc_out,cbc3_ok, | ||
| 357 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) | ||
| 358 | { | ||
| 359 | printf("des_ede3_cbc_encrypt encrypt error\n"); | ||
| 360 | err=1; | ||
| 361 | } | ||
| 362 | */ | ||
| 363 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 364 | memset(iv2,'\0',sizeof iv2); | ||
| 365 | DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT); | ||
| 366 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
| 367 | { | ||
| 368 | unsigned int n; | ||
| 369 | |||
| 370 | printf("des_ede3_cbcm_encrypt decrypt error\n"); | ||
| 371 | for(n=0 ; n < i ; ++n) | ||
| 372 | printf(" %02x",cbc_data[n]); | ||
| 373 | printf("\n"); | ||
| 374 | for(n=0 ; n < i ; ++n) | ||
| 375 | printf(" %02x",cbc_in[n]); | ||
| 376 | printf("\n"); | ||
| 377 | err=1; | ||
| 378 | } | ||
| 379 | #endif | ||
| 380 | |||
| 381 | printf("Doing ecb\n"); | ||
| 382 | for (i=0; i<NUM_TESTS; i++) | ||
| 383 | { | ||
| 384 | DES_set_key_unchecked(&key_data[i],&ks); | ||
| 385 | memcpy(in,plain_data[i],8); | ||
| 386 | memset(out,0,8); | ||
| 387 | memset(outin,0,8); | ||
| 388 | DES_ecb_encrypt(&in,&out,&ks,DES_ENCRYPT); | ||
| 389 | DES_ecb_encrypt(&out,&outin,&ks,DES_DECRYPT); | ||
| 390 | |||
| 391 | if (memcmp(out,cipher_data[i],8) != 0) | ||
| 392 | { | ||
| 393 | printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
| 394 | i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]), | ||
| 395 | pt(out)); | ||
| 396 | err=1; | ||
| 397 | } | ||
| 398 | if (memcmp(in,outin,8) != 0) | ||
| 399 | { | ||
| 400 | printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
| 401 | i+1,pt(key_data[i]),pt(out),pt(in),pt(outin)); | ||
| 402 | err=1; | ||
| 403 | } | ||
| 404 | } | ||
| 405 | |||
| 406 | printf("Doing ede ecb\n"); | ||
| 407 | for (i=0; i<(NUM_TESTS-2); i++) | ||
| 408 | { | ||
| 409 | DES_set_key_unchecked(&key_data[i],&ks); | ||
| 410 | DES_set_key_unchecked(&key_data[i+1],&ks2); | ||
| 411 | DES_set_key_unchecked(&key_data[i+2],&ks3); | ||
| 412 | memcpy(in,plain_data[i],8); | ||
| 413 | memset(out,0,8); | ||
| 414 | memset(outin,0,8); | ||
| 415 | DES_ecb3_encrypt(&in,&out,&ks,&ks2,&ks,DES_ENCRYPT); | ||
| 416 | DES_ecb3_encrypt(&out,&outin,&ks,&ks2,&ks,DES_DECRYPT); | ||
| 417 | |||
| 418 | if (memcmp(out,cipher_ecb2[i],8) != 0) | ||
| 419 | { | ||
| 420 | printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
| 421 | i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]), | ||
| 422 | pt(out)); | ||
| 423 | err=1; | ||
| 424 | } | ||
| 425 | if (memcmp(in,outin,8) != 0) | ||
| 426 | { | ||
| 427 | printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n", | ||
| 428 | i+1,pt(key_data[i]),pt(out),pt(in),pt(outin)); | ||
| 429 | err=1; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | printf("Doing cbc\n"); | ||
| 434 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
| 435 | { | ||
| 436 | printf("Key error %d\n",j); | ||
| 437 | err=1; | ||
| 438 | } | ||
| 439 | memset(cbc_out,0,40); | ||
| 440 | memset(cbc_in,0,40); | ||
| 441 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 442 | DES_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,&ks, | ||
| 443 | &iv3,DES_ENCRYPT); | ||
| 444 | if (memcmp(cbc_out,cbc_ok,32) != 0) | ||
| 445 | { | ||
| 446 | printf("cbc_encrypt encrypt error\n"); | ||
| 447 | err=1; | ||
| 448 | } | ||
| 449 | |||
| 450 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 451 | DES_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,&ks, | ||
| 452 | &iv3,DES_DECRYPT); | ||
| 453 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) | ||
| 454 | { | ||
| 455 | printf("cbc_encrypt decrypt error\n"); | ||
| 456 | err=1; | ||
| 457 | } | ||
| 458 | |||
| 459 | printf("Doing desx cbc\n"); | ||
| 460 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
| 461 | { | ||
| 462 | printf("Key error %d\n",j); | ||
| 463 | err=1; | ||
| 464 | } | ||
| 465 | memset(cbc_out,0,40); | ||
| 466 | memset(cbc_in,0,40); | ||
| 467 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 468 | DES_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,&ks, | ||
| 469 | &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT); | ||
| 470 | if (memcmp(cbc_out,xcbc_ok,32) != 0) | ||
| 471 | { | ||
| 472 | printf("des_xcbc_encrypt encrypt error\n"); | ||
| 473 | err=1; | ||
| 474 | } | ||
| 475 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 476 | DES_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,&ks, | ||
| 477 | &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT); | ||
| 478 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
| 479 | { | ||
| 480 | printf("des_xcbc_encrypt decrypt error\n"); | ||
| 481 | err=1; | ||
| 482 | } | ||
| 483 | |||
| 484 | printf("Doing ede cbc\n"); | ||
| 485 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
| 486 | { | ||
| 487 | printf("Key error %d\n",j); | ||
| 488 | err=1; | ||
| 489 | } | ||
| 490 | if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0) | ||
| 491 | { | ||
| 492 | printf("Key error %d\n",j); | ||
| 493 | err=1; | ||
| 494 | } | ||
| 495 | if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0) | ||
| 496 | { | ||
| 497 | printf("Key error %d\n",j); | ||
| 498 | err=1; | ||
| 499 | } | ||
| 500 | memset(cbc_out,0,40); | ||
| 501 | memset(cbc_in,0,40); | ||
| 502 | i=strlen((char *)cbc_data)+1; | ||
| 503 | /* i=((i+7)/8)*8; */ | ||
| 504 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 505 | |||
| 506 | DES_ede3_cbc_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3, | ||
| 507 | DES_ENCRYPT); | ||
| 508 | DES_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,&ks,&ks2,&ks3, | ||
| 509 | &iv3,DES_ENCRYPT); | ||
| 510 | if (memcmp(cbc_out,cbc3_ok, | ||
| 511 | (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) | ||
| 512 | { | ||
| 513 | unsigned int n; | ||
| 514 | |||
| 515 | printf("des_ede3_cbc_encrypt encrypt error\n"); | ||
| 516 | for(n=0 ; n < i ; ++n) | ||
| 517 | printf(" %02x",cbc_out[n]); | ||
| 518 | printf("\n"); | ||
| 519 | for(n=0 ; n < i ; ++n) | ||
| 520 | printf(" %02x",cbc3_ok[n]); | ||
| 521 | printf("\n"); | ||
| 522 | err=1; | ||
| 523 | } | ||
| 524 | |||
| 525 | memcpy(iv3,cbc_iv,sizeof(cbc_iv)); | ||
| 526 | DES_ede3_cbc_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,DES_DECRYPT); | ||
| 527 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
| 528 | { | ||
| 529 | unsigned int n; | ||
| 530 | |||
| 531 | printf("des_ede3_cbc_encrypt decrypt error\n"); | ||
| 532 | for(n=0 ; n < i ; ++n) | ||
| 533 | printf(" %02x",cbc_data[n]); | ||
| 534 | printf("\n"); | ||
| 535 | for(n=0 ; n < i ; ++n) | ||
| 536 | printf(" %02x",cbc_in[n]); | ||
| 537 | printf("\n"); | ||
| 538 | err=1; | ||
| 539 | } | ||
| 540 | |||
| 541 | printf("Doing pcbc\n"); | ||
| 542 | if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0) | ||
| 543 | { | ||
| 544 | printf("Key error %d\n",j); | ||
| 545 | err=1; | ||
| 546 | } | ||
| 547 | memset(cbc_out,0,40); | ||
| 548 | memset(cbc_in,0,40); | ||
| 549 | DES_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,&ks, | ||
| 550 | &cbc_iv,DES_ENCRYPT); | ||
| 551 | if (memcmp(cbc_out,pcbc_ok,32) != 0) | ||
| 552 | { | ||
| 553 | printf("pcbc_encrypt encrypt error\n"); | ||
| 554 | err=1; | ||
| 555 | } | ||
| 556 | DES_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,&ks,&cbc_iv, | ||
| 557 | DES_DECRYPT); | ||
| 558 | if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) | ||
| 559 | { | ||
| 560 | printf("pcbc_encrypt decrypt error\n"); | ||
| 561 | err=1; | ||
| 562 | } | ||
| 563 | |||
| 564 | printf("Doing "); | ||
| 565 | printf("cfb8 "); | ||
| 566 | err+=cfb_test(8,cfb_cipher8); | ||
| 567 | printf("cfb16 "); | ||
| 568 | err+=cfb_test(16,cfb_cipher16); | ||
| 569 | printf("cfb32 "); | ||
| 570 | err+=cfb_test(32,cfb_cipher32); | ||
| 571 | printf("cfb48 "); | ||
| 572 | err+=cfb_test(48,cfb_cipher48); | ||
| 573 | printf("cfb64 "); | ||
| 574 | err+=cfb_test(64,cfb_cipher64); | ||
| 575 | |||
| 576 | printf("cfb64() "); | ||
| 577 | err+=cfb64_test(cfb_cipher64); | ||
| 578 | |||
| 579 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 580 | for (i=0; i<sizeof(plain); i++) | ||
| 581 | DES_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), | ||
| 582 | 8,1,&ks,&cfb_tmp,DES_ENCRYPT); | ||
| 583 | if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) | ||
| 584 | { | ||
| 585 | printf("cfb_encrypt small encrypt error\n"); | ||
| 586 | err=1; | ||
| 587 | } | ||
| 588 | |||
| 589 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 590 | for (i=0; i<sizeof(plain); i++) | ||
| 591 | DES_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), | ||
| 592 | 8,1,&ks,&cfb_tmp,DES_DECRYPT); | ||
| 593 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
| 594 | { | ||
| 595 | printf("cfb_encrypt small decrypt error\n"); | ||
| 596 | err=1; | ||
| 597 | } | ||
| 598 | |||
| 599 | printf("ede_cfb64() "); | ||
| 600 | err+=ede_cfb64_test(cfb_cipher64); | ||
| 601 | |||
| 602 | printf("done\n"); | ||
| 603 | |||
| 604 | printf("Doing ofb\n"); | ||
| 605 | DES_set_key_checked(&ofb_key,&ks); | ||
| 606 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 607 | DES_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,&ks,&ofb_tmp); | ||
| 608 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
| 609 | { | ||
| 610 | printf("ofb_encrypt encrypt error\n"); | ||
| 611 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
| 612 | ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3], | ||
| 613 | ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]); | ||
| 614 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
| 615 | ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3], | ||
| 616 | ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]); | ||
| 617 | err=1; | ||
| 618 | } | ||
| 619 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 620 | DES_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,&ks,&ofb_tmp); | ||
| 621 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
| 622 | { | ||
| 623 | printf("ofb_encrypt decrypt error\n"); | ||
| 624 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
| 625 | ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3], | ||
| 626 | ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]); | ||
| 627 | printf("%02X %02X %02X %02X %02X %02X %02X %02X\n", | ||
| 628 | plain[8+0], plain[8+1], plain[8+2], plain[8+3], | ||
| 629 | plain[8+4], plain[8+5], plain[8+6], plain[8+7]); | ||
| 630 | err=1; | ||
| 631 | } | ||
| 632 | |||
| 633 | printf("Doing ofb64\n"); | ||
| 634 | DES_set_key_checked(&ofb_key,&ks); | ||
| 635 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 636 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | ||
| 637 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | ||
| 638 | num=0; | ||
| 639 | for (i=0; i<sizeof(plain); i++) | ||
| 640 | { | ||
| 641 | DES_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,&ks,&ofb_tmp, | ||
| 642 | &num); | ||
| 643 | } | ||
| 644 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
| 645 | { | ||
| 646 | printf("ofb64_encrypt encrypt error\n"); | ||
| 647 | err=1; | ||
| 648 | } | ||
| 649 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 650 | num=0; | ||
| 651 | DES_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),&ks,&ofb_tmp, | ||
| 652 | &num); | ||
| 653 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
| 654 | { | ||
| 655 | printf("ofb64_encrypt decrypt error\n"); | ||
| 656 | err=1; | ||
| 657 | } | ||
| 658 | |||
| 659 | printf("Doing ede_ofb64\n"); | ||
| 660 | DES_set_key_checked(&ofb_key,&ks); | ||
| 661 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 662 | memset(ofb_buf1,0,sizeof(ofb_buf1)); | ||
| 663 | memset(ofb_buf2,0,sizeof(ofb_buf1)); | ||
| 664 | num=0; | ||
| 665 | for (i=0; i<sizeof(plain); i++) | ||
| 666 | { | ||
| 667 | DES_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,&ks,&ks, | ||
| 668 | &ks,&ofb_tmp,&num); | ||
| 669 | } | ||
| 670 | if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) | ||
| 671 | { | ||
| 672 | printf("ede_ofb64_encrypt encrypt error\n"); | ||
| 673 | err=1; | ||
| 674 | } | ||
| 675 | memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); | ||
| 676 | num=0; | ||
| 677 | DES_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),&ks,&ks,&ks, | ||
| 678 | &ofb_tmp,&num); | ||
| 679 | if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) | ||
| 680 | { | ||
| 681 | printf("ede_ofb64_encrypt decrypt error\n"); | ||
| 682 | err=1; | ||
| 683 | } | ||
| 684 | |||
| 685 | printf("Doing cbc_cksum\n"); | ||
| 686 | DES_set_key_checked(&cbc_key,&ks); | ||
| 687 | cs=DES_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),&ks,&cbc_iv); | ||
| 688 | if (cs != cbc_cksum_ret) | ||
| 689 | { | ||
| 690 | printf("bad return value (%08lX), should be %08lX\n", | ||
| 691 | (unsigned long)cs,(unsigned long)cbc_cksum_ret); | ||
| 692 | err=1; | ||
| 693 | } | ||
| 694 | if (memcmp(cret,cbc_cksum_data,8) != 0) | ||
| 695 | { | ||
| 696 | printf("bad cbc_cksum block returned\n"); | ||
| 697 | err=1; | ||
| 698 | } | ||
| 699 | |||
| 700 | printf("Doing quad_cksum\n"); | ||
| 701 | cs=DES_quad_cksum(cbc_data,(DES_cblock *)lqret, | ||
| 702 | (long)strlen((char *)cbc_data),2,(DES_cblock *)cbc_iv); | ||
| 703 | if (cs != 0x70d7a63aL) | ||
| 704 | { | ||
| 705 | printf("quad_cksum error, ret %08lx should be 70d7a63a\n", | ||
| 706 | (unsigned long)cs); | ||
| 707 | err=1; | ||
| 708 | } | ||
| 709 | if (lqret[0] != 0x327eba8dL) | ||
| 710 | { | ||
| 711 | printf("quad_cksum error, out[0] %08lx is not %08lx\n", | ||
| 712 | (unsigned long)lqret[0],0x327eba8dUL); | ||
| 713 | err=1; | ||
| 714 | } | ||
| 715 | if (lqret[1] != 0x201a49ccL) | ||
| 716 | { | ||
| 717 | printf("quad_cksum error, out[1] %08lx is not %08lx\n", | ||
| 718 | (unsigned long)lqret[1],0x201a49ccUL); | ||
| 719 | err=1; | ||
| 720 | } | ||
| 721 | if (lqret[2] != 0x70d7a63aL) | ||
| 722 | { | ||
| 723 | printf("quad_cksum error, out[2] %08lx is not %08lx\n", | ||
| 724 | (unsigned long)lqret[2],0x70d7a63aUL); | ||
| 725 | err=1; | ||
| 726 | } | ||
| 727 | if (lqret[3] != 0x501c2c26L) | ||
| 728 | { | ||
| 729 | printf("quad_cksum error, out[3] %08lx is not %08lx\n", | ||
| 730 | (unsigned long)lqret[3],0x501c2c26UL); | ||
| 731 | err=1; | ||
| 732 | } | ||
| 733 | |||
| 734 | printf("input word alignment test"); | ||
| 735 | for (i=0; i<4; i++) | ||
| 736 | { | ||
| 737 | printf(" %u",i); | ||
| 738 | DES_ncbc_encrypt(&(cbc_out[i]),cbc_in, | ||
| 739 | strlen((char *)cbc_data)+1,&ks, | ||
| 740 | &cbc_iv,DES_ENCRYPT); | ||
| 741 | } | ||
| 742 | printf("\noutput word alignment test"); | ||
| 743 | for (i=0; i<4; i++) | ||
| 744 | { | ||
| 745 | printf(" %u",i); | ||
| 746 | DES_ncbc_encrypt(cbc_out,&(cbc_in[i]), | ||
| 747 | strlen((char *)cbc_data)+1,&ks, | ||
| 748 | &cbc_iv,DES_ENCRYPT); | ||
| 749 | } | ||
| 750 | printf("\n"); | ||
| 751 | printf("fast crypt test "); | ||
| 752 | str=crypt("testing","ef"); | ||
| 753 | if (strcmp("efGnQx2725bI2",str) != 0) | ||
| 754 | { | ||
| 755 | printf("fast crypt error, %s should be efGnQx2725bI2\n",str); | ||
| 756 | err=1; | ||
| 757 | } | ||
| 758 | str=crypt("bca76;23","yA"); | ||
| 759 | if (strcmp("yA1Rp/1hZXIJk",str) != 0) | ||
| 760 | { | ||
| 761 | printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str); | ||
| 762 | err=1; | ||
| 763 | } | ||
| 764 | printf("\n"); | ||
| 765 | return(err); | ||
| 766 | } | ||
| 767 | |||
| 768 | static char *pt(unsigned char *p) | ||
| 769 | { | ||
| 770 | static char bufs[10][20]; | ||
| 771 | static int bnum=0; | ||
| 772 | char *ret; | ||
| 773 | int i; | ||
| 774 | static char *f="0123456789ABCDEF"; | ||
| 775 | |||
| 776 | ret= &(bufs[bnum++][0]); | ||
| 777 | bnum%=10; | ||
| 778 | for (i=0; i<8; i++) | ||
| 779 | { | ||
| 780 | ret[i*2]=f[(p[i]>>4)&0xf]; | ||
| 781 | ret[i*2+1]=f[p[i]&0xf]; | ||
| 782 | } | ||
| 783 | ret[16]='\0'; | ||
| 784 | return(ret); | ||
| 785 | } | ||
| 786 | |||
| 787 | static int cfb_test(int bits, unsigned char *cfb_cipher) | ||
| 788 | { | ||
| 789 | DES_key_schedule ks; | ||
| 790 | int i,err=0; | ||
| 791 | |||
| 792 | DES_set_key_checked(&cfb_key,&ks); | ||
| 793 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 794 | DES_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),&ks,&cfb_tmp, | ||
| 795 | DES_ENCRYPT); | ||
| 796 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
| 797 | { | ||
| 798 | err=1; | ||
| 799 | printf("cfb_encrypt encrypt error\n"); | ||
| 800 | for (i=0; i<24; i+=8) | ||
| 801 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 802 | } | ||
| 803 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 804 | DES_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),&ks,&cfb_tmp, | ||
| 805 | DES_DECRYPT); | ||
| 806 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
| 807 | { | ||
| 808 | err=1; | ||
| 809 | printf("cfb_encrypt decrypt error\n"); | ||
| 810 | for (i=0; i<24; i+=8) | ||
| 811 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 812 | } | ||
| 813 | return(err); | ||
| 814 | } | ||
| 815 | |||
| 816 | static int cfb64_test(unsigned char *cfb_cipher) | ||
| 817 | { | ||
| 818 | DES_key_schedule ks; | ||
| 819 | int err=0,i,n; | ||
| 820 | |||
| 821 | DES_set_key_checked(&cfb_key,&ks); | ||
| 822 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 823 | n=0; | ||
| 824 | DES_cfb64_encrypt(plain,cfb_buf1,12,&ks,&cfb_tmp,&n,DES_ENCRYPT); | ||
| 825 | DES_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,&ks, | ||
| 826 | &cfb_tmp,&n,DES_ENCRYPT); | ||
| 827 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
| 828 | { | ||
| 829 | err=1; | ||
| 830 | printf("cfb_encrypt encrypt error\n"); | ||
| 831 | for (i=0; i<24; i+=8) | ||
| 832 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 833 | } | ||
| 834 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 835 | n=0; | ||
| 836 | DES_cfb64_encrypt(cfb_buf1,cfb_buf2,17,&ks,&cfb_tmp,&n,DES_DECRYPT); | ||
| 837 | DES_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
| 838 | sizeof(plain)-17,&ks,&cfb_tmp,&n,DES_DECRYPT); | ||
| 839 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
| 840 | { | ||
| 841 | err=1; | ||
| 842 | printf("cfb_encrypt decrypt error\n"); | ||
| 843 | for (i=0; i<24; i+=8) | ||
| 844 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
| 845 | } | ||
| 846 | return(err); | ||
| 847 | } | ||
| 848 | |||
| 849 | static int ede_cfb64_test(unsigned char *cfb_cipher) | ||
| 850 | { | ||
| 851 | DES_key_schedule ks; | ||
| 852 | int err=0,i,n; | ||
| 853 | |||
| 854 | DES_set_key_checked(&cfb_key,&ks); | ||
| 855 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 856 | n=0; | ||
| 857 | DES_ede3_cfb64_encrypt(plain,cfb_buf1,12,&ks,&ks,&ks,&cfb_tmp,&n, | ||
| 858 | DES_ENCRYPT); | ||
| 859 | DES_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
| 860 | sizeof(plain)-12,&ks,&ks,&ks, | ||
| 861 | &cfb_tmp,&n,DES_ENCRYPT); | ||
| 862 | if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) | ||
| 863 | { | ||
| 864 | err=1; | ||
| 865 | printf("ede_cfb_encrypt encrypt error\n"); | ||
| 866 | for (i=0; i<24; i+=8) | ||
| 867 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 868 | } | ||
| 869 | memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); | ||
| 870 | n=0; | ||
| 871 | DES_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&ks,&ks,&ks, | ||
| 872 | &cfb_tmp,&n,DES_DECRYPT); | ||
| 873 | DES_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
| 874 | sizeof(plain)-17,&ks,&ks,&ks, | ||
| 875 | &cfb_tmp,&n,DES_DECRYPT); | ||
| 876 | if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) | ||
| 877 | { | ||
| 878 | err=1; | ||
| 879 | printf("ede_cfb_encrypt decrypt error\n"); | ||
| 880 | for (i=0; i<24; i+=8) | ||
| 881 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
| 882 | } | ||
| 883 | return(err); | ||
| 884 | } | ||
diff --git a/src/regress/lib/libcrypto/dh/Makefile b/src/regress/lib/libcrypto/dh/Makefile deleted file mode 100644 index 3eaacc4296..0000000000 --- a/src/regress/lib/libcrypto/dh/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= dhtest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/dh/dhtest.c b/src/regress/lib/libcrypto/dh/dhtest.c deleted file mode 100644 index 599c51d5ed..0000000000 --- a/src/regress/lib/libcrypto/dh/dhtest.c +++ /dev/null | |||
| @@ -1,160 +0,0 @@ | |||
| 1 | /* $OpenBSD: dhtest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Until the key-gen callbacks are modified to use newer prototypes, we allow | ||
| 60 | * deprecated functions for openssl-internal code */ | ||
| 61 | #ifdef OPENSSL_NO_DEPRECATED | ||
| 62 | #undef OPENSSL_NO_DEPRECATED | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | ||
| 67 | #include <string.h> | ||
| 68 | |||
| 69 | #include <openssl/crypto.h> | ||
| 70 | #include <openssl/bio.h> | ||
| 71 | #include <openssl/bn.h> | ||
| 72 | #include <openssl/err.h> | ||
| 73 | |||
| 74 | #include <openssl/dh.h> | ||
| 75 | |||
| 76 | static int cb(int p, int n, BN_GENCB *arg) | ||
| 77 | { | ||
| 78 | char c='*'; | ||
| 79 | |||
| 80 | if (p == 0) | ||
| 81 | c='.'; | ||
| 82 | if (p == 1) | ||
| 83 | c='+'; | ||
| 84 | if (p == 2) | ||
| 85 | c='*'; | ||
| 86 | if (p == 3) | ||
| 87 | c='\n'; | ||
| 88 | BIO_write(arg->arg,&c,1); | ||
| 89 | (void)BIO_flush(arg->arg); | ||
| 90 | return 1; | ||
| 91 | } | ||
| 92 | |||
| 93 | int main(int argc, char *argv[]) | ||
| 94 | { | ||
| 95 | BN_GENCB _cb; | ||
| 96 | DH *a; | ||
| 97 | char buf[12]; | ||
| 98 | unsigned char *abuf=NULL; | ||
| 99 | int i,alen,aout,ret=1; | ||
| 100 | BIO *out; | ||
| 101 | |||
| 102 | out=BIO_new(BIO_s_file()); | ||
| 103 | if (out == NULL) exit(1); | ||
| 104 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
| 105 | |||
| 106 | BN_GENCB_set(&_cb, &cb, out); | ||
| 107 | if (((a = DH_new()) == NULL) || | ||
| 108 | !DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, &_cb)) | ||
| 109 | goto err; | ||
| 110 | |||
| 111 | if (!DH_check(a, &i)) | ||
| 112 | goto err; | ||
| 113 | if (i & DH_CHECK_P_NOT_PRIME) | ||
| 114 | BIO_puts(out, "p value is not prime\n"); | ||
| 115 | if (i & DH_CHECK_P_NOT_SAFE_PRIME) | ||
| 116 | BIO_puts(out, "p value is not a safe prime\n"); | ||
| 117 | if (i & DH_UNABLE_TO_CHECK_GENERATOR) | ||
| 118 | BIO_puts(out, "unable to check the generator value\n"); | ||
| 119 | if (i & DH_NOT_SUITABLE_GENERATOR) | ||
| 120 | BIO_puts(out, "the g value is not a generator\n"); | ||
| 121 | |||
| 122 | BIO_puts(out,"\np ="); | ||
| 123 | BN_print(out,a->p); | ||
| 124 | BIO_puts(out,"\ng ="); | ||
| 125 | BN_print(out,a->g); | ||
| 126 | BIO_puts(out,"\n"); | ||
| 127 | |||
| 128 | if (!DH_generate_key(a)) | ||
| 129 | goto err; | ||
| 130 | BIO_puts(out,"pri 1="); | ||
| 131 | BN_print(out,a->priv_key); | ||
| 132 | BIO_puts(out,"\npub 1="); | ||
| 133 | BN_print(out,a->pub_key); | ||
| 134 | BIO_puts(out,"\n"); | ||
| 135 | |||
| 136 | alen=DH_size(a); | ||
| 137 | abuf=malloc(alen); | ||
| 138 | aout=DH_compute_key(abuf,a->pub_key,a); | ||
| 139 | |||
| 140 | BIO_puts(out,"key1 ="); | ||
| 141 | for (i=0; i<aout; i++) { | ||
| 142 | snprintf(buf,sizeof buf,"%02X",abuf[i]); | ||
| 143 | BIO_puts(out,buf); | ||
| 144 | } | ||
| 145 | BIO_puts(out,"\n"); | ||
| 146 | |||
| 147 | if (aout < 4) { | ||
| 148 | fprintf(stderr,"Error in DH routines\n"); | ||
| 149 | ret=1; | ||
| 150 | } else | ||
| 151 | ret=0; | ||
| 152 | err: | ||
| 153 | ERR_print_errors_fp(stderr); | ||
| 154 | |||
| 155 | free(abuf); | ||
| 156 | if (a != NULL) | ||
| 157 | DH_free(a); | ||
| 158 | BIO_free(out); | ||
| 159 | exit(ret); | ||
| 160 | } | ||
diff --git a/src/regress/lib/libcrypto/dsa/Makefile b/src/regress/lib/libcrypto/dsa/Makefile deleted file mode 100644 index 0574c6e282..0000000000 --- a/src/regress/lib/libcrypto/dsa/Makefile +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= dsatest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-dsatest | ||
| 10 | |||
| 11 | regress-dsatest: ${PROG} | ||
| 12 | ./${PROG} | ||
| 13 | ./${PROG} -app2_1 | ||
| 14 | |||
| 15 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/dsa/dsatest.c b/src/regress/lib/libcrypto/dsa/dsatest.c deleted file mode 100644 index dd3e3166f7..0000000000 --- a/src/regress/lib/libcrypto/dsa/dsatest.c +++ /dev/null | |||
| @@ -1,224 +0,0 @@ | |||
| 1 | /* $OpenBSD: dsatest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Until the key-gen callbacks are modified to use newer prototypes, we allow | ||
| 60 | * deprecated functions for openssl-internal code */ | ||
| 61 | #ifdef OPENSSL_NO_DEPRECATED | ||
| 62 | #undef OPENSSL_NO_DEPRECATED | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | ||
| 67 | #include <string.h> | ||
| 68 | #include <sys/types.h> | ||
| 69 | #include <sys/stat.h> | ||
| 70 | |||
| 71 | #include <openssl/crypto.h> | ||
| 72 | #include <openssl/bio.h> | ||
| 73 | #include <openssl/err.h> | ||
| 74 | #include <openssl/bn.h> | ||
| 75 | |||
| 76 | #include <openssl/dsa.h> | ||
| 77 | |||
| 78 | static int dsa_cb(int p, int n, BN_GENCB *arg); | ||
| 79 | |||
| 80 | /* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to | ||
| 81 | * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */ | ||
| 82 | static unsigned char seed[20]={ | ||
| 83 | 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, | ||
| 84 | 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, | ||
| 85 | }; | ||
| 86 | |||
| 87 | static unsigned char out_p[]={ | ||
| 88 | 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa, | ||
| 89 | 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb, | ||
| 90 | 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7, | ||
| 91 | 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5, | ||
| 92 | 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf, | ||
| 93 | 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac, | ||
| 94 | 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2, | ||
| 95 | 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91, | ||
| 96 | }; | ||
| 97 | |||
| 98 | static unsigned char out_q[]={ | ||
| 99 | 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee, | ||
| 100 | 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e, | ||
| 101 | 0xda,0xce,0x91,0x5f, | ||
| 102 | }; | ||
| 103 | |||
| 104 | static unsigned char out_g[]={ | ||
| 105 | 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13, | ||
| 106 | 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00, | ||
| 107 | 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb, | ||
| 108 | 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e, | ||
| 109 | 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf, | ||
| 110 | 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c, | ||
| 111 | 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c, | ||
| 112 | 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, | ||
| 113 | }; | ||
| 114 | |||
| 115 | static const unsigned char str1[]="12345678901234567890"; | ||
| 116 | |||
| 117 | static BIO *bio_err=NULL; | ||
| 118 | |||
| 119 | int main(int argc, char **argv) | ||
| 120 | { | ||
| 121 | BN_GENCB cb; | ||
| 122 | DSA *dsa=NULL; | ||
| 123 | int counter,ret=0,i,j; | ||
| 124 | unsigned char buf[256]; | ||
| 125 | unsigned long h; | ||
| 126 | unsigned char sig[256]; | ||
| 127 | unsigned int siglen; | ||
| 128 | |||
| 129 | if (bio_err == NULL) | ||
| 130 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | ||
| 131 | |||
| 132 | ERR_load_crypto_strings(); | ||
| 133 | |||
| 134 | BIO_printf(bio_err,"test generation of DSA parameters\n"); | ||
| 135 | |||
| 136 | BN_GENCB_set(&cb, dsa_cb, bio_err); | ||
| 137 | if(((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512, | ||
| 138 | seed, 20, &counter, &h, &cb)) | ||
| 139 | goto end; | ||
| 140 | |||
| 141 | BIO_printf(bio_err,"seed\n"); | ||
| 142 | for (i=0; i<20; i+=4) | ||
| 143 | { | ||
| 144 | BIO_printf(bio_err,"%02X%02X%02X%02X ", | ||
| 145 | seed[i],seed[i+1],seed[i+2],seed[i+3]); | ||
| 146 | } | ||
| 147 | BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h); | ||
| 148 | |||
| 149 | DSA_print(bio_err,dsa,0); | ||
| 150 | if (counter != 105) | ||
| 151 | { | ||
| 152 | BIO_printf(bio_err,"counter should be 105\n"); | ||
| 153 | goto end; | ||
| 154 | } | ||
| 155 | if (h != 2) | ||
| 156 | { | ||
| 157 | BIO_printf(bio_err,"h should be 2\n"); | ||
| 158 | goto end; | ||
| 159 | } | ||
| 160 | |||
| 161 | i=BN_bn2bin(dsa->q,buf); | ||
| 162 | j=sizeof(out_q); | ||
| 163 | if ((i != j) || (memcmp(buf,out_q,i) != 0)) | ||
| 164 | { | ||
| 165 | BIO_printf(bio_err,"q value is wrong\n"); | ||
| 166 | goto end; | ||
| 167 | } | ||
| 168 | |||
| 169 | i=BN_bn2bin(dsa->p,buf); | ||
| 170 | j=sizeof(out_p); | ||
| 171 | if ((i != j) || (memcmp(buf,out_p,i) != 0)) | ||
| 172 | { | ||
| 173 | BIO_printf(bio_err,"p value is wrong\n"); | ||
| 174 | goto end; | ||
| 175 | } | ||
| 176 | |||
| 177 | i=BN_bn2bin(dsa->g,buf); | ||
| 178 | j=sizeof(out_g); | ||
| 179 | if ((i != j) || (memcmp(buf,out_g,i) != 0)) | ||
| 180 | { | ||
| 181 | BIO_printf(bio_err,"g value is wrong\n"); | ||
| 182 | goto end; | ||
| 183 | } | ||
| 184 | |||
| 185 | DSA_generate_key(dsa); | ||
| 186 | DSA_sign(0, str1, 20, sig, &siglen, dsa); | ||
| 187 | if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) | ||
| 188 | ret=1; | ||
| 189 | |||
| 190 | end: | ||
| 191 | if (!ret) | ||
| 192 | ERR_print_errors(bio_err); | ||
| 193 | if (dsa != NULL) DSA_free(dsa); | ||
| 194 | CRYPTO_cleanup_all_ex_data(); | ||
| 195 | ERR_remove_thread_state(NULL); | ||
| 196 | ERR_free_strings(); | ||
| 197 | CRYPTO_mem_leaks(bio_err); | ||
| 198 | if (bio_err != NULL) | ||
| 199 | { | ||
| 200 | BIO_free(bio_err); | ||
| 201 | bio_err = NULL; | ||
| 202 | } | ||
| 203 | exit(!ret); | ||
| 204 | } | ||
| 205 | |||
| 206 | static int dsa_cb(int p, int n, BN_GENCB *arg) | ||
| 207 | { | ||
| 208 | char c='*'; | ||
| 209 | static int ok=0,num=0; | ||
| 210 | |||
| 211 | if (p == 0) { c='.'; num++; }; | ||
| 212 | if (p == 1) c='+'; | ||
| 213 | if (p == 2) { c='*'; ok++; } | ||
| 214 | if (p == 3) c='\n'; | ||
| 215 | BIO_write(arg->arg,&c,1); | ||
| 216 | (void)BIO_flush(arg->arg); | ||
| 217 | |||
| 218 | if (!ok && (p == 0) && (num > 1)) | ||
| 219 | { | ||
| 220 | BIO_printf((BIO *)arg,"error in dsatest\n"); | ||
| 221 | return 0; | ||
| 222 | } | ||
| 223 | return 1; | ||
| 224 | } | ||
diff --git a/src/regress/lib/libcrypto/ec/Makefile b/src/regress/lib/libcrypto/ec/Makefile deleted file mode 100644 index c3e7975415..0000000000 --- a/src/regress/lib/libcrypto/ec/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= ectest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/ec/ectest.c b/src/regress/lib/libcrypto/ec/ectest.c deleted file mode 100644 index 401c013a6c..0000000000 --- a/src/regress/lib/libcrypto/ec/ectest.c +++ /dev/null | |||
| @@ -1,1456 +0,0 @@ | |||
| 1 | /* $OpenBSD: ectest.c,v 1.8 2018/07/15 18:22:57 tb Exp $ */ | ||
| 2 | /* crypto/ec/ectest.c */ | ||
| 3 | /* | ||
| 4 | * Originally written by Bodo Moeller for the OpenSSL project. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@openssl.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | /* ==================================================================== | ||
| 60 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 61 | * | ||
| 62 | * Portions of the attached software ("Contribution") are developed by | ||
| 63 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 64 | * | ||
| 65 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 66 | * license provided above. | ||
| 67 | * | ||
| 68 | * The elliptic curve binary polynomial software is originally written by | ||
| 69 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. | ||
| 70 | * | ||
| 71 | */ | ||
| 72 | |||
| 73 | #include <stdio.h> | ||
| 74 | #include <stdlib.h> | ||
| 75 | #include <string.h> | ||
| 76 | #include <time.h> | ||
| 77 | |||
| 78 | #include <openssl/ec.h> | ||
| 79 | #ifndef OPENSSL_NO_ENGINE | ||
| 80 | #include <openssl/engine.h> | ||
| 81 | #endif | ||
| 82 | #include <openssl/err.h> | ||
| 83 | #include <openssl/obj_mac.h> | ||
| 84 | #include <openssl/objects.h> | ||
| 85 | #include <openssl/bn.h> | ||
| 86 | #include <openssl/opensslconf.h> | ||
| 87 | |||
| 88 | #define ABORT do { \ | ||
| 89 | fflush(stdout); \ | ||
| 90 | fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \ | ||
| 91 | ERR_print_errors_fp(stderr); \ | ||
| 92 | exit(1); \ | ||
| 93 | } while (0) | ||
| 94 | |||
| 95 | #define TIMING_BASE_PT 0 | ||
| 96 | #define TIMING_RAND_PT 1 | ||
| 97 | #define TIMING_SIMUL 2 | ||
| 98 | |||
| 99 | /* test multiplication with group order, long and negative scalars */ | ||
| 100 | static void | ||
| 101 | group_order_tests(EC_GROUP *group) | ||
| 102 | { | ||
| 103 | BIGNUM *n1, *n2, *order; | ||
| 104 | EC_POINT *P = EC_POINT_new(group); | ||
| 105 | EC_POINT *Q = EC_POINT_new(group); | ||
| 106 | BN_CTX *ctx = BN_CTX_new(); | ||
| 107 | |||
| 108 | n1 = BN_new(); | ||
| 109 | n2 = BN_new(); | ||
| 110 | order = BN_new(); | ||
| 111 | fprintf(stdout, "verify group order ..."); | ||
| 112 | fflush(stdout); | ||
| 113 | if (!EC_GROUP_get_order(group, order, ctx)) | ||
| 114 | ABORT; | ||
| 115 | if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) | ||
| 116 | ABORT; | ||
| 117 | if (!EC_POINT_is_at_infinity(group, Q)) | ||
| 118 | ABORT; | ||
| 119 | fprintf(stdout, "."); | ||
| 120 | fflush(stdout); | ||
| 121 | if (!EC_GROUP_precompute_mult(group, ctx)) | ||
| 122 | ABORT; | ||
| 123 | if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx)) | ||
| 124 | ABORT; | ||
| 125 | if (!EC_POINT_is_at_infinity(group, Q)) | ||
| 126 | ABORT; | ||
| 127 | fprintf(stdout, " ok\n"); | ||
| 128 | fprintf(stdout, "long/negative scalar tests ... "); | ||
| 129 | if (!BN_one(n1)) | ||
| 130 | ABORT; | ||
| 131 | /* n1 = 1 - order */ | ||
| 132 | if (!BN_sub(n1, n1, order)) | ||
| 133 | ABORT; | ||
| 134 | if (!EC_POINT_mul(group, Q, NULL, P, n1, ctx)) | ||
| 135 | ABORT; | ||
| 136 | if (0 != EC_POINT_cmp(group, Q, P, ctx)) | ||
| 137 | ABORT; | ||
| 138 | /* n2 = 1 + order */ | ||
| 139 | if (!BN_add(n2, order, BN_value_one())) | ||
| 140 | ABORT; | ||
| 141 | if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) | ||
| 142 | ABORT; | ||
| 143 | if (0 != EC_POINT_cmp(group, Q, P, ctx)) | ||
| 144 | ABORT; | ||
| 145 | /* n2 = (1 - order) * (1 + order) */ | ||
| 146 | if (!BN_mul(n2, n1, n2, ctx)) | ||
| 147 | ABORT; | ||
| 148 | if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx)) | ||
| 149 | ABORT; | ||
| 150 | if (0 != EC_POINT_cmp(group, Q, P, ctx)) | ||
| 151 | ABORT; | ||
| 152 | fprintf(stdout, "ok\n"); | ||
| 153 | EC_POINT_free(P); | ||
| 154 | EC_POINT_free(Q); | ||
| 155 | BN_free(n1); | ||
| 156 | BN_free(n2); | ||
| 157 | BN_free(order); | ||
| 158 | BN_CTX_free(ctx); | ||
| 159 | } | ||
| 160 | |||
| 161 | static void | ||
| 162 | prime_field_tests(void) | ||
| 163 | { | ||
| 164 | BN_CTX *ctx = NULL; | ||
| 165 | BIGNUM *p, *a, *b; | ||
| 166 | EC_GROUP *group; | ||
| 167 | EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL; | ||
| 168 | EC_POINT *P, *Q, *R; | ||
| 169 | BIGNUM *x, *y, *z; | ||
| 170 | unsigned char buf[100]; | ||
| 171 | size_t i, len; | ||
| 172 | int k; | ||
| 173 | |||
| 174 | #if 1 /* optional */ | ||
| 175 | ctx = BN_CTX_new(); | ||
| 176 | if (!ctx) | ||
| 177 | ABORT; | ||
| 178 | #endif | ||
| 179 | |||
| 180 | p = BN_new(); | ||
| 181 | a = BN_new(); | ||
| 182 | b = BN_new(); | ||
| 183 | if (!p || !a || !b) | ||
| 184 | ABORT; | ||
| 185 | |||
| 186 | if (!BN_hex2bn(&p, "17")) | ||
| 187 | ABORT; | ||
| 188 | if (!BN_hex2bn(&a, "1")) | ||
| 189 | ABORT; | ||
| 190 | if (!BN_hex2bn(&b, "1")) | ||
| 191 | ABORT; | ||
| 192 | |||
| 193 | group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp | ||
| 194 | * so that the library gets to choose the EC_METHOD */ | ||
| 195 | if (!group) | ||
| 196 | ABORT; | ||
| 197 | |||
| 198 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 199 | ABORT; | ||
| 200 | |||
| 201 | { | ||
| 202 | EC_GROUP *tmp; | ||
| 203 | tmp = EC_GROUP_new(EC_GROUP_method_of(group)); | ||
| 204 | if (!tmp) | ||
| 205 | ABORT; | ||
| 206 | if (!EC_GROUP_copy(tmp, group)) | ||
| 207 | ABORT; | ||
| 208 | EC_GROUP_free(group); | ||
| 209 | group = tmp; | ||
| 210 | } | ||
| 211 | |||
| 212 | if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) | ||
| 213 | ABORT; | ||
| 214 | |||
| 215 | fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x"); | ||
| 216 | BN_print_fp(stdout, p); | ||
| 217 | fprintf(stdout, ")\n a = 0x"); | ||
| 218 | BN_print_fp(stdout, a); | ||
| 219 | fprintf(stdout, "\n b = 0x"); | ||
| 220 | BN_print_fp(stdout, b); | ||
| 221 | fprintf(stdout, "\n"); | ||
| 222 | |||
| 223 | P = EC_POINT_new(group); | ||
| 224 | Q = EC_POINT_new(group); | ||
| 225 | R = EC_POINT_new(group); | ||
| 226 | if (!P || !Q || !R) | ||
| 227 | ABORT; | ||
| 228 | |||
| 229 | if (!EC_POINT_set_to_infinity(group, P)) | ||
| 230 | ABORT; | ||
| 231 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 232 | ABORT; | ||
| 233 | |||
| 234 | buf[0] = 0; | ||
| 235 | if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) | ||
| 236 | ABORT; | ||
| 237 | |||
| 238 | if (!EC_POINT_add(group, P, P, Q, ctx)) | ||
| 239 | ABORT; | ||
| 240 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 241 | ABORT; | ||
| 242 | |||
| 243 | x = BN_new(); | ||
| 244 | y = BN_new(); | ||
| 245 | z = BN_new(); | ||
| 246 | if (!x || !y || !z) | ||
| 247 | ABORT; | ||
| 248 | |||
| 249 | if (!BN_hex2bn(&x, "D")) | ||
| 250 | ABORT; | ||
| 251 | if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) | ||
| 252 | ABORT; | ||
| 253 | if (!EC_POINT_is_on_curve(group, Q, ctx)) { | ||
| 254 | if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) | ||
| 255 | ABORT; | ||
| 256 | fprintf(stderr, "Point is not on curve: x = 0x"); | ||
| 257 | BN_print_fp(stderr, x); | ||
| 258 | fprintf(stderr, ", y = 0x"); | ||
| 259 | BN_print_fp(stderr, y); | ||
| 260 | fprintf(stderr, "\n"); | ||
| 261 | ABORT; | ||
| 262 | } | ||
| 263 | |||
| 264 | fprintf(stdout, "A cyclic subgroup:\n"); | ||
| 265 | k = 100; | ||
| 266 | do | ||
| 267 | { | ||
| 268 | if (k-- == 0) | ||
| 269 | ABORT; | ||
| 270 | |||
| 271 | if (EC_POINT_is_at_infinity(group, P)) | ||
| 272 | fprintf(stdout, " point at infinity\n"); | ||
| 273 | else { | ||
| 274 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 275 | ABORT; | ||
| 276 | |||
| 277 | fprintf(stdout, " x = 0x"); | ||
| 278 | BN_print_fp(stdout, x); | ||
| 279 | fprintf(stdout, ", y = 0x"); | ||
| 280 | BN_print_fp(stdout, y); | ||
| 281 | fprintf(stdout, "\n"); | ||
| 282 | } | ||
| 283 | |||
| 284 | if (!EC_POINT_copy(R, P)) | ||
| 285 | ABORT; | ||
| 286 | if (!EC_POINT_add(group, P, P, Q, ctx)) | ||
| 287 | ABORT; | ||
| 288 | |||
| 289 | #if 0 /* optional */ | ||
| 290 | { | ||
| 291 | EC_POINT *points[3]; | ||
| 292 | |||
| 293 | points[0] = R; | ||
| 294 | points[1] = Q; | ||
| 295 | points[2] = P; | ||
| 296 | if (!EC_POINTs_make_affine(group, 2, points, ctx)) | ||
| 297 | ABORT; | ||
| 298 | } | ||
| 299 | #endif | ||
| 300 | |||
| 301 | } | ||
| 302 | while (!EC_POINT_is_at_infinity(group, P)); | ||
| 303 | |||
| 304 | if (!EC_POINT_add(group, P, Q, R, ctx)) | ||
| 305 | ABORT; | ||
| 306 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 307 | ABORT; | ||
| 308 | |||
| 309 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); | ||
| 310 | if (len == 0) | ||
| 311 | ABORT; | ||
| 312 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 313 | ABORT; | ||
| 314 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 315 | ABORT; | ||
| 316 | fprintf(stdout, "Generator as octet string, compressed form:\n "); | ||
| 317 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 318 | |||
| 319 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); | ||
| 320 | if (len == 0) | ||
| 321 | ABORT; | ||
| 322 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 323 | ABORT; | ||
| 324 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 325 | ABORT; | ||
| 326 | fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); | ||
| 327 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 328 | |||
| 329 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); | ||
| 330 | if (len == 0) | ||
| 331 | ABORT; | ||
| 332 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 333 | ABORT; | ||
| 334 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 335 | ABORT; | ||
| 336 | fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); | ||
| 337 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 338 | |||
| 339 | if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) | ||
| 340 | ABORT; | ||
| 341 | fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x"); | ||
| 342 | BN_print_fp(stdout, x); | ||
| 343 | fprintf(stdout, ", Y = 0x"); | ||
| 344 | BN_print_fp(stdout, y); | ||
| 345 | fprintf(stdout, ", Z = 0x"); | ||
| 346 | BN_print_fp(stdout, z); | ||
| 347 | fprintf(stdout, "\n"); | ||
| 348 | |||
| 349 | if (!EC_POINT_invert(group, P, ctx)) | ||
| 350 | ABORT; | ||
| 351 | if (0 != EC_POINT_cmp(group, P, R, ctx)) | ||
| 352 | ABORT; | ||
| 353 | |||
| 354 | |||
| 355 | /* Curve secp160r1 (Certicom Research SEC 2 Version 1.0, section 2.4.2, 2000) | ||
| 356 | * -- not a NIST curve, but commonly used */ | ||
| 357 | |||
| 358 | if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF")) | ||
| 359 | ABORT; | ||
| 360 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 361 | ABORT; | ||
| 362 | if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC")) | ||
| 363 | ABORT; | ||
| 364 | if (!BN_hex2bn(&b, "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45")) | ||
| 365 | ABORT; | ||
| 366 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 367 | ABORT; | ||
| 368 | |||
| 369 | if (!BN_hex2bn(&x, "4A96B5688EF573284664698968C38BB913CBFC82")) | ||
| 370 | ABORT; | ||
| 371 | if (!BN_hex2bn(&y, "23a628553168947d59dcc912042351377ac5fb32")) | ||
| 372 | ABORT; | ||
| 373 | if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 374 | ABORT; | ||
| 375 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 376 | ABORT; | ||
| 377 | if (!BN_hex2bn(&z, "0100000000000000000001F4C8F927AED3CA752257")) | ||
| 378 | ABORT; | ||
| 379 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 380 | ABORT; | ||
| 381 | |||
| 382 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 383 | ABORT; | ||
| 384 | fprintf(stdout, "\nSEC2 curve secp160r1 -- Generator:\n x = 0x"); | ||
| 385 | BN_print_fp(stdout, x); | ||
| 386 | fprintf(stdout, "\n y = 0x"); | ||
| 387 | BN_print_fp(stdout, y); | ||
| 388 | fprintf(stdout, "\n"); | ||
| 389 | /* G_y value taken from the standard: */ | ||
| 390 | if (!BN_hex2bn(&z, "23a628553168947d59dcc912042351377ac5fb32")) | ||
| 391 | ABORT; | ||
| 392 | if (0 != BN_cmp(y, z)) | ||
| 393 | ABORT; | ||
| 394 | |||
| 395 | fprintf(stdout, "verify degree ..."); | ||
| 396 | if (EC_GROUP_get_degree(group) != 160) | ||
| 397 | ABORT; | ||
| 398 | fprintf(stdout, " ok\n"); | ||
| 399 | |||
| 400 | group_order_tests(group); | ||
| 401 | |||
| 402 | if (!(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 403 | ABORT; | ||
| 404 | if (!EC_GROUP_copy(P_160, group)) | ||
| 405 | ABORT; | ||
| 406 | |||
| 407 | |||
| 408 | /* Curve P-192 (FIPS PUB 186-2, App. 6) */ | ||
| 409 | |||
| 410 | if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) | ||
| 411 | ABORT; | ||
| 412 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 413 | ABORT; | ||
| 414 | if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) | ||
| 415 | ABORT; | ||
| 416 | if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) | ||
| 417 | ABORT; | ||
| 418 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 419 | ABORT; | ||
| 420 | |||
| 421 | if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) | ||
| 422 | ABORT; | ||
| 423 | if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) | ||
| 424 | ABORT; | ||
| 425 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 426 | ABORT; | ||
| 427 | if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) | ||
| 428 | ABORT; | ||
| 429 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 430 | ABORT; | ||
| 431 | |||
| 432 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 433 | ABORT; | ||
| 434 | fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x"); | ||
| 435 | BN_print_fp(stdout, x); | ||
| 436 | fprintf(stdout, "\n y = 0x"); | ||
| 437 | BN_print_fp(stdout, y); | ||
| 438 | fprintf(stdout, "\n"); | ||
| 439 | /* G_y value taken from the standard: */ | ||
| 440 | if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) | ||
| 441 | ABORT; | ||
| 442 | if (0 != BN_cmp(y, z)) | ||
| 443 | ABORT; | ||
| 444 | |||
| 445 | fprintf(stdout, "verify degree ..."); | ||
| 446 | if (EC_GROUP_get_degree(group) != 192) | ||
| 447 | ABORT; | ||
| 448 | fprintf(stdout, " ok\n"); | ||
| 449 | |||
| 450 | group_order_tests(group); | ||
| 451 | |||
| 452 | if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 453 | ABORT; | ||
| 454 | if (!EC_GROUP_copy(P_192, group)) | ||
| 455 | ABORT; | ||
| 456 | |||
| 457 | |||
| 458 | /* Curve P-224 (FIPS PUB 186-2, App. 6) */ | ||
| 459 | |||
| 460 | if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) | ||
| 461 | ABORT; | ||
| 462 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 463 | ABORT; | ||
| 464 | if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) | ||
| 465 | ABORT; | ||
| 466 | if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) | ||
| 467 | ABORT; | ||
| 468 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 469 | ABORT; | ||
| 470 | |||
| 471 | if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) | ||
| 472 | ABORT; | ||
| 473 | if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) | ||
| 474 | ABORT; | ||
| 475 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 476 | ABORT; | ||
| 477 | if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) | ||
| 478 | ABORT; | ||
| 479 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 480 | ABORT; | ||
| 481 | |||
| 482 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 483 | ABORT; | ||
| 484 | fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x"); | ||
| 485 | BN_print_fp(stdout, x); | ||
| 486 | fprintf(stdout, "\n y = 0x"); | ||
| 487 | BN_print_fp(stdout, y); | ||
| 488 | fprintf(stdout, "\n"); | ||
| 489 | /* G_y value taken from the standard: */ | ||
| 490 | if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) | ||
| 491 | ABORT; | ||
| 492 | if (0 != BN_cmp(y, z)) | ||
| 493 | ABORT; | ||
| 494 | |||
| 495 | fprintf(stdout, "verify degree ..."); | ||
| 496 | if (EC_GROUP_get_degree(group) != 224) | ||
| 497 | ABORT; | ||
| 498 | fprintf(stdout, " ok\n"); | ||
| 499 | |||
| 500 | group_order_tests(group); | ||
| 501 | |||
| 502 | if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 503 | ABORT; | ||
| 504 | if (!EC_GROUP_copy(P_224, group)) | ||
| 505 | ABORT; | ||
| 506 | |||
| 507 | |||
| 508 | /* Curve P-256 (FIPS PUB 186-2, App. 6) */ | ||
| 509 | |||
| 510 | if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) | ||
| 511 | ABORT; | ||
| 512 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 513 | ABORT; | ||
| 514 | if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) | ||
| 515 | ABORT; | ||
| 516 | if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) | ||
| 517 | ABORT; | ||
| 518 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 519 | ABORT; | ||
| 520 | |||
| 521 | if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) | ||
| 522 | ABORT; | ||
| 523 | if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) | ||
| 524 | ABORT; | ||
| 525 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 526 | ABORT; | ||
| 527 | if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E" | ||
| 528 | "84F3B9CAC2FC632551")) ABORT; | ||
| 529 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 530 | ABORT; | ||
| 531 | |||
| 532 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 533 | ABORT; | ||
| 534 | fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x"); | ||
| 535 | BN_print_fp(stdout, x); | ||
| 536 | fprintf(stdout, "\n y = 0x"); | ||
| 537 | BN_print_fp(stdout, y); | ||
| 538 | fprintf(stdout, "\n"); | ||
| 539 | /* G_y value taken from the standard: */ | ||
| 540 | if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) | ||
| 541 | ABORT; | ||
| 542 | if (0 != BN_cmp(y, z)) | ||
| 543 | ABORT; | ||
| 544 | |||
| 545 | fprintf(stdout, "verify degree ..."); | ||
| 546 | if (EC_GROUP_get_degree(group) != 256) | ||
| 547 | ABORT; | ||
| 548 | fprintf(stdout, " ok\n"); | ||
| 549 | |||
| 550 | group_order_tests(group); | ||
| 551 | |||
| 552 | if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 553 | ABORT; | ||
| 554 | if (!EC_GROUP_copy(P_256, group)) | ||
| 555 | ABORT; | ||
| 556 | |||
| 557 | |||
| 558 | /* Curve P-384 (FIPS PUB 186-2, App. 6) */ | ||
| 559 | |||
| 560 | if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 561 | "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT; | ||
| 562 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 563 | ABORT; | ||
| 564 | if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 565 | "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT; | ||
| 566 | if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141" | ||
| 567 | "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT; | ||
| 568 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 569 | ABORT; | ||
| 570 | |||
| 571 | if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B" | ||
| 572 | "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT; | ||
| 573 | if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) | ||
| 574 | ABORT; | ||
| 575 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 576 | ABORT; | ||
| 577 | if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 578 | "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT; | ||
| 579 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 580 | ABORT; | ||
| 581 | |||
| 582 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 583 | ABORT; | ||
| 584 | fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x"); | ||
| 585 | BN_print_fp(stdout, x); | ||
| 586 | fprintf(stdout, "\n y = 0x"); | ||
| 587 | BN_print_fp(stdout, y); | ||
| 588 | fprintf(stdout, "\n"); | ||
| 589 | /* G_y value taken from the standard: */ | ||
| 590 | if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14" | ||
| 591 | "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT; | ||
| 592 | if (0 != BN_cmp(y, z)) | ||
| 593 | ABORT; | ||
| 594 | |||
| 595 | fprintf(stdout, "verify degree ..."); | ||
| 596 | if (EC_GROUP_get_degree(group) != 384) | ||
| 597 | ABORT; | ||
| 598 | fprintf(stdout, " ok\n"); | ||
| 599 | |||
| 600 | group_order_tests(group); | ||
| 601 | |||
| 602 | if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 603 | ABORT; | ||
| 604 | if (!EC_GROUP_copy(P_384, group)) | ||
| 605 | ABORT; | ||
| 606 | |||
| 607 | |||
| 608 | /* Curve P-521 (FIPS PUB 186-2, App. 6) */ | ||
| 609 | |||
| 610 | if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 611 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 612 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT; | ||
| 613 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 614 | ABORT; | ||
| 615 | if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 616 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 617 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT; | ||
| 618 | if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B" | ||
| 619 | "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573" | ||
| 620 | "DF883D2C34F1EF451FD46B503F00")) ABORT; | ||
| 621 | if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) | ||
| 622 | ABORT; | ||
| 623 | |||
| 624 | if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F" | ||
| 625 | "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B" | ||
| 626 | "3C1856A429BF97E7E31C2E5BD66")) ABORT; | ||
| 627 | if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) | ||
| 628 | ABORT; | ||
| 629 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 630 | ABORT; | ||
| 631 | if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" | ||
| 632 | "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5" | ||
| 633 | "C9B8899C47AEBB6FB71E91386409")) ABORT; | ||
| 634 | if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) | ||
| 635 | ABORT; | ||
| 636 | |||
| 637 | if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) | ||
| 638 | ABORT; | ||
| 639 | fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x"); | ||
| 640 | BN_print_fp(stdout, x); | ||
| 641 | fprintf(stdout, "\n y = 0x"); | ||
| 642 | BN_print_fp(stdout, y); | ||
| 643 | fprintf(stdout, "\n"); | ||
| 644 | /* G_y value taken from the standard: */ | ||
| 645 | if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579" | ||
| 646 | "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C" | ||
| 647 | "7086A272C24088BE94769FD16650")) ABORT; | ||
| 648 | if (0 != BN_cmp(y, z)) | ||
| 649 | ABORT; | ||
| 650 | |||
| 651 | fprintf(stdout, "verify degree ..."); | ||
| 652 | if (EC_GROUP_get_degree(group) != 521) | ||
| 653 | ABORT; | ||
| 654 | fprintf(stdout, " ok\n"); | ||
| 655 | |||
| 656 | group_order_tests(group); | ||
| 657 | |||
| 658 | if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) | ||
| 659 | ABORT; | ||
| 660 | if (!EC_GROUP_copy(P_521, group)) | ||
| 661 | ABORT; | ||
| 662 | |||
| 663 | |||
| 664 | /* more tests using the last curve */ | ||
| 665 | fprintf(stdout, "infinity tests ..."); | ||
| 666 | fflush(stdout); | ||
| 667 | if (!EC_POINT_copy(Q, P)) | ||
| 668 | ABORT; | ||
| 669 | if (EC_POINT_is_at_infinity(group, Q)) | ||
| 670 | ABORT; | ||
| 671 | /* P := 2P */ | ||
| 672 | if (!EC_POINT_dbl(group, P, P, ctx)) | ||
| 673 | ABORT; | ||
| 674 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 675 | ABORT; | ||
| 676 | /* Q := -P */ | ||
| 677 | if (!EC_POINT_invert(group, Q, ctx)) | ||
| 678 | ABORT; | ||
| 679 | /* R := 2P - P = P */ | ||
| 680 | if (!EC_POINT_add(group, R, P, Q, ctx)) | ||
| 681 | ABORT; | ||
| 682 | /* R := R + Q = P - P = infty */ | ||
| 683 | if (!EC_POINT_add(group, R, R, Q, ctx)) | ||
| 684 | ABORT; | ||
| 685 | if (!EC_POINT_is_at_infinity(group, R)) | ||
| 686 | ABORT; | ||
| 687 | fprintf(stdout, " ok\n\n"); | ||
| 688 | |||
| 689 | if (ctx) | ||
| 690 | BN_CTX_free(ctx); | ||
| 691 | BN_free(p); | ||
| 692 | BN_free(a); | ||
| 693 | BN_free(b); | ||
| 694 | EC_GROUP_free(group); | ||
| 695 | EC_POINT_free(P); | ||
| 696 | EC_POINT_free(Q); | ||
| 697 | EC_POINT_free(R); | ||
| 698 | BN_free(x); | ||
| 699 | BN_free(y); | ||
| 700 | BN_free(z); | ||
| 701 | |||
| 702 | if (P_160) | ||
| 703 | EC_GROUP_free(P_160); | ||
| 704 | if (P_192) | ||
| 705 | EC_GROUP_free(P_192); | ||
| 706 | if (P_224) | ||
| 707 | EC_GROUP_free(P_224); | ||
| 708 | if (P_256) | ||
| 709 | EC_GROUP_free(P_256); | ||
| 710 | if (P_384) | ||
| 711 | EC_GROUP_free(P_384); | ||
| 712 | if (P_521) | ||
| 713 | EC_GROUP_free(P_521); | ||
| 714 | |||
| 715 | } | ||
| 716 | |||
| 717 | /* Change test based on whether binary point compression is enabled or not. */ | ||
| 718 | #ifdef OPENSSL_EC_BIN_PT_COMP | ||
| 719 | #define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ | ||
| 720 | if (!BN_hex2bn(&x, _x)) ABORT; \ | ||
| 721 | if (!EC_POINT_set_compressed_coordinates_GF2m(group, P, x, _y_bit, ctx)) ABORT; \ | ||
| 722 | if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ | ||
| 723 | if (!BN_hex2bn(&z, _order)) ABORT; \ | ||
| 724 | if (!BN_hex2bn(&cof, _cof)) ABORT; \ | ||
| 725 | if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ | ||
| 726 | if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ | ||
| 727 | fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ | ||
| 728 | BN_print_fp(stdout, x); \ | ||
| 729 | fprintf(stdout, "\n y = 0x"); \ | ||
| 730 | BN_print_fp(stdout, y); \ | ||
| 731 | fprintf(stdout, "\n"); \ | ||
| 732 | /* G_y value taken from the standard: */ \ | ||
| 733 | if (!BN_hex2bn(&z, _y)) ABORT; \ | ||
| 734 | if (0 != BN_cmp(y, z)) ABORT; | ||
| 735 | #else | ||
| 736 | #define CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ | ||
| 737 | if (!BN_hex2bn(&x, _x)) ABORT; \ | ||
| 738 | if (!BN_hex2bn(&y, _y)) ABORT; \ | ||
| 739 | if (!EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx)) ABORT; \ | ||
| 740 | if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT; \ | ||
| 741 | if (!BN_hex2bn(&z, _order)) ABORT; \ | ||
| 742 | if (!BN_hex2bn(&cof, _cof)) ABORT; \ | ||
| 743 | if (!EC_GROUP_set_generator(group, P, z, cof)) ABORT; \ | ||
| 744 | fprintf(stdout, "\n%s -- Generator:\n x = 0x", _name); \ | ||
| 745 | BN_print_fp(stdout, x); \ | ||
| 746 | fprintf(stdout, "\n y = 0x"); \ | ||
| 747 | BN_print_fp(stdout, y); \ | ||
| 748 | fprintf(stdout, "\n"); | ||
| 749 | #endif | ||
| 750 | |||
| 751 | #define CHAR2_CURVE_TEST(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ | ||
| 752 | if (!BN_hex2bn(&p, _p)) ABORT; \ | ||
| 753 | if (!BN_hex2bn(&a, _a)) ABORT; \ | ||
| 754 | if (!BN_hex2bn(&b, _b)) ABORT; \ | ||
| 755 | if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) ABORT; \ | ||
| 756 | CHAR2_CURVE_TEST_INTERNAL(_name, _p, _a, _b, _x, _y, _y_bit, _order, _cof, _degree, _variable) \ | ||
| 757 | fprintf(stdout, "verify degree ..."); \ | ||
| 758 | if (EC_GROUP_get_degree(group) != _degree) ABORT; \ | ||
| 759 | fprintf(stdout, " ok\n"); \ | ||
| 760 | group_order_tests(group); \ | ||
| 761 | if (!(_variable = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT; \ | ||
| 762 | if (!EC_GROUP_copy(_variable, group)) ABORT; \ | ||
| 763 | |||
| 764 | #ifndef OPENSSL_NO_EC2M | ||
| 765 | |||
| 766 | static void char2_field_tests(void) | ||
| 767 | { | ||
| 768 | BN_CTX *ctx = NULL; | ||
| 769 | BIGNUM *p, *a, *b; | ||
| 770 | EC_GROUP *group; | ||
| 771 | EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 = NULL, *C2_K571 = NULL; | ||
| 772 | EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 = NULL, *C2_B571 = NULL; | ||
| 773 | EC_POINT *P, *Q, *R; | ||
| 774 | BIGNUM *x, *y, *z, *cof; | ||
| 775 | unsigned char buf[100]; | ||
| 776 | size_t i, len; | ||
| 777 | int k; | ||
| 778 | |||
| 779 | #if 1 /* optional */ | ||
| 780 | ctx = BN_CTX_new(); | ||
| 781 | if (!ctx) | ||
| 782 | ABORT; | ||
| 783 | #endif | ||
| 784 | |||
| 785 | p = BN_new(); | ||
| 786 | a = BN_new(); | ||
| 787 | b = BN_new(); | ||
| 788 | if (!p || !a || !b) | ||
| 789 | ABORT; | ||
| 790 | |||
| 791 | if (!BN_hex2bn(&p, "13")) | ||
| 792 | ABORT; | ||
| 793 | if (!BN_hex2bn(&a, "3")) | ||
| 794 | ABORT; | ||
| 795 | if (!BN_hex2bn(&b, "1")) | ||
| 796 | ABORT; | ||
| 797 | |||
| 798 | group = EC_GROUP_new(EC_GF2m_simple_method()); /* applications should use EC_GROUP_new_curve_GF2m | ||
| 799 | * so that the library gets to choose the EC_METHOD */ | ||
| 800 | if (!group) | ||
| 801 | ABORT; | ||
| 802 | if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx)) | ||
| 803 | ABORT; | ||
| 804 | |||
| 805 | { | ||
| 806 | EC_GROUP *tmp; | ||
| 807 | tmp = EC_GROUP_new(EC_GROUP_method_of(group)); | ||
| 808 | if (!tmp) | ||
| 809 | ABORT; | ||
| 810 | if (!EC_GROUP_copy(tmp, group)) | ||
| 811 | ABORT; | ||
| 812 | EC_GROUP_free(group); | ||
| 813 | group = tmp; | ||
| 814 | } | ||
| 815 | |||
| 816 | if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)) | ||
| 817 | ABORT; | ||
| 818 | |||
| 819 | fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x"); | ||
| 820 | BN_print_fp(stdout, p); | ||
| 821 | fprintf(stdout, ")\n a = 0x"); | ||
| 822 | BN_print_fp(stdout, a); | ||
| 823 | fprintf(stdout, "\n b = 0x"); | ||
| 824 | BN_print_fp(stdout, b); | ||
| 825 | fprintf(stdout, "\n(0x... means binary polynomial)\n"); | ||
| 826 | |||
| 827 | P = EC_POINT_new(group); | ||
| 828 | Q = EC_POINT_new(group); | ||
| 829 | R = EC_POINT_new(group); | ||
| 830 | if (!P || !Q || !R) | ||
| 831 | ABORT; | ||
| 832 | |||
| 833 | if (!EC_POINT_set_to_infinity(group, P)) | ||
| 834 | ABORT; | ||
| 835 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 836 | ABORT; | ||
| 837 | |||
| 838 | buf[0] = 0; | ||
| 839 | if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) | ||
| 840 | ABORT; | ||
| 841 | |||
| 842 | if (!EC_POINT_add(group, P, P, Q, ctx)) | ||
| 843 | ABORT; | ||
| 844 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 845 | ABORT; | ||
| 846 | |||
| 847 | x = BN_new(); | ||
| 848 | y = BN_new(); | ||
| 849 | z = BN_new(); | ||
| 850 | cof = BN_new(); | ||
| 851 | if (!x || !y || !z || !cof) | ||
| 852 | ABORT; | ||
| 853 | |||
| 854 | if (!BN_hex2bn(&x, "6")) | ||
| 855 | ABORT; | ||
| 856 | /* Change test based on whether binary point compression is enabled or not. */ | ||
| 857 | #ifdef OPENSSL_EC_BIN_PT_COMP | ||
| 858 | if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx)) | ||
| 859 | ABORT; | ||
| 860 | #else | ||
| 861 | if (!BN_hex2bn(&y, "8")) | ||
| 862 | ABORT; | ||
| 863 | if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx)) | ||
| 864 | ABORT; | ||
| 865 | #endif | ||
| 866 | if (!EC_POINT_is_on_curve(group, Q, ctx)) { | ||
| 867 | /* Change test based on whether binary point compression is enabled or not. */ | ||
| 868 | #ifdef OPENSSL_EC_BIN_PT_COMP | ||
| 869 | if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx)) | ||
| 870 | ABORT; | ||
| 871 | #endif | ||
| 872 | fprintf(stderr, "Point is not on curve: x = 0x"); | ||
| 873 | BN_print_fp(stderr, x); | ||
| 874 | fprintf(stderr, ", y = 0x"); | ||
| 875 | BN_print_fp(stderr, y); | ||
| 876 | fprintf(stderr, "\n"); | ||
| 877 | ABORT; | ||
| 878 | } | ||
| 879 | |||
| 880 | fprintf(stdout, "A cyclic subgroup:\n"); | ||
| 881 | k = 100; | ||
| 882 | do | ||
| 883 | { | ||
| 884 | if (k-- == 0) | ||
| 885 | ABORT; | ||
| 886 | |||
| 887 | if (EC_POINT_is_at_infinity(group, P)) | ||
| 888 | fprintf(stdout, " point at infinity\n"); | ||
| 889 | else { | ||
| 890 | if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx)) | ||
| 891 | ABORT; | ||
| 892 | |||
| 893 | fprintf(stdout, " x = 0x"); | ||
| 894 | BN_print_fp(stdout, x); | ||
| 895 | fprintf(stdout, ", y = 0x"); | ||
| 896 | BN_print_fp(stdout, y); | ||
| 897 | fprintf(stdout, "\n"); | ||
| 898 | } | ||
| 899 | |||
| 900 | if (!EC_POINT_copy(R, P)) | ||
| 901 | ABORT; | ||
| 902 | if (!EC_POINT_add(group, P, P, Q, ctx)) | ||
| 903 | ABORT; | ||
| 904 | } | ||
| 905 | while (!EC_POINT_is_at_infinity(group, P)); | ||
| 906 | |||
| 907 | if (!EC_POINT_add(group, P, Q, R, ctx)) | ||
| 908 | ABORT; | ||
| 909 | if (!EC_POINT_is_at_infinity(group, P)) | ||
| 910 | ABORT; | ||
| 911 | |||
| 912 | /* Change test based on whether binary point compression is enabled or not. */ | ||
| 913 | #ifdef OPENSSL_EC_BIN_PT_COMP | ||
| 914 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx); | ||
| 915 | if (len == 0) | ||
| 916 | ABORT; | ||
| 917 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 918 | ABORT; | ||
| 919 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 920 | ABORT; | ||
| 921 | fprintf(stdout, "Generator as octet string, compressed form:\n "); | ||
| 922 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 923 | #endif | ||
| 924 | |||
| 925 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx); | ||
| 926 | if (len == 0) | ||
| 927 | ABORT; | ||
| 928 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 929 | ABORT; | ||
| 930 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 931 | ABORT; | ||
| 932 | fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n "); | ||
| 933 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 934 | |||
| 935 | /* Change test based on whether binary point compression is enabled or not. */ | ||
| 936 | #ifdef OPENSSL_EC_BIN_PT_COMP | ||
| 937 | len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx); | ||
| 938 | if (len == 0) | ||
| 939 | ABORT; | ||
| 940 | if (!EC_POINT_oct2point(group, P, buf, len, ctx)) | ||
| 941 | ABORT; | ||
| 942 | if (0 != EC_POINT_cmp(group, P, Q, ctx)) | ||
| 943 | ABORT; | ||
| 944 | fprintf(stdout, "\nGenerator as octet string, hybrid form:\n "); | ||
| 945 | for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]); | ||
| 946 | #endif | ||
| 947 | |||
| 948 | fprintf(stdout, "\n"); | ||
| 949 | |||
| 950 | if (!EC_POINT_invert(group, P, ctx)) | ||
| 951 | ABORT; | ||
| 952 | if (0 != EC_POINT_cmp(group, P, R, ctx)) | ||
| 953 | ABORT; | ||
| 954 | |||
| 955 | |||
| 956 | /* Curve K-163 (FIPS PUB 186-2, App. 6) */ | ||
| 957 | CHAR2_CURVE_TEST | ||
| 958 | ( | ||
| 959 | "NIST curve K-163", | ||
| 960 | "0800000000000000000000000000000000000000C9", | ||
| 961 | "1", | ||
| 962 | "1", | ||
| 963 | "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8", | ||
| 964 | "0289070FB05D38FF58321F2E800536D538CCDAA3D9", | ||
| 965 | 1, | ||
| 966 | "04000000000000000000020108A2E0CC0D99F8A5EF", | ||
| 967 | "2", | ||
| 968 | 163, | ||
| 969 | C2_K163 | ||
| 970 | ); | ||
| 971 | |||
| 972 | /* Curve B-163 (FIPS PUB 186-2, App. 6) */ | ||
| 973 | CHAR2_CURVE_TEST | ||
| 974 | ( | ||
| 975 | "NIST curve B-163", | ||
| 976 | "0800000000000000000000000000000000000000C9", | ||
| 977 | "1", | ||
| 978 | "020A601907B8C953CA1481EB10512F78744A3205FD", | ||
| 979 | "03F0EBA16286A2D57EA0991168D4994637E8343E36", | ||
| 980 | "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", | ||
| 981 | 1, | ||
| 982 | "040000000000000000000292FE77E70C12A4234C33", | ||
| 983 | "2", | ||
| 984 | 163, | ||
| 985 | C2_B163 | ||
| 986 | ); | ||
| 987 | |||
| 988 | /* Curve K-233 (FIPS PUB 186-2, App. 6) */ | ||
| 989 | CHAR2_CURVE_TEST | ||
| 990 | ( | ||
| 991 | "NIST curve K-233", | ||
| 992 | "020000000000000000000000000000000000000004000000000000000001", | ||
| 993 | "0", | ||
| 994 | "1", | ||
| 995 | "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126", | ||
| 996 | "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3", | ||
| 997 | 0, | ||
| 998 | "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF", | ||
| 999 | "4", | ||
| 1000 | 233, | ||
| 1001 | C2_K233 | ||
| 1002 | ); | ||
| 1003 | |||
| 1004 | /* Curve B-233 (FIPS PUB 186-2, App. 6) */ | ||
| 1005 | CHAR2_CURVE_TEST | ||
| 1006 | ( | ||
| 1007 | "NIST curve B-233", | ||
| 1008 | "020000000000000000000000000000000000000004000000000000000001", | ||
| 1009 | "000000000000000000000000000000000000000000000000000000000001", | ||
| 1010 | "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD", | ||
| 1011 | "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B", | ||
| 1012 | "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052", | ||
| 1013 | 1, | ||
| 1014 | "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7", | ||
| 1015 | "2", | ||
| 1016 | 233, | ||
| 1017 | C2_B233 | ||
| 1018 | ); | ||
| 1019 | |||
| 1020 | /* Curve K-283 (FIPS PUB 186-2, App. 6) */ | ||
| 1021 | CHAR2_CURVE_TEST | ||
| 1022 | ( | ||
| 1023 | "NIST curve K-283", | ||
| 1024 | "0800000000000000000000000000000000000000000000000000000000000000000010A1", | ||
| 1025 | "0", | ||
| 1026 | "1", | ||
| 1027 | "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836", | ||
| 1028 | "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259", | ||
| 1029 | 0, | ||
| 1030 | "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61", | ||
| 1031 | "4", | ||
| 1032 | 283, | ||
| 1033 | C2_K283 | ||
| 1034 | ); | ||
| 1035 | |||
| 1036 | /* Curve B-283 (FIPS PUB 186-2, App. 6) */ | ||
| 1037 | CHAR2_CURVE_TEST | ||
| 1038 | ( | ||
| 1039 | "NIST curve B-283", | ||
| 1040 | "0800000000000000000000000000000000000000000000000000000000000000000010A1", | ||
| 1041 | "000000000000000000000000000000000000000000000000000000000000000000000001", | ||
| 1042 | "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5", | ||
| 1043 | "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053", | ||
| 1044 | "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4", | ||
| 1045 | 1, | ||
| 1046 | "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307", | ||
| 1047 | "2", | ||
| 1048 | 283, | ||
| 1049 | C2_B283 | ||
| 1050 | ); | ||
| 1051 | |||
| 1052 | /* Curve K-409 (FIPS PUB 186-2, App. 6) */ | ||
| 1053 | CHAR2_CURVE_TEST | ||
| 1054 | ( | ||
| 1055 | "NIST curve K-409", | ||
| 1056 | "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", | ||
| 1057 | "0", | ||
| 1058 | "1", | ||
| 1059 | "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746", | ||
| 1060 | "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B", | ||
| 1061 | 1, | ||
| 1062 | "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF", | ||
| 1063 | "4", | ||
| 1064 | 409, | ||
| 1065 | C2_K409 | ||
| 1066 | ); | ||
| 1067 | |||
| 1068 | /* Curve B-409 (FIPS PUB 186-2, App. 6) */ | ||
| 1069 | CHAR2_CURVE_TEST | ||
| 1070 | ( | ||
| 1071 | "NIST curve B-409", | ||
| 1072 | "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001", | ||
| 1073 | "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", | ||
| 1074 | "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F", | ||
| 1075 | "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7", | ||
| 1076 | "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706", | ||
| 1077 | 1, | ||
| 1078 | "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173", | ||
| 1079 | "2", | ||
| 1080 | 409, | ||
| 1081 | C2_B409 | ||
| 1082 | ); | ||
| 1083 | |||
| 1084 | /* Curve K-571 (FIPS PUB 186-2, App. 6) */ | ||
| 1085 | CHAR2_CURVE_TEST | ||
| 1086 | ( | ||
| 1087 | "NIST curve K-571", | ||
| 1088 | "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", | ||
| 1089 | "0", | ||
| 1090 | "1", | ||
| 1091 | "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972", | ||
| 1092 | "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3", | ||
| 1093 | 0, | ||
| 1094 | "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001", | ||
| 1095 | "4", | ||
| 1096 | 571, | ||
| 1097 | C2_K571 | ||
| 1098 | ); | ||
| 1099 | |||
| 1100 | /* Curve B-571 (FIPS PUB 186-2, App. 6) */ | ||
| 1101 | CHAR2_CURVE_TEST | ||
| 1102 | ( | ||
| 1103 | "NIST curve B-571", | ||
| 1104 | "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425", | ||
| 1105 | "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", | ||
| 1106 | "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A", | ||
| 1107 | "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19", | ||
| 1108 | "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B", | ||
| 1109 | 1, | ||
| 1110 | "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47", | ||
| 1111 | "2", | ||
| 1112 | 571, | ||
| 1113 | C2_B571 | ||
| 1114 | ); | ||
| 1115 | |||
| 1116 | /* more tests using the last curve */ | ||
| 1117 | fprintf(stdout, "infinity tests ..."); | ||
| 1118 | fflush(stdout); | ||
| 1119 | if (!EC_POINT_copy(Q, P)) | ||
| 1120 | ABORT; | ||
| 1121 | if (EC_POINT_is_at_infinity(group, Q)) | ||
| 1122 | ABORT; | ||
| 1123 | /* P := 2P */ | ||
| 1124 | if (!EC_POINT_dbl(group, P, P, ctx)) | ||
| 1125 | ABORT; | ||
| 1126 | if (!EC_POINT_is_on_curve(group, P, ctx)) | ||
| 1127 | ABORT; | ||
| 1128 | /* Q := -P */ | ||
| 1129 | if (!EC_POINT_invert(group, Q, ctx)) | ||
| 1130 | ABORT; | ||
| 1131 | /* R := 2P - P = P */ | ||
| 1132 | if (!EC_POINT_add(group, R, P, Q, ctx)) | ||
| 1133 | ABORT; | ||
| 1134 | /* R := R + Q = P - P = infty */ | ||
| 1135 | if (!EC_POINT_add(group, R, R, Q, ctx)) | ||
| 1136 | ABORT; | ||
| 1137 | if (!EC_POINT_is_at_infinity(group, R)) | ||
| 1138 | ABORT; | ||
| 1139 | fprintf(stdout, " ok\n\n"); | ||
| 1140 | |||
| 1141 | if (ctx) | ||
| 1142 | BN_CTX_free(ctx); | ||
| 1143 | BN_free(p); | ||
| 1144 | BN_free(a); | ||
| 1145 | BN_free(b); | ||
| 1146 | EC_GROUP_free(group); | ||
| 1147 | EC_POINT_free(P); | ||
| 1148 | EC_POINT_free(Q); | ||
| 1149 | EC_POINT_free(R); | ||
| 1150 | BN_free(x); | ||
| 1151 | BN_free(y); | ||
| 1152 | BN_free(z); | ||
| 1153 | BN_free(cof); | ||
| 1154 | |||
| 1155 | if (C2_K163) | ||
| 1156 | EC_GROUP_free(C2_K163); | ||
| 1157 | if (C2_B163) | ||
| 1158 | EC_GROUP_free(C2_B163); | ||
| 1159 | if (C2_K233) | ||
| 1160 | EC_GROUP_free(C2_K233); | ||
| 1161 | if (C2_B233) | ||
| 1162 | EC_GROUP_free(C2_B233); | ||
| 1163 | if (C2_K283) | ||
| 1164 | EC_GROUP_free(C2_K283); | ||
| 1165 | if (C2_B283) | ||
| 1166 | EC_GROUP_free(C2_B283); | ||
| 1167 | if (C2_K409) | ||
| 1168 | EC_GROUP_free(C2_K409); | ||
| 1169 | if (C2_B409) | ||
| 1170 | EC_GROUP_free(C2_B409); | ||
| 1171 | if (C2_K571) | ||
| 1172 | EC_GROUP_free(C2_K571); | ||
| 1173 | if (C2_B571) | ||
| 1174 | EC_GROUP_free(C2_B571); | ||
| 1175 | |||
| 1176 | } | ||
| 1177 | #endif | ||
| 1178 | |||
| 1179 | static void | ||
| 1180 | internal_curve_test(void) | ||
| 1181 | { | ||
| 1182 | EC_builtin_curve *curves = NULL; | ||
| 1183 | size_t crv_len = 0, n = 0; | ||
| 1184 | int ok = 1; | ||
| 1185 | |||
| 1186 | crv_len = EC_get_builtin_curves(NULL, 0); | ||
| 1187 | |||
| 1188 | curves = reallocarray(NULL, sizeof(EC_builtin_curve), crv_len); | ||
| 1189 | |||
| 1190 | if (curves == NULL) | ||
| 1191 | return; | ||
| 1192 | |||
| 1193 | if (!EC_get_builtin_curves(curves, crv_len)) { | ||
| 1194 | free(curves); | ||
| 1195 | return; | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | fprintf(stdout, "testing internal curves: "); | ||
| 1199 | |||
| 1200 | for (n = 0; n < crv_len; n++) { | ||
| 1201 | EC_GROUP *group = NULL; | ||
| 1202 | int nid = curves[n].nid; | ||
| 1203 | if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) { | ||
| 1204 | ok = 0; | ||
| 1205 | fprintf(stdout, "\nEC_GROUP_new_curve_name() failed with" | ||
| 1206 | " curve %s\n", OBJ_nid2sn(nid)); | ||
| 1207 | /* try next curve */ | ||
| 1208 | continue; | ||
| 1209 | } | ||
| 1210 | if (!EC_GROUP_check(group, NULL)) { | ||
| 1211 | ok = 0; | ||
| 1212 | fprintf(stdout, "\nEC_GROUP_check() failed with" | ||
| 1213 | " curve %s\n", OBJ_nid2sn(nid)); | ||
| 1214 | EC_GROUP_free(group); | ||
| 1215 | /* try the next curve */ | ||
| 1216 | continue; | ||
| 1217 | } | ||
| 1218 | fprintf(stdout, "."); | ||
| 1219 | fflush(stdout); | ||
| 1220 | EC_GROUP_free(group); | ||
| 1221 | } | ||
| 1222 | if (ok) | ||
| 1223 | fprintf(stdout, " ok\n\n"); | ||
| 1224 | else { | ||
| 1225 | fprintf(stdout, " failed\n\n"); | ||
| 1226 | ABORT; | ||
| 1227 | } | ||
| 1228 | free(curves); | ||
| 1229 | return; | ||
| 1230 | } | ||
| 1231 | |||
| 1232 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 | ||
| 1233 | /* nistp_test_params contains magic numbers for testing our optimized | ||
| 1234 | * implementations of several NIST curves with characteristic > 3. */ | ||
| 1235 | struct nistp_test_params { | ||
| 1236 | const EC_METHOD* (*meth) (); | ||
| 1237 | int degree; | ||
| 1238 | /* Qx, Qy and D are taken from | ||
| 1239 | * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/ECDSA_Prime.pdf | ||
| 1240 | * Otherwise, values are standard curve parameters from FIPS 180-3 */ | ||
| 1241 | const char *p, *a, *b, *Qx, *Qy, *Gx, *Gy, *order, *d; | ||
| 1242 | }; | ||
| 1243 | |||
| 1244 | static const struct nistp_test_params nistp_tests_params[] = { { | ||
| 1245 | /* P-224 */ | ||
| 1246 | EC_GFp_nistp224_method, | ||
| 1247 | 224, | ||
| 1248 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", /* p */ | ||
| 1249 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", /* a */ | ||
| 1250 | "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", /* b */ | ||
| 1251 | "E84FB0B8E7000CB657D7973CF6B42ED78B301674276DF744AF130B3E", /* Qx */ | ||
| 1252 | "4376675C6FC5612C21A0FF2D2A89D2987DF7A2BC52183B5982298555", /* Qy */ | ||
| 1253 | "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", /* Gx */ | ||
| 1254 | "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", /* Gy */ | ||
| 1255 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", /* order */ | ||
| 1256 | "3F0C488E987C80BE0FEE521F8D90BE6034EC69AE11CA72AA777481E8", /* d */ | ||
| 1257 | }, | ||
| 1258 | { | ||
| 1259 | /* P-256 */ | ||
| 1260 | EC_GFp_nistp256_method, | ||
| 1261 | 256, | ||
| 1262 | "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff", /* p */ | ||
| 1263 | "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc", /* a */ | ||
| 1264 | "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b", /* b */ | ||
| 1265 | "b7e08afdfe94bad3f1dc8c734798ba1c62b3a0ad1e9ea2a38201cd0889bc7a19", /* Qx */ | ||
| 1266 | "3603f747959dbf7a4bb226e41928729063adc7ae43529e61b563bbc606cc5e09", /* Qy */ | ||
| 1267 | "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296", /* Gx */ | ||
| 1268 | "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", /* Gy */ | ||
| 1269 | "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", /* order */ | ||
| 1270 | "c477f9f65c22cce20657faa5b2d1d8122336f851a508a1ed04e479c34985bf96", /* d */ | ||
| 1271 | }, | ||
| 1272 | { | ||
| 1273 | /* P-521 */ | ||
| 1274 | EC_GFp_nistp521_method, | ||
| 1275 | 521, | ||
| 1276 | "1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", /* p */ | ||
| 1277 | "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc", /* a */ | ||
| 1278 | "051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00", /* b */ | ||
| 1279 | "0098e91eef9a68452822309c52fab453f5f117c1da8ed796b255e9ab8f6410cca16e59df403a6bdc6ca467a37056b1e54b3005d8ac030decfeb68df18b171885d5c4", /* Qx */ | ||
| 1280 | "0164350c321aecfc1cca1ba4364c9b15656150b4b78d6a48d7d28e7f31985ef17be8554376b72900712c4b83ad668327231526e313f5f092999a4632fd50d946bc2e", /* Qy */ | ||
| 1281 | "c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66", /* Gx */ | ||
| 1282 | "11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", /* Gy */ | ||
| 1283 | "1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", /* order */ | ||
| 1284 | "0100085f47b8e1b8b11b7eb33028c0b2888e304bfc98501955b45bba1478dc184eeedf09b86a5f7c21994406072787205e69a63709fe35aa93ba333514b24f961722", /* d */ | ||
| 1285 | }, | ||
| 1286 | }; | ||
| 1287 | |||
| 1288 | void | ||
| 1289 | nistp_single_test(const struct nistp_test_params *test) | ||
| 1290 | { | ||
| 1291 | BN_CTX *ctx; | ||
| 1292 | BIGNUM *p, *a, *b, *x, *y, *n, *m, *order; | ||
| 1293 | EC_GROUP *NISTP; | ||
| 1294 | EC_POINT *G, *P, *Q, *Q_CHECK; | ||
| 1295 | |||
| 1296 | fprintf(stdout, "\nNIST curve P-%d (optimised implementation):\n", test->degree); | ||
| 1297 | ctx = BN_CTX_new(); | ||
| 1298 | p = BN_new(); | ||
| 1299 | a = BN_new(); | ||
| 1300 | b = BN_new(); | ||
| 1301 | x = BN_new(); | ||
| 1302 | y = BN_new(); | ||
| 1303 | m = BN_new(); | ||
| 1304 | n = BN_new(); | ||
| 1305 | order = BN_new(); | ||
| 1306 | |||
| 1307 | NISTP = EC_GROUP_new(test->meth()); | ||
| 1308 | if (!NISTP) | ||
| 1309 | ABORT; | ||
| 1310 | if (!BN_hex2bn(&p, test->p)) | ||
| 1311 | ABORT; | ||
| 1312 | if (1 != BN_is_prime_ex(p, BN_prime_checks, ctx, NULL)) | ||
| 1313 | ABORT; | ||
| 1314 | if (!BN_hex2bn(&a, test->a)) | ||
| 1315 | ABORT; | ||
| 1316 | if (!BN_hex2bn(&b, test->b)) | ||
| 1317 | ABORT; | ||
| 1318 | if (!EC_GROUP_set_curve_GFp(NISTP, p, a, b, ctx)) | ||
| 1319 | ABORT; | ||
| 1320 | G = EC_POINT_new(NISTP); | ||
| 1321 | P = EC_POINT_new(NISTP); | ||
| 1322 | Q = EC_POINT_new(NISTP); | ||
| 1323 | Q_CHECK = EC_POINT_new(NISTP); | ||
| 1324 | if (!BN_hex2bn(&x, test->Qx)) | ||
| 1325 | ABORT; | ||
| 1326 | if (!BN_hex2bn(&y, test->Qy)) | ||
| 1327 | ABORT; | ||
| 1328 | if (!EC_POINT_set_affine_coordinates_GFp(NISTP, Q_CHECK, x, y, ctx)) | ||
| 1329 | ABORT; | ||
| 1330 | if (!BN_hex2bn(&x, test->Gx)) | ||
| 1331 | ABORT; | ||
| 1332 | if (!BN_hex2bn(&y, test->Gy)) | ||
| 1333 | ABORT; | ||
| 1334 | if (!EC_POINT_set_affine_coordinates_GFp(NISTP, G, x, y, ctx)) | ||
| 1335 | ABORT; | ||
| 1336 | if (!BN_hex2bn(&order, test->order)) | ||
| 1337 | ABORT; | ||
| 1338 | if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) | ||
| 1339 | ABORT; | ||
| 1340 | |||
| 1341 | fprintf(stdout, "verify degree ... "); | ||
| 1342 | if (EC_GROUP_get_degree(NISTP) != test->degree) | ||
| 1343 | ABORT; | ||
| 1344 | fprintf(stdout, "ok\n"); | ||
| 1345 | |||
| 1346 | fprintf(stdout, "NIST test vectors ... "); | ||
| 1347 | if (!BN_hex2bn(&n, test->d)) | ||
| 1348 | ABORT; | ||
| 1349 | /* fixed point multiplication */ | ||
| 1350 | EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); | ||
| 1351 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1352 | ABORT; | ||
| 1353 | /* random point multiplication */ | ||
| 1354 | EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); | ||
| 1355 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1356 | ABORT; | ||
| 1357 | |||
| 1358 | /* set generator to P = 2*G, where G is the standard generator */ | ||
| 1359 | if (!EC_POINT_dbl(NISTP, P, G, ctx)) | ||
| 1360 | ABORT; | ||
| 1361 | if (!EC_GROUP_set_generator(NISTP, P, order, BN_value_one())) | ||
| 1362 | ABORT; | ||
| 1363 | /* set the scalar to m=n/2, where n is the NIST test scalar */ | ||
| 1364 | if (!BN_rshift(m, n, 1)) | ||
| 1365 | ABORT; | ||
| 1366 | |||
| 1367 | /* test the non-standard generator */ | ||
| 1368 | /* fixed point multiplication */ | ||
| 1369 | EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); | ||
| 1370 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1371 | ABORT; | ||
| 1372 | /* random point multiplication */ | ||
| 1373 | EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); | ||
| 1374 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1375 | ABORT; | ||
| 1376 | |||
| 1377 | /* now repeat all tests with precomputation */ | ||
| 1378 | if (!EC_GROUP_precompute_mult(NISTP, ctx)) | ||
| 1379 | ABORT; | ||
| 1380 | |||
| 1381 | /* fixed point multiplication */ | ||
| 1382 | EC_POINT_mul(NISTP, Q, m, NULL, NULL, ctx); | ||
| 1383 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1384 | ABORT; | ||
| 1385 | /* random point multiplication */ | ||
| 1386 | EC_POINT_mul(NISTP, Q, NULL, P, m, ctx); | ||
| 1387 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1388 | ABORT; | ||
| 1389 | |||
| 1390 | /* reset generator */ | ||
| 1391 | if (!EC_GROUP_set_generator(NISTP, G, order, BN_value_one())) | ||
| 1392 | ABORT; | ||
| 1393 | /* fixed point multiplication */ | ||
| 1394 | EC_POINT_mul(NISTP, Q, n, NULL, NULL, ctx); | ||
| 1395 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1396 | ABORT; | ||
| 1397 | /* random point multiplication */ | ||
| 1398 | EC_POINT_mul(NISTP, Q, NULL, G, n, ctx); | ||
| 1399 | if (0 != EC_POINT_cmp(NISTP, Q, Q_CHECK, ctx)) | ||
| 1400 | ABORT; | ||
| 1401 | |||
| 1402 | fprintf(stdout, "ok\n"); | ||
| 1403 | group_order_tests(NISTP); | ||
| 1404 | EC_GROUP_free(NISTP); | ||
| 1405 | EC_POINT_free(G); | ||
| 1406 | EC_POINT_free(P); | ||
| 1407 | EC_POINT_free(Q); | ||
| 1408 | EC_POINT_free(Q_CHECK); | ||
| 1409 | BN_free(n); | ||
| 1410 | BN_free(m); | ||
| 1411 | BN_free(p); | ||
| 1412 | BN_free(a); | ||
| 1413 | BN_free(b); | ||
| 1414 | BN_free(x); | ||
| 1415 | BN_free(y); | ||
| 1416 | BN_free(order); | ||
| 1417 | BN_CTX_free(ctx); | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | void | ||
| 1421 | nistp_tests() | ||
| 1422 | { | ||
| 1423 | unsigned i; | ||
| 1424 | |||
| 1425 | for (i = 0; i < sizeof(nistp_tests_params) / sizeof(struct nistp_test_params); i++) { | ||
| 1426 | nistp_single_test(&nistp_tests_params[i]); | ||
| 1427 | } | ||
| 1428 | } | ||
| 1429 | #endif | ||
| 1430 | |||
| 1431 | int | ||
| 1432 | main(int argc, char *argv[]) | ||
| 1433 | { | ||
| 1434 | ERR_load_crypto_strings(); | ||
| 1435 | |||
| 1436 | prime_field_tests(); | ||
| 1437 | puts(""); | ||
| 1438 | #ifndef OPENSSL_NO_EC2M | ||
| 1439 | char2_field_tests(); | ||
| 1440 | #endif | ||
| 1441 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 | ||
| 1442 | nistp_tests(); | ||
| 1443 | #endif | ||
| 1444 | /* test the internal curves */ | ||
| 1445 | internal_curve_test(); | ||
| 1446 | |||
| 1447 | #ifndef OPENSSL_NO_ENGINE | ||
| 1448 | ENGINE_cleanup(); | ||
| 1449 | #endif | ||
| 1450 | CRYPTO_cleanup_all_ex_data(); | ||
| 1451 | ERR_free_strings(); | ||
| 1452 | ERR_remove_thread_state(NULL); | ||
| 1453 | CRYPTO_mem_leaks_fp(stderr); | ||
| 1454 | |||
| 1455 | return 0; | ||
| 1456 | } | ||
diff --git a/src/regress/lib/libcrypto/ecdh/Makefile b/src/regress/lib/libcrypto/ecdh/Makefile deleted file mode 100644 index b645771f7b..0000000000 --- a/src/regress/lib/libcrypto/ecdh/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= ecdhtest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/ecdh/ecdhtest.c b/src/regress/lib/libcrypto/ecdh/ecdhtest.c deleted file mode 100644 index faf519e07a..0000000000 --- a/src/regress/lib/libcrypto/ecdh/ecdhtest.c +++ /dev/null | |||
| @@ -1,477 +0,0 @@ | |||
| 1 | /* $OpenBSD: ecdhtest.c,v 1.10 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 4 | * | ||
| 5 | * The Elliptic Curve Public-Key Crypto Library (ECC Code) included | ||
| 6 | * herein is developed by SUN MICROSYSTEMS, INC., and is contributed | ||
| 7 | * to the OpenSSL project. | ||
| 8 | * | ||
| 9 | * The ECC Code is licensed pursuant to the OpenSSL open source | ||
| 10 | * license provided below. | ||
| 11 | * | ||
| 12 | * The ECDH software is originally written by Douglas Stebila of | ||
| 13 | * Sun Microsystems Laboratories. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | /* ==================================================================== | ||
| 17 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
| 18 | * | ||
| 19 | * Redistribution and use in source and binary forms, with or without | ||
| 20 | * modification, are permitted provided that the following conditions | ||
| 21 | * are met: | ||
| 22 | * | ||
| 23 | * 1. Redistributions of source code must retain the above copyright | ||
| 24 | * notice, this list of conditions and the following disclaimer. | ||
| 25 | * | ||
| 26 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer in | ||
| 28 | * the documentation and/or other materials provided with the | ||
| 29 | * distribution. | ||
| 30 | * | ||
| 31 | * 3. All advertising materials mentioning features or use of this | ||
| 32 | * software must display the following acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 37 | * endorse or promote products derived from this software without | ||
| 38 | * prior written permission. For written permission, please contact | ||
| 39 | * openssl-core@openssl.org. | ||
| 40 | * | ||
| 41 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 42 | * nor may "OpenSSL" appear in their names without prior written | ||
| 43 | * permission of the OpenSSL Project. | ||
| 44 | * | ||
| 45 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 46 | * acknowledgment: | ||
| 47 | * "This product includes software developed by the OpenSSL Project | ||
| 48 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 49 | * | ||
| 50 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 51 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 52 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 53 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 54 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 56 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 57 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 59 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 60 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 61 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 62 | * ==================================================================== | ||
| 63 | * | ||
| 64 | * This product includes cryptographic software written by Eric Young | ||
| 65 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 66 | * Hudson (tjh@cryptsoft.com). | ||
| 67 | * | ||
| 68 | */ | ||
| 69 | |||
| 70 | #include <stdio.h> | ||
| 71 | #include <stdlib.h> | ||
| 72 | #include <string.h> | ||
| 73 | |||
| 74 | #include <openssl/crypto.h> | ||
| 75 | #include <openssl/bio.h> | ||
| 76 | #include <openssl/bn.h> | ||
| 77 | #include <openssl/objects.h> | ||
| 78 | #include <openssl/sha.h> | ||
| 79 | #include <openssl/err.h> | ||
| 80 | |||
| 81 | #include <openssl/ec.h> | ||
| 82 | #include <openssl/ecdh.h> | ||
| 83 | |||
| 84 | static const int KDF1_SHA1_len = 20; | ||
| 85 | static void * | ||
| 86 | KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) | ||
| 87 | { | ||
| 88 | #ifndef OPENSSL_NO_SHA | ||
| 89 | if (*outlen < SHA_DIGEST_LENGTH) | ||
| 90 | return NULL; | ||
| 91 | else | ||
| 92 | *outlen = SHA_DIGEST_LENGTH; | ||
| 93 | return SHA1(in, inlen, out); | ||
| 94 | #else | ||
| 95 | return NULL; | ||
| 96 | #endif | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | static int | ||
| 101 | test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) | ||
| 102 | { | ||
| 103 | BIGNUM *x_a = NULL, *y_a = NULL, *x_b = NULL, *y_b = NULL; | ||
| 104 | EC_KEY *a = NULL, *b = NULL; | ||
| 105 | const EC_GROUP *group; | ||
| 106 | unsigned char *abuf = NULL, *bbuf = NULL; | ||
| 107 | int i, alen, blen, aout, bout, ret = 0; | ||
| 108 | char buf[12]; | ||
| 109 | |||
| 110 | a = EC_KEY_new_by_curve_name(nid); | ||
| 111 | b = EC_KEY_new_by_curve_name(nid); | ||
| 112 | if (a == NULL || b == NULL) | ||
| 113 | goto err; | ||
| 114 | |||
| 115 | group = EC_KEY_get0_group(a); | ||
| 116 | |||
| 117 | if ((x_a = BN_new()) == NULL) | ||
| 118 | goto err; | ||
| 119 | if ((y_a = BN_new()) == NULL) | ||
| 120 | goto err; | ||
| 121 | if ((x_b = BN_new()) == NULL) | ||
| 122 | goto err; | ||
| 123 | if ((y_b = BN_new()) == NULL) | ||
| 124 | goto err; | ||
| 125 | |||
| 126 | BIO_puts(out, "Testing key generation with "); | ||
| 127 | BIO_puts(out, text); | ||
| 128 | (void)BIO_flush(out); | ||
| 129 | |||
| 130 | if (!EC_KEY_generate_key(a)) | ||
| 131 | goto err; | ||
| 132 | |||
| 133 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 134 | NID_X9_62_prime_field) { | ||
| 135 | if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 136 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | ||
| 137 | } | ||
| 138 | #ifndef OPENSSL_NO_EC2M | ||
| 139 | else { | ||
| 140 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 141 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | ||
| 142 | } | ||
| 143 | #endif | ||
| 144 | BIO_printf(out, " ."); | ||
| 145 | (void)BIO_flush(out); | ||
| 146 | |||
| 147 | if (!EC_KEY_generate_key(b)) | ||
| 148 | goto err; | ||
| 149 | |||
| 150 | if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == | ||
| 151 | NID_X9_62_prime_field) { | ||
| 152 | if (!EC_POINT_get_affine_coordinates_GFp(group, | ||
| 153 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | ||
| 154 | } | ||
| 155 | #ifndef OPENSSL_NO_EC2M | ||
| 156 | else { | ||
| 157 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | ||
| 158 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | ||
| 159 | } | ||
| 160 | #endif | ||
| 161 | |||
| 162 | BIO_printf(out, "."); | ||
| 163 | (void)BIO_flush(out); | ||
| 164 | |||
| 165 | alen = KDF1_SHA1_len; | ||
| 166 | abuf = malloc(alen); | ||
| 167 | aout = ECDH_compute_key(abuf, alen, EC_KEY_get0_public_key(b), | ||
| 168 | a, KDF1_SHA1); | ||
| 169 | |||
| 170 | BIO_printf(out, "."); | ||
| 171 | (void)BIO_flush(out); | ||
| 172 | |||
| 173 | blen = KDF1_SHA1_len; | ||
| 174 | bbuf = malloc(blen); | ||
| 175 | bout = ECDH_compute_key(bbuf, blen, EC_KEY_get0_public_key(a), | ||
| 176 | b, KDF1_SHA1); | ||
| 177 | |||
| 178 | BIO_printf(out, "."); | ||
| 179 | (void)BIO_flush(out); | ||
| 180 | |||
| 181 | if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) { | ||
| 182 | BIO_printf(out, " failed\n\n"); | ||
| 183 | BIO_printf(out, "key a:\n"); | ||
| 184 | BIO_printf(out, "private key: "); | ||
| 185 | BN_print(out, EC_KEY_get0_private_key(a)); | ||
| 186 | BIO_printf(out, "\n"); | ||
| 187 | BIO_printf(out, "public key (x,y): "); | ||
| 188 | BN_print(out, x_a); | ||
| 189 | BIO_printf(out, ","); | ||
| 190 | BN_print(out, y_a); | ||
| 191 | BIO_printf(out, "\nkey b:\n"); | ||
| 192 | BIO_printf(out, "private key: "); | ||
| 193 | BN_print(out, EC_KEY_get0_private_key(b)); | ||
| 194 | BIO_printf(out, "\n"); | ||
| 195 | BIO_printf(out, "public key (x,y): "); | ||
| 196 | BN_print(out, x_b); | ||
| 197 | BIO_printf(out, ","); | ||
| 198 | BN_print(out, y_b); | ||
| 199 | BIO_printf(out, "\n"); | ||
| 200 | BIO_printf(out, "generated key a: "); | ||
| 201 | for (i = 0; i < bout; i++) { | ||
| 202 | snprintf(buf, sizeof buf, "%02X", bbuf[i]); | ||
| 203 | BIO_puts(out, buf); | ||
| 204 | } | ||
| 205 | BIO_printf(out, "\n"); | ||
| 206 | BIO_printf(out, "generated key b: "); | ||
| 207 | for (i = 0; i < aout; i++) { | ||
| 208 | snprintf(buf, sizeof buf, "%02X", abuf[i]); | ||
| 209 | BIO_puts(out, buf); | ||
| 210 | } | ||
| 211 | BIO_printf(out, "\n"); | ||
| 212 | fprintf(stderr, "Error in ECDH routines\n"); | ||
| 213 | ret = 0; | ||
| 214 | } else { | ||
| 215 | BIO_printf(out, " ok\n"); | ||
| 216 | ret = 1; | ||
| 217 | } | ||
| 218 | |||
| 219 | err: | ||
| 220 | ERR_print_errors_fp(stderr); | ||
| 221 | |||
| 222 | free(abuf); | ||
| 223 | free(bbuf); | ||
| 224 | BN_free(x_a); | ||
| 225 | BN_free(y_a); | ||
| 226 | BN_free(x_b); | ||
| 227 | BN_free(y_b); | ||
| 228 | EC_KEY_free(b); | ||
| 229 | EC_KEY_free(a); | ||
| 230 | |||
| 231 | return (ret); | ||
| 232 | } | ||
| 233 | |||
| 234 | /* Keys and shared secrets from RFC 7027 */ | ||
| 235 | |||
| 236 | static const unsigned char bp256_da[] = { | ||
| 237 | 0x81, 0xDB, 0x1E, 0xE1, 0x00, 0x15, 0x0F, 0xF2, 0xEA, 0x33, 0x8D, 0x70, | ||
| 238 | 0x82, 0x71, 0xBE, 0x38, 0x30, 0x0C, 0xB5, 0x42, 0x41, 0xD7, 0x99, 0x50, | ||
| 239 | 0xF7, 0x7B, 0x06, 0x30, 0x39, 0x80, 0x4F, 0x1D | ||
| 240 | }; | ||
| 241 | |||
| 242 | static const unsigned char bp256_db[] = { | ||
| 243 | 0x55, 0xE4, 0x0B, 0xC4, 0x1E, 0x37, 0xE3, 0xE2, 0xAD, 0x25, 0xC3, 0xC6, | ||
| 244 | 0x65, 0x45, 0x11, 0xFF, 0xA8, 0x47, 0x4A, 0x91, 0xA0, 0x03, 0x20, 0x87, | ||
| 245 | 0x59, 0x38, 0x52, 0xD3, 0xE7, 0xD7, 0x6B, 0xD3 | ||
| 246 | }; | ||
| 247 | |||
| 248 | static const unsigned char bp256_Z[] = { | ||
| 249 | 0x89, 0xAF, 0xC3, 0x9D, 0x41, 0xD3, 0xB3, 0x27, 0x81, 0x4B, 0x80, 0x94, | ||
| 250 | 0x0B, 0x04, 0x25, 0x90, 0xF9, 0x65, 0x56, 0xEC, 0x91, 0xE6, 0xAE, 0x79, | ||
| 251 | 0x39, 0xBC, 0xE3, 0x1F, 0x3A, 0x18, 0xBF, 0x2B | ||
| 252 | }; | ||
| 253 | |||
| 254 | static const unsigned char bp384_da[] = { | ||
| 255 | 0x1E, 0x20, 0xF5, 0xE0, 0x48, 0xA5, 0x88, 0x6F, 0x1F, 0x15, 0x7C, 0x74, | ||
| 256 | 0xE9, 0x1B, 0xDE, 0x2B, 0x98, 0xC8, 0xB5, 0x2D, 0x58, 0xE5, 0x00, 0x3D, | ||
| 257 | 0x57, 0x05, 0x3F, 0xC4, 0xB0, 0xBD, 0x65, 0xD6, 0xF1, 0x5E, 0xB5, 0xD1, | ||
| 258 | 0xEE, 0x16, 0x10, 0xDF, 0x87, 0x07, 0x95, 0x14, 0x36, 0x27, 0xD0, 0x42 | ||
| 259 | }; | ||
| 260 | |||
| 261 | static const unsigned char bp384_db[] = { | ||
| 262 | 0x03, 0x26, 0x40, 0xBC, 0x60, 0x03, 0xC5, 0x92, 0x60, 0xF7, 0x25, 0x0C, | ||
| 263 | 0x3D, 0xB5, 0x8C, 0xE6, 0x47, 0xF9, 0x8E, 0x12, 0x60, 0xAC, 0xCE, 0x4A, | ||
| 264 | 0xCD, 0xA3, 0xDD, 0x86, 0x9F, 0x74, 0xE0, 0x1F, 0x8B, 0xA5, 0xE0, 0x32, | ||
| 265 | 0x43, 0x09, 0xDB, 0x6A, 0x98, 0x31, 0x49, 0x7A, 0xBA, 0xC9, 0x66, 0x70 | ||
| 266 | }; | ||
| 267 | |||
| 268 | static const unsigned char bp384_Z[] = { | ||
| 269 | 0x0B, 0xD9, 0xD3, 0xA7, 0xEA, 0x0B, 0x3D, 0x51, 0x9D, 0x09, 0xD8, 0xE4, | ||
| 270 | 0x8D, 0x07, 0x85, 0xFB, 0x74, 0x4A, 0x6B, 0x35, 0x5E, 0x63, 0x04, 0xBC, | ||
| 271 | 0x51, 0xC2, 0x29, 0xFB, 0xBC, 0xE2, 0x39, 0xBB, 0xAD, 0xF6, 0x40, 0x37, | ||
| 272 | 0x15, 0xC3, 0x5D, 0x4F, 0xB2, 0xA5, 0x44, 0x4F, 0x57, 0x5D, 0x4F, 0x42 | ||
| 273 | }; | ||
| 274 | |||
| 275 | static const unsigned char bp512_da[] = { | ||
| 276 | 0x16, 0x30, 0x2F, 0xF0, 0xDB, 0xBB, 0x5A, 0x8D, 0x73, 0x3D, 0xAB, 0x71, | ||
| 277 | 0x41, 0xC1, 0xB4, 0x5A, 0xCB, 0xC8, 0x71, 0x59, 0x39, 0x67, 0x7F, 0x6A, | ||
| 278 | 0x56, 0x85, 0x0A, 0x38, 0xBD, 0x87, 0xBD, 0x59, 0xB0, 0x9E, 0x80, 0x27, | ||
| 279 | 0x96, 0x09, 0xFF, 0x33, 0x3E, 0xB9, 0xD4, 0xC0, 0x61, 0x23, 0x1F, 0xB2, | ||
| 280 | 0x6F, 0x92, 0xEE, 0xB0, 0x49, 0x82, 0xA5, 0xF1, 0xD1, 0x76, 0x4C, 0xAD, | ||
| 281 | 0x57, 0x66, 0x54, 0x22 | ||
| 282 | }; | ||
| 283 | |||
| 284 | static const unsigned char bp512_db[] = { | ||
| 285 | 0x23, 0x0E, 0x18, 0xE1, 0xBC, 0xC8, 0x8A, 0x36, 0x2F, 0xA5, 0x4E, 0x4E, | ||
| 286 | 0xA3, 0x90, 0x20, 0x09, 0x29, 0x2F, 0x7F, 0x80, 0x33, 0x62, 0x4F, 0xD4, | ||
| 287 | 0x71, 0xB5, 0xD8, 0xAC, 0xE4, 0x9D, 0x12, 0xCF, 0xAB, 0xBC, 0x19, 0x96, | ||
| 288 | 0x3D, 0xAB, 0x8E, 0x2F, 0x1E, 0xBA, 0x00, 0xBF, 0xFB, 0x29, 0xE4, 0xD7, | ||
| 289 | 0x2D, 0x13, 0xF2, 0x22, 0x45, 0x62, 0xF4, 0x05, 0xCB, 0x80, 0x50, 0x36, | ||
| 290 | 0x66, 0xB2, 0x54, 0x29 | ||
| 291 | }; | ||
| 292 | |||
| 293 | |||
| 294 | static const unsigned char bp512_Z[] = { | ||
| 295 | 0xA7, 0x92, 0x70, 0x98, 0x65, 0x5F, 0x1F, 0x99, 0x76, 0xFA, 0x50, 0xA9, | ||
| 296 | 0xD5, 0x66, 0x86, 0x5D, 0xC5, 0x30, 0x33, 0x18, 0x46, 0x38, 0x1C, 0x87, | ||
| 297 | 0x25, 0x6B, 0xAF, 0x32, 0x26, 0x24, 0x4B, 0x76, 0xD3, 0x64, 0x03, 0xC0, | ||
| 298 | 0x24, 0xD7, 0xBB, 0xF0, 0xAA, 0x08, 0x03, 0xEA, 0xFF, 0x40, 0x5D, 0x3D, | ||
| 299 | 0x24, 0xF1, 0x1A, 0x9B, 0x5C, 0x0B, 0xEF, 0x67, 0x9F, 0xE1, 0x45, 0x4B, | ||
| 300 | 0x21, 0xC4, 0xCD, 0x1F | ||
| 301 | }; | ||
| 302 | |||
| 303 | /* Given private value and NID, create EC_KEY structure */ | ||
| 304 | |||
| 305 | static EC_KEY * | ||
| 306 | mk_eckey(int nid, const unsigned char *p, size_t plen) | ||
| 307 | { | ||
| 308 | EC_KEY *k = NULL; | ||
| 309 | BIGNUM *priv = NULL; | ||
| 310 | EC_POINT *pub = NULL; | ||
| 311 | const EC_GROUP *grp; | ||
| 312 | int ok = 0; | ||
| 313 | |||
| 314 | k = EC_KEY_new_by_curve_name(nid); | ||
| 315 | if (!k) | ||
| 316 | goto err; | ||
| 317 | priv = BN_bin2bn(p, plen, NULL); | ||
| 318 | if (!priv) | ||
| 319 | goto err; | ||
| 320 | if (!EC_KEY_set_private_key(k, priv)) | ||
| 321 | goto err; | ||
| 322 | grp = EC_KEY_get0_group(k); | ||
| 323 | pub = EC_POINT_new(grp); | ||
| 324 | if (!pub) | ||
| 325 | goto err; | ||
| 326 | if (!EC_POINT_mul(grp, pub, priv, NULL, NULL, NULL)) | ||
| 327 | goto err; | ||
| 328 | if (!EC_KEY_set_public_key(k, pub)) | ||
| 329 | goto err; | ||
| 330 | ok = 1; | ||
| 331 | err: | ||
| 332 | BN_clear_free(priv); | ||
| 333 | EC_POINT_free(pub); | ||
| 334 | if (!ok) { | ||
| 335 | EC_KEY_free(k); | ||
| 336 | k = NULL; | ||
| 337 | } | ||
| 338 | return (k); | ||
| 339 | } | ||
| 340 | |||
| 341 | /* Known answer test: compute shared secret and check it matches | ||
| 342 | * expected value. | ||
| 343 | */ | ||
| 344 | |||
| 345 | static int | ||
| 346 | ecdh_kat(BIO *out, const char *cname, int nid, | ||
| 347 | const unsigned char *k1, size_t k1_len, | ||
| 348 | const unsigned char *k2, size_t k2_len, | ||
| 349 | const unsigned char *Z, size_t Zlen) | ||
| 350 | { | ||
| 351 | int rv = 0; | ||
| 352 | EC_KEY *key1 = NULL, *key2 = NULL; | ||
| 353 | unsigned char *Ztmp = NULL; | ||
| 354 | size_t Ztmplen; | ||
| 355 | BIO_puts(out, "Testing ECDH shared secret with "); | ||
| 356 | BIO_puts(out, cname); | ||
| 357 | key1 = mk_eckey(nid, k1, k1_len); | ||
| 358 | key2 = mk_eckey(nid, k2, k2_len); | ||
| 359 | if (!key1 || !key2) | ||
| 360 | goto err; | ||
| 361 | Ztmplen = ECDH_size(key1); | ||
| 362 | if (Ztmplen != Zlen) | ||
| 363 | goto err; | ||
| 364 | Ztmp = malloc(Ztmplen); | ||
| 365 | if (!ECDH_compute_key(Ztmp, Ztmplen, | ||
| 366 | EC_KEY_get0_public_key(key2), key1, 0)) | ||
| 367 | goto err; | ||
| 368 | if (memcmp(Ztmp, Z, Zlen)) | ||
| 369 | goto err; | ||
| 370 | memset(Ztmp, 0, Zlen); | ||
| 371 | if (!ECDH_compute_key(Ztmp, Ztmplen, | ||
| 372 | EC_KEY_get0_public_key(key1), key2, 0)) | ||
| 373 | goto err; | ||
| 374 | if (memcmp(Ztmp, Z, Zlen)) | ||
| 375 | goto err; | ||
| 376 | rv = 1; | ||
| 377 | |||
| 378 | err: | ||
| 379 | if (rv) | ||
| 380 | BIO_puts(out, " ok\n"); | ||
| 381 | else { | ||
| 382 | fprintf(stderr, "Error in ECDH routines\n"); | ||
| 383 | ERR_print_errors_fp(stderr); | ||
| 384 | } | ||
| 385 | |||
| 386 | EC_KEY_free(key1); | ||
| 387 | EC_KEY_free(key2); | ||
| 388 | free(Ztmp); | ||
| 389 | |||
| 390 | return rv; | ||
| 391 | } | ||
| 392 | |||
| 393 | #define test_ecdh_kat(bio, curve, bits) \ | ||
| 394 | ecdh_kat(bio, curve, NID_brainpoolP##bits##r1, \ | ||
| 395 | bp##bits##_da, sizeof(bp##bits##_da), \ | ||
| 396 | bp##bits##_db, sizeof(bp##bits##_db), \ | ||
| 397 | bp##bits##_Z, sizeof(bp##bits##_Z)) | ||
| 398 | |||
| 399 | int | ||
| 400 | main(int argc, char *argv[]) | ||
| 401 | { | ||
| 402 | BN_CTX *ctx = NULL; | ||
| 403 | int ret = 1; | ||
| 404 | BIO *out; | ||
| 405 | |||
| 406 | out = BIO_new(BIO_s_file()); | ||
| 407 | if (out == NULL) | ||
| 408 | exit(1); | ||
| 409 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | ||
| 410 | |||
| 411 | if ((ctx = BN_CTX_new()) == NULL) | ||
| 412 | goto err; | ||
| 413 | |||
| 414 | /* NIST PRIME CURVES TESTS */ | ||
| 415 | if (!test_ecdh_curve(NID_X9_62_prime192v1, "NIST Prime-Curve P-192", | ||
| 416 | ctx, out)) | ||
| 417 | goto err; | ||
| 418 | if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out)) | ||
| 419 | goto err; | ||
| 420 | if (!test_ecdh_curve(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", | ||
| 421 | ctx, out)) | ||
| 422 | goto err; | ||
| 423 | if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) | ||
| 424 | goto err; | ||
| 425 | if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) | ||
| 426 | goto err; | ||
| 427 | #ifndef OPENSSL_NO_EC2M | ||
| 428 | /* NIST BINARY CURVES TESTS */ | ||
| 429 | if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", | ||
| 430 | ctx, out)) | ||
| 431 | goto err; | ||
| 432 | if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", | ||
| 433 | ctx, out)) | ||
| 434 | goto err; | ||
| 435 | if (!test_ecdh_curve(NID_sect233k1, "NIST Binary-Curve K-233", | ||
| 436 | ctx, out)) | ||
| 437 | goto err; | ||
| 438 | if (!test_ecdh_curve(NID_sect233r1, "NIST Binary-Curve B-233", | ||
| 439 | ctx, out)) | ||
| 440 | goto err; | ||
| 441 | if (!test_ecdh_curve(NID_sect283k1, "NIST Binary-Curve K-283", | ||
| 442 | ctx, out)) | ||
| 443 | goto err; | ||
| 444 | if (!test_ecdh_curve(NID_sect283r1, "NIST Binary-Curve B-283", | ||
| 445 | ctx, out)) | ||
| 446 | goto err; | ||
| 447 | if (!test_ecdh_curve(NID_sect409k1, "NIST Binary-Curve K-409", | ||
| 448 | ctx, out)) | ||
| 449 | goto err; | ||
| 450 | if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", | ||
| 451 | ctx, out)) | ||
| 452 | goto err; | ||
| 453 | if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", | ||
| 454 | ctx, out)) | ||
| 455 | goto err; | ||
| 456 | if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", | ||
| 457 | ctx, out)) | ||
| 458 | goto err; | ||
| 459 | #endif | ||
| 460 | if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP256r1", 256)) | ||
| 461 | goto err; | ||
| 462 | if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP384r1", 384)) | ||
| 463 | goto err; | ||
| 464 | if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP512r1", 512)) | ||
| 465 | goto err; | ||
| 466 | |||
| 467 | ret = 0; | ||
| 468 | |||
| 469 | err: | ||
| 470 | ERR_print_errors_fp(stderr); | ||
| 471 | BN_CTX_free(ctx); | ||
| 472 | BIO_free(out); | ||
| 473 | CRYPTO_cleanup_all_ex_data(); | ||
| 474 | ERR_remove_thread_state(NULL); | ||
| 475 | CRYPTO_mem_leaks_fp(stderr); | ||
| 476 | exit(ret); | ||
| 477 | } | ||
diff --git a/src/regress/lib/libcrypto/ecdsa/Makefile b/src/regress/lib/libcrypto/ecdsa/Makefile deleted file mode 100644 index 0c2e26a85e..0000000000 --- a/src/regress/lib/libcrypto/ecdsa/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= ecdsatest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c deleted file mode 100644 index 097768d11e..0000000000 --- a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c +++ /dev/null | |||
| @@ -1,405 +0,0 @@ | |||
| 1 | /* $OpenBSD: ecdsatest.c,v 1.6 2018/07/17 17:10:04 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by Nils Larsch for the OpenSSL project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * | ||
| 61 | * Portions of the attached software ("Contribution") are developed by | ||
| 62 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | ||
| 63 | * | ||
| 64 | * The Contribution is licensed pursuant to the OpenSSL open source | ||
| 65 | * license provided above. | ||
| 66 | * | ||
| 67 | * The elliptic curve binary polynomial software is originally written by | ||
| 68 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories. | ||
| 69 | * | ||
| 70 | */ | ||
| 71 | |||
| 72 | #include <stdio.h> | ||
| 73 | #include <stdlib.h> | ||
| 74 | #include <string.h> | ||
| 75 | |||
| 76 | #include <openssl/crypto.h> | ||
| 77 | #include <openssl/bio.h> | ||
| 78 | #include <openssl/evp.h> | ||
| 79 | #include <openssl/bn.h> | ||
| 80 | #include <openssl/ecdsa.h> | ||
| 81 | #ifndef OPENSSL_NO_ENGINE | ||
| 82 | #include <openssl/engine.h> | ||
| 83 | #endif | ||
| 84 | #include <openssl/err.h> | ||
| 85 | |||
| 86 | /* declaration of the test functions */ | ||
| 87 | int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s); | ||
| 88 | int test_builtin(BIO *); | ||
| 89 | |||
| 90 | /* some tests from the X9.62 draft */ | ||
| 91 | int | ||
| 92 | x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) | ||
| 93 | { | ||
| 94 | int ret = 0; | ||
| 95 | const char message[] = "abc"; | ||
| 96 | unsigned char digest[20]; | ||
| 97 | unsigned int dgst_len = 0; | ||
| 98 | EVP_MD_CTX md_ctx; | ||
| 99 | EC_KEY *key = NULL; | ||
| 100 | ECDSA_SIG *signature = NULL; | ||
| 101 | BIGNUM *r = NULL, *s = NULL; | ||
| 102 | |||
| 103 | EVP_MD_CTX_init(&md_ctx); | ||
| 104 | /* get the message digest */ | ||
| 105 | EVP_DigestInit(&md_ctx, EVP_ecdsa()); | ||
| 106 | EVP_DigestUpdate(&md_ctx, (const void*)message, 3); | ||
| 107 | EVP_DigestFinal(&md_ctx, digest, &dgst_len); | ||
| 108 | |||
| 109 | BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid)); | ||
| 110 | /* create the key */ | ||
| 111 | if ((key = EC_KEY_new_by_curve_name(nid)) == NULL) | ||
| 112 | goto x962_int_err; | ||
| 113 | if (!EC_KEY_generate_key(key)) | ||
| 114 | goto x962_int_err; | ||
| 115 | BIO_printf(out, "."); | ||
| 116 | (void)BIO_flush(out); | ||
| 117 | /* create the signature */ | ||
| 118 | signature = ECDSA_do_sign(digest, 20, key); | ||
| 119 | if (signature == NULL) | ||
| 120 | goto x962_int_err; | ||
| 121 | BIO_printf(out, "."); | ||
| 122 | (void)BIO_flush(out); | ||
| 123 | /* compare the created signature with the expected signature */ | ||
| 124 | if ((r = BN_new()) == NULL || (s = BN_new()) == NULL) | ||
| 125 | goto x962_int_err; | ||
| 126 | if (!BN_dec2bn(&r, r_in) || | ||
| 127 | !BN_dec2bn(&s, s_in)) | ||
| 128 | goto x962_int_err; | ||
| 129 | if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s)) | ||
| 130 | goto x962_int_err; | ||
| 131 | BIO_printf(out, "."); | ||
| 132 | (void)BIO_flush(out); | ||
| 133 | /* verify the signature */ | ||
| 134 | if (ECDSA_do_verify(digest, 20, signature, key) != 1) | ||
| 135 | goto x962_int_err; | ||
| 136 | BIO_printf(out, "."); | ||
| 137 | (void)BIO_flush(out); | ||
| 138 | |||
| 139 | BIO_printf(out, " ok\n"); | ||
| 140 | ret = 1; | ||
| 141 | x962_int_err: | ||
| 142 | if (!ret) | ||
| 143 | BIO_printf(out, " failed\n"); | ||
| 144 | if (key) | ||
| 145 | EC_KEY_free(key); | ||
| 146 | if (signature) | ||
| 147 | ECDSA_SIG_free(signature); | ||
| 148 | if (r) | ||
| 149 | BN_free(r); | ||
| 150 | if (s) | ||
| 151 | BN_free(s); | ||
| 152 | EVP_MD_CTX_cleanup(&md_ctx); | ||
| 153 | return ret; | ||
| 154 | } | ||
| 155 | |||
| 156 | int | ||
| 157 | test_builtin(BIO *out) | ||
| 158 | { | ||
| 159 | EC_builtin_curve *curves = NULL; | ||
| 160 | size_t num_curves = 0, n = 0; | ||
| 161 | EC_KEY *eckey = NULL, *wrong_eckey = NULL; | ||
| 162 | EC_GROUP *group; | ||
| 163 | ECDSA_SIG *ecdsa_sig = NULL; | ||
| 164 | unsigned char digest[20], wrong_digest[20]; | ||
| 165 | unsigned char *signature = NULL; | ||
| 166 | const unsigned char *sig_ptr; | ||
| 167 | unsigned char *sig_ptr2; | ||
| 168 | unsigned char *raw_buf = NULL; | ||
| 169 | unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len; | ||
| 170 | int nid, ret = 0; | ||
| 171 | |||
| 172 | /* fill digest values with some random data */ | ||
| 173 | arc4random_buf(digest, 20); | ||
| 174 | arc4random_buf(wrong_digest, 20); | ||
| 175 | |||
| 176 | /* create and verify a ecdsa signature with every available curve */ | ||
| 177 | BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() " | ||
| 178 | "with some internal curves:\n"); | ||
| 179 | |||
| 180 | /* get a list of all internal curves */ | ||
| 181 | num_curves = EC_get_builtin_curves(NULL, 0); | ||
| 182 | |||
| 183 | curves = reallocarray(NULL, sizeof(EC_builtin_curve), num_curves); | ||
| 184 | |||
| 185 | if (curves == NULL) { | ||
| 186 | BIO_printf(out, "reallocarray error\n"); | ||
| 187 | goto builtin_err; | ||
| 188 | } | ||
| 189 | |||
| 190 | if (!EC_get_builtin_curves(curves, num_curves)) { | ||
| 191 | BIO_printf(out, "unable to get internal curves\n"); | ||
| 192 | goto builtin_err; | ||
| 193 | } | ||
| 194 | |||
| 195 | /* now create and verify a signature for every curve */ | ||
| 196 | for (n = 0; n < num_curves; n++) { | ||
| 197 | unsigned char dirt, offset; | ||
| 198 | |||
| 199 | nid = curves[n].nid; | ||
| 200 | if (nid == NID_ipsec4) | ||
| 201 | continue; | ||
| 202 | /* create new ecdsa key (== EC_KEY) */ | ||
| 203 | if ((eckey = EC_KEY_new()) == NULL) | ||
| 204 | goto builtin_err; | ||
| 205 | group = EC_GROUP_new_by_curve_name(nid); | ||
| 206 | if (group == NULL) | ||
| 207 | goto builtin_err; | ||
| 208 | if (EC_KEY_set_group(eckey, group) == 0) | ||
| 209 | goto builtin_err; | ||
| 210 | EC_GROUP_free(group); | ||
| 211 | degree = EC_GROUP_get_degree(EC_KEY_get0_group(eckey)); | ||
| 212 | if (degree < 160) { | ||
| 213 | /* drop the curve */ | ||
| 214 | EC_KEY_free(eckey); | ||
| 215 | eckey = NULL; | ||
| 216 | continue; | ||
| 217 | } | ||
| 218 | BIO_printf(out, "%s: ", OBJ_nid2sn(nid)); | ||
| 219 | /* create key */ | ||
| 220 | if (!EC_KEY_generate_key(eckey)) { | ||
| 221 | BIO_printf(out, " failed\n"); | ||
| 222 | goto builtin_err; | ||
| 223 | } | ||
| 224 | /* create second key */ | ||
| 225 | if ((wrong_eckey = EC_KEY_new()) == NULL) | ||
| 226 | goto builtin_err; | ||
| 227 | group = EC_GROUP_new_by_curve_name(nid); | ||
| 228 | if (group == NULL) | ||
| 229 | goto builtin_err; | ||
| 230 | if (EC_KEY_set_group(wrong_eckey, group) == 0) | ||
| 231 | goto builtin_err; | ||
| 232 | EC_GROUP_free(group); | ||
| 233 | if (!EC_KEY_generate_key(wrong_eckey)) { | ||
| 234 | BIO_printf(out, " failed\n"); | ||
| 235 | goto builtin_err; | ||
| 236 | } | ||
| 237 | |||
| 238 | BIO_printf(out, "."); | ||
| 239 | (void)BIO_flush(out); | ||
| 240 | /* check key */ | ||
| 241 | if (!EC_KEY_check_key(eckey)) { | ||
| 242 | BIO_printf(out, " failed\n"); | ||
| 243 | goto builtin_err; | ||
| 244 | } | ||
| 245 | BIO_printf(out, "."); | ||
| 246 | (void)BIO_flush(out); | ||
| 247 | /* create signature */ | ||
| 248 | sig_len = ECDSA_size(eckey); | ||
| 249 | if ((signature = malloc(sig_len)) == NULL) | ||
| 250 | goto builtin_err; | ||
| 251 | if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) { | ||
| 252 | BIO_printf(out, " failed\n"); | ||
| 253 | goto builtin_err; | ||
| 254 | } | ||
| 255 | BIO_printf(out, "."); | ||
| 256 | (void)BIO_flush(out); | ||
| 257 | /* verify signature */ | ||
| 258 | if (ECDSA_verify(0, digest, 20, signature, sig_len, | ||
| 259 | eckey) != 1) { | ||
| 260 | BIO_printf(out, " failed\n"); | ||
| 261 | goto builtin_err; | ||
| 262 | } | ||
| 263 | BIO_printf(out, "."); | ||
| 264 | (void)BIO_flush(out); | ||
| 265 | /* verify signature with the wrong key */ | ||
| 266 | if (ECDSA_verify(0, digest, 20, signature, sig_len, | ||
| 267 | wrong_eckey) == 1) { | ||
| 268 | BIO_printf(out, " failed\n"); | ||
| 269 | goto builtin_err; | ||
| 270 | } | ||
| 271 | BIO_printf(out, "."); | ||
| 272 | (void)BIO_flush(out); | ||
| 273 | /* wrong digest */ | ||
| 274 | if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len, | ||
| 275 | eckey) == 1) { | ||
| 276 | BIO_printf(out, " failed\n"); | ||
| 277 | goto builtin_err; | ||
| 278 | } | ||
| 279 | BIO_printf(out, "."); | ||
| 280 | (void)BIO_flush(out); | ||
| 281 | /* wrong length */ | ||
| 282 | if (ECDSA_verify(0, digest, 20, signature, sig_len - 1, | ||
| 283 | eckey) == 1) { | ||
| 284 | BIO_printf(out, " failed\n"); | ||
| 285 | goto builtin_err; | ||
| 286 | } | ||
| 287 | BIO_printf(out, "."); | ||
| 288 | (void)BIO_flush(out); | ||
| 289 | |||
| 290 | /* | ||
| 291 | * Modify a single byte of the signature: to ensure we don't | ||
| 292 | * garble the ASN1 structure, we read the raw signature and | ||
| 293 | * modify a byte in one of the bignums directly. | ||
| 294 | */ | ||
| 295 | sig_ptr = signature; | ||
| 296 | if ((ecdsa_sig = d2i_ECDSA_SIG(NULL, &sig_ptr, | ||
| 297 | sig_len)) == NULL) { | ||
| 298 | BIO_printf(out, " failed\n"); | ||
| 299 | goto builtin_err; | ||
| 300 | } | ||
| 301 | |||
| 302 | /* Store the two BIGNUMs in raw_buf. */ | ||
| 303 | r_len = BN_num_bytes(ecdsa_sig->r); | ||
| 304 | s_len = BN_num_bytes(ecdsa_sig->s); | ||
| 305 | bn_len = (degree + 7) / 8; | ||
| 306 | if ((r_len > bn_len) || (s_len > bn_len)) { | ||
| 307 | BIO_printf(out, " failed\n"); | ||
| 308 | goto builtin_err; | ||
| 309 | } | ||
| 310 | buf_len = 2 * bn_len; | ||
| 311 | if ((raw_buf = calloc(1, buf_len)) == NULL) | ||
| 312 | goto builtin_err; | ||
| 313 | BN_bn2bin(ecdsa_sig->r, raw_buf + bn_len - r_len); | ||
| 314 | BN_bn2bin(ecdsa_sig->s, raw_buf + buf_len - s_len); | ||
| 315 | |||
| 316 | /* Modify a single byte in the buffer. */ | ||
| 317 | offset = raw_buf[10] % buf_len; | ||
| 318 | dirt = raw_buf[11] ? raw_buf[11] : 1; | ||
| 319 | raw_buf[offset] ^= dirt; | ||
| 320 | /* Now read the BIGNUMs back in from raw_buf. */ | ||
| 321 | if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || | ||
| 322 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | ||
| 323 | goto builtin_err; | ||
| 324 | |||
| 325 | sig_ptr2 = signature; | ||
| 326 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); | ||
| 327 | if (ECDSA_verify(0, digest, 20, signature, sig_len, | ||
| 328 | eckey) == 1) { | ||
| 329 | BIO_printf(out, " failed\n"); | ||
| 330 | goto builtin_err; | ||
| 331 | } | ||
| 332 | /* Sanity check: undo the modification and verify signature. */ | ||
| 333 | raw_buf[offset] ^= dirt; | ||
| 334 | if ((BN_bin2bn(raw_buf, bn_len, ecdsa_sig->r) == NULL) || | ||
| 335 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | ||
| 336 | goto builtin_err; | ||
| 337 | |||
| 338 | sig_ptr2 = signature; | ||
| 339 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); | ||
| 340 | if (ECDSA_verify(0, digest, 20, signature, sig_len, | ||
| 341 | eckey) != 1) { | ||
| 342 | BIO_printf(out, " failed\n"); | ||
| 343 | goto builtin_err; | ||
| 344 | } | ||
| 345 | BIO_printf(out, "."); | ||
| 346 | (void)BIO_flush(out); | ||
| 347 | |||
| 348 | BIO_printf(out, " ok\n"); | ||
| 349 | /* cleanup */ | ||
| 350 | /* clean bogus errors */ | ||
| 351 | ERR_clear_error(); | ||
| 352 | free(signature); | ||
| 353 | signature = NULL; | ||
| 354 | EC_KEY_free(eckey); | ||
| 355 | eckey = NULL; | ||
| 356 | EC_KEY_free(wrong_eckey); | ||
| 357 | wrong_eckey = NULL; | ||
| 358 | ECDSA_SIG_free(ecdsa_sig); | ||
| 359 | ecdsa_sig = NULL; | ||
| 360 | free(raw_buf); | ||
| 361 | raw_buf = NULL; | ||
| 362 | } | ||
| 363 | |||
| 364 | ret = 1; | ||
| 365 | builtin_err: | ||
| 366 | EC_KEY_free(eckey); | ||
| 367 | EC_KEY_free(wrong_eckey); | ||
| 368 | ECDSA_SIG_free(ecdsa_sig); | ||
| 369 | free(signature); | ||
| 370 | free(raw_buf); | ||
| 371 | free(curves); | ||
| 372 | |||
| 373 | return ret; | ||
| 374 | } | ||
| 375 | |||
| 376 | int | ||
| 377 | main(void) | ||
| 378 | { | ||
| 379 | int ret = 1; | ||
| 380 | BIO *out; | ||
| 381 | |||
| 382 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | ||
| 383 | |||
| 384 | ERR_load_crypto_strings(); | ||
| 385 | |||
| 386 | /* the tests */ | ||
| 387 | if (!test_builtin(out)) | ||
| 388 | goto err; | ||
| 389 | |||
| 390 | ret = 0; | ||
| 391 | err: | ||
| 392 | if (ret) | ||
| 393 | BIO_printf(out, "\nECDSA test failed\n"); | ||
| 394 | else | ||
| 395 | BIO_printf(out, "\nECDSA test passed\n"); | ||
| 396 | if (ret) | ||
| 397 | ERR_print_errors(out); | ||
| 398 | CRYPTO_cleanup_all_ex_data(); | ||
| 399 | ERR_remove_thread_state(NULL); | ||
| 400 | ERR_free_strings(); | ||
| 401 | CRYPTO_mem_leaks(out); | ||
| 402 | if (out != NULL) | ||
| 403 | BIO_free(out); | ||
| 404 | return ret; | ||
| 405 | } | ||
diff --git a/src/regress/lib/libcrypto/engine/Makefile b/src/regress/lib/libcrypto/engine/Makefile deleted file mode 100644 index 7f11b0d382..0000000000 --- a/src/regress/lib/libcrypto/engine/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= enginetest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/engine/enginetest.c b/src/regress/lib/libcrypto/engine/enginetest.c deleted file mode 100644 index 123866259b..0000000000 --- a/src/regress/lib/libcrypto/engine/enginetest.c +++ /dev/null | |||
| @@ -1,244 +0,0 @@ | |||
| 1 | /* $OpenBSD: enginetest.c,v 1.8 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
| 3 | * project 2000. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include <openssl/crypto.h> | ||
| 64 | #include <openssl/engine.h> | ||
| 65 | #include <openssl/err.h> | ||
| 66 | |||
| 67 | static void display_engine_list(void) | ||
| 68 | { | ||
| 69 | ENGINE *h; | ||
| 70 | int loop; | ||
| 71 | |||
| 72 | h = ENGINE_get_first(); | ||
| 73 | loop = 0; | ||
| 74 | printf("listing available engine types\n"); | ||
| 75 | while (h) { | ||
| 76 | printf("engine %i, id = \"%s\", name = \"%s\"\n", | ||
| 77 | loop++, ENGINE_get_id(h), ENGINE_get_name(h)); | ||
| 78 | h = ENGINE_get_next(h); | ||
| 79 | } | ||
| 80 | |||
| 81 | printf("end of list\n"); | ||
| 82 | /* | ||
| 83 | * ENGINE_get_first() increases the struct_ref counter, so we must call | ||
| 84 | * ENGINE_free() to decrease it again | ||
| 85 | */ | ||
| 86 | ENGINE_free(h); | ||
| 87 | } | ||
| 88 | |||
| 89 | int main(int argc, char *argv[]) | ||
| 90 | { | ||
| 91 | ENGINE *block[512]; | ||
| 92 | char *id, *name; | ||
| 93 | ENGINE *ptr; | ||
| 94 | int loop; | ||
| 95 | int to_return = 1; | ||
| 96 | ENGINE *new_h1 = NULL; | ||
| 97 | ENGINE *new_h2 = NULL; | ||
| 98 | ENGINE *new_h3 = NULL; | ||
| 99 | ENGINE *new_h4 = NULL; | ||
| 100 | |||
| 101 | ERR_load_crypto_strings(); | ||
| 102 | |||
| 103 | memset(block, 0, 512 * sizeof(ENGINE *)); | ||
| 104 | if (((new_h1 = ENGINE_new()) == NULL) || | ||
| 105 | !ENGINE_set_id(new_h1, "test_id0") || | ||
| 106 | !ENGINE_set_name(new_h1, "First test item") || | ||
| 107 | ((new_h2 = ENGINE_new()) == NULL) || | ||
| 108 | !ENGINE_set_id(new_h2, "test_id1") || | ||
| 109 | !ENGINE_set_name(new_h2, "Second test item") || | ||
| 110 | ((new_h3 = ENGINE_new()) == NULL) || | ||
| 111 | !ENGINE_set_id(new_h3, "test_id2") || | ||
| 112 | !ENGINE_set_name(new_h3, "Third test item") || | ||
| 113 | ((new_h4 = ENGINE_new()) == NULL) || | ||
| 114 | !ENGINE_set_id(new_h4, "test_id3") || | ||
| 115 | !ENGINE_set_name(new_h4, "Fourth test item")) { | ||
| 116 | printf("Couldn't set up test ENGINE structures\n"); | ||
| 117 | goto end; | ||
| 118 | } | ||
| 119 | |||
| 120 | printf("\nenginetest beginning\n\n"); | ||
| 121 | display_engine_list(); | ||
| 122 | if (!ENGINE_add(new_h1)) { | ||
| 123 | printf("Add failed!\n"); | ||
| 124 | goto end; | ||
| 125 | } | ||
| 126 | display_engine_list(); | ||
| 127 | ptr = ENGINE_get_first(); | ||
| 128 | if (!ENGINE_remove(ptr)) { | ||
| 129 | printf("Remove failed!\n"); | ||
| 130 | goto end; | ||
| 131 | } | ||
| 132 | ENGINE_free(ptr); | ||
| 133 | display_engine_list(); | ||
| 134 | if (!ENGINE_add(new_h3) || !ENGINE_add(new_h2)) { | ||
| 135 | printf("Add failed!\n"); | ||
| 136 | goto end; | ||
| 137 | } | ||
| 138 | display_engine_list(); | ||
| 139 | if (!ENGINE_remove(new_h2)) { | ||
| 140 | printf("Remove failed!\n"); | ||
| 141 | goto end; | ||
| 142 | } | ||
| 143 | display_engine_list(); | ||
| 144 | if (!ENGINE_add(new_h4)) { | ||
| 145 | printf("Add failed!\n"); | ||
| 146 | goto end; | ||
| 147 | } | ||
| 148 | display_engine_list(); | ||
| 149 | if (ENGINE_add(new_h3)) { | ||
| 150 | printf("Add *should* have failed but didn't!\n"); | ||
| 151 | goto end; | ||
| 152 | } else | ||
| 153 | printf("Add that should fail did.\n"); | ||
| 154 | ERR_clear_error(); | ||
| 155 | if (ENGINE_remove(new_h2)) { | ||
| 156 | printf("Remove *should* have failed but didn't!\n"); | ||
| 157 | goto end; | ||
| 158 | } else | ||
| 159 | printf("Remove that should fail did.\n"); | ||
| 160 | ERR_clear_error(); | ||
| 161 | if (!ENGINE_remove(new_h3)) { | ||
| 162 | printf("Remove failed!\n"); | ||
| 163 | goto end; | ||
| 164 | } | ||
| 165 | display_engine_list(); | ||
| 166 | if (!ENGINE_remove(new_h4)) { | ||
| 167 | printf("Remove failed!\n"); | ||
| 168 | goto end; | ||
| 169 | } | ||
| 170 | display_engine_list(); | ||
| 171 | /* | ||
| 172 | * Depending on whether there's any hardware support compiled | ||
| 173 | * in, this remove may be destined to fail. | ||
| 174 | */ | ||
| 175 | ptr = ENGINE_get_first(); | ||
| 176 | if (ptr) | ||
| 177 | if (!ENGINE_remove(ptr)) | ||
| 178 | printf("Remove failed!i - probably no hardware " | ||
| 179 | "support present.\n"); | ||
| 180 | ENGINE_free(ptr); | ||
| 181 | display_engine_list(); | ||
| 182 | |||
| 183 | if (!ENGINE_add(new_h1) || !ENGINE_remove(new_h1)) { | ||
| 184 | printf("Couldn't add and remove to an empty list!\n"); | ||
| 185 | goto end; | ||
| 186 | } else | ||
| 187 | printf("Successfully added and removed to an empty list!\n"); | ||
| 188 | |||
| 189 | printf("About to beef up the engine-type list\n"); | ||
| 190 | for (loop = 0; loop < 512; loop++) { | ||
| 191 | if (asprintf(&id, "id%i", loop) == -1) | ||
| 192 | goto end; | ||
| 193 | if (asprintf(&name, "Fake engine type %i", loop) == -1) | ||
| 194 | goto end; | ||
| 195 | |||
| 196 | if (((block[loop] = ENGINE_new()) == NULL) || | ||
| 197 | !id || !ENGINE_set_id(block[loop], id) || | ||
| 198 | !name || !ENGINE_set_name(block[loop], name)) { | ||
| 199 | printf("Couldn't create block of ENGINE structures.\n"); | ||
| 200 | goto end; | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | for (loop = 0; loop < 512; loop++) { | ||
| 205 | if (!ENGINE_add(block[loop])) { | ||
| 206 | printf("\nAdding stopped at %i, (%s,%s)\n", | ||
| 207 | loop, ENGINE_get_id(block[loop]), | ||
| 208 | ENGINE_get_name(block[loop])); | ||
| 209 | break; | ||
| 210 | } | ||
| 211 | printf("."); | ||
| 212 | fflush(stdout); | ||
| 213 | } | ||
| 214 | printf("\nAbout to empty the engine-type list\n"); | ||
| 215 | while ((ptr = ENGINE_get_first()) != NULL) { | ||
| 216 | if (!ENGINE_remove(ptr)) { | ||
| 217 | printf("\nRemove failed!\n"); | ||
| 218 | goto end; | ||
| 219 | } | ||
| 220 | ENGINE_free(ptr); | ||
| 221 | printf("."); fflush(stdout); | ||
| 222 | } | ||
| 223 | for (loop = 0; loop < 512; loop++) { | ||
| 224 | free((void *)ENGINE_get_id(block[loop])); | ||
| 225 | free((void *)ENGINE_get_name(block[loop])); | ||
| 226 | } | ||
| 227 | printf("\nTests completed happily\n"); | ||
| 228 | to_return = 0; | ||
| 229 | end: | ||
| 230 | if (to_return) | ||
| 231 | ERR_print_errors_fp(stderr); | ||
| 232 | ENGINE_free(new_h1); | ||
| 233 | ENGINE_free(new_h2); | ||
| 234 | ENGINE_free(new_h3); | ||
| 235 | ENGINE_free(new_h4); | ||
| 236 | for (loop = 0; loop < 512; loop++) | ||
| 237 | ENGINE_free(block[loop]); | ||
| 238 | ENGINE_cleanup(); | ||
| 239 | CRYPTO_cleanup_all_ex_data(); | ||
| 240 | ERR_free_strings(); | ||
| 241 | ERR_remove_thread_state(NULL); | ||
| 242 | CRYPTO_mem_leaks_fp(stderr); | ||
| 243 | return to_return; | ||
| 244 | } | ||
diff --git a/src/regress/lib/libcrypto/evp/Makefile b/src/regress/lib/libcrypto/evp/Makefile deleted file mode 100644 index 33c77fc1dd..0000000000 --- a/src/regress/lib/libcrypto/evp/Makefile +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= evptest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-evptest | ||
| 10 | |||
| 11 | regress-evptest: ${PROG} | ||
| 12 | ./${PROG} ${.CURDIR}/evptests.txt | ||
| 13 | |||
| 14 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/evp/evptest.c b/src/regress/lib/libcrypto/evp/evptest.c deleted file mode 100644 index 1aa11d7b1e..0000000000 --- a/src/regress/lib/libcrypto/evp/evptest.c +++ /dev/null | |||
| @@ -1,436 +0,0 @@ | |||
| 1 | /* $OpenBSD: evptest.c,v 1.7 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Written by Ben Laurie, 2001 */ | ||
| 3 | /* | ||
| 4 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in | ||
| 15 | * the documentation and/or other materials provided with the | ||
| 16 | * distribution. | ||
| 17 | * | ||
| 18 | * 3. All advertising materials mentioning features or use of this | ||
| 19 | * software must display the following acknowledgment: | ||
| 20 | * "This product includes software developed by the OpenSSL Project | ||
| 21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 22 | * | ||
| 23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 24 | * endorse or promote products derived from this software without | ||
| 25 | * prior written permission. For written permission, please contact | ||
| 26 | * openssl-core@openssl.org. | ||
| 27 | * | ||
| 28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 29 | * nor may "OpenSSL" appear in their names without prior written | ||
| 30 | * permission of the OpenSSL Project. | ||
| 31 | * | ||
| 32 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 33 | * acknowledgment: | ||
| 34 | * "This product includes software developed by the OpenSSL Project | ||
| 35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 36 | * | ||
| 37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include <stdio.h> | ||
| 52 | #include <string.h> | ||
| 53 | |||
| 54 | #include <openssl/opensslconf.h> | ||
| 55 | #include <openssl/evp.h> | ||
| 56 | #ifndef OPENSSL_NO_ENGINE | ||
| 57 | #include <openssl/engine.h> | ||
| 58 | #endif | ||
| 59 | #include <openssl/err.h> | ||
| 60 | #include <openssl/conf.h> | ||
| 61 | |||
| 62 | static void | ||
| 63 | hexdump(FILE *f, const char *title, const unsigned char *s, int l) | ||
| 64 | { | ||
| 65 | int n = 0; | ||
| 66 | |||
| 67 | fprintf(f, "%s",title); | ||
| 68 | for (; n < l; ++n) { | ||
| 69 | if ((n % 16) == 0) | ||
| 70 | fprintf(f, "\n%04x",n); | ||
| 71 | fprintf(f, " %02x",s[n]); | ||
| 72 | } | ||
| 73 | fprintf(f, "\n"); | ||
| 74 | } | ||
| 75 | |||
| 76 | static int | ||
| 77 | convert(unsigned char *s) | ||
| 78 | { | ||
| 79 | unsigned char *d; | ||
| 80 | |||
| 81 | for (d = s; *s; s += 2,++d) { | ||
| 82 | unsigned int n; | ||
| 83 | |||
| 84 | if (!s[1]) { | ||
| 85 | fprintf(stderr, "Odd number of hex digits!\n"); | ||
| 86 | exit(4); | ||
| 87 | } | ||
| 88 | if (sscanf((char *)s, "%2x", &n) != 1) { | ||
| 89 | fprintf(stderr, "Invalid hex value at %s\n", s); | ||
| 90 | exit(4); | ||
| 91 | } | ||
| 92 | |||
| 93 | *d = (unsigned char)n; | ||
| 94 | } | ||
| 95 | return s - d; | ||
| 96 | } | ||
| 97 | |||
| 98 | static char * | ||
| 99 | sstrsep(char **string, const char *delim) | ||
| 100 | { | ||
| 101 | char isdelim[256]; | ||
| 102 | char *token = *string; | ||
| 103 | |||
| 104 | if (**string == 0) | ||
| 105 | return NULL; | ||
| 106 | |||
| 107 | memset(isdelim, 0, 256); | ||
| 108 | isdelim[0] = 1; | ||
| 109 | |||
| 110 | while (*delim) { | ||
| 111 | isdelim[(unsigned char)(*delim)] = 1; | ||
| 112 | delim++; | ||
| 113 | } | ||
| 114 | |||
| 115 | while (!isdelim[(unsigned char)(**string)]) { | ||
| 116 | (*string)++; | ||
| 117 | } | ||
| 118 | |||
| 119 | if (**string) { | ||
| 120 | **string = 0; | ||
| 121 | (*string)++; | ||
| 122 | } | ||
| 123 | |||
| 124 | return token; | ||
| 125 | } | ||
| 126 | |||
| 127 | static unsigned char * | ||
| 128 | ustrsep(char **p, const char *sep) | ||
| 129 | { | ||
| 130 | return (unsigned char *)sstrsep(p, sep); | ||
| 131 | } | ||
| 132 | |||
| 133 | static int | ||
| 134 | test1_exit(int ec) | ||
| 135 | { | ||
| 136 | exit(ec); | ||
| 137 | return(0); /* To keep some compilers quiet */ | ||
| 138 | } | ||
| 139 | |||
| 140 | static void | ||
| 141 | test1(const EVP_CIPHER *c, const unsigned char *key, int kn, | ||
| 142 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | ||
| 143 | const unsigned char *ciphertext, int cn, int encdec) | ||
| 144 | { | ||
| 145 | EVP_CIPHER_CTX ctx; | ||
| 146 | unsigned char out[4096]; | ||
| 147 | int outl, outl2; | ||
| 148 | |||
| 149 | printf("Testing cipher %s%s\n", EVP_CIPHER_name(c), | ||
| 150 | (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)"))); | ||
| 151 | hexdump(stdout, "Key",key,kn); | ||
| 152 | if (in) | ||
| 153 | hexdump(stdout, "IV",iv,in); | ||
| 154 | hexdump(stdout, "Plaintext",plaintext,pn); | ||
| 155 | hexdump(stdout, "Ciphertext",ciphertext,cn); | ||
| 156 | |||
| 157 | if (kn != c->key_len) { | ||
| 158 | fprintf(stderr, "Key length doesn't match, got %d expected %lu\n",kn, | ||
| 159 | (unsigned long)c->key_len); | ||
| 160 | test1_exit(5); | ||
| 161 | } | ||
| 162 | EVP_CIPHER_CTX_init(&ctx); | ||
| 163 | if (encdec != 0) { | ||
| 164 | if (!EVP_EncryptInit_ex(&ctx, c,NULL, key, iv)) { | ||
| 165 | fprintf(stderr, "EncryptInit failed\n"); | ||
| 166 | ERR_print_errors_fp(stderr); | ||
| 167 | test1_exit(10); | ||
| 168 | } | ||
| 169 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | ||
| 170 | |||
| 171 | if (!EVP_EncryptUpdate(&ctx, out, &outl, plaintext, pn)) { | ||
| 172 | fprintf(stderr, "Encrypt failed\n"); | ||
| 173 | ERR_print_errors_fp(stderr); | ||
| 174 | test1_exit(6); | ||
| 175 | } | ||
| 176 | if (!EVP_EncryptFinal_ex(&ctx, out + outl, &outl2)) { | ||
| 177 | fprintf(stderr, "EncryptFinal failed\n"); | ||
| 178 | ERR_print_errors_fp(stderr); | ||
| 179 | test1_exit(7); | ||
| 180 | } | ||
| 181 | |||
| 182 | if (outl + outl2 != cn) { | ||
| 183 | fprintf(stderr, "Ciphertext length mismatch got %d expected %d\n", | ||
| 184 | outl + outl2, cn); | ||
| 185 | test1_exit(8); | ||
| 186 | } | ||
| 187 | |||
| 188 | if (memcmp(out, ciphertext, cn)) { | ||
| 189 | fprintf(stderr, "Ciphertext mismatch\n"); | ||
| 190 | hexdump(stderr, "Got",out,cn); | ||
| 191 | hexdump(stderr, "Expected",ciphertext,cn); | ||
| 192 | test1_exit(9); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | if (encdec <= 0) { | ||
| 197 | if (!EVP_DecryptInit_ex(&ctx, c,NULL, key, iv)) { | ||
| 198 | fprintf(stderr, "DecryptInit failed\n"); | ||
| 199 | ERR_print_errors_fp(stderr); | ||
| 200 | test1_exit(11); | ||
| 201 | } | ||
| 202 | EVP_CIPHER_CTX_set_padding(&ctx, 0); | ||
| 203 | |||
| 204 | if (!EVP_DecryptUpdate(&ctx, out, &outl, ciphertext, cn)) { | ||
| 205 | fprintf(stderr, "Decrypt failed\n"); | ||
| 206 | ERR_print_errors_fp(stderr); | ||
| 207 | test1_exit(6); | ||
| 208 | } | ||
| 209 | if (!EVP_DecryptFinal_ex(&ctx, out + outl, &outl2)) { | ||
| 210 | fprintf(stderr, "DecryptFinal failed\n"); | ||
| 211 | ERR_print_errors_fp(stderr); | ||
| 212 | test1_exit(7); | ||
| 213 | } | ||
| 214 | |||
| 215 | if (outl + outl2 != pn) { | ||
| 216 | fprintf(stderr, "Plaintext length mismatch got %d expected %d\n", | ||
| 217 | outl + outl2, pn); | ||
| 218 | test1_exit(8); | ||
| 219 | } | ||
| 220 | |||
| 221 | if (memcmp(out, plaintext, pn)) { | ||
| 222 | fprintf(stderr, "Plaintext mismatch\n"); | ||
| 223 | hexdump(stderr, "Got",out,pn); | ||
| 224 | hexdump(stderr, "Expected",plaintext,pn); | ||
| 225 | test1_exit(9); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 230 | |||
| 231 | printf("\n"); | ||
| 232 | } | ||
| 233 | |||
| 234 | static int | ||
| 235 | test_cipher(const char *cipher, const unsigned char *key, int kn, | ||
| 236 | const unsigned char *iv, int in, const unsigned char *plaintext, int pn, | ||
| 237 | const unsigned char *ciphertext, int cn, int encdec) | ||
| 238 | { | ||
| 239 | const EVP_CIPHER *c; | ||
| 240 | |||
| 241 | c = EVP_get_cipherbyname(cipher); | ||
| 242 | if (!c) | ||
| 243 | return 0; | ||
| 244 | |||
| 245 | test1(c, key, kn, iv, in, plaintext, pn, ciphertext, cn, encdec); | ||
| 246 | |||
| 247 | return 1; | ||
| 248 | } | ||
| 249 | |||
| 250 | static int | ||
| 251 | test_digest(const char *digest, const unsigned char *plaintext, int pn, | ||
| 252 | const unsigned char *ciphertext, unsigned int cn) | ||
| 253 | { | ||
| 254 | const EVP_MD *d; | ||
| 255 | EVP_MD_CTX ctx; | ||
| 256 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
| 257 | unsigned int mdn; | ||
| 258 | |||
| 259 | d = EVP_get_digestbyname(digest); | ||
| 260 | if (!d) | ||
| 261 | return 0; | ||
| 262 | |||
| 263 | printf("Testing digest %s\n",EVP_MD_name(d)); | ||
| 264 | hexdump(stdout, "Plaintext",plaintext,pn); | ||
| 265 | hexdump(stdout, "Digest",ciphertext,cn); | ||
| 266 | |||
| 267 | EVP_MD_CTX_init(&ctx); | ||
| 268 | if (!EVP_DigestInit_ex(&ctx, d, NULL)) { | ||
| 269 | fprintf(stderr, "DigestInit failed\n"); | ||
| 270 | ERR_print_errors_fp(stderr); | ||
| 271 | exit(100); | ||
| 272 | } | ||
| 273 | if (!EVP_DigestUpdate(&ctx, plaintext, pn)) { | ||
| 274 | fprintf(stderr, "DigestUpdate failed\n"); | ||
| 275 | ERR_print_errors_fp(stderr); | ||
| 276 | exit(101); | ||
| 277 | } | ||
| 278 | if (!EVP_DigestFinal_ex(&ctx, md, &mdn)) { | ||
| 279 | fprintf(stderr, "DigestFinal failed\n"); | ||
| 280 | ERR_print_errors_fp(stderr); | ||
| 281 | exit(101); | ||
| 282 | } | ||
| 283 | EVP_MD_CTX_cleanup(&ctx); | ||
| 284 | |||
| 285 | if (mdn != cn) { | ||
| 286 | fprintf(stderr, "Digest length mismatch, got %d expected %d\n",mdn,cn); | ||
| 287 | exit(102); | ||
| 288 | } | ||
| 289 | |||
| 290 | if (memcmp(md, ciphertext, cn)) { | ||
| 291 | fprintf(stderr, "Digest mismatch\n"); | ||
| 292 | hexdump(stderr, "Got",md,cn); | ||
| 293 | hexdump(stderr, "Expected",ciphertext,cn); | ||
| 294 | exit(103); | ||
| 295 | } | ||
| 296 | |||
| 297 | printf("\n"); | ||
| 298 | |||
| 299 | EVP_MD_CTX_cleanup(&ctx); | ||
| 300 | |||
| 301 | return 1; | ||
| 302 | } | ||
| 303 | |||
| 304 | int | ||
| 305 | main(int argc, char **argv) | ||
| 306 | { | ||
| 307 | const char *szTestFile; | ||
| 308 | FILE *f; | ||
| 309 | |||
| 310 | if (argc != 2) { | ||
| 311 | fprintf(stderr, "%s <test file>\n",argv[0]); | ||
| 312 | exit(1); | ||
| 313 | } | ||
| 314 | |||
| 315 | szTestFile = argv[1]; | ||
| 316 | |||
| 317 | f=fopen(szTestFile, "r"); | ||
| 318 | if (!f) { | ||
| 319 | perror(szTestFile); | ||
| 320 | exit(2); | ||
| 321 | } | ||
| 322 | |||
| 323 | /* Load up the software EVP_CIPHER and EVP_MD definitions */ | ||
| 324 | OpenSSL_add_all_ciphers(); | ||
| 325 | OpenSSL_add_all_digests(); | ||
| 326 | #ifndef OPENSSL_NO_ENGINE | ||
| 327 | /* Load all compiled-in ENGINEs */ | ||
| 328 | ENGINE_load_builtin_engines(); | ||
| 329 | #endif | ||
| 330 | #if 0 | ||
| 331 | OPENSSL_config(); | ||
| 332 | #endif | ||
| 333 | #ifndef OPENSSL_NO_ENGINE | ||
| 334 | /* Register all available ENGINE implementations of ciphers and digests. | ||
| 335 | * This could perhaps be changed to "ENGINE_register_all_complete()"? */ | ||
| 336 | ENGINE_register_all_ciphers(); | ||
| 337 | ENGINE_register_all_digests(); | ||
| 338 | /* If we add command-line options, this statement should be switchable. | ||
| 339 | * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if | ||
| 340 | * they weren't already initialised. */ | ||
| 341 | /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */ | ||
| 342 | #endif | ||
| 343 | |||
| 344 | for (;;) { | ||
| 345 | char line[4096]; | ||
| 346 | char *p; | ||
| 347 | char *cipher; | ||
| 348 | unsigned char *iv, *key, *plaintext, *ciphertext; | ||
| 349 | int encdec; | ||
| 350 | int kn, in, pn, cn; | ||
| 351 | |||
| 352 | if (!fgets((char *)line, sizeof line, f)) | ||
| 353 | break; | ||
| 354 | if (line[0] == '#' || line[0] == '\n') | ||
| 355 | continue; | ||
| 356 | p = line; | ||
| 357 | cipher=sstrsep(&p, ":"); | ||
| 358 | key=ustrsep(&p, ":"); | ||
| 359 | iv=ustrsep(&p, ":"); | ||
| 360 | plaintext=ustrsep(&p, ":"); | ||
| 361 | ciphertext=ustrsep(&p, ":"); | ||
| 362 | if (p[-1] == '\n') { | ||
| 363 | p[-1] = '\0'; | ||
| 364 | encdec = -1; | ||
| 365 | } else { | ||
| 366 | encdec = atoi(sstrsep(&p, "\n")); | ||
| 367 | } | ||
| 368 | |||
| 369 | |||
| 370 | kn = convert(key); | ||
| 371 | in = convert(iv); | ||
| 372 | pn = convert(plaintext); | ||
| 373 | cn = convert(ciphertext); | ||
| 374 | |||
| 375 | if (!test_cipher(cipher, key, kn, iv, in, plaintext, pn, ciphertext, cn, encdec) && | ||
| 376 | !test_digest(cipher, plaintext, pn, ciphertext, cn)) { | ||
| 377 | #ifdef OPENSSL_NO_AES | ||
| 378 | if (strstr(cipher, "AES") == cipher) { | ||
| 379 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 380 | continue; | ||
| 381 | } | ||
| 382 | #endif | ||
| 383 | #ifdef OPENSSL_NO_DES | ||
| 384 | if (strstr(cipher, "DES") == cipher) { | ||
| 385 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 386 | continue; | ||
| 387 | } | ||
| 388 | #endif | ||
| 389 | #ifdef OPENSSL_NO_RC4 | ||
| 390 | if (strstr(cipher, "RC4") == cipher) { | ||
| 391 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 392 | continue; | ||
| 393 | } | ||
| 394 | #endif | ||
| 395 | #ifdef OPENSSL_NO_CAMELLIA | ||
| 396 | if (strstr(cipher, "CAMELLIA") == cipher) { | ||
| 397 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 398 | continue; | ||
| 399 | } | ||
| 400 | #endif | ||
| 401 | #ifdef OPENSSL_NO_SEED | ||
| 402 | if (strstr(cipher, "SEED") == cipher) { | ||
| 403 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 404 | continue; | ||
| 405 | } | ||
| 406 | #endif | ||
| 407 | #ifdef OPENSSL_NO_CHACHA | ||
| 408 | if (strstr(cipher, "ChaCha") == cipher) { | ||
| 409 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 410 | continue; | ||
| 411 | } | ||
| 412 | #endif | ||
| 413 | #ifdef OPENSSL_NO_GOST | ||
| 414 | if (strstr(cipher, "md_gost") == cipher || | ||
| 415 | strstr(cipher, "streebog") == cipher) { | ||
| 416 | fprintf(stdout, "Cipher disabled, skipping %s\n", cipher); | ||
| 417 | continue; | ||
| 418 | } | ||
| 419 | #endif | ||
| 420 | fprintf(stderr, "Can't find %s\n",cipher); | ||
| 421 | exit(3); | ||
| 422 | } | ||
| 423 | } | ||
| 424 | fclose(f); | ||
| 425 | |||
| 426 | #ifndef OPENSSL_NO_ENGINE | ||
| 427 | ENGINE_cleanup(); | ||
| 428 | #endif | ||
| 429 | EVP_cleanup(); | ||
| 430 | CRYPTO_cleanup_all_ex_data(); | ||
| 431 | ERR_remove_thread_state(NULL); | ||
| 432 | ERR_free_strings(); | ||
| 433 | CRYPTO_mem_leaks_fp(stderr); | ||
| 434 | |||
| 435 | return 0; | ||
| 436 | } | ||
diff --git a/src/regress/lib/libcrypto/evp/evptests.txt b/src/regress/lib/libcrypto/evp/evptests.txt deleted file mode 100644 index fd2c6cdfd1..0000000000 --- a/src/regress/lib/libcrypto/evp/evptests.txt +++ /dev/null | |||
| @@ -1,357 +0,0 @@ | |||
| 1 | # $OpenBSD: evptests.txt,v 1.5 2018/07/17 17:06:49 tb Exp $ | ||
| 2 | #cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt) | ||
| 3 | #digest:::input:output | ||
| 4 | |||
| 5 | # SHA(1) tests (from shatest.c) | ||
| 6 | SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d | ||
| 7 | |||
| 8 | # MD5 tests (from md5test.c) | ||
| 9 | MD5::::d41d8cd98f00b204e9800998ecf8427e | ||
| 10 | MD5:::61:0cc175b9c0f1b6a831c399e269772661 | ||
| 11 | MD5:::616263:900150983cd24fb0d6963f7d28e17f72 | ||
| 12 | MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0 | ||
| 13 | MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b | ||
| 14 | MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f | ||
| 15 | MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a | ||
| 16 | |||
| 17 | # MD5+SHA1 tests | ||
| 18 | MD5-SHA1:::616263:900150983cd24fb0d6963f7d28e17f72a9993e364706816aba3e25717850c26c9cd0d89d | ||
| 19 | |||
| 20 | # GOST R 34.11 tests | ||
| 21 | md_gost94::::981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0 | ||
| 22 | streebog512::::8e945da209aa869f0455928529bcae4679e9873ab707b55315f56ceb98bef0a7362f715528356ee83cda5f2aac4c6ad2ba3a715c1bcd81cb8e9f90bf4c1c1a8a | ||
| 23 | streebog256::::3f539a213e97c802cc229d474c6aa32a825a360b2a933a949fd925208d9ce1bb | ||
| 24 | streebog512:::303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132:1b54d01a4af5b9d5cc3d86d68d285462b19abc2475222f35c085122be4ba1ffa00ad30f8767b3a82384c6574f024c311e2a481332b08ef7f41797891c1646f48 | ||
| 25 | streebog256:::303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132:9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500 | ||
| 26 | streebog512:::d1e520e2e5f2f0e82c20d1f2f0e8e1eee6e820e2edf3f6e82c20e2e5fef2fa20f120eceef0ff20f1f2f0e5ebe0ece820ede020f5f0e0e1f0fbff20efebfaeafb20c8e3eef0e5e2fb:1e88e62226bfca6f9994f1f2d51569e0daf8475a3b0fe61a5300eee46d961376035fe83549ada2b8620fcd7c496ce5b33f0cb9dddc2b6460143b03dabac9fb28 | ||
| 27 | streebog256:::d1e520e2e5f2f0e82c20d1f2f0e8e1eee6e820e2edf3f6e82c20e2e5fef2fa20f120eceef0ff20f1f2f0e5ebe0ece820ede020f5f0e0e1f0fbff20efebfaeafb20c8e3eef0e5e2fb:9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50 | ||
| 28 | |||
| 29 | # AES 128 ECB tests (from FIPS-197 test vectors, encrypt) | ||
| 30 | |||
| 31 | AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A:1 | ||
| 32 | |||
| 33 | # AES 192 ECB tests (from FIPS-197 test vectors, encrypt) | ||
| 34 | |||
| 35 | AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191:1 | ||
| 36 | |||
| 37 | # AES 256 ECB tests (from FIPS-197 test vectors, encrypt) | ||
| 38 | |||
| 39 | AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089:1 | ||
| 40 | |||
| 41 | # AES 128 ECB tests (from NIST test vectors, encrypt) | ||
| 42 | |||
| 43 | #AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F:1 | ||
| 44 | |||
| 45 | # AES 128 ECB tests (from NIST test vectors, decrypt) | ||
| 46 | |||
| 47 | #AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000:0 | ||
| 48 | |||
| 49 | # AES 192 ECB tests (from NIST test vectors, decrypt) | ||
| 50 | |||
| 51 | #AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000:0 | ||
| 52 | |||
| 53 | # AES 256 ECB tests (from NIST test vectors, decrypt) | ||
| 54 | |||
| 55 | #AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000:0 | ||
| 56 | |||
| 57 | # AES 128 CBC tests (from NIST test vectors, encrypt) | ||
| 58 | |||
| 59 | #AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D:1 | ||
| 60 | |||
| 61 | # AES 192 CBC tests (from NIST test vectors, encrypt) | ||
| 62 | |||
| 63 | #AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104:1 | ||
| 64 | |||
| 65 | # AES 256 CBC tests (from NIST test vectors, encrypt) | ||
| 66 | |||
| 67 | #AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0:1 | ||
| 68 | |||
| 69 | # AES 128 CBC tests (from NIST test vectors, decrypt) | ||
| 70 | |||
| 71 | #AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000:0 | ||
| 72 | |||
| 73 | # AES tests from NIST document SP800-38A | ||
| 74 | # For all ECB encrypts and decrypts, the transformed sequence is | ||
| 75 | # AES-bits-ECB:key::plaintext:ciphertext:encdec | ||
| 76 | # ECB-AES128.Encrypt and ECB-AES128.Decrypt | ||
| 77 | AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:3AD77BB40D7A3660A89ECAF32466EF97 | ||
| 78 | AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:F5D3D58503B9699DE785895A96FDBAAF | ||
| 79 | AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:43B1CD7F598ECE23881B00E3ED030688 | ||
| 80 | AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:7B0C785E27E8AD3F8223207104725DD4 | ||
| 81 | # ECB-AES192.Encrypt and ECB-AES192.Decrypt | ||
| 82 | AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:BD334F1D6E45F25FF712A214571FA5CC | ||
| 83 | AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:974104846D0AD3AD7734ECB3ECEE4EEF | ||
| 84 | AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:EF7AFD2270E2E60ADCE0BA2FACE6444E | ||
| 85 | AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:9A4B41BA738D6C72FB16691603C18E0E | ||
| 86 | # ECB-AES256.Encrypt and ECB-AES256.Decrypt | ||
| 87 | AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:F3EED1BDB5D2A03C064B5A7E3DB181F8 | ||
| 88 | AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:591CCB10D410ED26DC5BA74A31362870 | ||
| 89 | AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:B6ED21B99CA6F4F9F153E7B1BEAFED1D | ||
| 90 | AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:23304B7A39F9F3FF067D8D8F9E24ECC7 | ||
| 91 | # For all CBC encrypts and decrypts, the transformed sequence is | ||
| 92 | # AES-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec | ||
| 93 | # CBC-AES128.Encrypt and CBC-AES128.Decrypt | ||
| 94 | AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:7649ABAC8119B246CEE98E9B12E9197D | ||
| 95 | AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:7649ABAC8119B246CEE98E9B12E9197D:AE2D8A571E03AC9C9EB76FAC45AF8E51:5086CB9B507219EE95DB113A917678B2 | ||
| 96 | AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:5086CB9B507219EE95DB113A917678B2:30C81C46A35CE411E5FBC1191A0A52EF:73BED6B8E3C1743B7116E69E22229516 | ||
| 97 | AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:73BED6B8E3C1743B7116E69E22229516:F69F2445DF4F9B17AD2B417BE66C3710:3FF1CAA1681FAC09120ECA307586E1A7 | ||
| 98 | # CBC-AES192.Encrypt and CBC-AES192.Decrypt | ||
| 99 | AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:4F021DB243BC633D7178183A9FA071E8 | ||
| 100 | AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:4F021DB243BC633D7178183A9FA071E8:AE2D8A571E03AC9C9EB76FAC45AF8E51:B4D9ADA9AD7DEDF4E5E738763F69145A | ||
| 101 | AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:B4D9ADA9AD7DEDF4E5E738763F69145A:30C81C46A35CE411E5FBC1191A0A52EF:571B242012FB7AE07FA9BAAC3DF102E0 | ||
| 102 | AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:571B242012FB7AE07FA9BAAC3DF102E0:F69F2445DF4F9B17AD2B417BE66C3710:08B0E27988598881D920A9E64F5615CD | ||
| 103 | # CBC-AES256.Encrypt and CBC-AES256.Decrypt | ||
| 104 | AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:F58C4C04D6E5F1BA779EABFB5F7BFBD6 | ||
| 105 | AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:F58C4C04D6E5F1BA779EABFB5F7BFBD6:AE2D8A571E03AC9C9EB76FAC45AF8E51:9CFC4E967EDB808D679F777BC6702C7D | ||
| 106 | AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:9CFC4E967EDB808D679F777BC6702C7D:30C81C46A35CE411E5FBC1191A0A52EF:39F23369A9D9BACFA530E26304231461 | ||
| 107 | AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39F23369A9D9BACFA530E26304231461:F69F2445DF4F9B17AD2B417BE66C3710:B2EB05E2C39BE9FCDA6C19078C6A9D1B | ||
| 108 | # We don't support CFB{1,8}-AESxxx.{En,De}crypt | ||
| 109 | # For all CFB128 encrypts and decrypts, the transformed sequence is | ||
| 110 | # AES-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec | ||
| 111 | # CFB128-AES128.Encrypt | ||
| 112 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1 | ||
| 113 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:1 | ||
| 114 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:1 | ||
| 115 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:1 | ||
| 116 | # CFB128-AES128.Decrypt | ||
| 117 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0 | ||
| 118 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:0 | ||
| 119 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:0 | ||
| 120 | AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:0 | ||
| 121 | # CFB128-AES192.Encrypt | ||
| 122 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1 | ||
| 123 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:1 | ||
| 124 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:1 | ||
| 125 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:1 | ||
| 126 | # CFB128-AES192.Decrypt | ||
| 127 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0 | ||
| 128 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:0 | ||
| 129 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:0 | ||
| 130 | AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:0 | ||
| 131 | # CFB128-AES256.Encrypt | ||
| 132 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1 | ||
| 133 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:1 | ||
| 134 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:1 | ||
| 135 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:1 | ||
| 136 | # CFB128-AES256.Decrypt | ||
| 137 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0 | ||
| 138 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:0 | ||
| 139 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:0 | ||
| 140 | AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:0 | ||
| 141 | # For all OFB encrypts and decrypts, the transformed sequence is | ||
| 142 | # AES-bits-CFB:key:IV/output':plaintext:ciphertext:encdec | ||
| 143 | # OFB-AES128.Encrypt | ||
| 144 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1 | ||
| 145 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:1 | ||
| 146 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:1 | ||
| 147 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:1 | ||
| 148 | # OFB-AES128.Decrypt | ||
| 149 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0 | ||
| 150 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:0 | ||
| 151 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:0 | ||
| 152 | AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:0 | ||
| 153 | # OFB-AES192.Encrypt | ||
| 154 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1 | ||
| 155 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:1 | ||
| 156 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:1 | ||
| 157 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:1 | ||
| 158 | # OFB-AES192.Decrypt | ||
| 159 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0 | ||
| 160 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:0 | ||
| 161 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:0 | ||
| 162 | AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:0 | ||
| 163 | # OFB-AES256.Encrypt | ||
| 164 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1 | ||
| 165 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:1 | ||
| 166 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:1 | ||
| 167 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:1 | ||
| 168 | # OFB-AES256.Decrypt | ||
| 169 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0 | ||
| 170 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:0 | ||
| 171 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:0 | ||
| 172 | AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:0 | ||
| 173 | |||
| 174 | # AES Counter test vectors from RFC3686 | ||
| 175 | aes-128-ctr:AE6852F8121067CC4BF7A5765577F39E:00000030000000000000000000000001:53696E676C6520626C6F636B206D7367:E4095D4FB7A7B3792D6175A3261311B8:1 | ||
| 176 | aes-128-ctr:7E24067817FAE0D743D6CE1F32539163:006CB6DBC0543B59DA48D90B00000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:5104A106168A72D9790D41EE8EDAD388EB2E1EFC46DA57C8FCE630DF9141BE28:1 | ||
| 177 | aes-128-ctr:7691BE035E5020A8AC6E618529F9A0DC:00E0017B27777F3F4A1786F000000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223:C1CF48A89F2FFDD9CF4652E9EFDB72D74540A42BDE6D7836D59A5CEAAEF3105325B2072F:1 | ||
| 178 | |||
| 179 | aes-192-ctr:16AF5B145FC9F579C175F93E3BFB0EED863D06CCFDB78515:0000004836733C147D6D93CB00000001:53696E676C6520626C6F636B206D7367:4B55384FE259C9C84E7935A003CBE928:1 | ||
| 180 | aes-192-ctr:7C5CB2401B3DC33C19E7340819E0F69C678C3DB8E6F6A91A:0096B03B020C6EADC2CB500D00000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:453243FC609B23327EDFAAFA7131CD9F8490701C5AD4A79CFC1FE0FF42F4FB00:1 | ||
| 181 | aes-192-ctr:02BF391EE8ECB159B959617B0965279BF59B60A786D3E0FE:0007BDFD5CBD60278DCC091200000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223:96893FC55E5C722F540B7DD1DDF7E758D288BC95C69165884536C811662F2188ABEE0935:1 | ||
| 182 | |||
| 183 | aes-256-ctr:776BEFF2851DB06F4C8A0542C8696F6C6A81AF1EEC96B4D37FC1D689E6C1C104:00000060DB5672C97AA8F0B200000001:53696E676C6520626C6F636B206D7367:145AD01DBF824EC7560863DC71E3E0C0:1 | ||
| 184 | aes-256-ctr:F6D66D6BD52D59BB0796365879EFF886C66DD51A5B6A99744B50590C87A23884:00FAAC24C1585EF15A43D87500000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F:F05E231B3894612C49EE000B804EB2A9B8306B508F839D6A5530831D9344AF1C:1 | ||
| 185 | aes-256-ctr:FF7A617CE69148E4F1726E2F43581DE2AA62D9F805532EDFF1EED687FB54153D:001CC5B751A51D70A1C1114800000001:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20212223:EB6C52821D0BBBF7CE7594462ACA4FAAB407DF866569FD07F48CC0B583D6071F1EC0E6B8:1 | ||
| 186 | |||
| 187 | # DES ECB tests (from destest) | ||
| 188 | |||
| 189 | DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7 | ||
| 190 | DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58 | ||
| 191 | DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B | ||
| 192 | DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533 | ||
| 193 | DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D | ||
| 194 | DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD | ||
| 195 | DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4 | ||
| 196 | |||
| 197 | # DESX-CBC tests (from destest) | ||
| 198 | DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4 | ||
| 199 | |||
| 200 | # DES EDE3 CBC tests (from destest) | ||
| 201 | DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675 | ||
| 202 | |||
| 203 | # RC4 tests (from rc4test) | ||
| 204 | RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596 | ||
| 205 | RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879 | ||
| 206 | RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a | ||
| 207 | RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858 | ||
| 208 | RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf | ||
| 209 | RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61 | ||
| 210 | |||
| 211 | |||
| 212 | # Camellia tests from RFC3713 | ||
| 213 | # For all ECB encrypts and decrypts, the transformed sequence is | ||
| 214 | # CAMELLIA-bits-ECB:key::plaintext:ciphertext:encdec | ||
| 215 | CAMELLIA-128-ECB:0123456789abcdeffedcba9876543210::0123456789abcdeffedcba9876543210:67673138549669730857065648eabe43 | ||
| 216 | CAMELLIA-192-ECB:0123456789abcdeffedcba98765432100011223344556677::0123456789abcdeffedcba9876543210:b4993401b3e996f84ee5cee7d79b09b9 | ||
| 217 | CAMELLIA-256-ECB:0123456789abcdeffedcba987654321000112233445566778899aabbccddeeff::0123456789abcdeffedcba9876543210:9acc237dff16d76c20ef7c919e3a7509 | ||
| 218 | |||
| 219 | # ECB-CAMELLIA128.Encrypt | ||
| 220 | CAMELLIA-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:77CF412067AF8270613529149919546F:1 | ||
| 221 | CAMELLIA-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:B22F3C36B72D31329EEE8ADDC2906C68:1 | ||
| 222 | CAMELLIA-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:2EDF1F3418D53B88841FC8985FB1ECF2:1 | ||
| 223 | |||
| 224 | # ECB-CAMELLIA128.Encrypt and ECB-CAMELLIA128.Decrypt | ||
| 225 | CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:432FC5DCD628115B7C388D770B270C96 | ||
| 226 | CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:0BE1F14023782A22E8384C5ABB7FAB2B | ||
| 227 | CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:A0A1ABCD1893AB6FE0FE5B65DF5F8636 | ||
| 228 | CAMELLIA-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:E61925E0D5DFAA9BB29F815B3076E51A | ||
| 229 | |||
| 230 | # ECB-CAMELLIA192.Encrypt and ECB-CAMELLIA192.Decrypt | ||
| 231 | CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:CCCC6C4E138B45848514D48D0D3439D3 | ||
| 232 | CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:5713C62C14B2EC0F8393B6AFD6F5785A | ||
| 233 | CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:B40ED2B60EB54D09D030CF511FEEF366 | ||
| 234 | CAMELLIA-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:909DBD95799096748CB27357E73E1D26 | ||
| 235 | |||
| 236 | # ECB-CAMELLIA256.Encrypt and ECB-CAMELLIA256.Decrypt | ||
| 237 | CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:BEFD219B112FA00098919CD101C9CCFA | ||
| 238 | CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:C91D3A8F1AEA08A9386CF4B66C0169EA | ||
| 239 | CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:A623D711DC5F25A51BB8A80D56397D28 | ||
| 240 | CAMELLIA-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:7960109FB6DC42947FCFE59EA3C5EB6B | ||
| 241 | |||
| 242 | # For all CBC encrypts and decrypts, the transformed sequence is | ||
| 243 | # CAMELLIA-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec | ||
| 244 | # CBC-CAMELLIA128.Encrypt and CBC-CAMELLIA128.Decrypt | ||
| 245 | CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:1607CF494B36BBF00DAEB0B503C831AB | ||
| 246 | CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:1607CF494B36BBF00DAEB0B503C831AB:AE2D8A571E03AC9C9EB76FAC45AF8E51:A2F2CF671629EF7840C5A5DFB5074887 | ||
| 247 | CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:A2F2CF671629EF7840C5A5DFB5074887:30C81C46A35CE411E5FBC1191A0A52EF:0F06165008CF8B8B5A63586362543E54 | ||
| 248 | CAMELLIA-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:36A84CDAFD5F9A85ADA0F0A993D6D577:F69F2445DF4F9B17AD2B417BE66C3710:74C64268CDB8B8FAF5B34E8AF3732980 | ||
| 249 | |||
| 250 | # CBC-CAMELLIA192.Encrypt and CBC-CAMELLIA192.Decrypt | ||
| 251 | CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:2A4830AB5AC4A1A2405955FD2195CF93 | ||
| 252 | CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2A4830AB5AC4A1A2405955FD2195CF93:AE2D8A571E03AC9C9EB76FAC45AF8E51:5D5A869BD14CE54264F892A6DD2EC3D5 | ||
| 253 | CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:5D5A869BD14CE54264F892A6DD2EC3D5:30C81C46A35CE411E5FBC1191A0A52EF:37D359C3349836D884E310ADDF68C449 | ||
| 254 | CAMELLIA-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:37D359C3349836D884E310ADDF68C449:F69F2445DF4F9B17AD2B417BE66C3710:01FAAA930B4AB9916E9668E1428C6B08 | ||
| 255 | |||
| 256 | # CBC-CAMELLIA256.Encrypt and CBC-CAMELLIA256.Decrypt | ||
| 257 | CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:E6CFA35FC02B134A4D2C0B6737AC3EDA | ||
| 258 | CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E6CFA35FC02B134A4D2C0B6737AC3EDA:AE2D8A571E03AC9C9EB76FAC45AF8E51:36CBEB73BD504B4070B1B7DE2B21EB50 | ||
| 259 | CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:36CBEB73BD504B4070B1B7DE2B21EB50:30C81C46A35CE411E5FBC1191A0A52EF:E31A6055297D96CA3330CDF1B1860A83 | ||
| 260 | CAMELLIA-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E31A6055297D96CA3330CDF1B1860A83:F69F2445DF4F9B17AD2B417BE66C3710:5D563F6D1CCCF236051C0C5C1C58F28F | ||
| 261 | |||
| 262 | # We don't support CFB{1,8}-CAMELLIAxxx.{En,De}crypt | ||
| 263 | # For all CFB128 encrypts and decrypts, the transformed sequence is | ||
| 264 | # CAMELLIA-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec | ||
| 265 | # CFB128-CAMELLIA128.Encrypt | ||
| 266 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1 | ||
| 267 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:1 | ||
| 268 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:1 | ||
| 269 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:1 | ||
| 270 | |||
| 271 | # CFB128-CAMELLIA128.Decrypt | ||
| 272 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0 | ||
| 273 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:14F7646187817EB586599146B82BD719:AE2D8A571E03AC9C9EB76FAC45AF8E51:A53D28BB82DF741103EA4F921A44880B:0 | ||
| 274 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:A53D28BB82DF741103EA4F921A44880B:30C81C46A35CE411E5FBC1191A0A52EF:9C2157A664626D1DEF9EA420FDE69B96:0 | ||
| 275 | CAMELLIA-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:9C2157A664626D1DEF9EA420FDE69B96:F69F2445DF4F9B17AD2B417BE66C3710:742A25F0542340C7BAEF24CA8482BB09:0 | ||
| 276 | |||
| 277 | # CFB128-CAMELLIA192.Encrypt | ||
| 278 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1 | ||
| 279 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:1 | ||
| 280 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:1 | ||
| 281 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:1 | ||
| 282 | |||
| 283 | # CFB128-CAMELLIA192.Decrypt | ||
| 284 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0 | ||
| 285 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:C832BB9780677DAA82D9B6860DCD565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:86F8491627906D780C7A6D46EA331F98:0 | ||
| 286 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:86F8491627906D780C7A6D46EA331F98:30C81C46A35CE411E5FBC1191A0A52EF:69511CCE594CF710CB98BB63D7221F01:0 | ||
| 287 | CAMELLIA-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:69511CCE594CF710CB98BB63D7221F01:F69F2445DF4F9B17AD2B417BE66C3710:D5B5378A3ABED55803F25565D8907B84:0 | ||
| 288 | |||
| 289 | # CFB128-CAMELLIA256.Encrypt | ||
| 290 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1 | ||
| 291 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:1 | ||
| 292 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:1 | ||
| 293 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:1 | ||
| 294 | |||
| 295 | # CFB128-CAMELLIA256.Decrypt | ||
| 296 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0 | ||
| 297 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:CF6107BB0CEA7D7FB1BD31F5E7B06C93:AE2D8A571E03AC9C9EB76FAC45AF8E51:89BEDB4CCDD864EA11BA4CBE849B5E2B:0 | ||
| 298 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:89BEDB4CCDD864EA11BA4CBE849B5E2B:30C81C46A35CE411E5FBC1191A0A52EF:555FC3F34BDD2D54C62D9E3BF338C1C4:0 | ||
| 299 | CAMELLIA-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:555FC3F34BDD2D54C62D9E3BF338C1C4:F69F2445DF4F9B17AD2B417BE66C3710:5953ADCE14DB8C7F39F1BD39F359BFFA:0 | ||
| 300 | |||
| 301 | # For all OFB encrypts and decrypts, the transformed sequence is | ||
| 302 | # CAMELLIA-bits-OFB:key:IV/output':plaintext:ciphertext:encdec | ||
| 303 | # OFB-CAMELLIA128.Encrypt | ||
| 304 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:1 | ||
| 305 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:1 | ||
| 306 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:1 | ||
| 307 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:1 | ||
| 308 | |||
| 309 | # OFB-CAMELLIA128.Decrypt | ||
| 310 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:14F7646187817EB586599146B82BD719:0 | ||
| 311 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:25623DB569CA51E01482649977E28D84:0 | ||
| 312 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:C776634A60729DC657D12B9FCA801E98:0 | ||
| 313 | CAMELLIA-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:D776379BE0E50825E681DA1A4C980E8E:0 | ||
| 314 | |||
| 315 | # OFB-CAMELLIA192.Encrypt | ||
| 316 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:1 | ||
| 317 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:1 | ||
| 318 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:1 | ||
| 319 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:1 | ||
| 320 | |||
| 321 | # OFB-CAMELLIA192.Decrypt | ||
| 322 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:C832BB9780677DAA82D9B6860DCD565E:0 | ||
| 323 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:8ECEB7D0350D72C7F78562AEBDF99339:0 | ||
| 324 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:BDD62DBBB9700846C53B507F544696F0:0 | ||
| 325 | CAMELLIA-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:E28014E046B802F385C4C2E13EAD4A72:0 | ||
| 326 | |||
| 327 | # OFB-CAMELLIA256.Encrypt | ||
| 328 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:1 | ||
| 329 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:1 | ||
| 330 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:1 | ||
| 331 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:1 | ||
| 332 | |||
| 333 | # OFB-CAMELLIA256.Decrypt | ||
| 334 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CF6107BB0CEA7D7FB1BD31F5E7B06C93:0 | ||
| 335 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:127AD97E8E3994E4820027D7BA109368:0 | ||
| 336 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:6BFF6265A6A6B7A535BC65A80B17214E:0 | ||
| 337 | CAMELLIA-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0A4A0404E26AA78A27CB271E8BF3CF20:0 | ||
| 338 | |||
| 339 | # SEED test vectors from RFC4269 | ||
| 340 | SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:0 | ||
| 341 | SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:0 | ||
| 342 | SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:0 | ||
| 343 | SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:0 | ||
| 344 | SEED-ECB:00000000000000000000000000000000::000102030405060708090A0B0C0D0E0F:5EBAC6E0054E166819AFF1CC6D346CDB:1 | ||
| 345 | SEED-ECB:000102030405060708090A0B0C0D0E0F::00000000000000000000000000000000:C11F22F20140505084483597E4370F43:1 | ||
| 346 | SEED-ECB:4706480851E61BE85D74BFB3FD956185::83A2F8A288641FB9A4E9A5CC2F131C7D:EE54D13EBCAE706D226BC3142CD40D4A:1 | ||
| 347 | SEED-ECB:28DBC3BC49FFD87DCFA509B11D422BE7::B41E6BE2EBA84A148E2EED84593C5EC7:9B9B7BFCD1813CB95D0B3618F40F5122:1 | ||
| 348 | |||
| 349 | # ChaCha test vectors | ||
| 350 | ChaCha:0000000000000000000000000000000000000000000000000000000000000000:0000000000000000:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586:1 | ||
| 351 | ChaCha:0100000000000000000000000000000000000000000000000000000000000000:0000000000000000:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:c5d30a7ce1ec119378c84f487d775a8542f13ece238a9455e8229e888de85bbd29eb63d0a17a5b999b52da22be4023eb07620a54f6fa6ad8737b71eb0464dac0:1 | ||
| 352 | ChaCha:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff:ffffffffffffffff:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:d9bf3f6bce6ed0b54254557767fb57443dd4778911b606055c39cc25e674b8363feabc57fde54f790c52c8ae43240b79d49042b777bfd6cb80e931270b7f50eb:1 | ||
| 353 | ChaCha:5555555555555555555555555555555555555555555555555555555555555555:aaaaaaaaaaaaaaaa:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:aff7418293f3a553894b1e7484bd1e8ede196eced5a1d6814de37091e07e076e34bbba8107a686c982850f0a7353940d40db1ab0b5765b78b4cf473d9485a3dd:1 | ||
| 354 | ChaCha:5555555555555555555555555555555555555555555555555555555555555555:5555555555555555:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:bea9411aa453c5434a5ae8c92862f564396855a9ea6e22d6d3b50ae1b3663311a4a3606c671d605ce16c3aece8e61ea145c59775017bee2fa6f88afc758069f7:1 | ||
| 355 | ChaCha:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:aaaaaaaaaaaaaaaa:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:9aa2a9f656efde5aa7591c5fed4b35aea2895dec7cb4543b9e9f21f5e7bcbcf3c43c748a970888f8248393a09d43e0b7e164bc4d0b0fb240a2d72115c4808906:1 | ||
| 356 | ChaCha:00112233445566778899aabbccddeeffffeeddccbbaa99887766554433221100:0f1e2d3c4b5a6978:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:9fadf409c00811d00431d67efbd88fba59218d5d6708b1d685863fabbb0e961eea480fd6fb532bfd494b2151015057423ab60a63fe4f55f7a212e2167ccab931:1 | ||
| 357 | ChaCha:c46ec1b18ce8a878725a37e780dfb7351f68ed2e194c79fbc6aebee1a667975d:1ada31d5cf688221:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000:f63a89b75c2271f9368816542ba52f06ed49241792302b00b5e8f80ae9a473afc25b218f519af0fdd406362e8d69de7f54c604a6e00f353f110f771bdca8ab92:1 | ||
diff --git a/src/regress/lib/libcrypto/exp/Makefile b/src/regress/lib/libcrypto/exp/Makefile deleted file mode 100644 index 890b38e9fe..0000000000 --- a/src/regress/lib/libcrypto/exp/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.4 2017/01/21 09:38:58 beck Exp $ | ||
| 2 | |||
| 3 | PROG= exptest | ||
| 4 | LDADD= ${CRYPTO_INT} | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/exp/exptest.c b/src/regress/lib/libcrypto/exp/exptest.c deleted file mode 100644 index 9c683464f6..0000000000 --- a/src/regress/lib/libcrypto/exp/exptest.c +++ /dev/null | |||
| @@ -1,353 +0,0 @@ | |||
| 1 | /* $OpenBSD: exptest.c,v 1.5 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/bio.h> | ||
| 64 | #include <openssl/bn.h> | ||
| 65 | #include <openssl/err.h> | ||
| 66 | |||
| 67 | int BN_mod_exp_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 68 | const BIGNUM *m, BN_CTX *ctx); | ||
| 69 | int BN_mod_exp_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 70 | const BIGNUM *m, BN_CTX *ctx); | ||
| 71 | int BN_mod_exp_mont_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 72 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 73 | int BN_mod_exp_mont_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 74 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 75 | |||
| 76 | #define NUM_BITS (BN_BITS*2) | ||
| 77 | |||
| 78 | /* | ||
| 79 | * Test that r == 0 in test_exp_mod_zero(). Returns one on success, | ||
| 80 | * returns zero and prints debug output otherwise. | ||
| 81 | */ | ||
| 82 | static int a_is_zero_mod_one(const char *method, const BIGNUM *r, | ||
| 83 | const BIGNUM *a) { | ||
| 84 | if (!BN_is_zero(r)) { | ||
| 85 | fprintf(stderr, "%s failed:\n", method); | ||
| 86 | fprintf(stderr, "a ** 0 mod 1 = r (should be 0)\n"); | ||
| 87 | fprintf(stderr, "a = "); | ||
| 88 | BN_print_fp(stderr, a); | ||
| 89 | fprintf(stderr, "\nr = "); | ||
| 90 | BN_print_fp(stderr, r); | ||
| 91 | fprintf(stderr, "\n"); | ||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | return 1; | ||
| 95 | } | ||
| 96 | |||
| 97 | /* | ||
| 98 | * test_exp_mod_zero tests that x**0 mod 1 == 0. It returns zero on success. | ||
| 99 | */ | ||
| 100 | static int test_exp_mod_zero(void) | ||
| 101 | { | ||
| 102 | BIGNUM a, p, m; | ||
| 103 | BIGNUM r; | ||
| 104 | BN_ULONG one_word = 1; | ||
| 105 | BN_CTX *ctx = BN_CTX_new(); | ||
| 106 | int ret = 1, failed = 0; | ||
| 107 | |||
| 108 | BN_init(&m); | ||
| 109 | BN_one(&m); | ||
| 110 | |||
| 111 | BN_init(&a); | ||
| 112 | BN_one(&a); | ||
| 113 | |||
| 114 | BN_init(&p); | ||
| 115 | BN_zero(&p); | ||
| 116 | |||
| 117 | BN_init(&r); | ||
| 118 | |||
| 119 | if (!BN_rand(&a, 1024, 0, 0)) | ||
| 120 | goto err; | ||
| 121 | |||
| 122 | if (!BN_mod_exp(&r, &a, &p, &m, ctx)) | ||
| 123 | goto err; | ||
| 124 | |||
| 125 | if (!a_is_zero_mod_one("BN_mod_exp", &r, &a)) | ||
| 126 | failed = 1; | ||
| 127 | |||
| 128 | if (!BN_mod_exp_ct(&r, &a, &p, &m, ctx)) | ||
| 129 | goto err; | ||
| 130 | |||
| 131 | if (!a_is_zero_mod_one("BN_mod_exp_ct", &r, &a)) | ||
| 132 | failed = 1; | ||
| 133 | |||
| 134 | if (!BN_mod_exp_nonct(&r, &a, &p, &m, ctx)) | ||
| 135 | goto err; | ||
| 136 | |||
| 137 | if (!a_is_zero_mod_one("BN_mod_exp_nonct", &r, &a)) | ||
| 138 | failed = 1; | ||
| 139 | |||
| 140 | if (!BN_mod_exp_recp(&r, &a, &p, &m, ctx)) | ||
| 141 | goto err; | ||
| 142 | |||
| 143 | if (!a_is_zero_mod_one("BN_mod_exp_recp", &r, &a)) | ||
| 144 | failed = 1; | ||
| 145 | |||
| 146 | if (!BN_mod_exp_simple(&r, &a, &p, &m, ctx)) | ||
| 147 | goto err; | ||
| 148 | |||
| 149 | if (!a_is_zero_mod_one("BN_mod_exp_simple", &r, &a)) | ||
| 150 | failed = 1; | ||
| 151 | |||
| 152 | if (!BN_mod_exp_mont(&r, &a, &p, &m, ctx, NULL)) | ||
| 153 | goto err; | ||
| 154 | |||
| 155 | if (!a_is_zero_mod_one("BN_mod_exp_mont", &r, &a)) | ||
| 156 | failed = 1; | ||
| 157 | |||
| 158 | if (!BN_mod_exp_mont_ct(&r, &a, &p, &m, ctx, NULL)) | ||
| 159 | goto err; | ||
| 160 | |||
| 161 | if (!a_is_zero_mod_one("BN_mod_exp_mont_ct", &r, &a)) | ||
| 162 | failed = 1; | ||
| 163 | |||
| 164 | if (!BN_mod_exp_mont_nonct(&r, &a, &p, &m, ctx, NULL)) | ||
| 165 | goto err; | ||
| 166 | |||
| 167 | if (!a_is_zero_mod_one("BN_mod_exp_mont_nonct", &r, &a)) | ||
| 168 | failed = 1; | ||
| 169 | |||
| 170 | if (!BN_mod_exp_mont_consttime(&r, &a, &p, &m, ctx, NULL)) { | ||
| 171 | goto err; | ||
| 172 | } | ||
| 173 | |||
| 174 | if (!a_is_zero_mod_one("BN_mod_exp_mont_consttime", &r, &a)) | ||
| 175 | failed = 1; | ||
| 176 | |||
| 177 | /* | ||
| 178 | * A different codepath exists for single word multiplication | ||
| 179 | * in non-constant-time only. | ||
| 180 | */ | ||
| 181 | if (!BN_mod_exp_mont_word(&r, one_word, &p, &m, ctx, NULL)) | ||
| 182 | goto err; | ||
| 183 | |||
| 184 | if (!BN_is_zero(&r)) { | ||
| 185 | fprintf(stderr, "BN_mod_exp_mont_word failed:\n"); | ||
| 186 | fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\n"); | ||
| 187 | fprintf(stderr, "r = "); | ||
| 188 | BN_print_fp(stderr, &r); | ||
| 189 | fprintf(stderr, "\n"); | ||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | |||
| 193 | ret = failed; | ||
| 194 | |||
| 195 | err: | ||
| 196 | BN_free(&r); | ||
| 197 | BN_free(&a); | ||
| 198 | BN_free(&p); | ||
| 199 | BN_free(&m); | ||
| 200 | BN_CTX_free(ctx); | ||
| 201 | |||
| 202 | return ret; | ||
| 203 | } | ||
| 204 | |||
| 205 | int main(int argc, char *argv[]) | ||
| 206 | { | ||
| 207 | BN_CTX *ctx; | ||
| 208 | BIO *out = NULL; | ||
| 209 | int i, ret; | ||
| 210 | unsigned char c; | ||
| 211 | BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, | ||
| 212 | *r_mont_ct, *r_mont_nonct, *a, *b, *m; | ||
| 213 | |||
| 214 | ERR_load_BN_strings(); | ||
| 215 | |||
| 216 | ctx = BN_CTX_new(); | ||
| 217 | if (ctx == NULL) | ||
| 218 | exit(1); | ||
| 219 | r_mont = BN_new(); | ||
| 220 | r_mont_const = BN_new(); | ||
| 221 | r_mont_ct = BN_new(); | ||
| 222 | r_mont_nonct = BN_new(); | ||
| 223 | r_recp = BN_new(); | ||
| 224 | r_simple = BN_new(); | ||
| 225 | a = BN_new(); | ||
| 226 | b = BN_new(); | ||
| 227 | m = BN_new(); | ||
| 228 | if ((r_mont == NULL) || (r_recp == NULL) || (a == NULL) || (b == NULL)) | ||
| 229 | goto err; | ||
| 230 | |||
| 231 | out = BIO_new(BIO_s_file()); | ||
| 232 | |||
| 233 | if (out == NULL) | ||
| 234 | exit(1); | ||
| 235 | BIO_set_fp(out, stdout, BIO_NOCLOSE); | ||
| 236 | |||
| 237 | for (i = 0; i < 200; i++) { | ||
| 238 | arc4random_buf(&c, 1); | ||
| 239 | c = (c % BN_BITS) - BN_BITS2; | ||
| 240 | BN_rand(a, NUM_BITS + c, 0, 0); | ||
| 241 | |||
| 242 | arc4random_buf(&c, 1); | ||
| 243 | c = (c % BN_BITS) - BN_BITS2; | ||
| 244 | BN_rand(b, NUM_BITS + c, 0, 0); | ||
| 245 | |||
| 246 | arc4random_buf(&c, 1); | ||
| 247 | c = (c % BN_BITS) - BN_BITS2; | ||
| 248 | BN_rand(m, NUM_BITS + c, 0, 1); | ||
| 249 | |||
| 250 | BN_mod(a, a, m, ctx); | ||
| 251 | BN_mod(b, b, m, ctx); | ||
| 252 | |||
| 253 | ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL); | ||
| 254 | if (ret <= 0) { | ||
| 255 | printf("BN_mod_exp_mont() problems\n"); | ||
| 256 | ERR_print_errors(out); | ||
| 257 | exit(1); | ||
| 258 | } | ||
| 259 | |||
| 260 | ret = BN_mod_exp_mont_ct(r_mont_ct, a, b, m, ctx, NULL); | ||
| 261 | if (ret <= 0) { | ||
| 262 | printf("BN_mod_exp_mont_ct() problems\n"); | ||
| 263 | ERR_print_errors(out); | ||
| 264 | exit(1); | ||
| 265 | } | ||
| 266 | |||
| 267 | ret = BN_mod_exp_mont_nonct(r_mont_nonct, a, b, m, ctx, NULL); | ||
| 268 | if (ret <= 0) { | ||
| 269 | printf("BN_mod_exp_mont_nonct() problems\n"); | ||
| 270 | ERR_print_errors(out); | ||
| 271 | exit(1); | ||
| 272 | } | ||
| 273 | |||
| 274 | ret = BN_mod_exp_recp(r_recp, a, b, m, ctx); | ||
| 275 | if (ret <= 0) { | ||
| 276 | printf("BN_mod_exp_recp() problems\n"); | ||
| 277 | ERR_print_errors(out); | ||
| 278 | exit(1); | ||
| 279 | } | ||
| 280 | |||
| 281 | ret = BN_mod_exp_simple(r_simple, a, b, m, ctx); | ||
| 282 | if (ret <= 0) { | ||
| 283 | printf("BN_mod_exp_simple() problems\n"); | ||
| 284 | ERR_print_errors(out); | ||
| 285 | exit(1); | ||
| 286 | } | ||
| 287 | |||
| 288 | ret = BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL); | ||
| 289 | if (ret <= 0) { | ||
| 290 | printf("BN_mod_exp_mont_consttime() problems\n"); | ||
| 291 | ERR_print_errors(out); | ||
| 292 | exit(1); | ||
| 293 | } | ||
| 294 | |||
| 295 | if (BN_cmp(r_simple, r_mont) == 0 | ||
| 296 | && BN_cmp(r_simple, r_recp) == 0 | ||
| 297 | && BN_cmp(r_simple, r_mont_const) == 0) { | ||
| 298 | printf("."); | ||
| 299 | fflush(stdout); | ||
| 300 | } else { | ||
| 301 | if (BN_cmp(r_simple, r_mont) != 0) | ||
| 302 | printf("\nsimple and mont results differ\n"); | ||
| 303 | if (BN_cmp(r_simple, r_mont_const) != 0) | ||
| 304 | printf("\nsimple and mont const time results differ\n"); | ||
| 305 | if (BN_cmp(r_simple, r_recp) != 0) | ||
| 306 | printf("\nsimple and recp results differ\n"); | ||
| 307 | if (BN_cmp(r_mont, r_mont_ct) != 0) | ||
| 308 | printf("\nmont_ct and mont results differ\n"); | ||
| 309 | if (BN_cmp(r_mont_ct, r_mont_nonct) != 0) | ||
| 310 | printf("\nmont_ct and mont_nonct results differ\n"); | ||
| 311 | |||
| 312 | printf("a (%3d) = ", BN_num_bits(a)); | ||
| 313 | BN_print(out, a); | ||
| 314 | printf("\nb (%3d) = ", BN_num_bits(b)); | ||
| 315 | BN_print(out, b); | ||
| 316 | printf("\nm (%3d) = ", BN_num_bits(m)); | ||
| 317 | BN_print(out, m); | ||
| 318 | printf("\nsimple ="); | ||
| 319 | BN_print(out, r_simple); | ||
| 320 | printf("\nrecp ="); | ||
| 321 | BN_print(out, r_recp); | ||
| 322 | printf("\nmont ="); | ||
| 323 | BN_print(out, r_mont); | ||
| 324 | printf("\nmont_ct ="); | ||
| 325 | BN_print(out, r_mont_const); | ||
| 326 | printf("\n"); | ||
| 327 | exit(1); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | BN_free(r_mont); | ||
| 331 | BN_free(r_mont_const); | ||
| 332 | BN_free(r_recp); | ||
| 333 | BN_free(r_simple); | ||
| 334 | BN_free(a); | ||
| 335 | BN_free(b); | ||
| 336 | BN_free(m); | ||
| 337 | BN_CTX_free(ctx); | ||
| 338 | ERR_remove_thread_state(NULL); | ||
| 339 | CRYPTO_mem_leaks(out); | ||
| 340 | BIO_free(out); | ||
| 341 | printf("\n"); | ||
| 342 | |||
| 343 | if (test_exp_mod_zero() != 0) | ||
| 344 | goto err; | ||
| 345 | |||
| 346 | printf("done\n"); | ||
| 347 | |||
| 348 | return (0); | ||
| 349 | err: | ||
| 350 | ERR_load_crypto_strings(); | ||
| 351 | ERR_print_errors(out); | ||
| 352 | return (1); | ||
| 353 | } | ||
diff --git a/src/regress/lib/libcrypto/free/Makefile b/src/regress/lib/libcrypto/free/Makefile deleted file mode 100644 index 4e8a7ed38d..0000000000 --- a/src/regress/lib/libcrypto/free/Makefile +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2018/08/31 17:35:21 tb Exp $ | ||
| 2 | |||
| 3 | TESTS = \ | ||
| 4 | freenull | ||
| 5 | |||
| 6 | PROG = ${TESTS} | ||
| 7 | |||
| 8 | REGRESS_TARGETS= all_tests | ||
| 9 | |||
| 10 | LDADD= -lcrypto | ||
| 11 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 12 | LDFLAGS+= -lcrypto | ||
| 13 | CFLAGS+= -DLIBRESSL_INTERNAL | ||
| 14 | |||
| 15 | CLEANFILES+= freenull.c freenull.c.body freenull.c.tmp | ||
| 16 | |||
| 17 | freenull.c: freenull.awk ../../../../lib/libcrypto/Symbols.list | ||
| 18 | awk -f ${.CURDIR}/freenull.awk \ | ||
| 19 | < ${BSDSRCDIR}/lib/libcrypto/Symbols.list > freenull.c.body | ||
| 20 | cat ${.CURDIR}/freenull.c.head freenull.c.body \ | ||
| 21 | ${.CURDIR}/freenull.c.tail > freenull.c.tmp | ||
| 22 | mv freenull.c.tmp freenull.c | ||
| 23 | |||
| 24 | all_tests: ${TESTS} | ||
| 25 | @for test in $>; do \ | ||
| 26 | ./$$test; \ | ||
| 27 | done | ||
| 28 | |||
| 29 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/free/freenull.awk b/src/regress/lib/libcrypto/free/freenull.awk deleted file mode 100644 index 95719da956..0000000000 --- a/src/regress/lib/libcrypto/free/freenull.awk +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | # $OpenBSD: freenull.awk,v 1.1 2018/07/10 20:53:30 tb Exp $ | ||
| 2 | # Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | ||
| 3 | # | ||
| 4 | # Permission to use, copy, modify, and distribute this software for any | ||
| 5 | # purpose with or without fee is hereby granted, provided that the above | ||
| 6 | # copyright notice and this permission notice appear in all copies. | ||
| 7 | # | ||
| 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | |||
| 16 | # usage: awk -f freenull.awk < Symbols.list > freenull.c.body | ||
| 17 | |||
| 18 | # Skip this function because it calls abort(3). | ||
| 19 | /^CRYPTO_dbg_free/ { | ||
| 20 | next | ||
| 21 | } | ||
| 22 | |||
| 23 | # Skip *_free functions that take more than one or no argument. | ||
| 24 | /^ASN1_item_ex_free$/ || | ||
| 25 | /^ASN1_item_free$/ || | ||
| 26 | /^ASN1_primitive_free$/ || | ||
| 27 | /^ASN1_template_free$/ || | ||
| 28 | /^CONF_modules_free$/ || | ||
| 29 | /^EVP_PKEY_asn1_set_free$/ || | ||
| 30 | /^OBJ_sigid_free$/ || | ||
| 31 | /^X509V3_section_free$/ || | ||
| 32 | /^X509V3_string_free$/ || | ||
| 33 | /^asn1_enc_free$/ || | ||
| 34 | /^sk_pop_free$/ { | ||
| 35 | next | ||
| 36 | } | ||
| 37 | |||
| 38 | # Skip functions that are prototyped in a .c file. | ||
| 39 | /^BIO_CONNECT_free$/ || | ||
| 40 | /^CRYPTO_free$/ || | ||
| 41 | /^EC_PRIVATEKEY_free$/ || | ||
| 42 | /^ECPARAMETERS_free$/ || | ||
| 43 | /^ECPKPARAMETERS_free$/ || | ||
| 44 | /^NETSCAPE_ENCRYPTED_PKEY_free$/ || | ||
| 45 | /^NETSCAPE_PKEY_free$/ || | ||
| 46 | /^X9_62_CHARACTERISTIC_TWO_free$/ || | ||
| 47 | /^X9_62_PENTANOMIAL_free$/ { | ||
| 48 | next | ||
| 49 | } | ||
| 50 | |||
| 51 | /^ENGINE_free$/ { | ||
| 52 | printf("#ifndef OPENSSL_NO_ENGINE\n") | ||
| 53 | printf("\tENGINE_free(NULL);\n") | ||
| 54 | printf("#endif\n") | ||
| 55 | next | ||
| 56 | } | ||
| 57 | |||
| 58 | /_free$/ { | ||
| 59 | printf("\t%s(NULL);\n", $0) | ||
| 60 | } | ||
diff --git a/src/regress/lib/libcrypto/free/freenull.c.head b/src/regress/lib/libcrypto/free/freenull.c.head deleted file mode 100644 index f7e2c31595..0000000000 --- a/src/regress/lib/libcrypto/free/freenull.c.head +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | /* $OpenBSD: freenull.c.head,v 1.2 2018/07/10 20:55:57 tb Exp $ */ | ||
| 2 | |||
| 3 | #include <openssl/asn1.h> | ||
| 4 | #include <openssl/cmac.h> | ||
| 5 | #include <openssl/comp.h> | ||
| 6 | #include <openssl/conf_api.h> | ||
| 7 | #include <openssl/dso.h> | ||
| 8 | #ifndef OPENSSL_NO_ENGINE | ||
| 9 | #include <openssl/engine.h> | ||
| 10 | #endif | ||
| 11 | #include <openssl/gost.h> | ||
| 12 | #include <openssl/hmac.h> | ||
| 13 | #include <openssl/ocsp.h> | ||
| 14 | #include <openssl/pkcs12.h> | ||
| 15 | #include <openssl/ts.h> | ||
| 16 | #include <openssl/ui.h> | ||
| 17 | #include <openssl/txt_db.h> | ||
| 18 | #include <openssl/x509.h> | ||
| 19 | #include <openssl/x509v3.h> | ||
| 20 | |||
| 21 | #include <err.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | |||
| 25 | int | ||
| 26 | main(int argc, char **argv) | ||
| 27 | { | ||
diff --git a/src/regress/lib/libcrypto/free/freenull.c.tail b/src/regress/lib/libcrypto/free/freenull.c.tail deleted file mode 100644 index e83e9e4aa2..0000000000 --- a/src/regress/lib/libcrypto/free/freenull.c.tail +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | /* $OpenBSD: freenull.c.tail,v 1.2 2018/07/10 20:55:57 tb Exp $ */ | ||
| 2 | |||
| 3 | BIO_free_all(NULL); | ||
| 4 | NCONF_free_data(NULL); | ||
| 5 | _CONF_free_data(NULL); | ||
| 6 | |||
| 7 | lh_FUNCTION_free(NULL); | ||
| 8 | |||
| 9 | sk_ASN1_OBJECT_pop_free(NULL, NULL); | ||
| 10 | sk_CONF_VALUE_pop_free(NULL, NULL); | ||
| 11 | sk_GENERAL_NAME_pop_free(NULL, NULL); | ||
| 12 | sk_OCSP_CERTID_free(NULL); | ||
| 13 | sk_OPENSSL_STRING_free(NULL); | ||
| 14 | sk_PKCS12_SAFEBAG_pop_free(NULL, NULL); | ||
| 15 | sk_PKCS7_pop_free(NULL, NULL); | ||
| 16 | sk_X509_ATTRIBUTE_free(NULL); | ||
| 17 | sk_X509_CRL_pop_free(NULL, NULL); | ||
| 18 | sk_X509_EXTENSION_pop_free(NULL, NULL); | ||
| 19 | sk_X509_INFO_free(NULL); | ||
| 20 | sk_X509_INFO_pop_free(NULL, NULL); | ||
| 21 | sk_X509_NAME_ENTRY_pop_free(NULL, NULL); | ||
| 22 | sk_X509_free(NULL); | ||
| 23 | sk_X509_pop_free(NULL, NULL); | ||
| 24 | |||
| 25 | printf("PASS\n"); | ||
| 26 | |||
| 27 | return 0; | ||
| 28 | } | ||
diff --git a/src/regress/lib/libcrypto/gcm128/Makefile b/src/regress/lib/libcrypto/gcm128/Makefile deleted file mode 100644 index c981203e3e..0000000000 --- a/src/regress/lib/libcrypto/gcm128/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2014/07/09 11:43:01 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= gcm128test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/gcm128/gcm128test.c b/src/regress/lib/libcrypto/gcm128/gcm128test.c deleted file mode 100644 index 07c6128c0f..0000000000 --- a/src/regress/lib/libcrypto/gcm128/gcm128test.c +++ /dev/null | |||
| @@ -1,926 +0,0 @@ | |||
| 1 | /* $OpenBSD: gcm128test.c,v 1.6 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2010 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include <err.h> | ||
| 52 | #include <stdio.h> | ||
| 53 | #include <stdint.h> | ||
| 54 | #include <stdlib.h> | ||
| 55 | #include <string.h> | ||
| 56 | |||
| 57 | #include <openssl/aes.h> | ||
| 58 | #include <openssl/modes.h> | ||
| 59 | |||
| 60 | /* XXX - something like this should be in the public headers. */ | ||
| 61 | struct gcm128_context { | ||
| 62 | uint64_t opaque[64]; | ||
| 63 | }; | ||
| 64 | |||
| 65 | struct gcm128_test { | ||
| 66 | const uint8_t K[128]; | ||
| 67 | size_t K_len; | ||
| 68 | const uint8_t IV[128]; | ||
| 69 | size_t IV_len; | ||
| 70 | const uint8_t P[512]; | ||
| 71 | size_t P_len; | ||
| 72 | const uint8_t A[128]; | ||
| 73 | size_t A_len; | ||
| 74 | const uint8_t C[512]; | ||
| 75 | size_t C_len; | ||
| 76 | const uint8_t T[16]; | ||
| 77 | }; | ||
| 78 | |||
| 79 | struct gcm128_test gcm128_tests[] = { | ||
| 80 | { | ||
| 81 | /* Test Case 1. */ | ||
| 82 | .K = {0}, | ||
| 83 | .K_len = 16, | ||
| 84 | .IV = {0}, | ||
| 85 | .IV_len = 12, | ||
| 86 | .P = {0}, | ||
| 87 | .P_len = 0, | ||
| 88 | .A = {0}, | ||
| 89 | .A_len = 0, | ||
| 90 | .C = {0}, | ||
| 91 | .C_len = 0, | ||
| 92 | .T = { | ||
| 93 | 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, | ||
| 94 | 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a, | ||
| 95 | }, | ||
| 96 | }, | ||
| 97 | { | ||
| 98 | /* Test Case 2. */ | ||
| 99 | .K = {0}, | ||
| 100 | .K_len = 16, | ||
| 101 | .IV = {0}, | ||
| 102 | .IV_len = 12, | ||
| 103 | .P = {0}, | ||
| 104 | .P_len = 16, | ||
| 105 | .A = {0}, | ||
| 106 | .A_len = 0, | ||
| 107 | .C = { | ||
| 108 | 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, | ||
| 109 | 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78, | ||
| 110 | }, | ||
| 111 | .C_len = 16, | ||
| 112 | .T = { | ||
| 113 | 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd, | ||
| 114 | 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf, | ||
| 115 | }, | ||
| 116 | }, | ||
| 117 | { | ||
| 118 | /* Test Case 3. */ | ||
| 119 | .K = { | ||
| 120 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 121 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 122 | }, | ||
| 123 | .K_len = 16, | ||
| 124 | .IV = { | ||
| 125 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 126 | 0xde, 0xca, 0xf8, 0x88, | ||
| 127 | }, | ||
| 128 | .IV_len = 12, | ||
| 129 | .P = { | ||
| 130 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 131 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 132 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 133 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 134 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 135 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 136 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 137 | 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, | ||
| 138 | }, | ||
| 139 | .P_len = 64, | ||
| 140 | .A = {0}, | ||
| 141 | .A_len = 0, | ||
| 142 | .C = { | ||
| 143 | 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, | ||
| 144 | 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, | ||
| 145 | 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, | ||
| 146 | 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, | ||
| 147 | 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, | ||
| 148 | 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, | ||
| 149 | 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, | ||
| 150 | 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85, | ||
| 151 | }, | ||
| 152 | .C_len = 64, | ||
| 153 | .T = { | ||
| 154 | 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, | ||
| 155 | 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4, | ||
| 156 | } | ||
| 157 | }, | ||
| 158 | { | ||
| 159 | /* Test Case 4. */ | ||
| 160 | .K = { | ||
| 161 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 162 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 163 | }, | ||
| 164 | .K_len = 16, | ||
| 165 | .IV = { | ||
| 166 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 167 | 0xde, 0xca, 0xf8, 0x88, | ||
| 168 | }, | ||
| 169 | .IV_len = 12, | ||
| 170 | .P = { | ||
| 171 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 172 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 173 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 174 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 175 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 176 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 177 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 178 | 0xba, 0x63, 0x7b, 0x39, | ||
| 179 | }, | ||
| 180 | .P_len = 60, | ||
| 181 | .A = { | ||
| 182 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 183 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 184 | 0xab, 0xad, 0xda, 0xd2, | ||
| 185 | }, | ||
| 186 | .A_len = 20, | ||
| 187 | .C = { | ||
| 188 | 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, | ||
| 189 | 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, | ||
| 190 | 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, | ||
| 191 | 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, | ||
| 192 | 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, | ||
| 193 | 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, | ||
| 194 | 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, | ||
| 195 | 0x3d, 0x58, 0xe0, 0x91, | ||
| 196 | }, | ||
| 197 | .C_len = 60, | ||
| 198 | .T = { | ||
| 199 | 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, | ||
| 200 | 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47, | ||
| 201 | }, | ||
| 202 | }, | ||
| 203 | { | ||
| 204 | /* Test Case 5. */ | ||
| 205 | /* K, P, A are the same as TC4. */ | ||
| 206 | .K = { | ||
| 207 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 208 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 209 | }, | ||
| 210 | .K_len = 16, | ||
| 211 | .IV = { | ||
| 212 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 213 | }, | ||
| 214 | .IV_len = 8, | ||
| 215 | .P = { | ||
| 216 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 217 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 218 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 219 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 220 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 221 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 222 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 223 | 0xba, 0x63, 0x7b, 0x39, | ||
| 224 | }, | ||
| 225 | .P_len = 60, | ||
| 226 | .A = { | ||
| 227 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 228 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 229 | 0xab, 0xad, 0xda, 0xd2, | ||
| 230 | }, | ||
| 231 | .A_len = 20, | ||
| 232 | .C = { | ||
| 233 | 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, | ||
| 234 | 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, | ||
| 235 | 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, | ||
| 236 | 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, | ||
| 237 | 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, | ||
| 238 | 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, | ||
| 239 | 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, | ||
| 240 | 0xc2, 0x3f, 0x45, 0x98, | ||
| 241 | }, | ||
| 242 | .C_len = 60, | ||
| 243 | .T = { | ||
| 244 | 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, | ||
| 245 | 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb, | ||
| 246 | }, | ||
| 247 | }, | ||
| 248 | { | ||
| 249 | /* Test Case 6. */ | ||
| 250 | /* K, P, A are the same as TC4. */ | ||
| 251 | .K = { | ||
| 252 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 253 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 254 | }, | ||
| 255 | .K_len = 16, | ||
| 256 | .IV = { | ||
| 257 | 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, | ||
| 258 | 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, | ||
| 259 | 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, | ||
| 260 | 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, | ||
| 261 | 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, | ||
| 262 | 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, | ||
| 263 | 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, | ||
| 264 | 0xa6, 0x37, 0xb3, 0x9b, | ||
| 265 | }, | ||
| 266 | .IV_len = 60, | ||
| 267 | .P = { | ||
| 268 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 269 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 270 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 271 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 272 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 273 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 274 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 275 | 0xba, 0x63, 0x7b, 0x39, | ||
| 276 | }, | ||
| 277 | .P_len = 60, | ||
| 278 | .A = { | ||
| 279 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 280 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 281 | 0xab, 0xad, 0xda, 0xd2, | ||
| 282 | }, | ||
| 283 | .A_len = 20, | ||
| 284 | .C = { | ||
| 285 | 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, | ||
| 286 | 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, | ||
| 287 | 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, | ||
| 288 | 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, | ||
| 289 | 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, | ||
| 290 | 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, | ||
| 291 | 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, | ||
| 292 | 0x4c, 0x34, 0xae, 0xe5, | ||
| 293 | }, | ||
| 294 | .C_len = 60, | ||
| 295 | .T = { | ||
| 296 | 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, | ||
| 297 | 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, | ||
| 298 | }, | ||
| 299 | }, | ||
| 300 | { | ||
| 301 | /* Test Case 7. */ | ||
| 302 | .K = {0}, | ||
| 303 | .K_len = 24, | ||
| 304 | .IV = {0}, | ||
| 305 | .IV_len = 12, | ||
| 306 | .P = {0}, | ||
| 307 | .P_len = 0, | ||
| 308 | .A = {0}, | ||
| 309 | .A_len = 0, | ||
| 310 | .C = {0}, | ||
| 311 | .C_len = 0, | ||
| 312 | .T = { | ||
| 313 | 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b, | ||
| 314 | 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35, | ||
| 315 | }, | ||
| 316 | }, | ||
| 317 | { | ||
| 318 | /* Test Case 8. */ | ||
| 319 | .K = {0}, | ||
| 320 | .K_len = 24, | ||
| 321 | .IV = {0}, | ||
| 322 | .IV_len = 12, | ||
| 323 | .P = {0}, | ||
| 324 | .P_len = 16, | ||
| 325 | .A = {0}, | ||
| 326 | .A_len = 0, | ||
| 327 | .C = { | ||
| 328 | 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, | ||
| 329 | 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00, | ||
| 330 | }, | ||
| 331 | .C_len = 16, | ||
| 332 | .T = { | ||
| 333 | 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab, | ||
| 334 | 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb, | ||
| 335 | }, | ||
| 336 | }, | ||
| 337 | { | ||
| 338 | /* Test Case 9. */ | ||
| 339 | .K = { | ||
| 340 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 341 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 342 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 343 | }, | ||
| 344 | .K_len = 24, | ||
| 345 | .IV = { | ||
| 346 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 347 | 0xde, 0xca, 0xf8, 0x88, | ||
| 348 | }, | ||
| 349 | .IV_len = 12, | ||
| 350 | .P = { | ||
| 351 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 352 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 353 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 354 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 355 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 356 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 357 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 358 | 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, | ||
| 359 | }, | ||
| 360 | .P_len = 64, | ||
| 361 | .A = {0}, | ||
| 362 | .A_len = 0, | ||
| 363 | .C = { | ||
| 364 | 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, | ||
| 365 | 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, | ||
| 366 | 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, | ||
| 367 | 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, | ||
| 368 | 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, | ||
| 369 | 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, | ||
| 370 | 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, | ||
| 371 | 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56, | ||
| 372 | }, | ||
| 373 | .C_len = 64, | ||
| 374 | .T = { | ||
| 375 | 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf, | ||
| 376 | 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14, | ||
| 377 | }, | ||
| 378 | }, | ||
| 379 | { | ||
| 380 | /* Test Case 10. */ | ||
| 381 | /* K and IV are the same as TC9. */ | ||
| 382 | .K = { | ||
| 383 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 384 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 385 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 386 | }, | ||
| 387 | .K_len = 24, | ||
| 388 | .IV = { | ||
| 389 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 390 | 0xde, 0xca, 0xf8, 0x88, | ||
| 391 | }, | ||
| 392 | .IV_len = 12, | ||
| 393 | .P = { | ||
| 394 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 395 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 396 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 397 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 398 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 399 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 400 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 401 | 0xba, 0x63, 0x7b, 0x39, | ||
| 402 | }, | ||
| 403 | .P_len = 60, | ||
| 404 | .A = { | ||
| 405 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 406 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 407 | 0xab, 0xad, 0xda, 0xd2, | ||
| 408 | }, | ||
| 409 | .A_len = 20, | ||
| 410 | .C = { | ||
| 411 | 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, | ||
| 412 | 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, | ||
| 413 | 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, | ||
| 414 | 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, | ||
| 415 | 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, | ||
| 416 | 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, | ||
| 417 | 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, | ||
| 418 | 0xcc, 0xda, 0x27, 0x10, | ||
| 419 | }, | ||
| 420 | .C_len = 60, | ||
| 421 | .T = { | ||
| 422 | 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f, | ||
| 423 | 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c, | ||
| 424 | }, | ||
| 425 | }, | ||
| 426 | { | ||
| 427 | /* Test Case 11. */ | ||
| 428 | /* K is the same as TC9, P and A are the same as TC10. */ | ||
| 429 | .K = { | ||
| 430 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 431 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 432 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 433 | }, | ||
| 434 | .K_len = 24, | ||
| 435 | .IV = { | ||
| 436 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 437 | }, | ||
| 438 | .IV_len = 8, | ||
| 439 | .P = { | ||
| 440 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 441 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 442 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 443 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 444 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 445 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 446 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 447 | 0xba, 0x63, 0x7b, 0x39, | ||
| 448 | }, | ||
| 449 | .P_len = 60, | ||
| 450 | .A = { | ||
| 451 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 452 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 453 | 0xab, 0xad, 0xda, 0xd2, | ||
| 454 | }, | ||
| 455 | .A_len = 20, | ||
| 456 | .C = { | ||
| 457 | 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54, | ||
| 458 | 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8, | ||
| 459 | 0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f, | ||
| 460 | 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57, | ||
| 461 | 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75, | ||
| 462 | 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9, | ||
| 463 | 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f, | ||
| 464 | 0xa0, 0xf0, 0x62, 0xf7 | ||
| 465 | }, | ||
| 466 | .C_len = 60, | ||
| 467 | .T = { | ||
| 468 | 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24, | ||
| 469 | 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8, | ||
| 470 | }, | ||
| 471 | }, | ||
| 472 | { | ||
| 473 | /* Test Case 12. */ | ||
| 474 | /* K is the same as TC9, P and A are the same as TC10. */ | ||
| 475 | .K = { | ||
| 476 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 477 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 478 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 479 | }, | ||
| 480 | .K_len = 24, | ||
| 481 | .IV = { | ||
| 482 | 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, | ||
| 483 | 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, | ||
| 484 | 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, | ||
| 485 | 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, | ||
| 486 | 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, | ||
| 487 | 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, | ||
| 488 | 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, | ||
| 489 | 0xa6, 0x37, 0xb3, 0x9b, | ||
| 490 | }, | ||
| 491 | .IV_len = 60, | ||
| 492 | .P = { | ||
| 493 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 494 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 495 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 496 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 497 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 498 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 499 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 500 | 0xba, 0x63, 0x7b, 0x39, | ||
| 501 | }, | ||
| 502 | .P_len = 60, | ||
| 503 | .A = { | ||
| 504 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 505 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 506 | 0xab, 0xad, 0xda, 0xd2, | ||
| 507 | }, | ||
| 508 | .A_len = 20, | ||
| 509 | .C = { | ||
| 510 | 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c, | ||
| 511 | 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff, | ||
| 512 | 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef, | ||
| 513 | 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45, | ||
| 514 | 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9, | ||
| 515 | 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3, | ||
| 516 | 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7, | ||
| 517 | 0xe9, 0xb7, 0x37, 0x3b, | ||
| 518 | }, | ||
| 519 | .C_len = 60, | ||
| 520 | .T = { | ||
| 521 | 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb, | ||
| 522 | 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9, | ||
| 523 | }, | ||
| 524 | }, | ||
| 525 | { | ||
| 526 | /* Test Case 13. */ | ||
| 527 | .K = {0}, | ||
| 528 | .K_len = 32, | ||
| 529 | .IV = {0}, | ||
| 530 | .IV_len = 12, | ||
| 531 | .P = {0}, | ||
| 532 | .P_len = 0, | ||
| 533 | .A = {0}, | ||
| 534 | .A_len = 0, | ||
| 535 | .C = {0}, | ||
| 536 | .C_len = 0, | ||
| 537 | .T = { | ||
| 538 | 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9, | ||
| 539 | 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b, | ||
| 540 | }, | ||
| 541 | }, | ||
| 542 | { | ||
| 543 | /* Test Case 14. */ | ||
| 544 | .K = {0}, | ||
| 545 | .K_len = 32, | ||
| 546 | .IV = {0}, | ||
| 547 | .IV_len = 12, | ||
| 548 | .P = {0}, | ||
| 549 | .P_len = 16, | ||
| 550 | .A = {0}, | ||
| 551 | .A_len = 0, | ||
| 552 | .C = { | ||
| 553 | 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, | ||
| 554 | 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18, | ||
| 555 | }, | ||
| 556 | .C_len = 16, | ||
| 557 | .T = { | ||
| 558 | 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, | ||
| 559 | 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19, | ||
| 560 | }, | ||
| 561 | }, | ||
| 562 | { | ||
| 563 | /* Test Case 15. */ | ||
| 564 | .K = { | ||
| 565 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 566 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 567 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 568 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 569 | }, | ||
| 570 | .K_len = 32, | ||
| 571 | .IV = { | ||
| 572 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 573 | 0xde, 0xca, 0xf8, 0x88, | ||
| 574 | }, | ||
| 575 | .IV_len = 12, | ||
| 576 | .P = { | ||
| 577 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 578 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 579 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 580 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 581 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 582 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 583 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 584 | 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, | ||
| 585 | }, | ||
| 586 | .P_len = 64, | ||
| 587 | .A = {0}, | ||
| 588 | .A_len = 0, | ||
| 589 | .C = { | ||
| 590 | 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, | ||
| 591 | 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, | ||
| 592 | 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, | ||
| 593 | 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, | ||
| 594 | 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, | ||
| 595 | 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, | ||
| 596 | 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, | ||
| 597 | 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad, | ||
| 598 | }, | ||
| 599 | .C_len = 64, | ||
| 600 | .T = { | ||
| 601 | 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd, | ||
| 602 | 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c, | ||
| 603 | }, | ||
| 604 | }, | ||
| 605 | { | ||
| 606 | /* Test Case 16. */ | ||
| 607 | /* K and IV are the same as TC15. */ | ||
| 608 | .K = { | ||
| 609 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 610 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 611 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 612 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 613 | }, | ||
| 614 | .K_len = 32, | ||
| 615 | .IV = { | ||
| 616 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 617 | 0xde, 0xca, 0xf8, 0x88, | ||
| 618 | }, | ||
| 619 | .IV_len = 12, | ||
| 620 | .P = { | ||
| 621 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 622 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 623 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 624 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 625 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 626 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 627 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 628 | 0xba, 0x63, 0x7b, 0x39, | ||
| 629 | }, | ||
| 630 | .P_len = 60, | ||
| 631 | .A = { | ||
| 632 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 633 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 634 | 0xab, 0xad, 0xda, 0xd2, | ||
| 635 | }, | ||
| 636 | .A_len = 20, | ||
| 637 | .C = { | ||
| 638 | 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, | ||
| 639 | 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, | ||
| 640 | 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, | ||
| 641 | 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, | ||
| 642 | 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, | ||
| 643 | 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, | ||
| 644 | 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, | ||
| 645 | 0xbc, 0xc9, 0xf6, 0x62, | ||
| 646 | }, | ||
| 647 | .C_len = 60, | ||
| 648 | .T = { | ||
| 649 | 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, | ||
| 650 | 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b, | ||
| 651 | }, | ||
| 652 | }, | ||
| 653 | { | ||
| 654 | /* Test Case 17. */ | ||
| 655 | /* K is the same as TC15, P and A are the same as TC 16. */ | ||
| 656 | .K = { | ||
| 657 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 658 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 659 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 660 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 661 | }, | ||
| 662 | .K_len = 32, | ||
| 663 | .IV = { | ||
| 664 | 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | ||
| 665 | }, | ||
| 666 | .IV_len = 8, | ||
| 667 | .P = { | ||
| 668 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 669 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 670 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 671 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 672 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 673 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 674 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 675 | 0xba, 0x63, 0x7b, 0x39, | ||
| 676 | }, | ||
| 677 | .P_len = 60, | ||
| 678 | .A = { | ||
| 679 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 680 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 681 | 0xab, 0xad, 0xda, 0xd2, | ||
| 682 | }, | ||
| 683 | .A_len = 20, | ||
| 684 | .C = { | ||
| 685 | 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, | ||
| 686 | 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb, | ||
| 687 | 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa, | ||
| 688 | 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, | ||
| 689 | 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0, | ||
| 690 | 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78, | ||
| 691 | 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, | ||
| 692 | 0xf4, 0x7c, 0x9b, 0x1f, | ||
| 693 | }, | ||
| 694 | .C_len = 60, | ||
| 695 | .T = { | ||
| 696 | 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, | ||
| 697 | 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2, | ||
| 698 | }, | ||
| 699 | }, | ||
| 700 | { | ||
| 701 | /* Test Case 18. */ | ||
| 702 | /* K is the same as TC15, P and A are the same as TC 16. */ | ||
| 703 | .K = { | ||
| 704 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 705 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 706 | 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | ||
| 707 | 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, | ||
| 708 | }, | ||
| 709 | .K_len = 32, | ||
| 710 | .IV = { | ||
| 711 | 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, | ||
| 712 | 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, | ||
| 713 | 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, | ||
| 714 | 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, | ||
| 715 | 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, | ||
| 716 | 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, | ||
| 717 | 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, | ||
| 718 | 0xa6, 0x37, 0xb3, 0x9b, | ||
| 719 | }, | ||
| 720 | .IV_len = 60, | ||
| 721 | .P = { | ||
| 722 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 723 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 724 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 725 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 726 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 727 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 728 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 729 | 0xba, 0x63, 0x7b, 0x39, | ||
| 730 | }, | ||
| 731 | .P_len = 60, | ||
| 732 | .A = { | ||
| 733 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 734 | 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | ||
| 735 | 0xab, 0xad, 0xda, 0xd2, | ||
| 736 | }, | ||
| 737 | .A_len = 20, | ||
| 738 | .C = { | ||
| 739 | 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1, | ||
| 740 | 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20, | ||
| 741 | 0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19, | ||
| 742 | 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4, | ||
| 743 | 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45, | ||
| 744 | 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde, | ||
| 745 | 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e, | ||
| 746 | 0x44, 0xae, 0x7e, 0x3f, | ||
| 747 | }, | ||
| 748 | .C_len = 60, | ||
| 749 | .T = { | ||
| 750 | 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0, | ||
| 751 | 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a, | ||
| 752 | }, | ||
| 753 | }, | ||
| 754 | { | ||
| 755 | /* Test Case 19. */ | ||
| 756 | .K = {0}, | ||
| 757 | .K_len = 16, | ||
| 758 | .IV = {0}, | ||
| 759 | .IV_len = 12, | ||
| 760 | .P = {0}, | ||
| 761 | .P_len = 0, | ||
| 762 | .A = { | ||
| 763 | 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | ||
| 764 | 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | ||
| 765 | 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | ||
| 766 | 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | ||
| 767 | 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | ||
| 768 | 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | ||
| 769 | 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | ||
| 770 | 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, | ||
| 771 | 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, | ||
| 772 | 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, | ||
| 773 | 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, | ||
| 774 | 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, | ||
| 775 | 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, | ||
| 776 | 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, | ||
| 777 | 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, | ||
| 778 | 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad, | ||
| 779 | }, | ||
| 780 | .A_len = 128, | ||
| 781 | .C = {0}, | ||
| 782 | .C_len = 0, | ||
| 783 | .T = { | ||
| 784 | 0x5f, 0xea, 0x79, 0x3a, 0x2d, 0x6f, 0x97, 0x4d, | ||
| 785 | 0x37, 0xe6, 0x8e, 0x0c, 0xb8, 0xff, 0x94, 0x92, | ||
| 786 | }, | ||
| 787 | }, | ||
| 788 | { | ||
| 789 | /* Test Case 20. */ | ||
| 790 | .K = {0}, | ||
| 791 | .K_len = 16, | ||
| 792 | .IV = { | ||
| 793 | /* This results in 0xff in counter LSB. */ | ||
| 794 | 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, | ||
| 795 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 796 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 797 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 798 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 799 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 800 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 801 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 802 | }, | ||
| 803 | .IV_len = 64, | ||
| 804 | .P = {0}, | ||
| 805 | .P_len = 288, | ||
| 806 | .A = {0}, | ||
| 807 | .A_len = 0, | ||
| 808 | .C = { | ||
| 809 | 0x56, 0xb3, 0x37, 0x3c, 0xa9, 0xef, 0x6e, 0x4a, | ||
| 810 | 0x2b, 0x64, 0xfe, 0x1e, 0x9a, 0x17, 0xb6, 0x14, | ||
| 811 | 0x25, 0xf1, 0x0d, 0x47, 0xa7, 0x5a, 0x5f, 0xce, | ||
| 812 | 0x13, 0xef, 0xc6, 0xbc, 0x78, 0x4a, 0xf2, 0x4f, | ||
| 813 | 0x41, 0x41, 0xbd, 0xd4, 0x8c, 0xf7, 0xc7, 0x70, | ||
| 814 | 0x88, 0x7a, 0xfd, 0x57, 0x3c, 0xca, 0x54, 0x18, | ||
| 815 | 0xa9, 0xae, 0xff, 0xcd, 0x7c, 0x5c, 0xed, 0xdf, | ||
| 816 | 0xc6, 0xa7, 0x83, 0x97, 0xb9, 0xa8, 0x5b, 0x49, | ||
| 817 | 0x9d, 0xa5, 0x58, 0x25, 0x72, 0x67, 0xca, 0xab, | ||
| 818 | 0x2a, 0xd0, 0xb2, 0x3c, 0xa4, 0x76, 0xa5, 0x3c, | ||
| 819 | 0xb1, 0x7f, 0xb4, 0x1c, 0x4b, 0x8b, 0x47, 0x5c, | ||
| 820 | 0xb4, 0xf3, 0xf7, 0x16, 0x50, 0x94, 0xc2, 0x29, | ||
| 821 | 0xc9, 0xe8, 0xc4, 0xdc, 0x0a, 0x2a, 0x5f, 0xf1, | ||
| 822 | 0x90, 0x3e, 0x50, 0x15, 0x11, 0x22, 0x13, 0x76, | ||
| 823 | 0xa1, 0xcd, 0xb8, 0x36, 0x4c, 0x50, 0x61, 0xa2, | ||
| 824 | 0x0c, 0xae, 0x74, 0xbc, 0x4a, 0xcd, 0x76, 0xce, | ||
| 825 | 0xb0, 0xab, 0xc9, 0xfd, 0x32, 0x17, 0xef, 0x9f, | ||
| 826 | 0x8c, 0x90, 0xbe, 0x40, 0x2d, 0xdf, 0x6d, 0x86, | ||
| 827 | 0x97, 0xf4, 0xf8, 0x80, 0xdf, 0xf1, 0x5b, 0xfb, | ||
| 828 | 0x7a, 0x6b, 0x28, 0x24, 0x1e, 0xc8, 0xfe, 0x18, | ||
| 829 | 0x3c, 0x2d, 0x59, 0xe3, 0xf9, 0xdf, 0xff, 0x65, | ||
| 830 | 0x3c, 0x71, 0x26, 0xf0, 0xac, 0xb9, 0xe6, 0x42, | ||
| 831 | 0x11, 0xf4, 0x2b, 0xae, 0x12, 0xaf, 0x46, 0x2b, | ||
| 832 | 0x10, 0x70, 0xbe, 0xf1, 0xab, 0x5e, 0x36, 0x06, | ||
| 833 | 0x87, 0x2c, 0xa1, 0x0d, 0xee, 0x15, 0xb3, 0x24, | ||
| 834 | 0x9b, 0x1a, 0x1b, 0x95, 0x8f, 0x23, 0x13, 0x4c, | ||
| 835 | 0x4b, 0xcc, 0xb7, 0xd0, 0x32, 0x00, 0xbc, 0xe4, | ||
| 836 | 0x20, 0xa2, 0xf8, 0xeb, 0x66, 0xdc, 0xf3, 0x64, | ||
| 837 | 0x4d, 0x14, 0x23, 0xc1, 0xb5, 0x69, 0x90, 0x03, | ||
| 838 | 0xc1, 0x3e, 0xce, 0xf4, 0xbf, 0x38, 0xa3, 0xb6, | ||
| 839 | 0x0e, 0xed, 0xc3, 0x40, 0x33, 0xba, 0xc1, 0x90, | ||
| 840 | 0x27, 0x83, 0xdc, 0x6d, 0x89, 0xe2, 0xe7, 0x74, | ||
| 841 | 0x18, 0x8a, 0x43, 0x9c, 0x7e, 0xbc, 0xc0, 0x67, | ||
| 842 | 0x2d, 0xbd, 0xa4, 0xdd, 0xcf, 0xb2, 0x79, 0x46, | ||
| 843 | 0x13, 0xb0, 0xbe, 0x41, 0x31, 0x5e, 0xf7, 0x78, | ||
| 844 | 0x70, 0x8a, 0x70, 0xee, 0x7d, 0x75, 0x16, 0x5c, | ||
| 845 | }, | ||
| 846 | .C_len = 288, | ||
| 847 | .T = { | ||
| 848 | 0x8b, 0x30, 0x7f, 0x6b, 0x33, 0x28, 0x6d, 0x0a, | ||
| 849 | 0xb0, 0x26, 0xa9, 0xed, 0x3f, 0xe1, 0xe8, 0x5f, | ||
| 850 | }, | ||
| 851 | }, | ||
| 852 | }; | ||
| 853 | |||
| 854 | #define N_TESTS (sizeof(gcm128_tests) / sizeof(*gcm128_tests)) | ||
| 855 | |||
| 856 | static int | ||
| 857 | do_gcm128_test(int test_no, struct gcm128_test *tv) | ||
| 858 | { | ||
| 859 | GCM128_CONTEXT ctx; | ||
| 860 | AES_KEY key; | ||
| 861 | uint8_t *out = NULL; | ||
| 862 | size_t out_len; | ||
| 863 | int ret = 1; | ||
| 864 | |||
| 865 | out_len = tv->P_len; | ||
| 866 | if (out_len != 0) { | ||
| 867 | out = malloc(out_len); | ||
| 868 | if (out == NULL) | ||
| 869 | err(1, "malloc"); | ||
| 870 | } | ||
| 871 | |||
| 872 | AES_set_encrypt_key(tv->K, tv->K_len * 8, &key); | ||
| 873 | |||
| 874 | if (out_len != 0) | ||
| 875 | memset(out, 0, out_len); | ||
| 876 | CRYPTO_gcm128_init(&ctx, &key, (block128_f)AES_encrypt); | ||
| 877 | CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); | ||
| 878 | if (tv->A_len > 0) | ||
| 879 | CRYPTO_gcm128_aad(&ctx, tv->A, tv->A_len); | ||
| 880 | if (tv->P_len > 0) | ||
| 881 | CRYPTO_gcm128_encrypt(&ctx, tv->P, out, out_len); | ||
| 882 | if (CRYPTO_gcm128_finish(&ctx, tv->T, 16)) { | ||
| 883 | fprintf(stderr, "TEST %i: CRYPTO_gcm128_finish failed\n", | ||
| 884 | test_no); | ||
| 885 | goto fail; | ||
| 886 | } | ||
| 887 | if (tv->C_len > 0 && memcmp(out, tv->C, out_len)) { | ||
| 888 | fprintf(stderr, "TEST %i: encrypt failed\n", test_no); | ||
| 889 | goto fail; | ||
| 890 | } | ||
| 891 | |||
| 892 | if (out_len != 0) | ||
| 893 | memset(out, 0, out_len); | ||
| 894 | CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); | ||
| 895 | if (tv->A_len > 0) | ||
| 896 | CRYPTO_gcm128_aad(&ctx, tv->A, tv->A_len); | ||
| 897 | if (tv->C_len > 0) | ||
| 898 | CRYPTO_gcm128_decrypt(&ctx, tv->C, out, out_len); | ||
| 899 | if (CRYPTO_gcm128_finish(&ctx, tv->T, 16)) { | ||
| 900 | fprintf(stderr, "TEST %i: CRYPTO_gcm128_finish failed\n", | ||
| 901 | test_no); | ||
| 902 | goto fail; | ||
| 903 | } | ||
| 904 | if (tv->P_len > 0 && memcmp(out, tv->P, out_len)) { | ||
| 905 | fprintf(stderr, "TEST %i: decrypt failed\n", test_no); | ||
| 906 | goto fail; | ||
| 907 | } | ||
| 908 | |||
| 909 | ret = 0; | ||
| 910 | |||
| 911 | fail: | ||
| 912 | free(out); | ||
| 913 | return (ret); | ||
| 914 | } | ||
| 915 | |||
| 916 | int | ||
| 917 | main(int argc, char **argv) | ||
| 918 | { | ||
| 919 | int ret = 0; | ||
| 920 | size_t i; | ||
| 921 | |||
| 922 | for (i = 0; i < N_TESTS; i++) | ||
| 923 | ret |= do_gcm128_test(i + 1, &gcm128_tests[i]); | ||
| 924 | |||
| 925 | return ret; | ||
| 926 | } | ||
diff --git a/src/regress/lib/libcrypto/gost/Makefile b/src/regress/lib/libcrypto/gost/Makefile deleted file mode 100644 index 14b0f9b824..0000000000 --- a/src/regress/lib/libcrypto/gost/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/11/09 19:45:26 miod Exp $ | ||
| 2 | |||
| 3 | PROG= gost2814789t | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/gost/gost2814789t.c b/src/regress/lib/libcrypto/gost/gost2814789t.c deleted file mode 100644 index 30aaead34e..0000000000 --- a/src/regress/lib/libcrypto/gost/gost2814789t.c +++ /dev/null | |||
| @@ -1,1459 +0,0 @@ | |||
| 1 | /* $OpenBSD: gost2814789t.c,v 1.2 2014/12/15 06:03:15 miod Exp $ */ | ||
| 2 | /* vim: set fileencoding=ascii : Charset: ASCII */ | ||
| 3 | /* test/gostr2814789t.c */ | ||
| 4 | /* ==================================================================== | ||
| 5 | * Copyright (c) 2012 Crypto-Pro, Ltd., Serguei E. Leontiev, | ||
| 6 | * lse@cryptopro.ru | ||
| 7 | * | ||
| 8 | * This file is distributed under the same license as OpenSSL | ||
| 9 | * ==================================================================== | ||
| 10 | */ | ||
| 11 | #include <stdio.h> | ||
| 12 | |||
| 13 | #if defined(OPENSSL_NO_GOST) | ||
| 14 | int main(int argc, char *argv[]) | ||
| 15 | { | ||
| 16 | printf("No GOST 28147-89 support\n"); | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | #else | ||
| 20 | |||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <inttypes.h> | ||
| 25 | #include <openssl/conf.h> | ||
| 26 | #include <openssl/crypto.h> | ||
| 27 | #include <openssl/engine.h> | ||
| 28 | #include <openssl/err.h> | ||
| 29 | #include <openssl/evp.h> | ||
| 30 | #include <openssl/hmac.h> | ||
| 31 | #include <openssl/obj_mac.h> | ||
| 32 | |||
| 33 | #define G89_MAX_TC_LEN (2048) | ||
| 34 | #define G89_BLOCK_LEN (8) | ||
| 35 | |||
| 36 | #undef U64 | ||
| 37 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) | ||
| 38 | #define U64(C) C##UI64 | ||
| 39 | #elif defined(_LP64) || defined(__arch64__) | ||
| 40 | #define U64(C) C##UL | ||
| 41 | #else | ||
| 42 | #define U64(C) C##ULL | ||
| 43 | #endif | ||
| 44 | |||
| 45 | typedef enum g89_mode_ { | ||
| 46 | G89_ECB, | ||
| 47 | G89_CFB, | ||
| 48 | G89_CNT, | ||
| 49 | G89_IMIT | ||
| 50 | } g89_mode; | ||
| 51 | |||
| 52 | typedef struct g89_tc_ { | ||
| 53 | uint64_t ullLen; /* ullLen > G89_MAX_TC_LEN */ | ||
| 54 | /* Clear text ullLen */ | ||
| 55 | /* of zero unsigned chars */ | ||
| 56 | const unsigned char bIn[G89_MAX_TC_LEN]; /* Clear text, when */ | ||
| 57 | /* ullLen <= G89_MAX_TC_LEN */ | ||
| 58 | const char *szParamSet; /* S-Box ID */ | ||
| 59 | const char *szDerive; /* String for derive bRawKey */ | ||
| 60 | const unsigned char bRawKey[EVP_MAX_KEY_LENGTH]; | ||
| 61 | g89_mode gMode; /* Mode of encryption or MAC */ | ||
| 62 | const unsigned char bIV[EVP_MAX_IV_LENGTH]; /* IV for CFB or CNT mode */ | ||
| 63 | const unsigned char bOut[G89_MAX_TC_LEN]; /* Cipher text for ECB/CFB/CNT */ | ||
| 64 | /* mode, when ullLen <= G89_MAX_TC_LEN; | ||
| 65 | * Last 16 unsigned char of cipher text for | ||
| 66 | * ECB/CFB/CNT, when ullLen > | ||
| 67 | * G89_MAX_TC_LEN; | ||
| 68 | * 4 unsigned char MAC for imitovstavka */ | ||
| 69 | } g89_tc; | ||
| 70 | |||
| 71 | const g89_tc tcs[] = { | ||
| 72 | /* | ||
| 73 | * GOST R 34.11-94 Test cases | ||
| 74 | */ | ||
| 75 | { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */ | ||
| 76 | /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */ | ||
| 77 | /* Iteration 1, K[1], see Errata for RFC 5831 */ | ||
| 78 | 8, | ||
| 79 | { | ||
| 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 81 | }, | ||
| 82 | "id-GostR3411-94-TestParamSet", | ||
| 83 | NULL, | ||
| 84 | { | ||
| 85 | 0x54, 0x6d, 0x20, 0x33, 0x68, 0x65, 0x6c, 0x32, | ||
| 86 | 0x69, 0x73, 0x65, 0x20, 0x73, 0x73, 0x6e, 0x62, | ||
| 87 | 0x20, 0x61, 0x67, 0x79, 0x69, 0x67, 0x74, 0x74, | ||
| 88 | 0x73, 0x65, 0x68, 0x65, 0x20, 0x2c, 0x3d, 0x73 | ||
| 89 | }, | ||
| 90 | G89_ECB, | ||
| 91 | { 0 }, | ||
| 92 | { | ||
| 93 | 0x1b, 0x0b, 0xbc, 0x32, 0xce, 0xbc, 0xab, 0x42 | ||
| 94 | } | ||
| 95 | }, | ||
| 96 | { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */ | ||
| 97 | /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */ | ||
| 98 | /* Iteration 1, K[4] */ | ||
| 99 | 8, | ||
| 100 | { | ||
| 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 102 | }, | ||
| 103 | "id-GostR3411-94-TestParamSet", | ||
| 104 | NULL, | ||
| 105 | { | ||
| 106 | 0xec, 0x0a, 0x8b, 0xa1, 0x5e, 0xc0, 0x04, 0xa8, | ||
| 107 | 0xba, 0xc5, 0x0c, 0xac, 0x0c, 0x62, 0x1d, 0xee, | ||
| 108 | 0xe1, 0xc7, 0xb8, 0xe7, 0x00, 0x7a, 0xe2, 0xec, | ||
| 109 | 0xf2, 0x73, 0x1b, 0xff, 0x4e, 0x80, 0xe2, 0xa0 | ||
| 110 | }, | ||
| 111 | G89_ECB, | ||
| 112 | { 0 }, | ||
| 113 | { | ||
| 114 | 0x2d, 0x56, 0x2a, 0x0d, 0x19, 0x04, 0x86, 0xe7 | ||
| 115 | } | ||
| 116 | }, | ||
| 117 | { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */ | ||
| 118 | /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */ | ||
| 119 | /* Iteration 2, K[1] */ | ||
| 120 | 8, | ||
| 121 | { | ||
| 122 | 0x34, 0xc0, 0x15, 0x33, 0xe3, 0x7d, 0x1c, 0x56 | ||
| 123 | }, | ||
| 124 | "id-GostR3411-94-TestParamSet", | ||
| 125 | NULL, | ||
| 126 | { | ||
| 127 | 0x34, 0x87, 0x24, 0xa4, 0xc1, 0xa6, 0x76, 0x67, | ||
| 128 | 0x15, 0x3d, 0xde, 0x59, 0x33, 0x88, 0x42, 0x50, | ||
| 129 | 0xe3, 0x24, 0x8c, 0x65, 0x7d, 0x41, 0x3b, 0x8c, | ||
| 130 | 0x1c, 0x9c, 0xa0, 0x9a, 0x56, 0xd9, 0x68, 0xcf | ||
| 131 | }, | ||
| 132 | G89_ECB, | ||
| 133 | { 0 }, | ||
| 134 | { | ||
| 135 | 0x86, 0x3e, 0x78, 0xdd, 0x2d, 0x60, 0xd1, 0x3c | ||
| 136 | } | ||
| 137 | }, | ||
| 138 | /* | ||
| 139 | * id-Gost28147-89-CryptoPro-A-ParamSet (1.2.643.2.2.31.1) | ||
| 140 | * Test cases | ||
| 141 | */ | ||
| 142 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 143 | 16, | ||
| 144 | { | ||
| 145 | 0x74, 0x3d, 0x76, 0xf9, 0x1b, 0xee, 0x35, 0x3c, | ||
| 146 | 0xa2, 0x5c, 0x3b, 0x10, 0xeb, 0x64, 0xcf, 0xf5 | ||
| 147 | }, | ||
| 148 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 149 | "testecb1", | ||
| 150 | { | ||
| 151 | 0xbb, 0xf1, 0xed, 0xd3, 0x20, 0xaf, 0x8a, 0x62, | ||
| 152 | 0x8e, 0x11, 0xc8, 0xa9, 0x51, 0xcc, 0xbe, 0x81, | ||
| 153 | 0x47, 0x7b, 0x41, 0xa1, 0x6a, 0xf6, 0x7f, 0x05, | ||
| 154 | 0xe8, 0x51, 0x2f, 0x9e, 0x01, 0xf8, 0xcf, 0x49 | ||
| 155 | }, | ||
| 156 | G89_ECB, | ||
| 157 | { 0 }, | ||
| 158 | { | ||
| 159 | 0xc3, 0x73, 0x90, 0x95, 0x35, 0x58, 0x08, 0x63, | ||
| 160 | 0xcb, 0x68, 0x85, 0x96, 0x77, 0xe8, 0xfb, 0xa9 | ||
| 161 | } | ||
| 162 | }, | ||
| 163 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 164 | 16, | ||
| 165 | { | ||
| 166 | 0xd2, 0xfd, 0xf8, 0x3a, 0xc1, 0xb4, 0x39, 0x23, | ||
| 167 | 0x2e, 0xaa, 0xcc, 0x98, 0x0a, 0x02, 0xda, 0x33 | ||
| 168 | }, | ||
| 169 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 170 | "testcfb1", | ||
| 171 | { | ||
| 172 | 0x8d, 0x5a, 0x2c, 0x83, 0xa7, 0xc7, 0x0a, 0x61, | ||
| 173 | 0xd6, 0x1b, 0x34, 0xb5, 0x1f, 0xdf, 0x42, 0x68, | ||
| 174 | 0x66, 0x71, 0xa3, 0x5d, 0x87, 0x4c, 0xfd, 0x84, | ||
| 175 | 0x99, 0x36, 0x63, 0xb6, 0x1e, 0xd6, 0x0d, 0xad | ||
| 176 | }, | ||
| 177 | G89_CFB, | ||
| 178 | { | ||
| 179 | 0x46, 0x60, 0x6f, 0x0d, 0x88, 0x34, 0x23, 0x5a | ||
| 180 | }, | ||
| 181 | { | ||
| 182 | 0x88, 0xb7, 0x75, 0x16, 0x74, 0xa5, 0xee, 0x2d, | ||
| 183 | 0x14, 0xfe, 0x91, 0x67, 0xd0, 0x5c, 0xcc, 0x40 | ||
| 184 | } | ||
| 185 | }, | ||
| 186 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 187 | 16, | ||
| 188 | { | ||
| 189 | 0x90, 0xa2, 0x39, 0x66, 0xae, 0x01, 0xb9, 0xa3, | ||
| 190 | 0x52, 0x4e, 0xc8, 0xed, 0x6c, 0xdd, 0x88, 0x30 | ||
| 191 | }, | ||
| 192 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 193 | "testcnt1", | ||
| 194 | { | ||
| 195 | 0x59, 0x9f, 0x84, 0xba, 0xc3, 0xf3, 0xd2, 0xf1, | ||
| 196 | 0x60, 0xe1, 0xe3, 0xf2, 0x6a, 0x96, 0x1a, 0xf9, | ||
| 197 | 0x9c, 0x48, 0xb2, 0x4e, 0xbc, 0xbb, 0xbf, 0x7c, | ||
| 198 | 0xd8, 0xf3, 0xac, 0xcd, 0x96, 0x8d, 0x28, 0x6a | ||
| 199 | }, | ||
| 200 | G89_CNT, | ||
| 201 | { | ||
| 202 | 0x8d, 0xaf, 0xa8, 0xd1, 0x58, 0xed, 0x05, 0x8d | ||
| 203 | }, | ||
| 204 | { | ||
| 205 | 0x6e, 0x72, 0x62, 0xcc, 0xe3, 0x59, 0x36, 0x90, | ||
| 206 | 0x83, 0x3a, 0xfe, 0xa9, 0x1b, 0xc9, 0xbe, 0xce | ||
| 207 | } | ||
| 208 | }, | ||
| 209 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 210 | 16, | ||
| 211 | { | ||
| 212 | 0xb5, 0xa1, 0xf0, 0xe3, 0xce, 0x2f, 0x02, 0x1d, | ||
| 213 | 0x67, 0x61, 0x94, 0x34, 0x5c, 0x41, 0xe3, 0x6e | ||
| 214 | }, | ||
| 215 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 216 | "testimit1", | ||
| 217 | { | ||
| 218 | 0x9d, 0x05, 0xb7, 0x9e, 0x90, 0xca, 0xd0, 0x0a, | ||
| 219 | 0x2c, 0xda, 0xd2, 0x2e, 0xf4, 0xe8, 0x6f, 0x5c, | ||
| 220 | 0xf5, 0xdc, 0x37, 0x68, 0x19, 0x85, 0xb3, 0xbf, | ||
| 221 | 0xaa, 0x18, 0xc1, 0xc3, 0x05, 0x0a, 0x91, 0xa2 | ||
| 222 | }, | ||
| 223 | G89_IMIT, | ||
| 224 | { 0 }, | ||
| 225 | { | ||
| 226 | 0xf8, 0x1f, 0x08, 0xa3 | ||
| 227 | } | ||
| 228 | }, | ||
| 229 | /* | ||
| 230 | * Other paramsets and key meshing test cases. | ||
| 231 | */ | ||
| 232 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 233 | 1039, | ||
| 234 | { | ||
| 235 | 0x8c, 0x9c, 0x44, 0x35, 0xfb, 0xe9, 0xa5, 0xa3, | ||
| 236 | 0xa0, 0xae, 0x28, 0x56, 0x91, 0x10, 0x8e, 0x1e , | ||
| 237 | 0xd2, 0xbb, 0x18, 0x53, 0x81, 0x27, 0x0d, 0xa6, | ||
| 238 | 0x68, 0x59, 0x36, 0xc5, 0x81, 0x62, 0x9a, 0x8e, | ||
| 239 | 0x7d, 0x50, 0xf1, 0x6f, 0x97, 0x62, 0x29, 0xec, | ||
| 240 | 0x80, 0x51, 0xe3, 0x7d, 0x6c, 0xc4, 0x07, 0x95, | ||
| 241 | 0x28, 0x63, 0xdc, 0xb4, 0xb9, 0x2d, 0xb8, 0x13, | ||
| 242 | 0xb1, 0x05, 0xb5, 0xf9, 0xeb, 0x75, 0x37, 0x4e, | ||
| 243 | 0xf7, 0xbf, 0x51, 0xf1, 0x98, 0x86, 0x43, 0xc4, | ||
| 244 | 0xe4, 0x3d, 0x3e, 0xa7, 0x62, 0xec, 0x41, 0x59, | ||
| 245 | 0xe0, 0xbd, 0xfb, 0xb6, 0xfd, 0xec, 0xe0, 0x77, | ||
| 246 | 0x13, 0xd2, 0x59, 0x90, 0xa1, 0xb8, 0x97, 0x6b, | ||
| 247 | 0x3d, 0x8b, 0x7d, 0xfc, 0x9d, 0xca, 0x82, 0x73, | ||
| 248 | 0x32, 0x70, 0x0a, 0x74, 0x03, 0xc6, 0x0c, 0x26, | ||
| 249 | 0x7f, 0x56, 0xf0, 0x9d, 0xb2, 0xeb, 0x71, 0x40, | ||
| 250 | 0xd7, 0xc3, 0xb1, 0xa7, 0xc5, 0x1e, 0x20, 0x17, | ||
| 251 | 0xb3, 0x50, 0x1d, 0x8a, 0x6e, 0x19, 0xcb, 0xbe, | ||
| 252 | 0x20, 0x86, 0x2b, 0xd6, 0x1c, 0xfd, 0xb4, 0xb7, | ||
| 253 | 0x5d, 0x9a, 0xb3, 0xe3, 0x7d, 0x15, 0x7a, 0x35, | ||
| 254 | 0x01, 0x9f, 0x5d, 0x65, 0x89, 0x4b, 0x34, 0xc6, | ||
| 255 | 0xf4, 0x81, 0x3f, 0x78, 0x30, 0xcf, 0xe9, 0x15, | ||
| 256 | 0x90, 0x9a, 0xf9, 0xde, 0xba, 0x63, 0xd0, 0x19, | ||
| 257 | 0x14, 0x66, 0x3c, 0xb9, 0xa4, 0xb2, 0x84, 0x94, | ||
| 258 | 0x02, 0xcf, 0xce, 0x20, 0xcf, 0x76, 0xe7, 0xc5, | ||
| 259 | 0x48, 0xf7, 0x69, 0x3a, 0x5d, 0xec, 0xaf, 0x41, | ||
| 260 | 0xa7, 0x12, 0x64, 0x83, 0xf5, 0x99, 0x1e, 0x9e, | ||
| 261 | 0xb2, 0xab, 0x86, 0x16, 0x00, 0x23, 0x8e, 0xe6, | ||
| 262 | 0xd9, 0x80, 0x0b, 0x6d, 0xc5, 0x93, 0xe2, 0x5c, | ||
| 263 | 0x8c, 0xd8, 0x5e, 0x5a, 0xae, 0x4a, 0x85, 0xfd, | ||
| 264 | 0x76, 0x01, 0xea, 0x30, 0xf3, 0x78, 0x34, 0x10, | ||
| 265 | 0x72, 0x51, 0xbc, 0x9f, 0x76, 0xce, 0x1f, 0xd4, | ||
| 266 | 0x8f, 0x33, 0x50, 0x34, 0xc7, 0x4d, 0x7b, 0xcf, | ||
| 267 | 0x91, 0x63, 0x7d, 0x82, 0x9e, 0xa1, 0x23, 0x45, | ||
| 268 | 0xf5, 0x45, 0xac, 0x98, 0x7a, 0x48, 0xff, 0x64, | ||
| 269 | 0xd5, 0x59, 0x47, 0xde, 0x2b, 0x3f, 0xfa, 0xec, | ||
| 270 | 0x50, 0xe0, 0x81, 0x60, 0x8b, 0xc3, 0xfc, 0x80, | ||
| 271 | 0x98, 0x17, 0xc7, 0xa3, 0xc2, 0x57, 0x3d, 0xab, | ||
| 272 | 0x91, 0x67, 0xf5, 0xc4, 0xab, 0x92, 0xc8, 0xd6, | ||
| 273 | 0x3b, 0x6b, 0x3f, 0xff, 0x15, 0x6b, 0xcf, 0x53, | ||
| 274 | 0x65, 0x02, 0xf1, 0x74, 0xca, 0xa9, 0xbe, 0x24, | ||
| 275 | 0xd2, 0xf0, 0xb7, 0x26, 0xa8, 0xd7, 0x6d, 0xed, | ||
| 276 | 0x90, 0x36, 0x7b, 0x3e, 0x41, 0xa9, 0x7f, 0xa3, | ||
| 277 | 0x1b, 0xf4, 0x43, 0xc5, 0x51, 0xbe, 0x28, 0x59, | ||
| 278 | 0xe9, 0x45, 0x26, 0x49, 0x38, 0x32, 0xf8, 0xf3, | ||
| 279 | 0x92, 0x6e, 0x30, 0xcc, 0xb0, 0xa0, 0xf9, 0x01, | ||
| 280 | 0x14, 0xc8, 0xba, 0xd9, 0xf0, 0x2a, 0x29, 0xe2, | ||
| 281 | 0x52, 0x9a, 0x76, 0x95, 0x3a, 0x16, 0x32, 0xec, | ||
| 282 | 0xf4, 0x10, 0xec, 0xee, 0x47, 0x00, 0x70, 0x19, | ||
| 283 | 0xe4, 0x72, 0x35, 0x66, 0x44, 0x53, 0x2d, 0xa2, | ||
| 284 | 0xf3, 0xaa, 0x7e, 0x8a, 0x33, 0x13, 0xcd, 0xc8, | ||
| 285 | 0xbf, 0x0e, 0x40, 0x90, 0x00, 0xe4, 0x42, 0xc3, | ||
| 286 | 0x09, 0x84, 0xe1, 0x66, 0x17, 0xa2, 0xaf, 0x03, | ||
| 287 | 0xab, 0x6b, 0xa1, 0xec, 0xfb, 0x17, 0x72, 0x81, | ||
| 288 | 0xfe, 0x9a, 0x9f, 0xf4, 0xb2, 0x33, 0x1f, 0xae, | ||
| 289 | 0x0c, 0xd1, 0x6a, 0xae, 0x19, 0xb8, 0xaf, 0xec, | ||
| 290 | 0xe3, 0xea, 0x00, 0xf8, 0xac, 0x87, 0x07, 0x5f, | ||
| 291 | 0x6d, 0xb0, 0xac, 0x6b, 0x22, 0x48, 0x36, 0xbf, | ||
| 292 | 0x22, 0x18, 0xb0, 0x03, 0x9f, 0x6c, 0x70, 0x45, | ||
| 293 | 0x36, 0xf0, 0x6b, 0xc6, 0xc2, 0xa5, 0x72, 0x2c, | ||
| 294 | 0xd8, 0xe0, 0x27, 0x3d, 0xec, 0x56, 0x07, 0x05, | ||
| 295 | 0x7d, 0x83, 0xa1, 0x65, 0x7d, 0x41, 0x5b, 0xcd, | ||
| 296 | 0x77, 0x24, 0xe5, 0xaa, 0x76, 0x47, 0xd0, 0x50, | ||
| 297 | 0xf6, 0xe7, 0xb5, 0x59, 0x75, 0x31, 0x27, 0xef, | ||
| 298 | 0xd8, 0xa6, 0x4e, 0x7f, 0xb8, 0x40, 0xb1, 0xdf, | ||
| 299 | 0x53, 0x14, 0xed, 0xf1, 0x68, 0x5f, 0xfc, 0x3f, | ||
| 300 | 0x02, 0xdb, 0x05, 0xeb, 0x31, 0xe4, 0x2c, 0x7f, | ||
| 301 | 0x32, 0xb5, 0x70, 0x8e, 0x75, 0x85, 0xa4, 0x5c, | ||
| 302 | 0x16, 0x23, 0x37, 0xf2, 0x10, 0x79, 0xcb, 0xdc, | ||
| 303 | 0xf8, 0x1c, 0x25, 0xc2, 0xa1, 0x3d, 0x9c, 0x33, | ||
| 304 | 0x6c, 0xed, 0xc3, 0xe7, 0xf3, 0x02, 0x87, 0x82, | ||
| 305 | 0x4e, 0xfb, 0xac, 0xb3, 0x2d, 0xfc, 0xf8, 0x0d, | ||
| 306 | 0x1d, 0x4a, 0x39, 0xd4, 0xb3, 0x09, 0xbb, 0xe9, | ||
| 307 | 0x25, 0xc7, 0xec, 0x6a, 0x87, 0x72, 0x84, 0xed, | ||
| 308 | 0x12, 0x60, 0x19, 0x64, 0xeb, 0x16, 0x2a, 0x5b, | ||
| 309 | 0x10, 0x76, 0x27, 0xff, 0x7b, 0xe4, 0xae, 0xe5, | ||
| 310 | 0xa4, 0x04, 0x02, 0x7f, 0xbb, 0x0a, 0xb5, 0xf4, | ||
| 311 | 0x05, 0xa5, 0x56, 0x1c, 0x53, 0x31, 0x7a, 0x93, | ||
| 312 | 0xba, 0x16, 0x15, 0xab, 0x62, 0x60, 0xfc, 0xde, | ||
| 313 | 0x72, 0x36, 0x6e, 0x28, 0xaf, 0x98, 0x0d, 0xe6, | ||
| 314 | 0xf4, 0xde, 0x60, 0xa7, 0x7e, 0x06, 0x07, 0x86, | ||
| 315 | 0xf3, 0x94, 0xb6, 0x6d, 0x0d, 0x93, 0xa6, 0xbc, | ||
| 316 | 0x60, 0x70, 0x33, 0xac, 0x3f, 0xa1, 0xa8, 0x4a, | ||
| 317 | 0x20, 0x61, 0xb6, 0xb5, 0x43, 0xa3, 0x15, 0x5a, | ||
| 318 | 0x00, 0xbe, 0x76, 0x98, 0x57, 0x72, 0xab, 0x7a, | ||
| 319 | 0x0e, 0x18, 0x93, 0x82, 0x3a, 0x18, 0x78, 0x6e, | ||
| 320 | 0x71, 0x7b, 0x78, 0x4f, 0x7e, 0x8c, 0xde, 0x7a, | ||
| 321 | 0x62, 0xb5, 0x0a, 0x7c, 0x45, 0x1d, 0x16, 0xd5, | ||
| 322 | 0xc3, 0x8c, 0x9b, 0x25, 0xb4, 0x50, 0x90, 0xcd, | ||
| 323 | 0x96, 0x93, 0xad, 0x0f, 0xd4, 0x43, 0xcb, 0x49, | ||
| 324 | 0x0f, 0xfc, 0x5a, 0x31, 0xf4, 0x19, 0xb7, 0xd4, | ||
| 325 | 0xeb, 0x4d, 0x40, 0x58, 0xd0, 0x3b, 0xc8, 0xe0, | ||
| 326 | 0x4a, 0x54, 0x2f, 0xdb, 0x22, 0xc3, 0x29, 0x7b, | ||
| 327 | 0x40, 0x90, 0x61, 0x43, 0xd3, 0x7e, 0xe2, 0x30, | ||
| 328 | 0x2b, 0x48, 0x3c, 0xce, 0x90, 0x93, 0xb1, 0x8b, | ||
| 329 | 0x31, 0x96, 0x65, 0x6d, 0x57, 0x8b, 0x9d, 0x4d, | ||
| 330 | 0x53, 0xf0, 0x83, 0x1c, 0xe5, 0xa1, 0x9d, 0x55, | ||
| 331 | 0xe3, 0xbf, 0x7e, 0xca, 0x1a, 0x74, 0x66, 0x14, | ||
| 332 | 0xcc, 0x47, 0x43, 0xd9, 0xbb, 0xef, 0x97, 0x7d, | ||
| 333 | 0xb7, 0x6e, 0xff, 0xf1, 0x22, 0xf8, 0x10, 0x2d, | ||
| 334 | 0x3f, 0xcd, 0x49, 0x96, 0xd9, 0x09, 0x11, 0xb8, | ||
| 335 | 0x33, 0xd0, 0x23, 0x9a, 0xfa, 0x16, 0xcb, 0x50, | ||
| 336 | 0x26, 0x57, 0x24, 0x5c, 0x0e, 0xba, 0xf0, 0x3f, | ||
| 337 | 0x37, 0x2f, 0xa3, 0xf7, 0x18, 0x57, 0x48, 0x48, | ||
| 338 | 0x95, 0xcf, 0xef, 0x87, 0x67, 0x2a, 0xe9, 0xb6, | ||
| 339 | 0x8a, 0x21, 0x36, 0x7f, 0xff, 0x48, 0x6c, 0x46, | ||
| 340 | 0x35, 0x57, 0xf2, 0xbc, 0x48, 0x67, 0x8f, 0x63, | ||
| 341 | 0x23, 0x78, 0x11, 0x2b, 0xc2, 0x08, 0xde, 0x51, | ||
| 342 | 0xe8, 0x8b, 0x92, 0x29, 0xf9, 0x9a, 0x9e, 0xad, | ||
| 343 | 0xed, 0x0f, 0xeb, 0xa2, 0xd2, 0x40, 0x92, 0xd4, | ||
| 344 | 0xde, 0x62, 0x95, 0x76, 0xfd, 0x6e, 0x3c, 0xbf, | ||
| 345 | 0xc0, 0xd7, 0x0d, 0xe5, 0x1b, 0xa4, 0xc7, 0x18, | ||
| 346 | 0xe1, 0x58, 0xa4, 0x56, 0xef, 0x2e, 0x17, 0x1b, | ||
| 347 | 0x75, 0xcb, 0xbc, 0xf9, 0x2a, 0x95, 0x71, 0xa7, | ||
| 348 | 0x1d, 0x7f, 0xe7, 0x73, 0x63, 0x05, 0x6b, 0x19, | ||
| 349 | 0x4c, 0xf4, 0x22, 0x14, 0xc4, 0x59, 0x88, 0x66, | ||
| 350 | 0x92, 0x86, 0x61, 0x5c, 0x6a, 0xae, 0xec, 0x58, | ||
| 351 | 0xff, 0xc9, 0xf2, 0x44, 0xd4, 0xa2, 0xf5, 0x98, | ||
| 352 | 0xeb, 0x5f, 0x09, 0xbc, 0x8a, 0xbf, 0x3c, 0xb4, | ||
| 353 | 0x3e, 0xb1, 0x20, 0x05, 0x44, 0x96, 0x79, 0x0a, | ||
| 354 | 0x40, 0x92, 0x7f, 0x9d, 0xd1, 0xaf, 0xbc, 0x90, | ||
| 355 | 0x95, 0x0a, 0x81, 0xd4, 0xa7, 0xc6, 0xb8, 0xe0, | ||
| 356 | 0xe4, 0x39, 0x30, 0x1d, 0x79, 0xc0, 0xe5, 0xfa, | ||
| 357 | 0xb4, 0xe9, 0x63, 0xb4, 0x09, 0x72, 0x3b, 0x3e, | ||
| 358 | 0xd9, 0xf6, 0xd9, 0x10, 0x21, 0x18, 0x7e, 0xe5, | ||
| 359 | 0xad, 0x81, 0xd7, 0xd5, 0x82, 0xd0, 0x8c, 0x3b, | ||
| 360 | 0x38, 0x95, 0xf8, 0x92, 0x01, 0xa9, 0x92, 0x00, | ||
| 361 | 0x70, 0xd1, 0xa7, 0x88, 0x77, 0x1f, 0x3a, 0xeb, | ||
| 362 | 0xb5, 0xe4, 0xf5, 0x9d, 0xc7, 0x37, 0x86, 0xb2, | ||
| 363 | 0x12, 0x46, 0x34, 0x19, 0x72, 0x8c, 0xf5, 0x8c, | ||
| 364 | 0xf6, 0x78, 0x98, 0xe0, 0x7c, 0xd3, 0xf4 | ||
| 365 | }, | ||
| 366 | "id-Gost28147-89-CryptoPro-B-ParamSet", | ||
| 367 | "testcfb2", | ||
| 368 | { | ||
| 369 | 0x48, 0x0c, 0x74, 0x1b, 0x02, 0x6b, 0x55, 0xd5, | ||
| 370 | 0xb6, 0x6d, 0xd7, 0x1d, 0x40, 0x48, 0x05, 0x6b, | ||
| 371 | 0x6d, 0xeb, 0x3c, 0x29, 0x0f, 0x84, 0x80, 0x23, | ||
| 372 | 0xee, 0x0d, 0x47, 0x77, 0xe3, 0xfe, 0x61, 0xc9 | ||
| 373 | }, | ||
| 374 | G89_CFB, | ||
| 375 | { | ||
| 376 | 0x1f, 0x3f, 0x82, 0x1e, 0x0d, 0xd8, 0x1e, 0x22 | ||
| 377 | }, | ||
| 378 | { | ||
| 379 | 0x23, 0xc6, 0x7f, 0x20, 0xa1, 0x23, 0x58, 0xbc, | ||
| 380 | 0x7b, 0x05, 0xdb, 0x21, 0x15, 0xcf, 0x96, 0x41, | ||
| 381 | 0xc7, 0x88, 0xef, 0x76, 0x5c, 0x49, 0xdb, 0x42, | ||
| 382 | 0xbf, 0xf3, 0xc0, 0xf5, 0xbd, 0x5d, 0xd9, 0x8e, | ||
| 383 | 0xaf, 0x3d, 0xf4, 0xe4, 0xda, 0x88, 0xbd, 0xbc, | ||
| 384 | 0x47, 0x5d, 0x76, 0x07, 0xc9, 0x5f, 0x54, 0x1d, | ||
| 385 | 0x1d, 0x6a, 0xa1, 0x2e, 0x18, 0xd6, 0x60, 0x84, | ||
| 386 | 0x02, 0x18, 0x37, 0x92, 0x92, 0x15, 0xab, 0x21, | ||
| 387 | 0xee, 0x21, 0xcc, 0x71, 0x6e, 0x51, 0xd9, 0x2b, | ||
| 388 | 0xcc, 0x81, 0x97, 0x3f, 0xeb, 0x45, 0x99, 0xb8, | ||
| 389 | 0x1b, 0xda, 0xff, 0x90, 0xd3, 0x41, 0x06, 0x9c, | ||
| 390 | 0x3f, 0xfb, 0xe4, 0xb2, 0xdc, 0xc9, 0x03, 0x0d, | ||
| 391 | 0xa7, 0xae, 0xd7, 0x7d, 0x02, 0xb8, 0x32, 0xab, | ||
| 392 | 0xf3, 0x65, 0xa3, 0x65, 0x6c, 0x4e, 0xe4, 0xa2, | ||
| 393 | 0x5e, 0x9e, 0xee, 0xcd, 0xde, 0x79, 0x36, 0x6b, | ||
| 394 | 0x1b, 0xe1, 0x3c, 0xdf, 0x10, 0xad, 0x4f, 0x02, | ||
| 395 | 0xe1, 0x14, 0xaa, 0x09, 0xb4, 0x0b, 0x76, 0xeb, | ||
| 396 | 0x69, 0x38, 0x20, 0x02, 0xcb, 0x8e, 0xc0, 0xdf, | ||
| 397 | 0xca, 0x48, 0x74, 0xc3, 0x31, 0xad, 0x42, 0x2c, | ||
| 398 | 0x51, 0x9b, 0xd0, 0x6a, 0xc1, 0x36, 0xd7, 0x21, | ||
| 399 | 0xdf, 0xb0, 0x45, 0xba, 0xca, 0x7f, 0x35, 0x20, | ||
| 400 | 0x28, 0xbb, 0xc1, 0x76, 0xfd, 0x43, 0x5d, 0x23, | ||
| 401 | 0x7d, 0x31, 0x84, 0x1a, 0x97, 0x4d, 0x83, 0xaa, | ||
| 402 | 0x7e, 0xf1, 0xc4, 0xe6, 0x83, 0xac, 0x0d, 0xef, | ||
| 403 | 0xef, 0x3c, 0xa4, 0x7c, 0x48, 0xe4, 0xc8, 0xca, | ||
| 404 | 0x0d, 0x7d, 0xea, 0x7c, 0x45, 0xd7, 0x73, 0x50, | ||
| 405 | 0x25, 0x1d, 0x01, 0xc4, 0x02, 0x1a, 0xcd, 0xe0, | ||
| 406 | 0x38, 0x5b, 0xa8, 0x5a, 0x16, 0x9a, 0x10, 0x59, | ||
| 407 | 0x74, 0xd7, 0x19, 0xc6, 0xf3, 0xb5, 0x17, 0xf6, | ||
| 408 | 0x59, 0x8d, 0x62, 0xaf, 0x44, 0xe8, 0xdc, 0xe9, | ||
| 409 | 0xc1, 0x76, 0xf1, 0xd0, 0xbd, 0x29, 0xd7, 0xec, | ||
| 410 | 0x1d, 0xac, 0x57, 0xdb, 0x1a, 0x3f, 0xd8, 0xf6, | ||
| 411 | 0x6e, 0xb6, 0xe6, 0xdf, 0x36, 0xe7, 0x89, 0xce, | ||
| 412 | 0x56, 0x35, 0x43, 0x1c, 0x7d, 0x57, 0x79, 0x0e, | ||
| 413 | 0xd8, 0xf4, 0xd7, 0xa7, 0x0d, 0xc6, 0x8f, 0x91, | ||
| 414 | 0x66, 0x67, 0x82, 0x0f, 0x49, 0xc9, 0xc5, 0x65, | ||
| 415 | 0x81, 0xa1, 0x39, 0x5a, 0x53, 0x9f, 0x02, 0xa5, | ||
| 416 | 0xd5, 0x36, 0x22, 0xa8, 0xa8, 0x1c, 0x37, 0x0e, | ||
| 417 | 0x76, 0x46, 0xdf, 0xbd, 0x6a, 0xdb, 0xfc, 0x1b, | ||
| 418 | 0xbd, 0x10, 0xb8, 0xb1, 0xbc, 0x72, 0x4c, 0x58, | ||
| 419 | 0x4a, 0xda, 0x6d, 0x66, 0x00, 0xda, 0x7a, 0x66, | ||
| 420 | 0xa0, 0xe7, 0x3b, 0x39, 0xa3, 0xf7, 0x05, 0x07, | ||
| 421 | 0xfa, 0x21, 0x4b, 0xc7, 0x94, 0xc0, 0xd3, 0x7b, | ||
| 422 | 0x19, 0x02, 0x5d, 0x4a, 0x10, 0xf1, 0xc2, 0x0f, | ||
| 423 | 0x19, 0x68, 0x27, 0xc7, 0x7d, 0xbf, 0x55, 0x03, | ||
| 424 | 0x57, 0x7d, 0xaf, 0x77, 0xae, 0x80, 0x2f, 0x7a, | ||
| 425 | 0xe6, 0x1f, 0x4b, 0xdc, 0x15, 0x18, 0xc0, 0x62, | ||
| 426 | 0xa1, 0xe8, 0xd9, 0x1c, 0x9e, 0x8c, 0x96, 0x39, | ||
| 427 | 0xc1, 0xc4, 0x88, 0xf7, 0x0c, 0xe1, 0x04, 0x84, | ||
| 428 | 0x68, 0x51, 0xce, 0xf1, 0x90, 0xda, 0x7f, 0x76, | ||
| 429 | 0xc8, 0xc0, 0x88, 0xef, 0x8e, 0x15, 0x25, 0x3e, | ||
| 430 | 0x7b, 0xe4, 0x79, 0xb5, 0x66, 0x2d, 0x9c, 0xd1, | ||
| 431 | 0x13, 0xda, 0xd0, 0xd5, 0x46, 0xd5, 0x8d, 0x46, | ||
| 432 | 0x18, 0x07, 0xee, 0xd8, 0xc9, 0x64, 0xe3, 0xbe, | ||
| 433 | 0x0e, 0x68, 0x27, 0x09, 0x96, 0x26, 0xf6, 0xe2, | ||
| 434 | 0x19, 0x61, 0x3f, 0xf4, 0x58, 0x27, 0x0a, 0xeb, | ||
| 435 | 0xce, 0x7c, 0xb6, 0x68, 0x92, 0xe7, 0x12, 0x3b, | ||
| 436 | 0x31, 0xd4, 0x48, 0xdf, 0x35, 0x8d, 0xf4, 0x86, | ||
| 437 | 0x42, 0x2a, 0x15, 0x4b, 0xe8, 0x19, 0x1f, 0x26, | ||
| 438 | 0x65, 0x9b, 0xa8, 0xda, 0x4b, 0x79, 0x1f, 0x8e, | ||
| 439 | 0xe6, 0x13, 0x7e, 0x49, 0x8f, 0xc1, 0xce, 0xdc, | ||
| 440 | 0x5e, 0x64, 0x74, 0xce, 0x02, 0x78, 0xe0, 0xcf, | ||
| 441 | 0xa0, 0xed, 0x5e, 0x31, 0x74, 0xd1, 0xd0, 0xb4, | ||
| 442 | 0xee, 0x70, 0x19, 0x14, 0x3c, 0x8f, 0x16, 0xa6, | ||
| 443 | 0xcf, 0x12, 0x93, 0x15, 0x88, 0xeb, 0x91, 0x65, | ||
| 444 | 0x76, 0x98, 0xfd, 0xa1, 0x94, 0x30, 0xba, 0x43, | ||
| 445 | 0x62, 0x65, 0x40, 0x04, 0x77, 0x9e, 0xd6, 0xab, | ||
| 446 | 0x8b, 0x0d, 0x93, 0x80, 0x50, 0x5f, 0xa2, 0x76, | ||
| 447 | 0x20, 0xa7, 0xd6, 0x9c, 0x27, 0x15, 0x27, 0xbc, | ||
| 448 | 0xa5, 0x5a, 0xbf, 0xe9, 0x92, 0x82, 0x05, 0xa8, | ||
| 449 | 0x41, 0xe9, 0xb5, 0x60, 0xd5, 0xc0, 0xd7, 0x4b, | ||
| 450 | 0xad, 0x38, 0xb2, 0xe9, 0xd1, 0xe5, 0x51, 0x5f, | ||
| 451 | 0x24, 0x78, 0x24, 0x9a, 0x23, 0xd2, 0xc2, 0x48, | ||
| 452 | 0xbd, 0x0e, 0xf1, 0x37, 0x72, 0x91, 0x87, 0xb0, | ||
| 453 | 0x4e, 0xbd, 0x99, 0x6b, 0x2c, 0x01, 0xb6, 0x79, | ||
| 454 | 0x69, 0xec, 0x0c, 0xed, 0xe5, 0x3f, 0x50, 0x64, | ||
| 455 | 0x7c, 0xb9, 0xdd, 0xe1, 0x92, 0x81, 0xb5, 0xd0, | ||
| 456 | 0xcb, 0x17, 0x83, 0x86, 0x8b, 0xea, 0x4f, 0x93, | ||
| 457 | 0x08, 0xbc, 0x22, 0x0c, 0xef, 0xe8, 0x0d, 0xf5, | ||
| 458 | 0x9e, 0x23, 0xe1, 0xf9, 0xb7, 0x6b, 0x45, 0x0b, | ||
| 459 | 0xcb, 0xa9, 0xb6, 0x4d, 0x28, 0x25, 0xba, 0x3e, | ||
| 460 | 0x86, 0xf2, 0x75, 0x47, 0x5d, 0x9d, 0x6b, 0xf6, | ||
| 461 | 0x8a, 0x05, 0x58, 0x73, 0x3d, 0x00, 0xde, 0xfd, | ||
| 462 | 0x69, 0xb1, 0x61, 0x16, 0xf5, 0x2e, 0xb0, 0x9f, | ||
| 463 | 0x31, 0x6a, 0x00, 0xb9, 0xef, 0x71, 0x63, 0x47, | ||
| 464 | 0xa3, 0xca, 0xe0, 0x40, 0xa8, 0x7e, 0x02, 0x04, | ||
| 465 | 0xfe, 0xe5, 0xce, 0x48, 0x73, 0xe3, 0x94, 0xcf, | ||
| 466 | 0xe2, 0xff, 0x29, 0x7e, 0xf6, 0x32, 0xbb, 0xb7, | ||
| 467 | 0x55, 0x12, 0x21, 0x7a, 0x9c, 0x75, 0x04, 0x0c, | ||
| 468 | 0xb4, 0x7c, 0xb0, 0x3d, 0x40, 0xb3, 0x11, 0x9a, | ||
| 469 | 0x7a, 0x9a, 0x13, 0xfb, 0x77, 0xa7, 0x51, 0x68, | ||
| 470 | 0xf7, 0x05, 0x47, 0x3b, 0x0f, 0x52, 0x5c, 0xe6, | ||
| 471 | 0xc2, 0x99, 0x3a, 0x37, 0x54, 0x5c, 0x4f, 0x2b, | ||
| 472 | 0xa7, 0x01, 0x08, 0x74, 0xbc, 0x91, 0xe3, 0xe2, | ||
| 473 | 0xfe, 0x65, 0x94, 0xfd, 0x3d, 0x18, 0xe0, 0xf0, | ||
| 474 | 0x62, 0xed, 0xc2, 0x10, 0x82, 0x9c, 0x58, 0x7f, | ||
| 475 | 0xb2, 0xa3, 0x87, 0x8a, 0x74, 0xd9, 0xc1, 0xfb, | ||
| 476 | 0x84, 0x28, 0x17, 0xc7, 0x2b, 0xcb, 0x53, 0x1f, | ||
| 477 | 0x4e, 0x8a, 0x82, 0xfc, 0xb4, 0x3f, 0xc1, 0x47, | ||
| 478 | 0x25, 0xf3, 0x21, 0xdc, 0x4c, 0x2d, 0x08, 0xfa, | ||
| 479 | 0xe7, 0x0f, 0x03, 0xa9, 0x68, 0xde, 0x6b, 0x41, | ||
| 480 | 0xa0, 0xf9, 0x41, 0x6c, 0x57, 0x4d, 0x3a, 0x0e, | ||
| 481 | 0xea, 0x51, 0xca, 0x9f, 0x97, 0x11, 0x7d, 0xf6, | ||
| 482 | 0x8e, 0x88, 0x63, 0x67, 0xc9, 0x65, 0x13, 0xca, | ||
| 483 | 0x38, 0xed, 0x35, 0xbe, 0xf4, 0x27, 0xa9, 0xfc, | ||
| 484 | 0xa9, 0xe6, 0xc3, 0x40, 0x86, 0x08, 0x39, 0x72, | ||
| 485 | 0x37, 0xee, 0xb2, 0x87, 0x09, 0x96, 0xb7, 0x40, | ||
| 486 | 0x87, 0x36, 0x92, 0xc1, 0x5d, 0x6a, 0x2c, 0x43, | ||
| 487 | 0xca, 0x25, 0xc8, 0x35, 0x37, 0x2d, 0xb5, 0xa9, | ||
| 488 | 0x27, 0x44, 0x50, 0xf2, 0x6d, 0x22, 0x75, 0x41, | ||
| 489 | 0x77, 0x2a, 0xdb, 0xb1, 0x8c, 0x6d, 0x05, 0xe8, | ||
| 490 | 0xc9, 0x99, 0xc7, 0x08, 0xf9, 0x14, 0x8f, 0x78, | ||
| 491 | 0xa9, 0x8f, 0xc2, 0x5a, 0x7a, 0x65, 0xc5, 0xd8, | ||
| 492 | 0x86, 0xbb, 0x72, 0x69, 0x6b, 0x6b, 0x45, 0x83, | ||
| 493 | 0x5b, 0xb1, 0xf7, 0xcd, 0x16, 0x73, 0xee, 0xe9, | ||
| 494 | 0x80, 0x85, 0xfe, 0x8e, 0xe1, 0xae, 0x53, 0x8f, | ||
| 495 | 0xde, 0xbe, 0x48, 0x8b, 0x59, 0xef, 0xf6, 0x7e, | ||
| 496 | 0xd8, 0xb5, 0xa8, 0x47, 0xc0, 0x4e, 0x15, 0x58, | ||
| 497 | 0xca, 0xd3, 0x2f, 0xf8, 0x6c, 0xa6, 0x3d, 0x78, | ||
| 498 | 0x4d, 0x7a, 0x54, 0xd6, 0x10, 0xe5, 0xcc, 0x05, | ||
| 499 | 0xe2, 0x29, 0xb5, 0x86, 0x07, 0x39, 0x7d, 0x78, | ||
| 500 | 0x8e, 0x5a, 0x8f, 0x83, 0x4c, 0xe7, 0x3d, 0x68, | ||
| 501 | 0x3e, 0xe5, 0x02, 0xe6, 0x64, 0x4f, 0x5e, 0xb4, | ||
| 502 | 0x49, 0x77, 0xf0, 0xc0, 0xfa, 0x6f, 0xc8, 0xfb, | ||
| 503 | 0x9f, 0x84, 0x6f, 0x55, 0xfb, 0x30, 0x5e, 0x89, | ||
| 504 | 0x93, 0xa9, 0xf3, 0xa6, 0xa3, 0xd7, 0x26, 0xbb, | ||
| 505 | 0xd8, 0xa8, 0xd9, 0x95, 0x1d, 0xfe, 0xfc, 0xd7, | ||
| 506 | 0xa8, 0x93, 0x66, 0x2f, 0x04, 0x53, 0x06, 0x64, | ||
| 507 | 0x7f, 0x31, 0x29, 0xae, 0xb7, 0x9f, 0xba, 0xc4, | ||
| 508 | 0x6d, 0x68, 0xd1, 0x24, 0x32, 0xf4, 0x11 | ||
| 509 | } | ||
| 510 | }, | ||
| 511 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 512 | 4, | ||
| 513 | { | ||
| 514 | 0x07, 0x9c, 0x91, 0xbe | ||
| 515 | }, | ||
| 516 | "id-Gost28147-89-CryptoPro-C-ParamSet", | ||
| 517 | "testcfb3", | ||
| 518 | { | ||
| 519 | 0x77, 0xc3, 0x45, 0x8e, 0xf6, 0x42, 0xe7, 0x04, | ||
| 520 | 0x8e, 0xfc, 0x08, 0xe4, 0x70, 0x96, 0xd6, 0x05, | ||
| 521 | 0x93, 0x59, 0x02, 0x6d, 0x6f, 0x97, 0xca, 0xe9, | ||
| 522 | 0xcf, 0x89, 0x44, 0x4b, 0xde, 0x6c, 0x22, 0x1d | ||
| 523 | }, | ||
| 524 | G89_CFB, | ||
| 525 | { | ||
| 526 | 0x43, 0x7c, 0x3e, 0x8e, 0x2f, 0x2a, 0x00, 0x98 | ||
| 527 | }, | ||
| 528 | { | ||
| 529 | 0x19, 0x35, 0x81, 0x34 | ||
| 530 | } | ||
| 531 | }, | ||
| 532 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 533 | 9, | ||
| 534 | { | ||
| 535 | 0x2f, 0x31, 0xd8, 0x83, 0xb4, 0x20, 0xe8, 0x6e, | ||
| 536 | 0xda | ||
| 537 | }, | ||
| 538 | "id-Gost28147-89-CryptoPro-D-ParamSet", | ||
| 539 | "testcfb4", | ||
| 540 | { | ||
| 541 | 0x38, 0x9f, 0xe8, 0x37, 0xff, 0x9c, 0x5d, 0x29, | ||
| 542 | 0xfc, 0x48, 0x55, 0xa0, 0x87, 0xea, 0xe8, 0x40, | ||
| 543 | 0x20, 0x87, 0x5b, 0xb2, 0x01, 0x15, 0x55, 0xa7, | ||
| 544 | 0xe3, 0x2d, 0xcb, 0x3d, 0xd6, 0x59, 0x04, 0x73 | ||
| 545 | }, | ||
| 546 | G89_CFB, | ||
| 547 | { | ||
| 548 | 0xc5, 0xa2, 0xd2, 0x1f, 0x2f, 0xdf, 0xb8, 0xeb | ||
| 549 | }, | ||
| 550 | { | ||
| 551 | 0x6d, 0xa4, 0xed, 0x40, 0x08, 0x88, 0x71, 0xad, | ||
| 552 | 0x16 | ||
| 553 | } | ||
| 554 | }, | ||
| 555 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 556 | 5242880+8, | ||
| 557 | { 0 }, | ||
| 558 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 559 | "test5Mcfb", | ||
| 560 | { | ||
| 561 | 0x61, 0x58, 0x44, 0x5a, 0x41, 0xf6, 0xc7, 0x0f, | ||
| 562 | 0x6b, 0xdb, 0x51, 0x91, 0x6a, 0xf6, 0x81, 0x30, | ||
| 563 | 0x8c, 0xa7, 0x98, 0xdd, 0x38, 0x35, 0x8a, 0x60, | ||
| 564 | 0x85, 0xb4, 0xf0, 0xf9, 0x43, 0xa2, 0x7d, 0x9a | ||
| 565 | }, | ||
| 566 | G89_CFB, | ||
| 567 | { | ||
| 568 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 569 | }, | ||
| 570 | { | ||
| 571 | 0x1c, 0x16, 0xa0, 0xe9, 0x63, 0x94, 0xfe, 0x38, | ||
| 572 | 0x37, 0xa7, 0x9b, 0x70, 0x25, 0x2e, 0xd6, 0x00 | ||
| 573 | } | ||
| 574 | }, | ||
| 575 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 576 | U64(4294967296)+16, | ||
| 577 | { 0 }, | ||
| 578 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 579 | "test4Gcfb", | ||
| 580 | { | ||
| 581 | 0xae, 0x57, 0xa2, 0xdd, 0xa4, 0xef, 0x4f, 0x96, | ||
| 582 | 0xb8, 0x94, 0xa5, 0xd1, 0x1b, 0xc8, 0x9b, 0x42, | ||
| 583 | 0xa5, 0x24, 0xcc, 0x89, 0x5c, 0xb8, 0x92, 0x52, | ||
| 584 | 0xc1, 0x12, 0x6a, 0xb0, 0x9a, 0x26, 0xe8, 0x06 | ||
| 585 | }, | ||
| 586 | G89_CFB, | ||
| 587 | { | ||
| 588 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 589 | }, | ||
| 590 | { | ||
| 591 | 0x2e, 0x62, 0xb0, 0x2e, 0xc7, 0x87, 0x4b, 0x29, | ||
| 592 | 0x33, 0x16, 0x6b, 0xb4, 0xd6, 0x61, 0x66, 0xd9 | ||
| 593 | } | ||
| 594 | }, | ||
| 595 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 596 | 1037, | ||
| 597 | { | ||
| 598 | 0x3d, 0x0b, 0x69, 0xf7, 0xa8, 0xe4, 0xfc, 0x99, | ||
| 599 | 0x22, 0x2e, 0xee, 0xd1, 0x63, 0x12, 0xfe, 0xa8, | ||
| 600 | 0x9d, 0xcb, 0x6c, 0x4d, 0x48, 0x8c, 0xe8, 0xbd, | ||
| 601 | 0x8b, 0x60, 0xf1, 0xbf, 0x7b, 0xe3, 0x79, 0xd5, | ||
| 602 | 0x2b, 0x25, 0x97, 0x13, 0xef, 0x35, 0xda, 0xf4, | ||
| 603 | 0xbc, 0x77, 0xce, 0xea, 0xe9, 0x3f, 0xa4, 0xb6, | ||
| 604 | 0x01, 0xd5, 0x73, 0x29, 0x58, 0xda, 0xd7, 0x67, | ||
| 605 | 0x17, 0xac, 0xe4, 0x75, 0x2f, 0x57, 0x23, 0xac, | ||
| 606 | 0x96, 0x21, 0xc7, 0x62, 0x2d, 0xf7, 0x32, 0xb5, | ||
| 607 | 0x44, 0x5f, 0x72, 0xb1, 0x5f, 0xba, 0x1b, 0x1e, | ||
| 608 | 0xdb, 0x4a, 0x09, 0x8c, 0x92, 0x61, 0xa2, 0xb0, | ||
| 609 | 0x49, 0x68, 0xe5, 0xb3, 0xa2, 0x8f, 0x13, 0x4b, | ||
| 610 | 0xf5, 0x4d, 0x84, 0xda, 0xab, 0xa0, 0xb6, 0xd1, | ||
| 611 | 0x5a, 0x63, 0x19, 0xe8, 0xa2, 0x09, 0xf6, 0x76, | ||
| 612 | 0x6f, 0x9b, 0x48, 0x0a, 0x15, 0x5d, 0xb7, 0x20, | ||
| 613 | 0x21, 0x9a, 0x2e, 0xb9, 0x6d, 0xfa, 0x1e, 0xc2, | ||
| 614 | 0x0e, 0xef, 0x15, 0xab, 0x59, 0x01, 0xfe, 0x43, | ||
| 615 | 0x90, 0xf2, 0x62, 0xca, 0x4a, 0x9a, 0x48, 0x38, | ||
| 616 | 0xab, 0x6f, 0x9d, 0x21, 0xb3, 0xad, 0xa7, 0x60, | ||
| 617 | 0x46, 0xe3, 0xef, 0xd0, 0xe3, 0x1d, 0xc5, 0xe1, | ||
| 618 | 0xb8, 0xa1, 0xe2, 0x99, 0x20, 0xc5, 0x76, 0xcc, | ||
| 619 | 0xaa, 0x8a, 0xa9, 0x45, 0x55, 0xa0, 0x78, 0x00, | ||
| 620 | 0x64, 0xde, 0xcf, 0x5b, 0xdf, 0x26, 0x48, 0xcd, | ||
| 621 | 0xba, 0x8a, 0xb5, 0xfb, 0xfd, 0x4a, 0xd5, 0xc4, | ||
| 622 | 0xe0, 0x43, 0xa6, 0x71, 0x90, 0xa4, 0x8b, 0xca, | ||
| 623 | 0x2e, 0x88, 0x7b, 0xac, 0xb2, 0xdc, 0xf2, 0x01, | ||
| 624 | 0xcb, 0xda, 0x6e, 0x91, 0x27, 0x28, 0x44, 0x88, | ||
| 625 | 0x9a, 0xd2, 0x12, 0xf1, 0xa6, 0xf5, 0xb7, 0x61, | ||
| 626 | 0xce, 0x79, 0x62, 0x52, 0x3c, 0xe6, 0x14, 0x73, | ||
| 627 | 0xd1, 0x41, 0x92, 0x50, 0xbd, 0xdc, 0x3b, 0xd0, | ||
| 628 | 0xa7, 0x11, 0x8c, 0x3a, 0xe4, 0x2d, 0xf2, 0x52, | ||
| 629 | 0xd3, 0x2f, 0x7c, 0x8e, 0x54, 0x90, 0x4e, 0x23, | ||
| 630 | 0xae, 0xb3, 0xa0, 0xf3, 0x25, 0x7e, 0x66, 0xaa, | ||
| 631 | 0x0f, 0x6f, 0x81, 0x72, 0x77, 0xbb, 0xd3, 0x47, | ||
| 632 | 0xe8, 0x05, 0xff, 0xe1, 0x5b, 0xc9, 0x37, 0x50, | ||
| 633 | 0x33, 0x49, 0x17, 0xaf, 0xab, 0x1d, 0xe1, 0x15, | ||
| 634 | 0xf2, 0xe5, 0x98, 0x5e, 0x2d, 0x05, 0x1f, 0x0d, | ||
| 635 | 0x55, 0x97, 0xed, 0xff, 0x5e, 0xe0, 0x0f, 0xc3, | ||
| 636 | 0x9c, 0xbd, 0x82, 0xc2, 0x06, 0xbe, 0x45, 0x66, | ||
| 637 | 0xae, 0x33, 0xbe, 0x28, 0x48, 0xe9, 0x2d, 0x1a, | ||
| 638 | 0xe6, 0x65, 0x8e, 0xdf, 0x76, 0x03, 0x73, 0x4b, | ||
| 639 | 0xc0, 0x80, 0x71, 0xf9, 0xac, 0xba, 0xa0, 0xb0, | ||
| 640 | 0x19, 0x1a, 0x0a, 0xd4, 0x35, 0x12, 0x88, 0x76, | ||
| 641 | 0x05, 0x75, 0x8f, 0x7c, 0xb5, 0xf0, 0x19, 0x75, | ||
| 642 | 0x6d, 0x05, 0xcb, 0x0d, 0xbc, 0x8d, 0xe9, 0xf0, | ||
| 643 | 0xd4, 0xdb, 0x3c, 0x3c, 0x29, 0x8e, 0x2c, 0x32, | ||
| 644 | 0x1d, 0xf7, 0xb6, 0x49, 0xcf, 0xdb, 0x63, 0xee, | ||
| 645 | 0x3c, 0xfa, 0x33, 0x73, 0x6f, 0xe4, 0x97, 0x4e, | ||
| 646 | 0x2f, 0xc9, 0x4c, 0x5c, 0x65, 0xfe, 0xea, 0xfb, | ||
| 647 | 0xc6, 0xdd, 0xc1, 0x1c, 0x47, 0x3f, 0xf4, 0x50, | ||
| 648 | 0x2f, 0xde, 0x1b, 0x5b, 0x0b, 0x16, 0xca, 0xb6, | ||
| 649 | 0x46, 0x44, 0xf2, 0xc1, 0x0d, 0xa1, 0x1d, 0xa6, | ||
| 650 | 0xdb, 0xf0, 0x3d, 0xb1, 0x6c, 0x05, 0x31, 0x85, | ||
| 651 | 0x8e, 0x74, 0xae, 0xf2, 0x39, 0x26, 0xf7, 0xc1, | ||
| 652 | 0xe7, 0x4c, 0xdd, 0x9d, 0x40, 0xb8, 0xf3, 0xc5, | ||
| 653 | 0xc2, 0x16, 0x64, 0x6b, 0xaa, 0xdb, 0x4b, 0x82, | ||
| 654 | 0x5c, 0xd3, 0x02, 0xd3, 0x8f, 0x26, 0x79, 0x8d, | ||
| 655 | 0xb0, 0x78, 0x70, 0x19, 0x58, 0x0c, 0xb4, 0x31, | ||
| 656 | 0x88, 0x44, 0x1c, 0x91, 0x6f, 0xf4, 0x52, 0x39, | ||
| 657 | 0xa8, 0xf5, 0xc0, 0x1b, 0xfe, 0xf2, 0x0e, 0x4b, | ||
| 658 | 0xac, 0x0a, 0xc2, 0x7e, 0x9c, 0x9b, 0xeb, 0x5d, | ||
| 659 | 0x4e, 0x4f, 0x42, 0xd8, 0x71, 0x0a, 0x97, 0x27, | ||
| 660 | 0x03, 0x14, 0x96, 0xa6, 0x3d, 0x04, 0xea, 0x9f, | ||
| 661 | 0x14, 0x14, 0x27, 0x4c, 0xd9, 0xa2, 0x89, 0x5f, | ||
| 662 | 0x65, 0x4a, 0xe1, 0x9d, 0x2c, 0xb8, 0xf8, 0xd4, | ||
| 663 | 0x8f, 0x2a, 0x57, 0x36, 0xcc, 0x06, 0x9c, 0x2c, | ||
| 664 | 0xc5, 0x13, 0x16, 0xdf, 0xfc, 0xae, 0x22, 0x16, | ||
| 665 | 0xa8, 0x2b, 0x71, 0x6f, 0x1d, 0xb3, 0x47, 0x54, | ||
| 666 | 0x3f, 0x2d, 0x0a, 0x68, 0x9f, 0x2e, 0xf6, 0x90, | ||
| 667 | 0xd8, 0xa1, 0x21, 0x09, 0xd4, 0x97, 0xb9, 0x7b, | ||
| 668 | 0x7f, 0x9b, 0x6a, 0xed, 0xd1, 0xf0, 0xe3, 0xb6, | ||
| 669 | 0x28, 0xc7, 0x62, 0x82, 0x00, 0xc9, 0x38, 0xa1, | ||
| 670 | 0x82, 0x78, 0xce, 0x87, 0xc8, 0x53, 0xac, 0x4f, | ||
| 671 | 0x2e, 0x31, 0xb9, 0x50, 0x7f, 0x36, 0x00, 0x4a, | ||
| 672 | 0x32, 0xe6, 0xd8, 0xbb, 0x59, 0x45, 0x0e, 0x91, | ||
| 673 | 0x1b, 0x38, 0xa9, 0xbc, 0xb9, 0x5e, 0x6c, 0x6a, | ||
| 674 | 0x9c, 0x03, 0x01, 0x1c, 0xde, 0xe8, 0x1f, 0x1e, | ||
| 675 | 0xe3, 0xde, 0x25, 0xa2, 0x56, 0x79, 0xe1, 0xbd, | ||
| 676 | 0x58, 0xc4, 0x93, 0xe6, 0xd0, 0x8a, 0x4d, 0x08, | ||
| 677 | 0xab, 0xf7, 0xaa, 0xc3, 0x7d, 0xc1, 0xee, 0x68, | ||
| 678 | 0x37, 0xbc, 0x78, 0x0b, 0x19, 0x68, 0x2b, 0x2b, | ||
| 679 | 0x2e, 0x6d, 0xc4, 0x6f, 0xaa, 0x3b, 0xc6, 0x19, | ||
| 680 | 0xcb, 0xf1, 0x58, 0xb9, 0x60, 0x85, 0x45, 0xae, | ||
| 681 | 0x52, 0x97, 0xba, 0x24, 0x32, 0x13, 0x72, 0x16, | ||
| 682 | 0x6e, 0x7b, 0xc1, 0x98, 0xac, 0xb1, 0xed, 0xb4, | ||
| 683 | 0xcc, 0x6c, 0xcf, 0x45, 0xfc, 0x50, 0x89, 0x80, | ||
| 684 | 0x8e, 0x7a, 0xa4, 0xd3, 0x64, 0x50, 0x63, 0x37, | ||
| 685 | 0xc9, 0x6c, 0xf1, 0xc4, 0x3d, 0xfb, 0xde, 0x5a, | ||
| 686 | 0x5c, 0xa8, 0x21, 0x35, 0xe6, 0x2e, 0x8c, 0x2a, | ||
| 687 | 0x3c, 0x12, 0x17, 0x79, 0x9a, 0x0d, 0x2e, 0x79, | ||
| 688 | 0xeb, 0x67, 0x1f, 0x2b, 0xf8, 0x6e, 0xca, 0xc1, | ||
| 689 | 0xfa, 0x45, 0x18, 0x9e, 0xdf, 0x6a, 0xe6, 0xcb, | ||
| 690 | 0xe9, 0x5c, 0xc3, 0x09, 0xaf, 0x93, 0x58, 0x13, | ||
| 691 | 0xbf, 0x90, 0x84, 0x87, 0x75, 0xd6, 0x82, 0x28, | ||
| 692 | 0x8d, 0xe7, 0x2f, 0xa3, 0xfb, 0x97, 0x74, 0x2a, | ||
| 693 | 0x73, 0x04, 0x82, 0x06, 0x76, 0x69, 0xb1, 0x0b, | ||
| 694 | 0x19, 0xfc, 0xae, 0xb3, 0xdd, 0x2a, 0xe5, 0xc1, | ||
| 695 | 0x05, 0xd8, 0x80, 0x95, 0x22, 0x90, 0x71, 0xfc, | ||
| 696 | 0xc2, 0x92, 0x42, 0xfd, 0xf1, 0x70, 0xb4, 0x68, | ||
| 697 | 0x88, 0xa4, 0x9e, 0x0a, 0x24, 0x40, 0x13, 0xc8, | ||
| 698 | 0xa2, 0x56, 0x4f, 0x39, 0xe6, 0x06, 0xf1, 0xdc, | ||
| 699 | 0xf5, 0x13, 0x0e, 0xad, 0x9c, 0x8b, 0xaf, 0xe9, | ||
| 700 | 0xe3, 0x88, 0x72, 0xff, 0xa0, 0x6d, 0xda, 0x08, | ||
| 701 | 0x70, 0xb9, 0x2e, 0x83, 0xc5, 0xbb, 0x32, 0xa5, | ||
| 702 | 0x74, 0xc7, 0xfb, 0x7b, 0x76, 0xaf, 0x02, 0xbb, | ||
| 703 | 0x2b, 0xb8, 0x5e, 0x65, 0x02, 0xfe, 0x0e, 0xa0, | ||
| 704 | 0x99, 0xce, 0x01, 0x3b, 0x35, 0xe1, 0xb0, 0x22, | ||
| 705 | 0xe5, 0x94, 0xbd, 0xdd, 0x8e, 0xbb, 0xf6, 0x75, | ||
| 706 | 0xbf, 0xbf, 0xee, 0x7a, 0xb1, 0x58, 0xb4, 0x81, | ||
| 707 | 0xb8, 0x39, 0x3e, 0xb6, 0x1e, 0xde, 0xda, 0x1b, | ||
| 708 | 0xd5, 0xf7, 0xdd, 0x7d, 0x65, 0x9c, 0xaa, 0x56, | ||
| 709 | 0x93, 0xb8, 0xaf, 0x48, 0x53, 0xc7, 0x22, 0xe4, | ||
| 710 | 0x1c, 0xdf, 0xe9, 0x79, 0xb4, 0x20, 0x89, 0xcc, | ||
| 711 | 0x2a, 0x79, 0x2c, 0x09, 0xbe, 0x78, 0xcf, 0xcc, | ||
| 712 | 0xf2, 0x90, 0xd6, 0x65, 0xc5, 0x29, 0xfc, 0xda, | ||
| 713 | 0x69, 0xfc, 0xc0, 0xd6, 0x70, 0x99, 0x61, 0x3f, | ||
| 714 | 0x60, 0x02, 0xd8, 0x12, 0x22, 0xc8, 0x34, 0xc6, | ||
| 715 | 0x3b, 0xb3, 0xc2, 0x33, 0xa1, 0x5c, 0x8f, 0x4c, | ||
| 716 | 0xd1, 0x52, 0x72, 0xf2, 0x42, 0x05, 0x8e, 0x18, | ||
| 717 | 0x1f, 0x16, 0xda, 0xb8, 0x53, 0xa1, 0x5f, 0x01, | ||
| 718 | 0x32, 0x1b, 0x90, 0xb3, 0x53, 0x9b, 0xd0, 0x85, | ||
| 719 | 0x61, 0x2d, 0x17, 0xed, 0x0a, 0xa4, 0xa5, 0x27, | ||
| 720 | 0x09, 0x75, 0x7c, 0xbc, 0x30, 0xf7, 0x5e, 0x59, | ||
| 721 | 0x9a, 0x07, 0x96, 0x84, 0x28, 0x86, 0x4b, 0xa7, | ||
| 722 | 0x22, 0x35, 0x28, 0xc7, 0xed, 0x0d, 0xc3, 0xce, | ||
| 723 | 0x98, 0xcc, 0x2d, 0xec, 0xd4, 0x98, 0x09, 0x8e, | ||
| 724 | 0x52, 0x5f, 0x2b, 0x9a, 0x13, 0xbe, 0x99, 0x16, | ||
| 725 | 0x73, 0xd1, 0x1f, 0x81, 0xe5, 0xa2, 0x08, 0x78, | ||
| 726 | 0xcb, 0x0c, 0x20, 0xd4, 0xa5, 0xea, 0x4b, 0x5b, | ||
| 727 | 0x95, 0x5a, 0x92, 0x9a, 0x52 | ||
| 728 | }, | ||
| 729 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 730 | "testcnt2", | ||
| 731 | { | ||
| 732 | 0x1b, 0x5d, 0xdb, 0x77, 0xcf, 0xf9, 0xec, 0x95, | ||
| 733 | 0x5e, 0xcc, 0x67, 0x9f, 0x5d, 0x28, 0xad, 0x4a, | ||
| 734 | 0x27, 0xf4, 0x32, 0xc6, 0xb2, 0xcb, 0xb1, 0x45, | ||
| 735 | 0x6a, 0x88, 0x14, 0x0c, 0x9b, 0x9b, 0x5f, 0x48 | ||
| 736 | }, | ||
| 737 | G89_CNT, | ||
| 738 | { | ||
| 739 | 0x71, 0x58, 0x8c, 0xe1, 0x55, 0xf4, 0xf6, 0xb3 | ||
| 740 | }, | ||
| 741 | { | ||
| 742 | 0x8e, 0xcd, 0x8f, 0xc8, 0xac, 0xe1, 0x15, 0x48, | ||
| 743 | 0x2d, 0xae, 0x24, 0x8a, 0xc7, 0xfb, 0xba, 0x0f, | ||
| 744 | 0x1d, 0x8a, 0x95, 0xa2, 0x43, 0xef, 0xcb, 0xdc, | ||
| 745 | 0x59, 0x57, 0xa7, 0xc7, 0x0e, 0xe3, 0xe2, 0xb9, | ||
| 746 | 0x0d, 0x86, 0x29, 0x62, 0xcb, 0x83, 0x4d, 0x07, | ||
| 747 | 0x0c, 0x40, 0xd4, 0x7b, 0x2e, 0xca, 0xba, 0xbf, | ||
| 748 | 0x4a, 0x60, 0x3b, 0x31, 0x98, 0xc8, 0x88, 0x47, | ||
| 749 | 0xd9, 0x82, 0xab, 0xfc, 0x8f, 0x48, 0xe2, 0x46, | ||
| 750 | 0xab, 0xd3, 0xa1, 0xab, 0x8a, 0x05, 0x22, 0x8c, | ||
| 751 | 0xf4, 0xec, 0x9a, 0x1e, 0x76, 0xab, 0x1a, 0x60, | ||
| 752 | 0xd9, 0x25, 0x6b, 0xb8, 0x56, 0xe5, 0xb2, 0xea, | ||
| 753 | 0x10, 0xf3, 0x62, 0x04, 0x32, 0x5e, 0xaa, 0x3b, | ||
| 754 | 0x7b, 0x57, 0xbc, 0x3b, 0x8b, 0x43, 0x47, 0xf2, | ||
| 755 | 0xd5, 0x03, 0x7e, 0x51, 0x01, 0xff, 0x77, 0x28, | ||
| 756 | 0xca, 0x90, 0xa3, 0xfe, 0x7e, 0x2e, 0x70, 0x16, | ||
| 757 | 0x75, 0x18, 0x44, 0xf0, 0x1b, 0x85, 0x05, 0xea, | ||
| 758 | 0xe3, 0x21, 0xf7, 0x26, 0x86, 0x76, 0x3c, 0x67, | ||
| 759 | 0x9d, 0xfc, 0xbc, 0x10, 0x7f, 0x77, 0xe4, 0xed, | ||
| 760 | 0xd3, 0x12, 0xf8, 0x83, 0x00, 0x1f, 0x4b, 0x92, | ||
| 761 | 0x95, 0x92, 0x5c, 0xf3, 0x5a, 0xf3, 0xb7, 0xd0, | ||
| 762 | 0xa9, 0x5f, 0xf2, 0x18, 0xc4, 0x66, 0x62, 0xc1, | ||
| 763 | 0x84, 0x0e, 0x66, 0xe8, 0x80, 0x7d, 0x1f, 0xf0, | ||
| 764 | 0xba, 0x01, 0x9b, 0x71, 0xae, 0x93, 0xcc, 0x27, | ||
| 765 | 0x54, 0x34, 0x9a, 0xbd, 0xca, 0xee, 0x52, 0x09, | ||
| 766 | 0x92, 0x9d, 0xb0, 0xd5, 0xd9, 0xba, 0x2f, 0xb9, | ||
| 767 | 0x96, 0xdc, 0xfa, 0xbd, 0xce, 0xea, 0x1a, 0x7b, | ||
| 768 | 0x9a, 0x1d, 0x13, 0xa7, 0x11, 0xe2, 0x9a, 0x64, | ||
| 769 | 0xf6, 0xd3, 0xee, 0xc6, 0x33, 0xb7, 0x6e, 0xef, | ||
| 770 | 0x25, 0x9e, 0x1e, 0x7c, 0xe3, 0x1f, 0x2c, 0x6e, | ||
| 771 | 0xa9, 0xc0, 0xf8, 0xc1, 0xbf, 0x3b, 0xf8, 0x34, | ||
| 772 | 0x03, 0x9b, 0xa1, 0x40, 0x5b, 0x0c, 0x3c, 0x09, | ||
| 773 | 0x66, 0x9d, 0x63, 0xe2, 0xe2, 0x04, 0x8f, 0x06, | ||
| 774 | 0x84, 0x74, 0x68, 0xb2, 0x5c, 0x3b, 0x4c, 0xad, | ||
| 775 | 0x0b, 0x3f, 0x03, 0xb3, 0x07, 0x8a, 0x64, 0xa7, | ||
| 776 | 0x36, 0x56, 0x26, 0x39, 0x66, 0xda, 0xe9, 0x6d, | ||
| 777 | 0x1b, 0xd5, 0x88, 0xe8, 0x5c, 0xaf, 0x5a, 0x4c, | ||
| 778 | 0x49, 0xf7, 0xf5, 0xb7, 0x78, 0xf0, 0xde, 0xec, | ||
| 779 | 0xcd, 0x16, 0x23, 0x9e, 0x8c, 0x13, 0xbe, 0x6b, | ||
| 780 | 0x6f, 0x9b, 0x07, 0xe5, 0xbb, 0xcc, 0x3a, 0x1b, | ||
| 781 | 0x6f, 0x43, 0xdf, 0xff, 0x46, 0x2a, 0xae, 0x47, | ||
| 782 | 0x19, 0x18, 0x9a, 0x25, 0x09, 0xc9, 0x24, 0x40, | ||
| 783 | 0x0c, 0x4b, 0xa7, 0xda, 0x5e, 0x0d, 0xee, 0xfa, | ||
| 784 | 0x62, 0x45, 0x8e, 0xcc, 0x2f, 0x23, 0x08, 0x1d, | ||
| 785 | 0x92, 0xf0, 0xfe, 0x82, 0x0f, 0xd7, 0x11, 0x60, | ||
| 786 | 0x7e, 0x0b, 0x0b, 0x75, 0xf4, 0xf5, 0x3b, 0xc0, | ||
| 787 | 0xa4, 0xe8, 0x72, 0xa5, 0xb6, 0xfa, 0x5a, 0xad, | ||
| 788 | 0x5a, 0x4f, 0x39, 0xb5, 0xa2, 0x12, 0x96, 0x0a, | ||
| 789 | 0x32, 0x84, 0xb2, 0xa1, 0x06, 0x68, 0x56, 0x57, | ||
| 790 | 0x97, 0xa3, 0x7b, 0x22, 0x61, 0x76, 0x5d, 0x30, | ||
| 791 | 0x1a, 0x31, 0xab, 0x99, 0x06, 0xc5, 0x1a, 0x96, | ||
| 792 | 0xcf, 0xcf, 0x14, 0xff, 0xb2, 0xc4, 0xcc, 0x2b, | ||
| 793 | 0xbf, 0x0c, 0x9d, 0x91, 0x8f, 0x79, 0x5b, 0xbc, | ||
| 794 | 0xa9, 0x6b, 0x91, 0x6a, 0xb4, 0x93, 0x5c, 0x7b, | ||
| 795 | 0x5d, 0xc2, 0x8a, 0x75, 0xc0, 0xc1, 0x08, 0xfa, | ||
| 796 | 0x99, 0xf9, 0x4d, 0x5e, 0x0c, 0x06, 0x64, 0x60, | ||
| 797 | 0xa9, 0x01, 0x4a, 0x34, 0x0f, 0x33, 0x84, 0x95, | ||
| 798 | 0x69, 0x30, 0xc1, 0x1c, 0x36, 0xf8, 0xfc, 0x30, | ||
| 799 | 0x23, 0xb2, 0x71, 0xe5, 0x52, 0x4d, 0x12, 0x1a, | ||
| 800 | 0xc9, 0xbe, 0xee, 0xc9, 0xcb, 0x01, 0x85, 0xf3, | ||
| 801 | 0xdb, 0x30, 0xf9, 0x41, 0xa9, 0x40, 0xb0, 0x06, | ||
| 802 | 0x29, 0x77, 0xcd, 0xc5, 0xec, 0x58, 0x02, 0x48, | ||
| 803 | 0x83, 0x53, 0x44, 0x6a, 0xd2, 0xca, 0x05, 0xd8, | ||
| 804 | 0x5a, 0x08, 0xeb, 0xa9, 0xf4, 0xe6, 0xc7, 0x9d, | ||
| 805 | 0xd5, 0x7b, 0x74, 0x0b, 0x31, 0xb7, 0xa5, 0x57, | ||
| 806 | 0x7c, 0x7a, 0xfd, 0x1a, 0x0e, 0xd7, 0x97, 0x41, | ||
| 807 | 0xbf, 0xdd, 0xc6, 0x19, 0x6c, 0x77, 0x8c, 0x18, | ||
| 808 | 0x52, 0x57, 0x83, 0xba, 0x71, 0x25, 0xee, 0x39, | ||
| 809 | 0xbb, 0xe2, 0x43, 0xa0, 0x14, 0xdc, 0x0e, 0x84, | ||
| 810 | 0xb4, 0x2b, 0xde, 0x3e, 0xe5, 0x36, 0xb7, 0xa2, | ||
| 811 | 0x92, 0x98, 0x05, 0xb8, 0x96, 0xe5, 0xd0, 0x8c, | ||
| 812 | 0x08, 0x93, 0x35, 0xc2, 0x81, 0xe0, 0xfc, 0x59, | ||
| 813 | 0x71, 0xe2, 0x44, 0x49, 0x5d, 0xda, 0xfb, 0x9c, | ||
| 814 | 0xaa, 0x70, 0x9f, 0x43, 0xa8, 0xa5, 0xd9, 0x67, | ||
| 815 | 0xd9, 0x8f, 0xa3, 0x1e, 0xbe, 0x0e, 0xec, 0xdf, | ||
| 816 | 0x12, 0x2b, 0x6a, 0xe7, 0x1c, 0x12, 0x17, 0xe7, | ||
| 817 | 0xc4, 0x6d, 0x50, 0xc9, 0x52, 0x7a, 0xd5, 0xe8, | ||
| 818 | 0x7f, 0xbc, 0x07, 0x15, 0xac, 0xdb, 0x93, 0x66, | ||
| 819 | 0xb1, 0xf0, 0xa7, 0x7b, 0x2f, 0xe9, 0xec, 0xd0, | ||
| 820 | 0x47, 0x69, 0x59, 0x87, 0xf1, 0x4c, 0x3e, 0x4b, | ||
| 821 | 0x9b, 0x11, 0x79, 0x13, 0xe4, 0x96, 0xf6, 0x56, | ||
| 822 | 0x04, 0x6e, 0x0b, 0x33, 0xfc, 0x40, 0xf6, 0xc7, | ||
| 823 | 0xc1, 0x43, 0xb1, 0xbf, 0x0e, 0xb3, 0x87, 0xfd, | ||
| 824 | 0x0b, 0x1c, 0x63, 0x46, 0x3a, 0xd3, 0xa0, 0x17, | ||
| 825 | 0x59, 0x25, 0x94, 0x6c, 0x9c, 0x3d, 0x0c, 0x81, | ||
| 826 | 0xce, 0x82, 0x72, 0x42, 0x28, 0xf9, 0x37, 0x6a, | ||
| 827 | 0x6d, 0xe4, 0x12, 0xf4, 0x21, 0xaa, 0xf7, 0xfe, | ||
| 828 | 0x27, 0x55, 0x40, 0x1a, 0x14, 0xc3, 0x39, 0x5b, | ||
| 829 | 0xbf, 0x63, 0xc2, 0x5f, 0x10, 0x1f, 0x14, 0x25, | ||
| 830 | 0xd0, 0xce, 0xf3, 0x14, 0x48, 0x13, 0xa5, 0x0b, | ||
| 831 | 0x4d, 0x38, 0xcf, 0x0d, 0x34, 0xc0, 0x0a, 0x11, | ||
| 832 | 0xb4, 0xb5, 0x72, 0xc8, 0x4b, 0xc2, 0x6f, 0xe7, | ||
| 833 | 0x9d, 0x93, 0xf7, 0xdf, 0xb8, 0x43, 0x72, 0x7e, | ||
| 834 | 0xda, 0x3e, 0x20, 0x1f, 0xbc, 0x21, 0x2a, 0xce, | ||
| 835 | 0x00, 0xfa, 0x96, 0x9f, 0x3d, 0xe5, 0x88, 0x96, | ||
| 836 | 0xef, 0x29, 0x84, 0xdf, 0x6c, 0x1c, 0x96, 0xd8, | ||
| 837 | 0x58, 0x47, 0xaa, 0x92, 0xf3, 0x07, 0xe5, 0xfb, | ||
| 838 | 0xaf, 0xea, 0x95, 0x7e, 0x0b, 0x71, 0xcd, 0x81, | ||
| 839 | 0x0f, 0xb7, 0x0a, 0x59, 0x8f, 0x31, 0x4d, 0xd1, | ||
| 840 | 0xc3, 0xf3, 0x2f, 0x70, 0x5c, 0x59, 0x18, 0x97, | ||
| 841 | 0xaf, 0x77, 0x95, 0x5e, 0xaf, 0x40, 0x06, 0x12, | ||
| 842 | 0x81, 0x61, 0x86, 0x08, 0x4e, 0xbc, 0x89, 0x46, | ||
| 843 | 0x07, 0x2e, 0x5b, 0x10, 0xaa, 0x12, 0xf0, 0xa7, | ||
| 844 | 0x84, 0xe2, 0x9a, 0x08, 0xf1, 0xde, 0x59, 0xe3, | ||
| 845 | 0x0e, 0x47, 0x4b, 0xff, 0xc3, 0xc9, 0x18, 0xaf, | ||
| 846 | 0x95, 0x9c, 0x67, 0x2a, 0xde, 0x8a, 0x7a, 0x99, | ||
| 847 | 0x04, 0xc4, 0xb8, 0x97, 0x4c, 0x04, 0x29, 0x71, | ||
| 848 | 0x05, 0xda, 0xb3, 0xd6, 0xdb, 0x6c, 0x71, 0xe6, | ||
| 849 | 0xe8, 0x03, 0xbf, 0x94, 0x7d, 0xde, 0x3d, 0xc8, | ||
| 850 | 0x44, 0xfa, 0x7d, 0x62, 0xb4, 0x36, 0x03, 0xee, | ||
| 851 | 0x36, 0x52, 0x64, 0xb4, 0x85, 0x6d, 0xd5, 0x78, | ||
| 852 | 0xf0, 0x6f, 0x67, 0x2d, 0x0e, 0xe0, 0x2c, 0x88, | ||
| 853 | 0x9b, 0x55, 0x19, 0x29, 0x40, 0xf6, 0x8c, 0x12, | ||
| 854 | 0xbb, 0x2c, 0x83, 0x96, 0x40, 0xc0, 0x36, 0xf5, | ||
| 855 | 0x77, 0xff, 0x70, 0x8c, 0x75, 0x92, 0x0b, 0xad, | ||
| 856 | 0x05, 0x9b, 0x7e, 0xa2, 0xfc, 0xa9, 0xd1, 0x64, | ||
| 857 | 0x76, 0x82, 0x13, 0xba, 0x22, 0x5e, 0x33, 0x0e, | ||
| 858 | 0x26, 0x70, 0xa9, 0xbe, 0x74, 0x28, 0xf5, 0xe2, | ||
| 859 | 0xc4, 0x96, 0xee, 0x3a, 0xbc, 0x97, 0xa6, 0x2c, | ||
| 860 | 0x2a, 0xe0, 0x64, 0x8d, 0x35, 0xc6, 0x1a, 0xca, | ||
| 861 | 0xf4, 0x92, 0xfa, 0xc3, 0xf1, 0x1f, 0x98, 0xe4, | ||
| 862 | 0x43, 0x88, 0x69, 0x3a, 0x09, 0xbf, 0x63, 0xe5, | ||
| 863 | 0x96, 0x29, 0x0b, 0x9b, 0x62, 0x23, 0x14, 0x8a, | ||
| 864 | 0x95, 0xe4, 0x1c, 0x5c, 0x0a, 0xa9, 0xc5, 0xb9, | ||
| 865 | 0x6f, 0x4f, 0x2b, 0x25, 0x6f, 0x74, 0x1e, 0x18, | ||
| 866 | 0xd5, 0xfe, 0x27, 0x7d, 0x3f, 0x6e, 0x55, 0x2c, | ||
| 867 | 0x67, 0xe6, 0xde, 0xb5, 0xcc, 0xc0, 0x2d, 0xff, | ||
| 868 | 0xc4, 0xe4, 0x06, 0x21, 0xa5, 0xc8, 0xd3, 0xd6, | ||
| 869 | 0x6c, 0xa1, 0xc3, 0xfb, 0x88, 0x92, 0xb1, 0x1d, | ||
| 870 | 0x90, 0xe1, 0x35, 0x05, 0x9b, 0x29, 0x6d, 0xba, | ||
| 871 | 0xf1, 0xf4, 0x1e, 0x23, 0x2e | ||
| 872 | } | ||
| 873 | }, | ||
| 874 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 875 | 5242880+8, | ||
| 876 | { 0 }, | ||
| 877 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 878 | "test5Mcnt", | ||
| 879 | { | ||
| 880 | 0x07, 0x52, 0x65, 0xe7, 0xca, 0xa3, 0xca, 0x45, | ||
| 881 | 0xcf, 0x3a, 0x05, 0x1d, 0x38, 0x03, 0x53, 0x0c, | ||
| 882 | 0x22, 0x31, 0xba, 0x99, 0x4f, 0x9b, 0x6a, 0x1b, | ||
| 883 | 0x7e, 0x09, 0x9d, 0x4e, 0xb5, 0xc9, 0x84, 0x2e | ||
| 884 | }, | ||
| 885 | G89_CNT, | ||
| 886 | { | ||
| 887 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 888 | }, | ||
| 889 | { | ||
| 890 | 0x3d, 0x05, 0x07, 0x57, 0xc0, 0x75, 0x89, 0x97, | ||
| 891 | 0xd6, 0x94, 0x49, 0x11, 0x1d, 0xd0, 0x91, 0xee | ||
| 892 | } | ||
| 893 | }, | ||
| 894 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 895 | U64(4294967296)+16, | ||
| 896 | { 0 }, | ||
| 897 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 898 | "test4Gcnt", | ||
| 899 | { | ||
| 900 | 0x75, 0xa3, 0x3c, 0xae, 0x03, 0x6b, 0x10, 0xdb, | ||
| 901 | 0xc1, 0x56, 0x50, 0x89, 0x03, 0xd2, 0x9f, 0x91, | ||
| 902 | 0xee, 0xe8, 0x64, 0x1d, 0x43, 0xf2, 0x4e, 0xf8, | ||
| 903 | 0xf2, 0x6c, 0xed, 0xda, 0x8f, 0xe4, 0x88, 0xe9 | ||
| 904 | }, | ||
| 905 | G89_CNT, | ||
| 906 | { | ||
| 907 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 908 | }, | ||
| 909 | { | ||
| 910 | 0xfa, 0x6c, 0x96, 0x78, 0xe2, 0xf8, 0xdd, 0xaa, | ||
| 911 | 0x67, 0x5a, 0xc9, 0x5d, 0x57, 0xf1, 0xbd, 0x99 | ||
| 912 | } | ||
| 913 | }, | ||
| 914 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 915 | 1035, | ||
| 916 | { | ||
| 917 | 0xd6, 0xcf, 0x31, 0x96, 0x9c, 0xa1, 0xfb, 0xd6, | ||
| 918 | 0x8d, 0xa3, 0xdd, 0x01, 0xd9, 0x88, 0xc0, 0x2f, | ||
| 919 | 0xbc, 0x46, 0xc7, 0x3a, 0xe4, 0x21, 0x86, 0x96, | ||
| 920 | 0x8d, 0xe2, 0xca, 0xb6, 0x37, 0xa2, 0xe1, 0xa8, | ||
| 921 | 0x7e, 0xa7, 0x79, 0x2e, 0xa4, 0x56, 0x75, 0x7f, | ||
| 922 | 0x3e, 0x55, 0x8b, 0x43, 0xae, 0x65, 0xdf, 0xaa, | ||
| 923 | 0x42, 0xb6, 0x00, 0xa6, 0x61, 0x03, 0x0d, 0xd3, | ||
| 924 | 0x41, 0x02, 0x27, 0x23, 0x95, 0x79, 0x9b, 0x34, | ||
| 925 | 0x81, 0xa9, 0x86, 0xb5, 0xa7, 0x90, 0xe2, 0xae, | ||
| 926 | 0xc4, 0x2f, 0xc3, 0x8e, 0x32, 0x56, 0x13, 0xfa, | ||
| 927 | 0x4d, 0x4e, 0x9f, 0x15, 0x75, 0x7e, 0x74, 0xdc, | ||
| 928 | 0x32, 0x2d, 0xee, 0x4d, 0x67, 0x70, 0x9f, 0x62, | ||
| 929 | 0xb9, 0xc4, 0xdb, 0x24, 0x84, 0xcc, 0x16, 0x7b, | ||
| 930 | 0xda, 0x22, 0xf7, 0xc5, 0xf3, 0x93, 0x35, 0x73, | ||
| 931 | 0xc6, 0x03, 0x1c, 0x77, 0xa5, 0xf2, 0x76, 0x56, | ||
| 932 | 0xb4, 0x95, 0xd4, 0x7e, 0x0d, 0x20, 0xc6, 0x6e, | ||
| 933 | 0xee, 0x8f, 0x25, 0x48, 0xff, 0x7e, 0x01, 0x3a, | ||
| 934 | 0xb4, 0x1f, 0xaa, 0x35, 0xc0, 0x33, 0x58, 0x9c, | ||
| 935 | 0xb5, 0xba, 0x65, 0x4b, 0xd3, 0x51, 0x14, 0xec, | ||
| 936 | 0x61, 0xce, 0xe4, 0xba, 0x49, 0xba, 0x39, 0x32, | ||
| 937 | 0xab, 0xce, 0x81, 0x72, 0xce, 0xab, 0xed, 0xd4, | ||
| 938 | 0xd2, 0x19, 0x87, 0x85, 0x92, 0xfa, 0x64, 0x34, | ||
| 939 | 0xd8, 0x86, 0xf4, 0x8a, 0x08, 0x3c, 0xde, 0xee, | ||
| 940 | 0x97, 0x92, 0x92, 0x69, 0xba, 0x9b, 0x5f, 0x7a, | ||
| 941 | 0x03, 0xc1, 0x5d, 0x43, 0x02, 0x8c, 0xbe, 0xd2, | ||
| 942 | 0x46, 0x72, 0x81, 0x40, 0x7d, 0x68, 0x98, 0x45, | ||
| 943 | 0x0b, 0x54, 0x27, 0x1c, 0xaf, 0x80, 0x42, 0xe4, | ||
| 944 | 0xd5, 0xd4, 0xe4, 0xa2, 0x98, 0x07, 0x8f, 0x03, | ||
| 945 | 0xf5, 0x2c, 0x8c, 0x88, 0xca, 0x5a, 0xde, 0xe4, | ||
| 946 | 0x9f, 0xb1, 0x5f, 0x82, 0xff, 0x20, 0x67, 0x52, | ||
| 947 | 0x85, 0x84, 0x4f, 0xc8, 0xfe, 0xa7, 0x9e, 0xae, | ||
| 948 | 0x1c, 0xfa, 0xb8, 0x75, 0xd3, 0xf7, 0x9f, 0x0d, | ||
| 949 | 0xda, 0x2d, 0xe6, 0xcc, 0x86, 0x6b, 0xa4, 0x14, | ||
| 950 | 0x65, 0xc3, 0xf9, 0x15, 0xbc, 0x87, 0xf5, 0xae, | ||
| 951 | 0x8c, 0x10, 0xd4, 0xce, 0x5b, 0x9c, 0xe2, 0xdd, | ||
| 952 | 0x42, 0x03, 0x09, 0x87, 0x47, 0xed, 0x5d, 0xd0, | ||
| 953 | 0x7a, 0x69, 0x4c, 0xfa, 0x43, 0x7d, 0xbf, 0x07, | ||
| 954 | 0x85, 0x6a, 0xee, 0x68, 0xe6, 0x7a, 0x57, 0xb2, | ||
| 955 | 0x20, 0x8d, 0x80, 0xf2, 0x91, 0x6f, 0x5c, 0x07, | ||
| 956 | 0x8c, 0xe4, 0x6a, 0x49, 0x90, 0x85, 0x8b, 0x77, | ||
| 957 | 0x29, 0x56, 0x1c, 0x5e, 0xa9, 0x3f, 0xab, 0x8b, | ||
| 958 | 0x79, 0xa3, 0x6f, 0x6b, 0x34, 0xcb, 0x61, 0xf6, | ||
| 959 | 0xe6, 0x92, 0xd1, 0x48, 0x9e, 0x11, 0xa2, 0x82, | ||
| 960 | 0xc0, 0x4e, 0x23, 0xd2, 0x15, 0x0d, 0x8d, 0xff, | ||
| 961 | 0xfa, 0x17, 0x9d, 0x81, 0xb8, 0xbc, 0xd7, 0x5b, | ||
| 962 | 0x08, 0x81, 0x20, 0x40, 0xc0, 0x3c, 0x06, 0x8b, | ||
| 963 | 0x1a, 0x88, 0x0b, 0x4b, 0x7b, 0x31, 0xf5, 0xd4, | ||
| 964 | 0x4e, 0x09, 0xd1, 0x4d, 0x0d, 0x7f, 0x45, 0xd1, | ||
| 965 | 0x09, 0x35, 0xba, 0xce, 0x65, 0xdd, 0xf2, 0xb8, | ||
| 966 | 0xfb, 0x7a, 0xbc, 0xc4, 0x4b, 0xc8, 0x75, 0xda, | ||
| 967 | 0x6b, 0xce, 0x3d, 0xe8, 0x94, 0xcc, 0x23, 0x6f, | ||
| 968 | 0xb0, 0x3b, 0x4f, 0x7d, 0x07, 0xb9, 0x0f, 0x62, | ||
| 969 | 0x92, 0x7e, 0xda, 0x70, 0x50, 0xce, 0xd3, 0x28, | ||
| 970 | 0x12, 0x11, 0x00, 0xeb, 0x8d, 0x63, 0x70, 0x78, | ||
| 971 | 0xa8, 0x7b, 0x76, 0xab, 0xc6, 0x40, 0xc0, 0x4e, | ||
| 972 | 0x80, 0xdd, 0xf0, 0xfe, 0x83, 0x72, 0x56, 0x4c, | ||
| 973 | 0x09, 0x4c, 0xf1, 0x72, 0x72, 0x86, 0x26, 0x31, | ||
| 974 | 0xc3, 0xc2, 0xdc, 0x8e, 0xc7, 0xf4, 0x35, 0xec, | ||
| 975 | 0x17, 0x06, 0x63, 0x47, 0x49, 0x88, 0x47, 0xaf, | ||
| 976 | 0xb3, 0x38, 0x4f, 0x7e, 0x44, 0x95, 0xb5, 0xbb, | ||
| 977 | 0x1d, 0xbd, 0x5a, 0x91, 0x5b, 0xd0, 0x1a, 0xdf, | ||
| 978 | 0x0d, 0x0b, 0x50, 0xd8, 0xe2, 0x0e, 0xc5, 0x00, | ||
| 979 | 0x2d, 0x5b, 0x29, 0x19, 0xaa, 0x2b, 0x64, 0xc5, | ||
| 980 | 0x40, 0x31, 0x48, 0x11, 0xbc, 0x04, 0xd1, 0xcf, | ||
| 981 | 0x6d, 0xf9, 0xa5, 0x2f, 0x4a, 0xc9, 0x82, 0xfa, | ||
| 982 | 0x59, 0xe1, 0xfc, 0xab, 0x1c, 0x33, 0x26, 0x0a, | ||
| 983 | 0x5f, 0xef, 0xf2, 0x06, 0xd8, 0xd3, 0x7e, 0x16, | ||
| 984 | 0x58, 0x16, 0x78, 0x73, 0xae, 0xba, 0xeb, 0xe5, | ||
| 985 | 0x3d, 0xb2, 0x0a, 0xb3, 0x32, 0x2d, 0x14, 0xa4, | ||
| 986 | 0xfa, 0x3f, 0x1f, 0x43, 0xf9, 0x7b, 0xa9, 0x43, | ||
| 987 | 0x98, 0x18, 0x94, 0x07, 0x07, 0xe5, 0x19, 0x34, | ||
| 988 | 0xa8, 0x16, 0x5f, 0x71, 0x67, 0xaa, 0x29, 0xe5, | ||
| 989 | 0xfa, 0xf0, 0x83, 0x06, 0x1d, 0x9d, 0xfc, 0xfe, | ||
| 990 | 0xfe, 0x8c, 0xb5, 0xb2, 0xa9, 0xe7, 0xa0, 0x40, | ||
| 991 | 0x60, 0xb6, 0x71, 0x9e, 0xab, 0x5b, 0x83, 0xb9, | ||
| 992 | 0x0c, 0x2b, 0x58, 0x23, 0x80, 0x09, 0x9e, 0x5d, | ||
| 993 | 0x94, 0x7d, 0x40, 0x76, 0xa9, 0x16, 0x96, 0x9e, | ||
| 994 | 0x83, 0xe0, 0x0d, 0xec, 0xa0, 0xec, 0x76, 0x2a, | ||
| 995 | 0xb7, 0xa0, 0xff, 0xb8, 0x50, 0x4c, 0x5b, 0xc6, | ||
| 996 | 0x8b, 0x0a, 0x65, 0x2e, 0xfe, 0xb4, 0x40, 0x9a, | ||
| 997 | 0x01, 0xd8, 0xc6, 0xa3, 0xab, 0x99, 0xa2, 0xc5, | ||
| 998 | 0x0c, 0x08, 0xc4, 0xb7, 0xee, 0x4d, 0x1d, 0xc4, | ||
| 999 | 0x08, 0x15, 0xd0, 0xdb, 0xaa, 0x63, 0x4f, 0x31, | ||
| 1000 | 0xeb, 0x14, 0x97, 0x43, 0xbd, 0xc1, 0x94, 0x08, | ||
| 1001 | 0xe6, 0xde, 0x43, 0x9f, 0x95, 0x0b, 0x96, 0x7e, | ||
| 1002 | 0x7f, 0x3c, 0x68, 0xba, 0x6f, 0xc4, 0xc9, 0x35, | ||
| 1003 | 0x2b, 0xc4, 0x0e, 0xda, 0x1f, 0x91, 0x68, 0x64, | ||
| 1004 | 0x63, 0x34, 0x73, 0xbe, 0x57, 0x75, 0xb9, 0xed, | ||
| 1005 | 0xf7, 0x2d, 0x3b, 0x05, 0x21, 0x93, 0x28, 0x48, | ||
| 1006 | 0x96, 0x95, 0x97, 0xa0, 0xd2, 0x7d, 0x78, 0xbb, | ||
| 1007 | 0x6a, 0x49, 0x8f, 0x76, 0x55, 0x74, 0x63, 0xb9, | ||
| 1008 | 0xc5, 0x36, 0x12, 0x25, 0xbf, 0x03, 0x82, 0x8f, | ||
| 1009 | 0xf0, 0xf6, 0x80, 0xbb, 0x33, 0xb4, 0xf4, 0x17, | ||
| 1010 | 0x27, 0x1c, 0xf3, 0x4c, 0x10, 0xa3, 0xe4, 0xd1, | ||
| 1011 | 0x55, 0xd9, 0x68, 0x21, 0x4e, 0x5a, 0x83, 0x67, | ||
| 1012 | 0xbf, 0xf8, 0x3c, 0x7d, 0x4e, 0x62, 0xd3, 0x28, | ||
| 1013 | 0xa7, 0x26, 0x6f, 0xe9, 0xee, 0xc2, 0x0b, 0x2d, | ||
| 1014 | 0x03, 0x84, 0xb1, 0xff, 0xd6, 0x68, 0x1f, 0xb6, | ||
| 1015 | 0xf2, 0xe4, 0x0f, 0xda, 0x2d, 0xee, 0x5f, 0x6e, | ||
| 1016 | 0x21, 0xc8, 0xe1, 0xfc, 0xad, 0x6b, 0x0e, 0x04, | ||
| 1017 | 0x7d, 0xaf, 0xc2, 0x3b, 0xa5, 0x68, 0x9b, 0x0c, | ||
| 1018 | 0xf3, 0x56, 0xf3, 0xda, 0x8d, 0xc8, 0x7d, 0x39, | ||
| 1019 | 0xdc, 0xd5, 0x99, 0xc6, 0x01, 0x10, 0xce, 0x42, | ||
| 1020 | 0x1b, 0xac, 0x48, 0xdc, 0x97, 0x78, 0x0a, 0xec, | ||
| 1021 | 0xb3, 0x8f, 0x47, 0x35, 0xa3, 0x6a, 0x64, 0xb2, | ||
| 1022 | 0x8e, 0x63, 0x69, 0x22, 0x66, 0xae, 0x2e, 0xe0, | ||
| 1023 | 0x88, 0xf9, 0x40, 0x3c, 0xc9, 0xa2, 0x57, 0x61, | ||
| 1024 | 0xf6, 0xad, 0xf0, 0xdc, 0x90, 0x56, 0x3f, 0x06, | ||
| 1025 | 0x9b, 0x7d, 0xbd, 0xc2, 0x81, 0x02, 0xab, 0xb8, | ||
| 1026 | 0x15, 0x09, 0x88, 0x4a, 0xff, 0x2f, 0x31, 0xbf, | ||
| 1027 | 0x5e, 0xfa, 0x6a, 0x7e, 0xf6, 0xc5, 0xa7, 0xf7, | ||
| 1028 | 0xd5, 0xab, 0x55, 0xac, 0xae, 0x0d, 0x8c, 0x8d, | ||
| 1029 | 0x7f, 0x4b, 0x25, 0xbb, 0x32, 0xff, 0x11, 0x33, | ||
| 1030 | 0x2e, 0x37, 0x37, 0x69, 0x96, 0x15, 0x17, 0xb1, | ||
| 1031 | 0x17, 0x49, 0xe0, 0x9a, 0x9c, 0xd9, 0x5b, 0x8d, | ||
| 1032 | 0x58, 0xa3, 0x1d, 0x92, 0x87, 0xf8, 0x80, 0xb9, | ||
| 1033 | 0xbd, 0x5a, 0xec, 0x40, 0xe1, 0x00, 0x33, 0x60, | ||
| 1034 | 0xe4, 0x86, 0x16, 0x6d, 0x61, 0x81, 0xf2, 0x28, | ||
| 1035 | 0x6a, 0xa7, 0xce, 0x3f, 0x95, 0xae, 0x43, 0xca, | ||
| 1036 | 0xe1, 0x3f, 0x81, 0x74, 0x7e, 0x1c, 0x47, 0x17, | ||
| 1037 | 0x95, 0xc6, 0x60, 0xda, 0x74, 0x77, 0xd9, 0x9f, | ||
| 1038 | 0xfa, 0x92, 0xb4, 0xbe, 0xe1, 0x23, 0x98, 0x18, | ||
| 1039 | 0x95, 0x63, 0x03, 0x13, 0x4c, 0x1a, 0x2d, 0x41, | ||
| 1040 | 0xcd, 0xe4, 0x84, 0xf7, 0xe6, 0x38, 0xef, 0xff, | ||
| 1041 | 0x95, 0xb2, 0xe8, 0x7c, 0x8f, 0x58, 0xb5, 0xb5, | ||
| 1042 | 0xed, 0x27, 0x7f, 0x3c, 0x18, 0xab, 0xbe, 0x7f, | ||
| 1043 | 0x4f, 0xe2, 0x35, 0x15, 0x71, 0xb7, 0x6f, 0x85, | ||
| 1044 | 0x38, 0x9b, 0x88, 0xf6, 0x9c, 0x8d, 0x43, 0xb5, | ||
| 1045 | 0x58, 0x9e, 0xf2, 0xd1, 0x96, 0xbe, 0xb7, 0xad, | ||
| 1046 | 0x1a, 0xa0, 0x98 | ||
| 1047 | }, | ||
| 1048 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1049 | "testimit2", | ||
| 1050 | { | ||
| 1051 | 0x80, 0xd9, 0xa0, 0xdc, 0x21, 0xf9, 0x30, 0x40, | ||
| 1052 | 0x75, 0xfe, 0x49, 0x1b, 0x9e, 0x71, 0x90, 0x91, | ||
| 1053 | 0x78, 0x88, 0x21, 0x60, 0x39, 0xe7, 0xc9, 0x2b, | ||
| 1054 | 0xfb, 0x55, 0x1d, 0xf4, 0xdd, 0x2b, 0x0a, 0x01 | ||
| 1055 | }, | ||
| 1056 | G89_IMIT, | ||
| 1057 | { 0 }, | ||
| 1058 | { | ||
| 1059 | 0x90, 0xf2, 0x11, 0x9a | ||
| 1060 | } | ||
| 1061 | }, | ||
| 1062 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1063 | 10, | ||
| 1064 | { | ||
| 1065 | 0x1d, 0xeb, 0xe6, 0x79, 0x0a, 0x59, 0x00, 0xe6, | ||
| 1066 | 0x8e, 0x5c | ||
| 1067 | }, | ||
| 1068 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1069 | "testimit3", | ||
| 1070 | { | ||
| 1071 | 0xa9, 0xb6, 0x37, 0xcc, 0x6d, 0x9b, 0x2f, 0x25, | ||
| 1072 | 0xb0, 0xdf, 0x47, 0x04, 0x50, 0x68, 0xb0, 0x27, | ||
| 1073 | 0x41, 0x27, 0x58, 0x6a, 0xbd, 0x0a, 0x6e, 0x50, | ||
| 1074 | 0x2f, 0xc6, 0xfc, 0xc0, 0x3e, 0x29, 0x42, 0xa5 | ||
| 1075 | }, | ||
| 1076 | G89_IMIT, | ||
| 1077 | { 0 }, | ||
| 1078 | { | ||
| 1079 | 0x31, 0x7c, 0x16, 0xe4 | ||
| 1080 | } | ||
| 1081 | }, | ||
| 1082 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1083 | 6, | ||
| 1084 | { | ||
| 1085 | 0xef, 0x06, 0x8f, 0x14, 0xc9, 0x04 | ||
| 1086 | }, | ||
| 1087 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1088 | "testimit4", | ||
| 1089 | { | ||
| 1090 | 0xb0, 0x6c, 0x48, 0x23, 0x0a, 0x6e, 0xf4, 0xec, | ||
| 1091 | 0x27, 0x98, 0x01, 0x23, 0xa7, 0xd8, 0xbf, 0x60, | ||
| 1092 | 0x89, 0xef, 0xad, 0xe8, 0x8f, 0x79, 0x14, 0x8c, | ||
| 1093 | 0x18, 0x5c, 0x9a, 0xda, 0xef, 0x0b, 0xdd, 0xa0 | ||
| 1094 | }, | ||
| 1095 | G89_IMIT, | ||
| 1096 | { 0 }, | ||
| 1097 | { | ||
| 1098 | 0xe9, 0x72, 0xae, 0xbf | ||
| 1099 | } | ||
| 1100 | }, | ||
| 1101 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1102 | 16, | ||
| 1103 | { | ||
| 1104 | 0x02, 0xf8, 0xec, 0x2b, 0x4d, 0x1f, 0xbc, 0x7c, | ||
| 1105 | 0x6e, 0x47, 0xe3, 0x87, 0x22, 0x75, 0x41, 0xa7 | ||
| 1106 | }, | ||
| 1107 | "id-Gost28147-89-CryptoPro-B-ParamSet", | ||
| 1108 | "testimit5", | ||
| 1109 | { | ||
| 1110 | 0x33, 0xd3, 0xef, 0x01, 0x19, 0x95, 0x0e, 0x15, | ||
| 1111 | 0xa1, 0x69, 0x75, 0xae, 0x56, 0x27, 0x17, 0x79, | ||
| 1112 | 0x63, 0x47, 0xab, 0x62, 0x9d, 0x4a, 0xf0, 0x34, | ||
| 1113 | 0xd3, 0x1e, 0x69, 0x74, 0xec, 0x31, 0x48, 0xfc | ||
| 1114 | }, | ||
| 1115 | G89_IMIT, | ||
| 1116 | { 0 }, | ||
| 1117 | { | ||
| 1118 | 0xf5, 0x55, 0x1f, 0x28 | ||
| 1119 | } | ||
| 1120 | }, | ||
| 1121 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1122 | 8, | ||
| 1123 | { | ||
| 1124 | 0xf3, 0xb2, 0x29, 0xd2, 0x7a, 0x37, 0x03, 0x12 | ||
| 1125 | }, | ||
| 1126 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1127 | "testimit6", | ||
| 1128 | { | ||
| 1129 | 0x42, 0x35, 0x81, 0x91, 0x0b, 0xa9, 0x99, 0xff, | ||
| 1130 | 0xd9, 0x43, 0xf8, 0xc6, 0x19, 0x55, 0x1f, 0x2f, | ||
| 1131 | 0x2d, 0x45, 0x40, 0x20, 0x1e, 0x1d, 0x32, 0x7a, | ||
| 1132 | 0xb1, 0x07, 0x6b, 0x4f, 0x45, 0x90, 0xd9, 0x80 | ||
| 1133 | }, | ||
| 1134 | G89_IMIT, | ||
| 1135 | { 0 }, | ||
| 1136 | { | ||
| 1137 | 0x6e, 0x15, 0xfa, 0xe8 | ||
| 1138 | } | ||
| 1139 | }, | ||
| 1140 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1141 | 0, | ||
| 1142 | { | ||
| 1143 | 0 | ||
| 1144 | }, | ||
| 1145 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1146 | "testimit7", | ||
| 1147 | { | ||
| 1148 | 0x26, 0xcb, 0xb9, 0xf0, 0x0c, 0x62, 0x9f, 0xaa, | ||
| 1149 | 0x4a, 0x1d, 0xb6, 0x30, 0x09, 0x01, 0x56, 0x89, | ||
| 1150 | 0x66, 0xd4, 0xe4, 0x0e, 0xfe, 0xf6, 0x10, 0x6b, | ||
| 1151 | 0x6c, 0xe8, 0x04, 0x3a, 0xe3, 0x61, 0x4b, 0x19 | ||
| 1152 | }, | ||
| 1153 | G89_IMIT, | ||
| 1154 | { 0 }, | ||
| 1155 | { | ||
| 1156 | 0x00, 0x00, 0x00, 0x00 | ||
| 1157 | } | ||
| 1158 | }, | ||
| 1159 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1160 | 5242880, | ||
| 1161 | { 0 }, | ||
| 1162 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1163 | "test5Mimit", | ||
| 1164 | { | ||
| 1165 | 0xaa, 0x85, 0x84, 0xcd, 0x65, 0x28, 0xe1, 0xdb, | ||
| 1166 | 0xb8, 0x20, 0x19, 0x43, 0xe0, 0x36, 0x35, 0x10, | ||
| 1167 | 0x19, 0xc3, 0x70, 0x5b, 0x27, 0xc1, 0x9d, 0x84, | ||
| 1168 | 0x75, 0xa3, 0xc6, 0x49, 0x46, 0x8f, 0x7c, 0x4e | ||
| 1169 | }, | ||
| 1170 | G89_IMIT, | ||
| 1171 | { 0 }, | ||
| 1172 | { | ||
| 1173 | 0x2a, 0xe6, 0x23, 0xc6 | ||
| 1174 | } | ||
| 1175 | }, | ||
| 1176 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1177 | 3221225472U + 16, | ||
| 1178 | { 0 }, | ||
| 1179 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1180 | "test3Gimit1", | ||
| 1181 | { | ||
| 1182 | 0xd5, 0xda, 0xfe, 0x06, 0x60, 0xdc, 0xf0, 0xb3, | ||
| 1183 | 0x49, 0x5a, 0x02, 0x59, 0xc8, 0x2e, 0x4a, 0x2b, | ||
| 1184 | 0xcc, 0x9b, 0x98, 0x04, 0xb7, 0xf2, 0x78, 0xb7, | ||
| 1185 | 0xce, 0xa3, 0xf2, 0xdb, 0x9e, 0xa8, 0x49, 0x1d | ||
| 1186 | }, | ||
| 1187 | G89_IMIT, | ||
| 1188 | { 0 }, | ||
| 1189 | { | ||
| 1190 | 0xcc, 0x46, 0x67, 0xe4 | ||
| 1191 | } | ||
| 1192 | }, | ||
| 1193 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1194 | U64(4)*1024*1024*1024, | ||
| 1195 | { 0 }, | ||
| 1196 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1197 | "test4Gimit3", | ||
| 1198 | { | ||
| 1199 | 0x0d, 0xf1, 0xa8, 0x7f, 0x57, 0x03, 0x44, 0xcc, | ||
| 1200 | 0xdb, 0x20, 0xde, 0xed, 0x85, 0x50, 0x38, 0xda, | ||
| 1201 | 0xc9, 0x44, 0xec, 0x2c, 0x0d, 0x66, 0xb7, 0xdc, | ||
| 1202 | 0x17, 0x14, 0x55, 0x95, 0x33, 0x6e, 0x43, 0x3e | ||
| 1203 | }, | ||
| 1204 | G89_IMIT, | ||
| 1205 | { 0 }, | ||
| 1206 | { | ||
| 1207 | 0xb7, 0x21, 0x2e, 0x48 | ||
| 1208 | } | ||
| 1209 | }, | ||
| 1210 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1211 | U64(4)*1024*1024*1024+4, | ||
| 1212 | { 0 }, | ||
| 1213 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1214 | "test4Gimit1", | ||
| 1215 | { | ||
| 1216 | 0x0c, 0xf3, 0xe9, 0xb0, 0x28, 0x3b, 0x9f, 0x8b, | ||
| 1217 | 0xe3, 0x82, 0xb9, 0xa2, 0xa6, 0xbd, 0x80, 0xd2, | ||
| 1218 | 0xcd, 0xfa, 0x3f, 0xf7, 0x90, 0xa7, 0x55, 0x06, | ||
| 1219 | 0x9b, 0x7a, 0x58, 0xee, 0xe7, 0xf1, 0x9d, 0xbe | ||
| 1220 | }, | ||
| 1221 | G89_IMIT, | ||
| 1222 | { 0 }, | ||
| 1223 | { | ||
| 1224 | 0xda, 0x15, 0x10, 0x73 | ||
| 1225 | } | ||
| 1226 | }, | ||
| 1227 | { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */ | ||
| 1228 | U64(4)*1024*1024*1024+10, | ||
| 1229 | { 0 }, | ||
| 1230 | "id-Gost28147-89-CryptoPro-A-ParamSet", | ||
| 1231 | "test4Gimit2", | ||
| 1232 | { | ||
| 1233 | 0x97, 0x1a, 0x42, 0x22, 0xfa, 0x07, 0xb2, 0xca, | ||
| 1234 | 0xf9, 0xd2, 0x34, 0x5a, 0x92, 0xb1, 0x1f, 0x6b, | ||
| 1235 | 0x53, 0xf8, 0xaf, 0xed, 0x9a, 0x73, 0xc4, 0x38, | ||
| 1236 | 0xd7, 0x7d, 0x25, 0x81, 0x00, 0x0d, 0xd4, 0x29 | ||
| 1237 | }, | ||
| 1238 | G89_IMIT, | ||
| 1239 | { 0 }, | ||
| 1240 | { | ||
| 1241 | 0x52, 0xaa, 0x22, 0xb4 | ||
| 1242 | } | ||
| 1243 | } | ||
| 1244 | }; | ||
| 1245 | |||
| 1246 | /* const */ unsigned char bZB[40*1024*1024]; | ||
| 1247 | unsigned char bTS[40*1024*1024]; | ||
| 1248 | |||
| 1249 | int main(int argc, char *argv[]) | ||
| 1250 | { | ||
| 1251 | unsigned int t; | ||
| 1252 | uint64_t ullMaxLen = 6*1000*1000; | ||
| 1253 | int ignore = 0; | ||
| 1254 | EVP_MD_CTX mctx; | ||
| 1255 | EVP_CIPHER_CTX ectx; | ||
| 1256 | EVP_PKEY *mac_key; | ||
| 1257 | unsigned char bDerive[EVP_MAX_KEY_LENGTH]; | ||
| 1258 | unsigned char bTest[G89_MAX_TC_LEN]; | ||
| 1259 | unsigned char bTest1[G89_MAX_TC_LEN]; | ||
| 1260 | uint64_t ullLeft; | ||
| 1261 | unsigned int mdl = 0; | ||
| 1262 | int enlu = 0; | ||
| 1263 | int enlf = 0; | ||
| 1264 | size_t siglen; | ||
| 1265 | size_t l = 0; | ||
| 1266 | BIO *bio_err; | ||
| 1267 | const EVP_MD *md_gost94 = NULL; | ||
| 1268 | const EVP_CIPHER *cp_g89ecb = NULL; | ||
| 1269 | const EVP_CIPHER *cp_g89cfb = NULL; | ||
| 1270 | const EVP_CIPHER *cp_g89cnt = NULL; | ||
| 1271 | const EVP_CIPHER *ctype = NULL; | ||
| 1272 | const EVP_MD *md_g89imit = NULL; | ||
| 1273 | |||
| 1274 | printf("Testing GOST 28147-89 "); | ||
| 1275 | |||
| 1276 | if(1 < argc) { | ||
| 1277 | if(1 != sscanf(argv[1], "%" SCNu64, &ullMaxLen) || | ||
| 1278 | ( 2 < argc ? | ||
| 1279 | 1 != sscanf(argv[2], "%d", &ignore) : 0)) { | ||
| 1280 | fflush(NULL); | ||
| 1281 | fprintf(stderr, "Usage: %s [maxlen [ignore-error]]\n", | ||
| 1282 | argv[0]); | ||
| 1283 | return 1; | ||
| 1284 | } | ||
| 1285 | } | ||
| 1286 | |||
| 1287 | ERR_load_crypto_strings(); | ||
| 1288 | ENGINE_load_builtin_engines(); | ||
| 1289 | OPENSSL_load_builtin_modules(); | ||
| 1290 | OpenSSL_add_all_algorithms(); | ||
| 1291 | |||
| 1292 | memset(bZB, 0, sizeof bZB); | ||
| 1293 | memset(bTS, 0, sizeof bTS); | ||
| 1294 | |||
| 1295 | /* Test load engine */ | ||
| 1296 | if(NULL == (md_gost94 = EVP_get_digestbyname(SN_id_GostR3411_94))) { | ||
| 1297 | fflush(NULL); | ||
| 1298 | fprintf(stderr, "\"" SN_id_GostR3411_94 "\" - not found\n"); | ||
| 1299 | if(!ignore) { | ||
| 1300 | return 7; | ||
| 1301 | } | ||
| 1302 | } | ||
| 1303 | if(NULL == (cp_g89cfb = EVP_get_cipherbyname(SN_id_Gost28147_89))) { | ||
| 1304 | fflush(NULL); | ||
| 1305 | fprintf(stderr, "\"" SN_id_Gost28147_89 "\" - not found\n"); | ||
| 1306 | if(!ignore) { | ||
| 1307 | return 8; | ||
| 1308 | } | ||
| 1309 | } | ||
| 1310 | if(NULL == (cp_g89cnt = EVP_get_cipherbyname(SN_gost89_cnt))) { | ||
| 1311 | fflush(NULL); | ||
| 1312 | fprintf(stderr, "\"" SN_gost89_cnt "\" - not found\n"); | ||
| 1313 | if(!ignore) { | ||
| 1314 | return 9; | ||
| 1315 | } | ||
| 1316 | } | ||
| 1317 | if(NULL == (cp_g89ecb = EVP_get_cipherbyname(SN_gost89_ecb))) { | ||
| 1318 | fflush(NULL); | ||
| 1319 | fprintf(stderr, "\"" SN_gost89_ecb "\" - not found\n"); | ||
| 1320 | if(!ignore) { | ||
| 1321 | return 8; | ||
| 1322 | } | ||
| 1323 | } | ||
| 1324 | if(NULL == (md_g89imit = EVP_get_digestbyname(SN_id_Gost28147_89_MAC))) { | ||
| 1325 | fflush(NULL); | ||
| 1326 | fprintf(stderr, "\"" SN_id_Gost28147_89_MAC "\" - not found\n"); | ||
| 1327 | if(!ignore) { | ||
| 1328 | return 10; | ||
| 1329 | } | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | /* Test cases */ | ||
| 1333 | for(t = 0; t < sizeof(tcs)/sizeof(tcs[0]); t++) { | ||
| 1334 | if(NULL != tcs[t].szDerive) { | ||
| 1335 | memset(bDerive, 0x3c, sizeof(bDerive)); | ||
| 1336 | mdl = sizeof(bDerive); | ||
| 1337 | EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), | ||
| 1338 | bDerive, &mdl, | ||
| 1339 | md_gost94, NULL); | ||
| 1340 | if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) { | ||
| 1341 | fflush(NULL); | ||
| 1342 | fprintf(stderr, "Engine test t=%d " | ||
| 1343 | "derive key error.\n", t); | ||
| 1344 | if(!ignore) { | ||
| 1345 | return 12; | ||
| 1346 | } | ||
| 1347 | } | ||
| 1348 | } | ||
| 1349 | if(ullMaxLen < tcs[t].ullLen) { | ||
| 1350 | printf("@"); | ||
| 1351 | continue; | ||
| 1352 | } | ||
| 1353 | memset(bTest, 0xa5, sizeof(bTest)); | ||
| 1354 | memset(bTest1, 0x5a, sizeof(bTest1)); | ||
| 1355 | |||
| 1356 | switch(tcs[t].gMode) { | ||
| 1357 | case G89_ECB: | ||
| 1358 | ctype = cp_g89ecb; | ||
| 1359 | goto engine_cipher_check; | ||
| 1360 | case G89_CFB: | ||
| 1361 | ctype = cp_g89cfb; | ||
| 1362 | goto engine_cipher_check; | ||
| 1363 | case G89_CNT: | ||
| 1364 | ctype = cp_g89cnt; | ||
| 1365 | engine_cipher_check: | ||
| 1366 | EVP_CIPHER_CTX_init(&ectx); | ||
| 1367 | EVP_EncryptInit_ex(&ectx, ctype, NULL, | ||
| 1368 | tcs[t].bRawKey, tcs[t].bIV); | ||
| 1369 | EVP_CIPHER_CTX_ctrl(&ectx, EVP_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); | ||
| 1370 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { | ||
| 1371 | enlu = sizeof(bTest); | ||
| 1372 | EVP_EncryptUpdate(&ectx, bTest, &enlu, | ||
| 1373 | tcs[t].bIn, (int)tcs[t].ullLen); | ||
| 1374 | l = (size_t)tcs[t].ullLen; | ||
| 1375 | } else { | ||
| 1376 | for(ullLeft = tcs[t].ullLen; | ||
| 1377 | ullLeft >= sizeof(bZB); | ||
| 1378 | ullLeft -= sizeof(bZB)) { | ||
| 1379 | printf("B"); | ||
| 1380 | fflush(NULL); | ||
| 1381 | enlu = sizeof(bTS); | ||
| 1382 | EVP_EncryptUpdate(&ectx, bTS, &enlu, | ||
| 1383 | bZB, sizeof(bZB)); | ||
| 1384 | } | ||
| 1385 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | ||
| 1386 | fflush(NULL); | ||
| 1387 | EVP_EncryptUpdate(&ectx, bTS, &enlu, | ||
| 1388 | bZB, (int)ullLeft); | ||
| 1389 | memcpy(bTest, &bTS[enlu-16], 16); | ||
| 1390 | enlu = (int)tcs[t].ullLen; | ||
| 1391 | l = 16; | ||
| 1392 | } | ||
| 1393 | enlf = sizeof(bTest1); | ||
| 1394 | if (tcs[t].gMode == G89_ECB) | ||
| 1395 | enlf = 0; | ||
| 1396 | else | ||
| 1397 | EVP_EncryptFinal_ex(&ectx, bTest1, &enlf); | ||
| 1398 | EVP_CIPHER_CTX_cleanup(&ectx); | ||
| 1399 | break; | ||
| 1400 | case G89_IMIT: | ||
| 1401 | EVP_MD_CTX_init(&mctx); | ||
| 1402 | mac_key = EVP_PKEY_new_mac_key( | ||
| 1403 | NID_id_Gost28147_89_MAC, NULL, | ||
| 1404 | bDerive, mdl); | ||
| 1405 | if (!mac_key) | ||
| 1406 | goto imit_fail; | ||
| 1407 | EVP_DigestSignInit(&mctx, NULL, | ||
| 1408 | md_g89imit, NULL, mac_key); | ||
| 1409 | EVP_MD_CTX_ctrl(&mctx, EVP_MD_CTRL_GOST_SET_SBOX, OBJ_txt2nid(tcs[t].szParamSet), 0); | ||
| 1410 | if(G89_MAX_TC_LEN >= tcs[t].ullLen) { | ||
| 1411 | EVP_DigestSignUpdate(&mctx, tcs[t].bIn, | ||
| 1412 | (unsigned int)tcs[t].ullLen); | ||
| 1413 | } else { | ||
| 1414 | for(ullLeft = tcs[t].ullLen; | ||
| 1415 | ullLeft >= sizeof(bZB); | ||
| 1416 | ullLeft -= sizeof(bZB)) { | ||
| 1417 | printf("B"); | ||
| 1418 | fflush(NULL); | ||
| 1419 | EVP_DigestSignUpdate(&mctx, bZB, sizeof(bZB)); | ||
| 1420 | } | ||
| 1421 | printf("b%" PRIu64 "/%" PRIu64, ullLeft, tcs[t].ullLen); | ||
| 1422 | fflush(NULL); | ||
| 1423 | EVP_DigestSignUpdate(&mctx, bZB, | ||
| 1424 | (unsigned int)ullLeft); | ||
| 1425 | } | ||
| 1426 | siglen = 4; | ||
| 1427 | OPENSSL_assert(EVP_DigestSignFinal(&mctx, bTest, &siglen)); | ||
| 1428 | EVP_MD_CTX_cleanup(&mctx); | ||
| 1429 | EVP_PKEY_free(mac_key); | ||
| 1430 | enlu = (int)tcs[t].ullLen; | ||
| 1431 | enlf = 0; | ||
| 1432 | l = siglen; | ||
| 1433 | break; | ||
| 1434 | } | ||
| 1435 | if((int)tcs[t].ullLen != enlu || 0 != enlf || | ||
| 1436 | 0 != memcmp(tcs[t].bOut, bTest, l)) { | ||
| 1437 | imit_fail: | ||
| 1438 | fflush(NULL); | ||
| 1439 | fprintf(stderr, "\nEngine test t=%d len=%" PRIu64 | ||
| 1440 | " mode=%d failed.\n", t, tcs[t].ullLen, tcs[t].gMode); | ||
| 1441 | if(!ignore) { | ||
| 1442 | return 13; | ||
| 1443 | } | ||
| 1444 | } else { | ||
| 1445 | printf("."); | ||
| 1446 | fflush(NULL); | ||
| 1447 | } | ||
| 1448 | } | ||
| 1449 | |||
| 1450 | printf(" passed\n"); | ||
| 1451 | fflush(NULL); | ||
| 1452 | |||
| 1453 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 1454 | ERR_print_errors(bio_err); | ||
| 1455 | (void)BIO_flush(bio_err); | ||
| 1456 | BIO_free(bio_err); | ||
| 1457 | return 0; | ||
| 1458 | } | ||
| 1459 | #endif | ||
diff --git a/src/regress/lib/libcrypto/hkdf/Makefile b/src/regress/lib/libcrypto/hkdf/Makefile deleted file mode 100644 index 38d7f5b1f9..0000000000 --- a/src/regress/lib/libcrypto/hkdf/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/05/06 20:42:57 beck Exp $ | ||
| 2 | |||
| 3 | PROG= hkdf_test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/hkdf/hkdf_test.c b/src/regress/lib/libcrypto/hkdf/hkdf_test.c deleted file mode 100644 index 5e89f3384c..0000000000 --- a/src/regress/lib/libcrypto/hkdf/hkdf_test.c +++ /dev/null | |||
| @@ -1,300 +0,0 @@ | |||
| 1 | /* $OpenBSD: hkdf_test.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (c) 2014, Google Inc. | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ | ||
| 15 | |||
| 16 | #include <stdio.h> | ||
| 17 | #include <string.h> | ||
| 18 | |||
| 19 | #include <openssl/crypto.h> | ||
| 20 | #include <openssl/evp.h> | ||
| 21 | #include <openssl/err.h> | ||
| 22 | #include <openssl/hkdf.h> | ||
| 23 | |||
| 24 | #define OPENSSL_ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) | ||
| 25 | |||
| 26 | typedef struct HKDFTestVector_st { | ||
| 27 | const EVP_MD *(*md_func)(void); | ||
| 28 | const uint8_t ikm[80]; | ||
| 29 | const size_t ikm_len; | ||
| 30 | const uint8_t salt[80]; | ||
| 31 | const size_t salt_len; | ||
| 32 | const uint8_t info[80]; | ||
| 33 | const size_t info_len; | ||
| 34 | const uint8_t prk[EVP_MAX_MD_SIZE]; | ||
| 35 | const size_t prk_len; | ||
| 36 | const size_t out_len; | ||
| 37 | const uint8_t out[82]; | ||
| 38 | } HKDFTestVector; | ||
| 39 | |||
| 40 | /* These test vectors are from RFC 5869. */ | ||
| 41 | static const HKDFTestVector kTests[] = { | ||
| 42 | { | ||
| 43 | EVP_sha256, | ||
| 44 | { | ||
| 45 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 46 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 47 | }, 22, | ||
| 48 | { | ||
| 49 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | ||
| 50 | 0x0c, | ||
| 51 | }, 13, | ||
| 52 | { | ||
| 53 | 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, | ||
| 54 | }, 10, | ||
| 55 | { | ||
| 56 | 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc, 0x3f, 0x0d, | ||
| 57 | 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31, | ||
| 58 | 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5, | ||
| 59 | }, 32, | ||
| 60 | 42, { | ||
| 61 | 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43, 0x4f, 0x64, | ||
| 62 | 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c, | ||
| 63 | 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, | ||
| 64 | 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65 | ||
| 65 | } | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | EVP_sha256, | ||
| 69 | { | ||
| 70 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | ||
| 71 | 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 72 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, | ||
| 73 | 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, | ||
| 74 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, | ||
| 75 | 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | ||
| 76 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f | ||
| 77 | }, 80, | ||
| 78 | { | ||
| 79 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, | ||
| 80 | 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | ||
| 81 | 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, | ||
| 82 | 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, | ||
| 83 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, | ||
| 84 | 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, | ||
| 85 | 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf | ||
| 86 | }, 80, | ||
| 87 | { | ||
| 88 | 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, | ||
| 89 | 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, | ||
| 90 | 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, | ||
| 91 | 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, | ||
| 92 | 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, | ||
| 93 | 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, | ||
| 94 | 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff | ||
| 95 | }, 80, | ||
| 96 | { | ||
| 97 | 0x06, 0xa6, 0xb8, 0x8c, 0x58, 0x53, 0x36, 0x1a, 0x06, 0x10, 0x4c, 0x9c, | ||
| 98 | 0xeb, 0x35, 0xb4, 0x5c, 0xef, 0x76, 0x00, 0x14, 0x90, 0x46, 0x71, 0x01, | ||
| 99 | 0x4a, 0x19, 0x3f, 0x40, 0xc1, 0x5f, 0xc2, 0x44, | ||
| 100 | }, 32, | ||
| 101 | 82, { | ||
| 102 | 0xb1, 0x1e, 0x39, 0x8d, 0xc8, 0x03, 0x27, 0xa1, 0xc8, 0xe7, 0xf7, 0x8c, | ||
| 103 | 0x59, 0x6a, 0x49, 0x34, 0x4f, 0x01, 0x2e, 0xda, 0x2d, 0x4e, 0xfa, 0xd8, | ||
| 104 | 0xa0, 0x50, 0xcc, 0x4c, 0x19, 0xaf, 0xa9, 0x7c, 0x59, 0x04, 0x5a, 0x99, | ||
| 105 | 0xca, 0xc7, 0x82, 0x72, 0x71, 0xcb, 0x41, 0xc6, 0x5e, 0x59, 0x0e, 0x09, | ||
| 106 | 0xda, 0x32, 0x75, 0x60, 0x0c, 0x2f, 0x09, 0xb8, 0x36, 0x77, 0x93, 0xa9, | ||
| 107 | 0xac, 0xa3, 0xdb, 0x71, 0xcc, 0x30, 0xc5, 0x81, 0x79, 0xec, 0x3e, 0x87, | ||
| 108 | 0xc1, 0x4c, 0x01, 0xd5, 0xc1, 0xf3, 0x43, 0x4f, 0x1d, 0x87 | ||
| 109 | } | ||
| 110 | }, | ||
| 111 | { | ||
| 112 | EVP_sha256, | ||
| 113 | { | ||
| 114 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 115 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 116 | }, 22, | ||
| 117 | { | ||
| 118 | 0, | ||
| 119 | }, 0, | ||
| 120 | { | ||
| 121 | 0, | ||
| 122 | }, 0, | ||
| 123 | { | ||
| 124 | 0x19, 0xef, 0x24, 0xa3, 0x2c, 0x71, 0x7b, 0x16, 0x7f, 0x33, 0xa9, 0x1d, | ||
| 125 | 0x6f, 0x64, 0x8b, 0xdf, 0x96, 0x59, 0x67, 0x76, 0xaf, 0xdb, 0x63, 0x77, | ||
| 126 | 0xac, 0x43, 0x4c, 0x1c, 0x29, 0x3c, 0xcb, 0x04 | ||
| 127 | }, 32, | ||
| 128 | 42, { | ||
| 129 | 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f, 0x71, 0x5f, 0x80, 0x2a, | ||
| 130 | 0x06, 0x3c, 0x5a, 0x31, 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e, | ||
| 131 | 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, 0x13, 0x95, | ||
| 132 | 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8 | ||
| 133 | } | ||
| 134 | }, | ||
| 135 | { | ||
| 136 | EVP_sha1, | ||
| 137 | { | ||
| 138 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 139 | }, 11, | ||
| 140 | { | ||
| 141 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | ||
| 142 | 0x0c, | ||
| 143 | }, 13, | ||
| 144 | { | ||
| 145 | 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, | ||
| 146 | }, 10, | ||
| 147 | { | ||
| 148 | 0x9b, 0x6c, 0x18, 0xc4, 0x32, 0xa7, 0xbf, 0x8f, 0x0e, 0x71, 0xc8, 0xeb, | ||
| 149 | 0x88, 0xf4, 0xb3, 0x0b, 0xaa, 0x2b, 0xa2, 0x43 | ||
| 150 | }, 20, | ||
| 151 | 42, { | ||
| 152 | 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69, 0x33, 0x06, 0x8b, 0x56, | ||
| 153 | 0xef, 0xa5, 0xad, 0x81, 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15, | ||
| 154 | 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, 0x42, 0x24, | ||
| 155 | 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96 | ||
| 156 | } | ||
| 157 | }, | ||
| 158 | { | ||
| 159 | EVP_sha1, | ||
| 160 | { | ||
| 161 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, | ||
| 162 | 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 163 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, | ||
| 164 | 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, | ||
| 165 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, | ||
| 166 | 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | ||
| 167 | 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f | ||
| 168 | }, 80, | ||
| 169 | { | ||
| 170 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, | ||
| 171 | 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | ||
| 172 | 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, | ||
| 173 | 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, | ||
| 174 | 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, | ||
| 175 | 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, | ||
| 176 | 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf | ||
| 177 | }, 80, | ||
| 178 | { | ||
| 179 | 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, | ||
| 180 | 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, | ||
| 181 | 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, | ||
| 182 | 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, | ||
| 183 | 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, | ||
| 184 | 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, | ||
| 185 | 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff | ||
| 186 | }, 80, | ||
| 187 | { | ||
| 188 | 0x8a, 0xda, 0xe0, 0x9a, 0x2a, 0x30, 0x70, 0x59, 0x47, 0x8d, 0x30, 0x9b, | ||
| 189 | 0x26, 0xc4, 0x11, 0x5a, 0x22, 0x4c, 0xfa, 0xf6, | ||
| 190 | }, 20, | ||
| 191 | 82, { | ||
| 192 | 0x0b, 0xd7, 0x70, 0xa7, 0x4d, 0x11, 0x60, 0xf7, 0xc9, 0xf1, 0x2c, 0xd5, | ||
| 193 | 0x91, 0x2a, 0x06, 0xeb, 0xff, 0x6a, 0xdc, 0xae, 0x89, 0x9d, 0x92, 0x19, | ||
| 194 | 0x1f, 0xe4, 0x30, 0x56, 0x73, 0xba, 0x2f, 0xfe, 0x8f, 0xa3, 0xf1, 0xa4, | ||
| 195 | 0xe5, 0xad, 0x79, 0xf3, 0xf3, 0x34, 0xb3, 0xb2, 0x02, 0xb2, 0x17, 0x3c, | ||
| 196 | 0x48, 0x6e, 0xa3, 0x7c, 0xe3, 0xd3, 0x97, 0xed, 0x03, 0x4c, 0x7f, 0x9d, | ||
| 197 | 0xfe, 0xb1, 0x5c, 0x5e, 0x92, 0x73, 0x36, 0xd0, 0x44, 0x1f, 0x4c, 0x43, | ||
| 198 | 0x00, 0xe2, 0xcf, 0xf0, 0xd0, 0x90, 0x0b, 0x52, 0xd3, 0xb4 | ||
| 199 | } | ||
| 200 | }, | ||
| 201 | { | ||
| 202 | EVP_sha1, | ||
| 203 | { | ||
| 204 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 205 | 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, | ||
| 206 | }, 22, | ||
| 207 | { | ||
| 208 | 0, | ||
| 209 | }, 0, | ||
| 210 | { | ||
| 211 | 0, | ||
| 212 | }, 0, | ||
| 213 | { | ||
| 214 | 0xda, 0x8c, 0x8a, 0x73, 0xc7, 0xfa, 0x77, 0x28, 0x8e, 0xc6, 0xf5, 0xe7, | ||
| 215 | 0xc2, 0x97, 0x78, 0x6a, 0xa0, 0xd3, 0x2d, 0x01, | ||
| 216 | }, 20, | ||
| 217 | 42, { | ||
| 218 | 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61, 0xd1, 0xe5, 0x52, 0x98, | ||
| 219 | 0xda, 0x9d, 0x05, 0x06, 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06, | ||
| 220 | 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0, 0xea, 0x00, 0x03, 0x3d, | ||
| 221 | 0xe0, 0x39, 0x84, 0xd3, 0x49, 0x18 | ||
| 222 | } | ||
| 223 | }, | ||
| 224 | { | ||
| 225 | EVP_sha1, | ||
| 226 | { | ||
| 227 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, | ||
| 228 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, | ||
| 229 | }, 22, | ||
| 230 | { | ||
| 231 | 0, | ||
| 232 | }, 0, | ||
| 233 | { | ||
| 234 | 0, | ||
| 235 | }, 0, | ||
| 236 | { | ||
| 237 | 0x2a, 0xdc, 0xca, 0xda, 0x18, 0x77, 0x9e, 0x7c, 0x20, 0x77, 0xad, 0x2e, | ||
| 238 | 0xb1, 0x9d, 0x3f, 0x3e, 0x73, 0x13, 0x85, 0xdd, | ||
| 239 | }, 20, | ||
| 240 | 42, { | ||
| 241 | 0x2c, 0x91, 0x11, 0x72, 0x04, 0xd7, 0x45, 0xf3, 0x50, 0x0d, 0x63, 0x6a, | ||
| 242 | 0x62, 0xf6, 0x4f, 0x0a, 0xb3, 0xba, 0xe5, 0x48, 0xaa, 0x53, 0xd4, 0x23, | ||
| 243 | 0xb0, 0xd1, 0xf2, 0x7e, 0xbb, 0xa6, 0xf5, 0xe5, 0x67, 0x3a, 0x08, 0x1d, | ||
| 244 | 0x70, 0xcc, 0xe7, 0xac, 0xfc, 0x48 | ||
| 245 | } | ||
| 246 | }, | ||
| 247 | }; | ||
| 248 | |||
| 249 | int main(void) { | ||
| 250 | size_t i; | ||
| 251 | OPENSSL_add_all_algorithms_noconf(); | ||
| 252 | |||
| 253 | for (i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) { | ||
| 254 | const HKDFTestVector *test = &kTests[i]; | ||
| 255 | uint8_t prk[EVP_MAX_MD_SIZE]; | ||
| 256 | uint8_t buf[82]; | ||
| 257 | size_t prk_len; | ||
| 258 | if (!HKDF_extract(prk, &prk_len, test->md_func(), test->ikm, | ||
| 259 | test->ikm_len, test->salt, test->salt_len)) { | ||
| 260 | fprintf(stderr, "Call to HKDF_extract failed\n"); | ||
| 261 | ERR_print_errors_fp(stderr); | ||
| 262 | return 1; | ||
| 263 | } | ||
| 264 | if (prk_len != test->prk_len || | ||
| 265 | memcmp(prk, test->prk, test->prk_len) != 0) { | ||
| 266 | fprintf(stderr, "%zu: Resulting PRK does not match" | ||
| 267 | "test vector\n", i); | ||
| 268 | return 1; | ||
| 269 | } | ||
| 270 | if (!HKDF_expand(buf, test->out_len, test->md_func(), prk, prk_len, | ||
| 271 | test->info, test->info_len)) { | ||
| 272 | fprintf(stderr, "Call to HKDF_expand failed\n"); | ||
| 273 | ERR_print_errors_fp(stderr); | ||
| 274 | return 1; | ||
| 275 | } | ||
| 276 | if (memcmp(buf, test->out, test->out_len) != 0) { | ||
| 277 | fprintf(stderr, | ||
| 278 | "%zu: Resulting key material does not match test" | ||
| 279 | "vector\n", i); | ||
| 280 | return 1; | ||
| 281 | } | ||
| 282 | |||
| 283 | if (!HKDF(buf, test->out_len, test->md_func(), test->ikm, | ||
| 284 | test->ikm_len, test->salt, test->salt_len, test->info, | ||
| 285 | test->info_len)) { | ||
| 286 | fprintf(stderr, "Call to HKDF failed\n"); | ||
| 287 | ERR_print_errors_fp(stderr); | ||
| 288 | return 1; | ||
| 289 | } | ||
| 290 | if (memcmp(buf, test->out, test->out_len) != 0) { | ||
| 291 | fprintf(stderr, | ||
| 292 | "%zu: Resulting key material does not match test" | ||
| 293 | "vector\n", i); | ||
| 294 | return 1; | ||
| 295 | } | ||
| 296 | } | ||
| 297 | |||
| 298 | printf("PASS\n"); | ||
| 299 | return 0; | ||
| 300 | } | ||
diff --git a/src/regress/lib/libcrypto/hmac/Makefile b/src/regress/lib/libcrypto/hmac/Makefile deleted file mode 100644 index 6705336211..0000000000 --- a/src/regress/lib/libcrypto/hmac/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= hmactest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/hmac/hmactest.c b/src/regress/lib/libcrypto/hmac/hmactest.c deleted file mode 100644 index 1f120da5d9..0000000000 --- a/src/regress/lib/libcrypto/hmac/hmactest.c +++ /dev/null | |||
| @@ -1,329 +0,0 @@ | |||
| 1 | /* $OpenBSD: hmactest.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/hmac.h> | ||
| 64 | #ifndef OPENSSL_NO_MD5 | ||
| 65 | #include <openssl/md5.h> | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifndef OPENSSL_NO_MD5 | ||
| 69 | static struct test_st { | ||
| 70 | unsigned char key[16]; | ||
| 71 | int key_len; | ||
| 72 | unsigned char data[64]; | ||
| 73 | int data_len; | ||
| 74 | unsigned char *digest; | ||
| 75 | } test[8] = { | ||
| 76 | { "", | ||
| 77 | 0, | ||
| 78 | "More text test vectors to stuff up EBCDIC machines :-)", | ||
| 79 | 54, | ||
| 80 | (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86", | ||
| 81 | }, | ||
| 82 | { {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b, | ||
| 83 | 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,}, | ||
| 84 | 16, | ||
| 85 | "Hi There", | ||
| 86 | 8, | ||
| 87 | (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d", | ||
| 88 | }, | ||
| 89 | { "Jefe", | ||
| 90 | 4, | ||
| 91 | "what do ya want for nothing?", | ||
| 92 | 28, | ||
| 93 | (unsigned char *)"750c783e6ab0b503eaa86e310a5db738", | ||
| 94 | }, | ||
| 95 | { {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, | ||
| 96 | 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,}, | ||
| 97 | 16, | ||
| 98 | {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 99 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 100 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 101 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 102 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 103 | 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd, | ||
| 104 | 0xdd,0xdd}, | ||
| 105 | 50, | ||
| 106 | (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6", | ||
| 107 | }, | ||
| 108 | { "", | ||
| 109 | 0, | ||
| 110 | "My test data", | ||
| 111 | 12, | ||
| 112 | (unsigned char *)"61afdecb95429ef494d61fdee15990cabf0826fc" | ||
| 113 | }, | ||
| 114 | { "", | ||
| 115 | 0, | ||
| 116 | "My test data", | ||
| 117 | 12, | ||
| 118 | (unsigned char *)"2274b195d90ce8e03406f4b526a47e0787a88a65479938f1a5baa3ce0f079776" | ||
| 119 | }, | ||
| 120 | { "123456", | ||
| 121 | 6, | ||
| 122 | "My test data", | ||
| 123 | 12, | ||
| 124 | (unsigned char *)"bab53058ae861a7f191abe2d0145cbb123776a6369ee3f9d79ce455667e411dd" | ||
| 125 | }, | ||
| 126 | { "12345", | ||
| 127 | 5, | ||
| 128 | "My test data again", | ||
| 129 | 12, | ||
| 130 | (unsigned char *)"7dbe8c764c068e3bcd6e6b0fbcd5e6fc197b15bb" | ||
| 131 | } | ||
| 132 | }; | ||
| 133 | #endif | ||
| 134 | |||
| 135 | static char *pt(unsigned char *md, unsigned int len); | ||
| 136 | |||
| 137 | int | ||
| 138 | main(int argc, char *argv[]) | ||
| 139 | { | ||
| 140 | #ifndef OPENSSL_NO_MD5 | ||
| 141 | int i; | ||
| 142 | char *p; | ||
| 143 | #endif | ||
| 144 | int err = 0; | ||
| 145 | HMAC_CTX ctx, ctx2; | ||
| 146 | unsigned char buf[EVP_MAX_MD_SIZE]; | ||
| 147 | unsigned int len; | ||
| 148 | |||
| 149 | #ifdef OPENSSL_NO_MD5 | ||
| 150 | printf("test skipped: MD5 disabled\n"); | ||
| 151 | #else | ||
| 152 | |||
| 153 | for (i = 0; i < 4; i++) { | ||
| 154 | p = pt(HMAC(EVP_md5(), | ||
| 155 | test[i].key, test[i].key_len, | ||
| 156 | test[i].data, test[i].data_len, NULL, NULL), | ||
| 157 | MD5_DIGEST_LENGTH); | ||
| 158 | |||
| 159 | if (strcmp(p, (char *)test[i].digest) != 0) { | ||
| 160 | printf("error calculating HMAC on %d entry'\n", i); | ||
| 161 | printf("got %s instead of %s\n", p, test[i].digest); | ||
| 162 | err++; | ||
| 163 | } else | ||
| 164 | printf("test %d ok\n", i); | ||
| 165 | } | ||
| 166 | #endif /* OPENSSL_NO_MD5 */ | ||
| 167 | |||
| 168 | /* test4 */ | ||
| 169 | HMAC_CTX_init(&ctx); | ||
| 170 | if (HMAC_Init_ex(&ctx, NULL, 0, NULL, NULL)) { | ||
| 171 | printf("Should fail to initialise HMAC with empty MD and key (test 4)\n"); | ||
| 172 | err++; | ||
| 173 | goto test5; | ||
| 174 | } | ||
| 175 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | ||
| 176 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); | ||
| 177 | err++; | ||
| 178 | goto test5; | ||
| 179 | } | ||
| 180 | if (HMAC_Init_ex(&ctx, NULL, 0, EVP_sha1(), NULL)) { | ||
| 181 | printf("Should fail to initialise HMAC with empty key (test 4)\n"); | ||
| 182 | err++; | ||
| 183 | goto test5; | ||
| 184 | } | ||
| 185 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | ||
| 186 | printf("Should fail HMAC_Update with ctx not set up (test 4)\n"); | ||
| 187 | err++; | ||
| 188 | goto test5; | ||
| 189 | } | ||
| 190 | printf("test 4 ok\n"); | ||
| 191 | test5: | ||
| 192 | HMAC_CTX_cleanup(&ctx); | ||
| 193 | HMAC_CTX_init(&ctx); | ||
| 194 | if (HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, NULL, NULL)) { | ||
| 195 | printf("Should fail to initialise HMAC with empty MD (test 5)\n"); | ||
| 196 | err++; | ||
| 197 | goto test6; | ||
| 198 | } | ||
| 199 | if (HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | ||
| 200 | printf("Should fail HMAC_Update with ctx not set up (test 5)\n"); | ||
| 201 | err++; | ||
| 202 | goto test6; | ||
| 203 | } | ||
| 204 | if (HMAC_Init_ex(&ctx, test[4].key, -1, EVP_sha1(), NULL)) { | ||
| 205 | printf("Should fail to initialise HMAC with invalid key len(test 5)\n"); | ||
| 206 | err++; | ||
| 207 | goto test6; | ||
| 208 | } | ||
| 209 | if (!HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, EVP_sha1(), NULL)) { | ||
| 210 | printf("Failed to initialise HMAC (test 5)\n"); | ||
| 211 | err++; | ||
| 212 | goto test6; | ||
| 213 | } | ||
| 214 | if (!HMAC_Update(&ctx, test[4].data, test[4].data_len)) { | ||
| 215 | printf("Error updating HMAC with data (test 5)\n"); | ||
| 216 | err++; | ||
| 217 | goto test6; | ||
| 218 | } | ||
| 219 | if (!HMAC_Final(&ctx, buf, &len)) { | ||
| 220 | printf("Error finalising data (test 5)\n"); | ||
| 221 | err++; | ||
| 222 | goto test6; | ||
| 223 | } | ||
| 224 | p = pt(buf, len); | ||
| 225 | if (strcmp(p, (char *)test[4].digest) != 0) { | ||
| 226 | printf("Error calculating interim HMAC on test 5\n"); | ||
| 227 | printf("got %s instead of %s\n", p, test[4].digest); | ||
| 228 | err++; | ||
| 229 | goto test6; | ||
| 230 | } | ||
| 231 | if (HMAC_Init_ex(&ctx, NULL, 0, EVP_sha256(), NULL)) { | ||
| 232 | printf("Should disallow changing MD without a new key (test 5)\n"); | ||
| 233 | err++; | ||
| 234 | goto test6; | ||
| 235 | } | ||
| 236 | if (!HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, EVP_sha256(), NULL)) { | ||
| 237 | printf("Failed to reinitialise HMAC (test 5)\n"); | ||
| 238 | err++; | ||
| 239 | goto test6; | ||
| 240 | } | ||
| 241 | if (!HMAC_Update(&ctx, test[5].data, test[5].data_len)) { | ||
| 242 | printf("Error updating HMAC with data (sha256) (test 5)\n"); | ||
| 243 | err++; | ||
| 244 | goto test6; | ||
| 245 | } | ||
| 246 | if (!HMAC_Final(&ctx, buf, &len)) { | ||
| 247 | printf("Error finalising data (sha256) (test 5)\n"); | ||
| 248 | err++; | ||
| 249 | goto test6; | ||
| 250 | } | ||
| 251 | p = pt(buf, len); | ||
| 252 | if (strcmp(p, (char *)test[5].digest) != 0) { | ||
| 253 | printf("Error calculating 2nd interim HMAC on test 5\n"); | ||
| 254 | printf("got %s instead of %s\n", p, test[5].digest); | ||
| 255 | err++; | ||
| 256 | goto test6; | ||
| 257 | } | ||
| 258 | if (!HMAC_Init_ex(&ctx, test[6].key, test[6].key_len, NULL, NULL)) { | ||
| 259 | printf("Failed to reinitialise HMAC with key (test 5)\n"); | ||
| 260 | err++; | ||
| 261 | goto test6; | ||
| 262 | } | ||
| 263 | if (!HMAC_Update(&ctx, test[6].data, test[6].data_len)) { | ||
| 264 | printf("Error updating HMAC with data (new key) (test 5)\n"); | ||
| 265 | err++; | ||
| 266 | goto test6; | ||
| 267 | } | ||
| 268 | if (!HMAC_Final(&ctx, buf, &len)) { | ||
| 269 | printf("Error finalising data (new key) (test 5)\n"); | ||
| 270 | err++; | ||
| 271 | goto test6; | ||
| 272 | } | ||
| 273 | p = pt(buf, len); | ||
| 274 | if (strcmp(p, (char *)test[6].digest) != 0) { | ||
| 275 | printf("error calculating HMAC on test 5\n"); | ||
| 276 | printf("got %s instead of %s\n", p, test[6].digest); | ||
| 277 | err++; | ||
| 278 | } else { | ||
| 279 | printf("test 5 ok\n"); | ||
| 280 | } | ||
| 281 | test6: | ||
| 282 | HMAC_CTX_cleanup(&ctx); | ||
| 283 | HMAC_CTX_init(&ctx); | ||
| 284 | if (!HMAC_Init_ex(&ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) { | ||
| 285 | printf("Failed to initialise HMAC (test 6)\n"); | ||
| 286 | err++; | ||
| 287 | goto end; | ||
| 288 | } | ||
| 289 | if (!HMAC_Update(&ctx, test[7].data, test[7].data_len)) { | ||
| 290 | printf("Error updating HMAC with data (test 6)\n"); | ||
| 291 | err++; | ||
| 292 | goto end; | ||
| 293 | } | ||
| 294 | if (!HMAC_CTX_copy(&ctx2, &ctx)) { | ||
| 295 | printf("Failed to copy HMAC_CTX (test 6)\n"); | ||
| 296 | err++; | ||
| 297 | goto end; | ||
| 298 | } | ||
| 299 | if (!HMAC_Final(&ctx2, buf, &len)) { | ||
| 300 | printf("Error finalising data (test 6)\n"); | ||
| 301 | err++; | ||
| 302 | goto end; | ||
| 303 | } | ||
| 304 | p = pt(buf, len); | ||
| 305 | if (strcmp(p, (char *)test[7].digest) != 0) { | ||
| 306 | printf("Error calculating HMAC on test 6\n"); | ||
| 307 | printf("got %s instead of %s\n", p, test[7].digest); | ||
| 308 | err++; | ||
| 309 | } else { | ||
| 310 | printf("test 6 ok\n"); | ||
| 311 | } | ||
| 312 | end: | ||
| 313 | HMAC_CTX_cleanup(&ctx); | ||
| 314 | exit(err); | ||
| 315 | return(0); | ||
| 316 | } | ||
| 317 | |||
| 318 | #ifndef OPENSSL_NO_MD5 | ||
| 319 | static char * | ||
| 320 | pt(unsigned char *md, unsigned int len) | ||
| 321 | { | ||
| 322 | unsigned int i; | ||
| 323 | static char buf[80]; | ||
| 324 | |||
| 325 | for (i = 0; i < len; i++) | ||
| 326 | snprintf(buf + i * 2, sizeof(buf) - i * 2, "%02x", md[i]); | ||
| 327 | return(buf); | ||
| 328 | } | ||
| 329 | #endif | ||
diff --git a/src/regress/lib/libcrypto/idea/Makefile b/src/regress/lib/libcrypto/idea/Makefile deleted file mode 100644 index b04ff3d2b5..0000000000 --- a/src/regress/lib/libcrypto/idea/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= ideatest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/idea/ideatest.c b/src/regress/lib/libcrypto/idea/ideatest.c deleted file mode 100644 index b33b824ae7..0000000000 --- a/src/regress/lib/libcrypto/idea/ideatest.c +++ /dev/null | |||
| @@ -1,221 +0,0 @@ | |||
| 1 | /* $OpenBSD: ideatest.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/idea.h> | ||
| 64 | |||
| 65 | unsigned char k[16]={ | ||
| 66 | 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04, | ||
| 67 | 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08}; | ||
| 68 | |||
| 69 | unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03}; | ||
| 70 | unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5}; | ||
| 71 | unsigned char out[80]; | ||
| 72 | |||
| 73 | char *text="Hello to all people out there"; | ||
| 74 | |||
| 75 | static unsigned char cfb_key[16]={ | ||
| 76 | 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96, | ||
| 77 | 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e, | ||
| 78 | }; | ||
| 79 | static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd}; | ||
| 80 | static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8]; | ||
| 81 | #define CFB_TEST_SIZE 24 | ||
| 82 | static unsigned char plain[CFB_TEST_SIZE]= | ||
| 83 | { | ||
| 84 | 0x4e,0x6f,0x77,0x20,0x69,0x73, | ||
| 85 | 0x20,0x74,0x68,0x65,0x20,0x74, | ||
| 86 | 0x69,0x6d,0x65,0x20,0x66,0x6f, | ||
| 87 | 0x72,0x20,0x61,0x6c,0x6c,0x20 | ||
| 88 | }; | ||
| 89 | static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ | ||
| 90 | 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F, | ||
| 91 | 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A, | ||
| 92 | 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45 | ||
| 93 | |||
| 94 | /* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38, | ||
| 95 | 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9, | ||
| 96 | 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/ | ||
| 97 | }; | ||
| 98 | |||
| 99 | static int cfb64_test(unsigned char *cfb_cipher); | ||
| 100 | static char *pt(unsigned char *p); | ||
| 101 | int main(int argc, char *argv[]) | ||
| 102 | { | ||
| 103 | int i,err=0; | ||
| 104 | IDEA_KEY_SCHEDULE key,dkey; | ||
| 105 | unsigned char iv[8]; | ||
| 106 | |||
| 107 | idea_set_encrypt_key(k,&key); | ||
| 108 | idea_ecb_encrypt(in,out,&key); | ||
| 109 | if (memcmp(out,c,8) != 0) | ||
| 110 | { | ||
| 111 | printf("ecb idea error encrypting\n"); | ||
| 112 | printf("got :"); | ||
| 113 | for (i=0; i<8; i++) | ||
| 114 | printf("%02X ",out[i]); | ||
| 115 | printf("\n"); | ||
| 116 | printf("expected:"); | ||
| 117 | for (i=0; i<8; i++) | ||
| 118 | printf("%02X ",c[i]); | ||
| 119 | err=20; | ||
| 120 | printf("\n"); | ||
| 121 | } | ||
| 122 | |||
| 123 | idea_set_decrypt_key(&key,&dkey); | ||
| 124 | idea_ecb_encrypt(c,out,&dkey); | ||
| 125 | if (memcmp(out,in,8) != 0) | ||
| 126 | { | ||
| 127 | printf("ecb idea error decrypting\n"); | ||
| 128 | printf("got :"); | ||
| 129 | for (i=0; i<8; i++) | ||
| 130 | printf("%02X ",out[i]); | ||
| 131 | printf("\n"); | ||
| 132 | printf("expected:"); | ||
| 133 | for (i=0; i<8; i++) | ||
| 134 | printf("%02X ",in[i]); | ||
| 135 | printf("\n"); | ||
| 136 | err=3; | ||
| 137 | } | ||
| 138 | |||
| 139 | if (err == 0) printf("ecb idea ok\n"); | ||
| 140 | |||
| 141 | memcpy(iv,k,8); | ||
| 142 | idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1); | ||
| 143 | memcpy(iv,k,8); | ||
| 144 | idea_cbc_encrypt(out,out,8,&dkey,iv,0); | ||
| 145 | idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0); | ||
| 146 | if (memcmp(text,out,strlen(text)+1) != 0) | ||
| 147 | { | ||
| 148 | printf("cbc idea bad\n"); | ||
| 149 | err=4; | ||
| 150 | } | ||
| 151 | else | ||
| 152 | printf("cbc idea ok\n"); | ||
| 153 | |||
| 154 | printf("cfb64 idea "); | ||
| 155 | if (cfb64_test(cfb_cipher64)) | ||
| 156 | { | ||
| 157 | printf("bad\n"); | ||
| 158 | err=5; | ||
| 159 | } | ||
| 160 | else | ||
| 161 | printf("ok\n"); | ||
| 162 | |||
| 163 | exit(err); | ||
| 164 | } | ||
| 165 | |||
| 166 | static int cfb64_test(unsigned char *cfb_cipher) | ||
| 167 | { | ||
| 168 | IDEA_KEY_SCHEDULE eks,dks; | ||
| 169 | int err=0,i,n; | ||
| 170 | |||
| 171 | idea_set_encrypt_key(cfb_key,&eks); | ||
| 172 | idea_set_decrypt_key(&eks,&dks); | ||
| 173 | memcpy(cfb_tmp,cfb_iv,8); | ||
| 174 | n=0; | ||
| 175 | idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks, | ||
| 176 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
| 177 | idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), | ||
| 178 | (long)CFB_TEST_SIZE-12,&eks, | ||
| 179 | cfb_tmp,&n,IDEA_ENCRYPT); | ||
| 180 | if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0) | ||
| 181 | { | ||
| 182 | err=1; | ||
| 183 | printf("idea_cfb64_encrypt encrypt error\n"); | ||
| 184 | for (i=0; i<CFB_TEST_SIZE; i+=8) | ||
| 185 | printf("%s\n",pt(&(cfb_buf1[i]))); | ||
| 186 | } | ||
| 187 | memcpy(cfb_tmp,cfb_iv,8); | ||
| 188 | n=0; | ||
| 189 | idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks, | ||
| 190 | cfb_tmp,&n,IDEA_DECRYPT); | ||
| 191 | idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), | ||
| 192 | (long)CFB_TEST_SIZE-17,&dks, | ||
| 193 | cfb_tmp,&n,IDEA_DECRYPT); | ||
| 194 | if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0) | ||
| 195 | { | ||
| 196 | err=1; | ||
| 197 | printf("idea_cfb_encrypt decrypt error\n"); | ||
| 198 | for (i=0; i<24; i+=8) | ||
| 199 | printf("%s\n",pt(&(cfb_buf2[i]))); | ||
| 200 | } | ||
| 201 | return(err); | ||
| 202 | } | ||
| 203 | |||
| 204 | static char *pt(unsigned char *p) | ||
| 205 | { | ||
| 206 | static char bufs[10][20]; | ||
| 207 | static int bnum=0; | ||
| 208 | char *ret; | ||
| 209 | int i; | ||
| 210 | static char *f="0123456789ABCDEF"; | ||
| 211 | |||
| 212 | ret= &(bufs[bnum++][0]); | ||
| 213 | bnum%=10; | ||
| 214 | for (i=0; i<8; i++) | ||
| 215 | { | ||
| 216 | ret[i*2]=f[(p[i]>>4)&0xf]; | ||
| 217 | ret[i*2+1]=f[p[i]&0xf]; | ||
| 218 | } | ||
| 219 | ret[16]='\0'; | ||
| 220 | return(ret); | ||
| 221 | } | ||
diff --git a/src/regress/lib/libcrypto/ige/Makefile b/src/regress/lib/libcrypto/ige/Makefile deleted file mode 100644 index a0197e059f..0000000000 --- a/src/regress/lib/libcrypto/ige/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= igetest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/ige/igetest.c b/src/regress/lib/libcrypto/ige/igetest.c deleted file mode 100644 index 2191af85b7..0000000000 --- a/src/regress/lib/libcrypto/ige/igetest.c +++ /dev/null | |||
| @@ -1,370 +0,0 @@ | |||
| 1 | /* $OpenBSD: igetest.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | |||
| 52 | #include <assert.h> | ||
| 53 | #include <stdio.h> | ||
| 54 | #include <stdlib.h> | ||
| 55 | #include <string.h> | ||
| 56 | |||
| 57 | #include <openssl/aes.h> | ||
| 58 | |||
| 59 | #define TEST_SIZE 128 | ||
| 60 | #define BIG_TEST_SIZE 10240 | ||
| 61 | |||
| 62 | static void hexdump(FILE *f,const char *title,const unsigned char *s,int l) | ||
| 63 | { | ||
| 64 | int n=0; | ||
| 65 | |||
| 66 | fprintf(f,"%s",title); | ||
| 67 | for( ; n < l ; ++n) | ||
| 68 | { | ||
| 69 | if((n%16) == 0) | ||
| 70 | fprintf(f,"\n%04x",n); | ||
| 71 | fprintf(f," %02x",s[n]); | ||
| 72 | } | ||
| 73 | fprintf(f,"\n"); | ||
| 74 | } | ||
| 75 | |||
| 76 | #define MAX_VECTOR_SIZE 64 | ||
| 77 | |||
| 78 | struct ige_test | ||
| 79 | { | ||
| 80 | const unsigned char key[16]; | ||
| 81 | const unsigned char iv[32]; | ||
| 82 | const unsigned char in[MAX_VECTOR_SIZE]; | ||
| 83 | const unsigned char out[MAX_VECTOR_SIZE]; | ||
| 84 | const size_t length; | ||
| 85 | const int encrypt; | ||
| 86 | }; | ||
| 87 | |||
| 88 | static struct ige_test const ige_test_vectors[] = { | ||
| 89 | { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 90 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, /* key */ | ||
| 91 | { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 92 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
| 93 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 94 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, /* iv */ | ||
| 95 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 98 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* in */ | ||
| 99 | { 0x1a, 0x85, 0x19, 0xa6, 0x55, 0x7b, 0xe6, 0x52, | ||
| 100 | 0xe9, 0xda, 0x8e, 0x43, 0xda, 0x4e, 0xf4, 0x45, | ||
| 101 | 0x3c, 0xf4, 0x56, 0xb4, 0xca, 0x48, 0x8a, 0xa3, | ||
| 102 | 0x83, 0xc7, 0x9c, 0x98, 0xb3, 0x47, 0x97, 0xcb }, /* out */ | ||
| 103 | 32, AES_ENCRYPT }, /* test vector 0 */ | ||
| 104 | |||
| 105 | { { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, | ||
| 106 | 0x61, 0x6e, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x65 }, /* key */ | ||
| 107 | { 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, | ||
| 108 | 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x49, 0x47, 0x45, | ||
| 109 | 0x20, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x66, 0x6f, | ||
| 110 | 0x72, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53 }, /* iv */ | ||
| 111 | { 0x4c, 0x2e, 0x20, 0x4c, 0x65, 0x74, 0x27, 0x73, | ||
| 112 | 0x20, 0x68, 0x6f, 0x70, 0x65, 0x20, 0x42, 0x65, | ||
| 113 | 0x6e, 0x20, 0x67, 0x6f, 0x74, 0x20, 0x69, 0x74, | ||
| 114 | 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x21, 0x0a }, /* in */ | ||
| 115 | { 0x99, 0x70, 0x64, 0x87, 0xa1, 0xcd, 0xe6, 0x13, | ||
| 116 | 0xbc, 0x6d, 0xe0, 0xb6, 0xf2, 0x4b, 0x1c, 0x7a, | ||
| 117 | 0xa4, 0x48, 0xc8, 0xb9, 0xc3, 0x40, 0x3e, 0x34, | ||
| 118 | 0x67, 0xa8, 0xca, 0xd8, 0x93, 0x40, 0xf5, 0x3b }, /* out */ | ||
| 119 | 32, AES_DECRYPT }, /* test vector 1 */ | ||
| 120 | }; | ||
| 121 | |||
| 122 | static int run_test_vectors(void) | ||
| 123 | { | ||
| 124 | unsigned int n; | ||
| 125 | int errs = 0; | ||
| 126 | |||
| 127 | for(n=0 ; n < sizeof(ige_test_vectors)/sizeof(ige_test_vectors[0]) ; ++n) | ||
| 128 | { | ||
| 129 | const struct ige_test * const v = &ige_test_vectors[n]; | ||
| 130 | AES_KEY key; | ||
| 131 | unsigned char buf[MAX_VECTOR_SIZE]; | ||
| 132 | unsigned char iv[AES_BLOCK_SIZE*2]; | ||
| 133 | |||
| 134 | assert(v->length <= MAX_VECTOR_SIZE); | ||
| 135 | |||
| 136 | if(v->encrypt == AES_ENCRYPT) | ||
| 137 | AES_set_encrypt_key(v->key, 8*sizeof v->key, &key); | ||
| 138 | else | ||
| 139 | AES_set_decrypt_key(v->key, 8*sizeof v->key, &key); | ||
| 140 | memcpy(iv, v->iv, sizeof iv); | ||
| 141 | AES_ige_encrypt(v->in, buf, v->length, &key, iv, v->encrypt); | ||
| 142 | |||
| 143 | if(memcmp(v->out, buf, v->length)) | ||
| 144 | { | ||
| 145 | printf("IGE test vector %d failed\n", n); | ||
| 146 | hexdump(stdout, "key", v->key, sizeof v->key); | ||
| 147 | hexdump(stdout, "iv", v->iv, sizeof v->iv); | ||
| 148 | hexdump(stdout, "in", v->in, v->length); | ||
| 149 | hexdump(stdout, "expected", v->out, v->length); | ||
| 150 | hexdump(stdout, "got", buf, v->length); | ||
| 151 | |||
| 152 | ++errs; | ||
| 153 | } | ||
| 154 | |||
| 155 | /* try with in == out */ | ||
| 156 | memcpy(iv, v->iv, sizeof iv); | ||
| 157 | memcpy(buf, v->in, v->length); | ||
| 158 | AES_ige_encrypt(buf, buf, v->length, &key, iv, v->encrypt); | ||
| 159 | |||
| 160 | if(memcmp(v->out, buf, v->length)) | ||
| 161 | { | ||
| 162 | printf("IGE test vector %d failed (with in == out)\n", n); | ||
| 163 | hexdump(stdout, "key", v->key, sizeof v->key); | ||
| 164 | hexdump(stdout, "iv", v->iv, sizeof v->iv); | ||
| 165 | hexdump(stdout, "in", v->in, v->length); | ||
| 166 | hexdump(stdout, "expected", v->out, v->length); | ||
| 167 | hexdump(stdout, "got", buf, v->length); | ||
| 168 | |||
| 169 | ++errs; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | return errs; | ||
| 174 | } | ||
| 175 | |||
| 176 | int main(int argc, char **argv) | ||
| 177 | { | ||
| 178 | unsigned char rkey[16]; | ||
| 179 | unsigned char rkey2[16]; | ||
| 180 | AES_KEY key; | ||
| 181 | AES_KEY key2; | ||
| 182 | unsigned char plaintext[BIG_TEST_SIZE]; | ||
| 183 | unsigned char ciphertext[BIG_TEST_SIZE]; | ||
| 184 | unsigned char checktext[BIG_TEST_SIZE]; | ||
| 185 | unsigned char iv[AES_BLOCK_SIZE*4]; | ||
| 186 | unsigned char saved_iv[AES_BLOCK_SIZE*4]; | ||
| 187 | int err = 0; | ||
| 188 | unsigned int n; | ||
| 189 | unsigned matches; | ||
| 190 | |||
| 191 | assert(BIG_TEST_SIZE >= TEST_SIZE); | ||
| 192 | |||
| 193 | arc4random_buf(rkey, sizeof(rkey)); | ||
| 194 | arc4random_buf(plaintext, sizeof(plaintext)); | ||
| 195 | arc4random_buf(iv, sizeof(iv)); | ||
| 196 | memcpy(saved_iv, iv, sizeof(saved_iv)); | ||
| 197 | |||
| 198 | /* Forward IGE only... */ | ||
| 199 | |||
| 200 | /* Straight encrypt/decrypt */ | ||
| 201 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 202 | AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE, &key, iv, | ||
| 203 | AES_ENCRYPT); | ||
| 204 | |||
| 205 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 206 | memcpy(iv, saved_iv, sizeof iv); | ||
| 207 | AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, | ||
| 208 | AES_DECRYPT); | ||
| 209 | |||
| 210 | if(memcmp(checktext, plaintext, TEST_SIZE)) | ||
| 211 | { | ||
| 212 | printf("Encrypt+decrypt doesn't match\n"); | ||
| 213 | hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); | ||
| 214 | hexdump(stdout, "Checktext", checktext, TEST_SIZE); | ||
| 215 | ++err; | ||
| 216 | } | ||
| 217 | |||
| 218 | /* Now check encrypt chaining works */ | ||
| 219 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 220 | memcpy(iv, saved_iv, sizeof iv); | ||
| 221 | AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv, | ||
| 222 | AES_ENCRYPT); | ||
| 223 | AES_ige_encrypt(plaintext+TEST_SIZE/2, | ||
| 224 | ciphertext+TEST_SIZE/2, TEST_SIZE/2, | ||
| 225 | &key, iv, AES_ENCRYPT); | ||
| 226 | |||
| 227 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 228 | memcpy(iv, saved_iv, sizeof iv); | ||
| 229 | AES_ige_encrypt(ciphertext, checktext, TEST_SIZE, &key, iv, | ||
| 230 | AES_DECRYPT); | ||
| 231 | |||
| 232 | if(memcmp(checktext, plaintext, TEST_SIZE)) | ||
| 233 | { | ||
| 234 | printf("Chained encrypt+decrypt doesn't match\n"); | ||
| 235 | hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); | ||
| 236 | hexdump(stdout, "Checktext", checktext, TEST_SIZE); | ||
| 237 | ++err; | ||
| 238 | } | ||
| 239 | |||
| 240 | /* And check decrypt chaining */ | ||
| 241 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 242 | memcpy(iv, saved_iv, sizeof iv); | ||
| 243 | AES_ige_encrypt(plaintext, ciphertext, TEST_SIZE/2, &key, iv, | ||
| 244 | AES_ENCRYPT); | ||
| 245 | AES_ige_encrypt(plaintext+TEST_SIZE/2, | ||
| 246 | ciphertext+TEST_SIZE/2, TEST_SIZE/2, | ||
| 247 | &key, iv, AES_ENCRYPT); | ||
| 248 | |||
| 249 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 250 | memcpy(iv, saved_iv, sizeof iv); | ||
| 251 | AES_ige_encrypt(ciphertext, checktext, TEST_SIZE/2, &key, iv, | ||
| 252 | AES_DECRYPT); | ||
| 253 | AES_ige_encrypt(ciphertext+TEST_SIZE/2, | ||
| 254 | checktext+TEST_SIZE/2, TEST_SIZE/2, &key, iv, | ||
| 255 | AES_DECRYPT); | ||
| 256 | |||
| 257 | if(memcmp(checktext, plaintext, TEST_SIZE)) | ||
| 258 | { | ||
| 259 | printf("Chained encrypt+chained decrypt doesn't match\n"); | ||
| 260 | hexdump(stdout, "Plaintext", plaintext, TEST_SIZE); | ||
| 261 | hexdump(stdout, "Checktext", checktext, TEST_SIZE); | ||
| 262 | ++err; | ||
| 263 | } | ||
| 264 | |||
| 265 | /* make sure garble extends forwards only */ | ||
| 266 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 267 | memcpy(iv, saved_iv, sizeof iv); | ||
| 268 | AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, | ||
| 269 | AES_ENCRYPT); | ||
| 270 | |||
| 271 | /* corrupt halfway through */ | ||
| 272 | ++ciphertext[sizeof ciphertext/2]; | ||
| 273 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 274 | memcpy(iv, saved_iv, sizeof iv); | ||
| 275 | AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, | ||
| 276 | AES_DECRYPT); | ||
| 277 | |||
| 278 | matches=0; | ||
| 279 | for(n=0 ; n < sizeof checktext ; ++n) | ||
| 280 | if(checktext[n] == plaintext[n]) | ||
| 281 | ++matches; | ||
| 282 | |||
| 283 | if(matches > sizeof checktext/2+sizeof checktext/100) | ||
| 284 | { | ||
| 285 | printf("More than 51%% matches after garbling\n"); | ||
| 286 | ++err; | ||
| 287 | } | ||
| 288 | |||
| 289 | if(matches < sizeof checktext/2) | ||
| 290 | { | ||
| 291 | printf("Garble extends backwards!\n"); | ||
| 292 | ++err; | ||
| 293 | } | ||
| 294 | |||
| 295 | /* make sure garble extends both ways */ | ||
| 296 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 297 | AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 298 | AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, | ||
| 299 | AES_ENCRYPT); | ||
| 300 | |||
| 301 | /* corrupt halfway through */ | ||
| 302 | ++ciphertext[sizeof ciphertext/2]; | ||
| 303 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 304 | AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 305 | AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, | ||
| 306 | AES_DECRYPT); | ||
| 307 | |||
| 308 | matches=0; | ||
| 309 | for(n=0 ; n < sizeof checktext ; ++n) | ||
| 310 | if(checktext[n] == plaintext[n]) | ||
| 311 | ++matches; | ||
| 312 | |||
| 313 | if(matches > sizeof checktext/100) | ||
| 314 | { | ||
| 315 | printf("More than 1%% matches after bidirectional garbling\n"); | ||
| 316 | ++err; | ||
| 317 | } | ||
| 318 | |||
| 319 | /* make sure garble extends both ways (2) */ | ||
| 320 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 321 | AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 322 | AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, | ||
| 323 | AES_ENCRYPT); | ||
| 324 | |||
| 325 | /* corrupt right at the end */ | ||
| 326 | ++ciphertext[sizeof ciphertext-1]; | ||
| 327 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 328 | AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 329 | AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, | ||
| 330 | AES_DECRYPT); | ||
| 331 | |||
| 332 | matches=0; | ||
| 333 | for(n=0 ; n < sizeof checktext ; ++n) | ||
| 334 | if(checktext[n] == plaintext[n]) | ||
| 335 | ++matches; | ||
| 336 | |||
| 337 | if(matches > sizeof checktext/100) | ||
| 338 | { | ||
| 339 | printf("More than 1%% matches after bidirectional garbling (2)\n"); | ||
| 340 | ++err; | ||
| 341 | } | ||
| 342 | |||
| 343 | /* make sure garble extends both ways (3) */ | ||
| 344 | AES_set_encrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 345 | AES_set_encrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 346 | AES_ige_encrypt(plaintext, ciphertext, sizeof plaintext, &key, iv, | ||
| 347 | AES_ENCRYPT); | ||
| 348 | |||
| 349 | /* corrupt right at the start */ | ||
| 350 | ++ciphertext[0]; | ||
| 351 | AES_set_decrypt_key(rkey, 8*sizeof rkey, &key); | ||
| 352 | AES_set_decrypt_key(rkey2, 8*sizeof rkey2, &key2); | ||
| 353 | AES_ige_encrypt(ciphertext, checktext, sizeof checktext, &key, iv, | ||
| 354 | AES_DECRYPT); | ||
| 355 | |||
| 356 | matches=0; | ||
| 357 | for(n=0 ; n < sizeof checktext ; ++n) | ||
| 358 | if(checktext[n] == plaintext[n]) | ||
| 359 | ++matches; | ||
| 360 | |||
| 361 | if(matches > sizeof checktext/100) | ||
| 362 | { | ||
| 363 | printf("More than 1%% matches after bidirectional garbling (3)\n"); | ||
| 364 | ++err; | ||
| 365 | } | ||
| 366 | |||
| 367 | err += run_test_vectors(); | ||
| 368 | |||
| 369 | return err; | ||
| 370 | } | ||
diff --git a/src/regress/lib/libcrypto/init/Makefile b/src/regress/lib/libcrypto/init/Makefile deleted file mode 100644 index 33b0a2aa76..0000000000 --- a/src/regress/lib/libcrypto/init/Makefile +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2018/03/19 14:34:33 beck Exp $ | ||
| 2 | PROG= init_pledge | ||
| 3 | SRCS+= init_pledge.c | ||
| 4 | NOMAN= yes | ||
| 5 | |||
| 6 | LDADD+= -lcrypto -lutil | ||
| 7 | CFLAGS+= -Wall -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS+= test_normal | ||
| 10 | |||
| 11 | test_normal: ${PROG} | ||
| 12 | ./${PROG} | ||
| 13 | |||
| 14 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/init/init_pledge.c b/src/regress/lib/libcrypto/init/init_pledge.c deleted file mode 100644 index 76f5668ab8..0000000000 --- a/src/regress/lib/libcrypto/init/init_pledge.c +++ /dev/null | |||
| @@ -1,34 +0,0 @@ | |||
| 1 | /* $OpenBSD: init_pledge.c,v 1.1 2018/03/19 14:34:33 beck Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> | ||
| 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 <openssl/err.h> | ||
| 20 | |||
| 21 | #include <stdio.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | |||
| 24 | |||
| 25 | int | ||
| 26 | main (int argc, char *argv[]) | ||
| 27 | { | ||
| 28 | pledge("stdio", NULL); | ||
| 29 | |||
| 30 | ERR_load_ERR_strings(); | ||
| 31 | printf("[SUCCESS] - crypto autoinit is pledge(\"stdio\") safe\n"); | ||
| 32 | |||
| 33 | exit(0); | ||
| 34 | } | ||
diff --git a/src/regress/lib/libcrypto/md4/Makefile b/src/regress/lib/libcrypto/md4/Makefile deleted file mode 100644 index ddb4acf2d1..0000000000 --- a/src/regress/lib/libcrypto/md4/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2015/09/14 01:45:03 doug Exp $ | ||
| 2 | |||
| 3 | PROG= md4test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/md4/md4test.c b/src/regress/lib/libcrypto/md4/md4test.c deleted file mode 100644 index 7279e40f16..0000000000 --- a/src/regress/lib/libcrypto/md4/md4test.c +++ /dev/null | |||
| @@ -1,125 +0,0 @@ | |||
| 1 | /* $OpenBSD: md4test.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/md4.h> | ||
| 65 | |||
| 66 | static char *test[]={ | ||
| 67 | "", | ||
| 68 | "a", | ||
| 69 | "abc", | ||
| 70 | "message digest", | ||
| 71 | "abcdefghijklmnopqrstuvwxyz", | ||
| 72 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
| 73 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
| 74 | NULL, | ||
| 75 | }; | ||
| 76 | |||
| 77 | static char *ret[]={ | ||
| 78 | "31d6cfe0d16ae931b73c59d7e0c089c0", | ||
| 79 | "bde52cb31de33e46245e05fbdbd6fb24", | ||
| 80 | "a448017aaf21d8525fc10ae87aa6729d", | ||
| 81 | "d9130a8164549fe818874806e1c7014b", | ||
| 82 | "d79e1c308aa5bbcdeea8ed63df412da9", | ||
| 83 | "043f8582f241db351ce627e153e7f0e4", | ||
| 84 | "e33b4ddc9c38f2199c3e7b164fcc0536", | ||
| 85 | }; | ||
| 86 | |||
| 87 | static char *pt(unsigned char *md); | ||
| 88 | int main(int argc, char *argv[]) | ||
| 89 | { | ||
| 90 | int i,err=0; | ||
| 91 | char **P,**R; | ||
| 92 | char *p; | ||
| 93 | unsigned char md[MD4_DIGEST_LENGTH]; | ||
| 94 | |||
| 95 | P=test; | ||
| 96 | R=ret; | ||
| 97 | i=1; | ||
| 98 | while (*P != NULL) | ||
| 99 | { | ||
| 100 | EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md4(), NULL); | ||
| 101 | p=pt(md); | ||
| 102 | if (strcmp(p,(char *)*R) != 0) | ||
| 103 | { | ||
| 104 | printf("error calculating MD4 on '%s'\n",*P); | ||
| 105 | printf("got %s instead of %s\n",p,*R); | ||
| 106 | err++; | ||
| 107 | } | ||
| 108 | else | ||
| 109 | printf("test %d ok\n",i); | ||
| 110 | i++; | ||
| 111 | R++; | ||
| 112 | P++; | ||
| 113 | } | ||
| 114 | exit(err); | ||
| 115 | } | ||
| 116 | |||
| 117 | static char *pt(unsigned char *md) | ||
| 118 | { | ||
| 119 | int i; | ||
| 120 | static char buf[80]; | ||
| 121 | |||
| 122 | for (i=0; i<MD4_DIGEST_LENGTH; i++) | ||
| 123 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x",md[i]); | ||
| 124 | return(buf); | ||
| 125 | } | ||
diff --git a/src/regress/lib/libcrypto/md5/Makefile b/src/regress/lib/libcrypto/md5/Makefile deleted file mode 100644 index d620dfa48a..0000000000 --- a/src/regress/lib/libcrypto/md5/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= md5test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/md5/md5test.c b/src/regress/lib/libcrypto/md5/md5test.c deleted file mode 100644 index 92b1b4a273..0000000000 --- a/src/regress/lib/libcrypto/md5/md5test.c +++ /dev/null | |||
| @@ -1,126 +0,0 @@ | |||
| 1 | /* $OpenBSD: md5test.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/md5.h> | ||
| 65 | |||
| 66 | static char *test[]={ | ||
| 67 | "", | ||
| 68 | "a", | ||
| 69 | "abc", | ||
| 70 | "message digest", | ||
| 71 | "abcdefghijklmnopqrstuvwxyz", | ||
| 72 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
| 73 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
| 74 | NULL, | ||
| 75 | }; | ||
| 76 | |||
| 77 | static char *ret[]={ | ||
| 78 | "d41d8cd98f00b204e9800998ecf8427e", | ||
| 79 | "0cc175b9c0f1b6a831c399e269772661", | ||
| 80 | "900150983cd24fb0d6963f7d28e17f72", | ||
| 81 | "f96b697d7cb7938d525a2f31aaf161d0", | ||
| 82 | "c3fcd3d76192e4007dfb496cca67e13b", | ||
| 83 | "d174ab98d277d9f5a5611c2c9f419d9f", | ||
| 84 | "57edf4a22be3c955ac49da2e2107b67a", | ||
| 85 | }; | ||
| 86 | |||
| 87 | static char *pt(unsigned char *md); | ||
| 88 | int main(int argc, char *argv[]) | ||
| 89 | { | ||
| 90 | int i,err=0; | ||
| 91 | char **P,**R; | ||
| 92 | char *p; | ||
| 93 | unsigned char md[MD5_DIGEST_LENGTH]; | ||
| 94 | |||
| 95 | P=test; | ||
| 96 | R=ret; | ||
| 97 | i=1; | ||
| 98 | while (*P != NULL) | ||
| 99 | { | ||
| 100 | EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_md5(), NULL); | ||
| 101 | p=pt(md); | ||
| 102 | if (strcmp(p,(char *)*R) != 0) | ||
| 103 | { | ||
| 104 | printf("error calculating MD5 on '%s'\n",*P); | ||
| 105 | printf("got %s instead of %s\n",p,*R); | ||
| 106 | err++; | ||
| 107 | } | ||
| 108 | else | ||
| 109 | printf("test %d ok\n",i); | ||
| 110 | i++; | ||
| 111 | R++; | ||
| 112 | P++; | ||
| 113 | } | ||
| 114 | |||
| 115 | exit(err); | ||
| 116 | } | ||
| 117 | |||
| 118 | static char *pt(unsigned char *md) | ||
| 119 | { | ||
| 120 | int i; | ||
| 121 | static char buf[80]; | ||
| 122 | |||
| 123 | for (i=0; i<MD5_DIGEST_LENGTH; i++) | ||
| 124 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x",md[i]); | ||
| 125 | return(buf); | ||
| 126 | } | ||
diff --git a/src/regress/lib/libcrypto/ocsp/Makefile b/src/regress/lib/libcrypto/ocsp/Makefile deleted file mode 100644 index 62fb985647..0000000000 --- a/src/regress/lib/libcrypto/ocsp/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2016/11/05 12:45:25 miod Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS= all_tests | ||
| 4 | |||
| 5 | PROG= ocsp_test | ||
| 6 | LDADD= -lcrypto -lssl | ||
| 7 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 8 | WARNINGS= Yes | ||
| 9 | LDFLAGS+= -lcrypto -lssl | ||
| 10 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
| 11 | |||
| 12 | all_tests: ${PROG} | ||
| 13 | ${.OBJDIR}/${PROG} www.amazon.com 443 | ||
| 14 | ${.OBJDIR}/${PROG} cloudflare.com 443 | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/ocsp/ocsp_test.c b/src/regress/lib/libcrypto/ocsp/ocsp_test.c deleted file mode 100644 index 5914729828..0000000000 --- a/src/regress/lib/libcrypto/ocsp/ocsp_test.c +++ /dev/null | |||
| @@ -1,154 +0,0 @@ | |||
| 1 | /* $OpenBSD: ocsp_test.c,v 1.6 2018/07/18 16:24:16 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2016 Bob Beck <beck@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdio.h> | ||
| 19 | #include <netdb.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <unistd.h> | ||
| 22 | #include <err.h> | ||
| 23 | #include <sys/socket.h> | ||
| 24 | |||
| 25 | #include <openssl/ssl.h> | ||
| 26 | #include <openssl/ocsp.h> | ||
| 27 | |||
| 28 | static int | ||
| 29 | tcp_connect(char *host, char *port) | ||
| 30 | { | ||
| 31 | int error, sd = -1; | ||
| 32 | struct addrinfo hints, *res, *r; | ||
| 33 | |||
| 34 | memset(&hints, 0, sizeof(struct addrinfo)); | ||
| 35 | hints.ai_family = AF_INET; | ||
| 36 | hints.ai_socktype = SOCK_STREAM; | ||
| 37 | |||
| 38 | error = getaddrinfo(host, port, &hints, &res); | ||
| 39 | if (error != 0) { | ||
| 40 | perror("getaddrinfo()"); | ||
| 41 | exit(-1); | ||
| 42 | } | ||
| 43 | |||
| 44 | for (r = res; r != NULL; r = r->ai_next) { | ||
| 45 | sd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); | ||
| 46 | if (sd == -1) | ||
| 47 | continue; | ||
| 48 | |||
| 49 | if (connect(sd, r->ai_addr, r->ai_addrlen) == 0) | ||
| 50 | break; | ||
| 51 | |||
| 52 | close(sd); | ||
| 53 | } | ||
| 54 | |||
| 55 | freeaddrinfo(res); | ||
| 56 | |||
| 57 | return sd; | ||
| 58 | } | ||
| 59 | |||
| 60 | int | ||
| 61 | main(int argc, char *argv[]) | ||
| 62 | { | ||
| 63 | int sd, ocsp_status; | ||
| 64 | const unsigned char *p; | ||
| 65 | long len; | ||
| 66 | OCSP_RESPONSE *rsp = NULL; | ||
| 67 | OCSP_BASICRESP *br = NULL; | ||
| 68 | X509_STORE *st = NULL; | ||
| 69 | STACK_OF(X509) *ch = NULL; | ||
| 70 | char *host, *port; | ||
| 71 | #ifdef _PATH_SSL_CA_FILE | ||
| 72 | char *cafile = _PATH_SSL_CA_FILE; | ||
| 73 | #else | ||
| 74 | char *cafile = "/etc/ssl/cert.pem"; | ||
| 75 | #endif | ||
| 76 | |||
| 77 | SSL *ssl; | ||
| 78 | SSL_CTX *ctx; | ||
| 79 | |||
| 80 | SSL_library_init(); | ||
| 81 | SSL_load_error_strings(); | ||
| 82 | |||
| 83 | ctx = SSL_CTX_new(SSLv23_client_method()); | ||
| 84 | |||
| 85 | if (!SSL_CTX_load_verify_locations(ctx, cafile, NULL)) { | ||
| 86 | printf("failed to load %s\n", cafile); | ||
| 87 | exit(-1); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (argc != 3) | ||
| 91 | errx(-1, "need a host and port to connect to"); | ||
| 92 | else { | ||
| 93 | host = argv[1]; | ||
| 94 | port = argv[2]; | ||
| 95 | } | ||
| 96 | |||
| 97 | sd = tcp_connect(host, port); | ||
| 98 | |||
| 99 | ssl = SSL_new(ctx); | ||
| 100 | |||
| 101 | SSL_set_fd(ssl, (int) sd); | ||
| 102 | SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp); | ||
| 103 | |||
| 104 | if (SSL_connect(ssl) <= 0) { | ||
| 105 | printf("SSL connect error\n"); | ||
| 106 | exit(-1); | ||
| 107 | } | ||
| 108 | |||
| 109 | if (SSL_get_verify_result(ssl) != X509_V_OK) { | ||
| 110 | printf("Certificate doesn't verify from host %s port %s\n", host, port); | ||
| 111 | exit(-1); | ||
| 112 | } | ||
| 113 | |||
| 114 | /* ==== VERIFY OCSP RESPONSE ==== */ | ||
| 115 | |||
| 116 | |||
| 117 | len = SSL_get_tlsext_status_ocsp_resp(ssl, &p); | ||
| 118 | |||
| 119 | if (!p) { | ||
| 120 | printf("No OCSP response received for %s port %s\n", host, port); | ||
| 121 | exit(-1); | ||
| 122 | } | ||
| 123 | |||
| 124 | rsp = d2i_OCSP_RESPONSE(NULL, &p, len); | ||
| 125 | if (!rsp) { | ||
| 126 | puts("Invalid OCSP response"); | ||
| 127 | exit(-1); | ||
| 128 | } | ||
| 129 | |||
| 130 | ocsp_status = OCSP_response_status(rsp); | ||
| 131 | if (ocsp_status != OCSP_RESPONSE_STATUS_SUCCESSFUL) { | ||
| 132 | printf("Invalid OCSP response status: %s (%d)", | ||
| 133 | OCSP_response_status_str(ocsp_status), ocsp_status); | ||
| 134 | exit(-1); | ||
| 135 | } | ||
| 136 | |||
| 137 | br = OCSP_response_get1_basic(rsp); | ||
| 138 | if (!br) { | ||
| 139 | puts("Invalid OCSP response"); | ||
| 140 | exit(-1); | ||
| 141 | } | ||
| 142 | |||
| 143 | ch = SSL_get_peer_cert_chain(ssl); | ||
| 144 | st = SSL_CTX_get_cert_store(ctx); | ||
| 145 | |||
| 146 | if (OCSP_basic_verify(br, ch, st, 0) <= 0) { | ||
| 147 | puts("OCSP response verification failed"); | ||
| 148 | exit(-1); | ||
| 149 | } | ||
| 150 | |||
| 151 | printf("OCSP validated from %s %s\n", host, port); | ||
| 152 | |||
| 153 | return 0; | ||
| 154 | } | ||
diff --git a/src/regress/lib/libcrypto/pbkdf2/Makefile b/src/regress/lib/libcrypto/pbkdf2/Makefile deleted file mode 100644 index 7f39430aa3..0000000000 --- a/src/regress/lib/libcrypto/pbkdf2/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/07/11 20:37:59 miod Exp $ | ||
| 2 | |||
| 3 | PROG= pbkdf2 | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/pbkdf2/pbkdf2.c b/src/regress/lib/libcrypto/pbkdf2/pbkdf2.c deleted file mode 100644 index 9cbc031821..0000000000 --- a/src/regress/lib/libcrypto/pbkdf2/pbkdf2.c +++ /dev/null | |||
| @@ -1,214 +0,0 @@ | |||
| 1 | /* $OpenBSD: pbkdf2.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Written by Christian Heimes, 2013 */ | ||
| 3 | /* | ||
| 4 | * Copyright (c) 2013 The OpenSSL Project. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * | ||
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer in | ||
| 15 | * the documentation and/or other materials provided with the | ||
| 16 | * distribution. | ||
| 17 | * | ||
| 18 | * 3. All advertising materials mentioning features or use of this | ||
| 19 | * software must display the following acknowledgment: | ||
| 20 | * "This product includes software developed by the OpenSSL Project | ||
| 21 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 22 | * | ||
| 23 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 24 | * endorse or promote products derived from this software without | ||
| 25 | * prior written permission. For written permission, please contact | ||
| 26 | * openssl-core@openssl.org. | ||
| 27 | * | ||
| 28 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 29 | * nor may "OpenSSL" appear in their names without prior written | ||
| 30 | * permission of the OpenSSL Project. | ||
| 31 | * | ||
| 32 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 33 | * acknowledgment: | ||
| 34 | * "This product includes software developed by the OpenSSL Project | ||
| 35 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 36 | * | ||
| 37 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 38 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 40 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 41 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 43 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 44 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 45 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 46 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 47 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 48 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 49 | */ | ||
| 50 | |||
| 51 | |||
| 52 | #include <stdio.h> | ||
| 53 | #include <stdlib.h> | ||
| 54 | #include <string.h> | ||
| 55 | #include <errno.h> | ||
| 56 | |||
| 57 | #include <openssl/opensslconf.h> | ||
| 58 | #include <openssl/evp.h> | ||
| 59 | #ifndef OPENSSL_NO_ENGINE | ||
| 60 | #include <openssl/engine.h> | ||
| 61 | #endif | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/conf.h> | ||
| 64 | |||
| 65 | typedef struct { | ||
| 66 | const char *pass; | ||
| 67 | int passlen; | ||
| 68 | const char *salt; | ||
| 69 | int saltlen; | ||
| 70 | int iter; | ||
| 71 | } testdata; | ||
| 72 | |||
| 73 | static const testdata test_cases[] = { | ||
| 74 | {"password", 8, "salt", 4, 1}, | ||
| 75 | {"password", 8, "salt", 4, 2}, | ||
| 76 | {"password", 8, "salt", 4, 4096}, | ||
| 77 | {"passwordPASSWORDpassword", 24, | ||
| 78 | "saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096}, | ||
| 79 | {"pass\0word", 9, "sa\0lt", 5, 4096}, | ||
| 80 | {NULL}, | ||
| 81 | }; | ||
| 82 | |||
| 83 | static const char *sha1_results[] = { | ||
| 84 | "0c60c80f961f0e71f3a9b524af6012062fe037a6", | ||
| 85 | "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957", | ||
| 86 | "4b007901b765489abead49d926f721d065a429c1", | ||
| 87 | "3d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038", | ||
| 88 | "56fa6aa75548099dcc37d7f03425e0c3", | ||
| 89 | }; | ||
| 90 | |||
| 91 | static const char *sha256_results[] = { | ||
| 92 | "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b", | ||
| 93 | "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43", | ||
| 94 | "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a", | ||
| 95 | "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c63551" | ||
| 96 | "8c7dac47e9", | ||
| 97 | "89b69d0516f829893c696226650a8687", | ||
| 98 | }; | ||
| 99 | |||
| 100 | static const char *sha512_results[] = { | ||
| 101 | "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d47" | ||
| 102 | "0a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce", | ||
| 103 | "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab" | ||
| 104 | "2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e", | ||
| 105 | "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30" | ||
| 106 | "602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5", | ||
| 107 | "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59" | ||
| 108 | "f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8", | ||
| 109 | "9d9e9c4cd21fe4be24d5b8244c759665", | ||
| 110 | }; | ||
| 111 | |||
| 112 | static void | ||
| 113 | hexdump(FILE *f, const char *title, const unsigned char *s, size_t len) | ||
| 114 | { | ||
| 115 | fprintf(f, "%s", title); | ||
| 116 | for (; len != 0; len--) | ||
| 117 | fprintf(f, " 0x%02x", *(s++)); | ||
| 118 | fprintf(f, "\n"); | ||
| 119 | } | ||
| 120 | |||
| 121 | static int | ||
| 122 | convert(unsigned char *dst, const unsigned char *src, size_t len) | ||
| 123 | { | ||
| 124 | unsigned int n; | ||
| 125 | |||
| 126 | for (; len != 0; src += 2, len--) { | ||
| 127 | if (sscanf((char *)src, "%2x", &n) != 1) | ||
| 128 | return EINVAL; | ||
| 129 | *dst++ = (unsigned char)n; | ||
| 130 | } | ||
| 131 | return 0; | ||
| 132 | } | ||
| 133 | |||
| 134 | static void | ||
| 135 | test_p5_pbkdf2(unsigned int n, const char *digestname, const testdata *test, | ||
| 136 | const char *hex) | ||
| 137 | { | ||
| 138 | const EVP_MD *digest; | ||
| 139 | unsigned char *out; | ||
| 140 | unsigned char *expected; | ||
| 141 | size_t keylen; | ||
| 142 | int r; | ||
| 143 | |||
| 144 | digest = EVP_get_digestbyname(digestname); | ||
| 145 | if (digest == NULL) { | ||
| 146 | fprintf(stderr, "unknown digest %s\n", digestname); | ||
| 147 | exit(5); | ||
| 148 | } | ||
| 149 | |||
| 150 | keylen = strlen(hex); | ||
| 151 | if ((keylen % 2) != 0) { | ||
| 152 | fprintf(stderr, "odd hex string %s, digest %u\n", digestname, n); | ||
| 153 | exit(5); | ||
| 154 | } | ||
| 155 | keylen /= 2; | ||
| 156 | expected = malloc(keylen); | ||
| 157 | out = malloc(keylen); | ||
| 158 | if (expected == NULL || out == NULL) { | ||
| 159 | fprintf(stderr, "malloc() failed\n"); | ||
| 160 | exit(5); | ||
| 161 | } | ||
| 162 | if (convert(expected, (const unsigned char *)hex, keylen) != 0) { | ||
| 163 | fprintf(stderr, "invalid hex string %s, digest %u\n", hex, n); | ||
| 164 | exit(5); | ||
| 165 | } | ||
| 166 | |||
| 167 | r = PKCS5_PBKDF2_HMAC(test->pass, test->passlen, | ||
| 168 | (const unsigned char *)test->salt, test->saltlen, | ||
| 169 | test->iter, digest, keylen, out); | ||
| 170 | |||
| 171 | if (r == 0) { | ||
| 172 | fprintf(stderr, "PKCS5_PBKDF2_HMAC(%s) failure test %u\n", | ||
| 173 | digestname, n); | ||
| 174 | exit(3); | ||
| 175 | } | ||
| 176 | if (memcmp(expected, out, keylen) != 0) { | ||
| 177 | fprintf(stderr, | ||
| 178 | "Wrong result for PKCS5_PBKDF2_HMAC(%s) test %u\n", | ||
| 179 | digestname, n); | ||
| 180 | hexdump(stderr, "expected: ", expected, keylen); | ||
| 181 | hexdump(stderr, "result: ", out, keylen); | ||
| 182 | exit(2); | ||
| 183 | } | ||
| 184 | free(expected); | ||
| 185 | free(out); | ||
| 186 | } | ||
| 187 | |||
| 188 | int | ||
| 189 | main(int argc,char **argv) | ||
| 190 | { | ||
| 191 | unsigned int n; | ||
| 192 | const testdata *test = test_cases; | ||
| 193 | |||
| 194 | OpenSSL_add_all_digests(); | ||
| 195 | #ifndef OPENSSL_NO_ENGINE | ||
| 196 | ENGINE_load_builtin_engines(); | ||
| 197 | ENGINE_register_all_digests(); | ||
| 198 | #endif | ||
| 199 | |||
| 200 | for (n = 0; test->pass != NULL; n++, test++) { | ||
| 201 | test_p5_pbkdf2(n, "sha1", test, sha1_results[n]); | ||
| 202 | test_p5_pbkdf2(n, "sha256", test, sha256_results[n]); | ||
| 203 | test_p5_pbkdf2(n, "sha512", test, sha512_results[n]); | ||
| 204 | } | ||
| 205 | |||
| 206 | #ifndef OPENSSL_NO_ENGINE | ||
| 207 | ENGINE_cleanup(); | ||
| 208 | #endif | ||
| 209 | EVP_cleanup(); | ||
| 210 | CRYPTO_cleanup_all_ex_data(); | ||
| 211 | ERR_remove_thread_state(NULL); | ||
| 212 | ERR_free_strings(); | ||
| 213 | return 0; | ||
| 214 | } | ||
diff --git a/src/regress/lib/libcrypto/pkcs7/Makefile b/src/regress/lib/libcrypto/pkcs7/Makefile deleted file mode 100644 index aceb169e16..0000000000 --- a/src/regress/lib/libcrypto/pkcs7/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= pkcs7test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/pkcs7/pkcs7test.c b/src/regress/lib/libcrypto/pkcs7/pkcs7test.c deleted file mode 100644 index 5548307375..0000000000 --- a/src/regress/lib/libcrypto/pkcs7/pkcs7test.c +++ /dev/null | |||
| @@ -1,289 +0,0 @@ | |||
| 1 | /* $OpenBSD: pkcs7test.c,v 1.3 2014/11/26 05:48:00 bcook Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdlib.h> | ||
| 20 | #include <string.h> | ||
| 21 | #include <unistd.h> | ||
| 22 | |||
| 23 | #include <openssl/bio.h> | ||
| 24 | #include <openssl/err.h> | ||
| 25 | #include <openssl/evp.h> | ||
| 26 | #include <openssl/pem.h> | ||
| 27 | #include <openssl/pkcs7.h> | ||
| 28 | #include <openssl/x509.h> | ||
| 29 | |||
| 30 | const char certificate[] = "\ | ||
| 31 | -----BEGIN CERTIFICATE----- \n\ | ||
| 32 | MIIDpTCCAo2gAwIBAgIJAPYm3GvOr5eTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV \n\ | ||
| 33 | BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT \n\ | ||
| 34 | VElORyBQVVJQT1NFUyBPTkxZMSUwIwYDVQQDDBxPcGVuU1NMIFRlc3QgSW50ZXJt \n\ | ||
| 35 | ZWRpYXRlIENBMB4XDTE0MDUyNDE0NDUxMVoXDTI0MDQwMTE0NDUxMVowZDELMAkG \n\ | ||
| 36 | A1UEBhMCVUsxFjAUBgNVBAoMDU9wZW5TU0wgR3JvdXAxIjAgBgNVBAsMGUZPUiBU \n\ | ||
| 37 | RVNUSU5HIFBVUlBPU0VTIE9OTFkxGTAXBgNVBAMMEFRlc3QgQ2xpZW50IENlcnQw \n\ | ||
| 38 | ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0ranbHRLcLVqN+0BzcZpY \n\ | ||
| 39 | +yOLqxzDWT1LD9eW1stC4NzXX9/DCtSIVyN7YIHdGLrIPr64IDdXXaMRzgZ2rOKs \n\ | ||
| 40 | lmHCAiFpO/ja99gGCJRxH0xwQatqAULfJVHeUhs7OEGOZc2nWifjqKvGfNTilP7D \n\ | ||
| 41 | nwi69ipQFq9oS19FmhwVHk2wg7KZGHI1qDyG04UrfCZMRitvS9+UVhPpIPjuiBi2 \n\ | ||
| 42 | x3/FZIpL5gXJvvFK6xHY63oq2asyzBATntBgnP4qJFWWcvRx24wF1PnZabxuVoL2 \n\ | ||
| 43 | bPnQ/KvONDrw3IdqkKhYNTul7jEcu3OlcZIMw+7DiaKJLAzKb/bBF5gm/pwW6As9 \n\ | ||
| 44 | AgMBAAGjTjBMMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCwGCWCGSAGG \n\ | ||
| 45 | +EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTANBgkqhkiG9w0B \n\ | ||
| 46 | AQUFAAOCAQEAJzA4KTjkjXGSC4He63yX9Br0DneGBzjAwc1H6f72uqnCs8m7jgkE \n\ | ||
| 47 | PQJFdTzQUKh97QPUuayZ2gl8XHagg+iWGy60Kw37gQ0+lumCN2sllvifhHU9R03H \n\ | ||
| 48 | bWtS4kue+yQjMbrzf3zWygMDgwvFOUAIgBpH9qGc+CdNu97INTYd0Mvz51vLlxRn \n\ | ||
| 49 | sC5aBYCWaZFnw3lWYxf9eVFRy9U+DkYFqX0LpmbDtcKP7AZGE6ZwSzaim+Cnoz1u \n\ | ||
| 50 | Cgn+QmpFXgJKMFIZ82iSZISn+JkCCGxctZX1lMvai4Wi8Y0HxW9FTFZ6KBNwwE4B \n\ | ||
| 51 | zjbN/ehBkgLlW/DWfi44DvwUHmuU6QP3cw== \n\ | ||
| 52 | -----END CERTIFICATE----- \n\ | ||
| 53 | "; | ||
| 54 | |||
| 55 | const char private_key[] = "\ | ||
| 56 | -----BEGIN RSA PRIVATE KEY----- \n\ | ||
| 57 | MIIEpQIBAAKCAQEAtK2p2x0S3C1ajftAc3GaWPsji6scw1k9Sw/XltbLQuDc11/f \n\ | ||
| 58 | wwrUiFcje2CB3Ri6yD6+uCA3V12jEc4GdqzirJZhwgIhaTv42vfYBgiUcR9McEGr \n\ | ||
| 59 | agFC3yVR3lIbOzhBjmXNp1on46irxnzU4pT+w58IuvYqUBavaEtfRZocFR5NsIOy \n\ | ||
| 60 | mRhyNag8htOFK3wmTEYrb0vflFYT6SD47ogYtsd/xWSKS+YFyb7xSusR2Ot6Ktmr \n\ | ||
| 61 | MswQE57QYJz+KiRVlnL0cduMBdT52Wm8blaC9mz50PyrzjQ68NyHapCoWDU7pe4x \n\ | ||
| 62 | HLtzpXGSDMPuw4miiSwMym/2wReYJv6cFugLPQIDAQABAoIBAAZOyc9MhIwLSU4L \n\ | ||
| 63 | p4RgQvM4UVVe8/Id+3XTZ8NsXExJbWxXfIhiqGjaIfL8u4vsgRjcl+v1s/jo2/iT \n\ | ||
| 64 | KMab4o4D8gXD7UavQVDjtjb/ta79WL3SjRl2Uc9YjjMkyq6WmDNQeo2NKDdafCTB \n\ | ||
| 65 | 1uzSJtLNipB8Z53ELPuHJhxX9QMHrMnuha49riQgXZ7buP9iQrHJFhImBjSzbxJx \n\ | ||
| 66 | L+TI6rkyLSf9Wi0Pd3L27Ob3QWNfNRYNSeTE+08eSRChkur5W0RuXAcuAICdQlCl \n\ | ||
| 67 | LBvWO/LmmvbzCqiDcgy/TliSb6CGGwgiNG7LJZmlkYNj8laGwalNlYZs3UrVv6NO \n\ | ||
| 68 | Br2loAECgYEA2kvCvPGj0Dg/6g7WhXDvAkEbcaL1tSeCxBbNH+6HS2UWMWvyTtCn \n\ | ||
| 69 | /bbD519QIdkvayy1QjEf32GV/UjUVmlULMLBcDy0DGjtL3+XpIhLKWDNxN1v1/ai \n\ | ||
| 70 | 1oz23ZJCOgnk6K4qtFtlRS1XtynjA+rBetvYvLP9SKeFrnpzCgaA2r0CgYEA0+KX \n\ | ||
| 71 | 1ACXDTNH5ySX3kMjSS9xdINf+OOw4CvPHFwbtc9aqk2HePlEsBTz5I/W3rKwXva3 \n\ | ||
| 72 | NqZ/bRqVVeZB/hHKFywgdUQk2Uc5z/S7Lw70/w1HubNTXGU06Ngb6zOFAo/o/TwZ \n\ | ||
| 73 | zTP1BMIKSOB6PAZPS3l+aLO4FRIRotfFhgRHOoECgYEAmiZbqt8cJaJDB/5YYDzC \n\ | ||
| 74 | mp3tSk6gIb936Q6M5VqkMYp9pIKsxhk0N8aDCnTU+kIK6SzWBpr3/d9Ecmqmfyq7 \n\ | ||
| 75 | 5SvWO3KyVf0WWK9KH0abhOm2BKm2HBQvI0DB5u8sUx2/hsvOnjPYDISbZ11t0MtK \n\ | ||
| 76 | u35Zy89yMYcSsIYJjG/ROCUCgYEAgI2P9G5PNxEP5OtMwOsW84Y3Xat/hPAQFlI+ \n\ | ||
| 77 | HES+AzbFGWJkeT8zL2nm95tVkFP1sggZ7Kxjz3w7cpx7GX0NkbWSE9O+T51pNASV \n\ | ||
| 78 | tN1sQ3p5M+/a+cnlqgfEGJVvc7iAcXQPa3LEi5h2yPR49QYXAgG6cifn3dDSpmwn \n\ | ||
| 79 | SUI7PQECgYEApGCIIpSRPLAEHTGmP87RBL1smurhwmy2s/pghkvUkWehtxg0sGHh \n\ | ||
| 80 | kuaqDWcskogv+QC0sVdytiLSz8G0DwcEcsHK1Fkyb8A+ayiw6jWJDo2m9+IF4Fww \n\ | ||
| 81 | 1Te6jFPYDESnbhq7+TLGgHGhtwcu5cnb4vSuYXGXKupZGzoLOBbv1Zw= \n\ | ||
| 82 | -----END RSA PRIVATE KEY----- \n\ | ||
| 83 | "; | ||
| 84 | |||
| 85 | const char message[] = "\ | ||
| 86 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do \r\n\ | ||
| 87 | eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut \r\n\ | ||
| 88 | enim ad minim veniam, quis nostrud exercitation ullamco laboris \r\n\ | ||
| 89 | nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor \r\n\ | ||
| 90 | in reprehenderit in voluptate velit esse cillum dolore eu fugiat \r\n\ | ||
| 91 | nulla pariatur. Excepteur sint occaecat cupidatat non proident, \r\n\ | ||
| 92 | sunt in culpa qui officia deserunt mollit anim id est laborum. \r\n\ | ||
| 93 | "; | ||
| 94 | |||
| 95 | static int | ||
| 96 | x509_store_callback(int ok, X509_STORE_CTX *ctx) | ||
| 97 | { | ||
| 98 | /* Pretend the certificate issuer is valid... */ | ||
| 99 | return 1; | ||
| 100 | } | ||
| 101 | |||
| 102 | static void | ||
| 103 | fatal(const char *msg) | ||
| 104 | { | ||
| 105 | warnx("%s", msg); | ||
| 106 | ERR_print_errors(BIO_new_fd(STDERR_FILENO, 0)); | ||
| 107 | exit(1); | ||
| 108 | } | ||
| 109 | |||
| 110 | static void | ||
| 111 | message_compare(const char *out, size_t len) | ||
| 112 | { | ||
| 113 | if (len != sizeof(message)) { | ||
| 114 | fprintf(stderr, "FAILURE: length mismatch (%zu != %zu)\n", | ||
| 115 | len, sizeof(message)); | ||
| 116 | exit(1); | ||
| 117 | } | ||
| 118 | if (memcmp(out, message, len) != 0) { | ||
| 119 | fprintf(stderr, "FAILURE: message mismatch\n"); | ||
| 120 | fprintf(stderr, "Got:\n%s\n", out); | ||
| 121 | fprintf(stderr, "Want:\n%s\n", message); | ||
| 122 | exit(1); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | int | ||
| 127 | main(int argc, char **argv) | ||
| 128 | { | ||
| 129 | BIO *bio_in, *bio_content, *bio_out, *bio_cert, *bio_pkey; | ||
| 130 | STACK_OF(X509) *certs; | ||
| 131 | const EVP_CIPHER *cipher; | ||
| 132 | EVP_PKEY *pkey; | ||
| 133 | X509_STORE *store; | ||
| 134 | X509 *cert; | ||
| 135 | PKCS7 *p7; | ||
| 136 | size_t len; | ||
| 137 | char *out; | ||
| 138 | int flags; | ||
| 139 | |||
| 140 | ERR_load_crypto_strings(); | ||
| 141 | OpenSSL_add_all_algorithms(); | ||
| 142 | |||
| 143 | /* | ||
| 144 | * A bunch of setup... | ||
| 145 | */ | ||
| 146 | cipher = EVP_aes_256_cbc(); | ||
| 147 | if (cipher == NULL) | ||
| 148 | fatal("cipher"); | ||
| 149 | |||
| 150 | certs = sk_X509_new_null(); | ||
| 151 | if (certs == NULL) | ||
| 152 | fatal("sk_X509_new_null"); | ||
| 153 | |||
| 154 | bio_cert = BIO_new_mem_buf((char *)certificate, sizeof(certificate)); | ||
| 155 | if (bio_cert == NULL) | ||
| 156 | fatal("BIO_new_mem_buf certificate"); | ||
| 157 | |||
| 158 | cert = PEM_read_bio_X509_AUX(bio_cert, NULL, NULL, NULL); | ||
| 159 | if (cert == NULL) | ||
| 160 | fatal("PEM_read_bio_X509_AUX"); | ||
| 161 | sk_X509_push(certs, cert); | ||
| 162 | |||
| 163 | store = X509_STORE_new(); | ||
| 164 | if (store == NULL) | ||
| 165 | fatal("X509_STORE_new"); | ||
| 166 | X509_STORE_set_verify_cb(store, x509_store_callback); | ||
| 167 | |||
| 168 | bio_pkey = BIO_new_mem_buf((char *)private_key, sizeof(private_key)); | ||
| 169 | if (bio_pkey == NULL) | ||
| 170 | fatal("BIO_new_mem_buf private_key"); | ||
| 171 | |||
| 172 | pkey = PEM_read_bio_PrivateKey(bio_pkey, NULL, NULL, NULL); | ||
| 173 | if (pkey == NULL) | ||
| 174 | fatal("PEM_read_bio_PrivateKey"); | ||
| 175 | |||
| 176 | bio_content = BIO_new_mem_buf((char *)message, sizeof(message)); | ||
| 177 | if (bio_content == NULL) | ||
| 178 | fatal("BIO_new_mem_buf message"); | ||
| 179 | |||
| 180 | /* | ||
| 181 | * Encrypt and then decrypt. | ||
| 182 | */ | ||
| 183 | if (BIO_reset(bio_content) != 1) | ||
| 184 | fatal("BIO_reset"); | ||
| 185 | bio_out = BIO_new(BIO_s_mem()); | ||
| 186 | if (bio_out == NULL) | ||
| 187 | fatal("BIO_new"); | ||
| 188 | |||
| 189 | p7 = PKCS7_encrypt(certs, bio_content, cipher, 0); | ||
| 190 | if (p7 == NULL) | ||
| 191 | fatal("PKCS7_encrypt"); | ||
| 192 | if (PEM_write_bio_PKCS7(bio_out, p7) != 1) | ||
| 193 | fatal("PEM_write_bio_PKCS7"); | ||
| 194 | PKCS7_free(p7); | ||
| 195 | |||
| 196 | bio_in = bio_out; | ||
| 197 | bio_out = BIO_new(BIO_s_mem()); | ||
| 198 | if (bio_out == NULL) | ||
| 199 | fatal("BIO_new"); | ||
| 200 | |||
| 201 | p7 = PEM_read_bio_PKCS7(bio_in, NULL, NULL, NULL); | ||
| 202 | if (p7 == NULL) | ||
| 203 | fatal("PEM_read_bio_PKCS7"); | ||
| 204 | if (PKCS7_decrypt(p7, pkey, cert, bio_out, 0) != 1) | ||
| 205 | fatal("PKCS7_decrypt"); | ||
| 206 | |||
| 207 | len = BIO_get_mem_data(bio_out, &out); | ||
| 208 | message_compare(out, len); | ||
| 209 | |||
| 210 | BIO_free(bio_out); | ||
| 211 | |||
| 212 | /* | ||
| 213 | * Sign and then verify. | ||
| 214 | */ | ||
| 215 | if (BIO_reset(bio_content) != 1) | ||
| 216 | fatal("BIO_reset"); | ||
| 217 | bio_out = BIO_new(BIO_s_mem()); | ||
| 218 | if (bio_out == NULL) | ||
| 219 | fatal("BIO_new"); | ||
| 220 | |||
| 221 | p7 = PKCS7_sign(cert, pkey, certs, bio_content, 0); | ||
| 222 | if (p7 == NULL) | ||
| 223 | fatal("PKCS7_sign"); | ||
| 224 | if (PEM_write_bio_PKCS7(bio_out, p7) != 1) | ||
| 225 | fatal("PEM_write_bio_PKCS7"); | ||
| 226 | PKCS7_free(p7); | ||
| 227 | |||
| 228 | bio_in = bio_out; | ||
| 229 | bio_out = BIO_new(BIO_s_mem()); | ||
| 230 | if (bio_out == NULL) | ||
| 231 | fatal("BIO_new"); | ||
| 232 | |||
| 233 | p7 = PEM_read_bio_PKCS7(bio_in, NULL, NULL, NULL); | ||
| 234 | if (p7 == NULL) | ||
| 235 | fatal("PEM_read_bio_PKCS7"); | ||
| 236 | if (PKCS7_verify(p7, certs, store, NULL, bio_out, 0) != 1) | ||
| 237 | fatal("PKCS7_verify"); | ||
| 238 | |||
| 239 | len = BIO_get_mem_data(bio_out, &out); | ||
| 240 | message_compare(out, len); | ||
| 241 | |||
| 242 | BIO_free(bio_in); | ||
| 243 | BIO_free(bio_out); | ||
| 244 | |||
| 245 | /* | ||
| 246 | * Sign and then verify with a detached signature. | ||
| 247 | */ | ||
| 248 | if (BIO_reset(bio_content) != 1) | ||
| 249 | fatal("BIO_reset"); | ||
| 250 | bio_out = BIO_new(BIO_s_mem()); | ||
| 251 | if (bio_out == NULL) | ||
| 252 | fatal("BIO_new"); | ||
| 253 | |||
| 254 | flags = PKCS7_DETACHED|PKCS7_PARTIAL; | ||
| 255 | p7 = PKCS7_sign(NULL, NULL, NULL, bio_content, flags); | ||
| 256 | if (p7 == NULL) | ||
| 257 | fatal("PKCS7_sign"); | ||
| 258 | if (PKCS7_sign_add_signer(p7, cert, pkey, NULL, flags) == NULL) | ||
| 259 | fatal("PKCS7_sign_add_signer"); | ||
| 260 | if (PKCS7_final(p7, bio_content, flags) != 1) | ||
| 261 | fatal("PKCS7_final"); | ||
| 262 | if (PEM_write_bio_PKCS7(bio_out, p7) != 1) | ||
| 263 | fatal("PEM_write_bio_PKCS7"); | ||
| 264 | PKCS7_free(p7); | ||
| 265 | |||
| 266 | /* bio_out contains only the detached signature. */ | ||
| 267 | bio_in = bio_out; | ||
| 268 | if (BIO_reset(bio_content) != 1) | ||
| 269 | fatal("BIO_reset"); | ||
| 270 | |||
| 271 | bio_out = BIO_new(BIO_s_mem()); | ||
| 272 | if (bio_out == NULL) | ||
| 273 | fatal("BIO_new"); | ||
| 274 | |||
| 275 | p7 = PEM_read_bio_PKCS7(bio_in, NULL, NULL, NULL); | ||
| 276 | if (p7 == NULL) | ||
| 277 | fatal("PEM_read_bio_PKCS7"); | ||
| 278 | if (PKCS7_verify(p7, certs, store, bio_content, bio_out, flags) != 1) | ||
| 279 | fatal("PKCS7_verify"); | ||
| 280 | |||
| 281 | len = BIO_get_mem_data(bio_out, &out); | ||
| 282 | message_compare(out, len); | ||
| 283 | |||
| 284 | BIO_free(bio_in); | ||
| 285 | BIO_free(bio_out); | ||
| 286 | BIO_free(bio_content); | ||
| 287 | |||
| 288 | return 0; | ||
| 289 | } | ||
diff --git a/src/regress/lib/libcrypto/poly1305/Makefile b/src/regress/lib/libcrypto/poly1305/Makefile deleted file mode 100644 index 4e3096c2cd..0000000000 --- a/src/regress/lib/libcrypto/poly1305/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= poly1305test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/poly1305/poly1305test.c b/src/regress/lib/libcrypto/poly1305/poly1305test.c deleted file mode 100644 index 3f9af0db00..0000000000 --- a/src/regress/lib/libcrypto/poly1305/poly1305test.c +++ /dev/null | |||
| @@ -1,169 +0,0 @@ | |||
| 1 | /* $OpenBSD: poly1305test.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Public Domain poly1305 from Andrew Moon | ||
| 4 | * Based on poly1305-donna.c from: | ||
| 5 | * https://github.com/floodyberry/poly1305-donna | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | |||
| 10 | #include <openssl/poly1305.h> | ||
| 11 | |||
| 12 | void poly1305_auth(unsigned char mac[16], const unsigned char *m, size_t bytes, | ||
| 13 | const unsigned char key[32]); | ||
| 14 | |||
| 15 | int poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]); | ||
| 16 | int poly1305_power_on_self_test(void); | ||
| 17 | |||
| 18 | void | ||
| 19 | poly1305_auth(unsigned char mac[16], const unsigned char *m, size_t bytes, | ||
| 20 | const unsigned char key[32]) { | ||
| 21 | poly1305_context ctx; | ||
| 22 | CRYPTO_poly1305_init(&ctx, key); | ||
| 23 | CRYPTO_poly1305_update(&ctx, m, bytes); | ||
| 24 | CRYPTO_poly1305_finish(&ctx, mac); | ||
| 25 | } | ||
| 26 | |||
| 27 | int | ||
| 28 | poly1305_verify(const unsigned char mac1[16], const unsigned char mac2[16]) | ||
| 29 | { | ||
| 30 | size_t i; | ||
| 31 | unsigned int dif = 0; | ||
| 32 | for (i = 0; i < 16; i++) | ||
| 33 | dif |= (mac1[i] ^ mac2[i]); | ||
| 34 | dif = (dif - 1) >> ((sizeof(unsigned int) * 8) - 1); | ||
| 35 | return (dif & 1); | ||
| 36 | } | ||
| 37 | |||
| 38 | /* test a few basic operations */ | ||
| 39 | int | ||
| 40 | poly1305_power_on_self_test(void) | ||
| 41 | { | ||
| 42 | /* example from nacl */ | ||
| 43 | static const unsigned char nacl_key[32] = { | ||
| 44 | 0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, | ||
| 45 | 0x6d, 0x11, 0xc2, 0xcb, 0x21, 0x4d, 0x3c, 0x25, | ||
| 46 | 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23, 0x4e, 0x65, | ||
| 47 | 0x2d, 0x65, 0x1f, 0xa4, 0xc8, 0xcf, 0xf8, 0x80, | ||
| 48 | }; | ||
| 49 | |||
| 50 | static const unsigned char nacl_msg[131] = { | ||
| 51 | 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, | ||
| 52 | 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, 0x76, 0xce, | ||
| 53 | 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, | ||
| 54 | 0x47, 0x6f, 0xb8, 0xc5, 0x31, 0xa1, 0x18, 0x6a, | ||
| 55 | 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b, | ||
| 56 | 0x4d, 0xa7, 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, | ||
| 57 | 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, | ||
| 58 | 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38, | ||
| 59 | 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, 0xcc, 0x8a, | ||
| 60 | 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, | ||
| 61 | 0x90, 0x22, 0x43, 0x68, 0x51, 0x7a, 0xcf, 0xea, | ||
| 62 | 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, | ||
| 63 | 0x99, 0x83, 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, | ||
| 64 | 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3, | ||
| 65 | 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, | ||
| 66 | 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, 0x5a, 0x74, | ||
| 67 | 0xe3, 0x55, 0xa5 | ||
| 68 | }; | ||
| 69 | |||
| 70 | static const unsigned char nacl_mac[16] = { | ||
| 71 | 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, | ||
| 72 | 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, 0x05, 0xd9 | ||
| 73 | }; | ||
| 74 | |||
| 75 | /* generates a final value of (2^130 - 2) == 3 */ | ||
| 76 | static const unsigned char wrap_key[32] = { | ||
| 77 | 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 81 | }; | ||
| 82 | |||
| 83 | static const unsigned char wrap_msg[16] = { | ||
| 84 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 85 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
| 86 | }; | ||
| 87 | |||
| 88 | static const unsigned char wrap_mac[16] = { | ||
| 89 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 90 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 91 | }; | ||
| 92 | |||
| 93 | /* | ||
| 94 | mac of the macs of messages of length 0 to 256, where the key and messages | ||
| 95 | have all their values set to the length | ||
| 96 | */ | ||
| 97 | static const unsigned char total_key[32] = { | ||
| 98 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 99 | 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, | ||
| 100 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
| 101 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | ||
| 102 | }; | ||
| 103 | |||
| 104 | static const unsigned char total_mac[16] = { | ||
| 105 | 0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, | ||
| 106 | 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, 0x3d, 0x39 | ||
| 107 | }; | ||
| 108 | |||
| 109 | poly1305_context ctx; | ||
| 110 | poly1305_context total_ctx; | ||
| 111 | unsigned char all_key[32]; | ||
| 112 | unsigned char all_msg[256]; | ||
| 113 | unsigned char mac[16]; | ||
| 114 | size_t i, j; | ||
| 115 | int result = 1; | ||
| 116 | |||
| 117 | for (i = 0; i < sizeof(mac); i++) | ||
| 118 | mac[i] = 0; | ||
| 119 | poly1305_auth(mac, nacl_msg, sizeof(nacl_msg), nacl_key); | ||
| 120 | result &= poly1305_verify(nacl_mac, mac); | ||
| 121 | |||
| 122 | for (i = 0; i < sizeof(mac); i++) | ||
| 123 | mac[i] = 0; | ||
| 124 | CRYPTO_poly1305_init(&ctx, nacl_key); | ||
| 125 | CRYPTO_poly1305_update(&ctx, nacl_msg + 0, 32); | ||
| 126 | CRYPTO_poly1305_update(&ctx, nacl_msg + 32, 64); | ||
| 127 | CRYPTO_poly1305_update(&ctx, nacl_msg + 96, 16); | ||
| 128 | CRYPTO_poly1305_update(&ctx, nacl_msg + 112, 8); | ||
| 129 | CRYPTO_poly1305_update(&ctx, nacl_msg + 120, 4); | ||
| 130 | CRYPTO_poly1305_update(&ctx, nacl_msg + 124, 2); | ||
| 131 | CRYPTO_poly1305_update(&ctx, nacl_msg + 126, 1); | ||
| 132 | CRYPTO_poly1305_update(&ctx, nacl_msg + 127, 1); | ||
| 133 | CRYPTO_poly1305_update(&ctx, nacl_msg + 128, 1); | ||
| 134 | CRYPTO_poly1305_update(&ctx, nacl_msg + 129, 1); | ||
| 135 | CRYPTO_poly1305_update(&ctx, nacl_msg + 130, 1); | ||
| 136 | CRYPTO_poly1305_finish(&ctx, mac); | ||
| 137 | result &= poly1305_verify(nacl_mac, mac); | ||
| 138 | |||
| 139 | for (i = 0; i < sizeof(mac); i++) | ||
| 140 | mac[i] = 0; | ||
| 141 | poly1305_auth(mac, wrap_msg, sizeof(wrap_msg), wrap_key); | ||
| 142 | result &= poly1305_verify(wrap_mac, mac); | ||
| 143 | |||
| 144 | CRYPTO_poly1305_init(&total_ctx, total_key); | ||
| 145 | for (i = 0; i < 256; i++) { | ||
| 146 | /* set key and message to 'i,i,i..' */ | ||
| 147 | for (j = 0; j < sizeof(all_key); j++) | ||
| 148 | all_key[j] = i; | ||
| 149 | for (j = 0; j < i; j++) | ||
| 150 | all_msg[j] = i; | ||
| 151 | poly1305_auth(mac, all_msg, i, all_key); | ||
| 152 | CRYPTO_poly1305_update(&total_ctx, mac, 16); | ||
| 153 | } | ||
| 154 | CRYPTO_poly1305_finish(&total_ctx, mac); | ||
| 155 | result &= poly1305_verify(total_mac, mac); | ||
| 156 | |||
| 157 | return result; | ||
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | main(int argc, char **argv) | ||
| 162 | { | ||
| 163 | if (!poly1305_power_on_self_test()) { | ||
| 164 | fprintf(stderr, "One or more self tests failed!\n"); | ||
| 165 | return 1; | ||
| 166 | } | ||
| 167 | |||
| 168 | return 0; | ||
| 169 | } | ||
diff --git a/src/regress/lib/libcrypto/rand/Makefile b/src/regress/lib/libcrypto/rand/Makefile deleted file mode 100644 index 0235a43ef1..0000000000 --- a/src/regress/lib/libcrypto/rand/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= randtest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/rand/randtest.c b/src/regress/lib/libcrypto/rand/randtest.c deleted file mode 100644 index d0f02ad22d..0000000000 --- a/src/regress/lib/libcrypto/rand/randtest.c +++ /dev/null | |||
| @@ -1,204 +0,0 @@ | |||
| 1 | /* $OpenBSD: randtest.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | |||
| 62 | #undef LIBRESSL_INTERNAL /* Needed to get RAND_pseudo_bytes(). */ | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | /* some FIPS 140-1 random number test */ | ||
| 66 | /* some simple tests */ | ||
| 67 | |||
| 68 | int main(int argc,char **argv) | ||
| 69 | { | ||
| 70 | unsigned char buf[2500]; | ||
| 71 | int i,j,k,s,sign,nsign,err=0; | ||
| 72 | unsigned long n1; | ||
| 73 | unsigned long n2[16]; | ||
| 74 | unsigned long runs[2][34]; | ||
| 75 | /*double d; */ | ||
| 76 | long d; | ||
| 77 | |||
| 78 | i = RAND_pseudo_bytes(buf,2500); | ||
| 79 | if (i < 0) | ||
| 80 | { | ||
| 81 | printf ("init failed, the rand method is not properly installed\n"); | ||
| 82 | err++; | ||
| 83 | goto err; | ||
| 84 | } | ||
| 85 | |||
| 86 | n1=0; | ||
| 87 | for (i=0; i<16; i++) n2[i]=0; | ||
| 88 | for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0; | ||
| 89 | |||
| 90 | /* test 1 and 2 */ | ||
| 91 | sign=0; | ||
| 92 | nsign=0; | ||
| 93 | for (i=0; i<2500; i++) | ||
| 94 | { | ||
| 95 | j=buf[i]; | ||
| 96 | |||
| 97 | n2[j&0x0f]++; | ||
| 98 | n2[(j>>4)&0x0f]++; | ||
| 99 | |||
| 100 | for (k=0; k<8; k++) | ||
| 101 | { | ||
| 102 | s=(j&0x01); | ||
| 103 | if (s == sign) | ||
| 104 | nsign++; | ||
| 105 | else | ||
| 106 | { | ||
| 107 | if (nsign > 34) nsign=34; | ||
| 108 | if (nsign != 0) | ||
| 109 | { | ||
| 110 | runs[sign][nsign-1]++; | ||
| 111 | if (nsign > 6) | ||
| 112 | runs[sign][5]++; | ||
| 113 | } | ||
| 114 | sign=s; | ||
| 115 | nsign=1; | ||
| 116 | } | ||
| 117 | |||
| 118 | if (s) n1++; | ||
| 119 | j>>=1; | ||
| 120 | } | ||
| 121 | } | ||
| 122 | if (nsign > 34) nsign=34; | ||
| 123 | if (nsign != 0) runs[sign][nsign-1]++; | ||
| 124 | |||
| 125 | /* test 1 */ | ||
| 126 | if (!((9654 < n1) && (n1 < 10346))) | ||
| 127 | { | ||
| 128 | printf("test 1 failed, X=%lu\n",n1); | ||
| 129 | err++; | ||
| 130 | } | ||
| 131 | printf("test 1 done\n"); | ||
| 132 | |||
| 133 | /* test 2 */ | ||
| 134 | d=0; | ||
| 135 | for (i=0; i<16; i++) | ||
| 136 | d+=n2[i]*n2[i]; | ||
| 137 | d=(d*8)/25-500000; | ||
| 138 | if (!((103 < d) && (d < 5740))) | ||
| 139 | { | ||
| 140 | printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L); | ||
| 141 | err++; | ||
| 142 | } | ||
| 143 | printf("test 2 done\n"); | ||
| 144 | |||
| 145 | /* test 3 */ | ||
| 146 | for (i=0; i<2; i++) | ||
| 147 | { | ||
| 148 | if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) | ||
| 149 | { | ||
| 150 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 151 | i,1,runs[i][0]); | ||
| 152 | err++; | ||
| 153 | } | ||
| 154 | if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) | ||
| 155 | { | ||
| 156 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 157 | i,2,runs[i][1]); | ||
| 158 | err++; | ||
| 159 | } | ||
| 160 | if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) | ||
| 161 | { | ||
| 162 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 163 | i,3,runs[i][2]); | ||
| 164 | err++; | ||
| 165 | } | ||
| 166 | if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) | ||
| 167 | { | ||
| 168 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 169 | i,4,runs[i][3]); | ||
| 170 | err++; | ||
| 171 | } | ||
| 172 | if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) | ||
| 173 | { | ||
| 174 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 175 | i,5,runs[i][4]); | ||
| 176 | err++; | ||
| 177 | } | ||
| 178 | if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) | ||
| 179 | { | ||
| 180 | printf("test 3 failed, bit=%d run=%d num=%lu\n", | ||
| 181 | i,6,runs[i][5]); | ||
| 182 | err++; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | printf("test 3 done\n"); | ||
| 186 | |||
| 187 | /* test 4 */ | ||
| 188 | if (runs[0][33] != 0) | ||
| 189 | { | ||
| 190 | printf("test 4 failed, bit=%d run=%d num=%lu\n", | ||
| 191 | 0,34,runs[0][33]); | ||
| 192 | err++; | ||
| 193 | } | ||
| 194 | if (runs[1][33] != 0) | ||
| 195 | { | ||
| 196 | printf("test 4 failed, bit=%d run=%d num=%lu\n", | ||
| 197 | 1,34,runs[1][33]); | ||
| 198 | err++; | ||
| 199 | } | ||
| 200 | printf("test 4 done\n"); | ||
| 201 | err: | ||
| 202 | err=((err)?1:0); | ||
| 203 | exit(err); | ||
| 204 | } | ||
diff --git a/src/regress/lib/libcrypto/rc2/Makefile b/src/regress/lib/libcrypto/rc2/Makefile deleted file mode 100644 index 99e7c748d7..0000000000 --- a/src/regress/lib/libcrypto/rc2/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= rc2test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/rc2/rc2test.c b/src/regress/lib/libcrypto/rc2/rc2test.c deleted file mode 100644 index a8d33077dd..0000000000 --- a/src/regress/lib/libcrypto/rc2/rc2test.c +++ /dev/null | |||
| @@ -1,138 +0,0 @@ | |||
| 1 | /* $OpenBSD: rc2test.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* This has been a quickly hacked 'ideatest.c'. When I add tests for other | ||
| 60 | * RC2 modes, more of the code will be uncommented. */ | ||
| 61 | |||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <stdlib.h> | ||
| 65 | |||
| 66 | #include <openssl/rc2.h> | ||
| 67 | |||
| 68 | static unsigned char RC2key[4][16]={ | ||
| 69 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 70 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 71 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 72 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}, | ||
| 73 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 74 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 75 | {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, | ||
| 76 | 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}, | ||
| 77 | }; | ||
| 78 | |||
| 79 | static unsigned char RC2plain[4][8]={ | ||
| 80 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 81 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 82 | {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, | ||
| 83 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 84 | }; | ||
| 85 | |||
| 86 | static unsigned char RC2cipher[4][8]={ | ||
| 87 | {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7}, | ||
| 88 | {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74}, | ||
| 89 | {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E}, | ||
| 90 | {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31}, | ||
| 91 | }; | ||
| 92 | /************/ | ||
| 93 | |||
| 94 | int main(int argc, char *argv[]) | ||
| 95 | { | ||
| 96 | int i,n,err=0; | ||
| 97 | RC2_KEY key; | ||
| 98 | unsigned char buf[8],buf2[8]; | ||
| 99 | |||
| 100 | for (n=0; n<4; n++) | ||
| 101 | { | ||
| 102 | RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */); | ||
| 103 | |||
| 104 | RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT); | ||
| 105 | if (memcmp(&(RC2cipher[n][0]),buf,8) != 0) | ||
| 106 | { | ||
| 107 | printf("ecb rc2 error encrypting\n"); | ||
| 108 | printf("got :"); | ||
| 109 | for (i=0; i<8; i++) | ||
| 110 | printf("%02X ",buf[i]); | ||
| 111 | printf("\n"); | ||
| 112 | printf("expected:"); | ||
| 113 | for (i=0; i<8; i++) | ||
| 114 | printf("%02X ",RC2cipher[n][i]); | ||
| 115 | err=20; | ||
| 116 | printf("\n"); | ||
| 117 | } | ||
| 118 | |||
| 119 | RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT); | ||
| 120 | if (memcmp(&(RC2plain[n][0]),buf2,8) != 0) | ||
| 121 | { | ||
| 122 | printf("ecb RC2 error decrypting\n"); | ||
| 123 | printf("got :"); | ||
| 124 | for (i=0; i<8; i++) | ||
| 125 | printf("%02X ",buf[i]); | ||
| 126 | printf("\n"); | ||
| 127 | printf("expected:"); | ||
| 128 | for (i=0; i<8; i++) | ||
| 129 | printf("%02X ",RC2plain[n][i]); | ||
| 130 | printf("\n"); | ||
| 131 | err=3; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | if (err == 0) printf("ecb RC2 ok\n"); | ||
| 136 | |||
| 137 | exit(err); | ||
| 138 | } | ||
diff --git a/src/regress/lib/libcrypto/rc4/Makefile b/src/regress/lib/libcrypto/rc4/Makefile deleted file mode 100644 index bbb62d328b..0000000000 --- a/src/regress/lib/libcrypto/rc4/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= rc4test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/rc4/rc4test.c b/src/regress/lib/libcrypto/rc4/rc4test.c deleted file mode 100644 index c1d98eb8c1..0000000000 --- a/src/regress/lib/libcrypto/rc4/rc4test.c +++ /dev/null | |||
| @@ -1,225 +0,0 @@ | |||
| 1 | /* $OpenBSD: rc4test.c,v 1.4 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/rc4.h> | ||
| 65 | #include <openssl/sha.h> | ||
| 66 | |||
| 67 | static unsigned char keys[7][30]={ | ||
| 68 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
| 69 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
| 70 | {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, | ||
| 71 | {4,0xef,0x01,0x23,0x45}, | ||
| 72 | {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, | ||
| 73 | {4,0xef,0x01,0x23,0x45}, | ||
| 74 | }; | ||
| 75 | |||
| 76 | static unsigned char data_len[7]={8,8,8,20,28,10}; | ||
| 77 | static unsigned char data[7][30]={ | ||
| 78 | {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff}, | ||
| 79 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
| 80 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
| 81 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 82 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
| 83 | 0x00,0x00,0x00,0x00,0xff}, | ||
| 84 | {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
| 85 | 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
| 86 | 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0, | ||
| 87 | 0x12,0x34,0x56,0x78,0xff}, | ||
| 88 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff}, | ||
| 89 | {0}, | ||
| 90 | }; | ||
| 91 | |||
| 92 | static unsigned char output[7][30]={ | ||
| 93 | {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00}, | ||
| 94 | {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00}, | ||
| 95 | {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00}, | ||
| 96 | {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf, | ||
| 97 | 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba, | ||
| 98 | 0x36,0xb6,0x78,0x58,0x00}, | ||
| 99 | {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89, | ||
| 100 | 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c, | ||
| 101 | 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87, | ||
| 102 | 0x40,0x01,0x1e,0xcf,0x00}, | ||
| 103 | {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00}, | ||
| 104 | {0}, | ||
| 105 | }; | ||
| 106 | |||
| 107 | int main(int argc, char *argv[]) | ||
| 108 | { | ||
| 109 | int i,err=0; | ||
| 110 | int j; | ||
| 111 | unsigned char *p; | ||
| 112 | RC4_KEY key; | ||
| 113 | unsigned char obuf[512]; | ||
| 114 | |||
| 115 | OPENSSL_add_all_algorithms_noconf(); | ||
| 116 | |||
| 117 | for (i=0; i<6; i++) | ||
| 118 | { | ||
| 119 | RC4_set_key(&key,keys[i][0],&(keys[i][1])); | ||
| 120 | memset(obuf,0x00,sizeof(obuf)); | ||
| 121 | RC4(&key,data_len[i],&(data[i][0]),obuf); | ||
| 122 | if (memcmp(obuf,output[i],data_len[i]+1) != 0) | ||
| 123 | { | ||
| 124 | printf("error calculating RC4\n"); | ||
| 125 | printf("output:"); | ||
| 126 | for (j=0; j<data_len[i]+1; j++) | ||
| 127 | printf(" %02x",obuf[j]); | ||
| 128 | printf("\n"); | ||
| 129 | printf("expect:"); | ||
| 130 | p= &(output[i][0]); | ||
| 131 | for (j=0; j<data_len[i]+1; j++) | ||
| 132 | printf(" %02x",*(p++)); | ||
| 133 | printf("\n"); | ||
| 134 | err++; | ||
| 135 | } | ||
| 136 | else | ||
| 137 | printf("test %d ok\n",i); | ||
| 138 | } | ||
| 139 | printf("test end processing "); | ||
| 140 | for (i=0; i<data_len[3]; i++) | ||
| 141 | { | ||
| 142 | RC4_set_key(&key,keys[3][0],&(keys[3][1])); | ||
| 143 | memset(obuf,0x00,sizeof(obuf)); | ||
| 144 | RC4(&key,i,&(data[3][0]),obuf); | ||
| 145 | if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0)) | ||
| 146 | { | ||
| 147 | printf("error in RC4 length processing\n"); | ||
| 148 | printf("output:"); | ||
| 149 | for (j=0; j<i+1; j++) | ||
| 150 | printf(" %02x",obuf[j]); | ||
| 151 | printf("\n"); | ||
| 152 | printf("expect:"); | ||
| 153 | p= &(output[3][0]); | ||
| 154 | for (j=0; j<i; j++) | ||
| 155 | printf(" %02x",*(p++)); | ||
| 156 | printf(" 00\n"); | ||
| 157 | err++; | ||
| 158 | } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | printf("."); | ||
| 162 | fflush(stdout); | ||
| 163 | } | ||
| 164 | } | ||
| 165 | printf("done\n"); | ||
| 166 | printf("test multi-call "); | ||
| 167 | for (i=0; i<data_len[3]; i++) | ||
| 168 | { | ||
| 169 | RC4_set_key(&key,keys[3][0],&(keys[3][1])); | ||
| 170 | memset(obuf,0x00,sizeof(obuf)); | ||
| 171 | RC4(&key,i,&(data[3][0]),obuf); | ||
| 172 | RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i])); | ||
| 173 | if (memcmp(obuf,output[3],data_len[3]+1) != 0) | ||
| 174 | { | ||
| 175 | printf("error in RC4 multi-call processing\n"); | ||
| 176 | printf("output:"); | ||
| 177 | for (j=0; j<data_len[3]+1; j++) | ||
| 178 | printf(" %02x",obuf[j]); | ||
| 179 | printf("\n"); | ||
| 180 | printf("expect:"); | ||
| 181 | p= &(output[3][0]); | ||
| 182 | for (j=0; j<data_len[3]+1; j++) | ||
| 183 | printf(" %02x",*(p++)); | ||
| 184 | err++; | ||
| 185 | } | ||
| 186 | else | ||
| 187 | { | ||
| 188 | printf("."); | ||
| 189 | fflush(stdout); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | printf("done\n"); | ||
| 193 | printf("bulk test "); | ||
| 194 | { unsigned char buf[513]; | ||
| 195 | SHA_CTX c; | ||
| 196 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 197 | static unsigned char expected[]={ | ||
| 198 | 0xa4,0x7b,0xcc,0x00,0x3d,0xd0,0xbd,0xe1,0xac,0x5f, | ||
| 199 | 0x12,0x1e,0x45,0xbc,0xfb,0x1a,0xa1,0xf2,0x7f,0xc5 }; | ||
| 200 | |||
| 201 | RC4_set_key(&key,keys[0][0],&(keys[3][1])); | ||
| 202 | memset(buf,'\0',sizeof(buf)); | ||
| 203 | SHA1_Init(&c); | ||
| 204 | for (i=0;i<2571;i++) { | ||
| 205 | RC4(&key,sizeof(buf),buf,buf); | ||
| 206 | SHA1_Update(&c,buf,sizeof(buf)); | ||
| 207 | } | ||
| 208 | SHA1_Final(md,&c); | ||
| 209 | |||
| 210 | if (memcmp(md,expected,sizeof(md))) { | ||
| 211 | printf("error in RC4 bulk test\n"); | ||
| 212 | printf("output:"); | ||
| 213 | for (j=0; j<(int)sizeof(md); j++) | ||
| 214 | printf(" %02x",md[j]); | ||
| 215 | printf("\n"); | ||
| 216 | printf("expect:"); | ||
| 217 | for (j=0; j<(int)sizeof(md); j++) | ||
| 218 | printf(" %02x",expected[j]); | ||
| 219 | printf("\n"); | ||
| 220 | err++; | ||
| 221 | } | ||
| 222 | else printf("ok\n"); | ||
| 223 | } | ||
| 224 | exit(err); | ||
| 225 | } | ||
diff --git a/src/regress/lib/libcrypto/rmd/Makefile b/src/regress/lib/libcrypto/rmd/Makefile deleted file mode 100644 index 843b6b54c9..0000000000 --- a/src/regress/lib/libcrypto/rmd/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= rmdtest | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/rmd/rmdtest.c b/src/regress/lib/libcrypto/rmd/rmdtest.c deleted file mode 100644 index aa6cb0174e..0000000000 --- a/src/regress/lib/libcrypto/rmd/rmdtest.c +++ /dev/null | |||
| @@ -1,128 +0,0 @@ | |||
| 1 | /* $OpenBSD: rmdtest.c,v 1.2 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/ripemd.h> | ||
| 64 | #include <openssl/evp.h> | ||
| 65 | |||
| 66 | static char *test[]={ | ||
| 67 | "", | ||
| 68 | "a", | ||
| 69 | "abc", | ||
| 70 | "message digest", | ||
| 71 | "abcdefghijklmnopqrstuvwxyz", | ||
| 72 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
| 73 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | ||
| 74 | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", | ||
| 75 | NULL, | ||
| 76 | }; | ||
| 77 | |||
| 78 | static char *ret[]={ | ||
| 79 | "9c1185a5c5e9fc54612808977ee8f548b2258d31", | ||
| 80 | "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", | ||
| 81 | "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", | ||
| 82 | "5d0689ef49d2fae572b881b123a85ffa21595f36", | ||
| 83 | "f71c27109c692c1b56bbdceb5b9d2865b3708dbc", | ||
| 84 | "12a053384a9c0c88e405a06c27dcf49ada62eb2b", | ||
| 85 | "b0e20b6e3116640286ed3a87a5713079b21f5189", | ||
| 86 | "9b752e45573d4b39f4dbd3323cab82bf63326bfb", | ||
| 87 | }; | ||
| 88 | |||
| 89 | static char *pt(unsigned char *md); | ||
| 90 | int main(int argc, char *argv[]) | ||
| 91 | { | ||
| 92 | int i,err=0; | ||
| 93 | char **P,**R; | ||
| 94 | char *p; | ||
| 95 | unsigned char md[RIPEMD160_DIGEST_LENGTH]; | ||
| 96 | |||
| 97 | P=test; | ||
| 98 | R=ret; | ||
| 99 | i=1; | ||
| 100 | while (*P != NULL) | ||
| 101 | { | ||
| 102 | EVP_Digest(&(P[0][0]),strlen((char *)*P),md,NULL,EVP_ripemd160(), NULL); | ||
| 103 | p=pt(md); | ||
| 104 | if (strcmp(p,(char *)*R) != 0) | ||
| 105 | { | ||
| 106 | printf("error calculating RIPEMD160 on '%s'\n",*P); | ||
| 107 | printf("got %s instead of %s\n",p,*R); | ||
| 108 | err++; | ||
| 109 | } | ||
| 110 | else | ||
| 111 | printf("test %d ok\n",i); | ||
| 112 | i++; | ||
| 113 | R++; | ||
| 114 | P++; | ||
| 115 | } | ||
| 116 | exit(err); | ||
| 117 | return(0); | ||
| 118 | } | ||
| 119 | |||
| 120 | static char *pt(unsigned char *md) | ||
| 121 | { | ||
| 122 | int i; | ||
| 123 | static char buf[80]; | ||
| 124 | |||
| 125 | for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++) | ||
| 126 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x",md[i]); | ||
| 127 | return(buf); | ||
| 128 | } | ||
diff --git a/src/regress/lib/libcrypto/rsa/Makefile b/src/regress/lib/libcrypto/rsa/Makefile deleted file mode 100644 index ac87800492..0000000000 --- a/src/regress/lib/libcrypto/rsa/Makefile +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/01/25 06:44:04 beck Exp $ | ||
| 2 | |||
| 3 | PROG= rsa_test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-dsatest | ||
| 10 | |||
| 11 | regress-dsatest: ${PROG} | ||
| 12 | ./${PROG} | ||
| 13 | ./${PROG} -app2_1 | ||
| 14 | |||
| 15 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/rsa/rsa_test.c b/src/regress/lib/libcrypto/rsa/rsa_test.c deleted file mode 100644 index 9e7cd6f472..0000000000 --- a/src/regress/lib/libcrypto/rsa/rsa_test.c +++ /dev/null | |||
| @@ -1,327 +0,0 @@ | |||
| 1 | /* $OpenBSD: rsa_test.c,v 1.3 2018/07/17 17:06:49 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved. | ||
| 4 | * | ||
| 5 | * Licensed under the OpenSSL license (the "License"). You may not use | ||
| 6 | * this file except in compliance with the License. You can obtain a copy | ||
| 7 | * in the file LICENSE in the source distribution or at | ||
| 8 | * https://www.openssl.org/source/license.html | ||
| 9 | */ | ||
| 10 | |||
| 11 | /* test vectors from p1ovect1.txt */ | ||
| 12 | |||
| 13 | #include <stdio.h> | ||
| 14 | #include <string.h> | ||
| 15 | |||
| 16 | #include <openssl/crypto.h> | ||
| 17 | #include <openssl/err.h> | ||
| 18 | #include <openssl/rand.h> | ||
| 19 | #include <openssl/bn.h> | ||
| 20 | #ifdef OPENSSL_NO_RSA | ||
| 21 | int main(int argc, char *argv[]) | ||
| 22 | { | ||
| 23 | printf("No RSA support\n"); | ||
| 24 | return (0); | ||
| 25 | } | ||
| 26 | #else | ||
| 27 | # include <openssl/rsa.h> | ||
| 28 | |||
| 29 | # define SetKey \ | ||
| 30 | key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \ | ||
| 31 | key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \ | ||
| 32 | key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \ | ||
| 33 | key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \ | ||
| 34 | key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \ | ||
| 35 | key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \ | ||
| 36 | key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \ | ||
| 37 | key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \ | ||
| 38 | memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \ | ||
| 39 | return (sizeof(ctext_ex) - 1); | ||
| 40 | |||
| 41 | static int key1(RSA *key, unsigned char *c) | ||
| 42 | { | ||
| 43 | static unsigned char n[] = | ||
| 44 | "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" | ||
| 45 | "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" | ||
| 46 | "\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93" | ||
| 47 | "\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1" | ||
| 48 | "\xF5"; | ||
| 49 | |||
| 50 | static unsigned char e[] = "\x11"; | ||
| 51 | |||
| 52 | static unsigned char d[] = | ||
| 53 | "\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44" | ||
| 54 | "\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64" | ||
| 55 | "\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9" | ||
| 56 | "\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51"; | ||
| 57 | |||
| 58 | static unsigned char p[] = | ||
| 59 | "\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 60 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12" | ||
| 61 | "\x0D"; | ||
| 62 | |||
| 63 | static unsigned char q[] = | ||
| 64 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 65 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 66 | "\x89"; | ||
| 67 | |||
| 68 | static unsigned char dmp1[] = | ||
| 69 | "\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF" | ||
| 70 | "\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05"; | ||
| 71 | |||
| 72 | static unsigned char dmq1[] = | ||
| 73 | "\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99" | ||
| 74 | "\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D" | ||
| 75 | "\x51"; | ||
| 76 | |||
| 77 | static unsigned char iqmp[] = | ||
| 78 | "\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8" | ||
| 79 | "\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26"; | ||
| 80 | |||
| 81 | static unsigned char ctext_ex[] = | ||
| 82 | "\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89" | ||
| 83 | "\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52" | ||
| 84 | "\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44" | ||
| 85 | "\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2"; | ||
| 86 | |||
| 87 | SetKey; | ||
| 88 | } | ||
| 89 | |||
| 90 | static int key2(RSA *key, unsigned char *c) | ||
| 91 | { | ||
| 92 | static unsigned char n[] = | ||
| 93 | "\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8" | ||
| 94 | "\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26" | ||
| 95 | "\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8" | ||
| 96 | "\x34\x77\xCF"; | ||
| 97 | |||
| 98 | static unsigned char e[] = "\x3"; | ||
| 99 | |||
| 100 | static unsigned char d[] = | ||
| 101 | "\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2" | ||
| 102 | "\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41" | ||
| 103 | "\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21" | ||
| 104 | "\xE5\xEB"; | ||
| 105 | |||
| 106 | static unsigned char p[] = | ||
| 107 | "\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92" | ||
| 108 | "\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91"; | ||
| 109 | |||
| 110 | static unsigned char q[] = | ||
| 111 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 112 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F"; | ||
| 113 | |||
| 114 | static unsigned char dmp1[] = | ||
| 115 | "\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61" | ||
| 116 | "\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B"; | ||
| 117 | |||
| 118 | static unsigned char dmq1[] = | ||
| 119 | "\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90" | ||
| 120 | "\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F"; | ||
| 121 | |||
| 122 | static unsigned char iqmp[] = | ||
| 123 | "\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13" | ||
| 124 | "\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D"; | ||
| 125 | |||
| 126 | static unsigned char ctext_ex[] = | ||
| 127 | "\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a" | ||
| 128 | "\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4" | ||
| 129 | "\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52" | ||
| 130 | "\x62\x51"; | ||
| 131 | |||
| 132 | SetKey; | ||
| 133 | } | ||
| 134 | |||
| 135 | static int key3(RSA *key, unsigned char *c) | ||
| 136 | { | ||
| 137 | static unsigned char n[] = | ||
| 138 | "\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" | ||
| 139 | "\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" | ||
| 140 | "\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD" | ||
| 141 | "\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80" | ||
| 142 | "\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25" | ||
| 143 | "\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39" | ||
| 144 | "\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68" | ||
| 145 | "\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD" | ||
| 146 | "\xCB"; | ||
| 147 | |||
| 148 | static unsigned char e[] = "\x11"; | ||
| 149 | |||
| 150 | static unsigned char d[] = | ||
| 151 | "\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD" | ||
| 152 | "\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41" | ||
| 153 | "\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69" | ||
| 154 | "\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA" | ||
| 155 | "\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94" | ||
| 156 | "\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A" | ||
| 157 | "\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94" | ||
| 158 | "\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3" | ||
| 159 | "\xC1"; | ||
| 160 | |||
| 161 | static unsigned char p[] = | ||
| 162 | "\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60" | ||
| 163 | "\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6" | ||
| 164 | "\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A" | ||
| 165 | "\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65" | ||
| 166 | "\x99"; | ||
| 167 | |||
| 168 | static unsigned char q[] = | ||
| 169 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 170 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 171 | "\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 172 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15" | ||
| 173 | "\x03"; | ||
| 174 | |||
| 175 | static unsigned char dmp1[] = | ||
| 176 | "\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A" | ||
| 177 | "\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E" | ||
| 178 | "\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E" | ||
| 179 | "\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81"; | ||
| 180 | |||
| 181 | static unsigned char dmq1[] = | ||
| 182 | "\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9" | ||
| 183 | "\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7" | ||
| 184 | "\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D" | ||
| 185 | "\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D"; | ||
| 186 | |||
| 187 | static unsigned char iqmp[] = | ||
| 188 | "\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23" | ||
| 189 | "\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11" | ||
| 190 | "\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E" | ||
| 191 | "\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39" | ||
| 192 | "\xF7"; | ||
| 193 | |||
| 194 | static unsigned char ctext_ex[] = | ||
| 195 | "\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7" | ||
| 196 | "\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce" | ||
| 197 | "\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3" | ||
| 198 | "\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06" | ||
| 199 | "\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86" | ||
| 200 | "\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4" | ||
| 201 | "\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a" | ||
| 202 | "\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1"; | ||
| 203 | |||
| 204 | SetKey; | ||
| 205 | } | ||
| 206 | |||
| 207 | static int pad_unknown(void) | ||
| 208 | { | ||
| 209 | unsigned long l; | ||
| 210 | while ((l = ERR_get_error()) != 0) | ||
| 211 | if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE) | ||
| 212 | return (1); | ||
| 213 | return (0); | ||
| 214 | } | ||
| 215 | |||
| 216 | int main(int argc, char *argv[]) | ||
| 217 | { | ||
| 218 | int err = 0; | ||
| 219 | int v; | ||
| 220 | RSA *key; | ||
| 221 | unsigned char ptext[256]; | ||
| 222 | unsigned char ctext[256]; | ||
| 223 | static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a"; | ||
| 224 | unsigned char ctext_ex[256]; | ||
| 225 | int plen; | ||
| 226 | int clen = 0; | ||
| 227 | int num; | ||
| 228 | int n; | ||
| 229 | |||
| 230 | plen = sizeof(ptext_ex) - 1; | ||
| 231 | |||
| 232 | for (v = 0; v < 3; v++) { | ||
| 233 | key = RSA_new(); | ||
| 234 | switch (v) { | ||
| 235 | case 0: | ||
| 236 | clen = key1(key, ctext_ex); | ||
| 237 | break; | ||
| 238 | case 1: | ||
| 239 | clen = key2(key, ctext_ex); | ||
| 240 | break; | ||
| 241 | case 2: | ||
| 242 | clen = key3(key, ctext_ex); | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | |||
| 246 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 247 | RSA_PKCS1_PADDING); | ||
| 248 | if (num != clen) { | ||
| 249 | printf("PKCS#1 v1.5 encryption failed!\n"); | ||
| 250 | err = 1; | ||
| 251 | goto oaep; | ||
| 252 | } | ||
| 253 | |||
| 254 | num = RSA_private_decrypt(num, ctext, ptext, key, RSA_PKCS1_PADDING); | ||
| 255 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) { | ||
| 256 | printf("PKCS#1 v1.5 decryption failed!\n"); | ||
| 257 | err = 1; | ||
| 258 | } else | ||
| 259 | printf("PKCS #1 v1.5 encryption/decryption ok\n"); | ||
| 260 | |||
| 261 | oaep: | ||
| 262 | ERR_clear_error(); | ||
| 263 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 264 | RSA_PKCS1_OAEP_PADDING); | ||
| 265 | if (num == -1 && pad_unknown()) { | ||
| 266 | printf("No OAEP support\n"); | ||
| 267 | goto next; | ||
| 268 | } | ||
| 269 | if (num != clen) { | ||
| 270 | printf("OAEP encryption failed!\n"); | ||
| 271 | err = 1; | ||
| 272 | goto next; | ||
| 273 | } | ||
| 274 | |||
| 275 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 276 | RSA_PKCS1_OAEP_PADDING); | ||
| 277 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) { | ||
| 278 | printf("OAEP decryption (encrypted data) failed!\n"); | ||
| 279 | err = 1; | ||
| 280 | } else if (memcmp(ctext, ctext_ex, num) == 0) | ||
| 281 | printf("OAEP test vector %d passed!\n", v); | ||
| 282 | |||
| 283 | /* | ||
| 284 | * Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). Try | ||
| 285 | * decrypting ctext_ex | ||
| 286 | */ | ||
| 287 | |||
| 288 | num = RSA_private_decrypt(clen, ctext_ex, ptext, key, | ||
| 289 | RSA_PKCS1_OAEP_PADDING); | ||
| 290 | |||
| 291 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) { | ||
| 292 | printf("OAEP decryption (test vector data) failed!\n"); | ||
| 293 | err = 1; | ||
| 294 | } else | ||
| 295 | printf("OAEP encryption/decryption ok\n"); | ||
| 296 | |||
| 297 | /* Try decrypting corrupted ciphertexts. */ | ||
| 298 | for (n = 0; n < clen; ++n) { | ||
| 299 | ctext[n] ^= 1; | ||
| 300 | num = RSA_private_decrypt(clen, ctext, ptext, key, | ||
| 301 | RSA_PKCS1_OAEP_PADDING); | ||
| 302 | if (num > 0) { | ||
| 303 | printf("Corrupt data decrypted!\n"); | ||
| 304 | err = 1; | ||
| 305 | break; | ||
| 306 | } | ||
| 307 | ctext[n] ^= 1; | ||
| 308 | } | ||
| 309 | |||
| 310 | /* Test truncated ciphertexts, as well as negative length. */ | ||
| 311 | for (n = -1; n < clen; ++n) { | ||
| 312 | num = RSA_private_decrypt(n, ctext, ptext, key, | ||
| 313 | RSA_PKCS1_OAEP_PADDING); | ||
| 314 | if (num > 0) { | ||
| 315 | printf("Truncated data decrypted!\n"); | ||
| 316 | err = 1; | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | next: | ||
| 322 | RSA_free(key); | ||
| 323 | } | ||
| 324 | |||
| 325 | return err; | ||
| 326 | } | ||
| 327 | #endif | ||
diff --git a/src/regress/lib/libcrypto/sha1/Makefile b/src/regress/lib/libcrypto/sha1/Makefile deleted file mode 100644 index 2bb0b45ec9..0000000000 --- a/src/regress/lib/libcrypto/sha1/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= sha1test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/sha1/sha1test.c b/src/regress/lib/libcrypto/sha1/sha1test.c deleted file mode 100644 index 7f28ba676f..0000000000 --- a/src/regress/lib/libcrypto/sha1/sha1test.c +++ /dev/null | |||
| @@ -1,139 +0,0 @@ | |||
| 1 | /* $OpenBSD: sha1test.c,v 1.3 2018/07/17 17:06:50 tb Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/sha.h> | ||
| 65 | |||
| 66 | static char *test[]={ | ||
| 67 | "abc", | ||
| 68 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
| 69 | NULL, | ||
| 70 | }; | ||
| 71 | |||
| 72 | static char *ret[]={ | ||
| 73 | "a9993e364706816aba3e25717850c26c9cd0d89d", | ||
| 74 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | ||
| 75 | }; | ||
| 76 | static char *bigret= | ||
| 77 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | ||
| 78 | |||
| 79 | static char *pt(unsigned char *md); | ||
| 80 | int main(int argc, char *argv[]) | ||
| 81 | { | ||
| 82 | int i,err=0; | ||
| 83 | char **P,**R; | ||
| 84 | static unsigned char buf[1000]; | ||
| 85 | char *p,*r; | ||
| 86 | EVP_MD_CTX c; | ||
| 87 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 88 | |||
| 89 | EVP_MD_CTX_init(&c); | ||
| 90 | P=test; | ||
| 91 | R=ret; | ||
| 92 | i=1; | ||
| 93 | while (*P != NULL) | ||
| 94 | { | ||
| 95 | EVP_Digest(*P,strlen((char *)*P),md,NULL,EVP_sha1(), NULL); | ||
| 96 | p=pt(md); | ||
| 97 | if (strcmp(p,(char *)*R) != 0) | ||
| 98 | { | ||
| 99 | printf("error calculating SHA1 on '%s'\n",*P); | ||
| 100 | printf("got %s instead of %s\n",p,*R); | ||
| 101 | err++; | ||
| 102 | } | ||
| 103 | else | ||
| 104 | printf("test %d ok\n",i); | ||
| 105 | i++; | ||
| 106 | R++; | ||
| 107 | P++; | ||
| 108 | } | ||
| 109 | |||
| 110 | memset(buf,'a',1000); | ||
| 111 | EVP_DigestInit_ex(&c,EVP_sha1(), NULL); | ||
| 112 | for (i=0; i<1000; i++) | ||
| 113 | EVP_DigestUpdate(&c,buf,1000); | ||
| 114 | EVP_DigestFinal_ex(&c,md,NULL); | ||
| 115 | p=pt(md); | ||
| 116 | |||
| 117 | r=bigret; | ||
| 118 | if (strcmp(p,r) != 0) | ||
| 119 | { | ||
| 120 | printf("error calculating SHA1 on 'a' * 1000\n"); | ||
| 121 | printf("got %s instead of %s\n",p,r); | ||
| 122 | err++; | ||
| 123 | } | ||
| 124 | else | ||
| 125 | printf("test 3 ok\n"); | ||
| 126 | |||
| 127 | EVP_MD_CTX_cleanup(&c); | ||
| 128 | exit(err); | ||
| 129 | } | ||
| 130 | |||
| 131 | static char *pt(unsigned char *md) | ||
| 132 | { | ||
| 133 | int i; | ||
| 134 | static char buf[80]; | ||
| 135 | |||
| 136 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 137 | snprintf(buf + i*2, sizeof(buf) - i*2, "%02x",md[i]); | ||
| 138 | return(buf); | ||
| 139 | } | ||
diff --git a/src/regress/lib/libcrypto/sha2/Makefile b/src/regress/lib/libcrypto/sha2/Makefile deleted file mode 100644 index e7bccf5f24..0000000000 --- a/src/regress/lib/libcrypto/sha2/Makefile +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2015/09/29 01:07:56 doug Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS=regress-sha2 | ||
| 4 | OPENSSL=/usr/bin/openssl | ||
| 5 | |||
| 6 | HASHES= \ | ||
| 7 | sha224 \ | ||
| 8 | abc \ | ||
| 9 | 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 \ | ||
| 10 | sha224 \ | ||
| 11 | abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq \ | ||
| 12 | 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 \ | ||
| 13 | sha256 \ | ||
| 14 | abc \ | ||
| 15 | ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad \ | ||
| 16 | sha256 \ | ||
| 17 | abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq \ | ||
| 18 | 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 \ | ||
| 19 | sha384 \ | ||
| 20 | abc \ | ||
| 21 | cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 \ | ||
| 22 | sha384 \ | ||
| 23 | abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu \ | ||
| 24 | 09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039 \ | ||
| 25 | sha512 \ | ||
| 26 | abc \ | ||
| 27 | ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f \ | ||
| 28 | sha512 \ | ||
| 29 | abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu \ | ||
| 30 | 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 | ||
| 31 | |||
| 32 | regress-sha2: | ||
| 33 | .for hash input output in ${HASHES} | ||
| 34 | @(echo -n ${input} | ${OPENSSL} ${hash} | (read a b; \ | ||
| 35 | test $$b == ${output} || \ | ||
| 36 | (echo wrong ${hash} hash of \"${input}\"; \ | ||
| 37 | echo expected: ${output}; \ | ||
| 38 | echo computed: $$b; \ | ||
| 39 | false))) | ||
| 40 | .endfor | ||
| 41 | |||
| 42 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/sha256/Makefile b/src/regress/lib/libcrypto/sha256/Makefile deleted file mode 100644 index 6e5f9d714b..0000000000 --- a/src/regress/lib/libcrypto/sha256/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= sha256test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/sha256/sha256test.c b/src/regress/lib/libcrypto/sha256/sha256test.c deleted file mode 100644 index 9c22bc7664..0000000000 --- a/src/regress/lib/libcrypto/sha256/sha256test.c +++ /dev/null | |||
| @@ -1,162 +0,0 @@ | |||
| 1 | /* $OpenBSD: sha256test.c,v 1.3 2018/07/17 17:06:50 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | |||
| 13 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256) | ||
| 14 | int | ||
| 15 | main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | printf("No SHA256 support\n"); | ||
| 18 | return (0); | ||
| 19 | } | ||
| 20 | #else | ||
| 21 | |||
| 22 | unsigned char app_b1[SHA256_DIGEST_LENGTH] = { | ||
| 23 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, | ||
| 24 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, | ||
| 25 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, | ||
| 26 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad, | ||
| 27 | }; | ||
| 28 | |||
| 29 | unsigned char app_b2[SHA256_DIGEST_LENGTH] = { | ||
| 30 | 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, | ||
| 31 | 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, | ||
| 32 | 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, | ||
| 33 | 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1, | ||
| 34 | }; | ||
| 35 | |||
| 36 | unsigned char app_b3[SHA256_DIGEST_LENGTH] = { | ||
| 37 | 0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92, | ||
| 38 | 0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67, | ||
| 39 | 0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e, | ||
| 40 | 0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0, | ||
| 41 | }; | ||
| 42 | |||
| 43 | unsigned char addenum_1[SHA224_DIGEST_LENGTH] = { | ||
| 44 | 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22, | ||
| 45 | 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3, | ||
| 46 | 0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7, | ||
| 47 | 0xe3, 0x6c, 0x9d, 0xa7, | ||
| 48 | }; | ||
| 49 | |||
| 50 | unsigned char addenum_2[SHA224_DIGEST_LENGTH] = { | ||
| 51 | 0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc, | ||
| 52 | 0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50, | ||
| 53 | 0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19, | ||
| 54 | 0x52, 0x52, 0x25, 0x25, | ||
| 55 | }; | ||
| 56 | |||
| 57 | unsigned char addenum_3[SHA224_DIGEST_LENGTH] = { | ||
| 58 | 0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8, | ||
| 59 | 0xbb, 0xb4, 0xc1, 0xea, 0x97, 0x61, 0x8a, 0x4b, | ||
| 60 | 0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48, 0xb2, 0xee, | ||
| 61 | 0x4e, 0xe7, 0xad, 0x67, | ||
| 62 | }; | ||
| 63 | |||
| 64 | int | ||
| 65 | main(int argc, char **argv) { | ||
| 66 | unsigned char md[SHA256_DIGEST_LENGTH]; | ||
| 67 | int i; | ||
| 68 | EVP_MD_CTX evp; | ||
| 69 | |||
| 70 | fprintf(stdout, "Testing SHA-256 "); | ||
| 71 | |||
| 72 | EVP_Digest("abc",3,md,NULL,EVP_sha256(),NULL); | ||
| 73 | if (memcmp(md, app_b1, sizeof(app_b1))) { | ||
| 74 | fflush(stdout); | ||
| 75 | fprintf(stderr, "\nTEST 1 of 3 failed.\n"); | ||
| 76 | return 1; | ||
| 77 | } | ||
| 78 | fprintf(stdout, "."); | ||
| 79 | fflush(stdout); | ||
| 80 | |||
| 81 | EVP_Digest( | ||
| 82 | "abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 83 | "ijkljklm""klmnlmno""mnopnopq", | ||
| 84 | 56, md, NULL, EVP_sha256(), NULL); | ||
| 85 | if (memcmp(md, app_b2, sizeof(app_b2))) { | ||
| 86 | fflush(stdout); | ||
| 87 | fprintf(stderr, "\nTEST 2 of 3 failed.\n"); | ||
| 88 | return 1; | ||
| 89 | } | ||
| 90 | fprintf(stdout, "."); | ||
| 91 | fflush(stdout); | ||
| 92 | |||
| 93 | EVP_MD_CTX_init(&evp); | ||
| 94 | EVP_DigestInit_ex(&evp, EVP_sha256(), NULL); | ||
| 95 | for (i = 0; i < 1000000; i += 160) | ||
| 96 | EVP_DigestUpdate(&evp, | ||
| 97 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 98 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 99 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 100 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 101 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 102 | (1000000 - i) < 160 ? 1000000 - i : 160); | ||
| 103 | EVP_DigestFinal_ex(&evp, md, NULL); | ||
| 104 | EVP_MD_CTX_cleanup(&evp); | ||
| 105 | |||
| 106 | if (memcmp(md, app_b3, sizeof(app_b3))) { | ||
| 107 | fflush(stdout); | ||
| 108 | fprintf(stderr, "\nTEST 3 of 3 failed.\n"); | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | fprintf(stdout, "."); | ||
| 112 | fflush(stdout); | ||
| 113 | |||
| 114 | fprintf(stdout, " passed.\n"); fflush(stdout); | ||
| 115 | |||
| 116 | fprintf(stdout, "Testing SHA-224 "); | ||
| 117 | |||
| 118 | EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL); | ||
| 119 | if (memcmp(md, addenum_1, sizeof(addenum_1))) { | ||
| 120 | fflush(stdout); | ||
| 121 | fprintf(stderr, "\nTEST 1 of 3 failed.\n"); | ||
| 122 | return 1; | ||
| 123 | } | ||
| 124 | fprintf(stdout, "."); | ||
| 125 | fflush(stdout); | ||
| 126 | |||
| 127 | EVP_Digest( | ||
| 128 | "abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 129 | "ijkljklm""klmnlmno""mnopnopq", | ||
| 130 | 56, md, NULL, EVP_sha224(), NULL); | ||
| 131 | if (memcmp(md, addenum_2, sizeof(addenum_2))) { | ||
| 132 | fflush(stdout); | ||
| 133 | fprintf(stderr, "\nTEST 2 of 3 failed.\n"); | ||
| 134 | return 1; | ||
| 135 | } | ||
| 136 | fprintf(stdout, "."); | ||
| 137 | fflush(stdout); | ||
| 138 | |||
| 139 | EVP_MD_CTX_init(&evp); | ||
| 140 | EVP_DigestInit_ex (&evp, EVP_sha224(), NULL); | ||
| 141 | for (i = 0; i < 1000000; i += 64) | ||
| 142 | EVP_DigestUpdate(&evp, | ||
| 143 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 144 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 145 | (1000000 - i) < 64 ? 1000000 - i : 64); | ||
| 146 | EVP_DigestFinal_ex(&evp, md, NULL); | ||
| 147 | EVP_MD_CTX_cleanup(&evp); | ||
| 148 | |||
| 149 | if (memcmp(md, addenum_3, sizeof(addenum_3))) { | ||
| 150 | fflush(stdout); | ||
| 151 | fprintf(stderr, "\nTEST 3 of 3 failed.\n"); | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | fprintf(stdout, "."); | ||
| 155 | fflush(stdout); | ||
| 156 | |||
| 157 | fprintf(stdout, " passed.\n"); | ||
| 158 | fflush(stdout); | ||
| 159 | |||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | #endif | ||
diff --git a/src/regress/lib/libcrypto/sha512/Makefile b/src/regress/lib/libcrypto/sha512/Makefile deleted file mode 100644 index 354860eae1..0000000000 --- a/src/regress/lib/libcrypto/sha512/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= sha512test | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/sha512/sha512test.c b/src/regress/lib/libcrypto/sha512/sha512test.c deleted file mode 100644 index bbcec93a2b..0000000000 --- a/src/regress/lib/libcrypto/sha512/sha512test.c +++ /dev/null | |||
| @@ -1,201 +0,0 @@ | |||
| 1 | /* $OpenBSD: sha512test.c,v 1.4 2018/07/17 17:06:50 tb Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | #include <openssl/crypto.h> | ||
| 13 | |||
| 14 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512) | ||
| 15 | int | ||
| 16 | main(int argc, char *argv[]) | ||
| 17 | { | ||
| 18 | printf("No SHA512 support\n"); | ||
| 19 | return (0); | ||
| 20 | } | ||
| 21 | #else | ||
| 22 | |||
| 23 | unsigned char app_c1[SHA512_DIGEST_LENGTH] = { | ||
| 24 | 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, | ||
| 25 | 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, | ||
| 26 | 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, | ||
| 27 | 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a, | ||
| 28 | 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8, | ||
| 29 | 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd, | ||
| 30 | 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e, | ||
| 31 | 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f, | ||
| 32 | }; | ||
| 33 | |||
| 34 | unsigned char app_c2[SHA512_DIGEST_LENGTH] = { | ||
| 35 | 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, | ||
| 36 | 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f, | ||
| 37 | 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1, | ||
| 38 | 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18, | ||
| 39 | 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4, | ||
| 40 | 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a, | ||
| 41 | 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54, | ||
| 42 | 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09, | ||
| 43 | }; | ||
| 44 | |||
| 45 | unsigned char app_c3[SHA512_DIGEST_LENGTH] = { | ||
| 46 | 0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64, | ||
| 47 | 0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63, | ||
| 48 | 0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28, | ||
| 49 | 0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb, | ||
| 50 | 0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a, | ||
| 51 | 0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b, | ||
| 52 | 0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e, | ||
| 53 | 0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b, | ||
| 54 | }; | ||
| 55 | |||
| 56 | unsigned char app_d1[SHA384_DIGEST_LENGTH] = { | ||
| 57 | 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, | ||
| 58 | 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, | ||
| 59 | 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, | ||
| 60 | 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, | ||
| 61 | 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, | ||
| 62 | 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7, | ||
| 63 | }; | ||
| 64 | |||
| 65 | unsigned char app_d2[SHA384_DIGEST_LENGTH] = { | ||
| 66 | 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, | ||
| 67 | 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, | ||
| 68 | 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, | ||
| 69 | 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, | ||
| 70 | 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, | ||
| 71 | 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39, | ||
| 72 | }; | ||
| 73 | |||
| 74 | unsigned char app_d3[SHA384_DIGEST_LENGTH] = { | ||
| 75 | 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb, | ||
| 76 | 0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c, | ||
| 77 | 0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52, | ||
| 78 | 0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b, | ||
| 79 | 0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb, | ||
| 80 | 0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85, | ||
| 81 | }; | ||
| 82 | |||
| 83 | int | ||
| 84 | main(int argc, char **argv) { | ||
| 85 | unsigned char md[SHA512_DIGEST_LENGTH]; | ||
| 86 | int i; | ||
| 87 | EVP_MD_CTX evp; | ||
| 88 | |||
| 89 | #ifdef OPENSSL_IA32_SSE2 | ||
| 90 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 91 | * The below code is retained exclusively for debugging purposes. */ | ||
| 92 | { | ||
| 93 | char *env; | ||
| 94 | |||
| 95 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 96 | OPENSSL_ia32cap = strtoul (env, NULL, 0); | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | fprintf(stdout, "Testing SHA-512 "); | ||
| 101 | |||
| 102 | EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL); | ||
| 103 | if (memcmp(md, app_c1, sizeof(app_c1))) { | ||
| 104 | fflush(stdout); | ||
| 105 | fprintf(stderr, "\nTEST 1 of 3 failed.\n"); | ||
| 106 | return 1; | ||
| 107 | } | ||
| 108 | fprintf(stdout, "."); | ||
| 109 | fflush(stdout); | ||
| 110 | |||
| 111 | EVP_Digest( | ||
| 112 | "abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 113 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 114 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 115 | "mnopqrst""nopqrstu", | ||
| 116 | 112, md, NULL, EVP_sha512(), NULL); | ||
| 117 | if (memcmp(md, app_c2, sizeof(app_c2))) { | ||
| 118 | fflush(stdout); | ||
| 119 | fprintf(stderr, "\nTEST 2 of 3 failed.\n"); | ||
| 120 | return 1; | ||
| 121 | } | ||
| 122 | fprintf(stdout, "."); | ||
| 123 | fflush(stdout); | ||
| 124 | |||
| 125 | EVP_MD_CTX_init(&evp); | ||
| 126 | EVP_DigestInit_ex(&evp, EVP_sha512(), NULL); | ||
| 127 | for (i = 0; i < 1000000; i += 288) | ||
| 128 | EVP_DigestUpdate(&evp, | ||
| 129 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 130 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 131 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 132 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 133 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 134 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 135 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 136 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 137 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 138 | (1000000 - i) < 288 ? 1000000 - i : 288); | ||
| 139 | EVP_DigestFinal_ex(&evp, md, NULL); | ||
| 140 | EVP_MD_CTX_cleanup(&evp); | ||
| 141 | |||
| 142 | if (memcmp(md, app_c3, sizeof(app_c3))) { | ||
| 143 | fflush(stdout); | ||
| 144 | fprintf(stderr, "\nTEST 3 of 3 failed.\n"); | ||
| 145 | return 1; | ||
| 146 | } | ||
| 147 | fprintf(stdout, "."); | ||
| 148 | fflush(stdout); | ||
| 149 | |||
| 150 | fprintf(stdout, " passed.\n"); | ||
| 151 | fflush(stdout); | ||
| 152 | |||
| 153 | fprintf(stdout, "Testing SHA-384 "); | ||
| 154 | |||
| 155 | EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL); | ||
| 156 | if (memcmp(md, app_d1, sizeof(app_d1))) { | ||
| 157 | fflush(stdout); | ||
| 158 | fprintf(stderr, "\nTEST 1 of 3 failed.\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | fprintf(stdout, "."); | ||
| 162 | fflush(stdout); | ||
| 163 | |||
| 164 | EVP_Digest( | ||
| 165 | "abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 166 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 167 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 168 | "mnopqrst""nopqrstu", | ||
| 169 | 112, md, NULL, EVP_sha384(), NULL); | ||
| 170 | if (memcmp(md, app_d2, sizeof(app_d2))) { | ||
| 171 | fflush(stdout); | ||
| 172 | fprintf(stderr, "\nTEST 2 of 3 failed.\n"); | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | fprintf(stdout, "."); | ||
| 176 | fflush(stdout); | ||
| 177 | |||
| 178 | EVP_MD_CTX_init(&evp); | ||
| 179 | EVP_DigestInit_ex(&evp, EVP_sha384(), NULL); | ||
| 180 | for (i = 0; i < 1000000; i += 64) | ||
| 181 | EVP_DigestUpdate(&evp, | ||
| 182 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 183 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 184 | (1000000 - i) < 64 ? 1000000 - i : 64); | ||
| 185 | EVP_DigestFinal_ex(&evp, md, NULL); | ||
| 186 | EVP_MD_CTX_cleanup(&evp); | ||
| 187 | |||
| 188 | if (memcmp(md, app_d3, sizeof(app_d3))) { | ||
| 189 | fflush(stdout); | ||
| 190 | fprintf(stderr, "\nTEST 3 of 3 failed.\n"); | ||
| 191 | return 1; | ||
| 192 | } | ||
| 193 | fprintf(stdout, "."); | ||
| 194 | fflush(stdout); | ||
| 195 | |||
| 196 | fprintf(stdout, " passed.\n"); | ||
| 197 | fflush(stdout); | ||
| 198 | |||
| 199 | return 0; | ||
| 200 | } | ||
| 201 | #endif | ||
diff --git a/src/regress/lib/libcrypto/utf8/Makefile b/src/regress/lib/libcrypto/utf8/Makefile deleted file mode 100644 index 5f06560ea5..0000000000 --- a/src/regress/lib/libcrypto/utf8/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2016/12/21 15:51:05 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= utf8test | ||
| 4 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libcrypto/asn1 | ||
| 5 | LDADD= ${CRYPTO_INT} | ||
| 6 | DPADD= ${LIBCRYPTO} | ||
| 7 | WARNINGS=Yes | ||
| 8 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/utf8/utf8test.c b/src/regress/lib/libcrypto/utf8/utf8test.c deleted file mode 100644 index e3a47d5adf..0000000000 --- a/src/regress/lib/libcrypto/utf8/utf8test.c +++ /dev/null | |||
| @@ -1,319 +0,0 @@ | |||
| 1 | /* $OpenBSD: utf8test.c,v 1.4 2018/07/17 17:06:50 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Philip Guenther <guenther@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * A mostly exhaustive test of UTF-8 decoder and encoder | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <err.h> | ||
| 25 | |||
| 26 | #include <openssl/asn1.h> | ||
| 27 | #include "asn1_locl.h" /* peek into the internals */ | ||
| 28 | |||
| 29 | #define UNCHANGED 0xfedcba98 | ||
| 30 | |||
| 31 | #define ASSERT(x) \ | ||
| 32 | do { \ | ||
| 33 | if (!(x)) \ | ||
| 34 | errx(1, "test failed at line %d: %s", \ | ||
| 35 | __LINE__, #x); \ | ||
| 36 | } while (0) | ||
| 37 | |||
| 38 | int | ||
| 39 | main(void) | ||
| 40 | { | ||
| 41 | unsigned char testbuf[] = "012345"; | ||
| 42 | const unsigned char zerobuf[sizeof testbuf] = { 0 }; | ||
| 43 | unsigned long value; | ||
| 44 | unsigned int i, j, k, l; | ||
| 45 | int ret; | ||
| 46 | |||
| 47 | /* | ||
| 48 | * First, verify UTF8_getc() | ||
| 49 | */ | ||
| 50 | value = UNCHANGED; | ||
| 51 | ret = UTF8_getc(testbuf, 0, &value); | ||
| 52 | ASSERT(ret == 0); | ||
| 53 | ASSERT(value == UNCHANGED); | ||
| 54 | |||
| 55 | /* check all valid single-byte chars */ | ||
| 56 | for (i = 0; i < 0x80; i++) { | ||
| 57 | testbuf[0] = i; | ||
| 58 | ret = UTF8_getc(testbuf, 1, &value); | ||
| 59 | ASSERT(ret == 1); | ||
| 60 | ASSERT(value == i); | ||
| 61 | |||
| 62 | ret = UTF8_getc(testbuf, 2, &value); | ||
| 63 | ASSERT(ret == 1); | ||
| 64 | ASSERT(value == i); | ||
| 65 | } | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Verify failure on all invalid initial bytes: | ||
| 69 | * 0x80 - 0xBF following bytes only | ||
| 70 | * 0xC0 - 0xC1 used to be in non-shortest forms | ||
| 71 | * 0xF5 - 0xFD used to be initial for 5 and 6 byte sequences | ||
| 72 | * 0xFE - 0xFF have never been valid in utf-8 | ||
| 73 | */ | ||
| 74 | for (i = 0x80; i < 0xC2; i++) { | ||
| 75 | value = UNCHANGED; | ||
| 76 | testbuf[0] = i; | ||
| 77 | ret = UTF8_getc(testbuf, 1, &value); | ||
| 78 | ASSERT(ret == -2); | ||
| 79 | ASSERT(value == UNCHANGED); | ||
| 80 | } | ||
| 81 | for (i = 0xF5; i < 0x100; i++) { | ||
| 82 | value = UNCHANGED; | ||
| 83 | testbuf[0] = i; | ||
| 84 | ret = UTF8_getc(testbuf, 1, &value); | ||
| 85 | ASSERT(ret == -2); | ||
| 86 | ASSERT(value == UNCHANGED); | ||
| 87 | } | ||
| 88 | |||
| 89 | /* | ||
| 90 | * Verify handling of all two-byte sequences | ||
| 91 | */ | ||
| 92 | for (i = 0xC2; i < 0xE0; i++) { | ||
| 93 | testbuf[0] = i; | ||
| 94 | |||
| 95 | for (j = 0; j < 0x100; j++) { | ||
| 96 | testbuf[1] = j; | ||
| 97 | |||
| 98 | value = UNCHANGED; | ||
| 99 | ret = UTF8_getc(testbuf, 1, &value); | ||
| 100 | ASSERT(ret == -1); | ||
| 101 | ASSERT(value == UNCHANGED); | ||
| 102 | |||
| 103 | ret = UTF8_getc(testbuf, 2, &value); | ||
| 104 | |||
| 105 | /* outside range of trailing bytes */ | ||
| 106 | if (j < 0x80 || j > 0xBF) { | ||
| 107 | ASSERT(ret == -3); | ||
| 108 | ASSERT(value == UNCHANGED); | ||
| 109 | continue; | ||
| 110 | } | ||
| 111 | |||
| 112 | /* valid */ | ||
| 113 | ASSERT(ret == 2); | ||
| 114 | ASSERT((value & 0x3F) == (j & 0x3F)); | ||
| 115 | ASSERT(value >> 6 == (i & 0x1F)); | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | /* | ||
| 120 | * Verify handling of all three-byte sequences | ||
| 121 | */ | ||
| 122 | for (i = 0xE0; i < 0xF0; i++) { | ||
| 123 | testbuf[0] = i; | ||
| 124 | |||
| 125 | for (j = 0; j < 0x100; j++) { | ||
| 126 | testbuf[1] = j; | ||
| 127 | |||
| 128 | for (k = 0; k < 0x100; k++) { | ||
| 129 | testbuf[2] = k; | ||
| 130 | |||
| 131 | value = UNCHANGED; | ||
| 132 | ret = UTF8_getc(testbuf, 2, &value); | ||
| 133 | ASSERT(ret == -1); | ||
| 134 | ASSERT(value == UNCHANGED); | ||
| 135 | |||
| 136 | ret = UTF8_getc(testbuf, 3, &value); | ||
| 137 | |||
| 138 | /* outside range of trailing bytes */ | ||
| 139 | if (j < 0x80 || j > 0xBF || | ||
| 140 | k < 0x80 || k > 0xBF) { | ||
| 141 | ASSERT(ret == -3); | ||
| 142 | ASSERT(value == UNCHANGED); | ||
| 143 | continue; | ||
| 144 | } | ||
| 145 | |||
| 146 | /* non-shortest form */ | ||
| 147 | if (i == 0xE0 && j < 0xA0) { | ||
| 148 | ASSERT(ret == -4); | ||
| 149 | ASSERT(value == UNCHANGED); | ||
| 150 | continue; | ||
| 151 | } | ||
| 152 | |||
| 153 | /* surrogate pair code point */ | ||
| 154 | if (i == 0xED && j > 0x9F) { | ||
| 155 | ASSERT(ret == -2); | ||
| 156 | ASSERT(value == UNCHANGED); | ||
| 157 | continue; | ||
| 158 | } | ||
| 159 | |||
| 160 | ASSERT(ret == 3); | ||
| 161 | ASSERT((value & 0x3F) == (k & 0x3F)); | ||
| 162 | ASSERT(((value >> 6) & 0x3F) == (j & 0x3F)); | ||
| 163 | ASSERT(value >> 12 == (i & 0x0F)); | ||
| 164 | } | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | /* | ||
| 169 | * Verify handling of all four-byte sequences | ||
| 170 | */ | ||
| 171 | for (i = 0xF0; i < 0xF5; i++) { | ||
| 172 | testbuf[0] = i; | ||
| 173 | |||
| 174 | for (j = 0; j < 0x100; j++) { | ||
| 175 | testbuf[1] = j; | ||
| 176 | |||
| 177 | for (k = 0; k < 0x100; k++) { | ||
| 178 | testbuf[2] = k; | ||
| 179 | |||
| 180 | for (l = 0; l < 0x100; l++) { | ||
| 181 | testbuf[3] = l; | ||
| 182 | |||
| 183 | value = UNCHANGED; | ||
| 184 | ret = UTF8_getc(testbuf, 3, &value); | ||
| 185 | ASSERT(ret == -1); | ||
| 186 | ASSERT(value == UNCHANGED); | ||
| 187 | |||
| 188 | ret = UTF8_getc(testbuf, 4, &value); | ||
| 189 | |||
| 190 | /* outside range of trailing bytes */ | ||
| 191 | if (j < 0x80 || j > 0xBF || | ||
| 192 | k < 0x80 || k > 0xBF || | ||
| 193 | l < 0x80 || l > 0xBF) { | ||
| 194 | ASSERT(ret == -3); | ||
| 195 | ASSERT(value == UNCHANGED); | ||
| 196 | continue; | ||
| 197 | } | ||
| 198 | |||
| 199 | /* non-shortest form */ | ||
| 200 | if (i == 0xF0 && j < 0x90) { | ||
| 201 | ASSERT(ret == -4); | ||
| 202 | ASSERT(value == UNCHANGED); | ||
| 203 | continue; | ||
| 204 | } | ||
| 205 | |||
| 206 | /* beyond end of UCS range */ | ||
| 207 | if (i == 0xF4 && j > 0x8F) { | ||
| 208 | ASSERT(ret == -2); | ||
| 209 | ASSERT(value == UNCHANGED); | ||
| 210 | continue; | ||
| 211 | } | ||
| 212 | |||
| 213 | ASSERT(ret == 4); | ||
| 214 | ASSERT((value & 0x3F) == (l & 0x3F)); | ||
| 215 | ASSERT(((value >> 6) & 0x3F) == | ||
| 216 | (k & 0x3F)); | ||
| 217 | ASSERT(((value >> 12) & 0x3F) == | ||
| 218 | (j & 0x3F)); | ||
| 219 | ASSERT(value >> 18 == (i & 0x07)); | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | |||
| 226 | /* | ||
| 227 | * Next, verify UTF8_putc() | ||
| 228 | */ | ||
| 229 | memset(testbuf, 0, sizeof testbuf); | ||
| 230 | |||
| 231 | /* single-byte sequences */ | ||
| 232 | for (i = 0; i < 0x80; i++) { | ||
| 233 | ret = UTF8_putc(NULL, 0, i); | ||
| 234 | ASSERT(ret == 1); | ||
| 235 | |||
| 236 | testbuf[0] = 0; | ||
| 237 | ret = UTF8_putc(testbuf, 0, i); | ||
| 238 | ASSERT(ret == -1); | ||
| 239 | ASSERT(memcmp(testbuf, zerobuf, sizeof testbuf) == 0); | ||
| 240 | |||
| 241 | ret = UTF8_putc(testbuf, 1, i); | ||
| 242 | ASSERT(ret == 1); | ||
| 243 | ASSERT(testbuf[0] == i); | ||
| 244 | ASSERT(memcmp(testbuf+1, zerobuf, sizeof(testbuf)-1) == 0); | ||
| 245 | } | ||
| 246 | |||
| 247 | /* two-byte sequences */ | ||
| 248 | for (i = 0x80; i < 0x800; i++) { | ||
| 249 | ret = UTF8_putc(NULL, 0, i); | ||
| 250 | ASSERT(ret == 2); | ||
| 251 | |||
| 252 | testbuf[0] = testbuf[1] = 0; | ||
| 253 | ret = UTF8_putc(testbuf, 1, i); | ||
| 254 | ASSERT(ret == -1); | ||
| 255 | ASSERT(memcmp(testbuf, zerobuf, sizeof testbuf) == 0); | ||
| 256 | |||
| 257 | ret = UTF8_putc(testbuf, 2, i); | ||
| 258 | ASSERT(ret == 2); | ||
| 259 | ASSERT(memcmp(testbuf+2, zerobuf, sizeof(testbuf)-2) == 0); | ||
| 260 | ret = UTF8_getc(testbuf, 2, &value); | ||
| 261 | ASSERT(ret == 2); | ||
| 262 | ASSERT(value == i); | ||
| 263 | } | ||
| 264 | |||
| 265 | /* three-byte sequences */ | ||
| 266 | for (i = 0x800; i < 0x10000; i++) { | ||
| 267 | if (i >= 0xD800 && i < 0xE000) { | ||
| 268 | /* surrogates aren't valid */ | ||
| 269 | ret = UTF8_putc(NULL, 0, i); | ||
| 270 | ASSERT(ret == -2); | ||
| 271 | continue; | ||
| 272 | } | ||
| 273 | |||
| 274 | ret = UTF8_putc(NULL, 0, i); | ||
| 275 | ASSERT(ret == 3); | ||
| 276 | |||
| 277 | testbuf[0] = testbuf[1] = testbuf[2] = 0; | ||
| 278 | ret = UTF8_putc(testbuf, 2, i); | ||
| 279 | ASSERT(ret == -1); | ||
| 280 | ASSERT(memcmp(testbuf, zerobuf, sizeof testbuf) == 0); | ||
| 281 | |||
| 282 | ret = UTF8_putc(testbuf, 3, i); | ||
| 283 | ASSERT(ret == 3); | ||
| 284 | ASSERT(memcmp(testbuf+3, zerobuf, sizeof(testbuf)-3) == 0); | ||
| 285 | ret = UTF8_getc(testbuf, 3, &value); | ||
| 286 | ASSERT(ret == 3); | ||
| 287 | ASSERT(value == i); | ||
| 288 | } | ||
| 289 | |||
| 290 | /* four-byte sequences */ | ||
| 291 | for (i = 0x10000; i < 0x110000; i++) { | ||
| 292 | ret = UTF8_putc(NULL, 0, i); | ||
| 293 | ASSERT(ret == 4); | ||
| 294 | |||
| 295 | testbuf[0] = testbuf[1] = testbuf[2] = testbuf[3] = 0; | ||
| 296 | ret = UTF8_putc(testbuf, 3, i); | ||
| 297 | ASSERT(ret == -1); | ||
| 298 | ASSERT(memcmp(testbuf, zerobuf, sizeof testbuf) == 0); | ||
| 299 | |||
| 300 | ret = UTF8_putc(testbuf, 4, i); | ||
| 301 | ASSERT(ret == 4); | ||
| 302 | ASSERT(memcmp(testbuf+4, zerobuf, sizeof(testbuf)-4) == 0); | ||
| 303 | ret = UTF8_getc(testbuf, 4, &value); | ||
| 304 | ASSERT(ret == 4); | ||
| 305 | ASSERT(value == i); | ||
| 306 | } | ||
| 307 | |||
| 308 | /* spot check some larger values to confirm error return */ | ||
| 309 | for (i = 0x110000; i < 0x110100; i++) { | ||
| 310 | ret = UTF8_putc(NULL, 0, i); | ||
| 311 | ASSERT(ret == -2); | ||
| 312 | } | ||
| 313 | for (value = (unsigned long)-1; value > (unsigned long)-256; value--) { | ||
| 314 | ret = UTF8_putc(NULL, 0, value); | ||
| 315 | ASSERT(ret == -2); | ||
| 316 | } | ||
| 317 | |||
| 318 | return 0; | ||
| 319 | } | ||
diff --git a/src/regress/lib/libcrypto/wycheproof/Makefile b/src/regress/lib/libcrypto/wycheproof/Makefile deleted file mode 100644 index 4359db438c..0000000000 --- a/src/regress/lib/libcrypto/wycheproof/Makefile +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2018/09/22 00:10:18 tb Exp $ | ||
| 2 | |||
| 3 | GO_VERSION != sh -c "(go version) 2>/dev/null || true" | ||
| 4 | |||
| 5 | .if empty(GO_VERSION) | ||
| 6 | regress: | ||
| 7 | @echo package go is required for this regress | ||
| 8 | @echo SKIPPED | ||
| 9 | .endif | ||
| 10 | |||
| 11 | CLEANFILES+=wycheproof | ||
| 12 | REGRESS_TARGETS=regress-wycheproof | ||
| 13 | |||
| 14 | audit: wycheproof | ||
| 15 | ./wycheproof -v | ||
| 16 | |||
| 17 | wycheproof: wycheproof.go | ||
| 18 | go build -o wycheproof ${.CURDIR}/wycheproof.go | ||
| 19 | |||
| 20 | regress-wycheproof: wycheproof | ||
| 21 | ./wycheproof | ||
| 22 | |||
| 23 | .PHONY: audit | ||
| 24 | |||
| 25 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go deleted file mode 100644 index 9bc4e5fd8b..0000000000 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ /dev/null | |||
| @@ -1,2211 +0,0 @@ | |||
| 1 | /* $OpenBSD: wycheproof.go,v 1.86 2018/10/20 16:02:05 tb Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | ||
| 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | ||
| 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 | // Wycheproof runs test vectors from Project Wycheproof against libcrypto. | ||
| 20 | package main | ||
| 21 | |||
| 22 | /* | ||
| 23 | #cgo LDFLAGS: -lcrypto | ||
| 24 | |||
| 25 | #include <string.h> | ||
| 26 | |||
| 27 | #include <openssl/aes.h> | ||
| 28 | #include <openssl/bio.h> | ||
| 29 | #include <openssl/bn.h> | ||
| 30 | #include <openssl/cmac.h> | ||
| 31 | #include <openssl/curve25519.h> | ||
| 32 | #include <openssl/dsa.h> | ||
| 33 | #include <openssl/ec.h> | ||
| 34 | #include <openssl/ecdsa.h> | ||
| 35 | #include <openssl/evp.h> | ||
| 36 | #include <openssl/objects.h> | ||
| 37 | #include <openssl/pem.h> | ||
| 38 | #include <openssl/x509.h> | ||
| 39 | #include <openssl/rsa.h> | ||
| 40 | */ | ||
| 41 | import "C" | ||
| 42 | |||
| 43 | import ( | ||
| 44 | "bytes" | ||
| 45 | "crypto/sha1" | ||
| 46 | "crypto/sha256" | ||
| 47 | "crypto/sha512" | ||
| 48 | "encoding/base64" | ||
| 49 | "encoding/hex" | ||
| 50 | "encoding/json" | ||
| 51 | "flag" | ||
| 52 | "fmt" | ||
| 53 | "hash" | ||
| 54 | "io/ioutil" | ||
| 55 | "log" | ||
| 56 | "os" | ||
| 57 | "path/filepath" | ||
| 58 | "sort" | ||
| 59 | "unsafe" | ||
| 60 | ) | ||
| 61 | |||
| 62 | const testVectorPath = "/usr/local/share/wycheproof/testvectors" | ||
| 63 | |||
| 64 | var acceptableAudit = false | ||
| 65 | var acceptableComments map[string]int | ||
| 66 | var acceptableFlags map[string]int | ||
| 67 | |||
| 68 | type wycheproofJWKPublic struct { | ||
| 69 | Crv string `json:"crv"` | ||
| 70 | KID string `json:"kid"` | ||
| 71 | KTY string `json:"kty"` | ||
| 72 | X string `json:"x"` | ||
| 73 | Y string `json:"y"` | ||
| 74 | } | ||
| 75 | |||
| 76 | type wycheproofJWKPrivate struct { | ||
| 77 | Crv string `json:"crv"` | ||
| 78 | D string `json:"d"` | ||
| 79 | KID string `json:"kid"` | ||
| 80 | KTY string `json:"kty"` | ||
| 81 | X string `json:"x"` | ||
| 82 | Y string `json:"y"` | ||
| 83 | } | ||
| 84 | |||
| 85 | type wycheproofTestGroupAesCbcPkcs5 struct { | ||
| 86 | IVSize int `json:"ivSize"` | ||
| 87 | KeySize int `json:"keySize"` | ||
| 88 | Type string `json:"type"` | ||
| 89 | Tests []*wycheproofTestAesCbcPkcs5 `json:"tests"` | ||
| 90 | } | ||
| 91 | |||
| 92 | type wycheproofTestAesCbcPkcs5 struct { | ||
| 93 | TCID int `json:"tcId"` | ||
| 94 | Comment string `json:"comment"` | ||
| 95 | Key string `json:"key"` | ||
| 96 | IV string `json:"iv"` | ||
| 97 | Msg string `json:"msg"` | ||
| 98 | CT string `json:"ct"` | ||
| 99 | Result string `json:"result"` | ||
| 100 | Flags []string `json:"flags"` | ||
| 101 | } | ||
| 102 | |||
| 103 | type wycheproofTestGroupAead struct { | ||
| 104 | IVSize int `json:"ivSize"` | ||
| 105 | KeySize int `json:"keySize"` | ||
| 106 | TagSize int `json:"tagSize"` | ||
| 107 | Type string `json:"type"` | ||
| 108 | Tests []*wycheproofTestAead `json:"tests"` | ||
| 109 | } | ||
| 110 | |||
| 111 | type wycheproofTestAead struct { | ||
| 112 | TCID int `json:"tcId"` | ||
| 113 | Comment string `json:"comment"` | ||
| 114 | Key string `json:"key"` | ||
| 115 | IV string `json:"iv"` | ||
| 116 | AAD string `json:"aad"` | ||
| 117 | Msg string `json:"msg"` | ||
| 118 | CT string `json:"ct"` | ||
| 119 | Tag string `json:"tag"` | ||
| 120 | Result string `json:"result"` | ||
| 121 | Flags []string `json:"flags"` | ||
| 122 | } | ||
| 123 | |||
| 124 | type wycheproofTestGroupAesCmac struct { | ||
| 125 | KeySize int `json:"keySize"` | ||
| 126 | TagSize int `json:"tagSize"` | ||
| 127 | Type string `json:"type"` | ||
| 128 | Tests []*wycheproofTestAesCmac `json:"tests"` | ||
| 129 | } | ||
| 130 | |||
| 131 | type wycheproofTestAesCmac struct { | ||
| 132 | TCID int `json:"tcId"` | ||
| 133 | Comment string `json:"comment"` | ||
| 134 | Key string `json:"key"` | ||
| 135 | Msg string `json:"msg"` | ||
| 136 | Tag string `json:"tag"` | ||
| 137 | Result string `json:"result"` | ||
| 138 | Flags []string `json:"flags"` | ||
| 139 | } | ||
| 140 | |||
| 141 | type wycheproofDSAKey struct { | ||
| 142 | G string `json:"g"` | ||
| 143 | KeySize int `json:"keySize"` | ||
| 144 | P string `json:"p"` | ||
| 145 | Q string `json:"q"` | ||
| 146 | Type string `json:"type"` | ||
| 147 | Y string `json:"y"` | ||
| 148 | } | ||
| 149 | |||
| 150 | type wycheproofTestDSA struct { | ||
| 151 | TCID int `json:"tcId"` | ||
| 152 | Comment string `json:"comment"` | ||
| 153 | Msg string `json:"msg"` | ||
| 154 | Sig string `json:"sig"` | ||
| 155 | Result string `json:"result"` | ||
| 156 | Flags []string `json:"flags"` | ||
| 157 | } | ||
| 158 | |||
| 159 | type wycheproofTestGroupDSA struct { | ||
| 160 | Key *wycheproofDSAKey `json:"key"` | ||
| 161 | KeyDER string `json:"keyDer"` | ||
| 162 | KeyPEM string `json:"keyPem"` | ||
| 163 | SHA string `json:"sha"` | ||
| 164 | Type string `json:"type"` | ||
| 165 | Tests []*wycheproofTestDSA `json:"tests"` | ||
| 166 | } | ||
| 167 | |||
| 168 | type wycheproofTestECDH struct { | ||
| 169 | TCID int `json:"tcId"` | ||
| 170 | Comment string `json:"comment"` | ||
| 171 | Public string `json:"public"` | ||
| 172 | Private string `json:"private"` | ||
| 173 | Shared string `json:"shared"` | ||
| 174 | Result string `json:"result"` | ||
| 175 | Flags []string `json:"flags"` | ||
| 176 | } | ||
| 177 | |||
| 178 | type wycheproofTestGroupECDH struct { | ||
| 179 | Curve string `json:"curve"` | ||
| 180 | Encoding string `json:"encoding"` | ||
| 181 | Type string `json:"type"` | ||
| 182 | Tests []*wycheproofTestECDH `json:"tests"` | ||
| 183 | } | ||
| 184 | |||
| 185 | type wycheproofTestECDHWebCrypto struct { | ||
| 186 | TCID int `json:"tcId"` | ||
| 187 | Comment string `json:"comment"` | ||
| 188 | Public *wycheproofJWKPublic `json:"public"` | ||
| 189 | Private *wycheproofJWKPrivate `json:"private"` | ||
| 190 | Shared string `json:"shared"` | ||
| 191 | Result string `json:"result"` | ||
| 192 | Flags []string `json:"flags"` | ||
| 193 | } | ||
| 194 | |||
| 195 | type wycheproofTestGroupECDHWebCrypto struct { | ||
| 196 | Curve string `json:"curve"` | ||
| 197 | Encoding string `json:"encoding"` | ||
| 198 | Type string `json:"type"` | ||
| 199 | Tests []*wycheproofTestECDHWebCrypto `json:"tests"` | ||
| 200 | } | ||
| 201 | |||
| 202 | type wycheproofECDSAKey struct { | ||
| 203 | Curve string `json:"curve"` | ||
| 204 | KeySize int `json:"keySize"` | ||
| 205 | Type string `json:"type"` | ||
| 206 | Uncompressed string `json:"uncompressed"` | ||
| 207 | WX string `json:"wx"` | ||
| 208 | WY string `json:"wy"` | ||
| 209 | } | ||
| 210 | |||
| 211 | type wycheproofTestECDSA struct { | ||
| 212 | TCID int `json:"tcId"` | ||
| 213 | Comment string `json:"comment"` | ||
| 214 | Msg string `json:"msg"` | ||
| 215 | Sig string `json:"sig"` | ||
| 216 | Result string `json:"result"` | ||
| 217 | Flags []string `json:"flags"` | ||
| 218 | } | ||
| 219 | |||
| 220 | type wycheproofTestGroupECDSA struct { | ||
| 221 | Key *wycheproofECDSAKey `json:"key"` | ||
| 222 | KeyDER string `json:"keyDer"` | ||
| 223 | KeyPEM string `json:"keyPem"` | ||
| 224 | SHA string `json:"sha"` | ||
| 225 | Type string `json:"type"` | ||
| 226 | Tests []*wycheproofTestECDSA `json:"tests"` | ||
| 227 | } | ||
| 228 | |||
| 229 | type wycheproofTestGroupECDSAWebCrypto struct { | ||
| 230 | JWK *wycheproofJWKPublic `json:"jwk"` | ||
| 231 | Key *wycheproofECDSAKey `json:"key"` | ||
| 232 | KeyDER string `json:"keyDer"` | ||
| 233 | KeyPEM string `json:"keyPem"` | ||
| 234 | SHA string `json:"sha"` | ||
| 235 | Type string `json:"type"` | ||
| 236 | Tests []*wycheproofTestECDSA `json:"tests"` | ||
| 237 | } | ||
| 238 | |||
| 239 | type wycheproofTestKW struct { | ||
| 240 | TCID int `json:"tcId"` | ||
| 241 | Comment string `json:"comment"` | ||
| 242 | Key string `json:"key"` | ||
| 243 | Msg string `json:"msg"` | ||
| 244 | CT string `json:"ct"` | ||
| 245 | Result string `json:"result"` | ||
| 246 | Flags []string `json:"flags"` | ||
| 247 | } | ||
| 248 | |||
| 249 | type wycheproofTestGroupKW struct { | ||
| 250 | KeySize int `json:"keySize"` | ||
| 251 | Type string `json:"type"` | ||
| 252 | Tests []*wycheproofTestKW `json:"tests"` | ||
| 253 | } | ||
| 254 | |||
| 255 | type wycheproofTestRSA struct { | ||
| 256 | TCID int `json:"tcId"` | ||
| 257 | Comment string `json:"comment"` | ||
| 258 | Msg string `json:"msg"` | ||
| 259 | Sig string `json:"sig"` | ||
| 260 | Padding string `json:"padding"` | ||
| 261 | Result string `json:"result"` | ||
| 262 | Flags []string `json:"flags"` | ||
| 263 | } | ||
| 264 | |||
| 265 | type wycheproofTestGroupRSA struct { | ||
| 266 | E string `json:"e"` | ||
| 267 | KeyASN string `json:"keyAsn"` | ||
| 268 | KeyDER string `json:"keyDer"` | ||
| 269 | KeyPEM string `json:"keyPem"` | ||
| 270 | KeySize int `json:"keysize"` | ||
| 271 | N string `json:"n"` | ||
| 272 | SHA string `json:"sha"` | ||
| 273 | Type string `json:"type"` | ||
| 274 | Tests []*wycheproofTestRSA `json:"tests"` | ||
| 275 | } | ||
| 276 | |||
| 277 | type wycheproofTestRSASSA struct { | ||
| 278 | TCID int `json:"tcId"` | ||
| 279 | Comment string `json:"comment"` | ||
| 280 | Msg string `json:"msg"` | ||
| 281 | Sig string `json:"sig"` | ||
| 282 | Result string `json:"result"` | ||
| 283 | Flags []string `json:"flags"` | ||
| 284 | } | ||
| 285 | |||
| 286 | type wycheproofTestGroupRSASSA struct { | ||
| 287 | E string `json:"e"` | ||
| 288 | KeyASN string `json:"keyAsn"` | ||
| 289 | KeyDER string `json:"keyDer"` | ||
| 290 | KeyPEM string `json:"keyPem"` | ||
| 291 | KeySize int `json:"keysize"` | ||
| 292 | MGF string `json:"mgf"` | ||
| 293 | MGFSHA string `json:"mgfSha"` | ||
| 294 | N string `json:"n"` | ||
| 295 | SLen int `json:"sLen"` | ||
| 296 | SHA string `json:"sha"` | ||
| 297 | Type string `json:"type"` | ||
| 298 | Tests []*wycheproofTestRSASSA `json:"tests"` | ||
| 299 | } | ||
| 300 | |||
| 301 | type wycheproofTestX25519 struct { | ||
| 302 | TCID int `json:"tcId"` | ||
| 303 | Comment string `json:"comment"` | ||
| 304 | Curve string `json:"curve"` | ||
| 305 | Public string `json:"public"` | ||
| 306 | Private string `json:"private"` | ||
| 307 | Shared string `json:"shared"` | ||
| 308 | Result string `json:"result"` | ||
| 309 | Flags []string `json:"flags"` | ||
| 310 | } | ||
| 311 | |||
| 312 | type wycheproofTestGroupX25519 struct { | ||
| 313 | Curve string `json:"curve"` | ||
| 314 | Tests []*wycheproofTestX25519 `json:"tests"` | ||
| 315 | } | ||
| 316 | |||
| 317 | type wycheproofTestVectors struct { | ||
| 318 | Algorithm string `json:"algorithm"` | ||
| 319 | GeneratorVersion string `json:"generatorVersion"` | ||
| 320 | Notes map[string]string `json:"notes"` | ||
| 321 | NumberOfTests int `json:"numberOfTests"` | ||
| 322 | // Header | ||
| 323 | TestGroups []json.RawMessage `json:"testGroups"` | ||
| 324 | } | ||
| 325 | |||
| 326 | var nids = map[string]int{ | ||
| 327 | "brainpoolP224r1": C.NID_brainpoolP224r1, | ||
| 328 | "brainpoolP256r1": C.NID_brainpoolP256r1, | ||
| 329 | "brainpoolP320r1": C.NID_brainpoolP320r1, | ||
| 330 | "brainpoolP384r1": C.NID_brainpoolP384r1, | ||
| 331 | "brainpoolP512r1": C.NID_brainpoolP512r1, | ||
| 332 | "brainpoolP224t1": C.NID_brainpoolP224t1, | ||
| 333 | "brainpoolP256t1": C.NID_brainpoolP256t1, | ||
| 334 | "brainpoolP320t1": C.NID_brainpoolP320t1, | ||
| 335 | "brainpoolP384t1": C.NID_brainpoolP384t1, | ||
| 336 | "brainpoolP512t1": C.NID_brainpoolP512t1, | ||
| 337 | "secp224r1": C.NID_secp224r1, | ||
| 338 | "secp256k1": C.NID_secp256k1, | ||
| 339 | "P-256K": C.NID_secp256k1, | ||
| 340 | "secp256r1": C.NID_X9_62_prime256v1, // RFC 8422, Table 4, p.32 | ||
| 341 | "P-256": C.NID_X9_62_prime256v1, | ||
| 342 | "secp384r1": C.NID_secp384r1, | ||
| 343 | "P-384": C.NID_secp384r1, | ||
| 344 | "secp521r1": C.NID_secp521r1, | ||
| 345 | "P-521": C.NID_secp521r1, | ||
| 346 | "SHA-1": C.NID_sha1, | ||
| 347 | "SHA-224": C.NID_sha224, | ||
| 348 | "SHA-256": C.NID_sha256, | ||
| 349 | "SHA-384": C.NID_sha384, | ||
| 350 | "SHA-512": C.NID_sha512, | ||
| 351 | } | ||
| 352 | |||
| 353 | func gatherAcceptableStatistics(testcase int, comment string, flags []string) { | ||
| 354 | fmt.Printf("AUDIT: Test case %d (%q) %v\n", testcase, comment, flags) | ||
| 355 | |||
| 356 | if comment == "" { | ||
| 357 | acceptableComments["No comment"]++ | ||
| 358 | } else { | ||
| 359 | acceptableComments[comment]++ | ||
| 360 | } | ||
| 361 | |||
| 362 | if len(flags) == 0 { | ||
| 363 | acceptableFlags["NoFlag"]++ | ||
| 364 | } else { | ||
| 365 | for _, flag := range flags { | ||
| 366 | acceptableFlags[flag]++ | ||
| 367 | } | ||
| 368 | } | ||
| 369 | } | ||
| 370 | |||
| 371 | func printAcceptableStatistics() { | ||
| 372 | fmt.Printf("\nComment statistics:\n") | ||
| 373 | |||
| 374 | var comments []string | ||
| 375 | for comment := range acceptableComments { | ||
| 376 | comments = append(comments, comment) | ||
| 377 | } | ||
| 378 | sort.Strings(comments) | ||
| 379 | for _, comment := range comments { | ||
| 380 | prcomment := comment | ||
| 381 | if len(comment) > 45 { | ||
| 382 | prcomment = comment[0:42] + "..." | ||
| 383 | } | ||
| 384 | fmt.Printf("%-45v %5d\n", prcomment, acceptableComments[comment]) | ||
| 385 | } | ||
| 386 | |||
| 387 | fmt.Printf("\nFlag statistics:\n") | ||
| 388 | var flags []string | ||
| 389 | for flag := range acceptableFlags { | ||
| 390 | flags = append(flags, flag) | ||
| 391 | } | ||
| 392 | sort.Strings(flags) | ||
| 393 | for _, flag := range flags { | ||
| 394 | fmt.Printf("%-45v %5d\n", flag, acceptableFlags[flag]) | ||
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 398 | func nidFromString(ns string) (int, error) { | ||
| 399 | nid, ok := nids[ns] | ||
| 400 | if ok { | ||
| 401 | return nid, nil | ||
| 402 | } | ||
| 403 | return -1, fmt.Errorf("unknown NID %q", ns) | ||
| 404 | } | ||
| 405 | |||
| 406 | func hashFromString(hs string) (hash.Hash, error) { | ||
| 407 | switch hs { | ||
| 408 | case "SHA-1": | ||
| 409 | return sha1.New(), nil | ||
| 410 | case "SHA-224": | ||
| 411 | return sha256.New224(), nil | ||
| 412 | case "SHA-256": | ||
| 413 | return sha256.New(), nil | ||
| 414 | case "SHA-384": | ||
| 415 | return sha512.New384(), nil | ||
| 416 | case "SHA-512": | ||
| 417 | return sha512.New(), nil | ||
| 418 | default: | ||
| 419 | return nil, fmt.Errorf("unknown hash %q", hs) | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | func hashEvpMdFromString(hs string) (*C.EVP_MD, error) { | ||
| 424 | switch hs { | ||
| 425 | case "SHA-1": | ||
| 426 | return C.EVP_sha1(), nil | ||
| 427 | case "SHA-224": | ||
| 428 | return C.EVP_sha224(), nil | ||
| 429 | case "SHA-256": | ||
| 430 | return C.EVP_sha256(), nil | ||
| 431 | case "SHA-384": | ||
| 432 | return C.EVP_sha384(), nil | ||
| 433 | case "SHA-512": | ||
| 434 | return C.EVP_sha512(), nil | ||
| 435 | default: | ||
| 436 | return nil, fmt.Errorf("unknown hash %q", hs) | ||
| 437 | } | ||
| 438 | } | ||
| 439 | |||
| 440 | func checkAesCbcPkcs5(ctx *C.EVP_CIPHER_CTX, doEncrypt int, key []byte, keyLen int, | ||
| 441 | iv []byte, ivLen int, in []byte, inLen int, out []byte, outLen int, | ||
| 442 | wt *wycheproofTestAesCbcPkcs5) bool { | ||
| 443 | var action string | ||
| 444 | if doEncrypt == 1 { | ||
| 445 | action = "encrypting" | ||
| 446 | } else { | ||
| 447 | action = "decrypting" | ||
| 448 | } | ||
| 449 | |||
| 450 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), | ||
| 451 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
| 452 | if ret != 1 { | ||
| 453 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) | ||
| 454 | } | ||
| 455 | |||
| 456 | cipherOut := make([]byte, inLen + C.EVP_MAX_BLOCK_LENGTH) | ||
| 457 | var cipherOutLen C.int | ||
| 458 | |||
| 459 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, | ||
| 460 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
| 461 | if ret != 1 { | ||
| 462 | if wt.Result == "invalid" { | ||
| 463 | fmt.Printf("INFO: Test case %d (%q) [%v] %v - EVP_CipherUpdate() = %d, want %v\n", | ||
| 464 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 465 | return true | ||
| 466 | } | ||
| 467 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - EVP_CipherUpdate() = %d, want %v\n", | ||
| 468 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 469 | return false | ||
| 470 | } | ||
| 471 | |||
| 472 | var finallen C.int | ||
| 473 | ret = C.EVP_CipherFinal_ex(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[cipherOutLen])), &finallen) | ||
| 474 | if ret != 1 { | ||
| 475 | if wt.Result == "invalid" { | ||
| 476 | return true | ||
| 477 | } | ||
| 478 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - EVP_CipherFinal_ex() = %d, want %v\n", | ||
| 479 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 480 | return false | ||
| 481 | } | ||
| 482 | |||
| 483 | cipherOutLen += finallen | ||
| 484 | if cipherOutLen != C.int(outLen) && wt.Result != "invalid" { | ||
| 485 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - open length mismatch: got %d, want %d\n", | ||
| 486 | wt.TCID, wt.Comment, action, wt.Flags, cipherOutLen, outLen) | ||
| 487 | return false | ||
| 488 | } | ||
| 489 | |||
| 490 | openedMsg := out[0:cipherOutLen] | ||
| 491 | if outLen == 0 { | ||
| 492 | out = nil | ||
| 493 | } | ||
| 494 | |||
| 495 | success := false | ||
| 496 | if bytes.Equal(openedMsg, out) || wt.Result == "invalid" { | ||
| 497 | success = true | ||
| 498 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 499 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 500 | } | ||
| 501 | } else { | ||
| 502 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - msg match: %t; want %v\n", | ||
| 503 | wt.TCID, wt.Comment, action, wt.Flags, bytes.Equal(openedMsg, out), wt.Result) | ||
| 504 | } | ||
| 505 | return success | ||
| 506 | } | ||
| 507 | |||
| 508 | func runAesCbcPkcs5Test(ctx *C.EVP_CIPHER_CTX, wt *wycheproofTestAesCbcPkcs5) bool { | ||
| 509 | key, err := hex.DecodeString(wt.Key) | ||
| 510 | if err != nil { | ||
| 511 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | ||
| 512 | } | ||
| 513 | iv, err := hex.DecodeString(wt.IV) | ||
| 514 | if err != nil { | ||
| 515 | log.Fatalf("Failed to decode IV %q: %v", wt.IV, err) | ||
| 516 | } | ||
| 517 | ct, err := hex.DecodeString(wt.CT) | ||
| 518 | if err != nil { | ||
| 519 | log.Fatalf("Failed to decode CT %q: %v", wt.CT, err) | ||
| 520 | } | ||
| 521 | msg, err := hex.DecodeString(wt.Msg) | ||
| 522 | if err != nil { | ||
| 523 | log.Fatalf("Failed to decode message %q: %v", wt.Msg, err) | ||
| 524 | } | ||
| 525 | |||
| 526 | keyLen, ivLen, ctLen, msgLen := len(key), len(iv), len(ct), len(msg) | ||
| 527 | |||
| 528 | if keyLen == 0 { | ||
| 529 | key = append(key, 0) | ||
| 530 | } | ||
| 531 | if ivLen == 0 { | ||
| 532 | iv = append(iv, 0) | ||
| 533 | } | ||
| 534 | if ctLen == 0 { | ||
| 535 | ct = append(ct, 0) | ||
| 536 | } | ||
| 537 | if msgLen == 0 { | ||
| 538 | msg = append(msg, 0) | ||
| 539 | } | ||
| 540 | |||
| 541 | openSuccess := checkAesCbcPkcs5(ctx, 0, key, keyLen, iv, ivLen, ct, ctLen, msg, msgLen, wt) | ||
| 542 | sealSuccess := checkAesCbcPkcs5(ctx, 1, key, keyLen, iv, ivLen, msg, msgLen, ct, ctLen, wt) | ||
| 543 | |||
| 544 | return openSuccess && sealSuccess | ||
| 545 | } | ||
| 546 | |||
| 547 | func runAesCbcPkcs5TestGroup(algorithm string, wtg *wycheproofTestGroupAesCbcPkcs5) bool { | ||
| 548 | fmt.Printf("Running %v test group %v with IV size %d and key size %d...\n", | ||
| 549 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize) | ||
| 550 | |||
| 551 | var cipher *C.EVP_CIPHER | ||
| 552 | switch wtg.KeySize { | ||
| 553 | case 128: | ||
| 554 | cipher = C.EVP_aes_128_cbc() | ||
| 555 | case 192: | ||
| 556 | cipher = C.EVP_aes_192_cbc() | ||
| 557 | case 256: | ||
| 558 | cipher = C.EVP_aes_256_cbc() | ||
| 559 | default: | ||
| 560 | log.Fatalf("Unsupported key size: %d", wtg.KeySize) | ||
| 561 | } | ||
| 562 | |||
| 563 | ctx := C.EVP_CIPHER_CTX_new() | ||
| 564 | if ctx == nil { | ||
| 565 | log.Fatal("EVP_CIPHER_CTX_new() failed") | ||
| 566 | } | ||
| 567 | defer C.EVP_CIPHER_CTX_free(ctx) | ||
| 568 | |||
| 569 | ret := C.EVP_CipherInit_ex(ctx, cipher, nil, nil, nil, 0) | ||
| 570 | if ret != 1 { | ||
| 571 | log.Fatalf("EVP_CipherInit_ex failed: %d", ret) | ||
| 572 | } | ||
| 573 | |||
| 574 | success := true | ||
| 575 | for _, wt := range wtg.Tests { | ||
| 576 | if !runAesCbcPkcs5Test(ctx, wt) { | ||
| 577 | success = false | ||
| 578 | } | ||
| 579 | } | ||
| 580 | return success | ||
| 581 | } | ||
| 582 | |||
| 583 | func checkAesAead(algorithm string, ctx *C.EVP_CIPHER_CTX, doEncrypt int, | ||
| 584 | key []byte, keyLen int, iv []byte, ivLen int, aad []byte, aadLen int, | ||
| 585 | in []byte, inLen int, out []byte, outLen int, tag []byte, tagLen int, | ||
| 586 | wt *wycheproofTestAead) bool { | ||
| 587 | var ctrlSetIVLen C.int | ||
| 588 | var ctrlSetTag C.int | ||
| 589 | var ctrlGetTag C.int | ||
| 590 | |||
| 591 | doCCM := false | ||
| 592 | switch algorithm { | ||
| 593 | case "AES-CCM": | ||
| 594 | doCCM = true | ||
| 595 | ctrlSetIVLen = C.EVP_CTRL_CCM_SET_IVLEN | ||
| 596 | ctrlSetTag = C.EVP_CTRL_CCM_SET_TAG | ||
| 597 | ctrlGetTag = C.EVP_CTRL_CCM_GET_TAG | ||
| 598 | case "AES-GCM": | ||
| 599 | ctrlSetIVLen = C.EVP_CTRL_GCM_SET_IVLEN | ||
| 600 | ctrlSetTag = C.EVP_CTRL_GCM_SET_TAG | ||
| 601 | ctrlGetTag = C.EVP_CTRL_GCM_GET_TAG | ||
| 602 | } | ||
| 603 | |||
| 604 | setTag := unsafe.Pointer(nil) | ||
| 605 | var action string | ||
| 606 | |||
| 607 | if doEncrypt == 1 { | ||
| 608 | action = "encrypting" | ||
| 609 | } else { | ||
| 610 | action = "decrypting" | ||
| 611 | setTag = unsafe.Pointer(&tag[0]) | ||
| 612 | } | ||
| 613 | |||
| 614 | ret := C.EVP_CipherInit_ex(ctx, nil, nil, nil, nil, C.int(doEncrypt)) | ||
| 615 | if ret != 1 { | ||
| 616 | log.Fatalf("[%v] cipher init failed", action) | ||
| 617 | } | ||
| 618 | |||
| 619 | ret = C.EVP_CIPHER_CTX_ctrl(ctx, ctrlSetIVLen, C.int(ivLen), nil) | ||
| 620 | if ret != 1 { | ||
| 621 | if wt.Comment == "Nonce is too long" || wt.Comment == "Invalid nonce size" || | ||
| 622 | wt.Comment == "0 size IV is not valid" { | ||
| 623 | return true | ||
| 624 | } | ||
| 625 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting IV len to %d failed. got %d, want %v\n", | ||
| 626 | wt.TCID, wt.Comment, action, wt.Flags, ivLen, ret, wt.Result) | ||
| 627 | return false | ||
| 628 | } | ||
| 629 | |||
| 630 | if doEncrypt == 0 || doCCM { | ||
| 631 | ret = C.EVP_CIPHER_CTX_ctrl(ctx, ctrlSetTag, C.int(tagLen), setTag) | ||
| 632 | if ret != 1 { | ||
| 633 | if wt.Comment == "Invalid tag size" { | ||
| 634 | return true | ||
| 635 | } | ||
| 636 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting tag length to %d failed. got %d, want %v\n", | ||
| 637 | wt.TCID, wt.Comment, action, wt.Flags, tagLen, ret, wt.Result) | ||
| 638 | return false | ||
| 639 | } | ||
| 640 | } | ||
| 641 | |||
| 642 | ret = C.EVP_CipherInit_ex(ctx, nil, nil, (*C.uchar)(unsafe.Pointer(&key[0])), | ||
| 643 | (*C.uchar)(unsafe.Pointer(&iv[0])), C.int(doEncrypt)) | ||
| 644 | if ret != 1 { | ||
| 645 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting key and IV failed. got %d, want %v\n", | ||
| 646 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 647 | return false | ||
| 648 | } | ||
| 649 | |||
| 650 | var cipherOutLen C.int | ||
| 651 | if doCCM { | ||
| 652 | ret = C.EVP_CipherUpdate(ctx, nil, &cipherOutLen, nil, C.int(inLen)) | ||
| 653 | if ret != 1 { | ||
| 654 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - setting input length to %d failed. got %d, want %v\n", | ||
| 655 | wt.TCID, wt.Comment, action, wt.Flags, inLen, ret, wt.Result) | ||
| 656 | return false | ||
| 657 | } | ||
| 658 | } | ||
| 659 | |||
| 660 | ret = C.EVP_CipherUpdate(ctx, nil, &cipherOutLen, (*C.uchar)(unsafe.Pointer(&aad[0])), C.int(aadLen)) | ||
| 661 | if ret != 1 { | ||
| 662 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - processing AAD failed. got %d, want %v\n", | ||
| 663 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 664 | return false | ||
| 665 | } | ||
| 666 | |||
| 667 | cipherOutLen = 0 | ||
| 668 | cipherOut := make([]byte, inLen) | ||
| 669 | if inLen == 0 { | ||
| 670 | cipherOut = append(cipherOut, 0) | ||
| 671 | } | ||
| 672 | |||
| 673 | ret = C.EVP_CipherUpdate(ctx, (*C.uchar)(unsafe.Pointer(&cipherOut[0])), &cipherOutLen, | ||
| 674 | (*C.uchar)(unsafe.Pointer(&in[0])), C.int(inLen)) | ||
| 675 | if ret != 1 { | ||
| 676 | if wt.Result == "invalid" { | ||
| 677 | return true | ||
| 678 | } | ||
| 679 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - EVP_CipherUpdate() = %d, want %v\n", | ||
| 680 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 681 | return false | ||
| 682 | } | ||
| 683 | |||
| 684 | if doEncrypt == 1 { | ||
| 685 | var tmpLen C.int | ||
| 686 | dummyOut := make([]byte, 16) | ||
| 687 | |||
| 688 | ret = C.EVP_CipherFinal_ex(ctx, (*C.uchar)(unsafe.Pointer(&dummyOut[0])), &tmpLen) | ||
| 689 | if ret != 1 { | ||
| 690 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - EVP_CipherFinal_ex() = %d, want %v\n", | ||
| 691 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 692 | return false | ||
| 693 | } | ||
| 694 | cipherOutLen += tmpLen | ||
| 695 | } | ||
| 696 | |||
| 697 | if cipherOutLen != C.int(outLen) { | ||
| 698 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - cipherOutLen %d != outLen %d. Result %v\n", | ||
| 699 | wt.TCID, wt.Comment, action, wt.Flags, cipherOutLen, outLen, wt.Result) | ||
| 700 | return false | ||
| 701 | } | ||
| 702 | |||
| 703 | success := true | ||
| 704 | if !bytes.Equal(cipherOut, out) { | ||
| 705 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - expected and computed output do not match. Result: %v\n", | ||
| 706 | wt.TCID, wt.Comment, action, wt.Flags, wt.Result) | ||
| 707 | success = false | ||
| 708 | } | ||
| 709 | if doEncrypt == 1 { | ||
| 710 | tagOut := make([]byte, tagLen) | ||
| 711 | ret = C.EVP_CIPHER_CTX_ctrl(ctx, ctrlGetTag, C.int(tagLen), unsafe.Pointer(&tagOut[0])) | ||
| 712 | if ret != 1 { | ||
| 713 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - EVP_CIPHER_CTX_ctrl() = %d, want %v\n", | ||
| 714 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 715 | return false | ||
| 716 | } | ||
| 717 | |||
| 718 | // There are no acceptable CCM cases. All acceptable GCM tests | ||
| 719 | // pass. They have len(IV) <= 48. NIST SP 800-38D, 5.2.1.1, p.8, | ||
| 720 | // allows 1 <= len(IV) <= 2^64-1, but notes: | ||
| 721 | // "For IVs it is recommended that implementations restrict | ||
| 722 | // support to the length of 96 bits, to promote | ||
| 723 | // interoperability, efficiency and simplicity of design." | ||
| 724 | if bytes.Equal(tagOut, tag) != (wt.Result == "valid" || wt.Result == "acceptable") { | ||
| 725 | fmt.Printf("FAIL: Test case %d (%q) [%v] %v - expected and computed tag do not match - ret: %d, Result: %v\n", | ||
| 726 | wt.TCID, wt.Comment, action, wt.Flags, ret, wt.Result) | ||
| 727 | success = false | ||
| 728 | } | ||
| 729 | if acceptableAudit && bytes.Equal(tagOut, tag) && wt.Result == "acceptable" { | ||
| 730 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 731 | } | ||
| 732 | } | ||
| 733 | return success | ||
| 734 | } | ||
| 735 | |||
| 736 | func runAesAeadTest(algorithm string, ctx *C.EVP_CIPHER_CTX, aead *C.EVP_AEAD, wt *wycheproofTestAead) bool { | ||
| 737 | key, err := hex.DecodeString(wt.Key) | ||
| 738 | if err != nil { | ||
| 739 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | ||
| 740 | } | ||
| 741 | |||
| 742 | iv, err := hex.DecodeString(wt.IV) | ||
| 743 | if err != nil { | ||
| 744 | log.Fatalf("Failed to decode IV %q: %v", wt.IV, err) | ||
| 745 | } | ||
| 746 | |||
| 747 | aad, err := hex.DecodeString(wt.AAD) | ||
| 748 | if err != nil { | ||
| 749 | log.Fatalf("Failed to decode AAD %q: %v", wt.AAD, err) | ||
| 750 | } | ||
| 751 | |||
| 752 | msg, err := hex.DecodeString(wt.Msg) | ||
| 753 | if err != nil { | ||
| 754 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) | ||
| 755 | } | ||
| 756 | |||
| 757 | ct, err := hex.DecodeString(wt.CT) | ||
| 758 | if err != nil { | ||
| 759 | log.Fatalf("Failed to decode CT %q: %v", wt.CT, err) | ||
| 760 | } | ||
| 761 | |||
| 762 | tag, err := hex.DecodeString(wt.Tag) | ||
| 763 | if err != nil { | ||
| 764 | log.Fatalf("Failed to decode tag %q: %v", wt.Tag, err) | ||
| 765 | } | ||
| 766 | |||
| 767 | keyLen, ivLen, aadLen, msgLen, ctLen, tagLen := len(key), len(iv), len(aad), len(msg), len(ct), len(tag) | ||
| 768 | |||
| 769 | if keyLen == 0 { | ||
| 770 | key = append(key, 0) | ||
| 771 | } | ||
| 772 | if ivLen == 0 { | ||
| 773 | iv = append(iv, 0) | ||
| 774 | } | ||
| 775 | if aadLen == 0 { | ||
| 776 | aad = append(aad, 0) | ||
| 777 | } | ||
| 778 | if msgLen == 0 { | ||
| 779 | msg = append(msg, 0) | ||
| 780 | } | ||
| 781 | if ctLen == 0 { | ||
| 782 | ct = append(ct, 0) | ||
| 783 | } | ||
| 784 | if tagLen == 0 { | ||
| 785 | tag = append(tag, 0) | ||
| 786 | } | ||
| 787 | |||
| 788 | openEvp := checkAesAead(algorithm, ctx, 0, key, keyLen, iv, ivLen, aad, aadLen, ct, ctLen, msg, msgLen, tag, tagLen, wt) | ||
| 789 | sealEvp := checkAesAead(algorithm, ctx, 1, key, keyLen, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 790 | |||
| 791 | openAead, sealAead := true, true | ||
| 792 | if aead != nil { | ||
| 793 | var ctx C.EVP_AEAD_CTX | ||
| 794 | if C.EVP_AEAD_CTX_init(&ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 { | ||
| 795 | log.Fatal("Failed to initialize AEAD context") | ||
| 796 | } | ||
| 797 | defer C.EVP_AEAD_CTX_cleanup(&ctx) | ||
| 798 | |||
| 799 | // Make sure we don't accidentally prepend or compare against a 0. | ||
| 800 | if ctLen == 0 { | ||
| 801 | ct = nil | ||
| 802 | } | ||
| 803 | |||
| 804 | openAead = checkAeadOpen(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 805 | sealAead = checkAeadSeal(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 806 | } | ||
| 807 | |||
| 808 | return openEvp && sealEvp && openAead && sealAead | ||
| 809 | } | ||
| 810 | |||
| 811 | func runAesAeadTestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { | ||
| 812 | fmt.Printf("Running %v test group %v with IV size %d, key size %d and tag size %d...\n", | ||
| 813 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) | ||
| 814 | |||
| 815 | var cipher *C.EVP_CIPHER | ||
| 816 | var aead *C.EVP_AEAD | ||
| 817 | switch algorithm { | ||
| 818 | case "AES-CCM": | ||
| 819 | switch wtg.KeySize { | ||
| 820 | case 128: | ||
| 821 | cipher = C.EVP_aes_128_ccm() | ||
| 822 | case 192: | ||
| 823 | cipher = C.EVP_aes_192_ccm() | ||
| 824 | case 256: | ||
| 825 | cipher = C.EVP_aes_256_ccm() | ||
| 826 | default: | ||
| 827 | fmt.Printf("INFO: Skipping tests with invalid key size %d\n", wtg.KeySize) | ||
| 828 | return true | ||
| 829 | } | ||
| 830 | case "AES-GCM": | ||
| 831 | switch wtg.KeySize { | ||
| 832 | case 128: | ||
| 833 | cipher = C.EVP_aes_128_gcm() | ||
| 834 | aead = C.EVP_aead_aes_128_gcm() | ||
| 835 | case 192: | ||
| 836 | cipher = C.EVP_aes_192_gcm() | ||
| 837 | case 256: | ||
| 838 | cipher = C.EVP_aes_256_gcm() | ||
| 839 | aead = C.EVP_aead_aes_256_gcm() | ||
| 840 | default: | ||
| 841 | fmt.Printf("INFO: Skipping tests with invalid key size %d\n", wtg.KeySize) | ||
| 842 | return true | ||
| 843 | } | ||
| 844 | default: | ||
| 845 | log.Fatalf("runAesAeadTestGroup() - unhandled algorithm: %v", algorithm) | ||
| 846 | } | ||
| 847 | |||
| 848 | ctx := C.EVP_CIPHER_CTX_new() | ||
| 849 | if ctx == nil { | ||
| 850 | log.Fatal("EVP_CIPHER_CTX_new() failed") | ||
| 851 | } | ||
| 852 | defer C.EVP_CIPHER_CTX_free(ctx) | ||
| 853 | |||
| 854 | C.EVP_CipherInit_ex(ctx, cipher, nil, nil, nil, 1) | ||
| 855 | |||
| 856 | success := true | ||
| 857 | for _, wt := range wtg.Tests { | ||
| 858 | if !runAesAeadTest(algorithm, ctx, aead, wt) { | ||
| 859 | success = false | ||
| 860 | } | ||
| 861 | } | ||
| 862 | return success | ||
| 863 | } | ||
| 864 | |||
| 865 | func runAesCmacTest(cipher *C.EVP_CIPHER, wt *wycheproofTestAesCmac) bool { | ||
| 866 | key, err := hex.DecodeString(wt.Key) | ||
| 867 | if err != nil { | ||
| 868 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | ||
| 869 | } | ||
| 870 | |||
| 871 | msg, err := hex.DecodeString(wt.Msg) | ||
| 872 | if err != nil { | ||
| 873 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) | ||
| 874 | } | ||
| 875 | |||
| 876 | tag, err := hex.DecodeString(wt.Tag) | ||
| 877 | if err != nil { | ||
| 878 | log.Fatalf("Failed to decode tag %q: %v", wt.Tag, err) | ||
| 879 | } | ||
| 880 | |||
| 881 | keyLen, msgLen, tagLen := len(key), len(msg), len(tag) | ||
| 882 | |||
| 883 | if keyLen == 0 { | ||
| 884 | key = append(key, 0) | ||
| 885 | } | ||
| 886 | if msgLen == 0 { | ||
| 887 | msg = append(msg, 0) | ||
| 888 | } | ||
| 889 | if tagLen == 0 { | ||
| 890 | tag = append(tag, 0) | ||
| 891 | } | ||
| 892 | |||
| 893 | ctx := C.CMAC_CTX_new() | ||
| 894 | if ctx == nil { | ||
| 895 | log.Fatal("CMAC_CTX_new failed") | ||
| 896 | } | ||
| 897 | defer C.CMAC_CTX_free(ctx) | ||
| 898 | |||
| 899 | ret := C.CMAC_Init(ctx, unsafe.Pointer(&key[0]), C.size_t(keyLen), cipher, nil) | ||
| 900 | if ret != 1 { | ||
| 901 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Init() = %d, want %v\n", | ||
| 902 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 903 | return false | ||
| 904 | } | ||
| 905 | |||
| 906 | ret = C.CMAC_Update(ctx, unsafe.Pointer(&msg[0]), C.size_t(msgLen)) | ||
| 907 | if ret != 1 { | ||
| 908 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Update() = %d, want %v\n", | ||
| 909 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 910 | return false | ||
| 911 | } | ||
| 912 | |||
| 913 | var outLen C.size_t | ||
| 914 | outTag := make([]byte, 16) | ||
| 915 | |||
| 916 | ret = C.CMAC_Final(ctx, (*C.uchar)(unsafe.Pointer(&outTag[0])), &outLen) | ||
| 917 | if ret != 1 { | ||
| 918 | fmt.Printf("FAIL: Test case %d (%q) %v - CMAC_Final() = %d, want %v\n", | ||
| 919 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 920 | return false | ||
| 921 | } | ||
| 922 | |||
| 923 | outTag = outTag[0:tagLen] | ||
| 924 | |||
| 925 | success := true | ||
| 926 | if bytes.Equal(tag, outTag) != (wt.Result == "valid") { | ||
| 927 | fmt.Printf("FAIL: Test case %d (%q) %v - want %v\n", | ||
| 928 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | ||
| 929 | success = false | ||
| 930 | } | ||
| 931 | return success | ||
| 932 | } | ||
| 933 | |||
| 934 | func runAesCmacTestGroup(algorithm string, wtg *wycheproofTestGroupAesCmac) bool { | ||
| 935 | fmt.Printf("Running %v test group %v with key size %d and tag size %d...\n", | ||
| 936 | algorithm, wtg.Type, wtg.KeySize, wtg.TagSize) | ||
| 937 | var cipher *C.EVP_CIPHER | ||
| 938 | |||
| 939 | switch wtg.KeySize { | ||
| 940 | case 128: | ||
| 941 | cipher = C.EVP_aes_128_cbc() | ||
| 942 | case 192: | ||
| 943 | cipher = C.EVP_aes_192_cbc() | ||
| 944 | case 256: | ||
| 945 | cipher = C.EVP_aes_256_cbc() | ||
| 946 | default: | ||
| 947 | fmt.Printf("INFO: Skipping tests with invalid key size %d\n", wtg.KeySize) | ||
| 948 | return true | ||
| 949 | } | ||
| 950 | |||
| 951 | success := true | ||
| 952 | for _, wt := range wtg.Tests { | ||
| 953 | if !runAesCmacTest(cipher, wt) { | ||
| 954 | success = false | ||
| 955 | } | ||
| 956 | } | ||
| 957 | return success | ||
| 958 | } | ||
| 959 | |||
| 960 | func checkAeadOpen(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, msgLen int, | ||
| 961 | ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
| 962 | maxOutLen := ctLen + tagLen | ||
| 963 | |||
| 964 | opened := make([]byte, maxOutLen) | ||
| 965 | var openedMsgLen C.size_t | ||
| 966 | |||
| 967 | catCtTag := append(ct, tag...) | ||
| 968 | openRet := C.EVP_AEAD_CTX_open(ctx, (*C.uint8_t)(unsafe.Pointer(&opened[0])), | ||
| 969 | (*C.size_t)(unsafe.Pointer(&openedMsgLen)), C.size_t(maxOutLen), | ||
| 970 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
| 971 | (*C.uint8_t)(unsafe.Pointer(&catCtTag[0])), C.size_t(len(catCtTag)), | ||
| 972 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
| 973 | |||
| 974 | if openRet != 1 { | ||
| 975 | if wt.Result == "invalid" { | ||
| 976 | return true | ||
| 977 | } | ||
| 978 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_open() = %d, want %v\n", | ||
| 979 | wt.TCID, wt.Comment, wt.Flags, int(openRet), wt.Result) | ||
| 980 | return false | ||
| 981 | } | ||
| 982 | |||
| 983 | if openedMsgLen != C.size_t(msgLen) { | ||
| 984 | fmt.Printf("FAIL: Test case %d (%q) %v - open length mismatch: got %d, want %d\n", | ||
| 985 | wt.TCID, wt.Comment, wt.Flags, openedMsgLen, msgLen) | ||
| 986 | return false | ||
| 987 | } | ||
| 988 | |||
| 989 | openedMsg := opened[0:openedMsgLen] | ||
| 990 | if msgLen == 0 { | ||
| 991 | msg = nil | ||
| 992 | } | ||
| 993 | |||
| 994 | success := false | ||
| 995 | if bytes.Equal(openedMsg, msg) || wt.Result == "invalid" { | ||
| 996 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 997 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 998 | } | ||
| 999 | success = true | ||
| 1000 | } else { | ||
| 1001 | fmt.Printf("FAIL: Test case %d (%q) %v - msg match: %t; want %v\n", | ||
| 1002 | wt.TCID, wt.Comment, wt.Flags, bytes.Equal(openedMsg, msg), wt.Result) | ||
| 1003 | } | ||
| 1004 | return success | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | func checkAeadSeal(ctx *C.EVP_AEAD_CTX, iv []byte, ivLen int, aad []byte, aadLen int, msg []byte, | ||
| 1008 | msgLen int, ct []byte, ctLen int, tag []byte, tagLen int, wt *wycheproofTestAead) bool { | ||
| 1009 | maxOutLen := msgLen + tagLen | ||
| 1010 | |||
| 1011 | sealed := make([]byte, maxOutLen) | ||
| 1012 | var sealedLen C.size_t | ||
| 1013 | |||
| 1014 | sealRet := C.EVP_AEAD_CTX_seal(ctx, (*C.uint8_t)(unsafe.Pointer(&sealed[0])), | ||
| 1015 | (*C.size_t)(unsafe.Pointer(&sealedLen)), C.size_t(maxOutLen), | ||
| 1016 | (*C.uint8_t)(unsafe.Pointer(&iv[0])), C.size_t(ivLen), | ||
| 1017 | (*C.uint8_t)(unsafe.Pointer(&msg[0])), C.size_t(msgLen), | ||
| 1018 | (*C.uint8_t)(unsafe.Pointer(&aad[0])), C.size_t(aadLen)) | ||
| 1019 | |||
| 1020 | if sealRet != 1 { | ||
| 1021 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, want %v\n", | ||
| 1022 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), wt.Result) | ||
| 1023 | return false | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | if sealedLen != C.size_t(maxOutLen) { | ||
| 1027 | fmt.Printf("FAIL: Test case %d (%q) %v - seal length mismatch: got %d, want %d\n", | ||
| 1028 | wt.TCID, wt.Comment, wt.Flags, sealedLen, maxOutLen) | ||
| 1029 | return false | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | sealedCt := sealed[0:msgLen] | ||
| 1033 | sealedTag := sealed[msgLen:maxOutLen] | ||
| 1034 | |||
| 1035 | success := false | ||
| 1036 | if bytes.Equal(sealedCt, ct) && bytes.Equal(sealedTag, tag) || wt.Result == "invalid" { | ||
| 1037 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 1038 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1039 | } | ||
| 1040 | success = true | ||
| 1041 | } else { | ||
| 1042 | fmt.Printf("FAIL: Test case %d (%q) %v - EVP_AEAD_CTX_seal() = %d, ct match: %t, tag match: %t; want %v\n", | ||
| 1043 | wt.TCID, wt.Comment, wt.Flags, int(sealRet), | ||
| 1044 | bytes.Equal(sealedCt, ct), bytes.Equal(sealedTag, tag), wt.Result) | ||
| 1045 | } | ||
| 1046 | return success | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | func runChaCha20Poly1305Test(wt *wycheproofTestAead) bool { | ||
| 1050 | aead := C.EVP_aead_chacha20_poly1305() | ||
| 1051 | |||
| 1052 | key, err := hex.DecodeString(wt.Key) | ||
| 1053 | if err != nil { | ||
| 1054 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | ||
| 1055 | } | ||
| 1056 | iv, err := hex.DecodeString(wt.IV) | ||
| 1057 | if err != nil { | ||
| 1058 | log.Fatalf("Failed to decode key %q: %v", wt.IV, err) | ||
| 1059 | } | ||
| 1060 | aad, err := hex.DecodeString(wt.AAD) | ||
| 1061 | if err != nil { | ||
| 1062 | log.Fatalf("Failed to decode AAD %q: %v", wt.AAD, err) | ||
| 1063 | } | ||
| 1064 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1065 | if err != nil { | ||
| 1066 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) | ||
| 1067 | } | ||
| 1068 | ct, err := hex.DecodeString(wt.CT) | ||
| 1069 | if err != nil { | ||
| 1070 | log.Fatalf("Failed to decode ct %q: %v", wt.CT, err) | ||
| 1071 | } | ||
| 1072 | tag, err := hex.DecodeString(wt.Tag) | ||
| 1073 | if err != nil { | ||
| 1074 | log.Fatalf("Failed to decode tag %q: %v", wt.Tag, err) | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | keyLen, ivLen, aadLen, msgLen, ctLen, tagLen := len(key), len(iv), len(aad), len(msg), len(ct), len(tag) | ||
| 1078 | |||
| 1079 | if ivLen == 0 { | ||
| 1080 | iv = append(iv, 0) | ||
| 1081 | } | ||
| 1082 | if aadLen == 0 { | ||
| 1083 | aad = append(aad, 0) | ||
| 1084 | } | ||
| 1085 | if msgLen == 0 { | ||
| 1086 | msg = append(msg, 0) | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | var ctx C.EVP_AEAD_CTX | ||
| 1090 | if C.EVP_AEAD_CTX_init(&ctx, aead, (*C.uchar)(unsafe.Pointer(&key[0])), C.size_t(keyLen), C.size_t(tagLen), nil) != 1 { | ||
| 1091 | log.Fatal("Failed to initialize AEAD context") | ||
| 1092 | } | ||
| 1093 | defer C.EVP_AEAD_CTX_cleanup(&ctx) | ||
| 1094 | |||
| 1095 | openSuccess := checkAeadOpen(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 1096 | sealSuccess := checkAeadSeal(&ctx, iv, ivLen, aad, aadLen, msg, msgLen, ct, ctLen, tag, tagLen, wt) | ||
| 1097 | |||
| 1098 | return openSuccess && sealSuccess | ||
| 1099 | } | ||
| 1100 | |||
| 1101 | func runChaCha20Poly1305TestGroup(algorithm string, wtg *wycheproofTestGroupAead) bool { | ||
| 1102 | // We currently only support nonces of length 12 (96 bits) | ||
| 1103 | if wtg.IVSize != 96 { | ||
| 1104 | return true | ||
| 1105 | } | ||
| 1106 | |||
| 1107 | fmt.Printf("Running %v test group %v with IV size %d, key size %d, tag size %d...\n", | ||
| 1108 | algorithm, wtg.Type, wtg.IVSize, wtg.KeySize, wtg.TagSize) | ||
| 1109 | |||
| 1110 | success := true | ||
| 1111 | for _, wt := range wtg.Tests { | ||
| 1112 | if !runChaCha20Poly1305Test(wt) { | ||
| 1113 | success = false | ||
| 1114 | } | ||
| 1115 | } | ||
| 1116 | return success | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | func runDSATest(dsa *C.DSA, h hash.Hash, wt *wycheproofTestDSA) bool { | ||
| 1120 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1121 | if err != nil { | ||
| 1122 | log.Fatalf("Failed to decode message %q: %v", wt.Msg, err) | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | h.Reset() | ||
| 1126 | h.Write(msg) | ||
| 1127 | msg = h.Sum(nil) | ||
| 1128 | |||
| 1129 | sig, err := hex.DecodeString(wt.Sig) | ||
| 1130 | if err != nil { | ||
| 1131 | log.Fatalf("Failed to decode signature %q: %v", wt.Sig, err) | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | msgLen, sigLen := len(msg), len(sig) | ||
| 1135 | if msgLen == 0 { | ||
| 1136 | msg = append(msg, 0) | ||
| 1137 | } | ||
| 1138 | if sigLen == 0 { | ||
| 1139 | sig = append(msg, 0) | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | ret := C.DSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | ||
| 1143 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), dsa) | ||
| 1144 | |||
| 1145 | success := true | ||
| 1146 | if ret == 1 != (wt.Result == "valid") { | ||
| 1147 | fmt.Printf("FAIL: Test case %d (%q) %v - DSA_verify() = %d, want %v\n", | ||
| 1148 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 1149 | success = false | ||
| 1150 | } | ||
| 1151 | return success | ||
| 1152 | } | ||
| 1153 | |||
| 1154 | func runDSATestGroup(algorithm string, wtg *wycheproofTestGroupDSA) bool { | ||
| 1155 | fmt.Printf("Running %v test group %v, key size %d and %v...\n", | ||
| 1156 | algorithm, wtg.Type, wtg.Key.KeySize, wtg.SHA) | ||
| 1157 | |||
| 1158 | dsa := C.DSA_new() | ||
| 1159 | if dsa == nil { | ||
| 1160 | log.Fatal("DSA_new failed") | ||
| 1161 | } | ||
| 1162 | defer C.DSA_free(dsa) | ||
| 1163 | |||
| 1164 | var bnG *C.BIGNUM | ||
| 1165 | wg := C.CString(wtg.Key.G) | ||
| 1166 | if C.BN_hex2bn(&bnG, wg) == 0 { | ||
| 1167 | log.Fatal("Failed to decode g") | ||
| 1168 | } | ||
| 1169 | C.free(unsafe.Pointer(wg)) | ||
| 1170 | |||
| 1171 | var bnP *C.BIGNUM | ||
| 1172 | wp := C.CString(wtg.Key.P) | ||
| 1173 | if C.BN_hex2bn(&bnP, wp) == 0 { | ||
| 1174 | log.Fatal("Failed to decode p") | ||
| 1175 | } | ||
| 1176 | C.free(unsafe.Pointer(wp)) | ||
| 1177 | |||
| 1178 | var bnQ *C.BIGNUM | ||
| 1179 | wq := C.CString(wtg.Key.Q) | ||
| 1180 | if C.BN_hex2bn(&bnQ, wq) == 0 { | ||
| 1181 | log.Fatal("Failed to decode q") | ||
| 1182 | } | ||
| 1183 | C.free(unsafe.Pointer(wq)) | ||
| 1184 | |||
| 1185 | ret := C.DSA_set0_pqg(dsa, bnP, bnQ, bnG) | ||
| 1186 | if ret != 1 { | ||
| 1187 | log.Fatalf("DSA_set0_pqg returned %d", ret) | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | var bnY *C.BIGNUM | ||
| 1191 | wy := C.CString(wtg.Key.Y) | ||
| 1192 | if C.BN_hex2bn(&bnY, wy) == 0 { | ||
| 1193 | log.Fatal("Failed to decode y") | ||
| 1194 | } | ||
| 1195 | C.free(unsafe.Pointer(wy)) | ||
| 1196 | |||
| 1197 | ret = C.DSA_set0_key(dsa, bnY, nil) | ||
| 1198 | if ret != 1 { | ||
| 1199 | log.Fatalf("DSA_set0_key returned %d", ret) | ||
| 1200 | } | ||
| 1201 | |||
| 1202 | h, err := hashFromString(wtg.SHA) | ||
| 1203 | if err != nil { | ||
| 1204 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | der, err := hex.DecodeString(wtg.KeyDER) | ||
| 1208 | if err != nil { | ||
| 1209 | log.Fatalf("Failed to decode DER encoded key: %v", err) | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | derLen := len(der) | ||
| 1213 | if derLen == 0 { | ||
| 1214 | der = append(der, 0) | ||
| 1215 | } | ||
| 1216 | |||
| 1217 | Cder := (*C.uchar)(C.malloc(C.ulong(derLen))) | ||
| 1218 | if Cder == nil { | ||
| 1219 | log.Fatal("malloc failed") | ||
| 1220 | } | ||
| 1221 | C.memcpy(unsafe.Pointer(Cder), unsafe.Pointer(&der[0]), C.ulong(derLen)) | ||
| 1222 | |||
| 1223 | p := (*C.uchar)(Cder) | ||
| 1224 | dsaDER := C.d2i_DSA_PUBKEY(nil, (**C.uchar)(&p), C.long(derLen)) | ||
| 1225 | defer C.DSA_free(dsaDER) | ||
| 1226 | C.free(unsafe.Pointer(Cder)) | ||
| 1227 | |||
| 1228 | keyPEM := C.CString(wtg.KeyPEM) | ||
| 1229 | bio := C.BIO_new_mem_buf(unsafe.Pointer(keyPEM), C.int(len(wtg.KeyPEM))) | ||
| 1230 | if bio == nil { | ||
| 1231 | log.Fatal("BIO_new_mem_buf failed") | ||
| 1232 | } | ||
| 1233 | defer C.free(unsafe.Pointer(keyPEM)) | ||
| 1234 | defer C.BIO_free(bio) | ||
| 1235 | |||
| 1236 | dsaPEM := C.PEM_read_bio_DSA_PUBKEY(bio, nil, nil, nil) | ||
| 1237 | if dsaPEM == nil { | ||
| 1238 | log.Fatal("PEM_read_bio_DSA_PUBKEY failed") | ||
| 1239 | } | ||
| 1240 | defer C.DSA_free(dsaPEM) | ||
| 1241 | |||
| 1242 | success := true | ||
| 1243 | for _, wt := range wtg.Tests { | ||
| 1244 | if !runDSATest(dsa, h, wt) { | ||
| 1245 | success = false | ||
| 1246 | } | ||
| 1247 | if !runDSATest(dsaDER, h, wt) { | ||
| 1248 | success = false | ||
| 1249 | } | ||
| 1250 | if !runDSATest(dsaPEM, h, wt) { | ||
| 1251 | success = false | ||
| 1252 | } | ||
| 1253 | } | ||
| 1254 | return success | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | func runECDHTest(nid int, doECpoint bool, wt *wycheproofTestECDH) bool { | ||
| 1258 | privKey := C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1259 | if privKey == nil { | ||
| 1260 | log.Fatalf("EC_KEY_new_by_curve_name failed") | ||
| 1261 | } | ||
| 1262 | defer C.EC_KEY_free(privKey) | ||
| 1263 | |||
| 1264 | var bnPriv *C.BIGNUM | ||
| 1265 | wPriv := C.CString(wt.Private) | ||
| 1266 | if C.BN_hex2bn(&bnPriv, wPriv) == 0 { | ||
| 1267 | log.Fatal("Failed to decode wPriv") | ||
| 1268 | } | ||
| 1269 | C.free(unsafe.Pointer(wPriv)) | ||
| 1270 | defer C.BN_free(bnPriv) | ||
| 1271 | |||
| 1272 | ret := C.EC_KEY_set_private_key(privKey, bnPriv) | ||
| 1273 | if ret != 1 { | ||
| 1274 | fmt.Printf("FAIL: Test case %d (%q) %v - EC_KEY_set_private_key() = %d, want %v\n", | ||
| 1275 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 1276 | return false | ||
| 1277 | } | ||
| 1278 | |||
| 1279 | pub, err := hex.DecodeString(wt.Public) | ||
| 1280 | if err != nil { | ||
| 1281 | log.Fatalf("Failed to decode public key: %v", err) | ||
| 1282 | } | ||
| 1283 | |||
| 1284 | pubLen := len(pub) | ||
| 1285 | if pubLen == 0 { | ||
| 1286 | pub = append(pub, 0) | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | Cpub := (*C.uchar)(C.malloc(C.ulong(pubLen))) | ||
| 1290 | if Cpub == nil { | ||
| 1291 | log.Fatal("malloc failed") | ||
| 1292 | } | ||
| 1293 | C.memcpy(unsafe.Pointer(Cpub), unsafe.Pointer(&pub[0]), C.ulong(pubLen)) | ||
| 1294 | |||
| 1295 | p := (*C.uchar)(Cpub) | ||
| 1296 | var pubKey *C.EC_KEY | ||
| 1297 | if doECpoint { | ||
| 1298 | pubKey = C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1299 | if pubKey == nil { | ||
| 1300 | log.Fatal("EC_KEY_new_by_curve_name failed") | ||
| 1301 | } | ||
| 1302 | pubKey = C.o2i_ECPublicKey(&pubKey, (**C.uchar)(&p), C.long(pubLen)) | ||
| 1303 | } else { | ||
| 1304 | pubKey = C.d2i_EC_PUBKEY(nil, (**C.uchar)(&p), C.long(pubLen)) | ||
| 1305 | } | ||
| 1306 | defer C.EC_KEY_free(pubKey) | ||
| 1307 | C.free(unsafe.Pointer(Cpub)) | ||
| 1308 | |||
| 1309 | if pubKey == nil { | ||
| 1310 | if wt.Result == "invalid" || wt.Result == "acceptable" { | ||
| 1311 | return true | ||
| 1312 | } | ||
| 1313 | fmt.Printf("FAIL: Test case %d (%q) %v - ASN decoding failed: want %v\n", | ||
| 1314 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | ||
| 1315 | return false | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | privGroup := C.EC_KEY_get0_group(privKey) | ||
| 1319 | |||
| 1320 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 | ||
| 1321 | |||
| 1322 | secret := make([]byte, secLen) | ||
| 1323 | if secLen == 0 { | ||
| 1324 | secret = append(secret, 0) | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | pubPoint := C.EC_KEY_get0_public_key(pubKey) | ||
| 1328 | |||
| 1329 | ret = C.ECDH_compute_key(unsafe.Pointer(&secret[0]), C.ulong(secLen), pubPoint, privKey, nil) | ||
| 1330 | if ret != C.int(secLen) { | ||
| 1331 | if wt.Result == "invalid" { | ||
| 1332 | return true | ||
| 1333 | } | ||
| 1334 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", | ||
| 1335 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) | ||
| 1336 | return false | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | shared, err := hex.DecodeString(wt.Shared) | ||
| 1340 | if err != nil { | ||
| 1341 | log.Fatalf("Failed to decode shared secret: %v", err) | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | success := true | ||
| 1345 | if !bytes.Equal(shared, secret) { | ||
| 1346 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", | ||
| 1347 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | ||
| 1348 | success = false | ||
| 1349 | } | ||
| 1350 | if acceptableAudit && success && wt.Result == "acceptable" { | ||
| 1351 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1352 | } | ||
| 1353 | return success | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | func runECDHTestGroup(algorithm string, wtg *wycheproofTestGroupECDH) bool { | ||
| 1357 | doECpoint := false | ||
| 1358 | if wtg.Encoding == "ecpoint" { | ||
| 1359 | doECpoint = true | ||
| 1360 | } | ||
| 1361 | |||
| 1362 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", | ||
| 1363 | algorithm, wtg.Type, wtg.Curve, wtg.Encoding) | ||
| 1364 | |||
| 1365 | nid, err := nidFromString(wtg.Curve) | ||
| 1366 | if err != nil { | ||
| 1367 | log.Fatalf("Failed to get nid for curve: %v", err) | ||
| 1368 | } | ||
| 1369 | |||
| 1370 | success := true | ||
| 1371 | for _, wt := range wtg.Tests { | ||
| 1372 | if !runECDHTest(nid, doECpoint, wt) { | ||
| 1373 | success = false | ||
| 1374 | } | ||
| 1375 | } | ||
| 1376 | return success | ||
| 1377 | } | ||
| 1378 | |||
| 1379 | func runECDHWebCryptoTest(nid int, wt *wycheproofTestECDHWebCrypto) bool { | ||
| 1380 | privKey := C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1381 | if privKey == nil { | ||
| 1382 | log.Fatalf("EC_KEY_new_by_curve_name failed") | ||
| 1383 | } | ||
| 1384 | defer C.EC_KEY_free(privKey) | ||
| 1385 | |||
| 1386 | d, err := base64.RawURLEncoding.DecodeString(wt.Private.D) | ||
| 1387 | if err != nil { | ||
| 1388 | log.Fatalf("Failed to base64 decode d: %v", err) | ||
| 1389 | } | ||
| 1390 | bnD := C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&d[0])), C.int(len(d)), nil) | ||
| 1391 | if bnD == nil { | ||
| 1392 | log.Fatal("Failed to decode D") | ||
| 1393 | } | ||
| 1394 | defer C.BN_free(bnD) | ||
| 1395 | |||
| 1396 | ret := C.EC_KEY_set_private_key(privKey, bnD) | ||
| 1397 | if ret != 1 { | ||
| 1398 | fmt.Printf("FAIL: Test case %d (%q) %v - EC_KEY_set_private_key() = %d, want %v\n", | ||
| 1399 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 1400 | return false | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | x, err := base64.RawURLEncoding.DecodeString(wt.Public.X) | ||
| 1404 | if err != nil { | ||
| 1405 | log.Fatalf("Failed to base64 decode x: %v", err) | ||
| 1406 | } | ||
| 1407 | bnX := C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), C.int(len(x)), nil) | ||
| 1408 | if bnX == nil { | ||
| 1409 | log.Fatal("Failed to decode X") | ||
| 1410 | } | ||
| 1411 | defer C.BN_free(bnX) | ||
| 1412 | |||
| 1413 | y, err := base64.RawURLEncoding.DecodeString(wt.Public.Y) | ||
| 1414 | if err != nil { | ||
| 1415 | log.Fatalf("Failed to base64 decode y: %v", err) | ||
| 1416 | } | ||
| 1417 | bnY := C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), C.int(len(y)), nil) | ||
| 1418 | if bnY == nil { | ||
| 1419 | log.Fatal("Failed to decode Y") | ||
| 1420 | } | ||
| 1421 | defer C.BN_free(bnY) | ||
| 1422 | |||
| 1423 | pubKey := C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1424 | if pubKey == nil { | ||
| 1425 | log.Fatal("Failed to create EC_KEY") | ||
| 1426 | } | ||
| 1427 | defer C.EC_KEY_free(pubKey) | ||
| 1428 | |||
| 1429 | ret = C.EC_KEY_set_public_key_affine_coordinates(pubKey, bnX, bnY) | ||
| 1430 | if ret != 1 { | ||
| 1431 | if wt.Result == "invalid" { | ||
| 1432 | return true | ||
| 1433 | } | ||
| 1434 | fmt.Printf("FAIL: Test case %d (%q) %v - EC_KEY_set_public_key_affine_coordinates() = %d, want %v\n", | ||
| 1435 | wt.TCID, wt.Comment, wt.Flags, ret, wt.Result) | ||
| 1436 | return false | ||
| 1437 | } | ||
| 1438 | pubPoint := C.EC_KEY_get0_public_key(pubKey) | ||
| 1439 | |||
| 1440 | privGroup := C.EC_KEY_get0_group(privKey) | ||
| 1441 | |||
| 1442 | secLen := (C.EC_GROUP_get_degree(privGroup) + 7) / 8 | ||
| 1443 | |||
| 1444 | secret := make([]byte, secLen) | ||
| 1445 | if secLen == 0 { | ||
| 1446 | secret = append(secret, 0) | ||
| 1447 | } | ||
| 1448 | |||
| 1449 | ret = C.ECDH_compute_key(unsafe.Pointer(&secret[0]), C.ulong(secLen), pubPoint, privKey, nil) | ||
| 1450 | if ret != C.int(secLen) { | ||
| 1451 | if wt.Result == "invalid" { | ||
| 1452 | return true | ||
| 1453 | } | ||
| 1454 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDH_compute_key() = %d, want %d, result: %v\n", | ||
| 1455 | wt.TCID, wt.Comment, wt.Flags, ret, int(secLen), wt.Result) | ||
| 1456 | return false | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | shared, err := hex.DecodeString(wt.Shared) | ||
| 1460 | if err != nil { | ||
| 1461 | log.Fatalf("Failed to decode shared secret: %v", err) | ||
| 1462 | } | ||
| 1463 | |||
| 1464 | success := true | ||
| 1465 | if !bytes.Equal(shared, secret) { | ||
| 1466 | fmt.Printf("FAIL: Test case %d (%q) %v - expected and computed shared secret do not match, want %v\n", | ||
| 1467 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | ||
| 1468 | success = false | ||
| 1469 | } | ||
| 1470 | if acceptableAudit && success && wt.Result == "acceptable" { | ||
| 1471 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1472 | } | ||
| 1473 | return success | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | func runECDHWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDHWebCrypto) bool { | ||
| 1477 | fmt.Printf("Running %v test group %v with curve %v and %v encoding...\n", | ||
| 1478 | algorithm, wtg.Type, wtg.Curve, wtg.Encoding) | ||
| 1479 | |||
| 1480 | nid, err := nidFromString(wtg.Curve) | ||
| 1481 | if err != nil { | ||
| 1482 | log.Fatalf("Failed to get nid for curve: %v", err) | ||
| 1483 | } | ||
| 1484 | |||
| 1485 | success := true | ||
| 1486 | for _, wt := range wtg.Tests { | ||
| 1487 | if !runECDHWebCryptoTest(nid, wt) { | ||
| 1488 | success = false | ||
| 1489 | } | ||
| 1490 | } | ||
| 1491 | return success | ||
| 1492 | } | ||
| 1493 | |||
| 1494 | func runECDSATest(ecKey *C.EC_KEY, nid int, h hash.Hash, webcrypto bool, wt *wycheproofTestECDSA) bool { | ||
| 1495 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1496 | if err != nil { | ||
| 1497 | log.Fatalf("Failed to decode message %q: %v", wt.Msg, err) | ||
| 1498 | } | ||
| 1499 | |||
| 1500 | h.Reset() | ||
| 1501 | h.Write(msg) | ||
| 1502 | msg = h.Sum(nil) | ||
| 1503 | |||
| 1504 | msgLen := len(msg) | ||
| 1505 | if msgLen == 0 { | ||
| 1506 | msg = append(msg, 0) | ||
| 1507 | } | ||
| 1508 | |||
| 1509 | var ret C.int | ||
| 1510 | if webcrypto { | ||
| 1511 | cDer, derLen := encodeECDSAWebCryptoSig(wt.Sig) | ||
| 1512 | if cDer == nil { | ||
| 1513 | fmt.Print("FAIL: unable to decode signature") | ||
| 1514 | return false | ||
| 1515 | } | ||
| 1516 | defer C.free(unsafe.Pointer(cDer)) | ||
| 1517 | |||
| 1518 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | ||
| 1519 | (*C.uchar)(unsafe.Pointer(cDer)), C.int(derLen), ecKey) | ||
| 1520 | } else { | ||
| 1521 | sig, err := hex.DecodeString(wt.Sig) | ||
| 1522 | if err != nil { | ||
| 1523 | log.Fatalf("Failed to decode signature %q: %v", wt.Sig, err) | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | sigLen := len(sig) | ||
| 1527 | if sigLen == 0 { | ||
| 1528 | sig = append(sig, 0) | ||
| 1529 | } | ||
| 1530 | ret = C.ECDSA_verify(0, (*C.uchar)(unsafe.Pointer(&msg[0])), C.int(msgLen), | ||
| 1531 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.int(sigLen), ecKey) | ||
| 1532 | } | ||
| 1533 | |||
| 1534 | // XXX audit acceptable cases... | ||
| 1535 | success := true | ||
| 1536 | if ret == 1 != (wt.Result == "valid") && wt.Result != "acceptable" { | ||
| 1537 | fmt.Printf("FAIL: Test case %d (%q) %v - ECDSA_verify() = %d, want %v\n", | ||
| 1538 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1539 | success = false | ||
| 1540 | } | ||
| 1541 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | ||
| 1542 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1543 | } | ||
| 1544 | return success | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | func runECDSATestGroup(algorithm string, wtg *wycheproofTestGroupECDSA) bool { | ||
| 1548 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", | ||
| 1549 | algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) | ||
| 1550 | |||
| 1551 | nid, err := nidFromString(wtg.Key.Curve) | ||
| 1552 | if err != nil { | ||
| 1553 | log.Fatalf("Failed to get nid for curve: %v", err) | ||
| 1554 | } | ||
| 1555 | ecKey := C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1556 | if ecKey == nil { | ||
| 1557 | log.Fatal("EC_KEY_new_by_curve_name failed") | ||
| 1558 | } | ||
| 1559 | defer C.EC_KEY_free(ecKey) | ||
| 1560 | |||
| 1561 | var bnX *C.BIGNUM | ||
| 1562 | wx := C.CString(wtg.Key.WX) | ||
| 1563 | if C.BN_hex2bn(&bnX, wx) == 0 { | ||
| 1564 | log.Fatal("Failed to decode WX") | ||
| 1565 | } | ||
| 1566 | C.free(unsafe.Pointer(wx)) | ||
| 1567 | defer C.BN_free(bnX) | ||
| 1568 | |||
| 1569 | var bnY *C.BIGNUM | ||
| 1570 | wy := C.CString(wtg.Key.WY) | ||
| 1571 | if C.BN_hex2bn(&bnY, wy) == 0 { | ||
| 1572 | log.Fatal("Failed to decode WY") | ||
| 1573 | } | ||
| 1574 | C.free(unsafe.Pointer(wy)) | ||
| 1575 | defer C.BN_free(bnY) | ||
| 1576 | |||
| 1577 | if C.EC_KEY_set_public_key_affine_coordinates(ecKey, bnX, bnY) != 1 { | ||
| 1578 | log.Fatal("Failed to set EC public key") | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | nid, err = nidFromString(wtg.SHA) | ||
| 1582 | if err != nil { | ||
| 1583 | log.Fatalf("Failed to get MD NID: %v", err) | ||
| 1584 | } | ||
| 1585 | h, err := hashFromString(wtg.SHA) | ||
| 1586 | if err != nil { | ||
| 1587 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1588 | } | ||
| 1589 | |||
| 1590 | success := true | ||
| 1591 | for _, wt := range wtg.Tests { | ||
| 1592 | if !runECDSATest(ecKey, nid, h, false, wt) { | ||
| 1593 | success = false | ||
| 1594 | } | ||
| 1595 | } | ||
| 1596 | return success | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | // DER encode the signature (so that ECDSA_verify() can decode and encode it again...) | ||
| 1600 | func encodeECDSAWebCryptoSig(wtSig string) (*C.uchar, C.int) { | ||
| 1601 | cSig := C.ECDSA_SIG_new() | ||
| 1602 | if cSig == nil { | ||
| 1603 | log.Fatal("ECDSA_SIG_new() failed") | ||
| 1604 | } | ||
| 1605 | defer C.ECDSA_SIG_free(cSig) | ||
| 1606 | |||
| 1607 | sigLen := len(wtSig) | ||
| 1608 | r := C.CString(wtSig[:sigLen/2]) | ||
| 1609 | s := C.CString(wtSig[sigLen/2:]) | ||
| 1610 | defer C.free(unsafe.Pointer(r)) | ||
| 1611 | defer C.free(unsafe.Pointer(s)) | ||
| 1612 | if C.BN_hex2bn(&cSig.r, r) == 0 { | ||
| 1613 | return nil, 0 | ||
| 1614 | } | ||
| 1615 | if C.BN_hex2bn(&cSig.s, s) == 0 { | ||
| 1616 | return nil, 0 | ||
| 1617 | } | ||
| 1618 | |||
| 1619 | derLen := C.i2d_ECDSA_SIG(cSig, nil) | ||
| 1620 | if derLen == 0 { | ||
| 1621 | return nil, 0 | ||
| 1622 | } | ||
| 1623 | cDer := (*C.uchar)(C.malloc(C.ulong(derLen))) | ||
| 1624 | if cDer == nil { | ||
| 1625 | log.Fatal("malloc failed") | ||
| 1626 | } | ||
| 1627 | |||
| 1628 | p := cDer | ||
| 1629 | ret := C.i2d_ECDSA_SIG(cSig, (**C.uchar)(&p)) | ||
| 1630 | if ret == 0 || ret != derLen { | ||
| 1631 | C.free(unsafe.Pointer(cDer)) | ||
| 1632 | return nil, 0 | ||
| 1633 | } | ||
| 1634 | |||
| 1635 | return cDer, derLen | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | func runECDSAWebCryptoTestGroup(algorithm string, wtg *wycheproofTestGroupECDSAWebCrypto) bool { | ||
| 1639 | fmt.Printf("Running %v test group %v with curve %v, key size %d and %v...\n", | ||
| 1640 | algorithm, wtg.Type, wtg.Key.Curve, wtg.Key.KeySize, wtg.SHA) | ||
| 1641 | |||
| 1642 | nid, err := nidFromString(wtg.JWK.Crv) | ||
| 1643 | if err != nil { | ||
| 1644 | log.Fatalf("Failed to get nid for curve: %v", err) | ||
| 1645 | } | ||
| 1646 | ecKey := C.EC_KEY_new_by_curve_name(C.int(nid)) | ||
| 1647 | if ecKey == nil { | ||
| 1648 | log.Fatal("EC_KEY_new_by_curve_name failed") | ||
| 1649 | } | ||
| 1650 | defer C.EC_KEY_free(ecKey) | ||
| 1651 | |||
| 1652 | x, err := base64.RawURLEncoding.DecodeString(wtg.JWK.X) | ||
| 1653 | if err != nil { | ||
| 1654 | log.Fatalf("Failed to base64 decode X: %v", err) | ||
| 1655 | } | ||
| 1656 | bnX := C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&x[0])), C.int(len(x)), nil) | ||
| 1657 | if bnX == nil { | ||
| 1658 | log.Fatal("Failed to decode X") | ||
| 1659 | } | ||
| 1660 | defer C.BN_free(bnX) | ||
| 1661 | |||
| 1662 | y, err := base64.RawURLEncoding.DecodeString(wtg.JWK.Y) | ||
| 1663 | if err != nil { | ||
| 1664 | log.Fatalf("Failed to base64 decode Y: %v", err) | ||
| 1665 | } | ||
| 1666 | bnY := C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&y[0])), C.int(len(y)), nil) | ||
| 1667 | if bnY == nil { | ||
| 1668 | log.Fatal("Failed to decode Y") | ||
| 1669 | } | ||
| 1670 | defer C.BN_free(bnY) | ||
| 1671 | |||
| 1672 | if C.EC_KEY_set_public_key_affine_coordinates(ecKey, bnX, bnY) != 1 { | ||
| 1673 | log.Fatal("Failed to set EC public key") | ||
| 1674 | } | ||
| 1675 | |||
| 1676 | nid, err = nidFromString(wtg.SHA) | ||
| 1677 | if err != nil { | ||
| 1678 | log.Fatalf("Failed to get MD NID: %v", err) | ||
| 1679 | } | ||
| 1680 | h, err := hashFromString(wtg.SHA) | ||
| 1681 | if err != nil { | ||
| 1682 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1683 | } | ||
| 1684 | |||
| 1685 | success := true | ||
| 1686 | for _, wt := range wtg.Tests { | ||
| 1687 | if !runECDSATest(ecKey, nid, h, true, wt) { | ||
| 1688 | success = false | ||
| 1689 | } | ||
| 1690 | } | ||
| 1691 | return success | ||
| 1692 | } | ||
| 1693 | |||
| 1694 | func runKWTestWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
| 1695 | var aesKey C.AES_KEY | ||
| 1696 | |||
| 1697 | ret := C.AES_set_encrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
| 1698 | if ret != 0 { | ||
| 1699 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
| 1700 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1701 | return false | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | outLen := msgLen + 8 | ||
| 1705 | out := make([]byte, outLen) | ||
| 1706 | ret = C.AES_wrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&msg[0])), (C.uint)(msgLen)) | ||
| 1707 | success := false | ||
| 1708 | if ret == C.int(outLen) && bytes.Equal(out, ct) { | ||
| 1709 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 1710 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1711 | } | ||
| 1712 | if wt.Result != "invalid" { | ||
| 1713 | success = true | ||
| 1714 | } | ||
| 1715 | } else if wt.Result != "valid" { | ||
| 1716 | success = true | ||
| 1717 | } | ||
| 1718 | if !success { | ||
| 1719 | fmt.Printf("FAIL: Test case %d (%q) %v - msgLen = %d, AES_wrap_key() = %d, want %v\n", | ||
| 1720 | wt.TCID, wt.Comment, wt.Flags, msgLen, int(ret), wt.Result) | ||
| 1721 | } | ||
| 1722 | return success | ||
| 1723 | } | ||
| 1724 | |||
| 1725 | func runKWTestUnWrap(keySize int, key []byte, keyLen int, msg []byte, msgLen int, ct []byte, ctLen int, wt *wycheproofTestKW) bool { | ||
| 1726 | var aesKey C.AES_KEY | ||
| 1727 | |||
| 1728 | ret := C.AES_set_decrypt_key((*C.uchar)(unsafe.Pointer(&key[0])), (C.int)(keySize), (*C.AES_KEY)(unsafe.Pointer(&aesKey))) | ||
| 1729 | if ret != 0 { | ||
| 1730 | fmt.Printf("FAIL: Test case %d (%q) %v - AES_set_encrypt_key() = %d, want %v\n", | ||
| 1731 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1732 | return false | ||
| 1733 | } | ||
| 1734 | |||
| 1735 | out := make([]byte, ctLen) | ||
| 1736 | if ctLen == 0 { | ||
| 1737 | out = append(out, 0) | ||
| 1738 | } | ||
| 1739 | ret = C.AES_unwrap_key((*C.AES_KEY)(unsafe.Pointer(&aesKey)), nil, (*C.uchar)(unsafe.Pointer(&out[0])), (*C.uchar)(unsafe.Pointer(&ct[0])), (C.uint)(ctLen)) | ||
| 1740 | success := false | ||
| 1741 | if ret == C.int(ctLen - 8) && bytes.Equal(out[0:ret], msg[0:ret]) { | ||
| 1742 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 1743 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1744 | } | ||
| 1745 | if wt.Result != "invalid" { | ||
| 1746 | success = true | ||
| 1747 | } | ||
| 1748 | } else if wt.Result != "valid" { | ||
| 1749 | success = true | ||
| 1750 | } | ||
| 1751 | if !success { | ||
| 1752 | fmt.Printf("FAIL: Test case %d (%q) %v - keyLen = %d, AES_unwrap_key() = %d, want %v\n", | ||
| 1753 | wt.TCID, wt.Comment, wt.Flags, keyLen, int(ret), wt.Result) | ||
| 1754 | } | ||
| 1755 | return success | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | func runKWTest(keySize int, wt *wycheproofTestKW) bool { | ||
| 1759 | key, err := hex.DecodeString(wt.Key) | ||
| 1760 | if err != nil { | ||
| 1761 | log.Fatalf("Failed to decode key %q: %v", wt.Key, err) | ||
| 1762 | } | ||
| 1763 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1764 | if err != nil { | ||
| 1765 | log.Fatalf("Failed to decode msg %q: %v", wt.Msg, err) | ||
| 1766 | } | ||
| 1767 | ct, err := hex.DecodeString(wt.CT) | ||
| 1768 | if err != nil { | ||
| 1769 | log.Fatalf("Failed to decode ct %q: %v", wt.CT, err) | ||
| 1770 | } | ||
| 1771 | |||
| 1772 | keyLen, msgLen, ctLen := len(key), len(msg), len(ct) | ||
| 1773 | |||
| 1774 | if keyLen == 0 { | ||
| 1775 | key = append(key, 0) | ||
| 1776 | } | ||
| 1777 | if msgLen == 0 { | ||
| 1778 | msg = append(msg, 0) | ||
| 1779 | } | ||
| 1780 | if ctLen == 0 { | ||
| 1781 | ct = append(ct, 0) | ||
| 1782 | } | ||
| 1783 | |||
| 1784 | wrapSuccess := runKWTestWrap(keySize, key, keyLen, msg, msgLen, ct, ctLen, wt) | ||
| 1785 | unwrapSuccess := runKWTestUnWrap(keySize, key, keyLen, msg, msgLen, ct, ctLen, wt) | ||
| 1786 | |||
| 1787 | return wrapSuccess && unwrapSuccess | ||
| 1788 | } | ||
| 1789 | |||
| 1790 | func runKWTestGroup(algorithm string, wtg *wycheproofTestGroupKW) bool { | ||
| 1791 | fmt.Printf("Running %v test group %v with key size %d...\n", | ||
| 1792 | algorithm, wtg.Type, wtg.KeySize) | ||
| 1793 | |||
| 1794 | success := true | ||
| 1795 | for _, wt := range wtg.Tests { | ||
| 1796 | if !runKWTest(wtg.KeySize, wt) { | ||
| 1797 | success = false | ||
| 1798 | } | ||
| 1799 | } | ||
| 1800 | return success | ||
| 1801 | } | ||
| 1802 | |||
| 1803 | func runRSASSATest(rsa *C.RSA, h hash.Hash, sha *C.EVP_MD, mgfSha *C.EVP_MD, sLen int, wt *wycheproofTestRSASSA) bool { | ||
| 1804 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1805 | if err != nil { | ||
| 1806 | log.Fatalf("Failed to decode message %q: %v", wt.Msg, err) | ||
| 1807 | } | ||
| 1808 | |||
| 1809 | h.Reset() | ||
| 1810 | h.Write(msg) | ||
| 1811 | msg = h.Sum(nil) | ||
| 1812 | |||
| 1813 | sig, err := hex.DecodeString(wt.Sig) | ||
| 1814 | if err != nil { | ||
| 1815 | log.Fatalf("Failed to decode signature %q: %v", wt.Sig, err) | ||
| 1816 | } | ||
| 1817 | |||
| 1818 | msgLen, sigLen := len(msg), len(sig) | ||
| 1819 | if msgLen == 0 { | ||
| 1820 | msg = append(msg, 0) | ||
| 1821 | } | ||
| 1822 | if sigLen == 0 { | ||
| 1823 | sig = append(sig, 0) | ||
| 1824 | } | ||
| 1825 | |||
| 1826 | sigOut := make([]byte, C.RSA_size(rsa) - 11) | ||
| 1827 | if sigLen == 0 { | ||
| 1828 | sigOut = append(sigOut, 0) | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | ret := C.RSA_public_decrypt(C.int(sigLen), (*C.uchar)(unsafe.Pointer(&sig[0])), | ||
| 1832 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), rsa, C.RSA_NO_PADDING) | ||
| 1833 | if ret == -1 { | ||
| 1834 | if wt.Result == "invalid" { | ||
| 1835 | return true | ||
| 1836 | } | ||
| 1837 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_public_decrypt() = %d, want %v\n", | ||
| 1838 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1839 | return false | ||
| 1840 | } | ||
| 1841 | |||
| 1842 | ret = C.RSA_verify_PKCS1_PSS_mgf1(rsa, (*C.uchar)(unsafe.Pointer(&msg[0])), sha, mgfSha, | ||
| 1843 | (*C.uchar)(unsafe.Pointer(&sigOut[0])), C.int(sLen)) | ||
| 1844 | |||
| 1845 | success := false | ||
| 1846 | if ret == 1 && (wt.Result == "valid" || wt.Result == "acceptable") { | ||
| 1847 | // All acceptable cases that pass use SHA-1 and are flagged: | ||
| 1848 | // "WeakHash" : "The key for this test vector uses a weak hash function." | ||
| 1849 | if acceptableAudit && wt.Result == "acceptable" { | ||
| 1850 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1851 | } | ||
| 1852 | success = true | ||
| 1853 | } else if ret == 0 && (wt.Result == "invalid" || wt.Result == "acceptable") { | ||
| 1854 | success = true | ||
| 1855 | } else { | ||
| 1856 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify_PKCS1_PSS_mgf1() = %d, want %v\n", | ||
| 1857 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1858 | } | ||
| 1859 | return success | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | func runRSASSATestGroup(algorithm string, wtg *wycheproofTestGroupRSASSA) bool { | ||
| 1863 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", | ||
| 1864 | algorithm, wtg.Type, wtg.KeySize, wtg.SHA) | ||
| 1865 | rsa := C.RSA_new() | ||
| 1866 | if rsa == nil { | ||
| 1867 | log.Fatal("RSA_new failed") | ||
| 1868 | } | ||
| 1869 | defer C.RSA_free(rsa) | ||
| 1870 | |||
| 1871 | e := C.CString(wtg.E) | ||
| 1872 | if C.BN_hex2bn(&rsa.e, e) == 0 { | ||
| 1873 | log.Fatal("Failed to set RSA e") | ||
| 1874 | } | ||
| 1875 | C.free(unsafe.Pointer(e)) | ||
| 1876 | |||
| 1877 | n := C.CString(wtg.N) | ||
| 1878 | if C.BN_hex2bn(&rsa.n, n) == 0 { | ||
| 1879 | log.Fatal("Failed to set RSA n") | ||
| 1880 | } | ||
| 1881 | C.free(unsafe.Pointer(n)) | ||
| 1882 | |||
| 1883 | h, err := hashFromString(wtg.SHA) | ||
| 1884 | if err != nil { | ||
| 1885 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1886 | } | ||
| 1887 | |||
| 1888 | sha, err := hashEvpMdFromString(wtg.SHA) | ||
| 1889 | if err != nil { | ||
| 1890 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1891 | } | ||
| 1892 | |||
| 1893 | mgfSha, err := hashEvpMdFromString(wtg.MGFSHA) | ||
| 1894 | if err != nil { | ||
| 1895 | log.Fatalf("Failed to get MGF hash: %v", err) | ||
| 1896 | } | ||
| 1897 | |||
| 1898 | success := true | ||
| 1899 | for _, wt := range wtg.Tests { | ||
| 1900 | if !runRSASSATest(rsa, h, sha, mgfSha, wtg.SLen, wt) { | ||
| 1901 | success = false | ||
| 1902 | } | ||
| 1903 | } | ||
| 1904 | return success | ||
| 1905 | } | ||
| 1906 | |||
| 1907 | func runRSATest(rsa *C.RSA, nid int, h hash.Hash, wt *wycheproofTestRSA) bool { | ||
| 1908 | msg, err := hex.DecodeString(wt.Msg) | ||
| 1909 | if err != nil { | ||
| 1910 | log.Fatalf("Failed to decode message %q: %v", wt.Msg, err) | ||
| 1911 | } | ||
| 1912 | |||
| 1913 | h.Reset() | ||
| 1914 | h.Write(msg) | ||
| 1915 | msg = h.Sum(nil) | ||
| 1916 | |||
| 1917 | sig, err := hex.DecodeString(wt.Sig) | ||
| 1918 | if err != nil { | ||
| 1919 | log.Fatalf("Failed to decode signature %q: %v", wt.Sig, err) | ||
| 1920 | } | ||
| 1921 | |||
| 1922 | msgLen, sigLen := len(msg), len(sig) | ||
| 1923 | if msgLen == 0 { | ||
| 1924 | msg = append(msg, 0) | ||
| 1925 | } | ||
| 1926 | if sigLen == 0 { | ||
| 1927 | sig = append(sig, 0) | ||
| 1928 | } | ||
| 1929 | |||
| 1930 | ret := C.RSA_verify(C.int(nid), (*C.uchar)(unsafe.Pointer(&msg[0])), C.uint(msgLen), | ||
| 1931 | (*C.uchar)(unsafe.Pointer(&sig[0])), C.uint(sigLen), rsa) | ||
| 1932 | |||
| 1933 | // XXX audit acceptable cases... | ||
| 1934 | success := true | ||
| 1935 | if ret == 1 != (wt.Result == "valid") && wt.Result != "acceptable" { | ||
| 1936 | fmt.Printf("FAIL: Test case %d (%q) %v - RSA_verify() = %d, want %v\n", | ||
| 1937 | wt.TCID, wt.Comment, wt.Flags, int(ret), wt.Result) | ||
| 1938 | success = false | ||
| 1939 | } | ||
| 1940 | if acceptableAudit && ret == 1 && wt.Result == "acceptable" { | ||
| 1941 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 1942 | } | ||
| 1943 | return success | ||
| 1944 | } | ||
| 1945 | |||
| 1946 | func runRSATestGroup(algorithm string, wtg *wycheproofTestGroupRSA) bool { | ||
| 1947 | fmt.Printf("Running %v test group %v with key size %d and %v...\n", | ||
| 1948 | algorithm, wtg.Type, wtg.KeySize, wtg.SHA) | ||
| 1949 | |||
| 1950 | rsa := C.RSA_new() | ||
| 1951 | if rsa == nil { | ||
| 1952 | log.Fatal("RSA_new failed") | ||
| 1953 | } | ||
| 1954 | defer C.RSA_free(rsa) | ||
| 1955 | |||
| 1956 | e := C.CString(wtg.E) | ||
| 1957 | if C.BN_hex2bn(&rsa.e, e) == 0 { | ||
| 1958 | log.Fatal("Failed to set RSA e") | ||
| 1959 | } | ||
| 1960 | C.free(unsafe.Pointer(e)) | ||
| 1961 | |||
| 1962 | n := C.CString(wtg.N) | ||
| 1963 | if C.BN_hex2bn(&rsa.n, n) == 0 { | ||
| 1964 | log.Fatal("Failed to set RSA n") | ||
| 1965 | } | ||
| 1966 | C.free(unsafe.Pointer(n)) | ||
| 1967 | |||
| 1968 | nid, err := nidFromString(wtg.SHA) | ||
| 1969 | if err != nil { | ||
| 1970 | log.Fatalf("Failed to get MD NID: %v", err) | ||
| 1971 | } | ||
| 1972 | h, err := hashFromString(wtg.SHA) | ||
| 1973 | if err != nil { | ||
| 1974 | log.Fatalf("Failed to get hash: %v", err) | ||
| 1975 | } | ||
| 1976 | |||
| 1977 | success := true | ||
| 1978 | for _, wt := range wtg.Tests { | ||
| 1979 | if !runRSATest(rsa, nid, h, wt) { | ||
| 1980 | success = false | ||
| 1981 | } | ||
| 1982 | } | ||
| 1983 | return success | ||
| 1984 | } | ||
| 1985 | |||
| 1986 | func runX25519Test(wt *wycheproofTestX25519) bool { | ||
| 1987 | public, err := hex.DecodeString(wt.Public) | ||
| 1988 | if err != nil { | ||
| 1989 | log.Fatalf("Failed to decode public %q: %v", wt.Public, err) | ||
| 1990 | } | ||
| 1991 | private, err := hex.DecodeString(wt.Private) | ||
| 1992 | if err != nil { | ||
| 1993 | log.Fatalf("Failed to decode private %q: %v", wt.Private, err) | ||
| 1994 | } | ||
| 1995 | shared, err := hex.DecodeString(wt.Shared) | ||
| 1996 | if err != nil { | ||
| 1997 | log.Fatalf("Failed to decode shared %q: %v", wt.Shared, err) | ||
| 1998 | } | ||
| 1999 | |||
| 2000 | got := make([]byte, C.X25519_KEY_LENGTH) | ||
| 2001 | result := true | ||
| 2002 | |||
| 2003 | if C.X25519((*C.uint8_t)(unsafe.Pointer(&got[0])), (*C.uint8_t)(unsafe.Pointer(&private[0])), (*C.uint8_t)(unsafe.Pointer(&public[0]))) != 1 { | ||
| 2004 | result = false | ||
| 2005 | } else { | ||
| 2006 | result = bytes.Equal(got, shared) | ||
| 2007 | } | ||
| 2008 | |||
| 2009 | // XXX audit acceptable cases... | ||
| 2010 | success := true | ||
| 2011 | if result != (wt.Result == "valid") && wt.Result != "acceptable" { | ||
| 2012 | fmt.Printf("FAIL: Test case %d (%q) %v - X25519(), want %v\n", | ||
| 2013 | wt.TCID, wt.Comment, wt.Flags, wt.Result) | ||
| 2014 | success = false | ||
| 2015 | } | ||
| 2016 | if acceptableAudit && result && wt.Result == "acceptable" { | ||
| 2017 | gatherAcceptableStatistics(wt.TCID, wt.Comment, wt.Flags) | ||
| 2018 | } | ||
| 2019 | return success | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | func runX25519TestGroup(algorithm string, wtg *wycheproofTestGroupX25519) bool { | ||
| 2023 | fmt.Printf("Running %v test group with curve %v...\n", algorithm, wtg.Curve) | ||
| 2024 | |||
| 2025 | success := true | ||
| 2026 | for _, wt := range wtg.Tests { | ||
| 2027 | if !runX25519Test(wt) { | ||
| 2028 | success = false | ||
| 2029 | } | ||
| 2030 | } | ||
| 2031 | return success | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | func runTestVectors(path string, webcrypto bool) bool { | ||
| 2035 | b, err := ioutil.ReadFile(path) | ||
| 2036 | if err != nil { | ||
| 2037 | log.Fatalf("Failed to read test vectors: %v", err) | ||
| 2038 | } | ||
| 2039 | wtv := &wycheproofTestVectors{} | ||
| 2040 | if err := json.Unmarshal(b, wtv); err != nil { | ||
| 2041 | log.Fatalf("Failed to unmarshal JSON: %v", err) | ||
| 2042 | } | ||
| 2043 | fmt.Printf("Loaded Wycheproof test vectors for %v with %d tests from %q\n", | ||
| 2044 | wtv.Algorithm, wtv.NumberOfTests, filepath.Base(path)) | ||
| 2045 | |||
| 2046 | var wtg interface{} | ||
| 2047 | switch wtv.Algorithm { | ||
| 2048 | case "AES-CBC-PKCS5": | ||
| 2049 | wtg = &wycheproofTestGroupAesCbcPkcs5{} | ||
| 2050 | case "AES-CCM": | ||
| 2051 | wtg = &wycheproofTestGroupAead{} | ||
| 2052 | case "AES-CMAC": | ||
| 2053 | wtg = &wycheproofTestGroupAesCmac{} | ||
| 2054 | case "AES-GCM": | ||
| 2055 | wtg = &wycheproofTestGroupAead{} | ||
| 2056 | case "CHACHA20-POLY1305": | ||
| 2057 | wtg = &wycheproofTestGroupAead{} | ||
| 2058 | case "DSA": | ||
| 2059 | wtg = &wycheproofTestGroupDSA{} | ||
| 2060 | case "ECDH": | ||
| 2061 | if webcrypto { | ||
| 2062 | wtg = &wycheproofTestGroupECDHWebCrypto{} | ||
| 2063 | } else { | ||
| 2064 | wtg = &wycheproofTestGroupECDH{} | ||
| 2065 | } | ||
| 2066 | case "ECDSA": | ||
| 2067 | if webcrypto { | ||
| 2068 | wtg = &wycheproofTestGroupECDSAWebCrypto{} | ||
| 2069 | } else { | ||
| 2070 | wtg = &wycheproofTestGroupECDSA{} | ||
| 2071 | } | ||
| 2072 | case "KW": | ||
| 2073 | wtg = &wycheproofTestGroupKW{} | ||
| 2074 | case "RSASSA-PSS": | ||
| 2075 | wtg = &wycheproofTestGroupRSASSA{} | ||
| 2076 | case "RSASig": | ||
| 2077 | wtg = &wycheproofTestGroupRSA{} | ||
| 2078 | case "X25519": | ||
| 2079 | wtg = &wycheproofTestGroupX25519{} | ||
| 2080 | default: | ||
| 2081 | log.Fatalf("Unknown test vector algorithm %q", wtv.Algorithm) | ||
| 2082 | } | ||
| 2083 | |||
| 2084 | success := true | ||
| 2085 | for _, tg := range wtv.TestGroups { | ||
| 2086 | if err := json.Unmarshal(tg, wtg); err != nil { | ||
| 2087 | log.Fatalf("Failed to unmarshal test groups JSON: %v", err) | ||
| 2088 | } | ||
| 2089 | switch wtv.Algorithm { | ||
| 2090 | case "AES-CBC-PKCS5": | ||
| 2091 | if !runAesCbcPkcs5TestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAesCbcPkcs5)) { | ||
| 2092 | success = false | ||
| 2093 | } | ||
| 2094 | case "AES-CCM": | ||
| 2095 | if !runAesAeadTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { | ||
| 2096 | success = false | ||
| 2097 | } | ||
| 2098 | case "AES-CMAC": | ||
| 2099 | if !runAesCmacTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAesCmac)) { | ||
| 2100 | success = false | ||
| 2101 | } | ||
| 2102 | case "AES-GCM": | ||
| 2103 | if !runAesAeadTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { | ||
| 2104 | success = false | ||
| 2105 | } | ||
| 2106 | case "CHACHA20-POLY1305": | ||
| 2107 | if !runChaCha20Poly1305TestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupAead)) { | ||
| 2108 | success = false | ||
| 2109 | } | ||
| 2110 | case "DSA": | ||
| 2111 | if !runDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupDSA)) { | ||
| 2112 | success = false | ||
| 2113 | } | ||
| 2114 | case "ECDH": | ||
| 2115 | if webcrypto { | ||
| 2116 | if !runECDHWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDHWebCrypto)) { | ||
| 2117 | success = false | ||
| 2118 | } | ||
| 2119 | } else { | ||
| 2120 | if !runECDHTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDH)) { | ||
| 2121 | success = false | ||
| 2122 | } | ||
| 2123 | } | ||
| 2124 | case "ECDSA": | ||
| 2125 | if webcrypto { | ||
| 2126 | if !runECDSAWebCryptoTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSAWebCrypto)) { | ||
| 2127 | success = false | ||
| 2128 | } | ||
| 2129 | } else { | ||
| 2130 | if !runECDSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupECDSA)) { | ||
| 2131 | success = false | ||
| 2132 | } | ||
| 2133 | } | ||
| 2134 | case "KW": | ||
| 2135 | if !runKWTestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupKW)) { | ||
| 2136 | success = false | ||
| 2137 | } | ||
| 2138 | case "RSASSA-PSS": | ||
| 2139 | if !runRSASSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupRSASSA)) { | ||
| 2140 | success = false | ||
| 2141 | } | ||
| 2142 | case "RSASig": | ||
| 2143 | if !runRSATestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupRSA)) { | ||
| 2144 | success = false | ||
| 2145 | } | ||
| 2146 | case "X25519": | ||
| 2147 | if !runX25519TestGroup(wtv.Algorithm, wtg.(*wycheproofTestGroupX25519)) { | ||
| 2148 | success = false | ||
| 2149 | } | ||
| 2150 | default: | ||
| 2151 | log.Fatalf("Unknown test vector algorithm %q", wtv.Algorithm) | ||
| 2152 | } | ||
| 2153 | } | ||
| 2154 | return success | ||
| 2155 | } | ||
| 2156 | |||
| 2157 | func main() { | ||
| 2158 | if _, err := os.Stat(testVectorPath); os.IsNotExist(err) { | ||
| 2159 | fmt.Printf("package wycheproof-testvectors is required for this regress\n") | ||
| 2160 | fmt.Printf("SKIPPED\n") | ||
| 2161 | os.Exit(0) | ||
| 2162 | } | ||
| 2163 | |||
| 2164 | flag.BoolVar(&acceptableAudit, "v", false, "audit acceptable cases") | ||
| 2165 | flag.Parse() | ||
| 2166 | |||
| 2167 | acceptableComments = make(map[string]int) | ||
| 2168 | acceptableFlags = make(map[string]int) | ||
| 2169 | |||
| 2170 | tests := []struct { | ||
| 2171 | name string | ||
| 2172 | pattern string | ||
| 2173 | }{ | ||
| 2174 | {"AES", "aes_[cg]*[^xv]_test.json"}, // Skip AES-EAX, AES-GCM-SIV and AES-SIV-CMAC. | ||
| 2175 | {"ChaCha20-Poly1305", "chacha20_poly1305_test.json"}, | ||
| 2176 | {"DSA", "dsa_test.json"}, | ||
| 2177 | {"ECDH", "ecdh_[^w]*test.json"}, | ||
| 2178 | {"ECDHWebCrypto", "ecdh_w*_test.json"}, | ||
| 2179 | {"ECDSA", "ecdsa_[^w]*test.json"}, | ||
| 2180 | {"ECDSAWebCrypto", "ecdsa_w*_test.json"}, | ||
| 2181 | {"KW", "kw_test.json"}, | ||
| 2182 | {"RSA", "rsa_*test.json"}, | ||
| 2183 | {"X25519", "x25519_*test.json"}, | ||
| 2184 | } | ||
| 2185 | |||
| 2186 | success := true | ||
| 2187 | |||
| 2188 | for _, test := range tests { | ||
| 2189 | webcrypto := test.name == "ECDSAWebCrypto" || test.name == "ECDHWebCrypto" | ||
| 2190 | tvs, err := filepath.Glob(filepath.Join(testVectorPath, test.pattern)) | ||
| 2191 | if err != nil { | ||
| 2192 | log.Fatalf("Failed to glob %v test vectors: %v", test.name, err) | ||
| 2193 | } | ||
| 2194 | if len(tvs) == 0 { | ||
| 2195 | log.Fatalf("Failed to find %v test vectors at %q\n", test.name, testVectorPath) | ||
| 2196 | } | ||
| 2197 | for _, tv := range tvs { | ||
| 2198 | if !runTestVectors(tv, webcrypto) { | ||
| 2199 | success = false | ||
| 2200 | } | ||
| 2201 | } | ||
| 2202 | } | ||
| 2203 | |||
| 2204 | if acceptableAudit { | ||
| 2205 | printAcceptableStatistics() | ||
| 2206 | } | ||
| 2207 | |||
| 2208 | if !success { | ||
| 2209 | os.Exit(1) | ||
| 2210 | } | ||
| 2211 | } | ||
diff --git a/src/regress/lib/libcrypto/x509/Makefile b/src/regress/lib/libcrypto/x509/Makefile deleted file mode 100644 index 106a9f2bf2..0000000000 --- a/src/regress/lib/libcrypto/x509/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2018/04/07 13:54:46 schwarze Exp $ | ||
| 2 | |||
| 3 | PROG= x509name | ||
| 4 | LDADD= -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -Wall -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-x509name | ||
| 10 | CLEANFILES+= x509name.result | ||
| 11 | |||
| 12 | regress-x509name: ${PROG} | ||
| 13 | ./${PROG} > x509name.result | ||
| 14 | diff -u ${.CURDIR}/x509name.expected x509name.result | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libcrypto/x509/x509name.c b/src/regress/lib/libcrypto/x509/x509name.c deleted file mode 100644 index 4ff8ac6908..0000000000 --- a/src/regress/lib/libcrypto/x509/x509name.c +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509name.c,v 1.1 2018/04/07 13:54:46 schwarze Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | #include <openssl/x509.h> | ||
| 22 | |||
| 23 | static void debug_print(X509_NAME *); | ||
| 24 | |||
| 25 | static void | ||
| 26 | debug_print(X509_NAME *name) | ||
| 27 | { | ||
| 28 | int loc; | ||
| 29 | |||
| 30 | for (loc = 0; loc < X509_NAME_entry_count(name); loc++) | ||
| 31 | printf("%d:", X509_NAME_get_entry(name, loc)->set); | ||
| 32 | putchar(' '); | ||
| 33 | X509_NAME_print_ex_fp(stdout, name, 0, XN_FLAG_SEP_CPLUS_SPC); | ||
| 34 | putchar('\n'); | ||
| 35 | } | ||
| 36 | |||
| 37 | int | ||
| 38 | main(void) | ||
| 39 | { | ||
| 40 | X509_NAME *name; | ||
| 41 | |||
| 42 | if ((name = X509_NAME_new()) == NULL) | ||
| 43 | err(1, NULL); | ||
| 44 | X509_NAME_add_entry_by_txt(name, "ST", MBSTRING_ASC, | ||
| 45 | "BaWue", -1, -1, 0); | ||
| 46 | X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC, | ||
| 47 | "KIT", -1, -1, 0); | ||
| 48 | debug_print(name); | ||
| 49 | |||
| 50 | X509_NAME_add_entry_by_txt(name, "L", MBSTRING_ASC, | ||
| 51 | "Karlsruhe", -1, 1, 0); | ||
| 52 | debug_print(name); | ||
| 53 | |||
| 54 | X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, | ||
| 55 | "DE", -1, 0, 1); | ||
| 56 | debug_print(name); | ||
| 57 | |||
| 58 | return 0; | ||
| 59 | } | ||
diff --git a/src/regress/lib/libcrypto/x509/x509name.expected b/src/regress/lib/libcrypto/x509/x509name.expected deleted file mode 100644 index 6cee7cc435..0000000000 --- a/src/regress/lib/libcrypto/x509/x509name.expected +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | 0:1: ST=BaWue, O=KIT | ||
| 2 | 0:1:2: ST=BaWue, L=Karlsruhe, O=KIT | ||
| 3 | 0:0:1:2: C=DE + ST=BaWue, L=Karlsruhe, O=KIT | ||
diff --git a/src/regress/lib/libssl/Makefile b/src/regress/lib/libssl/Makefile deleted file mode 100644 index 0cc3e156a3..0000000000 --- a/src/regress/lib/libssl/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.26 2017/07/16 18:18:10 jsing Exp $ | ||
| 2 | |||
| 3 | SUBDIR= \ | ||
| 4 | asn1 \ | ||
| 5 | bytestring \ | ||
| 6 | ciphers \ | ||
| 7 | client \ | ||
| 8 | pqueue \ | ||
| 9 | server \ | ||
| 10 | ssl \ | ||
| 11 | tlsext \ | ||
| 12 | unit | ||
| 13 | |||
| 14 | install: | ||
| 15 | |||
| 16 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libssl/Makefile.inc b/src/regress/lib/libssl/Makefile.inc deleted file mode 100644 index a8880845e9..0000000000 --- a/src/regress/lib/libssl/Makefile.inc +++ /dev/null | |||
| @@ -1,2 +0,0 @@ | |||
| 1 | # Use this variable when the test needs internal symbols from libssl | ||
| 2 | SSL_INT= -Wl,-Bstatic -lssl -Wl,-Bdynamic | ||
diff --git a/src/regress/lib/libssl/asn1/Makefile b/src/regress/lib/libssl/asn1/Makefile deleted file mode 100644 index f4a57933e2..0000000000 --- a/src/regress/lib/libssl/asn1/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/07/13 16:03:54 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= asn1test | ||
| 4 | LDADD= -lcrypto -lssl | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 6 | |||
| 7 | WARNINGS= Yes | ||
| 8 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/asn1/asn1test.c b/src/regress/lib/libssl/asn1/asn1test.c deleted file mode 100644 index 69be086724..0000000000 --- a/src/regress/lib/libssl/asn1/asn1test.c +++ /dev/null | |||
| @@ -1,478 +0,0 @@ | |||
| 1 | /* $OpenBSD: asn1test.c,v 1.6 2016/12/26 15:31:38 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014, 2016 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdlib.h> | ||
| 20 | |||
| 21 | #include <openssl/bio.h> | ||
| 22 | #include <openssl/err.h> | ||
| 23 | #include <openssl/ssl.h> | ||
| 24 | #include <openssl/tls1.h> | ||
| 25 | |||
| 26 | int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp); | ||
| 27 | SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, | ||
| 28 | long length); | ||
| 29 | |||
| 30 | X509 *peer_cert; | ||
| 31 | |||
| 32 | unsigned char *peer_cert_pem = | ||
| 33 | "-----BEGIN CERTIFICATE-----\n" | ||
| 34 | "MIIBcTCCARugAwIBAgIJAPYhaZJAvUuUMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV\n" | ||
| 35 | "BAoMCVRlc3QgUGVlcjAeFw0xNjEyMjYxNDQ3NDdaFw0yNjEyMjQxNDQ3NDdaMBQx\n" | ||
| 36 | "EjAQBgNVBAoMCVRlc3QgUGVlcjBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCyhAdJ\n" | ||
| 37 | "wojHv/uKONh8MbmR2U2+VF1HQusnLfSfHPqkJfvDzLWJ41TG7QcXkx2rIJVtAFrO\n" | ||
| 38 | "U9yNdFYJLA/hsrbjAgMBAAGjUDBOMB0GA1UdDgQWBBS3bZOw7fvaortdsdE2TPMq\n" | ||
| 39 | "IRXFRzAfBgNVHSMEGDAWgBS3bZOw7fvaortdsdE2TPMqIRXFRzAMBgNVHRMEBTAD\n" | ||
| 40 | "AQH/MA0GCSqGSIb3DQEBBQUAA0EAHsxNS+rNUZbopeDMhVIviOfUmelDjJrT56Rc\n" | ||
| 41 | "VJoFN3Gc1cV8nQAHm9aJs71uksC+MN04Pzh0WqmYX9XXrnYPcg==\n" | ||
| 42 | "-----END CERTIFICATE-----\n"; | ||
| 43 | |||
| 44 | struct ssl_asn1_test { | ||
| 45 | SSL_SESSION session; | ||
| 46 | int peer_cert; | ||
| 47 | const unsigned char asn1[1024]; | ||
| 48 | int asn1_len; | ||
| 49 | }; | ||
| 50 | |||
| 51 | unsigned char tlsext_tick[] = { | ||
| 52 | 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, | ||
| 53 | 0x2d, 0x30, 0x31, 0x36, 0x30, 0x3a, 0x20, 0x37, | ||
| 54 | 0x74, 0x68, 0x20, 0x41, 0x70, 0x72, 0x69, 0x6c, | ||
| 55 | 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, | ||
| 56 | 0x45, 0x2d, 0x32, 0x30, 0x31, 0x30, 0x2d, 0x35, | ||
| 57 | 0x32, 0x39, 0x38, 0x3a, 0x20, 0x38, 0x74, 0x68, | ||
| 58 | 0x20, 0x41, 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, | ||
| 59 | 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, | ||
| 60 | 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, 0x31, 0x39, | ||
| 61 | 0x38, 0x3a, 0x20, 0x32, 0x31, 0x73, 0x74, 0x20, | ||
| 62 | 0x41, 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, | ||
| 63 | 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, | ||
| 64 | 0x30, 0x31, 0x34, 0x2d, 0x33, 0x34, 0x37, 0x30, | ||
| 65 | 0x3a, 0x20, 0x33, 0x30, 0x74, 0x68, 0x20, 0x4d, | ||
| 66 | 0x61, 0x79, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, | ||
| 67 | 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, | ||
| 68 | 0x2d, 0x30, 0x31, 0x39, 0x35, 0x3a, 0x20, 0x35, | ||
| 69 | 0x74, 0x68, 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20, | ||
| 70 | 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, | ||
| 71 | 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, 0x32, | ||
| 72 | 0x32, 0x31, 0x3a, 0x20, 0x35, 0x74, 0x68, 0x20, | ||
| 73 | 0x4a, 0x75, 0x6e, 0x65, 0x20, 0x32, 0x30, 0x31, | ||
| 74 | 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, | ||
| 75 | 0x31, 0x34, 0x2d, 0x30, 0x32, 0x32, 0x34, 0x3a, | ||
| 76 | 0x20, 0x35, 0x74, 0x68, 0x20, 0x4a, 0x75, 0x6e, | ||
| 77 | 0x65, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, | ||
| 78 | }; | ||
| 79 | |||
| 80 | struct ssl_asn1_test ssl_asn1_tests[] = { | ||
| 81 | { | ||
| 82 | .session = { | ||
| 83 | .cipher_id = 0x03000000L | 1, | ||
| 84 | .ssl_version = TLS1_2_VERSION, | ||
| 85 | }, | ||
| 86 | .asn1 = { | ||
| 87 | 0x30, 0x13, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, | ||
| 88 | 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x00, 0x04, | ||
| 89 | 0x00, 0xa4, 0x02, 0x04, 0x00, | ||
| 90 | }, | ||
| 91 | .asn1_len = 21, | ||
| 92 | }, | ||
| 93 | { | ||
| 94 | .session = { | ||
| 95 | .cipher_id = 0x03000000L | 1, | ||
| 96 | .ssl_version = TLS1_2_VERSION, | ||
| 97 | .master_key_length = 26, | ||
| 98 | .session_id = "0123456789", | ||
| 99 | .session_id_length = 10, | ||
| 100 | .sid_ctx = "abcdefghijklmnopqrstuvwxyz", | ||
| 101 | .sid_ctx_length = 26, | ||
| 102 | }, | ||
| 103 | .asn1 = { | ||
| 104 | 0x30, 0x51, 0x02, 0x01, 0x01, 0x02, 0x02, 0x03, | ||
| 105 | 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, 0x0a, 0x30, | ||
| 106 | 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, | ||
| 107 | 0x39, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x1c, 0x04, | ||
| 111 | 0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, | ||
| 112 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, | ||
| 113 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | ||
| 114 | 0x78, 0x79, 0x7a, | ||
| 115 | }, | ||
| 116 | .asn1_len = 83, | ||
| 117 | }, | ||
| 118 | { | ||
| 119 | .session = { | ||
| 120 | .cipher_id = 0x03000000L | 1, | ||
| 121 | .ssl_version = TLS1_2_VERSION, | ||
| 122 | .master_key_length = 26, | ||
| 123 | .session_id = "0123456789", | ||
| 124 | .session_id_length = 10, | ||
| 125 | .sid_ctx = "abcdefghijklmnopqrstuvwxyz", | ||
| 126 | .sid_ctx_length = 26, | ||
| 127 | .time = 1405266069, | ||
| 128 | .timeout = 5, | ||
| 129 | .verify_result = 42, | ||
| 130 | .tlsext_hostname = "libressl.openbsd.org", | ||
| 131 | .tlsext_tick_lifetime_hint = 0x7abbccdd, | ||
| 132 | .tlsext_tick = tlsext_tick, | ||
| 133 | .tlsext_ticklen = sizeof(tlsext_tick), | ||
| 134 | }, | ||
| 135 | .peer_cert = 1, | ||
| 136 | .asn1 = { | ||
| 137 | 0x30, 0x82, 0x02, 0xd1, 0x02, 0x01, 0x01, 0x02, | ||
| 138 | 0x02, 0x03, 0x03, 0x04, 0x02, 0x00, 0x01, 0x04, | ||
| 139 | 0x0a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, | ||
| 140 | 0x37, 0x38, 0x39, 0x04, 0x1a, 0x00, 0x00, 0x00, | ||
| 141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 143 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, | ||
| 144 | 0x06, 0x02, 0x04, 0x53, 0xc2, 0xa8, 0x95, 0xa2, | ||
| 145 | 0x03, 0x02, 0x01, 0x05, 0xa3, 0x82, 0x01, 0x75, | ||
| 146 | 0x30, 0x82, 0x01, 0x71, 0x30, 0x82, 0x01, 0x1b, | ||
| 147 | 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, | ||
| 148 | 0xf6, 0x21, 0x69, 0x92, 0x40, 0xbd, 0x4b, 0x94, | ||
| 149 | 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | ||
| 150 | 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, | ||
| 151 | 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, | ||
| 152 | 0x04, 0x0a, 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, | ||
| 153 | 0x20, 0x50, 0x65, 0x65, 0x72, 0x30, 0x1e, 0x17, | ||
| 154 | 0x0d, 0x31, 0x36, 0x31, 0x32, 0x32, 0x36, 0x31, | ||
| 155 | 0x34, 0x34, 0x37, 0x34, 0x37, 0x5a, 0x17, 0x0d, | ||
| 156 | 0x32, 0x36, 0x31, 0x32, 0x32, 0x34, 0x31, 0x34, | ||
| 157 | 0x34, 0x37, 0x34, 0x37, 0x5a, 0x30, 0x14, 0x31, | ||
| 158 | 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, | ||
| 159 | 0x0c, 0x09, 0x54, 0x65, 0x73, 0x74, 0x20, 0x50, | ||
| 160 | 0x65, 0x65, 0x72, 0x30, 0x5c, 0x30, 0x0d, 0x06, | ||
| 161 | 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, | ||
| 162 | 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, | ||
| 163 | 0x48, 0x02, 0x41, 0x00, 0xb2, 0x84, 0x07, 0x49, | ||
| 164 | 0xc2, 0x88, 0xc7, 0xbf, 0xfb, 0x8a, 0x38, 0xd8, | ||
| 165 | 0x7c, 0x31, 0xb9, 0x91, 0xd9, 0x4d, 0xbe, 0x54, | ||
| 166 | 0x5d, 0x47, 0x42, 0xeb, 0x27, 0x2d, 0xf4, 0x9f, | ||
| 167 | 0x1c, 0xfa, 0xa4, 0x25, 0xfb, 0xc3, 0xcc, 0xb5, | ||
| 168 | 0x89, 0xe3, 0x54, 0xc6, 0xed, 0x07, 0x17, 0x93, | ||
| 169 | 0x1d, 0xab, 0x20, 0x95, 0x6d, 0x00, 0x5a, 0xce, | ||
| 170 | 0x53, 0xdc, 0x8d, 0x74, 0x56, 0x09, 0x2c, 0x0f, | ||
| 171 | 0xe1, 0xb2, 0xb6, 0xe3, 0x02, 0x03, 0x01, 0x00, | ||
| 172 | 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, | ||
| 173 | 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, | ||
| 174 | 0xb7, 0x6d, 0x93, 0xb0, 0xed, 0xfb, 0xda, 0xa2, | ||
| 175 | 0xbb, 0x5d, 0xb1, 0xd1, 0x36, 0x4c, 0xf3, 0x2a, | ||
| 176 | 0x21, 0x15, 0xc5, 0x47, 0x30, 0x1f, 0x06, 0x03, | ||
| 177 | 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, | ||
| 178 | 0x14, 0xb7, 0x6d, 0x93, 0xb0, 0xed, 0xfb, 0xda, | ||
| 179 | 0xa2, 0xbb, 0x5d, 0xb1, 0xd1, 0x36, 0x4c, 0xf3, | ||
| 180 | 0x2a, 0x21, 0x15, 0xc5, 0x47, 0x30, 0x0c, 0x06, | ||
| 181 | 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, | ||
| 182 | 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, | ||
| 183 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, | ||
| 184 | 0x05, 0x00, 0x03, 0x41, 0x00, 0x1e, 0xcc, 0x4d, | ||
| 185 | 0x4b, 0xea, 0xcd, 0x51, 0x96, 0xe8, 0xa5, 0xe0, | ||
| 186 | 0xcc, 0x85, 0x52, 0x2f, 0x88, 0xe7, 0xd4, 0x99, | ||
| 187 | 0xe9, 0x43, 0x8c, 0x9a, 0xd3, 0xe7, 0xa4, 0x5c, | ||
| 188 | 0x54, 0x9a, 0x05, 0x37, 0x71, 0x9c, 0xd5, 0xc5, | ||
| 189 | 0x7c, 0x9d, 0x00, 0x07, 0x9b, 0xd6, 0x89, 0xb3, | ||
| 190 | 0xbd, 0x6e, 0x92, 0xc0, 0xbe, 0x30, 0xdd, 0x38, | ||
| 191 | 0x3f, 0x38, 0x74, 0x5a, 0xa9, 0x98, 0x5f, 0xd5, | ||
| 192 | 0xd7, 0xae, 0x76, 0x0f, 0x72, 0xa4, 0x1c, 0x04, | ||
| 193 | 0x1a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, | ||
| 194 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, | ||
| 195 | 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, | ||
| 196 | 0x78, 0x79, 0x7a, 0xa5, 0x03, 0x02, 0x01, 0x2a, | ||
| 197 | 0xa6, 0x16, 0x04, 0x14, 0x6c, 0x69, 0x62, 0x72, | ||
| 198 | 0x65, 0x73, 0x73, 0x6c, 0x2e, 0x6f, 0x70, 0x65, | ||
| 199 | 0x6e, 0x62, 0x73, 0x64, 0x2e, 0x6f, 0x72, 0x67, | ||
| 200 | 0xa9, 0x06, 0x02, 0x04, 0x7a, 0xbb, 0xcc, 0xdd, | ||
| 201 | 0xaa, 0x81, 0xd2, 0x04, 0x81, 0xcf, 0x43, 0x56, | ||
| 202 | 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, | ||
| 203 | 0x31, 0x36, 0x30, 0x3a, 0x20, 0x37, 0x74, 0x68, | ||
| 204 | 0x20, 0x41, 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, | ||
| 205 | 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, | ||
| 206 | 0x32, 0x30, 0x31, 0x30, 0x2d, 0x35, 0x32, 0x39, | ||
| 207 | 0x38, 0x3a, 0x20, 0x38, 0x74, 0x68, 0x20, 0x41, | ||
| 208 | 0x70, 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31, | ||
| 209 | 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, | ||
| 210 | 0x31, 0x34, 0x2d, 0x30, 0x31, 0x39, 0x38, 0x3a, | ||
| 211 | 0x20, 0x32, 0x31, 0x73, 0x74, 0x20, 0x41, 0x70, | ||
| 212 | 0x72, 0x69, 0x6c, 0x20, 0x32, 0x30, 0x31, 0x34, | ||
| 213 | 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, | ||
| 214 | 0x34, 0x2d, 0x33, 0x34, 0x37, 0x30, 0x3a, 0x20, | ||
| 215 | 0x33, 0x30, 0x74, 0x68, 0x20, 0x4d, 0x61, 0x79, | ||
| 216 | 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, 0x43, 0x56, | ||
| 217 | 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, 0x2d, 0x30, | ||
| 218 | 0x31, 0x39, 0x35, 0x3a, 0x20, 0x35, 0x74, 0x68, | ||
| 219 | 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20, 0x32, 0x30, | ||
| 220 | 0x31, 0x34, 0x0a, 0x43, 0x56, 0x45, 0x2d, 0x32, | ||
| 221 | 0x30, 0x31, 0x34, 0x2d, 0x30, 0x32, 0x32, 0x31, | ||
| 222 | 0x3a, 0x20, 0x35, 0x74, 0x68, 0x20, 0x4a, 0x75, | ||
| 223 | 0x6e, 0x65, 0x20, 0x32, 0x30, 0x31, 0x34, 0x0a, | ||
| 224 | 0x43, 0x56, 0x45, 0x2d, 0x32, 0x30, 0x31, 0x34, | ||
| 225 | 0x2d, 0x30, 0x32, 0x32, 0x34, 0x3a, 0x20, 0x35, | ||
| 226 | 0x74, 0x68, 0x20, 0x4a, 0x75, 0x6e, 0x65, 0x20, | ||
| 227 | 0x32, 0x30, 0x31, 0x34, 0x0a, | ||
| 228 | }, | ||
| 229 | .asn1_len = 725, | ||
| 230 | }, | ||
| 231 | { | ||
| 232 | .session = { | ||
| 233 | .cipher_id = 0x03000000L | 1, | ||
| 234 | .ssl_version = TLS1_2_VERSION, | ||
| 235 | .timeout = -1, | ||
| 236 | }, | ||
| 237 | .asn1 = { | ||
| 238 | 0x0, | ||
| 239 | }, | ||
| 240 | .asn1_len = -1, | ||
| 241 | }, | ||
| 242 | { | ||
| 243 | .session = { | ||
| 244 | .cipher_id = 0x03000000L | 1, | ||
| 245 | .ssl_version = TLS1_2_VERSION, | ||
| 246 | .time = -1, | ||
| 247 | }, | ||
| 248 | .asn1 = { | ||
| 249 | 0x0, | ||
| 250 | }, | ||
| 251 | .asn1_len = -1, | ||
| 252 | }, | ||
| 253 | }; | ||
| 254 | |||
| 255 | #define N_SSL_ASN1_TESTS \ | ||
| 256 | (sizeof(ssl_asn1_tests) / sizeof(*ssl_asn1_tests)) | ||
| 257 | |||
| 258 | static int | ||
| 259 | session_strcmp(const unsigned char *o1, const unsigned char *o2, size_t len) | ||
| 260 | { | ||
| 261 | if (o1 == NULL && o2 == NULL) | ||
| 262 | return (0); | ||
| 263 | if (o1 == NULL || o2 == NULL) | ||
| 264 | return (1); | ||
| 265 | return memcmp(o1, o2, len); | ||
| 266 | } | ||
| 267 | |||
| 268 | static int | ||
| 269 | session_cmp(SSL_SESSION *s1, SSL_SESSION *s2) | ||
| 270 | { | ||
| 271 | /* Compare the ASN.1 encoded values from two sessions. */ | ||
| 272 | if (s1->ssl_version != s2->ssl_version) { | ||
| 273 | fprintf(stderr, "ssl_version differs: %i != %i\n", | ||
| 274 | s1->ssl_version, s2->ssl_version); | ||
| 275 | return (1); | ||
| 276 | } | ||
| 277 | if (s1->cipher_id != s2->cipher_id) { | ||
| 278 | fprintf(stderr, "cipher_id differs: %li != %li\n", | ||
| 279 | s1->cipher_id, s2->cipher_id); | ||
| 280 | return (1); | ||
| 281 | } | ||
| 282 | |||
| 283 | if (s1->master_key_length != s2->master_key_length) { | ||
| 284 | fprintf(stderr, "master_key_length differs: %i != %i\n", | ||
| 285 | s1->master_key_length, s2->master_key_length); | ||
| 286 | return (1); | ||
| 287 | } | ||
| 288 | if (session_strcmp(s1->master_key, s2->master_key, | ||
| 289 | s1->master_key_length) != 0) { | ||
| 290 | fprintf(stderr, "master_key differs\n"); | ||
| 291 | return (1); | ||
| 292 | } | ||
| 293 | |||
| 294 | if (s1->session_id_length != s2->session_id_length) { | ||
| 295 | fprintf(stderr, "session_id_length differs: %i != %i\n", | ||
| 296 | s1->session_id_length, s2->session_id_length); | ||
| 297 | return (1); | ||
| 298 | } | ||
| 299 | if (session_strcmp(s1->session_id, s2->session_id, | ||
| 300 | s1->session_id_length) != 0) { | ||
| 301 | fprintf(stderr, "session_id differs\n"); | ||
| 302 | return (1); | ||
| 303 | } | ||
| 304 | |||
| 305 | if (s1->sid_ctx_length != s2->sid_ctx_length) { | ||
| 306 | fprintf(stderr, "sid_ctx_length differs: %i != %i\n", | ||
| 307 | s1->sid_ctx_length, s2->sid_ctx_length); | ||
| 308 | return (1); | ||
| 309 | } | ||
| 310 | if (session_strcmp(s1->sid_ctx, s2->sid_ctx, | ||
| 311 | s1->sid_ctx_length) != 0) { | ||
| 312 | fprintf(stderr, "sid_ctx differs\n"); | ||
| 313 | return (1); | ||
| 314 | } | ||
| 315 | |||
| 316 | /* d2i_SSL_SESSION uses the current time if decoding a zero value. */ | ||
| 317 | if ((s1->time != s2->time) && s1->time != 0 && s2->time != 0) { | ||
| 318 | fprintf(stderr, "time differs: %lli != %lli\n", | ||
| 319 | (long long)s1->time, (long long)s2->time); | ||
| 320 | return (1); | ||
| 321 | } | ||
| 322 | /* d2i_SSL_SESSION uses a timeout of 3 if decoding a zero value. */ | ||
| 323 | if ((s1->timeout != s2->timeout) && | ||
| 324 | s1->timeout != 3 && s2->timeout != 3) { | ||
| 325 | fprintf(stderr, "timeout differs: %li != %li\n", | ||
| 326 | s1->timeout, s2->timeout); | ||
| 327 | return (1); | ||
| 328 | } | ||
| 329 | |||
| 330 | /* Ensure that a certificate is or is not present in both. */ | ||
| 331 | if ((s1->peer != NULL || s2->peer != NULL) && | ||
| 332 | (s1->peer == NULL || s2->peer == NULL || | ||
| 333 | X509_cmp(s1->peer, s2->peer) != 0)) { | ||
| 334 | fprintf(stderr, "peer differs\n"); | ||
| 335 | return (1); | ||
| 336 | } | ||
| 337 | |||
| 338 | if (s1->verify_result != s2->verify_result) { | ||
| 339 | fprintf(stderr, "verify_result differs: %li != %li\n", | ||
| 340 | s1->verify_result, s2->verify_result); | ||
| 341 | return (1); | ||
| 342 | } | ||
| 343 | |||
| 344 | if (session_strcmp(s1->tlsext_hostname, s2->tlsext_hostname, | ||
| 345 | (s1->tlsext_hostname ? strlen(s1->tlsext_hostname) : 0)) != 0) { | ||
| 346 | fprintf(stderr, "sid_ctx differs\n"); | ||
| 347 | return (1); | ||
| 348 | } | ||
| 349 | if (s1->tlsext_tick_lifetime_hint != s2->tlsext_tick_lifetime_hint) { | ||
| 350 | fprintf(stderr, "tlsext_tick_lifetime_hint differs: " | ||
| 351 | "%li != %li\n", s1->tlsext_tick_lifetime_hint, | ||
| 352 | s2->tlsext_tick_lifetime_hint); | ||
| 353 | return (1); | ||
| 354 | } | ||
| 355 | if (s1->tlsext_ticklen != s2->tlsext_ticklen) { | ||
| 356 | fprintf(stderr, "tlsext_ticklen differs: %zu != %zu\n", | ||
| 357 | s1->tlsext_ticklen, s2->tlsext_ticklen); | ||
| 358 | return (1); | ||
| 359 | } | ||
| 360 | if (session_strcmp(s1->tlsext_tick, s2->tlsext_tick, | ||
| 361 | s1->tlsext_ticklen) != 0) { | ||
| 362 | fprintf(stderr, "tlsext_tick differs\n"); | ||
| 363 | return (1); | ||
| 364 | } | ||
| 365 | |||
| 366 | return (0); | ||
| 367 | } | ||
| 368 | |||
| 369 | static int | ||
| 370 | do_ssl_asn1_test(int test_no, struct ssl_asn1_test *sat) | ||
| 371 | { | ||
| 372 | SSL_SESSION session, *sp = NULL; | ||
| 373 | unsigned char *ap, *asn1 = NULL; | ||
| 374 | const unsigned char *pp; | ||
| 375 | int i, len, rv = 1; | ||
| 376 | |||
| 377 | if (sat->peer_cert) | ||
| 378 | sat->session.peer = peer_cert; | ||
| 379 | |||
| 380 | len = i2d_SSL_SESSION(&sat->session, NULL); | ||
| 381 | if (len != sat->asn1_len) { | ||
| 382 | fprintf(stderr, "FAIL: test %i returned ASN1 length %i, " | ||
| 383 | "want %i\n", test_no, len, sat->asn1_len); | ||
| 384 | goto failed; | ||
| 385 | } | ||
| 386 | |||
| 387 | /* See if the test is expected to fail... */ | ||
| 388 | if (sat->asn1_len == -1) | ||
| 389 | return (0); | ||
| 390 | |||
| 391 | if ((asn1 = malloc(len)) == NULL) | ||
| 392 | errx(1, "failed to allocate memory"); | ||
| 393 | |||
| 394 | ap = asn1; | ||
| 395 | len = i2d_SSL_SESSION(&sat->session, &ap); | ||
| 396 | |||
| 397 | /* Check the length again since the code path is different. */ | ||
| 398 | if (len != sat->asn1_len) { | ||
| 399 | fprintf(stderr, "FAIL: test %i returned ASN1 length %i, " | ||
| 400 | "want %i\n", test_no, len, sat->asn1_len); | ||
| 401 | goto failed; | ||
| 402 | } | ||
| 403 | /* ap should now point at the end of the buffer. */ | ||
| 404 | if (ap - asn1 != len) { | ||
| 405 | fprintf(stderr, "FAIL: test %i pointer increment does not " | ||
| 406 | "match length (%i != %i)\n", test_no, (int)(ap - asn1), len); | ||
| 407 | goto failed; | ||
| 408 | } | ||
| 409 | |||
| 410 | if (memcmp(asn1, &sat->asn1, len) != 0) { | ||
| 411 | fprintf(stderr, "FAIL: test %i - encoding differs:\n", test_no); | ||
| 412 | fprintf(stderr, "encoding:\n"); | ||
| 413 | for (i = 1; i <= len; i++) { | ||
| 414 | fprintf(stderr, " 0x%02hhx,", asn1[i - 1]); | ||
| 415 | if (i % 8 == 0) | ||
| 416 | fprintf(stderr, "\n"); | ||
| 417 | } | ||
| 418 | fprintf(stderr, "\n"); | ||
| 419 | fprintf(stderr, "test data:\n"); | ||
| 420 | for (i = 1; i <= sat->asn1_len; i++) { | ||
| 421 | fprintf(stderr, " 0x%02hhx,", sat->asn1[i - 1]); | ||
| 422 | if (i % 8 == 0) | ||
| 423 | fprintf(stderr, "\n"); | ||
| 424 | } | ||
| 425 | fprintf(stderr, "\n"); | ||
| 426 | goto failed; | ||
| 427 | } | ||
| 428 | |||
| 429 | sp = &session; | ||
| 430 | memset(sp, 0, sizeof(*sp)); | ||
| 431 | pp = sat->asn1; | ||
| 432 | |||
| 433 | if ((sp = d2i_SSL_SESSION(&sp, &pp, sat->asn1_len)) == NULL) { | ||
| 434 | fprintf(stderr, "FAIL: test %i - decoding failed\n", test_no); | ||
| 435 | goto failed; | ||
| 436 | } | ||
| 437 | |||
| 438 | if (session_cmp(sp, &sat->session) != 0) { | ||
| 439 | fprintf(stderr, "FAIL: test %i - decoding differs\n", test_no); | ||
| 440 | goto failed; | ||
| 441 | } | ||
| 442 | |||
| 443 | rv = 0; | ||
| 444 | |||
| 445 | failed: | ||
| 446 | ERR_print_errors(BIO_new_fp(stderr, BIO_NOCLOSE)); | ||
| 447 | |||
| 448 | free(asn1); | ||
| 449 | |||
| 450 | return (rv); | ||
| 451 | } | ||
| 452 | |||
| 453 | int | ||
| 454 | main(int argc, char **argv) | ||
| 455 | { | ||
| 456 | BIO *bio = NULL; | ||
| 457 | int failed = 0; | ||
| 458 | size_t i; | ||
| 459 | |||
| 460 | SSL_library_init(); | ||
| 461 | SSL_load_error_strings(); | ||
| 462 | |||
| 463 | bio = BIO_new_mem_buf(peer_cert_pem, -1); | ||
| 464 | if (bio == NULL) | ||
| 465 | errx(1, "failed to create bio"); | ||
| 466 | |||
| 467 | peer_cert = PEM_read_bio_X509(bio, NULL, NULL, NULL); | ||
| 468 | if (peer_cert == NULL) | ||
| 469 | errx(1, "failed to read peer cert"); | ||
| 470 | |||
| 471 | for (i = 0; i < N_SSL_ASN1_TESTS; i++) | ||
| 472 | failed += do_ssl_asn1_test(i, &ssl_asn1_tests[i]); | ||
| 473 | |||
| 474 | X509_free(peer_cert); | ||
| 475 | BIO_free(bio); | ||
| 476 | |||
| 477 | return (failed); | ||
| 478 | } | ||
diff --git a/src/regress/lib/libssl/bytestring/Makefile b/src/regress/lib/libssl/bytestring/Makefile deleted file mode 100644 index 162c81d255..0000000000 --- a/src/regress/lib/libssl/bytestring/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2016/11/04 17:51:54 guenther Exp $ | ||
| 2 | |||
| 3 | PROG= bytestringtest | ||
| 4 | LDADD= ${SSL_INT} -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Wundef -Werror -I$(BSDSRCDIR)/lib/libssl | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/bytestring/bytestringtest.c b/src/regress/lib/libssl/bytestring/bytestringtest.c deleted file mode 100644 index 0e9f5f47e5..0000000000 --- a/src/regress/lib/libssl/bytestring/bytestringtest.c +++ /dev/null | |||
| @@ -1,876 +0,0 @@ | |||
| 1 | /* $OpenBSD: bytestringtest.c,v 1.12 2018/08/16 18:40:19 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014, Google Inc. | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
| 12 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
| 14 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
| 15 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ | ||
| 16 | |||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <string.h> | ||
| 20 | |||
| 21 | #include <openssl/crypto.h> | ||
| 22 | |||
| 23 | #include "bytestring.h" | ||
| 24 | |||
| 25 | /* This is from <openssl/base.h> in boringssl */ | ||
| 26 | #define OPENSSL_U64(x) x##ULL | ||
| 27 | |||
| 28 | #define PRINT_ERROR printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
| 29 | __LINE__) | ||
| 30 | |||
| 31 | #define CHECK(a) do { \ | ||
| 32 | if (!(a)) { \ | ||
| 33 | PRINT_ERROR; \ | ||
| 34 | return 0; \ | ||
| 35 | } \ | ||
| 36 | } while (0) | ||
| 37 | |||
| 38 | #define CHECK_GOTO(a) do { \ | ||
| 39 | if (!(a)) { \ | ||
| 40 | PRINT_ERROR; \ | ||
| 41 | goto err; \ | ||
| 42 | } \ | ||
| 43 | } while (0) | ||
| 44 | |||
| 45 | static int | ||
| 46 | test_skip(void) | ||
| 47 | { | ||
| 48 | static const uint8_t kData[] = {1, 2, 3}; | ||
| 49 | CBS data; | ||
| 50 | |||
| 51 | CBS_init(&data, kData, sizeof(kData)); | ||
| 52 | |||
| 53 | CHECK(CBS_len(&data) == 3); | ||
| 54 | CHECK(CBS_skip(&data, 1)); | ||
| 55 | CHECK(CBS_len(&data) == 2); | ||
| 56 | CHECK(CBS_skip(&data, 2)); | ||
| 57 | CHECK(CBS_len(&data) == 0); | ||
| 58 | CHECK(!CBS_skip(&data, 1)); | ||
| 59 | |||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | |||
| 63 | static int | ||
| 64 | test_get_u(void) | ||
| 65 | { | ||
| 66 | static const uint8_t kData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
| 67 | uint8_t u8; | ||
| 68 | uint16_t u16; | ||
| 69 | uint32_t u32; | ||
| 70 | CBS data; | ||
| 71 | |||
| 72 | CBS_init(&data, kData, sizeof(kData)); | ||
| 73 | |||
| 74 | CHECK(CBS_get_u8(&data, &u8)); | ||
| 75 | CHECK(u8 == 1); | ||
| 76 | CHECK(CBS_get_u16(&data, &u16)); | ||
| 77 | CHECK(u16 == 0x203); | ||
| 78 | CHECK(CBS_get_u24(&data, &u32)); | ||
| 79 | CHECK(u32 == 0x40506); | ||
| 80 | CHECK(CBS_get_u32(&data, &u32)); | ||
| 81 | CHECK(u32 == 0x708090a); | ||
| 82 | CHECK(!CBS_get_u8(&data, &u8)); | ||
| 83 | |||
| 84 | return 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int | ||
| 88 | test_get_prefixed(void) | ||
| 89 | { | ||
| 90 | static const uint8_t kData[] = {1, 2, 0, 2, 3, 4, 0, 0, 3, 3, 2, 1}; | ||
| 91 | uint8_t u8; | ||
| 92 | uint16_t u16; | ||
| 93 | uint32_t u32; | ||
| 94 | CBS data, prefixed; | ||
| 95 | |||
| 96 | CBS_init(&data, kData, sizeof(kData)); | ||
| 97 | |||
| 98 | CHECK(CBS_get_u8_length_prefixed(&data, &prefixed)); | ||
| 99 | CHECK(CBS_len(&prefixed) == 1); | ||
| 100 | CHECK(CBS_get_u8(&prefixed, &u8)); | ||
| 101 | CHECK(u8 == 2); | ||
| 102 | CHECK(CBS_get_u16_length_prefixed(&data, &prefixed)); | ||
| 103 | CHECK(CBS_len(&prefixed) == 2); | ||
| 104 | CHECK(CBS_get_u16(&prefixed, &u16)); | ||
| 105 | CHECK(u16 == 0x304); | ||
| 106 | CHECK(CBS_get_u24_length_prefixed(&data, &prefixed)); | ||
| 107 | CHECK(CBS_len(&prefixed) == 3); | ||
| 108 | CHECK(CBS_get_u24(&prefixed, &u32)); | ||
| 109 | CHECK(u32 == 0x30201); | ||
| 110 | |||
| 111 | return 1; | ||
| 112 | } | ||
| 113 | |||
| 114 | static int | ||
| 115 | test_get_prefixed_bad(void) | ||
| 116 | { | ||
| 117 | static const uint8_t kData1[] = {2, 1}; | ||
| 118 | static const uint8_t kData2[] = {0, 2, 1}; | ||
| 119 | static const uint8_t kData3[] = {0, 0, 2, 1}; | ||
| 120 | CBS data, prefixed; | ||
| 121 | |||
| 122 | CBS_init(&data, kData1, sizeof(kData1)); | ||
| 123 | CHECK(!CBS_get_u8_length_prefixed(&data, &prefixed)); | ||
| 124 | |||
| 125 | CBS_init(&data, kData2, sizeof(kData2)); | ||
| 126 | CHECK(!CBS_get_u16_length_prefixed(&data, &prefixed)); | ||
| 127 | |||
| 128 | CBS_init(&data, kData3, sizeof(kData3)); | ||
| 129 | CHECK(!CBS_get_u24_length_prefixed(&data, &prefixed)); | ||
| 130 | |||
| 131 | return 1; | ||
| 132 | } | ||
| 133 | |||
| 134 | static int | ||
| 135 | test_get_asn1(void) | ||
| 136 | { | ||
| 137 | static const uint8_t kData1[] = {0x30, 2, 1, 2}; | ||
| 138 | static const uint8_t kData2[] = {0x30, 3, 1, 2}; | ||
| 139 | static const uint8_t kData3[] = {0x30, 0x80}; | ||
| 140 | static const uint8_t kData4[] = {0x30, 0x81, 1, 1}; | ||
| 141 | static const uint8_t kData5[4 + 0x80] = {0x30, 0x82, 0, 0x80}; | ||
| 142 | static const uint8_t kData6[] = {0xa1, 3, 0x4, 1, 1}; | ||
| 143 | static const uint8_t kData7[] = {0xa1, 3, 0x4, 2, 1}; | ||
| 144 | static const uint8_t kData8[] = {0xa1, 3, 0x2, 1, 1}; | ||
| 145 | static const uint8_t kData9[] = {0xa1, 3, 0x2, 1, 0xff}; | ||
| 146 | |||
| 147 | CBS data, contents; | ||
| 148 | int present; | ||
| 149 | uint64_t value; | ||
| 150 | |||
| 151 | CBS_init(&data, kData1, sizeof(kData1)); | ||
| 152 | |||
| 153 | CHECK(!CBS_peek_asn1_tag(&data, 0x1)); | ||
| 154 | CHECK(CBS_peek_asn1_tag(&data, 0x30)); | ||
| 155 | |||
| 156 | CHECK(CBS_get_asn1(&data, &contents, 0x30)); | ||
| 157 | CHECK(CBS_len(&contents) == 2); | ||
| 158 | CHECK(memcmp(CBS_data(&contents), "\x01\x02", 2) == 0); | ||
| 159 | |||
| 160 | CBS_init(&data, kData2, sizeof(kData2)); | ||
| 161 | /* data is truncated */ | ||
| 162 | CHECK(!CBS_get_asn1(&data, &contents, 0x30)); | ||
| 163 | |||
| 164 | CBS_init(&data, kData3, sizeof(kData3)); | ||
| 165 | /* zero byte length of length */ | ||
| 166 | CHECK(!CBS_get_asn1(&data, &contents, 0x30)); | ||
| 167 | |||
| 168 | CBS_init(&data, kData4, sizeof(kData4)); | ||
| 169 | /* long form mistakenly used. */ | ||
| 170 | CHECK(!CBS_get_asn1(&data, &contents, 0x30)); | ||
| 171 | |||
| 172 | CBS_init(&data, kData5, sizeof(kData5)); | ||
| 173 | /* length takes too many bytes. */ | ||
| 174 | CHECK(!CBS_get_asn1(&data, &contents, 0x30)); | ||
| 175 | |||
| 176 | CBS_init(&data, kData1, sizeof(kData1)); | ||
| 177 | /* wrong tag. */ | ||
| 178 | CHECK(!CBS_get_asn1(&data, &contents, 0x31)); | ||
| 179 | |||
| 180 | CBS_init(&data, NULL, 0); | ||
| 181 | /* peek at empty data. */ | ||
| 182 | CHECK(!CBS_peek_asn1_tag(&data, 0x30)); | ||
| 183 | |||
| 184 | CBS_init(&data, NULL, 0); | ||
| 185 | /* optional elements at empty data. */ | ||
| 186 | CHECK(CBS_get_optional_asn1(&data, &contents, &present, 0xa0)); | ||
| 187 | CHECK(!present); | ||
| 188 | CHECK(CBS_get_optional_asn1_octet_string(&data, &contents, &present, | ||
| 189 | 0xa0)); | ||
| 190 | CHECK(!present); | ||
| 191 | CHECK(CBS_len(&contents) == 0); | ||
| 192 | CHECK(CBS_get_optional_asn1_octet_string(&data, &contents, NULL, 0xa0)); | ||
| 193 | CHECK(CBS_len(&contents) == 0); | ||
| 194 | CHECK(CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42)); | ||
| 195 | CHECK(value == 42); | ||
| 196 | |||
| 197 | CBS_init(&data, kData6, sizeof(kData6)); | ||
| 198 | /* optional element. */ | ||
| 199 | CHECK(CBS_get_optional_asn1(&data, &contents, &present, 0xa0)); | ||
| 200 | CHECK(!present); | ||
| 201 | CHECK(CBS_get_optional_asn1(&data, &contents, &present, 0xa1)); | ||
| 202 | CHECK(present); | ||
| 203 | CHECK(CBS_len(&contents) == 3); | ||
| 204 | CHECK(memcmp(CBS_data(&contents), "\x04\x01\x01", 3) == 0); | ||
| 205 | |||
| 206 | CBS_init(&data, kData6, sizeof(kData6)); | ||
| 207 | /* optional octet string. */ | ||
| 208 | CHECK(CBS_get_optional_asn1_octet_string(&data, &contents, &present, | ||
| 209 | 0xa0)); | ||
| 210 | CHECK(!present); | ||
| 211 | CHECK(CBS_len(&contents) == 0); | ||
| 212 | CHECK(CBS_get_optional_asn1_octet_string(&data, &contents, &present, | ||
| 213 | 0xa1)); | ||
| 214 | CHECK(present); | ||
| 215 | CHECK(CBS_len(&contents) == 1); | ||
| 216 | CHECK(CBS_data(&contents)[0] == 1); | ||
| 217 | |||
| 218 | CBS_init(&data, kData7, sizeof(kData7)); | ||
| 219 | /* invalid optional octet string. */ | ||
| 220 | CHECK(!CBS_get_optional_asn1_octet_string(&data, &contents, &present, | ||
| 221 | 0xa1)); | ||
| 222 | |||
| 223 | CBS_init(&data, kData8, sizeof(kData8)); | ||
| 224 | /* optional octet string. */ | ||
| 225 | CHECK(CBS_get_optional_asn1_uint64(&data, &value, 0xa0, 42)); | ||
| 226 | CHECK(value == 42); | ||
| 227 | CHECK(CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42)); | ||
| 228 | CHECK(value == 1); | ||
| 229 | |||
| 230 | CBS_init(&data, kData9, sizeof(kData9)); | ||
| 231 | /* invalid optional integer. */ | ||
| 232 | CHECK(!CBS_get_optional_asn1_uint64(&data, &value, 0xa1, 42)); | ||
| 233 | |||
| 234 | return 1; | ||
| 235 | } | ||
| 236 | |||
| 237 | static int | ||
| 238 | test_get_optional_asn1_bool(void) | ||
| 239 | { | ||
| 240 | CBS data; | ||
| 241 | int val; | ||
| 242 | |||
| 243 | static const uint8_t kTrue[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0xff}; | ||
| 244 | static const uint8_t kFalse[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x00}; | ||
| 245 | static const uint8_t kInvalid[] = {0x0a, 3, CBS_ASN1_BOOLEAN, 1, 0x01}; | ||
| 246 | |||
| 247 | CBS_init(&data, NULL, 0); | ||
| 248 | val = 2; | ||
| 249 | CHECK(CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0)); | ||
| 250 | CHECK(val == 0); | ||
| 251 | |||
| 252 | CBS_init(&data, kTrue, sizeof(kTrue)); | ||
| 253 | val = 2; | ||
| 254 | CHECK(CBS_get_optional_asn1_bool(&data, &val, 0x0a, 0)); | ||
| 255 | CHECK(val == 1); | ||
| 256 | |||
| 257 | CBS_init(&data, kFalse, sizeof(kFalse)); | ||
| 258 | val = 2; | ||
| 259 | CHECK(CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1)); | ||
| 260 | CHECK(val == 0); | ||
| 261 | |||
| 262 | CBS_init(&data, kInvalid, sizeof(kInvalid)); | ||
| 263 | CHECK(!CBS_get_optional_asn1_bool(&data, &val, 0x0a, 1)); | ||
| 264 | |||
| 265 | return 1; | ||
| 266 | } | ||
| 267 | |||
| 268 | static int | ||
| 269 | test_cbb_basic(void) | ||
| 270 | { | ||
| 271 | static const uint8_t kExpected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | ||
| 272 | uint8_t *buf = NULL; | ||
| 273 | size_t buf_len; | ||
| 274 | int ret = 0; | ||
| 275 | CBB cbb; | ||
| 276 | |||
| 277 | CHECK(CBB_init(&cbb, 100)); | ||
| 278 | |||
| 279 | CBB_cleanup(&cbb); | ||
| 280 | |||
| 281 | CHECK(CBB_init(&cbb, 0)); | ||
| 282 | CHECK_GOTO(CBB_add_u8(&cbb, 1)); | ||
| 283 | CHECK_GOTO(CBB_add_u16(&cbb, 0x203)); | ||
| 284 | CHECK_GOTO(CBB_add_u24(&cbb, 0x40506)); | ||
| 285 | CHECK_GOTO(CBB_add_u32(&cbb, 0x708090a)); | ||
| 286 | CHECK_GOTO(CBB_add_bytes(&cbb, (const uint8_t*) "\x0b\x0c", 2)); | ||
| 287 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 288 | |||
| 289 | ret = (buf_len == sizeof(kExpected) | ||
| 290 | && memcmp(buf, kExpected, buf_len) == 0); | ||
| 291 | |||
| 292 | if (0) { | ||
| 293 | err: | ||
| 294 | CBB_cleanup(&cbb); | ||
| 295 | } | ||
| 296 | free(buf); | ||
| 297 | return ret; | ||
| 298 | } | ||
| 299 | |||
| 300 | static int | ||
| 301 | test_cbb_fixed(void) | ||
| 302 | { | ||
| 303 | CBB cbb; | ||
| 304 | uint8_t buf[1]; | ||
| 305 | uint8_t *out_buf = NULL; | ||
| 306 | size_t out_size; | ||
| 307 | int ret = 0; | ||
| 308 | |||
| 309 | CHECK(CBB_init_fixed(&cbb, NULL, 0)); | ||
| 310 | CHECK_GOTO(!CBB_add_u8(&cbb, 1)); | ||
| 311 | CHECK_GOTO(CBB_finish(&cbb, &out_buf, &out_size)); | ||
| 312 | CHECK(out_buf == NULL && out_size == 0); | ||
| 313 | |||
| 314 | CHECK(CBB_init_fixed(&cbb, buf, 1)); | ||
| 315 | CHECK_GOTO(CBB_add_u8(&cbb, 1)); | ||
| 316 | CHECK_GOTO(!CBB_add_u8(&cbb, 2)); | ||
| 317 | CHECK_GOTO(CBB_finish(&cbb, &out_buf, &out_size)); | ||
| 318 | |||
| 319 | ret = (out_buf == buf && out_size == 1 && buf[0] == 1); | ||
| 320 | |||
| 321 | if (0) { | ||
| 322 | err: | ||
| 323 | CBB_cleanup(&cbb); | ||
| 324 | } | ||
| 325 | |||
| 326 | return ret; | ||
| 327 | } | ||
| 328 | |||
| 329 | static int | ||
| 330 | test_cbb_finish_child(void) | ||
| 331 | { | ||
| 332 | CBB cbb, child; | ||
| 333 | uint8_t *out_buf = NULL; | ||
| 334 | size_t out_size; | ||
| 335 | int ret = 0; | ||
| 336 | |||
| 337 | CHECK(CBB_init(&cbb, 16)); | ||
| 338 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &child)); | ||
| 339 | CHECK_GOTO(!CBB_finish(&child, &out_buf, &out_size)); | ||
| 340 | CHECK_GOTO(CBB_finish(&cbb, &out_buf, &out_size)); | ||
| 341 | |||
| 342 | ret = (out_size == 1 && out_buf[0] == 0); | ||
| 343 | |||
| 344 | err: | ||
| 345 | free(out_buf); | ||
| 346 | return ret; | ||
| 347 | } | ||
| 348 | |||
| 349 | static int | ||
| 350 | test_cbb_prefixed(void) | ||
| 351 | { | ||
| 352 | static const uint8_t kExpected[] = {0, 1, 1, 0, 2, 2, 3, 0, 0, 3, | ||
| 353 | 4, 5, 6, 5, 4, 1, 0, 1, 2}; | ||
| 354 | CBB cbb, contents, inner_contents, inner_inner_contents; | ||
| 355 | uint8_t *buf = NULL; | ||
| 356 | size_t buf_len; | ||
| 357 | int ret = 0; | ||
| 358 | |||
| 359 | CHECK(CBB_init(&cbb, 0)); | ||
| 360 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 361 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 362 | CHECK_GOTO(CBB_add_u8(&contents, 1)); | ||
| 363 | CHECK_GOTO(CBB_add_u16_length_prefixed(&cbb, &contents)); | ||
| 364 | CHECK_GOTO(CBB_add_u16(&contents, 0x203)); | ||
| 365 | CHECK_GOTO(CBB_add_u24_length_prefixed(&cbb, &contents)); | ||
| 366 | CHECK_GOTO(CBB_add_u24(&contents, 0x40506)); | ||
| 367 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 368 | CHECK_GOTO(CBB_add_u8_length_prefixed(&contents, &inner_contents)); | ||
| 369 | CHECK_GOTO(CBB_add_u8(&inner_contents, 1)); | ||
| 370 | CHECK_GOTO(CBB_add_u16_length_prefixed(&inner_contents, | ||
| 371 | &inner_inner_contents)); | ||
| 372 | CHECK_GOTO(CBB_add_u8(&inner_inner_contents, 2)); | ||
| 373 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 374 | |||
| 375 | ret = (buf_len == sizeof(kExpected) | ||
| 376 | && memcmp(buf, kExpected, buf_len) == 0); | ||
| 377 | |||
| 378 | if (0) { | ||
| 379 | err: | ||
| 380 | CBB_cleanup(&cbb); | ||
| 381 | } | ||
| 382 | free(buf); | ||
| 383 | return ret; | ||
| 384 | } | ||
| 385 | |||
| 386 | static int | ||
| 387 | test_cbb_discard_child(void) | ||
| 388 | { | ||
| 389 | static const uint8_t kExpected[] = { | ||
| 390 | 0xaa, | ||
| 391 | 0, | ||
| 392 | 1, 0xbb, | ||
| 393 | 0, 2, 0xcc, 0xcc, | ||
| 394 | 0, 0, 3, 0xdd, 0xdd, 0xdd, | ||
| 395 | 1, 0xff, | ||
| 396 | }; | ||
| 397 | CBB cbb, contents, inner_contents, inner_inner_contents; | ||
| 398 | uint8_t *buf = NULL; | ||
| 399 | size_t buf_len; | ||
| 400 | int ret = 0; | ||
| 401 | |||
| 402 | CHECK(CBB_init(&cbb, 0)); | ||
| 403 | CHECK_GOTO(CBB_add_u8(&cbb, 0xaa)); | ||
| 404 | |||
| 405 | // Discarding |cbb|'s children preserves the byte written. | ||
| 406 | CBB_discard_child(&cbb); | ||
| 407 | |||
| 408 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 409 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 410 | CHECK_GOTO(CBB_add_u8(&contents, 0xbb)); | ||
| 411 | CHECK_GOTO(CBB_add_u16_length_prefixed(&cbb, &contents)); | ||
| 412 | CHECK_GOTO(CBB_add_u16(&contents, 0xcccc)); | ||
| 413 | CHECK_GOTO(CBB_add_u24_length_prefixed(&cbb, &contents)); | ||
| 414 | CHECK_GOTO(CBB_add_u24(&contents, 0xdddddd)); | ||
| 415 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &contents)); | ||
| 416 | CHECK_GOTO(CBB_add_u8(&contents, 0xff)); | ||
| 417 | CHECK_GOTO(CBB_add_u8_length_prefixed(&contents, &inner_contents)); | ||
| 418 | CHECK_GOTO(CBB_add_u8(&inner_contents, 0x42)); | ||
| 419 | CHECK_GOTO(CBB_add_u16_length_prefixed(&inner_contents, | ||
| 420 | &inner_inner_contents)); | ||
| 421 | CHECK_GOTO(CBB_add_u8(&inner_inner_contents, 0x99)); | ||
| 422 | |||
| 423 | // Discard everything from |inner_contents| down. | ||
| 424 | CBB_discard_child(&contents); | ||
| 425 | |||
| 426 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 427 | |||
| 428 | ret = (buf_len == sizeof(kExpected) | ||
| 429 | && memcmp(buf, kExpected, buf_len) == 0); | ||
| 430 | |||
| 431 | if (0) { | ||
| 432 | err: | ||
| 433 | CBB_cleanup(&cbb); | ||
| 434 | } | ||
| 435 | free(buf); | ||
| 436 | return ret; | ||
| 437 | } | ||
| 438 | |||
| 439 | static int | ||
| 440 | test_cbb_misuse(void) | ||
| 441 | { | ||
| 442 | CBB cbb, child, contents; | ||
| 443 | uint8_t *buf = NULL; | ||
| 444 | size_t buf_len; | ||
| 445 | int ret = 0; | ||
| 446 | |||
| 447 | CHECK(CBB_init(&cbb, 0)); | ||
| 448 | CHECK_GOTO(CBB_add_u8_length_prefixed(&cbb, &child)); | ||
| 449 | CHECK_GOTO(CBB_add_u8(&child, 1)); | ||
| 450 | CHECK_GOTO(CBB_add_u8(&cbb, 2)); | ||
| 451 | |||
| 452 | /* | ||
| 453 | * Since we wrote to |cbb|, |child| is now invalid and attempts to write | ||
| 454 | * to it should fail. | ||
| 455 | */ | ||
| 456 | CHECK_GOTO(!CBB_add_u8(&child, 1)); | ||
| 457 | CHECK_GOTO(!CBB_add_u16(&child, 1)); | ||
| 458 | CHECK_GOTO(!CBB_add_u24(&child, 1)); | ||
| 459 | CHECK_GOTO(!CBB_add_u8_length_prefixed(&child, &contents)); | ||
| 460 | CHECK_GOTO(!CBB_add_u16_length_prefixed(&child, &contents)); | ||
| 461 | CHECK_GOTO(!CBB_add_asn1(&child, &contents, 1)); | ||
| 462 | CHECK_GOTO(!CBB_add_bytes(&child, (const uint8_t*) "a", 1)); | ||
| 463 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 464 | |||
| 465 | ret = (buf_len == 3 && memcmp(buf, "\x01\x01\x02", 3) == 0); | ||
| 466 | |||
| 467 | if (0) { | ||
| 468 | err: | ||
| 469 | CBB_cleanup(&cbb); | ||
| 470 | } | ||
| 471 | free(buf); | ||
| 472 | return ret; | ||
| 473 | } | ||
| 474 | |||
| 475 | static int | ||
| 476 | test_cbb_asn1(void) | ||
| 477 | { | ||
| 478 | static const uint8_t kExpected[] = {0x30, 3, 1, 2, 3}; | ||
| 479 | uint8_t *buf = NULL, *test_data = NULL; | ||
| 480 | size_t buf_len; | ||
| 481 | CBB cbb, contents, inner_contents; | ||
| 482 | int ret = 0; | ||
| 483 | int alloc = 0; | ||
| 484 | |||
| 485 | CHECK_GOTO(CBB_init(&cbb, 0)); | ||
| 486 | alloc = 1; | ||
| 487 | CHECK_GOTO(CBB_add_asn1(&cbb, &contents, 0x30)); | ||
| 488 | CHECK_GOTO(CBB_add_bytes(&contents, (const uint8_t*) "\x01\x02\x03", | ||
| 489 | 3)); | ||
| 490 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 491 | alloc = 0; | ||
| 492 | |||
| 493 | CHECK_GOTO(buf_len == sizeof(kExpected)); | ||
| 494 | CHECK_GOTO(memcmp(buf, kExpected, buf_len) == 0); | ||
| 495 | |||
| 496 | free(buf); | ||
| 497 | buf = NULL; | ||
| 498 | |||
| 499 | CHECK_GOTO(((test_data = malloc(100000)) != NULL)); | ||
| 500 | memset(test_data, 0x42, 100000); | ||
| 501 | |||
| 502 | CHECK_GOTO(CBB_init(&cbb, 0)); | ||
| 503 | alloc = 1; | ||
| 504 | CHECK_GOTO(CBB_add_asn1(&cbb, &contents, 0x30)); | ||
| 505 | CHECK_GOTO(CBB_add_bytes(&contents, test_data, 130)); | ||
| 506 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 507 | alloc = 0; | ||
| 508 | |||
| 509 | CHECK_GOTO(buf_len == 3 + 130); | ||
| 510 | CHECK_GOTO(memcmp(buf, "\x30\x81\x82", 3) == 0); | ||
| 511 | CHECK_GOTO(memcmp(buf + 3, test_data, 130) == 0); | ||
| 512 | |||
| 513 | free(buf); | ||
| 514 | buf = NULL; | ||
| 515 | |||
| 516 | CHECK_GOTO(CBB_init(&cbb, 0)); | ||
| 517 | alloc = 1; | ||
| 518 | CHECK_GOTO(CBB_add_asn1(&cbb, &contents, 0x30)); | ||
| 519 | CHECK_GOTO(CBB_add_bytes(&contents, test_data, 1000)); | ||
| 520 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 521 | alloc = 0; | ||
| 522 | |||
| 523 | CHECK_GOTO(buf_len == 4 + 1000); | ||
| 524 | CHECK_GOTO(memcmp(buf, "\x30\x82\x03\xe8", 4) == 0); | ||
| 525 | CHECK_GOTO(!memcmp(buf + 4, test_data, 1000)); | ||
| 526 | |||
| 527 | free(buf); | ||
| 528 | buf = NULL; | ||
| 529 | |||
| 530 | CHECK_GOTO(CBB_init(&cbb, 0)); | ||
| 531 | alloc = 1; | ||
| 532 | CHECK_GOTO(CBB_add_asn1(&cbb, &contents, 0x30)); | ||
| 533 | CHECK_GOTO(CBB_add_asn1(&contents, &inner_contents, 0x30)); | ||
| 534 | CHECK_GOTO(CBB_add_bytes(&inner_contents, test_data, 100000)); | ||
| 535 | CHECK_GOTO(CBB_finish(&cbb, &buf, &buf_len)); | ||
| 536 | alloc = 0; | ||
| 537 | |||
| 538 | CHECK_GOTO(buf_len == 5 + 5 + 100000); | ||
| 539 | CHECK_GOTO(memcmp(buf, "\x30\x83\x01\x86\xa5\x30\x83\x01\x86\xa0", 10) | ||
| 540 | == 0); | ||
| 541 | CHECK_GOTO(!memcmp(buf + 10, test_data, 100000)); | ||
| 542 | |||
| 543 | ret = 1; | ||
| 544 | |||
| 545 | if (0) { | ||
| 546 | err: | ||
| 547 | if (alloc) | ||
| 548 | CBB_cleanup(&cbb); | ||
| 549 | } | ||
| 550 | free(buf); | ||
| 551 | free(test_data); | ||
| 552 | return ret; | ||
| 553 | } | ||
| 554 | |||
| 555 | static int | ||
| 556 | do_indefinite_convert(const char *name, const uint8_t *definite_expected, | ||
| 557 | size_t definite_len, const uint8_t *indefinite, size_t indefinite_len) | ||
| 558 | { | ||
| 559 | CBS in; | ||
| 560 | uint8_t *out = NULL; | ||
| 561 | size_t out_len; | ||
| 562 | int ret = 0; | ||
| 563 | |||
| 564 | CBS_init(&in, indefinite, indefinite_len); | ||
| 565 | |||
| 566 | CHECK_GOTO(CBS_asn1_indefinite_to_definite(&in, &out, &out_len)); | ||
| 567 | |||
| 568 | if (out == NULL) { | ||
| 569 | |||
| 570 | if (indefinite_len != definite_len || | ||
| 571 | memcmp(definite_expected, indefinite, indefinite_len) != 0) { | ||
| 572 | PRINT_ERROR; | ||
| 573 | goto err; | ||
| 574 | } | ||
| 575 | |||
| 576 | return 1; | ||
| 577 | } | ||
| 578 | |||
| 579 | if (out_len != definite_len || | ||
| 580 | memcmp(out, definite_expected, definite_len) != 0) { | ||
| 581 | PRINT_ERROR; | ||
| 582 | goto err; | ||
| 583 | } | ||
| 584 | |||
| 585 | ret = 1; | ||
| 586 | err: | ||
| 587 | free(out); | ||
| 588 | return ret; | ||
| 589 | } | ||
| 590 | |||
| 591 | static int | ||
| 592 | test_indefinite_convert(void) | ||
| 593 | { | ||
| 594 | static const uint8_t kSimpleBER[] = {0x01, 0x01, 0x00}; | ||
| 595 | |||
| 596 | /* kIndefBER contains a SEQUENCE with an indefinite length. */ | ||
| 597 | static const uint8_t kIndefBER[] = {0x30, 0x80, 0x01, 0x01, 0x02, 0x00, | ||
| 598 | 0x00}; | ||
| 599 | static const uint8_t kIndefDER[] = {0x30, 0x03, 0x01, 0x01, 0x02}; | ||
| 600 | |||
| 601 | /* | ||
| 602 | * kOctetStringBER contains an indefinite length OCTETSTRING with two | ||
| 603 | * parts. These parts need to be concatenated in DER form. | ||
| 604 | */ | ||
| 605 | static const uint8_t kOctetStringBER[] = {0x24, 0x80, 0x04, 0x02, 0, | ||
| 606 | 1, 0x04, 0x02, 2, 3, 0x00, 0x00}; | ||
| 607 | static const uint8_t kOctetStringDER[] = {0x04, 0x04, 0, 1, 2, 3}; | ||
| 608 | |||
| 609 | /* | ||
| 610 | * kNSSBER is part of a PKCS#12 message generated by NSS that uses | ||
| 611 | * indefinite length elements extensively. | ||
| 612 | */ | ||
| 613 | static const uint8_t kNSSBER[] = { | ||
| 614 | 0x30, 0x80, 0x02, 0x01, 0x03, 0x30, 0x80, 0x06, 0x09, 0x2a, 0x86, | ||
| 615 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x80, 0x24, 0x80, | ||
| 616 | 0x04, 0x04, 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 617 | 0x00, 0x30, 0x39, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, | ||
| 618 | 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0x84, 0x98, 0xfc, 0x66, | ||
| 619 | 0x33, 0xee, 0xba, 0xe7, 0x90, 0xc1, 0xb6, 0xe8, 0x8f, 0xfe, 0x1d, | ||
| 620 | 0xc5, 0xa5, 0x97, 0x93, 0x3e, 0x04, 0x10, 0x38, 0x62, 0xc6, 0x44, | ||
| 621 | 0x12, 0xd5, 0x30, 0x00, 0xf8, 0xf2, 0x1b, 0xf0, 0x6e, 0x10, 0x9b, | ||
| 622 | 0xb8, 0x02, 0x02, 0x07, 0xd0, 0x00, 0x00, | ||
| 623 | }; | ||
| 624 | |||
| 625 | static const uint8_t kNSSDER[] = { | ||
| 626 | 0x30, 0x53, 0x02, 0x01, 0x03, 0x30, 0x13, 0x06, 0x09, 0x2a, 0x86, | ||
| 627 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x06, 0x04, 0x04, | ||
| 628 | 0x01, 0x02, 0x03, 0x04, 0x30, 0x39, 0x30, 0x21, 0x30, 0x09, 0x06, | ||
| 629 | 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14, 0x84, | ||
| 630 | 0x98, 0xfc, 0x66, 0x33, 0xee, 0xba, 0xe7, 0x90, 0xc1, 0xb6, 0xe8, | ||
| 631 | 0x8f, 0xfe, 0x1d, 0xc5, 0xa5, 0x97, 0x93, 0x3e, 0x04, 0x10, 0x38, | ||
| 632 | 0x62, 0xc6, 0x44, 0x12, 0xd5, 0x30, 0x00, 0xf8, 0xf2, 0x1b, 0xf0, | ||
| 633 | 0x6e, 0x10, 0x9b, 0xb8, 0x02, 0x02, 0x07, 0xd0, | ||
| 634 | }; | ||
| 635 | |||
| 636 | CHECK(do_indefinite_convert("kSimpleBER", kSimpleBER, sizeof(kSimpleBER), | ||
| 637 | kSimpleBER, sizeof(kSimpleBER))); | ||
| 638 | CHECK(do_indefinite_convert("kIndefBER", kIndefDER, sizeof(kIndefDER), | ||
| 639 | kIndefBER, sizeof(kIndefBER))); | ||
| 640 | CHECK(do_indefinite_convert("kOctetStringBER", kOctetStringDER, | ||
| 641 | sizeof(kOctetStringDER), kOctetStringBER, | ||
| 642 | sizeof(kOctetStringBER))); | ||
| 643 | CHECK(do_indefinite_convert("kNSSBER", kNSSDER, sizeof(kNSSDER), kNSSBER, | ||
| 644 | sizeof(kNSSBER))); | ||
| 645 | |||
| 646 | return 1; | ||
| 647 | } | ||
| 648 | |||
| 649 | typedef struct { | ||
| 650 | uint64_t value; | ||
| 651 | const char *encoding; | ||
| 652 | size_t encoding_len; | ||
| 653 | } ASN1_UINT64_TEST; | ||
| 654 | |||
| 655 | static const ASN1_UINT64_TEST kAsn1Uint64Tests[] = { | ||
| 656 | {0, "\x02\x01\x00", 3}, | ||
| 657 | {1, "\x02\x01\x01", 3}, | ||
| 658 | {127, "\x02\x01\x7f", 3}, | ||
| 659 | {128, "\x02\x02\x00\x80", 4}, | ||
| 660 | {0xdeadbeef, "\x02\x05\x00\xde\xad\xbe\xef", 7}, | ||
| 661 | {OPENSSL_U64(0x0102030405060708), | ||
| 662 | "\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10}, | ||
| 663 | {OPENSSL_U64(0xffffffffffffffff), | ||
| 664 | "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11}, | ||
| 665 | }; | ||
| 666 | |||
| 667 | typedef struct { | ||
| 668 | const char *encoding; | ||
| 669 | size_t encoding_len; | ||
| 670 | } ASN1_INVALID_UINT64_TEST; | ||
| 671 | |||
| 672 | static const ASN1_INVALID_UINT64_TEST kAsn1InvalidUint64Tests[] = { | ||
| 673 | /* Bad tag. */ | ||
| 674 | {"\x03\x01\x00", 3}, | ||
| 675 | /* Empty contents. */ | ||
| 676 | {"\x02\x00", 2}, | ||
| 677 | /* Negative number. */ | ||
| 678 | {"\x02\x01\x80", 3}, | ||
| 679 | /* Overflow. */ | ||
| 680 | {"\x02\x09\x01\x00\x00\x00\x00\x00\x00\x00\x00", 11}, | ||
| 681 | /* Leading zeros. */ | ||
| 682 | {"\x02\x02\x00\x01", 4}, | ||
| 683 | }; | ||
| 684 | |||
| 685 | static int | ||
| 686 | test_asn1_uint64(void) | ||
| 687 | { | ||
| 688 | CBB cbb; | ||
| 689 | uint8_t *out = NULL; | ||
| 690 | size_t i; | ||
| 691 | int ret = 0; | ||
| 692 | int alloc = 0; | ||
| 693 | |||
| 694 | for (i = 0; i < sizeof(kAsn1Uint64Tests) / sizeof(kAsn1Uint64Tests[0]); | ||
| 695 | i++) { | ||
| 696 | const ASN1_UINT64_TEST *test = &kAsn1Uint64Tests[i]; | ||
| 697 | CBS cbs; | ||
| 698 | uint64_t value; | ||
| 699 | size_t len; | ||
| 700 | |||
| 701 | CBS_init(&cbs, (const uint8_t *)test->encoding, | ||
| 702 | test->encoding_len); | ||
| 703 | |||
| 704 | CHECK(CBS_get_asn1_uint64(&cbs, &value)); | ||
| 705 | CHECK(CBS_len(&cbs) == 0); | ||
| 706 | CHECK(value == test->value); | ||
| 707 | |||
| 708 | CHECK(CBB_init(&cbb, 0)); | ||
| 709 | alloc = 1; | ||
| 710 | CHECK_GOTO(CBB_add_asn1_uint64(&cbb, test->value)); | ||
| 711 | CHECK_GOTO(CBB_finish(&cbb, &out, &len)); | ||
| 712 | alloc = 0; | ||
| 713 | |||
| 714 | CHECK_GOTO(len == test->encoding_len); | ||
| 715 | CHECK_GOTO(memcmp(out, test->encoding, len) == 0); | ||
| 716 | free(out); | ||
| 717 | out = NULL; | ||
| 718 | } | ||
| 719 | |||
| 720 | for (i = 0; i < sizeof(kAsn1InvalidUint64Tests) | ||
| 721 | / sizeof(kAsn1InvalidUint64Tests[0]); i++) { | ||
| 722 | const ASN1_INVALID_UINT64_TEST *test = | ||
| 723 | &kAsn1InvalidUint64Tests[i]; | ||
| 724 | CBS cbs; | ||
| 725 | uint64_t value; | ||
| 726 | |||
| 727 | CBS_init(&cbs, (const uint8_t *)test->encoding, | ||
| 728 | test->encoding_len); | ||
| 729 | CHECK(!CBS_get_asn1_uint64(&cbs, &value)); | ||
| 730 | } | ||
| 731 | |||
| 732 | ret = 1; | ||
| 733 | |||
| 734 | if (0) { | ||
| 735 | err: | ||
| 736 | if (alloc) | ||
| 737 | CBB_cleanup(&cbb); | ||
| 738 | } | ||
| 739 | free(out); | ||
| 740 | |||
| 741 | return ret; | ||
| 742 | } | ||
| 743 | |||
| 744 | static int | ||
| 745 | test_offset(void) | ||
| 746 | { | ||
| 747 | uint8_t v; | ||
| 748 | static const uint8_t input[] = {1, 2, 3, 4, 5}; | ||
| 749 | CBS data; | ||
| 750 | |||
| 751 | CBS_init(&data, input, sizeof(input)); | ||
| 752 | CHECK(sizeof(input) == 5); | ||
| 753 | CHECK(CBS_len(&data) == 5); | ||
| 754 | CHECK(CBS_offset(&data) == 0); | ||
| 755 | CHECK(CBS_get_u8(&data, &v)); | ||
| 756 | CHECK(v == 1); | ||
| 757 | CHECK(CBS_len(&data) == 4); | ||
| 758 | CHECK(CBS_offset(&data) == 1); | ||
| 759 | CHECK(CBS_skip(&data, 2)); | ||
| 760 | CHECK(CBS_len(&data) == 2); | ||
| 761 | CHECK(CBS_offset(&data) == 3); | ||
| 762 | CHECK(CBS_get_u8(&data, &v)); | ||
| 763 | CHECK(v == 4); | ||
| 764 | CHECK(CBS_get_u8(&data, &v)); | ||
| 765 | CHECK(v == 5); | ||
| 766 | CHECK(CBS_len(&data) == 0); | ||
| 767 | CHECK(CBS_offset(&data) == 5); | ||
| 768 | CHECK(!CBS_skip(&data, 1)); | ||
| 769 | |||
| 770 | CBS_init(&data, input, sizeof(input)); | ||
| 771 | CHECK(CBS_skip(&data, 2)); | ||
| 772 | CHECK(CBS_len(&data) == 3); | ||
| 773 | CHECK(CBS_offset(&data) == 2); | ||
| 774 | CHECK(CBS_skip(&data, 3)); | ||
| 775 | CHECK(CBS_len(&data) == 0); | ||
| 776 | CHECK(CBS_offset(&data) == 5); | ||
| 777 | CHECK(!CBS_get_u8(&data, &v)); | ||
| 778 | |||
| 779 | return 1; | ||
| 780 | } | ||
| 781 | |||
| 782 | static int | ||
| 783 | test_write_bytes(void) | ||
| 784 | { | ||
| 785 | int ret = 0; | ||
| 786 | uint8_t v; | ||
| 787 | size_t len; | ||
| 788 | static const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'}; | ||
| 789 | CBS data; | ||
| 790 | char *tmp = NULL; | ||
| 791 | |||
| 792 | CHECK_GOTO((tmp = malloc(sizeof(input))) != NULL); | ||
| 793 | memset(tmp, 100, sizeof(input)); | ||
| 794 | |||
| 795 | CBS_init(&data, input, sizeof(input)); | ||
| 796 | CHECK_GOTO(CBS_len(&data) == 6); | ||
| 797 | CHECK_GOTO(CBS_offset(&data) == 0); | ||
| 798 | CHECK_GOTO(CBS_get_u8(&data, &v)); | ||
| 799 | CHECK_GOTO(v == 102 /* f */); | ||
| 800 | CHECK_GOTO(CBS_skip(&data, 1)); | ||
| 801 | CHECK_GOTO(!CBS_skip(&data, 15)); | ||
| 802 | CHECK_GOTO(CBS_write_bytes(&data, tmp, sizeof(input), &len)); | ||
| 803 | CHECK_GOTO(len == 4); | ||
| 804 | CHECK_GOTO(memcmp(input + 2, tmp, len) == 0); | ||
| 805 | CHECK_GOTO(tmp[4] == 100 && tmp[5] == 100); | ||
| 806 | |||
| 807 | ret = 1; | ||
| 808 | |||
| 809 | err: | ||
| 810 | free(tmp); | ||
| 811 | return ret; | ||
| 812 | } | ||
| 813 | |||
| 814 | static int | ||
| 815 | test_cbs_dup(void) | ||
| 816 | { | ||
| 817 | CBS data, check; | ||
| 818 | static const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'}; | ||
| 819 | |||
| 820 | CBS_init(&data, input, sizeof(input)); | ||
| 821 | CHECK(CBS_len(&data) == 6); | ||
| 822 | CBS_dup(&data, &check); | ||
| 823 | CHECK(CBS_len(&check) == 6); | ||
| 824 | CHECK(CBS_data(&data) == CBS_data(&check)); | ||
| 825 | CHECK(CBS_skip(&data, 1)); | ||
| 826 | CHECK(CBS_len(&data) == 5); | ||
| 827 | CHECK(CBS_len(&check) == 6); | ||
| 828 | CHECK(CBS_data(&data) == CBS_data(&check) + 1); | ||
| 829 | CHECK(CBS_skip(&check, 1)); | ||
| 830 | CHECK(CBS_len(&data) == 5); | ||
| 831 | CHECK(CBS_len(&check) == 5); | ||
| 832 | CHECK(CBS_data(&data) == CBS_data(&check)); | ||
| 833 | CHECK(CBS_offset(&data) == 1); | ||
| 834 | CHECK(CBS_offset(&check) == 1); | ||
| 835 | |||
| 836 | CBS_init(&data, input, sizeof(input)); | ||
| 837 | CHECK(CBS_skip(&data, 5)); | ||
| 838 | CBS_dup(&data, &check); | ||
| 839 | CHECK(CBS_len(&data) == 1); | ||
| 840 | CHECK(CBS_len(&check) == 1); | ||
| 841 | CHECK(CBS_data(&data) == input + 5); | ||
| 842 | CHECK(CBS_data(&data) == CBS_data(&check)); | ||
| 843 | CHECK(CBS_offset(&data) == 5); | ||
| 844 | CHECK(CBS_offset(&check) == 5); | ||
| 845 | |||
| 846 | return 1; | ||
| 847 | } | ||
| 848 | |||
| 849 | int | ||
| 850 | main(void) | ||
| 851 | { | ||
| 852 | int failed = 0; | ||
| 853 | |||
| 854 | failed |= !test_skip(); | ||
| 855 | failed |= !test_get_u(); | ||
| 856 | failed |= !test_get_prefixed(); | ||
| 857 | failed |= !test_get_prefixed_bad(); | ||
| 858 | failed |= !test_get_asn1(); | ||
| 859 | failed |= !test_cbb_basic(); | ||
| 860 | failed |= !test_cbb_fixed(); | ||
| 861 | failed |= !test_cbb_finish_child(); | ||
| 862 | failed |= !test_cbb_discard_child(); | ||
| 863 | failed |= !test_cbb_misuse(); | ||
| 864 | failed |= !test_cbb_prefixed(); | ||
| 865 | failed |= !test_cbb_asn1(); | ||
| 866 | failed |= !test_indefinite_convert(); | ||
| 867 | failed |= !test_asn1_uint64(); | ||
| 868 | failed |= !test_get_optional_asn1_bool(); | ||
| 869 | failed |= !test_offset(); | ||
| 870 | failed |= !test_write_bytes(); | ||
| 871 | failed |= !test_cbs_dup(); | ||
| 872 | |||
| 873 | if (!failed) | ||
| 874 | printf("PASS\n"); | ||
| 875 | return failed; | ||
| 876 | } | ||
diff --git a/src/regress/lib/libssl/certs/ca.pem b/src/regress/lib/libssl/certs/ca.pem deleted file mode 100644 index 07f9b3fddb..0000000000 --- a/src/regress/lib/libssl/certs/ca.pem +++ /dev/null | |||
| @@ -1,45 +0,0 @@ | |||
| 1 | -----BEGIN CERTIFICATE----- | ||
| 2 | MIIDtjCCAp6gAwIBAgIJAJz/hGfwYXLrMA0GCSqGSIb3DQEBBQUAMGgxCzAJBgNV | ||
| 3 | BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT | ||
| 4 | VElORyBQVVJQT1NFUyBPTkxZMR0wGwYDVQQDDBRPcGVuU1NMIFRlc3QgUm9vdCBD | ||
| 5 | QTAeFw0xNDA1MjQxNDQ1MTFaFw0yNDA1MjExNDQ1MTFaMGgxCzAJBgNVBAYTAlVL | ||
| 6 | MRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVTVElORyBQ | ||
| 7 | VVJQT1NFUyBPTkxZMR0wGwYDVQQDDBRPcGVuU1NMIFRlc3QgUm9vdCBDQTCCASIw | ||
| 8 | DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANMaarigKGOra5Mc/LrhOkcmHzDs | ||
| 9 | vkYL7dfaaht8fLBKRTYwzSBvO9x54koTWjq7HkbaxkYAg3HnDTkNCyzkGKNdM89H | ||
| 10 | q/PtGIFFlceQIOat3Kjd05Iw3PtLEWTDjT6FMA9Mkjk/XbpmycqRIwNKtgICoFsG | ||
| 11 | juIpc4P31kxK7i3ri+JnlyvVmRZjJxrheJB0qHGXilrOVDPOliDn//jXbcyzXemu | ||
| 12 | R8KgAeQM4IIs9jYHJOgHrTItIpwa9wNTEp9KCGkO6xr20NkKyDp6XRyd+hmnUB7r | ||
| 13 | 77WTptvKPFFTjTDFqEtcif9U2kVkCfn2mSRO8noCbVH++fuR8LMWlD99gt8CAwEA | ||
| 14 | AaNjMGEwHQYDVR0OBBYEFIwZD9dCMXcFBuHTsZ/rOft4cTpFMB8GA1UdIwQYMBaA | ||
| 15 | FIwZD9dCMXcFBuHTsZ/rOft4cTpFMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/ | ||
| 16 | BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQCPfqm4KbYtXEB8aP1RdUH2BkPSjyau | ||
| 17 | WQLMGfKNF/zkUQue0REgdJ4wVR06NTTlOCsfHC6b68vgz2QFC1mM8ZANgDiyr4M1 | ||
| 18 | 6gjvP0eZQVxokJ3EMzjDMFRHIiFrZZAFr7aGq8dxoruuehovqyehuJRakAe0oNUb | ||
| 19 | 4ZTKrGuTKh9Mwti9721XNFByjeTFL2dlH6ulz7qyfI+lrTi+pNsUchuVYE8a1TP3 | ||
| 20 | OEiG6whsyPU1YoTlemC1mvW0ixtj8Tcem0KyotCUyOmJlwyWj0bA43sCI6z/OVqJ | ||
| 21 | tVvwgfqrOeVNk9nN2JslCsttnwstwqUfDoEXFoScej2CT0QezFGPTN21 | ||
| 22 | -----END CERTIFICATE----- | ||
| 23 | -----BEGIN CERTIFICATE----- | ||
| 24 | MIIDvjCCAqagAwIBAgIJAPrXr2k7uM/OMA0GCSqGSIb3DQEBBQUAMGgxCzAJBgNV | ||
| 25 | BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT | ||
| 26 | VElORyBQVVJQT1NFUyBPTkxZMR0wGwYDVQQDDBRPcGVuU1NMIFRlc3QgUm9vdCBD | ||
| 27 | QTAeFw0xNDA1MjQxNDQ1MTFaFw0yNDA1MDExNDQ1MTFaMHAxCzAJBgNVBAYTAlVL | ||
| 28 | MRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVTVElORyBQ | ||
| 29 | VVJQT1NFUyBPTkxZMSUwIwYDVQQDDBxPcGVuU1NMIFRlc3QgSW50ZXJtZWRpYXRl | ||
| 30 | IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsErw75CmLYD6pkrG | ||
| 31 | W/YhAl/K8L5wJYxDjqu2FghxjD8K308W3EHq4uBxEwR1OHXaM1+6ZZw7/r2I37VL | ||
| 32 | IdurBEAIEUdbzx0so74FPawgz5EW2CTqoJnK8F71/vo5Kj1VPwW46CxwxUR3cfvJ | ||
| 33 | GNXND2ip0TcyTSPLROXOyQakcVfIGJmdSa1wHKi+c2gMA4emADudZUOYLrg80gr2 | ||
| 34 | ldePm07ynbVsKKzCcStw8MdmoW9Qt3fLnPJn2TFUUBNWj+4kvL+88edWCVQXKNds | ||
| 35 | ysD/CDrH4W/hjyPDStVsM6XpiNU0+L2ZY6fcj3OP8d0goOx45xotMn9m8hNkCGsr | ||
| 36 | VXx9IwIDAQABo2MwYTAdBgNVHQ4EFgQUNsNsiOeV/rC97M4+PYarIYGH2towHwYD | ||
| 37 | VR0jBBgwFoAUjBkP10IxdwUG4dOxn+s5+3hxOkUwDwYDVR0TAQH/BAUwAwEB/zAO | ||
| 38 | BgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEFBQADggEBAAIwwR8jyFN6qYGIRAKi | ||
| 39 | ahyeHd26hNPC4RiCvjz6dytuvDUqfMTUZcjBy6Ez1Wsfs1/PC8u3IDpOTwZSz72K | ||
| 40 | ACQzPpmXREWkO5nx8I+W+94yJsbklhsTxDlZj3X2oJCQ7qO4hdIpYESWfMchYra9 | ||
| 41 | 5e55SMBXeGDp+uRILt+6UfOXCGaXaoYqyrzQROJAiGy1x96A/5sU6ZU3KdKN1JLM | ||
| 42 | XTZ268ihubCMRVScHnpYUjRDoGrhnQM7007ybVfRUGNXDs+ENqjGfyxc5ScR+Un4 | ||
| 43 | UQtOd4zD2g9wrdXvlDiqxci6W7IOEPVP6qHG2GIh+T2zpO3GOAuZCe5cjLiCDATs | ||
| 44 | hNw= | ||
| 45 | -----END CERTIFICATE----- | ||
diff --git a/src/regress/lib/libssl/certs/client.pem b/src/regress/lib/libssl/certs/client.pem deleted file mode 100644 index ce4bf49ce6..0000000000 --- a/src/regress/lib/libssl/certs/client.pem +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | subject= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = Test Client Cert | ||
| 2 | issuer= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = OpenSSL Test Intermediate CA | ||
| 3 | -----BEGIN CERTIFICATE----- | ||
| 4 | MIIDpTCCAo2gAwIBAgIJAPYm3GvOr5eTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV | ||
| 5 | BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT | ||
| 6 | VElORyBQVVJQT1NFUyBPTkxZMSUwIwYDVQQDDBxPcGVuU1NMIFRlc3QgSW50ZXJt | ||
| 7 | ZWRpYXRlIENBMB4XDTE0MDUyNDE0NDUxMVoXDTI0MDQwMTE0NDUxMVowZDELMAkG | ||
| 8 | A1UEBhMCVUsxFjAUBgNVBAoMDU9wZW5TU0wgR3JvdXAxIjAgBgNVBAsMGUZPUiBU | ||
| 9 | RVNUSU5HIFBVUlBPU0VTIE9OTFkxGTAXBgNVBAMMEFRlc3QgQ2xpZW50IENlcnQw | ||
| 10 | ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0ranbHRLcLVqN+0BzcZpY | ||
| 11 | +yOLqxzDWT1LD9eW1stC4NzXX9/DCtSIVyN7YIHdGLrIPr64IDdXXaMRzgZ2rOKs | ||
| 12 | lmHCAiFpO/ja99gGCJRxH0xwQatqAULfJVHeUhs7OEGOZc2nWifjqKvGfNTilP7D | ||
| 13 | nwi69ipQFq9oS19FmhwVHk2wg7KZGHI1qDyG04UrfCZMRitvS9+UVhPpIPjuiBi2 | ||
| 14 | x3/FZIpL5gXJvvFK6xHY63oq2asyzBATntBgnP4qJFWWcvRx24wF1PnZabxuVoL2 | ||
| 15 | bPnQ/KvONDrw3IdqkKhYNTul7jEcu3OlcZIMw+7DiaKJLAzKb/bBF5gm/pwW6As9 | ||
| 16 | AgMBAAGjTjBMMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCwGCWCGSAGG | ||
| 17 | +EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTANBgkqhkiG9w0B | ||
| 18 | AQUFAAOCAQEAJzA4KTjkjXGSC4He63yX9Br0DneGBzjAwc1H6f72uqnCs8m7jgkE | ||
| 19 | PQJFdTzQUKh97QPUuayZ2gl8XHagg+iWGy60Kw37gQ0+lumCN2sllvifhHU9R03H | ||
| 20 | bWtS4kue+yQjMbrzf3zWygMDgwvFOUAIgBpH9qGc+CdNu97INTYd0Mvz51vLlxRn | ||
| 21 | sC5aBYCWaZFnw3lWYxf9eVFRy9U+DkYFqX0LpmbDtcKP7AZGE6ZwSzaim+Cnoz1u | ||
| 22 | Cgn+QmpFXgJKMFIZ82iSZISn+JkCCGxctZX1lMvai4Wi8Y0HxW9FTFZ6KBNwwE4B | ||
| 23 | zjbN/ehBkgLlW/DWfi44DvwUHmuU6QP3cw== | ||
| 24 | -----END CERTIFICATE----- | ||
| 25 | -----BEGIN RSA PRIVATE KEY----- | ||
| 26 | MIIEpQIBAAKCAQEAtK2p2x0S3C1ajftAc3GaWPsji6scw1k9Sw/XltbLQuDc11/f | ||
| 27 | wwrUiFcje2CB3Ri6yD6+uCA3V12jEc4GdqzirJZhwgIhaTv42vfYBgiUcR9McEGr | ||
| 28 | agFC3yVR3lIbOzhBjmXNp1on46irxnzU4pT+w58IuvYqUBavaEtfRZocFR5NsIOy | ||
| 29 | mRhyNag8htOFK3wmTEYrb0vflFYT6SD47ogYtsd/xWSKS+YFyb7xSusR2Ot6Ktmr | ||
| 30 | MswQE57QYJz+KiRVlnL0cduMBdT52Wm8blaC9mz50PyrzjQ68NyHapCoWDU7pe4x | ||
| 31 | HLtzpXGSDMPuw4miiSwMym/2wReYJv6cFugLPQIDAQABAoIBAAZOyc9MhIwLSU4L | ||
| 32 | p4RgQvM4UVVe8/Id+3XTZ8NsXExJbWxXfIhiqGjaIfL8u4vsgRjcl+v1s/jo2/iT | ||
| 33 | KMab4o4D8gXD7UavQVDjtjb/ta79WL3SjRl2Uc9YjjMkyq6WmDNQeo2NKDdafCTB | ||
| 34 | 1uzSJtLNipB8Z53ELPuHJhxX9QMHrMnuha49riQgXZ7buP9iQrHJFhImBjSzbxJx | ||
| 35 | L+TI6rkyLSf9Wi0Pd3L27Ob3QWNfNRYNSeTE+08eSRChkur5W0RuXAcuAICdQlCl | ||
| 36 | LBvWO/LmmvbzCqiDcgy/TliSb6CGGwgiNG7LJZmlkYNj8laGwalNlYZs3UrVv6NO | ||
| 37 | Br2loAECgYEA2kvCvPGj0Dg/6g7WhXDvAkEbcaL1tSeCxBbNH+6HS2UWMWvyTtCn | ||
| 38 | /bbD519QIdkvayy1QjEf32GV/UjUVmlULMLBcDy0DGjtL3+XpIhLKWDNxN1v1/ai | ||
| 39 | 1oz23ZJCOgnk6K4qtFtlRS1XtynjA+rBetvYvLP9SKeFrnpzCgaA2r0CgYEA0+KX | ||
| 40 | 1ACXDTNH5ySX3kMjSS9xdINf+OOw4CvPHFwbtc9aqk2HePlEsBTz5I/W3rKwXva3 | ||
| 41 | NqZ/bRqVVeZB/hHKFywgdUQk2Uc5z/S7Lw70/w1HubNTXGU06Ngb6zOFAo/o/TwZ | ||
| 42 | zTP1BMIKSOB6PAZPS3l+aLO4FRIRotfFhgRHOoECgYEAmiZbqt8cJaJDB/5YYDzC | ||
| 43 | mp3tSk6gIb936Q6M5VqkMYp9pIKsxhk0N8aDCnTU+kIK6SzWBpr3/d9Ecmqmfyq7 | ||
| 44 | 5SvWO3KyVf0WWK9KH0abhOm2BKm2HBQvI0DB5u8sUx2/hsvOnjPYDISbZ11t0MtK | ||
| 45 | u35Zy89yMYcSsIYJjG/ROCUCgYEAgI2P9G5PNxEP5OtMwOsW84Y3Xat/hPAQFlI+ | ||
| 46 | HES+AzbFGWJkeT8zL2nm95tVkFP1sggZ7Kxjz3w7cpx7GX0NkbWSE9O+T51pNASV | ||
| 47 | tN1sQ3p5M+/a+cnlqgfEGJVvc7iAcXQPa3LEi5h2yPR49QYXAgG6cifn3dDSpmwn | ||
| 48 | SUI7PQECgYEApGCIIpSRPLAEHTGmP87RBL1smurhwmy2s/pghkvUkWehtxg0sGHh | ||
| 49 | kuaqDWcskogv+QC0sVdytiLSz8G0DwcEcsHK1Fkyb8A+ayiw6jWJDo2m9+IF4Fww | ||
| 50 | 1Te6jFPYDESnbhq7+TLGgHGhtwcu5cnb4vSuYXGXKupZGzoLOBbv1Zw= | ||
| 51 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/regress/lib/libssl/certs/server.pem b/src/regress/lib/libssl/certs/server.pem deleted file mode 100644 index 7412490f51..0000000000 --- a/src/regress/lib/libssl/certs/server.pem +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | subject= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = Test Server Cert | ||
| 2 | issuer= C = UK, O = OpenSSL Group, OU = FOR TESTING PURPOSES ONLY, CN = OpenSSL Test Intermediate CA | ||
| 3 | -----BEGIN CERTIFICATE----- | ||
| 4 | MIIDpTCCAo2gAwIBAgIJAPYm3GvOr5eUMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV | ||
| 5 | BAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMSIwIAYDVQQLDBlGT1IgVEVT | ||
| 6 | VElORyBQVVJQT1NFUyBPTkxZMSUwIwYDVQQDDBxPcGVuU1NMIFRlc3QgSW50ZXJt | ||
| 7 | ZWRpYXRlIENBMB4XDTE0MDUyNDE0NDUxMloXDTI0MDQwMTE0NDUxMlowZDELMAkG | ||
| 8 | A1UEBhMCVUsxFjAUBgNVBAoMDU9wZW5TU0wgR3JvdXAxIjAgBgNVBAsMGUZPUiBU | ||
| 9 | RVNUSU5HIFBVUlBPU0VTIE9OTFkxGTAXBgNVBAMMEFRlc3QgU2VydmVyIENlcnQw | ||
| 10 | ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDzhPOSNtyyRspmeuUpxfNJ | ||
| 11 | KCLTuf7g3uQ4zu4iHOmRO5TQci+HhVlLZrHF9XqFXcIP0y4pWDbMSGuiorUmzmfi | ||
| 12 | R7bfSdI/+qIQt8KXRH6HNG1t8ou0VSvWId5TS5Dq/er5ODUr9OaaDva7EquHIcMv | ||
| 13 | vPQGuI+OEAcnleVCy9HVEIySrO4P3CNIicnGkwwiAud05yUAq/gPXBC1hTtmlPD7 | ||
| 14 | TVcGVSEiJdvzqqlgv02qedGrkki6GY4S7GjZxrrf7Foc2EP+51LJzwLQx3/JfrCU | ||
| 15 | 41NEWAsu/Sl0tQabXESN+zJ1pDqoZ3uHMgpQjeGiE0olr+YcsSW/tJmiU9OiAr8R | ||
| 16 | AgMBAAGjTjBMMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCwGCWCGSAGG | ||
| 17 | +EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTANBgkqhkiG9w0B | ||
| 18 | AQUFAAOCAQEADfy8VrY5er5ebYLyiC1il5kVOuJHSf8aN5SciJz/VcifA1+Hl2Bu | ||
| 19 | CfuizhP/kUdB9PTSj8ep9sL+5PBFl7CZJDO6Sxs5+qJe15XvLBP8UEdvc779plL6 | ||
| 20 | StUMJT0aU/MaqUZZCldC3G4CcbwzOzKSD5YzvxxIGspxBWRduZKKMOju/4aqK76p | ||
| 21 | dwA/VGCve9mjft3LIrb0gSaPi5KmdGtpAjzW3H1+63DSqxCYb1oiPtUZBs4STwjh | ||
| 22 | WPRmAEVR4RPCETM3Sth4C+bE0QMCGY12ctcbzhj7Xgo7LcSpqviq6JD8SPuU7ISL | ||
| 23 | hy4NcnBBHJr9OV9WTLpmS9V9Vg6QmOpxQw== | ||
| 24 | -----END CERTIFICATE----- | ||
| 25 | -----BEGIN RSA PRIVATE KEY----- | ||
| 26 | MIIEpAIBAAKCAQEA84TzkjbcskbKZnrlKcXzSSgi07n+4N7kOM7uIhzpkTuU0HIv | ||
| 27 | h4VZS2axxfV6hV3CD9MuKVg2zEhroqK1Js5n4ke230nSP/qiELfCl0R+hzRtbfKL | ||
| 28 | tFUr1iHeU0uQ6v3q+Tg1K/Tmmg72uxKrhyHDL7z0BriPjhAHJ5XlQsvR1RCMkqzu | ||
| 29 | D9wjSInJxpMMIgLndOclAKv4D1wQtYU7ZpTw+01XBlUhIiXb86qpYL9NqnnRq5JI | ||
| 30 | uhmOEuxo2ca63+xaHNhD/udSyc8C0Md/yX6wlONTRFgLLv0pdLUGm1xEjfsydaQ6 | ||
| 31 | qGd7hzIKUI3hohNKJa/mHLElv7SZolPTogK/EQIDAQABAoIBAADq9FwNtuE5IRQn | ||
| 32 | zGtO4q7Y5uCzZ8GDNYr9RKp+P2cbuWDbvVAecYq2NV9QoIiWJOAYZKklOvekIju3 | ||
| 33 | r0UZLA0PRiIrTg6NrESx3JrjWDK8QNlUO7CPTZ39/K+FrmMkV9lem9yxjJjyC34D | ||
| 34 | AQB+YRTx+l14HppjdxNwHjAVQpIx/uO2F5xAMuk32+3K+pq9CZUtrofe1q4Agj9R | ||
| 35 | 5s8mSy9pbRo9kW9wl5xdEotz1LivFOEiqPUJTUq5J5PeMKao3vdK726XI4Z455Nm | ||
| 36 | W2/MA0YV0ug2FYinHcZdvKM6dimH8GLfa3X8xKRfzjGjTiMSwsdjgMa4awY3tEHH | ||
| 37 | 674jhAECgYEA/zqMrc0zsbNk83sjgaYIug5kzEpN4ic020rSZsmQxSCerJTgNhmg | ||
| 38 | utKSCt0Re09Jt3LqG48msahX8ycqDsHNvlEGPQSbMu9IYeO3Wr3fAm75GEtFWePY | ||
| 39 | BhM73I7gkRt4s8bUiUepMG/wY45c5tRF23xi8foReHFFe9MDzh8fJFECgYEA9EFX | ||
| 40 | 4qAik1pOJGNei9BMwmx0I0gfVEIgu0tzeVqT45vcxbxr7RkTEaDoAG6PlbWP6D9a | ||
| 41 | WQNLp4gsgRM90ZXOJ4up5DsAWDluvaF4/omabMA+MJJ5kGZ0gCj5rbZbKqUws7x8 | ||
| 42 | bp+6iBfUPJUbcqNqFmi/08Yt7vrDnMnyMw2A/sECgYEAiiuRMxnuzVm34hQcsbhH | ||
| 43 | 6ymVqf7j0PW2qK0F4H1ocT9qhzWFd+RB3kHWrCjnqODQoI6GbGr/4JepHUpre1ex | ||
| 44 | 4UEN5oSS3G0ru0rC3U4C59dZ5KwDHFm7ffZ1pr52ljfQDUsrjjIMRtuiwNK2OoRa | ||
| 45 | WSsqiaL+SDzSB+nBmpnAizECgYBdt/y6rerWUx4MhDwwtTnel7JwHyo2MDFS6/5g | ||
| 46 | n8qC2Lj6/fMDRE22w+CA2esp7EJNQJGv+b27iFpbJEDh+/Lf5YzIT4MwVskQ5bYB | ||
| 47 | JFcmRxUVmf4e09D7o705U/DjCgMH09iCsbLmqQ38ONIRSHZaJtMDtNTHD1yi+jF+ | ||
| 48 | OT43gQKBgQC/2OHZoko6iRlNOAQ/tMVFNq7fL81GivoQ9F1U0Qr+DH3ZfaH8eIkX | ||
| 49 | xT0ToMPJUzWAn8pZv0snA0um6SIgvkCuxO84OkANCVbttzXImIsL7pFzfcwV/ERK | ||
| 50 | UM6j0ZuSMFOCr/lGPAoOQU0fskidGEHi1/kW+suSr28TqsyYZpwBDQ== | ||
| 51 | -----END RSA PRIVATE KEY----- | ||
diff --git a/src/regress/lib/libssl/ciphers/Makefile b/src/regress/lib/libssl/ciphers/Makefile deleted file mode 100644 index c9a58a5e09..0000000000 --- a/src/regress/lib/libssl/ciphers/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2015/02/06 08:48:39 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= cipherstest | ||
| 4 | LDADD= -lssl -lcrypto | ||
| 5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/ciphers/cipherstest.c b/src/regress/lib/libssl/ciphers/cipherstest.c deleted file mode 100644 index d76fbfc8c0..0000000000 --- a/src/regress/lib/libssl/ciphers/cipherstest.c +++ /dev/null | |||
| @@ -1,175 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <openssl/ssl.h> | ||
| 18 | |||
| 19 | #include <err.h> | ||
| 20 | #include <stdio.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | static int | ||
| 24 | get_put_test(const char *name, const SSL_METHOD *method) | ||
| 25 | { | ||
| 26 | STACK_OF(SSL_CIPHER) *ciphers; | ||
| 27 | const SSL_CIPHER *cipher; | ||
| 28 | unsigned char buf[2]; | ||
| 29 | SSL_CTX *ssl_ctx = NULL; | ||
| 30 | SSL *ssl = NULL; | ||
| 31 | int ret = 1; | ||
| 32 | int i, len; | ||
| 33 | |||
| 34 | if ((len = method->put_cipher_by_char(NULL, NULL)) != 2) { | ||
| 35 | fprintf(stderr, | ||
| 36 | "%s: put_cipher_by_char() returned len %i (want 2)\n", | ||
| 37 | name, len); | ||
| 38 | return (1); | ||
| 39 | } | ||
| 40 | |||
| 41 | if ((ssl_ctx = SSL_CTX_new(method)) == NULL) { | ||
| 42 | fprintf(stderr, "%s: SSL_CTX_new() returned NULL\n", name); | ||
| 43 | goto failure; | ||
| 44 | } | ||
| 45 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 46 | fprintf(stderr, "%s: SSL_new() returned NULL\n", name); | ||
| 47 | goto failure; | ||
| 48 | } | ||
| 49 | |||
| 50 | if ((ciphers = SSL_get_ciphers(ssl)) == NULL) { | ||
| 51 | fprintf(stderr, "%s: no ciphers\n", name); | ||
| 52 | goto failure; | ||
| 53 | } | ||
| 54 | |||
| 55 | for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { | ||
| 56 | cipher = sk_SSL_CIPHER_value(ciphers, i); | ||
| 57 | if ((len = method->put_cipher_by_char(cipher, buf)) != 2) { | ||
| 58 | fprintf(stderr, | ||
| 59 | "%s: put_cipher_by_char() returned len %i for %s " | ||
| 60 | "(want 2)\n", | ||
| 61 | name, len, SSL_CIPHER_get_name(cipher)); | ||
| 62 | goto failure; | ||
| 63 | } | ||
| 64 | if ((cipher = method->get_cipher_by_char(buf)) == NULL) { | ||
| 65 | fprintf(stderr, | ||
| 66 | "%s: get_cipher_by_char() returned NULL for %s\n", | ||
| 67 | name, SSL_CIPHER_get_name(cipher)); | ||
| 68 | goto failure; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | ret = 0; | ||
| 73 | |||
| 74 | failure: | ||
| 75 | SSL_CTX_free(ssl_ctx); | ||
| 76 | SSL_free(ssl); | ||
| 77 | |||
| 78 | return (ret); | ||
| 79 | } | ||
| 80 | |||
| 81 | static int | ||
| 82 | cipher_get_put_tests(void) | ||
| 83 | { | ||
| 84 | int failed = 0; | ||
| 85 | |||
| 86 | failed |= get_put_test("SSLv23", SSLv23_method()); | ||
| 87 | failed |= get_put_test("SSLv23_client", SSLv23_client_method()); | ||
| 88 | failed |= get_put_test("SSLv23_server", SSLv23_server_method()); | ||
| 89 | |||
| 90 | failed |= get_put_test("TLSv1", TLSv1_method()); | ||
| 91 | failed |= get_put_test("TLSv1_client", TLSv1_client_method()); | ||
| 92 | failed |= get_put_test("TLSv1_server", TLSv1_server_method()); | ||
| 93 | |||
| 94 | failed |= get_put_test("TLSv1_1", TLSv1_1_method()); | ||
| 95 | failed |= get_put_test("TLSv1_1_client", TLSv1_1_client_method()); | ||
| 96 | failed |= get_put_test("TLSv1_1_server", TLSv1_1_server_method()); | ||
| 97 | |||
| 98 | failed |= get_put_test("TLSv1_2", TLSv1_2_method()); | ||
| 99 | failed |= get_put_test("TLSv1_2_client", TLSv1_2_client_method()); | ||
| 100 | failed |= get_put_test("TLSv1_2_server", TLSv1_2_server_method()); | ||
| 101 | |||
| 102 | failed |= get_put_test("DTLSv1", DTLSv1_method()); | ||
| 103 | failed |= get_put_test("DTLSv1_client", DTLSv1_client_method()); | ||
| 104 | failed |= get_put_test("DTLSv1_server", DTLSv1_server_method()); | ||
| 105 | |||
| 106 | return failed; | ||
| 107 | } | ||
| 108 | |||
| 109 | static int | ||
| 110 | cipher_get_by_value_tests(void) | ||
| 111 | { | ||
| 112 | STACK_OF(SSL_CIPHER) *ciphers; | ||
| 113 | const SSL_CIPHER *cipher; | ||
| 114 | SSL_CTX *ssl_ctx = NULL; | ||
| 115 | SSL *ssl = NULL; | ||
| 116 | unsigned long id; | ||
| 117 | uint16_t value; | ||
| 118 | int ret = 1; | ||
| 119 | int i; | ||
| 120 | |||
| 121 | if ((ssl_ctx = SSL_CTX_new(SSLv23_method())) == NULL) { | ||
| 122 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 123 | goto failure; | ||
| 124 | } | ||
| 125 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 126 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 127 | goto failure; | ||
| 128 | } | ||
| 129 | |||
| 130 | if ((ciphers = SSL_get_ciphers(ssl)) == NULL) { | ||
| 131 | fprintf(stderr, "no ciphers\n"); | ||
| 132 | goto failure; | ||
| 133 | } | ||
| 134 | |||
| 135 | for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { | ||
| 136 | cipher = sk_SSL_CIPHER_value(ciphers, i); | ||
| 137 | |||
| 138 | id = SSL_CIPHER_get_id(cipher); | ||
| 139 | if (SSL_CIPHER_get_by_id(id) == NULL) { | ||
| 140 | fprintf(stderr, "SSL_CIPHER_get_by_id() failed " | ||
| 141 | "for %s (0x%lx)\n", SSL_CIPHER_get_name(cipher), | ||
| 142 | id); | ||
| 143 | goto failure; | ||
| 144 | } | ||
| 145 | |||
| 146 | value = SSL_CIPHER_get_value(cipher); | ||
| 147 | if (SSL_CIPHER_get_by_value(value) == NULL) { | ||
| 148 | fprintf(stderr, "SSL_CIPHER_get_by_value() failed " | ||
| 149 | "for %s (0x%04hx)\n", SSL_CIPHER_get_name(cipher), | ||
| 150 | value); | ||
| 151 | goto failure; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | ret = 0; | ||
| 156 | |||
| 157 | failure: | ||
| 158 | SSL_CTX_free(ssl_ctx); | ||
| 159 | SSL_free(ssl); | ||
| 160 | |||
| 161 | return (ret); | ||
| 162 | } | ||
| 163 | |||
| 164 | int | ||
| 165 | main(int argc, char **argv) | ||
| 166 | { | ||
| 167 | int failed = 0; | ||
| 168 | |||
| 169 | SSL_library_init(); | ||
| 170 | |||
| 171 | failed |= cipher_get_put_tests(); | ||
| 172 | failed |= cipher_get_by_value_tests(); | ||
| 173 | |||
| 174 | return (failed); | ||
| 175 | } | ||
diff --git a/src/regress/lib/libssl/client/Makefile b/src/regress/lib/libssl/client/Makefile deleted file mode 100644 index 4f99f0e97c..0000000000 --- a/src/regress/lib/libssl/client/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2015/09/01 17:02:18 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= clienttest | ||
| 4 | LDADD= -lssl -lcrypto | ||
| 5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/client/clienttest.c b/src/regress/lib/libssl/client/clienttest.c deleted file mode 100644 index cb45dc583c..0000000000 --- a/src/regress/lib/libssl/client/clienttest.c +++ /dev/null | |||
| @@ -1,447 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <openssl/ssl.h> | ||
| 18 | |||
| 19 | #include <openssl/dtls1.h> | ||
| 20 | #include <openssl/ssl3.h> | ||
| 21 | |||
| 22 | #include <err.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | #define DTLS_HM_OFFSET (DTLS1_RT_HEADER_LENGTH + DTLS1_HM_HEADER_LENGTH) | ||
| 27 | #define DTLS_RANDOM_OFFSET (DTLS_HM_OFFSET + 2) | ||
| 28 | #define DTLS_CIPHER_OFFSET (DTLS_HM_OFFSET + 38) | ||
| 29 | |||
| 30 | #define SSL3_HM_OFFSET (SSL3_RT_HEADER_LENGTH + SSL3_HM_HEADER_LENGTH) | ||
| 31 | #define SSL3_RANDOM_OFFSET (SSL3_HM_OFFSET + 2) | ||
| 32 | #define SSL3_CIPHER_OFFSET (SSL3_HM_OFFSET + 37) | ||
| 33 | |||
| 34 | static unsigned char cipher_list_dtls1[] = { | ||
| 35 | 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, | ||
| 36 | 0x00, 0x88, 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, | ||
| 37 | 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, | ||
| 38 | 0x00, 0x2f, 0x00, 0x41, 0xc0, 0x12, 0xc0, 0x08, | ||
| 39 | 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, | ||
| 40 | }; | ||
| 41 | |||
| 42 | static unsigned char client_hello_dtls1[] = { | ||
| 43 | 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 44 | 0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, | ||
| 45 | 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 46 | 0x54, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0xc0, | ||
| 51 | 0x14, 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, 0x00, | ||
| 52 | 0x88, 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, 0xc0, | ||
| 53 | 0x13, 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, 0x00, | ||
| 54 | 0x2f, 0x00, 0x41, 0xc0, 0x12, 0xc0, 0x08, 0x00, | ||
| 55 | 0x16, 0x00, 0x0a, 0x00, 0xff, 0x01, 0x00, 0x00, | ||
| 56 | 0x04, 0x00, 0x23, 0x00, 0x00, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static unsigned char cipher_list_tls10[] = { | ||
| 60 | 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, | ||
| 61 | 0x00, 0x88, 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, | ||
| 62 | 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, | ||
| 63 | 0x00, 0x2f, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, | ||
| 64 | 0x00, 0x05, 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, | ||
| 65 | 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, | ||
| 66 | }; | ||
| 67 | |||
| 68 | static unsigned char client_hello_tls10[] = { | ||
| 69 | 0x16, 0x03, 0x01, 0x00, 0x71, 0x01, 0x00, 0x00, | ||
| 70 | 0x6d, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 71 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 72 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 73 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0xc0, 0x14, | ||
| 75 | 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, 0x00, 0x88, | ||
| 76 | 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, 0xc0, 0x13, | ||
| 77 | 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, 0x00, 0x2f, | ||
| 78 | 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, | ||
| 79 | 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, | ||
| 80 | 0x00, 0x0a, 0x00, 0xff, 0x01, 0x00, 0x00, 0x16, | ||
| 81 | 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, | ||
| 82 | 0x00, 0x08, 0x00, 0x06, 0x00, 0x1d, 0x00, 0x17, | ||
| 83 | 0x00, 0x18, 0x00, 0x23, 0x00, 0x00, | ||
| 84 | }; | ||
| 85 | |||
| 86 | static unsigned char cipher_list_tls11[] = { | ||
| 87 | 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, | ||
| 88 | 0x00, 0x88, 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, | ||
| 89 | 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, | ||
| 90 | 0x00, 0x2f, 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, | ||
| 91 | 0x00, 0x05, 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, | ||
| 92 | 0x00, 0x16, 0x00, 0x0a, 0x00, 0xff, | ||
| 93 | }; | ||
| 94 | |||
| 95 | static unsigned char client_hello_tls11[] = { | ||
| 96 | 0x16, 0x03, 0x01, 0x00, 0x71, 0x01, 0x00, 0x00, | ||
| 97 | 0x6d, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 98 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 99 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0xc0, 0x14, | ||
| 102 | 0xc0, 0x0a, 0x00, 0x39, 0xff, 0x85, 0x00, 0x88, | ||
| 103 | 0x00, 0x81, 0x00, 0x35, 0x00, 0x84, 0xc0, 0x13, | ||
| 104 | 0xc0, 0x09, 0x00, 0x33, 0x00, 0x45, 0x00, 0x2f, | ||
| 105 | 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, | ||
| 106 | 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, | ||
| 107 | 0x00, 0x0a, 0x00, 0xff, 0x01, 0x00, 0x00, 0x16, | ||
| 108 | 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, | ||
| 109 | 0x00, 0x08, 0x00, 0x06, 0x00, 0x1d, 0x00, 0x17, | ||
| 110 | 0x00, 0x18, 0x00, 0x23, 0x00, 0x00, | ||
| 111 | }; | ||
| 112 | |||
| 113 | static unsigned char cipher_list_tls12_aes[] = { | ||
| 114 | 0xc0, 0x30, 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, | ||
| 115 | 0xc0, 0x14, 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, | ||
| 116 | 0x00, 0x39, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, | ||
| 117 | 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, | ||
| 118 | 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, | ||
| 119 | 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, | ||
| 120 | 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, | ||
| 121 | 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, | ||
| 122 | 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, | ||
| 123 | 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, | ||
| 124 | 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, | ||
| 125 | 0x00, 0x0a, 0x00, 0xff, | ||
| 126 | }; | ||
| 127 | |||
| 128 | static unsigned char cipher_list_tls12_chacha[] = { | ||
| 129 | 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, | ||
| 130 | 0xc0, 0x2c, 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, | ||
| 131 | 0xc0, 0x0a, 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, | ||
| 132 | 0xff, 0x85, 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, | ||
| 133 | 0x00, 0x9d, 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, | ||
| 134 | 0x00, 0x84, 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, | ||
| 135 | 0xc0, 0x23, 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, | ||
| 136 | 0x00, 0x67, 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, | ||
| 137 | 0x00, 0x9c, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, | ||
| 138 | 0x00, 0x41, 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, | ||
| 139 | 0x00, 0x04, 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, | ||
| 140 | 0x00, 0x0a, 0x00, 0xff, | ||
| 141 | }; | ||
| 142 | |||
| 143 | static unsigned char client_hello_tls12[] = { | ||
| 144 | 0x16, 0x03, 0x01, 0x00, 0xbf, 0x01, 0x00, 0x00, | ||
| 145 | 0xbb, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 147 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 148 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 149 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0xcc, 0xa9, | ||
| 150 | 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x30, 0xc0, 0x2c, | ||
| 151 | 0xc0, 0x28, 0xc0, 0x24, 0xc0, 0x14, 0xc0, 0x0a, | ||
| 152 | 0x00, 0x9f, 0x00, 0x6b, 0x00, 0x39, 0xff, 0x85, | ||
| 153 | 0x00, 0xc4, 0x00, 0x88, 0x00, 0x81, 0x00, 0x9d, | ||
| 154 | 0x00, 0x3d, 0x00, 0x35, 0x00, 0xc0, 0x00, 0x84, | ||
| 155 | 0xc0, 0x2f, 0xc0, 0x2b, 0xc0, 0x27, 0xc0, 0x23, | ||
| 156 | 0xc0, 0x13, 0xc0, 0x09, 0x00, 0x9e, 0x00, 0x67, | ||
| 157 | 0x00, 0x33, 0x00, 0xbe, 0x00, 0x45, 0x00, 0x9c, | ||
| 158 | 0x00, 0x3c, 0x00, 0x2f, 0x00, 0xba, 0x00, 0x41, | ||
| 159 | 0xc0, 0x11, 0xc0, 0x07, 0x00, 0x05, 0x00, 0x04, | ||
| 160 | 0xc0, 0x12, 0xc0, 0x08, 0x00, 0x16, 0x00, 0x0a, | ||
| 161 | 0x00, 0xff, 0x01, 0x00, 0x00, 0x36, 0x00, 0x0b, | ||
| 162 | 0x00, 0x02, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, | ||
| 163 | 0x00, 0x06, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, | ||
| 164 | 0x00, 0x23, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x1c, | ||
| 165 | 0x00, 0x1a, 0x06, 0x01, 0x06, 0x03, 0xef, 0xef, | ||
| 166 | 0x05, 0x01, 0x05, 0x03, 0x04, 0x01, 0x04, 0x03, | ||
| 167 | 0xee, 0xee, 0xed, 0xed, 0x03, 0x01, 0x03, 0x03, | ||
| 168 | 0x02, 0x01, 0x02, 0x03, | ||
| 169 | }; | ||
| 170 | |||
| 171 | struct client_hello_test { | ||
| 172 | const unsigned char *desc; | ||
| 173 | const int protocol; | ||
| 174 | const size_t random_start; | ||
| 175 | const SSL_METHOD *(*ssl_method)(void); | ||
| 176 | const long ssl_options; | ||
| 177 | }; | ||
| 178 | |||
| 179 | static struct client_hello_test client_hello_tests[] = { | ||
| 180 | { | ||
| 181 | .desc = "DTLSv1 client", | ||
| 182 | .protocol = DTLS1_VERSION, | ||
| 183 | .random_start = DTLS_RANDOM_OFFSET, | ||
| 184 | .ssl_method = DTLSv1_client_method, | ||
| 185 | }, | ||
| 186 | { | ||
| 187 | .desc = "TLSv1 client", | ||
| 188 | .protocol = TLS1_VERSION, | ||
| 189 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 190 | .ssl_method = TLSv1_client_method, | ||
| 191 | }, | ||
| 192 | { | ||
| 193 | .desc = "TLSv1_1 client", | ||
| 194 | .protocol = TLS1_1_VERSION, | ||
| 195 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 196 | .ssl_method = TLSv1_1_client_method, | ||
| 197 | }, | ||
| 198 | { | ||
| 199 | .desc = "TLSv1_2 client", | ||
| 200 | .protocol = TLS1_2_VERSION, | ||
| 201 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 202 | .ssl_method = TLSv1_2_client_method, | ||
| 203 | }, | ||
| 204 | { | ||
| 205 | .desc = "SSLv23 default", | ||
| 206 | .protocol = TLS1_2_VERSION, | ||
| 207 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 208 | .ssl_method = SSLv23_client_method, | ||
| 209 | .ssl_options = 0, | ||
| 210 | }, | ||
| 211 | { | ||
| 212 | .desc = "SSLv23 (no TLSv1.2)", | ||
| 213 | .protocol = TLS1_1_VERSION, | ||
| 214 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 215 | .ssl_method = SSLv23_client_method, | ||
| 216 | .ssl_options = SSL_OP_NO_TLSv1_2, | ||
| 217 | }, | ||
| 218 | { | ||
| 219 | .desc = "SSLv23 (no TLSv1.1)", | ||
| 220 | .protocol = TLS1_VERSION, | ||
| 221 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 222 | .ssl_method = SSLv23_client_method, | ||
| 223 | .ssl_options = SSL_OP_NO_TLSv1_1, | ||
| 224 | }, | ||
| 225 | { | ||
| 226 | .desc = "TLS default", | ||
| 227 | .protocol = TLS1_2_VERSION, | ||
| 228 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 229 | .ssl_method = TLS_client_method, | ||
| 230 | .ssl_options = 0, | ||
| 231 | }, | ||
| 232 | { | ||
| 233 | .desc = "TLS (no TLSv1.2)", | ||
| 234 | .protocol = TLS1_1_VERSION, | ||
| 235 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 236 | .ssl_method = TLS_client_method, | ||
| 237 | .ssl_options = SSL_OP_NO_TLSv1_2, | ||
| 238 | }, | ||
| 239 | { | ||
| 240 | .desc = "TLS (no TLSv1.1)", | ||
| 241 | .protocol = TLS1_VERSION, | ||
| 242 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 243 | .ssl_method = TLS_client_method, | ||
| 244 | .ssl_options = SSL_OP_NO_TLSv1_1, | ||
| 245 | }, | ||
| 246 | { | ||
| 247 | .desc = "TLS (no TLSv1.0, no TLSv1.1)", | ||
| 248 | .protocol = TLS1_2_VERSION, | ||
| 249 | .random_start = SSL3_RANDOM_OFFSET, | ||
| 250 | .ssl_method = TLS_client_method, | ||
| 251 | .ssl_options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1, | ||
| 252 | }, | ||
| 253 | }; | ||
| 254 | |||
| 255 | #define N_CLIENT_HELLO_TESTS \ | ||
| 256 | (sizeof(client_hello_tests) / sizeof(*client_hello_tests)) | ||
| 257 | |||
| 258 | static void | ||
| 259 | hexdump(const unsigned char *buf, size_t len) | ||
| 260 | { | ||
| 261 | size_t i; | ||
| 262 | |||
| 263 | for (i = 1; i <= len; i++) | ||
| 264 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 265 | |||
| 266 | fprintf(stderr, "\n"); | ||
| 267 | } | ||
| 268 | |||
| 269 | static inline int | ||
| 270 | ssl_aes_is_accelerated(void) | ||
| 271 | { | ||
| 272 | #if defined(__i386__) || defined(__x86_64__) | ||
| 273 | return ((OPENSSL_cpu_caps() & (1ULL << 57)) != 0); | ||
| 274 | #else | ||
| 275 | return (0); | ||
| 276 | #endif | ||
| 277 | } | ||
| 278 | |||
| 279 | static int | ||
| 280 | make_client_hello(int protocol, char **out, size_t *outlen) | ||
| 281 | { | ||
| 282 | size_t client_hello_len, cipher_list_len, cipher_list_offset; | ||
| 283 | const char *client_hello, *cipher_list; | ||
| 284 | char *p; | ||
| 285 | |||
| 286 | *out = NULL; | ||
| 287 | *outlen = 0; | ||
| 288 | |||
| 289 | switch (protocol) { | ||
| 290 | case DTLS1_VERSION: | ||
| 291 | client_hello = client_hello_dtls1; | ||
| 292 | client_hello_len = sizeof(client_hello_dtls1); | ||
| 293 | cipher_list = cipher_list_dtls1; | ||
| 294 | cipher_list_len = sizeof(cipher_list_dtls1); | ||
| 295 | cipher_list_offset = DTLS_CIPHER_OFFSET; | ||
| 296 | break; | ||
| 297 | |||
| 298 | case TLS1_VERSION: | ||
| 299 | client_hello = client_hello_tls10; | ||
| 300 | client_hello_len = sizeof(client_hello_tls10); | ||
| 301 | cipher_list = cipher_list_tls10; | ||
| 302 | cipher_list_len = sizeof(cipher_list_tls10); | ||
| 303 | cipher_list_offset = SSL3_CIPHER_OFFSET; | ||
| 304 | break; | ||
| 305 | |||
| 306 | case TLS1_1_VERSION: | ||
| 307 | client_hello = client_hello_tls11; | ||
| 308 | client_hello_len = sizeof(client_hello_tls11); | ||
| 309 | cipher_list = cipher_list_tls11; | ||
| 310 | cipher_list_len = sizeof(cipher_list_tls11); | ||
| 311 | cipher_list_offset = SSL3_CIPHER_OFFSET; | ||
| 312 | break; | ||
| 313 | |||
| 314 | case TLS1_2_VERSION: | ||
| 315 | client_hello = client_hello_tls12; | ||
| 316 | client_hello_len = sizeof(client_hello_tls12); | ||
| 317 | if (ssl_aes_is_accelerated() == 1) | ||
| 318 | cipher_list = cipher_list_tls12_aes; | ||
| 319 | else | ||
| 320 | cipher_list = cipher_list_tls12_chacha; | ||
| 321 | cipher_list_len = sizeof(cipher_list_tls12_chacha); | ||
| 322 | cipher_list_offset = SSL3_CIPHER_OFFSET; | ||
| 323 | break; | ||
| 324 | |||
| 325 | default: | ||
| 326 | return (-1); | ||
| 327 | } | ||
| 328 | |||
| 329 | if ((p = malloc(client_hello_len)) == NULL) | ||
| 330 | return (-1); | ||
| 331 | |||
| 332 | memcpy(p, client_hello, client_hello_len); | ||
| 333 | memcpy(p + cipher_list_offset, cipher_list, cipher_list_len); | ||
| 334 | |||
| 335 | *out = p; | ||
| 336 | *outlen = client_hello_len; | ||
| 337 | |||
| 338 | return (0); | ||
| 339 | } | ||
| 340 | |||
| 341 | static int | ||
| 342 | client_hello_test(int testno, struct client_hello_test *cht) | ||
| 343 | { | ||
| 344 | BIO *rbio = NULL, *wbio = NULL; | ||
| 345 | SSL_CTX *ssl_ctx = NULL; | ||
| 346 | SSL *ssl = NULL; | ||
| 347 | char *client_hello = NULL; | ||
| 348 | size_t client_hello_len; | ||
| 349 | char *wbuf, rbuf[1]; | ||
| 350 | int ret = 1; | ||
| 351 | size_t i; | ||
| 352 | long len; | ||
| 353 | |||
| 354 | fprintf(stderr, "Test %i - %s\n", testno, cht->desc); | ||
| 355 | |||
| 356 | /* Providing a small buf causes *_get_server_hello() to return. */ | ||
| 357 | if ((rbio = BIO_new_mem_buf(rbuf, sizeof(rbuf))) == NULL) { | ||
| 358 | fprintf(stderr, "Failed to setup rbio\n"); | ||
| 359 | goto failure; | ||
| 360 | } | ||
| 361 | if ((wbio = BIO_new(BIO_s_mem())) == NULL) { | ||
| 362 | fprintf(stderr, "Failed to setup wbio\n"); | ||
| 363 | goto failure; | ||
| 364 | } | ||
| 365 | |||
| 366 | if ((ssl_ctx = SSL_CTX_new(cht->ssl_method())) == NULL) { | ||
| 367 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 368 | goto failure; | ||
| 369 | } | ||
| 370 | |||
| 371 | SSL_CTX_set_options(ssl_ctx, cht->ssl_options); | ||
| 372 | |||
| 373 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 374 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 375 | goto failure; | ||
| 376 | } | ||
| 377 | |||
| 378 | rbio->references = 2; | ||
| 379 | wbio->references = 2; | ||
| 380 | |||
| 381 | SSL_set_bio(ssl, rbio, wbio); | ||
| 382 | |||
| 383 | if (SSL_connect(ssl) != 0) { | ||
| 384 | fprintf(stderr, "SSL_connect() returned non-zero\n"); | ||
| 385 | goto failure; | ||
| 386 | } | ||
| 387 | |||
| 388 | len = BIO_get_mem_data(wbio, &wbuf); | ||
| 389 | |||
| 390 | if (make_client_hello(cht->protocol, &client_hello, | ||
| 391 | &client_hello_len) != 0) | ||
| 392 | goto failure; | ||
| 393 | |||
| 394 | if ((size_t)len != client_hello_len) { | ||
| 395 | fprintf(stderr, "FAIL: test returned ClientHello length %li, " | ||
| 396 | "want %zu\n", len, client_hello_len); | ||
| 397 | fprintf(stderr, "received:\n"); | ||
| 398 | hexdump(wbuf, len); | ||
| 399 | goto failure; | ||
| 400 | } | ||
| 401 | |||
| 402 | /* We expect the client random to differ. */ | ||
| 403 | i = cht->random_start + SSL3_RANDOM_SIZE; | ||
| 404 | if (memcmp(client_hello, wbuf, cht->random_start) != 0 || | ||
| 405 | memcmp(&client_hello[cht->random_start], | ||
| 406 | &wbuf[cht->random_start], SSL3_RANDOM_SIZE) == 0 || | ||
| 407 | memcmp(&client_hello[i], &wbuf[i], len - i) != 0) { | ||
| 408 | fprintf(stderr, "FAIL: ClientHello differs:\n"); | ||
| 409 | fprintf(stderr, "received:\n"); | ||
| 410 | memset(&wbuf[cht->random_start], 0, SSL3_RANDOM_SIZE); | ||
| 411 | hexdump(wbuf, len); | ||
| 412 | fprintf(stderr, "test data:\n"); | ||
| 413 | hexdump(client_hello, client_hello_len); | ||
| 414 | fprintf(stderr, "\n"); | ||
| 415 | goto failure; | ||
| 416 | } | ||
| 417 | |||
| 418 | ret = 0; | ||
| 419 | |||
| 420 | failure: | ||
| 421 | SSL_CTX_free(ssl_ctx); | ||
| 422 | SSL_free(ssl); | ||
| 423 | |||
| 424 | rbio->references = 1; | ||
| 425 | wbio->references = 1; | ||
| 426 | |||
| 427 | BIO_free(rbio); | ||
| 428 | BIO_free(wbio); | ||
| 429 | |||
| 430 | free(client_hello); | ||
| 431 | |||
| 432 | return (ret); | ||
| 433 | } | ||
| 434 | |||
| 435 | int | ||
| 436 | main(int argc, char **argv) | ||
| 437 | { | ||
| 438 | int failed = 0; | ||
| 439 | size_t i; | ||
| 440 | |||
| 441 | SSL_library_init(); | ||
| 442 | |||
| 443 | for (i = 0; i < N_CLIENT_HELLO_TESTS; i++) | ||
| 444 | failed |= client_hello_test(i, &client_hello_tests[i]); | ||
| 445 | |||
| 446 | return (failed); | ||
| 447 | } | ||
diff --git a/src/regress/lib/libssl/pqueue/Makefile b/src/regress/lib/libssl/pqueue/Makefile deleted file mode 100644 index 48c2cb7e61..0000000000 --- a/src/regress/lib/libssl/pqueue/Makefile +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2016/11/04 19:45:12 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= pq_test | ||
| 4 | SRC= ${.CURDIR}/../../../../lib/libssl | ||
| 5 | CFLAGS+= -I${SRC} | ||
| 6 | |||
| 7 | LDADD= ${SSL_INT} -lcrypto | ||
| 8 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
| 9 | WARNINGS= Yes | ||
| 10 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 11 | |||
| 12 | REGRESS_TARGETS= regress-pq_test | ||
| 13 | |||
| 14 | regress-pq_test: ${PROG} | ||
| 15 | ${.OBJDIR}/pq_test | cmp -s ${.CURDIR}/expected.txt /dev/stdin | ||
| 16 | |||
| 17 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/pqueue/expected.txt b/src/regress/lib/libssl/pqueue/expected.txt deleted file mode 100644 index c59d6cd838..0000000000 --- a/src/regress/lib/libssl/pqueue/expected.txt +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | item 6966726167696c69 | ||
| 2 | item 7374696365787069 | ||
| 3 | item 737570657263616c | ||
diff --git a/src/regress/lib/libssl/pqueue/pq_test.c b/src/regress/lib/libssl/pqueue/pq_test.c deleted file mode 100644 index a078ba5366..0000000000 --- a/src/regress/lib/libssl/pqueue/pq_test.c +++ /dev/null | |||
| @@ -1,118 +0,0 @@ | |||
| 1 | /* crypto/pqueue/pq_test.c */ | ||
| 2 | /* | ||
| 3 | * DTLS implementation written by Nagendra Modadugu | ||
| 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | ||
| 5 | */ | ||
| 6 | /* ==================================================================== | ||
| 7 | * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. | ||
| 8 | * | ||
| 9 | * Redistribution and use in source and binary forms, with or without | ||
| 10 | * modification, are permitted provided that the following conditions | ||
| 11 | * are met: | ||
| 12 | * | ||
| 13 | * 1. Redistributions of source code must retain the above copyright | ||
| 14 | * notice, this list of conditions and the following disclaimer. | ||
| 15 | * | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in | ||
| 18 | * the documentation and/or other materials provided with the | ||
| 19 | * distribution. | ||
| 20 | * | ||
| 21 | * 3. All advertising materials mentioning features or use of this | ||
| 22 | * software must display the following acknowledgment: | ||
| 23 | * "This product includes software developed by the OpenSSL Project | ||
| 24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 25 | * | ||
| 26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 27 | * endorse or promote products derived from this software without | ||
| 28 | * prior written permission. For written permission, please contact | ||
| 29 | * openssl-core@OpenSSL.org. | ||
| 30 | * | ||
| 31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 32 | * nor may "OpenSSL" appear in their names without prior written | ||
| 33 | * permission of the OpenSSL Project. | ||
| 34 | * | ||
| 35 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 36 | * acknowledgment: | ||
| 37 | * "This product includes software developed by the OpenSSL Project | ||
| 38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 39 | * | ||
| 40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 52 | * ==================================================================== | ||
| 53 | * | ||
| 54 | * This product includes cryptographic software written by Eric Young | ||
| 55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 56 | * Hudson (tjh@cryptsoft.com). | ||
| 57 | * | ||
| 58 | */ | ||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "pqueue.h" | ||
| 63 | |||
| 64 | /* remember to change expected.txt if you change these values */ | ||
| 65 | unsigned char prio1[8] = "supercal"; | ||
| 66 | unsigned char prio2[8] = "ifragili"; | ||
| 67 | unsigned char prio3[8] = "sticexpi"; | ||
| 68 | |||
| 69 | static void | ||
| 70 | pqueue_print(pqueue pq) | ||
| 71 | { | ||
| 72 | pitem *iter, *item; | ||
| 73 | |||
| 74 | iter = pqueue_iterator(pq); | ||
| 75 | for (item = pqueue_next(&iter); item != NULL; | ||
| 76 | item = pqueue_next(&iter)) { | ||
| 77 | printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", | ||
| 78 | item->priority[0], item->priority[1], | ||
| 79 | item->priority[2], item->priority[3], | ||
| 80 | item->priority[4], item->priority[5], | ||
| 81 | item->priority[6], item->priority[7]); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | main(void) | ||
| 87 | { | ||
| 88 | pitem *item; | ||
| 89 | pqueue pq; | ||
| 90 | |||
| 91 | pq = pqueue_new(); | ||
| 92 | |||
| 93 | item = pitem_new(prio3, NULL); | ||
| 94 | pqueue_insert(pq, item); | ||
| 95 | |||
| 96 | item = pitem_new(prio1, NULL); | ||
| 97 | pqueue_insert(pq, item); | ||
| 98 | |||
| 99 | item = pitem_new(prio2, NULL); | ||
| 100 | pqueue_insert(pq, item); | ||
| 101 | |||
| 102 | item = pqueue_find(pq, prio1); | ||
| 103 | fprintf(stderr, "found %p\n", item->priority); | ||
| 104 | |||
| 105 | item = pqueue_find(pq, prio2); | ||
| 106 | fprintf(stderr, "found %p\n", item->priority); | ||
| 107 | |||
| 108 | item = pqueue_find(pq, prio3); | ||
| 109 | fprintf(stderr, "found %p\n", item ? item->priority: 0); | ||
| 110 | |||
| 111 | pqueue_print(pq); | ||
| 112 | |||
| 113 | for (item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq)) | ||
| 114 | pitem_free(item); | ||
| 115 | |||
| 116 | pqueue_free(pq); | ||
| 117 | return 0; | ||
| 118 | } | ||
diff --git a/src/regress/lib/libssl/server/Makefile b/src/regress/lib/libssl/server/Makefile deleted file mode 100644 index 705190d076..0000000000 --- a/src/regress/lib/libssl/server/Makefile +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/03/05 14:15:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= servertest | ||
| 4 | LDADD= -lssl -lcrypto | ||
| 5 | DPADD= ${LIBSSL} ${LIBCRYPTO} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS= \ | ||
| 10 | regress-servertest | ||
| 11 | |||
| 12 | regress-servertest: ${PROG} | ||
| 13 | ./servertest \ | ||
| 14 | ${.CURDIR}/../../libssl/certs/server.pem \ | ||
| 15 | ${.CURDIR}/../../libssl/certs/server.pem \ | ||
| 16 | ${.CURDIR}/../../libssl/certs/ca.pem | ||
| 17 | |||
| 18 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/server/servertest.c b/src/regress/lib/libssl/server/servertest.c deleted file mode 100644 index 32578599e5..0000000000 --- a/src/regress/lib/libssl/server/servertest.c +++ /dev/null | |||
| @@ -1,200 +0,0 @@ | |||
| 1 | /* $OpenBSD: servertest.c,v 1.1 2017/03/05 14:15:53 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015, 2016, 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <openssl/ssl.h> | ||
| 19 | |||
| 20 | #include <openssl/err.h> | ||
| 21 | #include <openssl/dtls1.h> | ||
| 22 | #include <openssl/ssl3.h> | ||
| 23 | |||
| 24 | #include <err.h> | ||
| 25 | #include <stdio.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | char *server_ca_file; | ||
| 29 | char *server_cert_file; | ||
| 30 | char *server_key_file; | ||
| 31 | |||
| 32 | static unsigned char sslv2_client_hello_tls10[] = { | ||
| 33 | 0x80, 0x6a, 0x01, 0x03, 0x01, 0x00, 0x51, 0x00, | ||
| 34 | 0x00, 0x00, 0x10, 0x00, 0x00, 0x39, 0x00, 0x00, | ||
| 35 | 0x38, 0x00, 0x00, 0x35, 0x00, 0x00, 0x16, 0x00, | ||
| 36 | 0x00, 0x13, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x33, | ||
| 37 | 0x00, 0x00, 0x32, 0x00, 0x00, 0x2f, 0x00, 0x00, | ||
| 38 | 0x07, 0x00, 0x00, 0x66, 0x00, 0x00, 0x05, 0x00, | ||
| 39 | 0x00, 0x04, 0x00, 0x00, 0x63, 0x00, 0x00, 0x62, | ||
| 40 | 0x00, 0x00, 0x61, 0x00, 0x00, 0x15, 0x00, 0x00, | ||
| 41 | 0x12, 0x00, 0x00, 0x09, 0x00, 0x00, 0x65, 0x00, | ||
| 42 | 0x00, 0x64, 0x00, 0x00, 0x60, 0x00, 0x00, 0x14, | ||
| 43 | 0x00, 0x00, 0x11, 0x00, 0x00, 0x08, 0x00, 0x00, | ||
| 44 | 0x06, 0x00, 0x00, 0x03, 0xdd, 0xb6, 0x59, 0x26, | ||
| 45 | 0x46, 0xe6, 0x79, 0x77, 0xf4, 0xec, 0x42, 0x76, | ||
| 46 | 0xc8, 0x73, 0xad, 0x9c, | ||
| 47 | }; | ||
| 48 | |||
| 49 | static unsigned char sslv2_client_hello_tls12[] = { | ||
| 50 | 0x80, 0xcb, 0x01, 0x03, 0x03, 0x00, 0xa2, 0x00, | ||
| 51 | 0x00, 0x00, 0x20, 0x00, 0x00, 0xa5, 0x00, 0x00, | ||
| 52 | 0xa3, 0x00, 0x00, 0xa1, 0x00, 0x00, 0x9f, 0x00, | ||
| 53 | 0x00, 0x6b, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x69, | ||
| 54 | 0x00, 0x00, 0x68, 0x00, 0x00, 0x39, 0x00, 0x00, | ||
| 55 | 0x38, 0x00, 0x00, 0x37, 0x00, 0x00, 0x36, 0x00, | ||
| 56 | 0x00, 0x88, 0x00, 0x00, 0x87, 0x00, 0x00, 0x86, | ||
| 57 | 0x00, 0x00, 0x85, 0x00, 0x00, 0x9d, 0x00, 0x00, | ||
| 58 | 0x3d, 0x00, 0x00, 0x35, 0x00, 0x00, 0x84, 0x00, | ||
| 59 | 0x00, 0xa4, 0x00, 0x00, 0xa2, 0x00, 0x00, 0xa0, | ||
| 60 | 0x00, 0x00, 0x9e, 0x00, 0x00, 0x67, 0x00, 0x00, | ||
| 61 | 0x40, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x3e, 0x00, | ||
| 62 | 0x00, 0x33, 0x00, 0x00, 0x32, 0x00, 0x00, 0x31, | ||
| 63 | 0x00, 0x00, 0x30, 0x00, 0x00, 0x9a, 0x00, 0x00, | ||
| 64 | 0x99, 0x00, 0x00, 0x98, 0x00, 0x00, 0x97, 0x00, | ||
| 65 | 0x00, 0x45, 0x00, 0x00, 0x44, 0x00, 0x00, 0x43, | ||
| 66 | 0x00, 0x00, 0x42, 0x00, 0x00, 0x9c, 0x00, 0x00, | ||
| 67 | 0x3c, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x96, 0x00, | ||
| 68 | 0x00, 0x41, 0x00, 0x00, 0x07, 0x00, 0x00, 0x05, | ||
| 69 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x16, 0x00, 0x00, | ||
| 70 | 0x13, 0x00, 0x00, 0x10, 0x00, 0x00, 0x0d, 0x00, | ||
| 71 | 0x00, 0x0a, 0x00, 0x00, 0xff, 0x1d, 0xfd, 0x90, | ||
| 72 | 0x03, 0x61, 0x3c, 0x5a, 0x22, 0x83, 0xed, 0x11, | ||
| 73 | 0x85, 0xf4, 0xea, 0x36, 0x59, 0xd9, 0x1b, 0x27, | ||
| 74 | 0x22, 0x01, 0x14, 0x07, 0x66, 0xb2, 0x24, 0xf5, | ||
| 75 | 0x4e, 0x7d, 0x9d, 0x9c, 0x52, | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct server_hello_test { | ||
| 79 | const unsigned char *desc; | ||
| 80 | unsigned char *client_hello; | ||
| 81 | const size_t client_hello_len; | ||
| 82 | const SSL_METHOD *(*ssl_method)(void); | ||
| 83 | const long ssl_options; | ||
| 84 | }; | ||
| 85 | |||
| 86 | static struct server_hello_test server_hello_tests[] = { | ||
| 87 | { | ||
| 88 | .desc = "TLSv1.0 in SSLv2 record", | ||
| 89 | .client_hello = sslv2_client_hello_tls10, | ||
| 90 | .client_hello_len = sizeof(sslv2_client_hello_tls10), | ||
| 91 | .ssl_method = TLS_server_method, | ||
| 92 | .ssl_options = 0, | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | .desc = "TLSv1.2 in SSLv2 record", | ||
| 96 | .client_hello = sslv2_client_hello_tls12, | ||
| 97 | .client_hello_len = sizeof(sslv2_client_hello_tls12), | ||
| 98 | .ssl_method = TLS_server_method, | ||
| 99 | .ssl_options = 0, | ||
| 100 | }, | ||
| 101 | }; | ||
| 102 | |||
| 103 | #define N_SERVER_HELLO_TESTS \ | ||
| 104 | (sizeof(server_hello_tests) / sizeof(*server_hello_tests)) | ||
| 105 | |||
| 106 | static int | ||
| 107 | server_hello_test(int testno, struct server_hello_test *sht) | ||
| 108 | { | ||
| 109 | BIO *rbio = NULL, *wbio = NULL; | ||
| 110 | SSL_CTX *ssl_ctx = NULL; | ||
| 111 | SSL *ssl = NULL; | ||
| 112 | int ret = 1; | ||
| 113 | |||
| 114 | fprintf(stderr, "Test %i - %s\n", testno, sht->desc); | ||
| 115 | |||
| 116 | if ((rbio = BIO_new_mem_buf(sht->client_hello, | ||
| 117 | sht->client_hello_len)) == NULL) { | ||
| 118 | fprintf(stderr, "Failed to setup rbio\n"); | ||
| 119 | goto failure; | ||
| 120 | } | ||
| 121 | if ((wbio = BIO_new(BIO_s_mem())) == NULL) { | ||
| 122 | fprintf(stderr, "Failed to setup wbio\n"); | ||
| 123 | goto failure; | ||
| 124 | } | ||
| 125 | |||
| 126 | if ((ssl_ctx = SSL_CTX_new(sht->ssl_method())) == NULL) { | ||
| 127 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 128 | goto failure; | ||
| 129 | } | ||
| 130 | |||
| 131 | if (SSL_CTX_use_certificate_file(ssl_ctx, server_cert_file, | ||
| 132 | SSL_FILETYPE_PEM) != 1) { | ||
| 133 | fprintf(stderr, "Failed to load server certificate"); | ||
| 134 | goto failure; | ||
| 135 | } | ||
| 136 | if (SSL_CTX_use_PrivateKey_file(ssl_ctx, server_key_file, | ||
| 137 | SSL_FILETYPE_PEM) != 1) { | ||
| 138 | fprintf(stderr, "Failed to load server private key"); | ||
| 139 | goto failure; | ||
| 140 | } | ||
| 141 | |||
| 142 | SSL_CTX_set_dh_auto(ssl_ctx, 1); | ||
| 143 | SSL_CTX_set_ecdh_auto(ssl_ctx, 1); | ||
| 144 | SSL_CTX_set_options(ssl_ctx, sht->ssl_options); | ||
| 145 | |||
| 146 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 147 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 148 | goto failure; | ||
| 149 | } | ||
| 150 | |||
| 151 | rbio->references = 2; | ||
| 152 | wbio->references = 2; | ||
| 153 | |||
| 154 | SSL_set_bio(ssl, rbio, wbio); | ||
| 155 | |||
| 156 | if (SSL_accept(ssl) != 0) { | ||
| 157 | fprintf(stderr, "SSL_accept() returned non-zero\n"); | ||
| 158 | ERR_print_errors_fp(stderr); | ||
| 159 | goto failure; | ||
| 160 | } | ||
| 161 | |||
| 162 | ret = 0; | ||
| 163 | |||
| 164 | failure: | ||
| 165 | SSL_CTX_free(ssl_ctx); | ||
| 166 | SSL_free(ssl); | ||
| 167 | |||
| 168 | rbio->references = 1; | ||
| 169 | wbio->references = 1; | ||
| 170 | |||
| 171 | BIO_free(rbio); | ||
| 172 | BIO_free(wbio); | ||
| 173 | |||
| 174 | return (ret); | ||
| 175 | } | ||
| 176 | |||
| 177 | int | ||
| 178 | main(int argc, char **argv) | ||
| 179 | { | ||
| 180 | int failed = 0; | ||
| 181 | size_t i; | ||
| 182 | |||
| 183 | if (argc != 4) { | ||
| 184 | fprintf(stderr, "usage: %s keyfile certfile cafile\n", | ||
| 185 | argv[0]); | ||
| 186 | exit(1); | ||
| 187 | } | ||
| 188 | |||
| 189 | server_key_file = argv[1]; | ||
| 190 | server_cert_file = argv[2]; | ||
| 191 | server_ca_file = argv[3]; | ||
| 192 | |||
| 193 | SSL_library_init(); | ||
| 194 | SSL_load_error_strings(); | ||
| 195 | |||
| 196 | for (i = 0; i < N_SERVER_HELLO_TESTS; i++) | ||
| 197 | failed |= server_hello_test(i, &server_hello_tests[i]); | ||
| 198 | |||
| 199 | return (failed); | ||
| 200 | } | ||
diff --git a/src/regress/lib/libssl/ssl/Makefile b/src/regress/lib/libssl/ssl/Makefile deleted file mode 100644 index 581341c310..0000000000 --- a/src/regress/lib/libssl/ssl/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2014/07/08 15:53:53 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= ssltest | ||
| 4 | LDADD= -lcrypto -lssl | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | ||
| 8 | |||
| 9 | REGRESS_TARGETS=regress-ssltest | ||
| 10 | |||
| 11 | regress-ssltest: ${PROG} | ||
| 12 | sh ${.CURDIR}/testssl \ | ||
| 13 | ${.CURDIR}/../certs/server.pem ${.CURDIR}/../certs/server.pem \ | ||
| 14 | ${.CURDIR}/../certs/ca.pem | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/ssl/ssltest.c b/src/regress/lib/libssl/ssl/ssltest.c deleted file mode 100644 index 7137d0c407..0000000000 --- a/src/regress/lib/libssl/ssl/ssltest.c +++ /dev/null | |||
| @@ -1,2044 +0,0 @@ | |||
| 1 | /* ssl/ssltest.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
| 60 | * | ||
| 61 | * Redistribution and use in source and binary forms, with or without | ||
| 62 | * modification, are permitted provided that the following conditions | ||
| 63 | * are met: | ||
| 64 | * | ||
| 65 | * 1. Redistributions of source code must retain the above copyright | ||
| 66 | * notice, this list of conditions and the following disclaimer. | ||
| 67 | * | ||
| 68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 69 | * notice, this list of conditions and the following disclaimer in | ||
| 70 | * the documentation and/or other materials provided with the | ||
| 71 | * distribution. | ||
| 72 | * | ||
| 73 | * 3. All advertising materials mentioning features or use of this | ||
| 74 | * software must display the following acknowledgment: | ||
| 75 | * "This product includes software developed by the OpenSSL Project | ||
| 76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 77 | * | ||
| 78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 79 | * endorse or promote products derived from this software without | ||
| 80 | * prior written permission. For written permission, please contact | ||
| 81 | * openssl-core@openssl.org. | ||
| 82 | * | ||
| 83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 84 | * nor may "OpenSSL" appear in their names without prior written | ||
| 85 | * permission of the OpenSSL Project. | ||
| 86 | * | ||
| 87 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 88 | * acknowledgment: | ||
| 89 | * "This product includes software developed by the OpenSSL Project | ||
| 90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 91 | * | ||
| 92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 104 | * ==================================================================== | ||
| 105 | * | ||
| 106 | * This product includes cryptographic software written by Eric Young | ||
| 107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 108 | * Hudson (tjh@cryptsoft.com). | ||
| 109 | * | ||
| 110 | */ | ||
| 111 | /* ==================================================================== | ||
| 112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 113 | * ECC cipher suite support in OpenSSL originally developed by | ||
| 114 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 115 | */ | ||
| 116 | /* ==================================================================== | ||
| 117 | * Copyright 2005 Nokia. All rights reserved. | ||
| 118 | * | ||
| 119 | * The portions of the attached software ("Contribution") is developed by | ||
| 120 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source | ||
| 121 | * license. | ||
| 122 | * | ||
| 123 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of | ||
| 124 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites | ||
| 125 | * support (see RFC 4279) to OpenSSL. | ||
| 126 | * | ||
| 127 | * No patent licenses or other rights except those expressly stated in | ||
| 128 | * the OpenSSL open source license shall be deemed granted or received | ||
| 129 | * expressly, by implication, estoppel, or otherwise. | ||
| 130 | * | ||
| 131 | * No assurances are provided by Nokia that the Contribution does not | ||
| 132 | * infringe the patent or other intellectual property rights of any third | ||
| 133 | * party or that the license provides you with all the necessary rights | ||
| 134 | * to make use of the Contribution. | ||
| 135 | * | ||
| 136 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN | ||
| 137 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA | ||
| 138 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY | ||
| 139 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR | ||
| 140 | * OTHERWISE. | ||
| 141 | */ | ||
| 142 | |||
| 143 | #define _BSD_SOURCE 1 /* Or gethostname won't be declared properly | ||
| 144 | on Linux and GNU platforms. */ | ||
| 145 | #include <sys/types.h> | ||
| 146 | #include <sys/param.h> | ||
| 147 | #include <sys/socket.h> | ||
| 148 | |||
| 149 | #include <netinet/in.h> | ||
| 150 | |||
| 151 | #include <assert.h> | ||
| 152 | #include <errno.h> | ||
| 153 | #include <limits.h> | ||
| 154 | #include <netdb.h> | ||
| 155 | #include <stdio.h> | ||
| 156 | #include <stdlib.h> | ||
| 157 | #include <string.h> | ||
| 158 | #include <time.h> | ||
| 159 | #include <unistd.h> | ||
| 160 | |||
| 161 | #include <ctype.h> | ||
| 162 | |||
| 163 | #include <openssl/opensslconf.h> | ||
| 164 | #include <openssl/bio.h> | ||
| 165 | #include <openssl/crypto.h> | ||
| 166 | #include <openssl/evp.h> | ||
| 167 | #include <openssl/x509.h> | ||
| 168 | #include <openssl/x509v3.h> | ||
| 169 | #include <openssl/ssl.h> | ||
| 170 | #ifndef OPENSSL_NO_ENGINE | ||
| 171 | #include <openssl/engine.h> | ||
| 172 | #endif | ||
| 173 | #include <openssl/err.h> | ||
| 174 | #include <openssl/rand.h> | ||
| 175 | #include <openssl/rsa.h> | ||
| 176 | #include <openssl/dsa.h> | ||
| 177 | #include <openssl/dh.h> | ||
| 178 | #include <openssl/bn.h> | ||
| 179 | |||
| 180 | #define TEST_SERVER_CERT "../apps/server.pem" | ||
| 181 | #define TEST_CLIENT_CERT "../apps/client.pem" | ||
| 182 | |||
| 183 | static int verify_callback(int ok, X509_STORE_CTX *ctx); | ||
| 184 | static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength); | ||
| 185 | static void free_tmp_rsa(void); | ||
| 186 | static int app_verify_callback(X509_STORE_CTX *ctx, void *arg); | ||
| 187 | #define APP_CALLBACK_STRING "Test Callback Argument" | ||
| 188 | struct app_verify_arg { | ||
| 189 | char *string; | ||
| 190 | int app_verify; | ||
| 191 | int allow_proxy_certs; | ||
| 192 | char *proxy_auth; | ||
| 193 | char *proxy_cond; | ||
| 194 | }; | ||
| 195 | |||
| 196 | static DH *get_dh1024(void); | ||
| 197 | static DH *get_dh1024dsa(void); | ||
| 198 | |||
| 199 | static BIO *bio_err = NULL; | ||
| 200 | static BIO *bio_stdout = NULL; | ||
| 201 | |||
| 202 | static const char *alpn_client; | ||
| 203 | static const char *alpn_server; | ||
| 204 | static const char *alpn_expected; | ||
| 205 | static unsigned char *alpn_selected; | ||
| 206 | |||
| 207 | /* | ||
| 208 | * next_protos_parse parses a comma separated list of strings into a string | ||
| 209 | * in a format suitable for passing to SSL_CTX_set_next_protos_advertised. | ||
| 210 | * outlen: (output) set to the length of the resulting buffer on success. | ||
| 211 | * err: (maybe NULL) on failure, an error message line is written to this BIO. | ||
| 212 | * in: a NUL terminated string like "abc,def,ghi" | ||
| 213 | * | ||
| 214 | * returns: a malloced buffer or NULL on failure. | ||
| 215 | */ | ||
| 216 | static unsigned char * | ||
| 217 | next_protos_parse(unsigned short *outlen, const char *in) | ||
| 218 | { | ||
| 219 | size_t i, len, start = 0; | ||
| 220 | unsigned char *out; | ||
| 221 | |||
| 222 | len = strlen(in); | ||
| 223 | if (len >= 65535) | ||
| 224 | return (NULL); | ||
| 225 | |||
| 226 | if ((out = malloc(strlen(in) + 1)) == NULL) | ||
| 227 | return (NULL); | ||
| 228 | |||
| 229 | for (i = 0; i <= len; ++i) { | ||
| 230 | if (i == len || in[i] == ',') { | ||
| 231 | if (i - start > 255) { | ||
| 232 | free(out); | ||
| 233 | return (NULL); | ||
| 234 | } | ||
| 235 | out[start] = i - start; | ||
| 236 | start = i + 1; | ||
| 237 | } else | ||
| 238 | out[i+1] = in[i]; | ||
| 239 | } | ||
| 240 | *outlen = len + 1; | ||
| 241 | return (out); | ||
| 242 | } | ||
| 243 | |||
| 244 | static int | ||
| 245 | cb_server_alpn(SSL *s, const unsigned char **out, unsigned char *outlen, | ||
| 246 | const unsigned char *in, unsigned int inlen, void *arg) | ||
| 247 | { | ||
| 248 | unsigned char *protos; | ||
| 249 | unsigned short protos_len; | ||
| 250 | |||
| 251 | if ((protos = next_protos_parse(&protos_len, alpn_server)) == NULL) { | ||
| 252 | fprintf(stderr, | ||
| 253 | "failed to parser ALPN server protocol string: %s\n", | ||
| 254 | alpn_server); | ||
| 255 | abort(); | ||
| 256 | } | ||
| 257 | |||
| 258 | if (SSL_select_next_proto((unsigned char **)out, outlen, protos, | ||
| 259 | protos_len, in, inlen) != OPENSSL_NPN_NEGOTIATED) { | ||
| 260 | free(protos); | ||
| 261 | return (SSL_TLSEXT_ERR_NOACK); | ||
| 262 | } | ||
| 263 | |||
| 264 | /* | ||
| 265 | * Make a copy of the selected protocol which will be freed in | ||
| 266 | * verify_alpn. | ||
| 267 | */ | ||
| 268 | if ((alpn_selected = malloc(*outlen)) == NULL) { | ||
| 269 | fprintf(stderr, "malloc failed\n"); | ||
| 270 | abort(); | ||
| 271 | } | ||
| 272 | memcpy(alpn_selected, *out, *outlen); | ||
| 273 | *out = alpn_selected; | ||
| 274 | free(protos); | ||
| 275 | |||
| 276 | return (SSL_TLSEXT_ERR_OK); | ||
| 277 | } | ||
| 278 | |||
| 279 | static int | ||
| 280 | verify_alpn(SSL *client, SSL *server) | ||
| 281 | { | ||
| 282 | const unsigned char *client_proto, *server_proto; | ||
| 283 | unsigned int client_proto_len = 0, server_proto_len = 0; | ||
| 284 | |||
| 285 | SSL_get0_alpn_selected(client, &client_proto, &client_proto_len); | ||
| 286 | SSL_get0_alpn_selected(server, &server_proto, &server_proto_len); | ||
| 287 | |||
| 288 | free(alpn_selected); | ||
| 289 | alpn_selected = NULL; | ||
| 290 | |||
| 291 | if (client_proto_len != server_proto_len || | ||
| 292 | memcmp(client_proto, server_proto, client_proto_len) != 0) { | ||
| 293 | BIO_printf(bio_stdout, "ALPN selected protocols differ!\n"); | ||
| 294 | goto err; | ||
| 295 | } | ||
| 296 | |||
| 297 | if (client_proto_len > 0 && alpn_expected == NULL) { | ||
| 298 | BIO_printf(bio_stdout, "ALPN unexpectedly negotiated\n"); | ||
| 299 | goto err; | ||
| 300 | } | ||
| 301 | |||
| 302 | if (alpn_expected != NULL && | ||
| 303 | (client_proto_len != strlen(alpn_expected) || | ||
| 304 | memcmp(client_proto, alpn_expected, client_proto_len) != 0)) { | ||
| 305 | BIO_printf(bio_stdout, "ALPN selected protocols not equal to " | ||
| 306 | "expected protocol: %s\n", alpn_expected); | ||
| 307 | goto err; | ||
| 308 | } | ||
| 309 | |||
| 310 | return (0); | ||
| 311 | |||
| 312 | err: | ||
| 313 | BIO_printf(bio_stdout, "ALPN results: client: '"); | ||
| 314 | BIO_write(bio_stdout, client_proto, client_proto_len); | ||
| 315 | BIO_printf(bio_stdout, "', server: '"); | ||
| 316 | BIO_write(bio_stdout, server_proto, server_proto_len); | ||
| 317 | BIO_printf(bio_stdout, "'\n"); | ||
| 318 | BIO_printf(bio_stdout, "ALPN configured: client: '%s', server: '%s'\n", | ||
| 319 | alpn_client, alpn_server); | ||
| 320 | |||
| 321 | return (-1); | ||
| 322 | } | ||
| 323 | |||
| 324 | static char *cipher = NULL; | ||
| 325 | static int verbose = 0; | ||
| 326 | static int debug = 0; | ||
| 327 | |||
| 328 | int doit_biopair(SSL *s_ssl, SSL *c_ssl, long bytes, clock_t *s_time, | ||
| 329 | clock_t *c_time); | ||
| 330 | int doit(SSL *s_ssl, SSL *c_ssl, long bytes); | ||
| 331 | static int do_test_cipherlist(void); | ||
| 332 | |||
| 333 | static void | ||
| 334 | sv_usage(void) | ||
| 335 | { | ||
| 336 | fprintf(stderr, "usage: ssltest [args ...]\n"); | ||
| 337 | fprintf(stderr, "\n"); | ||
| 338 | fprintf(stderr, " -server_auth - check server certificate\n"); | ||
| 339 | fprintf(stderr, " -client_auth - do client authentication\n"); | ||
| 340 | fprintf(stderr, " -proxy - allow proxy certificates\n"); | ||
| 341 | fprintf(stderr, " -proxy_auth <val> - set proxy policy rights\n"); | ||
| 342 | fprintf(stderr, " -proxy_cond <val> - experssion to test proxy policy rights\n"); | ||
| 343 | fprintf(stderr, " -v - more output\n"); | ||
| 344 | fprintf(stderr, " -d - debug output\n"); | ||
| 345 | fprintf(stderr, " -reuse - use session-id reuse\n"); | ||
| 346 | fprintf(stderr, " -num <val> - number of connections to perform\n"); | ||
| 347 | fprintf(stderr, " -bytes <val> - number of bytes to swap between client/server\n"); | ||
| 348 | fprintf(stderr, " -dhe1024dsa - use 1024 bit key (with 160-bit subprime) for DHE\n"); | ||
| 349 | fprintf(stderr, " -no_dhe - disable DHE\n"); | ||
| 350 | fprintf(stderr, " -no_ecdhe - disable ECDHE\n"); | ||
| 351 | fprintf(stderr, " -dtls1 - use DTLSv1\n"); | ||
| 352 | fprintf(stderr, " -tls1 - use TLSv1\n"); | ||
| 353 | fprintf(stderr, " -CApath arg - PEM format directory of CA's\n"); | ||
| 354 | fprintf(stderr, " -CAfile arg - PEM format file of CA's\n"); | ||
| 355 | fprintf(stderr, " -cert arg - Server certificate file\n"); | ||
| 356 | fprintf(stderr, " -key arg - Server key file (default: same as -cert)\n"); | ||
| 357 | fprintf(stderr, " -c_cert arg - Client certificate file\n"); | ||
| 358 | fprintf(stderr, " -c_key arg - Client key file (default: same as -c_cert)\n"); | ||
| 359 | fprintf(stderr, " -cipher arg - The cipher list\n"); | ||
| 360 | fprintf(stderr, " -bio_pair - Use BIO pairs\n"); | ||
| 361 | fprintf(stderr, " -f - Test even cases that can't work\n"); | ||
| 362 | fprintf(stderr, " -time - measure processor time used by client and server\n"); | ||
| 363 | fprintf(stderr, " -named_curve arg - Elliptic curve name to use for ephemeral ECDH keys.\n" \ | ||
| 364 | " Use \"openssl ecparam -list_curves\" for all names\n" \ | ||
| 365 | " (default is sect163r2).\n"); | ||
| 366 | fprintf(stderr, " -test_cipherlist - verifies the order of the ssl cipher lists\n"); | ||
| 367 | fprintf(stderr, " -alpn_client <string> - have client side offer ALPN\n"); | ||
| 368 | fprintf(stderr, " -alpn_server <string> - have server side offer ALPN\n"); | ||
| 369 | fprintf(stderr, " -alpn_expected <string> - the ALPN protocol that should be negotiated\n"); | ||
| 370 | } | ||
| 371 | |||
| 372 | static void | ||
| 373 | print_details(SSL *c_ssl, const char *prefix) | ||
| 374 | { | ||
| 375 | const SSL_CIPHER *ciph; | ||
| 376 | X509 *cert; | ||
| 377 | |||
| 378 | ciph = SSL_get_current_cipher(c_ssl); | ||
| 379 | BIO_printf(bio_stdout, "%s%s, cipher %s %s", | ||
| 380 | prefix, SSL_get_version(c_ssl), SSL_CIPHER_get_version(ciph), | ||
| 381 | SSL_CIPHER_get_name(ciph)); | ||
| 382 | cert = SSL_get_peer_certificate(c_ssl); | ||
| 383 | if (cert != NULL) { | ||
| 384 | EVP_PKEY *pkey = X509_get_pubkey(cert); | ||
| 385 | if (pkey != NULL) { | ||
| 386 | if (pkey->type == EVP_PKEY_RSA && | ||
| 387 | pkey->pkey.rsa != NULL && | ||
| 388 | pkey->pkey.rsa->n != NULL) { | ||
| 389 | BIO_printf(bio_stdout, ", %d bit RSA", | ||
| 390 | BN_num_bits(pkey->pkey.rsa->n)); | ||
| 391 | } else if (pkey->type == EVP_PKEY_DSA && | ||
| 392 | pkey->pkey.dsa != NULL && | ||
| 393 | pkey->pkey.dsa->p != NULL) { | ||
| 394 | BIO_printf(bio_stdout, ", %d bit DSA", | ||
| 395 | BN_num_bits(pkey->pkey.dsa->p)); | ||
| 396 | } | ||
| 397 | EVP_PKEY_free(pkey); | ||
| 398 | } | ||
| 399 | X509_free(cert); | ||
| 400 | } | ||
| 401 | /* The SSL API does not allow us to look at temporary RSA/DH keys, | ||
| 402 | * otherwise we should print their lengths too */ | ||
| 403 | BIO_printf(bio_stdout, "\n"); | ||
| 404 | } | ||
| 405 | |||
| 406 | static void | ||
| 407 | lock_dbg_cb(int mode, int type, const char *file, int line) | ||
| 408 | { | ||
| 409 | static int modes[CRYPTO_NUM_LOCKS]; /* = {0, 0, ... } */ | ||
| 410 | const char *errstr = NULL; | ||
| 411 | int rw; | ||
| 412 | |||
| 413 | rw = mode & (CRYPTO_READ|CRYPTO_WRITE); | ||
| 414 | if (!((rw == CRYPTO_READ) || (rw == CRYPTO_WRITE))) { | ||
| 415 | errstr = "invalid mode"; | ||
| 416 | goto err; | ||
| 417 | } | ||
| 418 | |||
| 419 | if (type < 0 || type >= CRYPTO_NUM_LOCKS) { | ||
| 420 | errstr = "type out of bounds"; | ||
| 421 | goto err; | ||
| 422 | } | ||
| 423 | |||
| 424 | if (mode & CRYPTO_LOCK) { | ||
| 425 | if (modes[type]) { | ||
| 426 | errstr = "already locked"; | ||
| 427 | /* must not happen in a single-threaded program | ||
| 428 | * (would deadlock) */ | ||
| 429 | goto err; | ||
| 430 | } | ||
| 431 | |||
| 432 | modes[type] = rw; | ||
| 433 | } else if (mode & CRYPTO_UNLOCK) { | ||
| 434 | if (!modes[type]) { | ||
| 435 | errstr = "not locked"; | ||
| 436 | goto err; | ||
| 437 | } | ||
| 438 | |||
| 439 | if (modes[type] != rw) { | ||
| 440 | errstr = (rw == CRYPTO_READ) ? | ||
| 441 | "CRYPTO_r_unlock on write lock" : | ||
| 442 | "CRYPTO_w_unlock on read lock"; | ||
| 443 | } | ||
| 444 | |||
| 445 | modes[type] = 0; | ||
| 446 | } else { | ||
| 447 | errstr = "invalid mode"; | ||
| 448 | goto err; | ||
| 449 | } | ||
| 450 | |||
| 451 | err: | ||
| 452 | if (errstr) { | ||
| 453 | /* we cannot use bio_err here */ | ||
| 454 | fprintf(stderr, | ||
| 455 | "openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d\n", | ||
| 456 | errstr, mode, type, file, line); | ||
| 457 | } | ||
| 458 | } | ||
| 459 | |||
| 460 | int | ||
| 461 | main(int argc, char *argv[]) | ||
| 462 | { | ||
| 463 | char *CApath = NULL, *CAfile = NULL; | ||
| 464 | int badop = 0; | ||
| 465 | int bio_pair = 0; | ||
| 466 | int force = 0; | ||
| 467 | int tls1 = 0, dtls1 = 0, ret = 1; | ||
| 468 | int client_auth = 0; | ||
| 469 | int server_auth = 0, i; | ||
| 470 | struct app_verify_arg app_verify_arg = | ||
| 471 | { APP_CALLBACK_STRING, 0, 0, NULL, NULL }; | ||
| 472 | char *server_cert = TEST_SERVER_CERT; | ||
| 473 | char *server_key = NULL; | ||
| 474 | char *client_cert = TEST_CLIENT_CERT; | ||
| 475 | char *client_key = NULL; | ||
| 476 | char *named_curve = NULL; | ||
| 477 | SSL_CTX *s_ctx = NULL; | ||
| 478 | SSL_CTX *c_ctx = NULL; | ||
| 479 | const SSL_METHOD *meth = NULL; | ||
| 480 | SSL *c_ssl, *s_ssl; | ||
| 481 | int number = 1, reuse = 0; | ||
| 482 | long bytes = 256L; | ||
| 483 | DH *dh; | ||
| 484 | int dhe1024dsa = 0; | ||
| 485 | EC_KEY *ecdh = NULL; | ||
| 486 | int no_dhe = 0; | ||
| 487 | int no_ecdhe = 0; | ||
| 488 | int print_time = 0; | ||
| 489 | clock_t s_time = 0, c_time = 0; | ||
| 490 | int test_cipherlist = 0; | ||
| 491 | |||
| 492 | verbose = 0; | ||
| 493 | debug = 0; | ||
| 494 | cipher = 0; | ||
| 495 | |||
| 496 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE|BIO_FP_TEXT); | ||
| 497 | |||
| 498 | CRYPTO_set_locking_callback(lock_dbg_cb); | ||
| 499 | |||
| 500 | bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE|BIO_FP_TEXT); | ||
| 501 | |||
| 502 | argc--; | ||
| 503 | argv++; | ||
| 504 | |||
| 505 | while (argc >= 1) { | ||
| 506 | if (!strcmp(*argv, "-F")) { | ||
| 507 | fprintf(stderr, "not compiled with FIPS support, so exitting without running.\n"); | ||
| 508 | exit(0); | ||
| 509 | } else if (strcmp(*argv, "-server_auth") == 0) | ||
| 510 | server_auth = 1; | ||
| 511 | else if (strcmp(*argv, "-client_auth") == 0) | ||
| 512 | client_auth = 1; | ||
| 513 | else if (strcmp(*argv, "-proxy_auth") == 0) { | ||
| 514 | if (--argc < 1) | ||
| 515 | goto bad; | ||
| 516 | app_verify_arg.proxy_auth= *(++argv); | ||
| 517 | } else if (strcmp(*argv, "-proxy_cond") == 0) { | ||
| 518 | if (--argc < 1) | ||
| 519 | goto bad; | ||
| 520 | app_verify_arg.proxy_cond= *(++argv); | ||
| 521 | } else if (strcmp(*argv, "-v") == 0) | ||
| 522 | verbose = 1; | ||
| 523 | else if (strcmp(*argv, "-d") == 0) | ||
| 524 | debug = 1; | ||
| 525 | else if (strcmp(*argv, "-reuse") == 0) | ||
| 526 | reuse = 1; | ||
| 527 | else if (strcmp(*argv, "-dhe1024dsa") == 0) { | ||
| 528 | dhe1024dsa = 1; | ||
| 529 | } else if (strcmp(*argv, "-no_dhe") == 0) | ||
| 530 | no_dhe = 1; | ||
| 531 | else if (strcmp(*argv, "-no_ecdhe") == 0) | ||
| 532 | no_ecdhe = 1; | ||
| 533 | else if (strcmp(*argv, "-dtls1") == 0) | ||
| 534 | dtls1 = 1; | ||
| 535 | else if (strcmp(*argv, "-tls1") == 0) | ||
| 536 | tls1 = 1; | ||
| 537 | else if (strncmp(*argv, "-num", 4) == 0) { | ||
| 538 | if (--argc < 1) | ||
| 539 | goto bad; | ||
| 540 | number = atoi(*(++argv)); | ||
| 541 | if (number == 0) | ||
| 542 | number = 1; | ||
| 543 | } else if (strcmp(*argv, "-bytes") == 0) { | ||
| 544 | if (--argc < 1) | ||
| 545 | goto bad; | ||
| 546 | bytes = atol(*(++argv)); | ||
| 547 | if (bytes == 0L) | ||
| 548 | bytes = 1L; | ||
| 549 | i = strlen(argv[0]); | ||
| 550 | if (argv[0][i - 1] == 'k') | ||
| 551 | bytes*=1024L; | ||
| 552 | if (argv[0][i - 1] == 'm') | ||
| 553 | bytes*=1024L*1024L; | ||
| 554 | } else if (strcmp(*argv, "-cert") == 0) { | ||
| 555 | if (--argc < 1) | ||
| 556 | goto bad; | ||
| 557 | server_cert= *(++argv); | ||
| 558 | } else if (strcmp(*argv, "-s_cert") == 0) { | ||
| 559 | if (--argc < 1) | ||
| 560 | goto bad; | ||
| 561 | server_cert= *(++argv); | ||
| 562 | } else if (strcmp(*argv, "-key") == 0) { | ||
| 563 | if (--argc < 1) | ||
| 564 | goto bad; | ||
| 565 | server_key= *(++argv); | ||
| 566 | } else if (strcmp(*argv, "-s_key") == 0) { | ||
| 567 | if (--argc < 1) | ||
| 568 | goto bad; | ||
| 569 | server_key= *(++argv); | ||
| 570 | } else if (strcmp(*argv, "-c_cert") == 0) { | ||
| 571 | if (--argc < 1) | ||
| 572 | goto bad; | ||
| 573 | client_cert= *(++argv); | ||
| 574 | } else if (strcmp(*argv, "-c_key") == 0) { | ||
| 575 | if (--argc < 1) | ||
| 576 | goto bad; | ||
| 577 | client_key= *(++argv); | ||
| 578 | } else if (strcmp(*argv, "-cipher") == 0) { | ||
| 579 | if (--argc < 1) | ||
| 580 | goto bad; | ||
| 581 | cipher= *(++argv); | ||
| 582 | } else if (strcmp(*argv, "-CApath") == 0) { | ||
| 583 | if (--argc < 1) | ||
| 584 | goto bad; | ||
| 585 | CApath= *(++argv); | ||
| 586 | } else if (strcmp(*argv, "-CAfile") == 0) { | ||
| 587 | if (--argc < 1) | ||
| 588 | goto bad; | ||
| 589 | CAfile= *(++argv); | ||
| 590 | } else if (strcmp(*argv, "-bio_pair") == 0) { | ||
| 591 | bio_pair = 1; | ||
| 592 | } else if (strcmp(*argv, "-f") == 0) { | ||
| 593 | force = 1; | ||
| 594 | } else if (strcmp(*argv, "-time") == 0) { | ||
| 595 | print_time = 1; | ||
| 596 | } else if (strcmp(*argv, "-named_curve") == 0) { | ||
| 597 | if (--argc < 1) | ||
| 598 | goto bad; | ||
| 599 | named_curve = *(++argv); | ||
| 600 | } else if (strcmp(*argv, "-app_verify") == 0) { | ||
| 601 | app_verify_arg.app_verify = 1; | ||
| 602 | } else if (strcmp(*argv, "-proxy") == 0) { | ||
| 603 | app_verify_arg.allow_proxy_certs = 1; | ||
| 604 | } else if (strcmp(*argv, "-test_cipherlist") == 0) { | ||
| 605 | test_cipherlist = 1; | ||
| 606 | } else if (strcmp(*argv, "-alpn_client") == 0) { | ||
| 607 | if (--argc < 1) | ||
| 608 | goto bad; | ||
| 609 | alpn_client = *(++argv); | ||
| 610 | } else if (strcmp(*argv, "-alpn_server") == 0) { | ||
| 611 | if (--argc < 1) | ||
| 612 | goto bad; | ||
| 613 | alpn_server = *(++argv); | ||
| 614 | } else if (strcmp(*argv, "-alpn_expected") == 0) { | ||
| 615 | if (--argc < 1) | ||
| 616 | goto bad; | ||
| 617 | alpn_expected = *(++argv); | ||
| 618 | } else { | ||
| 619 | fprintf(stderr, "unknown option %s\n", *argv); | ||
| 620 | badop = 1; | ||
| 621 | break; | ||
| 622 | } | ||
| 623 | argc--; | ||
| 624 | argv++; | ||
| 625 | } | ||
| 626 | if (badop) { | ||
| 627 | bad: | ||
| 628 | sv_usage(); | ||
| 629 | goto end; | ||
| 630 | } | ||
| 631 | |||
| 632 | if (test_cipherlist == 1) { | ||
| 633 | /* ensure that the cipher list are correctly sorted and exit */ | ||
| 634 | if (do_test_cipherlist() == 0) | ||
| 635 | exit(1); | ||
| 636 | ret = 0; | ||
| 637 | goto end; | ||
| 638 | } | ||
| 639 | |||
| 640 | if (!dtls1 && !tls1 && | ||
| 641 | number > 1 && !reuse && !force) { | ||
| 642 | fprintf(stderr, | ||
| 643 | "This case cannot work. Use -f to perform " | ||
| 644 | "the test anyway (and\n-d to see what happens), " | ||
| 645 | "or add one of -dtls1, -tls1, -reuse\n" | ||
| 646 | "to avoid protocol mismatch.\n"); | ||
| 647 | exit(1); | ||
| 648 | } | ||
| 649 | |||
| 650 | if (print_time) { | ||
| 651 | if (!bio_pair) { | ||
| 652 | fprintf(stderr, "Using BIO pair (-bio_pair)\n"); | ||
| 653 | bio_pair = 1; | ||
| 654 | } | ||
| 655 | if (number < 50 && !force) | ||
| 656 | fprintf(stderr, "Warning: For accurate timings, use more connections (e.g. -num 1000)\n"); | ||
| 657 | } | ||
| 658 | |||
| 659 | /* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */ | ||
| 660 | |||
| 661 | SSL_library_init(); | ||
| 662 | SSL_load_error_strings(); | ||
| 663 | |||
| 664 | if (dtls1) | ||
| 665 | meth = DTLSv1_method(); | ||
| 666 | else if (tls1) | ||
| 667 | meth = TLSv1_method(); | ||
| 668 | else | ||
| 669 | meth = SSLv23_method(); | ||
| 670 | |||
| 671 | c_ctx = SSL_CTX_new(meth); | ||
| 672 | s_ctx = SSL_CTX_new(meth); | ||
| 673 | if ((c_ctx == NULL) || (s_ctx == NULL)) { | ||
| 674 | ERR_print_errors(bio_err); | ||
| 675 | goto end; | ||
| 676 | } | ||
| 677 | |||
| 678 | if (cipher != NULL) { | ||
| 679 | SSL_CTX_set_cipher_list(c_ctx, cipher); | ||
| 680 | SSL_CTX_set_cipher_list(s_ctx, cipher); | ||
| 681 | } | ||
| 682 | |||
| 683 | if (!no_dhe) { | ||
| 684 | if (dhe1024dsa) { | ||
| 685 | /* use SSL_OP_SINGLE_DH_USE to avoid small subgroup attacks */ | ||
| 686 | SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE); | ||
| 687 | dh = get_dh1024dsa(); | ||
| 688 | } else | ||
| 689 | dh = get_dh1024(); | ||
| 690 | SSL_CTX_set_tmp_dh(s_ctx, dh); | ||
| 691 | DH_free(dh); | ||
| 692 | } | ||
| 693 | |||
| 694 | if (!no_ecdhe) { | ||
| 695 | int nid; | ||
| 696 | |||
| 697 | if (named_curve != NULL) { | ||
| 698 | nid = OBJ_sn2nid(named_curve); | ||
| 699 | if (nid == 0) { | ||
| 700 | BIO_printf(bio_err, "unknown curve name (%s)\n", named_curve); | ||
| 701 | goto end; | ||
| 702 | } | ||
| 703 | } else | ||
| 704 | nid = NID_X9_62_prime256v1; | ||
| 705 | |||
| 706 | ecdh = EC_KEY_new_by_curve_name(nid); | ||
| 707 | if (ecdh == NULL) { | ||
| 708 | BIO_printf(bio_err, "unable to create curve\n"); | ||
| 709 | goto end; | ||
| 710 | } | ||
| 711 | |||
| 712 | SSL_CTX_set_tmp_ecdh(s_ctx, ecdh); | ||
| 713 | SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_ECDH_USE); | ||
| 714 | EC_KEY_free(ecdh); | ||
| 715 | } | ||
| 716 | |||
| 717 | SSL_CTX_set_tmp_rsa_callback(s_ctx, tmp_rsa_cb); | ||
| 718 | |||
| 719 | if (!SSL_CTX_use_certificate_file(s_ctx, server_cert, | ||
| 720 | SSL_FILETYPE_PEM)) { | ||
| 721 | ERR_print_errors(bio_err); | ||
| 722 | } else if (!SSL_CTX_use_PrivateKey_file(s_ctx, | ||
| 723 | (server_key ? server_key : server_cert), SSL_FILETYPE_PEM)) { | ||
| 724 | ERR_print_errors(bio_err); | ||
| 725 | goto end; | ||
| 726 | } | ||
| 727 | |||
| 728 | if (client_auth) { | ||
| 729 | SSL_CTX_use_certificate_file(c_ctx, client_cert, | ||
| 730 | SSL_FILETYPE_PEM); | ||
| 731 | SSL_CTX_use_PrivateKey_file(c_ctx, | ||
| 732 | (client_key ? client_key : client_cert), | ||
| 733 | SSL_FILETYPE_PEM); | ||
| 734 | } | ||
| 735 | |||
| 736 | if ((!SSL_CTX_load_verify_locations(s_ctx, CAfile, CApath)) || | ||
| 737 | (!SSL_CTX_set_default_verify_paths(s_ctx)) || | ||
| 738 | (!SSL_CTX_load_verify_locations(c_ctx, CAfile, CApath)) || | ||
| 739 | (!SSL_CTX_set_default_verify_paths(c_ctx))) { | ||
| 740 | /* fprintf(stderr,"SSL_load_verify_locations\n"); */ | ||
| 741 | ERR_print_errors(bio_err); | ||
| 742 | /* goto end; */ | ||
| 743 | } | ||
| 744 | |||
| 745 | if (client_auth) { | ||
| 746 | BIO_printf(bio_err, "client authentication\n"); | ||
| 747 | SSL_CTX_set_verify(s_ctx, | ||
| 748 | SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, | ||
| 749 | verify_callback); | ||
| 750 | SSL_CTX_set_cert_verify_callback(s_ctx, app_verify_callback, | ||
| 751 | &app_verify_arg); | ||
| 752 | } | ||
| 753 | if (server_auth) { | ||
| 754 | BIO_printf(bio_err, "server authentication\n"); | ||
| 755 | SSL_CTX_set_verify(c_ctx, SSL_VERIFY_PEER, | ||
| 756 | verify_callback); | ||
| 757 | SSL_CTX_set_cert_verify_callback(c_ctx, app_verify_callback, | ||
| 758 | &app_verify_arg); | ||
| 759 | } | ||
| 760 | |||
| 761 | { | ||
| 762 | int session_id_context = 0; | ||
| 763 | SSL_CTX_set_session_id_context(s_ctx, | ||
| 764 | (void *)&session_id_context, sizeof(session_id_context)); | ||
| 765 | } | ||
| 766 | |||
| 767 | if (alpn_server != NULL) | ||
| 768 | SSL_CTX_set_alpn_select_cb(s_ctx, cb_server_alpn, NULL); | ||
| 769 | |||
| 770 | if (alpn_client != NULL) { | ||
| 771 | unsigned short alpn_len; | ||
| 772 | unsigned char *alpn = next_protos_parse(&alpn_len, alpn_client); | ||
| 773 | |||
| 774 | if (alpn == NULL) { | ||
| 775 | BIO_printf(bio_err, "Error parsing -alpn_client argument\n"); | ||
| 776 | goto end; | ||
| 777 | } | ||
| 778 | SSL_CTX_set_alpn_protos(c_ctx, alpn, alpn_len); | ||
| 779 | free(alpn); | ||
| 780 | } | ||
| 781 | |||
| 782 | c_ssl = SSL_new(c_ctx); | ||
| 783 | s_ssl = SSL_new(s_ctx); | ||
| 784 | |||
| 785 | for (i = 0; i < number; i++) { | ||
| 786 | if (!reuse) | ||
| 787 | SSL_set_session(c_ssl, NULL); | ||
| 788 | if (bio_pair) | ||
| 789 | ret = doit_biopair(s_ssl, c_ssl, bytes, &s_time, | ||
| 790 | &c_time); | ||
| 791 | else | ||
| 792 | ret = doit(s_ssl, c_ssl, bytes); | ||
| 793 | } | ||
| 794 | |||
| 795 | if (!verbose) { | ||
| 796 | print_details(c_ssl, ""); | ||
| 797 | } | ||
| 798 | if ((number > 1) || (bytes > 1L)) | ||
| 799 | BIO_printf(bio_stdout, "%d handshakes of %ld bytes done\n", | ||
| 800 | number, bytes); | ||
| 801 | if (print_time) { | ||
| 802 | #ifdef CLOCKS_PER_SEC | ||
| 803 | /* "To determine the time in seconds, the value returned | ||
| 804 | * by the clock function should be divided by the value | ||
| 805 | * of the macro CLOCKS_PER_SEC." | ||
| 806 | * -- ISO/IEC 9899 */ | ||
| 807 | BIO_printf(bio_stdout, | ||
| 808 | "Approximate total server time: %6.2f s\n" | ||
| 809 | "Approximate total client time: %6.2f s\n", | ||
| 810 | (double)s_time/CLOCKS_PER_SEC, | ||
| 811 | (double)c_time/CLOCKS_PER_SEC); | ||
| 812 | #else | ||
| 813 | /* "`CLOCKS_PER_SEC' undeclared (first use this function)" | ||
| 814 | * -- cc on NeXTstep/OpenStep */ | ||
| 815 | BIO_printf(bio_stdout, | ||
| 816 | "Approximate total server time: %6.2f units\n" | ||
| 817 | "Approximate total client time: %6.2f units\n", | ||
| 818 | (double)s_time, | ||
| 819 | (double)c_time); | ||
| 820 | #endif | ||
| 821 | } | ||
| 822 | |||
| 823 | SSL_free(s_ssl); | ||
| 824 | SSL_free(c_ssl); | ||
| 825 | |||
| 826 | end: | ||
| 827 | SSL_CTX_free(s_ctx); | ||
| 828 | SSL_CTX_free(c_ctx); | ||
| 829 | BIO_free(bio_stdout); | ||
| 830 | |||
| 831 | free_tmp_rsa(); | ||
| 832 | #ifndef OPENSSL_NO_ENGINE | ||
| 833 | ENGINE_cleanup(); | ||
| 834 | #endif | ||
| 835 | CRYPTO_cleanup_all_ex_data(); | ||
| 836 | ERR_free_strings(); | ||
| 837 | ERR_remove_thread_state(NULL); | ||
| 838 | EVP_cleanup(); | ||
| 839 | CRYPTO_mem_leaks(bio_err); | ||
| 840 | BIO_free(bio_err); | ||
| 841 | |||
| 842 | exit(ret); | ||
| 843 | return ret; | ||
| 844 | } | ||
| 845 | |||
| 846 | int | ||
| 847 | doit_biopair(SSL *s_ssl, SSL *c_ssl, long count, clock_t *s_time, | ||
| 848 | clock_t *c_time) | ||
| 849 | { | ||
| 850 | long cw_num = count, cr_num = count, sw_num = count, sr_num = count; | ||
| 851 | BIO *s_ssl_bio = NULL, *c_ssl_bio = NULL; | ||
| 852 | BIO *server = NULL, *server_io = NULL; | ||
| 853 | BIO *client = NULL, *client_io = NULL; | ||
| 854 | int ret = 1; | ||
| 855 | |||
| 856 | size_t bufsiz = 256; /* small buffer for testing */ | ||
| 857 | |||
| 858 | if (!BIO_new_bio_pair(&server, bufsiz, &server_io, bufsiz)) | ||
| 859 | goto err; | ||
| 860 | if (!BIO_new_bio_pair(&client, bufsiz, &client_io, bufsiz)) | ||
| 861 | goto err; | ||
| 862 | |||
| 863 | s_ssl_bio = BIO_new(BIO_f_ssl()); | ||
| 864 | if (!s_ssl_bio) | ||
| 865 | goto err; | ||
| 866 | |||
| 867 | c_ssl_bio = BIO_new(BIO_f_ssl()); | ||
| 868 | if (!c_ssl_bio) | ||
| 869 | goto err; | ||
| 870 | |||
| 871 | SSL_set_connect_state(c_ssl); | ||
| 872 | SSL_set_bio(c_ssl, client, client); | ||
| 873 | (void)BIO_set_ssl(c_ssl_bio, c_ssl, BIO_NOCLOSE); | ||
| 874 | |||
| 875 | SSL_set_accept_state(s_ssl); | ||
| 876 | SSL_set_bio(s_ssl, server, server); | ||
| 877 | (void)BIO_set_ssl(s_ssl_bio, s_ssl, BIO_NOCLOSE); | ||
| 878 | |||
| 879 | do { | ||
| 880 | /* c_ssl_bio: SSL filter BIO | ||
| 881 | * | ||
| 882 | * client: pseudo-I/O for SSL library | ||
| 883 | * | ||
| 884 | * client_io: client's SSL communication; usually to be | ||
| 885 | * relayed over some I/O facility, but in this | ||
| 886 | * test program, we're the server, too: | ||
| 887 | * | ||
| 888 | * server_io: server's SSL communication | ||
| 889 | * | ||
| 890 | * server: pseudo-I/O for SSL library | ||
| 891 | * | ||
| 892 | * s_ssl_bio: SSL filter BIO | ||
| 893 | * | ||
| 894 | * The client and the server each employ a "BIO pair": | ||
| 895 | * client + client_io, server + server_io. | ||
| 896 | * BIO pairs are symmetric. A BIO pair behaves similar | ||
| 897 | * to a non-blocking socketpair (but both endpoints must | ||
| 898 | * be handled by the same thread). | ||
| 899 | * [Here we could connect client and server to the ends | ||
| 900 | * of a single BIO pair, but then this code would be less | ||
| 901 | * suitable as an example for BIO pairs in general.] | ||
| 902 | * | ||
| 903 | * Useful functions for querying the state of BIO pair endpoints: | ||
| 904 | * | ||
| 905 | * BIO_ctrl_pending(bio) number of bytes we can read now | ||
| 906 | * BIO_ctrl_get_read_request(bio) number of bytes needed to fulfil | ||
| 907 | * other side's read attempt | ||
| 908 | * BIO_ctrl_get_write_guarantee(bio) number of bytes we can write now | ||
| 909 | * | ||
| 910 | * ..._read_request is never more than ..._write_guarantee; | ||
| 911 | * it depends on the application which one you should use. | ||
| 912 | */ | ||
| 913 | |||
| 914 | /* We have non-blocking behaviour throughout this test program, but | ||
| 915 | * can be sure that there is *some* progress in each iteration; so | ||
| 916 | * we don't have to worry about ..._SHOULD_READ or ..._SHOULD_WRITE | ||
| 917 | * -- we just try everything in each iteration | ||
| 918 | */ | ||
| 919 | |||
| 920 | { | ||
| 921 | /* CLIENT */ | ||
| 922 | |||
| 923 | char cbuf[1024*8]; | ||
| 924 | int i, r; | ||
| 925 | clock_t c_clock = clock(); | ||
| 926 | |||
| 927 | memset(cbuf, 0, sizeof(cbuf)); | ||
| 928 | |||
| 929 | if (debug) | ||
| 930 | if (SSL_in_init(c_ssl)) | ||
| 931 | printf("client waiting in SSL_connect - %s\n", | ||
| 932 | SSL_state_string_long(c_ssl)); | ||
| 933 | |||
| 934 | if (cw_num > 0) { | ||
| 935 | /* Write to server. */ | ||
| 936 | |||
| 937 | if (cw_num > (long)sizeof cbuf) | ||
| 938 | i = sizeof cbuf; | ||
| 939 | else | ||
| 940 | i = (int)cw_num; | ||
| 941 | r = BIO_write(c_ssl_bio, cbuf, i); | ||
| 942 | if (r < 0) { | ||
| 943 | if (!BIO_should_retry(c_ssl_bio)) { | ||
| 944 | fprintf(stderr, "ERROR in CLIENT\n"); | ||
| 945 | goto err; | ||
| 946 | } | ||
| 947 | /* BIO_should_retry(...) can just be ignored here. | ||
| 948 | * The library expects us to call BIO_write with | ||
| 949 | * the same arguments again, and that's what we will | ||
| 950 | * do in the next iteration. */ | ||
| 951 | } else if (r == 0) { | ||
| 952 | fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); | ||
| 953 | goto err; | ||
| 954 | } else { | ||
| 955 | if (debug) | ||
| 956 | printf("client wrote %d\n", r); | ||
| 957 | cw_num -= r; | ||
| 958 | |||
| 959 | } | ||
| 960 | } | ||
| 961 | |||
| 962 | if (cr_num > 0) { | ||
| 963 | /* Read from server. */ | ||
| 964 | |||
| 965 | r = BIO_read(c_ssl_bio, cbuf, sizeof(cbuf)); | ||
| 966 | if (r < 0) { | ||
| 967 | if (!BIO_should_retry(c_ssl_bio)) { | ||
| 968 | fprintf(stderr, "ERROR in CLIENT\n"); | ||
| 969 | goto err; | ||
| 970 | } | ||
| 971 | /* Again, "BIO_should_retry" can be ignored. */ | ||
| 972 | } else if (r == 0) { | ||
| 973 | fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); | ||
| 974 | goto err; | ||
| 975 | } else { | ||
| 976 | if (debug) | ||
| 977 | printf("client read %d\n", r); | ||
| 978 | cr_num -= r; | ||
| 979 | } | ||
| 980 | } | ||
| 981 | |||
| 982 | /* c_time and s_time increments will typically be very small | ||
| 983 | * (depending on machine speed and clock tick intervals), | ||
| 984 | * but sampling over a large number of connections should | ||
| 985 | * result in fairly accurate figures. We cannot guarantee | ||
| 986 | * a lot, however -- if each connection lasts for exactly | ||
| 987 | * one clock tick, it will be counted only for the client | ||
| 988 | * or only for the server or even not at all. | ||
| 989 | */ | ||
| 990 | *c_time += (clock() - c_clock); | ||
| 991 | } | ||
| 992 | |||
| 993 | { | ||
| 994 | /* SERVER */ | ||
| 995 | |||
| 996 | char sbuf[1024*8]; | ||
| 997 | int i, r; | ||
| 998 | clock_t s_clock = clock(); | ||
| 999 | |||
| 1000 | memset(sbuf, 0, sizeof(sbuf)); | ||
| 1001 | |||
| 1002 | if (debug) | ||
| 1003 | if (SSL_in_init(s_ssl)) | ||
| 1004 | printf("server waiting in SSL_accept - %s\n", | ||
| 1005 | SSL_state_string_long(s_ssl)); | ||
| 1006 | |||
| 1007 | if (sw_num > 0) { | ||
| 1008 | /* Write to client. */ | ||
| 1009 | |||
| 1010 | if (sw_num > (long)sizeof sbuf) | ||
| 1011 | i = sizeof sbuf; | ||
| 1012 | else | ||
| 1013 | i = (int)sw_num; | ||
| 1014 | r = BIO_write(s_ssl_bio, sbuf, i); | ||
| 1015 | if (r < 0) { | ||
| 1016 | if (!BIO_should_retry(s_ssl_bio)) { | ||
| 1017 | fprintf(stderr, "ERROR in SERVER\n"); | ||
| 1018 | goto err; | ||
| 1019 | } | ||
| 1020 | /* Ignore "BIO_should_retry". */ | ||
| 1021 | } else if (r == 0) { | ||
| 1022 | fprintf(stderr, "SSL SERVER STARTUP FAILED\n"); | ||
| 1023 | goto err; | ||
| 1024 | } else { | ||
| 1025 | if (debug) | ||
| 1026 | printf("server wrote %d\n", r); | ||
| 1027 | sw_num -= r; | ||
| 1028 | |||
| 1029 | } | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | if (sr_num > 0) { | ||
| 1033 | /* Read from client. */ | ||
| 1034 | |||
| 1035 | r = BIO_read(s_ssl_bio, sbuf, sizeof(sbuf)); | ||
| 1036 | if (r < 0) { | ||
| 1037 | if (!BIO_should_retry(s_ssl_bio)) { | ||
| 1038 | fprintf(stderr, "ERROR in SERVER\n"); | ||
| 1039 | goto err; | ||
| 1040 | } | ||
| 1041 | /* blah, blah */ | ||
| 1042 | } else if (r == 0) { | ||
| 1043 | fprintf(stderr, "SSL SERVER STARTUP FAILED\n"); | ||
| 1044 | goto err; | ||
| 1045 | } else { | ||
| 1046 | if (debug) | ||
| 1047 | printf("server read %d\n", r); | ||
| 1048 | sr_num -= r; | ||
| 1049 | } | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | *s_time += (clock() - s_clock); | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | { | ||
| 1056 | /* "I/O" BETWEEN CLIENT AND SERVER. */ | ||
| 1057 | |||
| 1058 | size_t r1, r2; | ||
| 1059 | BIO *io1 = server_io, *io2 = client_io; | ||
| 1060 | /* we use the non-copying interface for io1 | ||
| 1061 | * and the standard BIO_write/BIO_read interface for io2 | ||
| 1062 | */ | ||
| 1063 | |||
| 1064 | static int prev_progress = 1; | ||
| 1065 | int progress = 0; | ||
| 1066 | |||
| 1067 | /* io1 to io2 */ | ||
| 1068 | do { | ||
| 1069 | size_t num; | ||
| 1070 | int r; | ||
| 1071 | |||
| 1072 | r1 = BIO_ctrl_pending(io1); | ||
| 1073 | r2 = BIO_ctrl_get_write_guarantee(io2); | ||
| 1074 | |||
| 1075 | num = r1; | ||
| 1076 | if (r2 < num) | ||
| 1077 | num = r2; | ||
| 1078 | if (num) { | ||
| 1079 | char *dataptr; | ||
| 1080 | |||
| 1081 | if (INT_MAX < num) /* yeah, right */ | ||
| 1082 | num = INT_MAX; | ||
| 1083 | |||
| 1084 | r = BIO_nread(io1, &dataptr, (int)num); | ||
| 1085 | assert(r > 0); | ||
| 1086 | assert(r <= (int)num); | ||
| 1087 | /* possibly r < num (non-contiguous data) */ | ||
| 1088 | num = r; | ||
| 1089 | r = BIO_write(io2, dataptr, (int)num); | ||
| 1090 | if (r != (int)num) /* can't happen */ | ||
| 1091 | { | ||
| 1092 | fprintf(stderr, "ERROR: BIO_write could not write " | ||
| 1093 | "BIO_ctrl_get_write_guarantee() bytes"); | ||
| 1094 | goto err; | ||
| 1095 | } | ||
| 1096 | progress = 1; | ||
| 1097 | |||
| 1098 | if (debug) | ||
| 1099 | printf((io1 == client_io) ? | ||
| 1100 | "C->S relaying: %d bytes\n" : | ||
| 1101 | "S->C relaying: %d bytes\n", | ||
| 1102 | (int)num); | ||
| 1103 | } | ||
| 1104 | } while (r1 && r2); | ||
| 1105 | |||
| 1106 | /* io2 to io1 */ | ||
| 1107 | { | ||
| 1108 | size_t num; | ||
| 1109 | int r; | ||
| 1110 | |||
| 1111 | r1 = BIO_ctrl_pending(io2); | ||
| 1112 | r2 = BIO_ctrl_get_read_request(io1); | ||
| 1113 | /* here we could use ..._get_write_guarantee instead of | ||
| 1114 | * ..._get_read_request, but by using the latter | ||
| 1115 | * we test restartability of the SSL implementation | ||
| 1116 | * more thoroughly */ | ||
| 1117 | num = r1; | ||
| 1118 | if (r2 < num) | ||
| 1119 | num = r2; | ||
| 1120 | if (num) { | ||
| 1121 | char *dataptr; | ||
| 1122 | |||
| 1123 | if (INT_MAX < num) | ||
| 1124 | num = INT_MAX; | ||
| 1125 | |||
| 1126 | if (num > 1) | ||
| 1127 | --num; /* test restartability even more thoroughly */ | ||
| 1128 | |||
| 1129 | r = BIO_nwrite0(io1, &dataptr); | ||
| 1130 | assert(r > 0); | ||
| 1131 | if (r < (int)num) | ||
| 1132 | num = r; | ||
| 1133 | r = BIO_read(io2, dataptr, (int)num); | ||
| 1134 | if (r != (int)num) /* can't happen */ | ||
| 1135 | { | ||
| 1136 | fprintf(stderr, "ERROR: BIO_read could not read " | ||
| 1137 | "BIO_ctrl_pending() bytes"); | ||
| 1138 | goto err; | ||
| 1139 | } | ||
| 1140 | progress = 1; | ||
| 1141 | r = BIO_nwrite(io1, &dataptr, (int)num); | ||
| 1142 | if (r != (int)num) /* can't happen */ | ||
| 1143 | { | ||
| 1144 | fprintf(stderr, "ERROR: BIO_nwrite() did not accept " | ||
| 1145 | "BIO_nwrite0() bytes"); | ||
| 1146 | goto err; | ||
| 1147 | } | ||
| 1148 | |||
| 1149 | if (debug) | ||
| 1150 | printf((io2 == client_io) ? | ||
| 1151 | "C->S relaying: %d bytes\n" : | ||
| 1152 | "S->C relaying: %d bytes\n", | ||
| 1153 | (int)num); | ||
| 1154 | } | ||
| 1155 | } /* no loop, BIO_ctrl_get_read_request now returns 0 anyway */ | ||
| 1156 | |||
| 1157 | if (!progress && !prev_progress) { | ||
| 1158 | if (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0) { | ||
| 1159 | fprintf(stderr, "ERROR: got stuck\n"); | ||
| 1160 | goto err; | ||
| 1161 | } | ||
| 1162 | } | ||
| 1163 | prev_progress = progress; | ||
| 1164 | } | ||
| 1165 | } while (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0); | ||
| 1166 | |||
| 1167 | if (verbose) | ||
| 1168 | print_details(c_ssl, "DONE via BIO pair: "); | ||
| 1169 | |||
| 1170 | if (verify_alpn(c_ssl, s_ssl) < 0) { | ||
| 1171 | ret = 1; | ||
| 1172 | goto err; | ||
| 1173 | } | ||
| 1174 | |||
| 1175 | ret = 0; | ||
| 1176 | |||
| 1177 | err: | ||
| 1178 | ERR_print_errors(bio_err); | ||
| 1179 | |||
| 1180 | BIO_free(server); | ||
| 1181 | BIO_free(server_io); | ||
| 1182 | BIO_free(client); | ||
| 1183 | BIO_free(client_io); | ||
| 1184 | BIO_free(s_ssl_bio); | ||
| 1185 | BIO_free(c_ssl_bio); | ||
| 1186 | |||
| 1187 | return ret; | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | |||
| 1191 | #define W_READ 1 | ||
| 1192 | #define W_WRITE 2 | ||
| 1193 | #define C_DONE 1 | ||
| 1194 | #define S_DONE 2 | ||
| 1195 | |||
| 1196 | int | ||
| 1197 | doit(SSL *s_ssl, SSL *c_ssl, long count) | ||
| 1198 | { | ||
| 1199 | char cbuf[1024*8], sbuf[1024*8]; | ||
| 1200 | long cw_num = count, cr_num = count; | ||
| 1201 | long sw_num = count, sr_num = count; | ||
| 1202 | int ret = 1; | ||
| 1203 | BIO *c_to_s = NULL; | ||
| 1204 | BIO *s_to_c = NULL; | ||
| 1205 | BIO *c_bio = NULL; | ||
| 1206 | BIO *s_bio = NULL; | ||
| 1207 | int c_r, c_w, s_r, s_w; | ||
| 1208 | int i, j; | ||
| 1209 | int done = 0; | ||
| 1210 | int c_write, s_write; | ||
| 1211 | int do_server = 0, do_client = 0; | ||
| 1212 | |||
| 1213 | memset(cbuf, 0, sizeof(cbuf)); | ||
| 1214 | memset(sbuf, 0, sizeof(sbuf)); | ||
| 1215 | |||
| 1216 | c_to_s = BIO_new(BIO_s_mem()); | ||
| 1217 | s_to_c = BIO_new(BIO_s_mem()); | ||
| 1218 | if ((s_to_c == NULL) || (c_to_s == NULL)) { | ||
| 1219 | ERR_print_errors(bio_err); | ||
| 1220 | goto err; | ||
| 1221 | } | ||
| 1222 | |||
| 1223 | c_bio = BIO_new(BIO_f_ssl()); | ||
| 1224 | s_bio = BIO_new(BIO_f_ssl()); | ||
| 1225 | if ((c_bio == NULL) || (s_bio == NULL)) { | ||
| 1226 | ERR_print_errors(bio_err); | ||
| 1227 | goto err; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | SSL_set_connect_state(c_ssl); | ||
| 1231 | SSL_set_bio(c_ssl, s_to_c, c_to_s); | ||
| 1232 | BIO_set_ssl(c_bio, c_ssl, BIO_NOCLOSE); | ||
| 1233 | |||
| 1234 | SSL_set_accept_state(s_ssl); | ||
| 1235 | SSL_set_bio(s_ssl, c_to_s, s_to_c); | ||
| 1236 | BIO_set_ssl(s_bio, s_ssl, BIO_NOCLOSE); | ||
| 1237 | |||
| 1238 | c_r = 0; | ||
| 1239 | s_r = 1; | ||
| 1240 | c_w = 1; | ||
| 1241 | s_w = 0; | ||
| 1242 | c_write = 1, s_write = 0; | ||
| 1243 | |||
| 1244 | /* We can always do writes */ | ||
| 1245 | for (;;) { | ||
| 1246 | do_server = 0; | ||
| 1247 | do_client = 0; | ||
| 1248 | |||
| 1249 | i = (int)BIO_pending(s_bio); | ||
| 1250 | if ((i && s_r) || s_w) | ||
| 1251 | do_server = 1; | ||
| 1252 | |||
| 1253 | i = (int)BIO_pending(c_bio); | ||
| 1254 | if ((i && c_r) || c_w) | ||
| 1255 | do_client = 1; | ||
| 1256 | |||
| 1257 | if (do_server && debug) { | ||
| 1258 | if (SSL_in_init(s_ssl)) | ||
| 1259 | printf("server waiting in SSL_accept - %s\n", | ||
| 1260 | SSL_state_string_long(s_ssl)); | ||
| 1261 | } | ||
| 1262 | |||
| 1263 | if (do_client && debug) { | ||
| 1264 | if (SSL_in_init(c_ssl)) | ||
| 1265 | printf("client waiting in SSL_connect - %s\n", | ||
| 1266 | SSL_state_string_long(c_ssl)); | ||
| 1267 | } | ||
| 1268 | |||
| 1269 | if (!do_client && !do_server) { | ||
| 1270 | fprintf(stdout, "ERROR in STARTUP\n"); | ||
| 1271 | ERR_print_errors(bio_err); | ||
| 1272 | goto err; | ||
| 1273 | } | ||
| 1274 | |||
| 1275 | if (do_client && !(done & C_DONE)) { | ||
| 1276 | if (c_write) { | ||
| 1277 | j = (cw_num > (long)sizeof(cbuf)) ? | ||
| 1278 | (int)sizeof(cbuf) : (int)cw_num; | ||
| 1279 | i = BIO_write(c_bio, cbuf, j); | ||
| 1280 | if (i < 0) { | ||
| 1281 | c_r = 0; | ||
| 1282 | c_w = 0; | ||
| 1283 | if (BIO_should_retry(c_bio)) { | ||
| 1284 | if (BIO_should_read(c_bio)) | ||
| 1285 | c_r = 1; | ||
| 1286 | if (BIO_should_write(c_bio)) | ||
| 1287 | c_w = 1; | ||
| 1288 | } else { | ||
| 1289 | fprintf(stderr, "ERROR in CLIENT\n"); | ||
| 1290 | ERR_print_errors(bio_err); | ||
| 1291 | goto err; | ||
| 1292 | } | ||
| 1293 | } else if (i == 0) { | ||
| 1294 | fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); | ||
| 1295 | goto err; | ||
| 1296 | } else { | ||
| 1297 | if (debug) | ||
| 1298 | printf("client wrote %d\n", i); | ||
| 1299 | /* ok */ | ||
| 1300 | s_r = 1; | ||
| 1301 | c_write = 0; | ||
| 1302 | cw_num -= i; | ||
| 1303 | } | ||
| 1304 | } else { | ||
| 1305 | i = BIO_read(c_bio, cbuf, sizeof(cbuf)); | ||
| 1306 | if (i < 0) { | ||
| 1307 | c_r = 0; | ||
| 1308 | c_w = 0; | ||
| 1309 | if (BIO_should_retry(c_bio)) { | ||
| 1310 | if (BIO_should_read(c_bio)) | ||
| 1311 | c_r = 1; | ||
| 1312 | if (BIO_should_write(c_bio)) | ||
| 1313 | c_w = 1; | ||
| 1314 | } else { | ||
| 1315 | fprintf(stderr, "ERROR in CLIENT\n"); | ||
| 1316 | ERR_print_errors(bio_err); | ||
| 1317 | goto err; | ||
| 1318 | } | ||
| 1319 | } else if (i == 0) { | ||
| 1320 | fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); | ||
| 1321 | goto err; | ||
| 1322 | } else { | ||
| 1323 | if (debug) | ||
| 1324 | printf("client read %d\n", i); | ||
| 1325 | cr_num -= i; | ||
| 1326 | if (sw_num > 0) { | ||
| 1327 | s_write = 1; | ||
| 1328 | s_w = 1; | ||
| 1329 | } | ||
| 1330 | if (cr_num <= 0) { | ||
| 1331 | s_write = 1; | ||
| 1332 | s_w = 1; | ||
| 1333 | done = S_DONE|C_DONE; | ||
| 1334 | } | ||
| 1335 | } | ||
| 1336 | } | ||
| 1337 | } | ||
| 1338 | |||
| 1339 | if (do_server && !(done & S_DONE)) { | ||
| 1340 | if (!s_write) { | ||
| 1341 | i = BIO_read(s_bio, sbuf, sizeof(cbuf)); | ||
| 1342 | if (i < 0) { | ||
| 1343 | s_r = 0; | ||
| 1344 | s_w = 0; | ||
| 1345 | if (BIO_should_retry(s_bio)) { | ||
| 1346 | if (BIO_should_read(s_bio)) | ||
| 1347 | s_r = 1; | ||
| 1348 | if (BIO_should_write(s_bio)) | ||
| 1349 | s_w = 1; | ||
| 1350 | } else { | ||
| 1351 | fprintf(stderr, "ERROR in SERVER\n"); | ||
| 1352 | ERR_print_errors(bio_err); | ||
| 1353 | goto err; | ||
| 1354 | } | ||
| 1355 | } else if (i == 0) { | ||
| 1356 | ERR_print_errors(bio_err); | ||
| 1357 | fprintf(stderr, "SSL SERVER STARTUP FAILED in SSL_read\n"); | ||
| 1358 | goto err; | ||
| 1359 | } else { | ||
| 1360 | if (debug) | ||
| 1361 | printf("server read %d\n", i); | ||
| 1362 | sr_num -= i; | ||
| 1363 | if (cw_num > 0) { | ||
| 1364 | c_write = 1; | ||
| 1365 | c_w = 1; | ||
| 1366 | } | ||
| 1367 | if (sr_num <= 0) { | ||
| 1368 | s_write = 1; | ||
| 1369 | s_w = 1; | ||
| 1370 | c_write = 0; | ||
| 1371 | } | ||
| 1372 | } | ||
| 1373 | } else { | ||
| 1374 | j = (sw_num > (long)sizeof(sbuf)) ? | ||
| 1375 | (int)sizeof(sbuf) : (int)sw_num; | ||
| 1376 | i = BIO_write(s_bio, sbuf, j); | ||
| 1377 | if (i < 0) { | ||
| 1378 | s_r = 0; | ||
| 1379 | s_w = 0; | ||
| 1380 | if (BIO_should_retry(s_bio)) { | ||
| 1381 | if (BIO_should_read(s_bio)) | ||
| 1382 | s_r = 1; | ||
| 1383 | if (BIO_should_write(s_bio)) | ||
| 1384 | s_w = 1; | ||
| 1385 | } else { | ||
| 1386 | fprintf(stderr, "ERROR in SERVER\n"); | ||
| 1387 | ERR_print_errors(bio_err); | ||
| 1388 | goto err; | ||
| 1389 | } | ||
| 1390 | } else if (i == 0) { | ||
| 1391 | ERR_print_errors(bio_err); | ||
| 1392 | fprintf(stderr, "SSL SERVER STARTUP FAILED in SSL_write\n"); | ||
| 1393 | goto err; | ||
| 1394 | } else { | ||
| 1395 | if (debug) | ||
| 1396 | printf("server wrote %d\n", i); | ||
| 1397 | sw_num -= i; | ||
| 1398 | s_write = 0; | ||
| 1399 | c_r = 1; | ||
| 1400 | if (sw_num <= 0) | ||
| 1401 | done |= S_DONE; | ||
| 1402 | } | ||
| 1403 | } | ||
| 1404 | } | ||
| 1405 | |||
| 1406 | if ((done & S_DONE) && (done & C_DONE)) | ||
| 1407 | break; | ||
| 1408 | } | ||
| 1409 | |||
| 1410 | if (verbose) | ||
| 1411 | print_details(c_ssl, "DONE: "); | ||
| 1412 | |||
| 1413 | if (verify_alpn(c_ssl, s_ssl) < 0) { | ||
| 1414 | ret = 1; | ||
| 1415 | goto err; | ||
| 1416 | } | ||
| 1417 | |||
| 1418 | ret = 0; | ||
| 1419 | err: | ||
| 1420 | /* We have to set the BIO's to NULL otherwise they will be | ||
| 1421 | * free()ed twice. Once when th s_ssl is SSL_free()ed and | ||
| 1422 | * again when c_ssl is SSL_free()ed. | ||
| 1423 | * This is a hack required because s_ssl and c_ssl are sharing the same | ||
| 1424 | * BIO structure and SSL_set_bio() and SSL_free() automatically | ||
| 1425 | * BIO_free non NULL entries. | ||
| 1426 | * You should not normally do this or be required to do this */ | ||
| 1427 | if (s_ssl != NULL) { | ||
| 1428 | s_ssl->rbio = NULL; | ||
| 1429 | s_ssl->wbio = NULL; | ||
| 1430 | } | ||
| 1431 | if (c_ssl != NULL) { | ||
| 1432 | c_ssl->rbio = NULL; | ||
| 1433 | c_ssl->wbio = NULL; | ||
| 1434 | } | ||
| 1435 | |||
| 1436 | BIO_free(c_to_s); | ||
| 1437 | BIO_free(s_to_c); | ||
| 1438 | BIO_free_all(c_bio); | ||
| 1439 | BIO_free_all(s_bio); | ||
| 1440 | |||
| 1441 | return (ret); | ||
| 1442 | } | ||
| 1443 | |||
| 1444 | static int | ||
| 1445 | get_proxy_auth_ex_data_idx(void) | ||
| 1446 | { | ||
| 1447 | static volatile int idx = -1; | ||
| 1448 | if (idx < 0) { | ||
| 1449 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX); | ||
| 1450 | if (idx < 0) { | ||
| 1451 | idx = X509_STORE_CTX_get_ex_new_index(0, | ||
| 1452 | "SSLtest for verify callback", NULL, NULL, NULL); | ||
| 1453 | } | ||
| 1454 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX); | ||
| 1455 | } | ||
| 1456 | return idx; | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | static int | ||
| 1460 | verify_callback(int ok, X509_STORE_CTX *ctx) | ||
| 1461 | { | ||
| 1462 | char *s, buf[256]; | ||
| 1463 | |||
| 1464 | s = X509_NAME_oneline(X509_get_subject_name(ctx->current_cert), buf, | ||
| 1465 | sizeof buf); | ||
| 1466 | if (s != NULL) { | ||
| 1467 | if (ok) | ||
| 1468 | fprintf(stderr, "depth=%d %s\n", | ||
| 1469 | ctx->error_depth, buf); | ||
| 1470 | else { | ||
| 1471 | fprintf(stderr, "depth=%d error=%d %s\n", | ||
| 1472 | ctx->error_depth, ctx->error, buf); | ||
| 1473 | } | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | if (ok == 0) { | ||
| 1477 | fprintf(stderr, "Error string: %s\n", | ||
| 1478 | X509_verify_cert_error_string(ctx->error)); | ||
| 1479 | switch (ctx->error) { | ||
| 1480 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
| 1481 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
| 1482 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
| 1483 | fprintf(stderr, " ... ignored.\n"); | ||
| 1484 | ok = 1; | ||
| 1485 | } | ||
| 1486 | } | ||
| 1487 | |||
| 1488 | if (ok == 1) { | ||
| 1489 | X509 *xs = ctx->current_cert; | ||
| 1490 | #if 0 | ||
| 1491 | X509 *xi = ctx->current_issuer; | ||
| 1492 | #endif | ||
| 1493 | |||
| 1494 | if (xs->ex_flags & EXFLAG_PROXY) { | ||
| 1495 | unsigned int *letters = | ||
| 1496 | X509_STORE_CTX_get_ex_data(ctx, | ||
| 1497 | get_proxy_auth_ex_data_idx()); | ||
| 1498 | |||
| 1499 | if (letters) { | ||
| 1500 | int found_any = 0; | ||
| 1501 | int i; | ||
| 1502 | PROXY_CERT_INFO_EXTENSION *pci = | ||
| 1503 | X509_get_ext_d2i(xs, NID_proxyCertInfo, | ||
| 1504 | NULL, NULL); | ||
| 1505 | |||
| 1506 | switch (OBJ_obj2nid(pci->proxyPolicy->policyLanguage)) { | ||
| 1507 | case NID_Independent: | ||
| 1508 | /* Completely meaningless in this | ||
| 1509 | program, as there's no way to | ||
| 1510 | grant explicit rights to a | ||
| 1511 | specific PrC. Basically, using | ||
| 1512 | id-ppl-Independent is the perfect | ||
| 1513 | way to grant no rights at all. */ | ||
| 1514 | fprintf(stderr, " Independent proxy certificate"); | ||
| 1515 | for (i = 0; i < 26; i++) | ||
| 1516 | letters[i] = 0; | ||
| 1517 | break; | ||
| 1518 | case NID_id_ppl_inheritAll: | ||
| 1519 | /* This is basically a NOP, we | ||
| 1520 | simply let the current rights | ||
| 1521 | stand as they are. */ | ||
| 1522 | fprintf(stderr, " Proxy certificate inherits all"); | ||
| 1523 | break; | ||
| 1524 | default: | ||
| 1525 | s = (char *) | ||
| 1526 | pci->proxyPolicy->policy->data; | ||
| 1527 | i = pci->proxyPolicy->policy->length; | ||
| 1528 | |||
| 1529 | /* The algorithm works as follows: | ||
| 1530 | it is assumed that previous | ||
| 1531 | iterations or the initial granted | ||
| 1532 | rights has already set some elements | ||
| 1533 | of `letters'. What we need to do is | ||
| 1534 | to clear those that weren't granted | ||
| 1535 | by the current PrC as well. The | ||
| 1536 | easiest way to do this is to add 1 | ||
| 1537 | to all the elements whose letters | ||
| 1538 | are given with the current policy. | ||
| 1539 | That way, all elements that are set | ||
| 1540 | by the current policy and were | ||
| 1541 | already set by earlier policies and | ||
| 1542 | through the original grant of rights | ||
| 1543 | will get the value 2 or higher. | ||
| 1544 | The last thing to do is to sweep | ||
| 1545 | through `letters' and keep the | ||
| 1546 | elements having the value 2 as set, | ||
| 1547 | and clear all the others. */ | ||
| 1548 | |||
| 1549 | fprintf(stderr, " Certificate proxy rights = %*.*s", i, i, s); | ||
| 1550 | while (i-- > 0) { | ||
| 1551 | int c = *s++; | ||
| 1552 | if (isascii(c) && isalpha(c)) { | ||
| 1553 | if (islower(c)) | ||
| 1554 | c = toupper(c); | ||
| 1555 | letters[c - 'A']++; | ||
| 1556 | } | ||
| 1557 | } | ||
| 1558 | for (i = 0; i < 26; i++) | ||
| 1559 | if (letters[i] < 2) | ||
| 1560 | letters[i] = 0; | ||
| 1561 | else | ||
| 1562 | letters[i] = 1; | ||
| 1563 | } | ||
| 1564 | |||
| 1565 | found_any = 0; | ||
| 1566 | fprintf(stderr, ", resulting proxy rights = "); | ||
| 1567 | for (i = 0; i < 26; i++) | ||
| 1568 | if (letters[i]) { | ||
| 1569 | fprintf(stderr, "%c", i + 'A'); | ||
| 1570 | found_any = 1; | ||
| 1571 | } | ||
| 1572 | if (!found_any) | ||
| 1573 | fprintf(stderr, "none"); | ||
| 1574 | fprintf(stderr, "\n"); | ||
| 1575 | |||
| 1576 | PROXY_CERT_INFO_EXTENSION_free(pci); | ||
| 1577 | } | ||
| 1578 | } | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | return (ok); | ||
| 1582 | } | ||
| 1583 | |||
| 1584 | static void | ||
| 1585 | process_proxy_debug(int indent, const char *format, ...) | ||
| 1586 | { | ||
| 1587 | static const char indentation[] = | ||
| 1588 | ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" | ||
| 1589 | ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; /* That's 80 > */ | ||
| 1590 | char my_format[256]; | ||
| 1591 | va_list args; | ||
| 1592 | |||
| 1593 | (void) snprintf(my_format, sizeof(my_format), "%*.*s %s", | ||
| 1594 | indent, indent, indentation, format); | ||
| 1595 | |||
| 1596 | va_start(args, format); | ||
| 1597 | vfprintf(stderr, my_format, args); | ||
| 1598 | va_end(args); | ||
| 1599 | } | ||
| 1600 | /* Priority levels: | ||
| 1601 | 0 [!]var, () | ||
| 1602 | 1 & ^ | ||
| 1603 | 2 | | ||
| 1604 | */ | ||
| 1605 | static int process_proxy_cond_adders(unsigned int letters[26], | ||
| 1606 | const char *cond, const char **cond_end, int *pos, int indent); | ||
| 1607 | |||
| 1608 | static int | ||
| 1609 | process_proxy_cond_val(unsigned int letters[26], const char *cond, | ||
| 1610 | const char **cond_end, int *pos, int indent) | ||
| 1611 | { | ||
| 1612 | int c; | ||
| 1613 | int ok = 1; | ||
| 1614 | int negate = 0; | ||
| 1615 | |||
| 1616 | while (isspace((int)*cond)) { | ||
| 1617 | cond++; | ||
| 1618 | (*pos)++; | ||
| 1619 | } | ||
| 1620 | c = *cond; | ||
| 1621 | |||
| 1622 | if (debug) | ||
| 1623 | process_proxy_debug(indent, | ||
| 1624 | "Start process_proxy_cond_val at position %d: %s\n", | ||
| 1625 | *pos, cond); | ||
| 1626 | |||
| 1627 | while (c == '!') { | ||
| 1628 | negate = !negate; | ||
| 1629 | cond++; | ||
| 1630 | (*pos)++; | ||
| 1631 | while (isspace((int)*cond)) { | ||
| 1632 | cond++; | ||
| 1633 | (*pos)++; | ||
| 1634 | } | ||
| 1635 | c = *cond; | ||
| 1636 | } | ||
| 1637 | |||
| 1638 | if (c == '(') { | ||
| 1639 | cond++; | ||
| 1640 | (*pos)++; | ||
| 1641 | ok = process_proxy_cond_adders(letters, cond, cond_end, pos, | ||
| 1642 | indent + 1); | ||
| 1643 | cond = *cond_end; | ||
| 1644 | if (ok < 0) | ||
| 1645 | goto end; | ||
| 1646 | while (isspace((int)*cond)) { | ||
| 1647 | cond++; | ||
| 1648 | (*pos)++; | ||
| 1649 | } | ||
| 1650 | c = *cond; | ||
| 1651 | if (c != ')') { | ||
| 1652 | fprintf(stderr, | ||
| 1653 | "Weird condition character in position %d: " | ||
| 1654 | "%c\n", *pos, c); | ||
| 1655 | ok = -1; | ||
| 1656 | goto end; | ||
| 1657 | } | ||
| 1658 | cond++; | ||
| 1659 | (*pos)++; | ||
| 1660 | } else if (isascii(c) && isalpha(c)) { | ||
| 1661 | if (islower(c)) | ||
| 1662 | c = toupper(c); | ||
| 1663 | ok = letters[c - 'A']; | ||
| 1664 | cond++; | ||
| 1665 | (*pos)++; | ||
| 1666 | } else { | ||
| 1667 | fprintf(stderr, | ||
| 1668 | "Weird condition character in position %d: " | ||
| 1669 | "%c\n", *pos, c); | ||
| 1670 | ok = -1; | ||
| 1671 | goto end; | ||
| 1672 | } | ||
| 1673 | end: | ||
| 1674 | *cond_end = cond; | ||
| 1675 | if (ok >= 0 && negate) | ||
| 1676 | ok = !ok; | ||
| 1677 | |||
| 1678 | if (debug) | ||
| 1679 | process_proxy_debug(indent, | ||
| 1680 | "End process_proxy_cond_val at position %d: %s, returning %d\n", | ||
| 1681 | *pos, cond, ok); | ||
| 1682 | |||
| 1683 | return ok; | ||
| 1684 | } | ||
| 1685 | |||
| 1686 | static int | ||
| 1687 | process_proxy_cond_multipliers(unsigned int letters[26], const char *cond, | ||
| 1688 | const char **cond_end, int *pos, int indent) | ||
| 1689 | { | ||
| 1690 | int ok; | ||
| 1691 | char c; | ||
| 1692 | |||
| 1693 | if (debug) | ||
| 1694 | process_proxy_debug(indent, | ||
| 1695 | "Start process_proxy_cond_multipliers at position %d: %s\n", | ||
| 1696 | *pos, cond); | ||
| 1697 | |||
| 1698 | ok = process_proxy_cond_val(letters, cond, cond_end, pos, indent + 1); | ||
| 1699 | cond = *cond_end; | ||
| 1700 | if (ok < 0) | ||
| 1701 | goto end; | ||
| 1702 | |||
| 1703 | while (ok >= 0) { | ||
| 1704 | while (isspace((int)*cond)) { | ||
| 1705 | cond++; | ||
| 1706 | (*pos)++; | ||
| 1707 | } | ||
| 1708 | c = *cond; | ||
| 1709 | |||
| 1710 | switch (c) { | ||
| 1711 | case '&': | ||
| 1712 | case '^': | ||
| 1713 | { | ||
| 1714 | int save_ok = ok; | ||
| 1715 | |||
| 1716 | cond++; | ||
| 1717 | (*pos)++; | ||
| 1718 | ok = process_proxy_cond_val(letters, | ||
| 1719 | cond, cond_end, pos, indent + 1); | ||
| 1720 | cond = *cond_end; | ||
| 1721 | if (ok < 0) | ||
| 1722 | break; | ||
| 1723 | |||
| 1724 | switch (c) { | ||
| 1725 | case '&': | ||
| 1726 | ok &= save_ok; | ||
| 1727 | break; | ||
| 1728 | case '^': | ||
| 1729 | ok ^= save_ok; | ||
| 1730 | break; | ||
| 1731 | default: | ||
| 1732 | fprintf(stderr, "SOMETHING IS SERIOUSLY WRONG!" | ||
| 1733 | " STOPPING\n"); | ||
| 1734 | exit(1); | ||
| 1735 | } | ||
| 1736 | } | ||
| 1737 | break; | ||
| 1738 | default: | ||
| 1739 | goto end; | ||
| 1740 | } | ||
| 1741 | } | ||
| 1742 | end: | ||
| 1743 | if (debug) | ||
| 1744 | process_proxy_debug(indent, | ||
| 1745 | "End process_proxy_cond_multipliers at position %d: %s, " | ||
| 1746 | "returning %d\n", | ||
| 1747 | *pos, cond, ok); | ||
| 1748 | |||
| 1749 | *cond_end = cond; | ||
| 1750 | return ok; | ||
| 1751 | } | ||
| 1752 | |||
| 1753 | static int | ||
| 1754 | process_proxy_cond_adders(unsigned int letters[26], const char *cond, | ||
| 1755 | const char **cond_end, int *pos, int indent) | ||
| 1756 | { | ||
| 1757 | int ok; | ||
| 1758 | char c; | ||
| 1759 | |||
| 1760 | if (debug) | ||
| 1761 | process_proxy_debug(indent, | ||
| 1762 | "Start process_proxy_cond_adders at position %d: %s\n", | ||
| 1763 | *pos, cond); | ||
| 1764 | |||
| 1765 | ok = process_proxy_cond_multipliers(letters, cond, cond_end, pos, | ||
| 1766 | indent + 1); | ||
| 1767 | cond = *cond_end; | ||
| 1768 | if (ok < 0) | ||
| 1769 | goto end; | ||
| 1770 | |||
| 1771 | while (ok >= 0) { | ||
| 1772 | while (isspace((int)*cond)) { | ||
| 1773 | cond++; | ||
| 1774 | (*pos)++; | ||
| 1775 | } | ||
| 1776 | c = *cond; | ||
| 1777 | |||
| 1778 | switch (c) { | ||
| 1779 | case '|': | ||
| 1780 | { | ||
| 1781 | int save_ok = ok; | ||
| 1782 | |||
| 1783 | cond++; | ||
| 1784 | (*pos)++; | ||
| 1785 | ok = process_proxy_cond_multipliers(letters, | ||
| 1786 | cond, cond_end, pos, indent + 1); | ||
| 1787 | cond = *cond_end; | ||
| 1788 | if (ok < 0) | ||
| 1789 | break; | ||
| 1790 | |||
| 1791 | switch (c) { | ||
| 1792 | case '|': | ||
| 1793 | ok |= save_ok; | ||
| 1794 | break; | ||
| 1795 | default: | ||
| 1796 | fprintf(stderr, "SOMETHING IS SERIOUSLY WRONG!" | ||
| 1797 | " STOPPING\n"); | ||
| 1798 | exit(1); | ||
| 1799 | } | ||
| 1800 | } | ||
| 1801 | break; | ||
| 1802 | default: | ||
| 1803 | goto end; | ||
| 1804 | } | ||
| 1805 | } | ||
| 1806 | end: | ||
| 1807 | if (debug) | ||
| 1808 | process_proxy_debug(indent, | ||
| 1809 | "End process_proxy_cond_adders at position %d: %s, returning %d\n", | ||
| 1810 | *pos, cond, ok); | ||
| 1811 | |||
| 1812 | *cond_end = cond; | ||
| 1813 | return ok; | ||
| 1814 | } | ||
| 1815 | |||
| 1816 | static int | ||
| 1817 | process_proxy_cond(unsigned int letters[26], const char *cond, | ||
| 1818 | const char **cond_end) | ||
| 1819 | { | ||
| 1820 | int pos = 1; | ||
| 1821 | return process_proxy_cond_adders(letters, cond, cond_end, &pos, 1); | ||
| 1822 | } | ||
| 1823 | |||
| 1824 | static int | ||
| 1825 | app_verify_callback(X509_STORE_CTX *ctx, void *arg) | ||
| 1826 | { | ||
| 1827 | int ok = 1; | ||
| 1828 | struct app_verify_arg *cb_arg = arg; | ||
| 1829 | unsigned int letters[26]; /* only used with proxy_auth */ | ||
| 1830 | |||
| 1831 | if (cb_arg->app_verify) { | ||
| 1832 | char *s = NULL, buf[256]; | ||
| 1833 | |||
| 1834 | fprintf(stderr, "In app_verify_callback, allowing cert. "); | ||
| 1835 | fprintf(stderr, "Arg is: %s\n", cb_arg->string); | ||
| 1836 | fprintf(stderr, "Finished printing do we have a context? 0x%p a cert? 0x%p\n", | ||
| 1837 | (void *)ctx, (void *)ctx->cert); | ||
| 1838 | if (ctx->cert) | ||
| 1839 | s = X509_NAME_oneline(X509_get_subject_name(ctx->cert), buf, 256); | ||
| 1840 | if (s != NULL) { | ||
| 1841 | fprintf(stderr, "cert depth=%d %s\n", ctx->error_depth, buf); | ||
| 1842 | } | ||
| 1843 | return (1); | ||
| 1844 | } | ||
| 1845 | if (cb_arg->proxy_auth) { | ||
| 1846 | int found_any = 0, i; | ||
| 1847 | char *sp; | ||
| 1848 | |||
| 1849 | for (i = 0; i < 26; i++) | ||
| 1850 | letters[i] = 0; | ||
| 1851 | for (sp = cb_arg->proxy_auth; *sp; sp++) { | ||
| 1852 | int c = *sp; | ||
| 1853 | if (isascii(c) && isalpha(c)) { | ||
| 1854 | if (islower(c)) | ||
| 1855 | c = toupper(c); | ||
| 1856 | letters[c - 'A'] = 1; | ||
| 1857 | } | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | fprintf(stderr, " Initial proxy rights = "); | ||
| 1861 | for (i = 0; i < 26; i++) | ||
| 1862 | if (letters[i]) { | ||
| 1863 | fprintf(stderr, "%c", i + 'A'); | ||
| 1864 | found_any = 1; | ||
| 1865 | } | ||
| 1866 | if (!found_any) | ||
| 1867 | fprintf(stderr, "none"); | ||
| 1868 | fprintf(stderr, "\n"); | ||
| 1869 | |||
| 1870 | X509_STORE_CTX_set_ex_data(ctx, | ||
| 1871 | get_proxy_auth_ex_data_idx(), letters); | ||
| 1872 | } | ||
| 1873 | if (cb_arg->allow_proxy_certs) { | ||
| 1874 | X509_STORE_CTX_set_flags(ctx, X509_V_FLAG_ALLOW_PROXY_CERTS); | ||
| 1875 | } | ||
| 1876 | |||
| 1877 | ok = X509_verify_cert(ctx); | ||
| 1878 | |||
| 1879 | if (cb_arg->proxy_auth) { | ||
| 1880 | if (ok > 0) { | ||
| 1881 | const char *cond_end = NULL; | ||
| 1882 | |||
| 1883 | ok = process_proxy_cond(letters, | ||
| 1884 | cb_arg->proxy_cond, &cond_end); | ||
| 1885 | |||
| 1886 | if (ok < 0) | ||
| 1887 | exit(3); | ||
| 1888 | if (*cond_end) { | ||
| 1889 | fprintf(stderr, "Stopped processing condition before it's end.\n"); | ||
| 1890 | ok = 0; | ||
| 1891 | } | ||
| 1892 | if (!ok) | ||
| 1893 | fprintf(stderr, "Proxy rights check with condition '%s' proved invalid\n", | ||
| 1894 | cb_arg->proxy_cond); | ||
| 1895 | else | ||
| 1896 | fprintf(stderr, "Proxy rights check with condition '%s' proved valid\n", | ||
| 1897 | cb_arg->proxy_cond); | ||
| 1898 | } | ||
| 1899 | } | ||
| 1900 | return (ok); | ||
| 1901 | } | ||
| 1902 | |||
| 1903 | static RSA *rsa_tmp = NULL; | ||
| 1904 | |||
| 1905 | static RSA * | ||
| 1906 | tmp_rsa_cb(SSL *s, int is_export, int keylength) | ||
| 1907 | { | ||
| 1908 | BIGNUM *bn = NULL; | ||
| 1909 | if (rsa_tmp == NULL) { | ||
| 1910 | bn = BN_new(); | ||
| 1911 | rsa_tmp = RSA_new(); | ||
| 1912 | if (!bn || !rsa_tmp || !BN_set_word(bn, RSA_F4)) { | ||
| 1913 | BIO_printf(bio_err, "Memory error..."); | ||
| 1914 | goto end; | ||
| 1915 | } | ||
| 1916 | BIO_printf(bio_err, "Generating temp (%d bit) RSA key...", keylength); | ||
| 1917 | (void)BIO_flush(bio_err); | ||
| 1918 | if (!RSA_generate_key_ex(rsa_tmp, keylength, bn, NULL)) { | ||
| 1919 | BIO_printf(bio_err, "Error generating key."); | ||
| 1920 | RSA_free(rsa_tmp); | ||
| 1921 | rsa_tmp = NULL; | ||
| 1922 | } | ||
| 1923 | end: | ||
| 1924 | BIO_printf(bio_err, "\n"); | ||
| 1925 | (void)BIO_flush(bio_err); | ||
| 1926 | } | ||
| 1927 | if (bn) | ||
| 1928 | BN_free(bn); | ||
| 1929 | return (rsa_tmp); | ||
| 1930 | } | ||
| 1931 | |||
| 1932 | static void | ||
| 1933 | free_tmp_rsa(void) | ||
| 1934 | { | ||
| 1935 | if (rsa_tmp != NULL) { | ||
| 1936 | RSA_free(rsa_tmp); | ||
| 1937 | rsa_tmp = NULL; | ||
| 1938 | } | ||
| 1939 | } | ||
| 1940 | |||
| 1941 | /* These DH parameters have been generated as follows: | ||
| 1942 | * $ openssl dhparam -C -noout 1024 | ||
| 1943 | * $ openssl dhparam -C -noout -dsaparam 1024 | ||
| 1944 | * (The second function has been renamed to avoid name conflicts.) | ||
| 1945 | */ | ||
| 1946 | static DH * | ||
| 1947 | get_dh1024() | ||
| 1948 | { | ||
| 1949 | static unsigned char dh1024_p[] = { | ||
| 1950 | 0xF8, 0x81, 0x89, 0x7D, 0x14, 0x24, 0xC5, 0xD1, 0xE6, 0xF7, 0xBF, 0x3A, | ||
| 1951 | 0xE4, 0x90, 0xF4, 0xFC, 0x73, 0xFB, 0x34, 0xB5, 0xFA, 0x4C, 0x56, 0xA2, | ||
| 1952 | 0xEA, 0xA7, 0xE9, 0xC0, 0xC0, 0xCE, 0x89, 0xE1, 0xFA, 0x63, 0x3F, 0xB0, | ||
| 1953 | 0x6B, 0x32, 0x66, 0xF1, 0xD1, 0x7B, 0xB0, 0x00, 0x8F, 0xCA, 0x87, 0xC2, | ||
| 1954 | 0xAE, 0x98, 0x89, 0x26, 0x17, 0xC2, 0x05, 0xD2, 0xEC, 0x08, 0xD0, 0x8C, | ||
| 1955 | 0xFF, 0x17, 0x52, 0x8C, 0xC5, 0x07, 0x93, 0x03, 0xB1, 0xF6, 0x2F, 0xB8, | ||
| 1956 | 0x1C, 0x52, 0x47, 0x27, 0x1B, 0xDB, 0xD1, 0x8D, 0x9D, 0x69, 0x1D, 0x52, | ||
| 1957 | 0x4B, 0x32, 0x81, 0xAA, 0x7F, 0x00, 0xC8, 0xDC, 0xE6, 0xD9, 0xCC, 0xC1, | ||
| 1958 | 0x11, 0x2D, 0x37, 0x34, 0x6C, 0xEA, 0x02, 0x97, 0x4B, 0x0E, 0xBB, 0xB1, | ||
| 1959 | 0x71, 0x33, 0x09, 0x15, 0xFD, 0xDD, 0x23, 0x87, 0x07, 0x5E, 0x89, 0xAB, | ||
| 1960 | 0x6B, 0x7C, 0x5F, 0xEC, 0xA6, 0x24, 0xDC, 0x53, | ||
| 1961 | }; | ||
| 1962 | static unsigned char dh1024_g[] = { | ||
| 1963 | 0x02, | ||
| 1964 | }; | ||
| 1965 | DH *dh; | ||
| 1966 | |||
| 1967 | if ((dh = DH_new()) == NULL) | ||
| 1968 | return (NULL); | ||
| 1969 | dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL); | ||
| 1970 | dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL); | ||
| 1971 | if ((dh->p == NULL) || (dh->g == NULL)) { | ||
| 1972 | DH_free(dh); | ||
| 1973 | return (NULL); | ||
| 1974 | } | ||
| 1975 | return (dh); | ||
| 1976 | } | ||
| 1977 | |||
| 1978 | static DH * | ||
| 1979 | get_dh1024dsa() | ||
| 1980 | { | ||
| 1981 | static unsigned char dh1024_p[] = { | ||
| 1982 | 0xC8, 0x00, 0xF7, 0x08, 0x07, 0x89, 0x4D, 0x90, 0x53, 0xF3, 0xD5, 0x00, | ||
| 1983 | 0x21, 0x1B, 0xF7, 0x31, 0xA6, 0xA2, 0xDA, 0x23, 0x9A, 0xC7, 0x87, 0x19, | ||
| 1984 | 0x3B, 0x47, 0xB6, 0x8C, 0x04, 0x6F, 0xFF, 0xC6, 0x9B, 0xB8, 0x65, 0xD2, | ||
| 1985 | 0xC2, 0x5F, 0x31, 0x83, 0x4A, 0xA7, 0x5F, 0x2F, 0x88, 0x38, 0xB6, 0x55, | ||
| 1986 | 0xCF, 0xD9, 0x87, 0x6D, 0x6F, 0x9F, 0xDA, 0xAC, 0xA6, 0x48, 0xAF, 0xFC, | ||
| 1987 | 0x33, 0x84, 0x37, 0x5B, 0x82, 0x4A, 0x31, 0x5D, 0xE7, 0xBD, 0x52, 0x97, | ||
| 1988 | 0xA1, 0x77, 0xBF, 0x10, 0x9E, 0x37, 0xEA, 0x64, 0xFA, 0xCA, 0x28, 0x8D, | ||
| 1989 | 0x9D, 0x3B, 0xD2, 0x6E, 0x09, 0x5C, 0x68, 0xC7, 0x45, 0x90, 0xFD, 0xBB, | ||
| 1990 | 0x70, 0xC9, 0x3A, 0xBB, 0xDF, 0xD4, 0x21, 0x0F, 0xC4, 0x6A, 0x3C, 0xF6, | ||
| 1991 | 0x61, 0xCF, 0x3F, 0xD6, 0x13, 0xF1, 0x5F, 0xBC, 0xCF, 0xBC, 0x26, 0x9E, | ||
| 1992 | 0xBC, 0x0B, 0xBD, 0xAB, 0x5D, 0xC9, 0x54, 0x39, | ||
| 1993 | }; | ||
| 1994 | static unsigned char dh1024_g[] = { | ||
| 1995 | 0x3B, 0x40, 0x86, 0xE7, 0xF3, 0x6C, 0xDE, 0x67, 0x1C, 0xCC, 0x80, 0x05, | ||
| 1996 | 0x5A, 0xDF, 0xFE, 0xBD, 0x20, 0x27, 0x74, 0x6C, 0x24, 0xC9, 0x03, 0xF3, | ||
| 1997 | 0xE1, 0x8D, 0xC3, 0x7D, 0x98, 0x27, 0x40, 0x08, 0xB8, 0x8C, 0x6A, 0xE9, | ||
| 1998 | 0xBB, 0x1A, 0x3A, 0xD6, 0x86, 0x83, 0x5E, 0x72, 0x41, 0xCE, 0x85, 0x3C, | ||
| 1999 | 0xD2, 0xB3, 0xFC, 0x13, 0xCE, 0x37, 0x81, 0x9E, 0x4C, 0x1C, 0x7B, 0x65, | ||
| 2000 | 0xD3, 0xE6, 0xA6, 0x00, 0xF5, 0x5A, 0x95, 0x43, 0x5E, 0x81, 0xCF, 0x60, | ||
| 2001 | 0xA2, 0x23, 0xFC, 0x36, 0xA7, 0x5D, 0x7A, 0x4C, 0x06, 0x91, 0x6E, 0xF6, | ||
| 2002 | 0x57, 0xEE, 0x36, 0xCB, 0x06, 0xEA, 0xF5, 0x3D, 0x95, 0x49, 0xCB, 0xA7, | ||
| 2003 | 0xDD, 0x81, 0xDF, 0x80, 0x09, 0x4A, 0x97, 0x4D, 0xA8, 0x22, 0x72, 0xA1, | ||
| 2004 | 0x7F, 0xC4, 0x70, 0x56, 0x70, 0xE8, 0x20, 0x10, 0x18, 0x8F, 0x2E, 0x60, | ||
| 2005 | 0x07, 0xE7, 0x68, 0x1A, 0x82, 0x5D, 0x32, 0xA2, | ||
| 2006 | }; | ||
| 2007 | DH *dh; | ||
| 2008 | |||
| 2009 | if ((dh = DH_new()) == NULL) | ||
| 2010 | return (NULL); | ||
| 2011 | dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL); | ||
| 2012 | dh->g = BN_bin2bn(dh1024_g, sizeof(dh1024_g), NULL); | ||
| 2013 | if ((dh->p == NULL) || (dh->g == NULL)) { | ||
| 2014 | DH_free(dh); | ||
| 2015 | return (NULL); | ||
| 2016 | } | ||
| 2017 | dh->length = 160; | ||
| 2018 | return (dh); | ||
| 2019 | } | ||
| 2020 | |||
| 2021 | static int | ||
| 2022 | do_test_cipherlist(void) | ||
| 2023 | { | ||
| 2024 | int i = 0; | ||
| 2025 | const SSL_METHOD *meth; | ||
| 2026 | const SSL_CIPHER *ci, *tci = NULL; | ||
| 2027 | |||
| 2028 | fprintf(stderr, "testing TLSv1 cipher list order: "); | ||
| 2029 | meth = TLSv1_method(); | ||
| 2030 | tci = NULL; | ||
| 2031 | while ((ci = meth->get_cipher(i++)) != NULL) { | ||
| 2032 | if (tci != NULL) { | ||
| 2033 | if (ci->id >= tci->id) { | ||
| 2034 | fprintf(stderr, | ||
| 2035 | "failed %lx vs. %lx\n", ci->id, tci->id); | ||
| 2036 | return 0; | ||
| 2037 | } | ||
| 2038 | } | ||
| 2039 | tci = ci; | ||
| 2040 | } | ||
| 2041 | fprintf(stderr, "ok\n"); | ||
| 2042 | |||
| 2043 | return 1; | ||
| 2044 | } | ||
diff --git a/src/regress/lib/libssl/ssl/testssl b/src/regress/lib/libssl/ssl/testssl deleted file mode 100644 index 3563d13607..0000000000 --- a/src/regress/lib/libssl/ssl/testssl +++ /dev/null | |||
| @@ -1,138 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | key="$1" | ||
| 4 | cert="$2" | ||
| 5 | CA="-CAfile $3" | ||
| 6 | ssltest="${4-./ssltest} -key $key -cert $cert -c_key $key -c_cert $cert" | ||
| 7 | openssl=${5-openssl} | ||
| 8 | extra="$6" | ||
| 9 | |||
| 10 | $openssl version || exit 1 | ||
| 11 | |||
| 12 | if $openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then | ||
| 13 | dsa_cert=YES | ||
| 14 | else | ||
| 15 | dsa_cert=NO | ||
| 16 | fi | ||
| 17 | |||
| 18 | ############################################################################# | ||
| 19 | |||
| 20 | echo test sslv2/sslv3 | ||
| 21 | $ssltest $extra || exit 1 | ||
| 22 | |||
| 23 | echo test sslv2/sslv3 with server authentication | ||
| 24 | $ssltest -server_auth $CA $extra || exit 1 | ||
| 25 | |||
| 26 | echo test sslv2/sslv3 with client authentication | ||
| 27 | $ssltest -client_auth $CA $extra || exit 1 | ||
| 28 | |||
| 29 | echo test sslv2/sslv3 with both client and server authentication | ||
| 30 | $ssltest -server_auth -client_auth $CA $extra || exit 1 | ||
| 31 | |||
| 32 | echo test sslv2/sslv3 via BIO pair | ||
| 33 | $ssltest $extra || exit 1 | ||
| 34 | |||
| 35 | if [ $dsa_cert = NO ]; then | ||
| 36 | echo 'test sslv2/sslv3 w/o (EC)DHE via BIO pair' | ||
| 37 | $ssltest -bio_pair -no_dhe -no_ecdhe $extra || exit 1 | ||
| 38 | fi | ||
| 39 | |||
| 40 | echo test sslv2/sslv3 with 1024bit DHE via BIO pair | ||
| 41 | $ssltest -bio_pair -dhe1024dsa -v $extra || exit 1 | ||
| 42 | |||
| 43 | echo test sslv2/sslv3 with server authentication | ||
| 44 | $ssltest -bio_pair -server_auth $CA $extra || exit 1 | ||
| 45 | |||
| 46 | echo test sslv2/sslv3 with client authentication via BIO pair | ||
| 47 | $ssltest -bio_pair -client_auth $CA $extra || exit 1 | ||
| 48 | |||
| 49 | echo test sslv2/sslv3 with both client and server authentication via BIO pair | ||
| 50 | $ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1 | ||
| 51 | |||
| 52 | echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify | ||
| 53 | $ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1 | ||
| 54 | |||
| 55 | echo "Testing ciphersuites" | ||
| 56 | for protocol in TLSv1.2; do | ||
| 57 | echo "Testing ciphersuites for $protocol" | ||
| 58 | for cipher in `$openssl ciphers "$protocol+aRSA" | tr ':' ' '`; do | ||
| 59 | echo "Testing $cipher" | ||
| 60 | $ssltest -cipher $cipher | ||
| 61 | if [ $? -ne 0 ] ; then | ||
| 62 | echo "Failed $cipher" | ||
| 63 | exit 1 | ||
| 64 | fi | ||
| 65 | done | ||
| 66 | done | ||
| 67 | |||
| 68 | ############################################################################# | ||
| 69 | |||
| 70 | if $openssl no-dh; then | ||
| 71 | echo skipping anonymous DH tests | ||
| 72 | else | ||
| 73 | echo test tls1 with 1024bit anonymous DH, multiple handshakes | ||
| 74 | $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
| 75 | fi | ||
| 76 | |||
| 77 | #if $openssl no-rsa; then | ||
| 78 | # echo skipping RSA tests | ||
| 79 | #else | ||
| 80 | # echo 'test tls1 with 1024bit RSA, no (EC)DHE, multiple handshakes' | ||
| 81 | # ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -no_ecdhe -num 10 -f -time $extra || exit 1 | ||
| 82 | # | ||
| 83 | # if $openssl no-dh; then | ||
| 84 | # echo skipping RSA+DHE tests | ||
| 85 | # else | ||
| 86 | # echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes | ||
| 87 | # ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
| 88 | # fi | ||
| 89 | #fi | ||
| 90 | |||
| 91 | # | ||
| 92 | # DTLS tests | ||
| 93 | # | ||
| 94 | |||
| 95 | echo test dtlsv1 | ||
| 96 | $ssltest -dtls1 $extra || exit 1 | ||
| 97 | |||
| 98 | echo test dtlsv1 with server authentication | ||
| 99 | $ssltest -dtls1 -server_auth $CA $extra || exit 1 | ||
| 100 | |||
| 101 | echo test dtlsv1 with client authentication | ||
| 102 | $ssltest -dtls1 -client_auth $CA $extra || exit 1 | ||
| 103 | |||
| 104 | echo test dtlsv1 with both client and server authentication | ||
| 105 | $ssltest -dtls1 -server_auth -client_auth $CA $extra || exit 1 | ||
| 106 | |||
| 107 | echo "Testing DTLS ciphersuites" | ||
| 108 | for protocol in SSLv3; do | ||
| 109 | echo "Testing ciphersuites for $protocol" | ||
| 110 | for cipher in `$openssl ciphers "RSA+$protocol" | tr ':' '\n' | | ||
| 111 | grep -v RC4`; do | ||
| 112 | echo "Testing $cipher" | ||
| 113 | $ssltest -cipher $cipher -dtls1 | ||
| 114 | if [ $? -ne 0 ] ; then | ||
| 115 | echo "Failed $cipher" | ||
| 116 | exit 1 | ||
| 117 | fi | ||
| 118 | done | ||
| 119 | done | ||
| 120 | |||
| 121 | # | ||
| 122 | # ALPN tests | ||
| 123 | # | ||
| 124 | echo "Testing ALPN..." | ||
| 125 | $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server bar || exit 1 | ||
| 126 | $ssltest -bio_pair -tls1 -alpn_client foo -alpn_server foo \ | ||
| 127 | -alpn_expected foo || exit 1 | ||
| 128 | $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server foo \ | ||
| 129 | -alpn_expected foo || exit 1 | ||
| 130 | $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo \ | ||
| 131 | -alpn_expected foo || exit 1 | ||
| 132 | $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server foo,bar \ | ||
| 133 | -alpn_expected foo || exit 1 | ||
| 134 | $ssltest -bio_pair -tls1 -alpn_client bar,foo -alpn_server bar,foo \ | ||
| 135 | -alpn_expected bar || exit 1 | ||
| 136 | $ssltest -bio_pair -tls1 -alpn_client foo,bar -alpn_server bar,foo \ | ||
| 137 | -alpn_expected bar || exit 1 | ||
| 138 | $ssltest -bio_pair -tls1 -alpn_client baz -alpn_server bar,foo || exit 1 | ||
diff --git a/src/regress/lib/libssl/tlsext/Makefile b/src/regress/lib/libssl/tlsext/Makefile deleted file mode 100644 index 48b5bc1e25..0000000000 --- a/src/regress/lib/libssl/tlsext/Makefile +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2017/07/16 18:18:10 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= tlsexttest | ||
| 4 | LDADD= ${SSL_INT} -lcrypto | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} | ||
| 6 | WARNINGS= Yes | ||
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -Wundef -Werror -I$(BSDSRCDIR)/lib/libssl | ||
| 8 | |||
| 9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/tlsext/tlsexttest.c b/src/regress/lib/libssl/tlsext/tlsexttest.c deleted file mode 100644 index b50736d802..0000000000 --- a/src/regress/lib/libssl/tlsext/tlsexttest.c +++ /dev/null | |||
| @@ -1,2981 +0,0 @@ | |||
| 1 | /* $OpenBSD: tlsexttest.c,v 1.19 2018/11/06 01:19:35 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | ||
| 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 <err.h> | ||
| 20 | |||
| 21 | #include "ssl_locl.h" | ||
| 22 | |||
| 23 | #include "bytestring.h" | ||
| 24 | #include "ssl_tlsext.h" | ||
| 25 | |||
| 26 | static void | ||
| 27 | hexdump(const unsigned char *buf, size_t len) | ||
| 28 | { | ||
| 29 | size_t i; | ||
| 30 | |||
| 31 | for (i = 1; i <= len; i++) | ||
| 32 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 33 | |||
| 34 | fprintf(stderr, "\n"); | ||
| 35 | } | ||
| 36 | |||
| 37 | static void | ||
| 38 | hexdump2(const uint16_t *buf, size_t len) | ||
| 39 | { | ||
| 40 | size_t i; | ||
| 41 | |||
| 42 | for (i = 1; i <= len / 2; i++) | ||
| 43 | fprintf(stderr, " 0x%04hx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 44 | |||
| 45 | fprintf(stderr, "\n"); | ||
| 46 | } | ||
| 47 | |||
| 48 | static void | ||
| 49 | compare_data(const uint8_t *recv, size_t recv_len, const uint8_t *expect, | ||
| 50 | size_t expect_len) | ||
| 51 | { | ||
| 52 | fprintf(stderr, "received:\n"); | ||
| 53 | hexdump(recv, recv_len); | ||
| 54 | |||
| 55 | fprintf(stderr, "test data:\n"); | ||
| 56 | hexdump(expect, expect_len); | ||
| 57 | } | ||
| 58 | |||
| 59 | static void | ||
| 60 | compare_data2(const uint16_t *recv, size_t recv_len, const uint16_t *expect, | ||
| 61 | size_t expect_len) | ||
| 62 | { | ||
| 63 | fprintf(stderr, "received:\n"); | ||
| 64 | hexdump2(recv, recv_len); | ||
| 65 | |||
| 66 | fprintf(stderr, "test data:\n"); | ||
| 67 | hexdump2(expect, expect_len); | ||
| 68 | } | ||
| 69 | |||
| 70 | #define FAIL(msg, ...) \ | ||
| 71 | do { \ | ||
| 72 | fprintf(stderr, "[%s:%d] FAIL: ", __FILE__, __LINE__); \ | ||
| 73 | fprintf(stderr, msg, ##__VA_ARGS__); \ | ||
| 74 | } while(0) | ||
| 75 | |||
| 76 | /* | ||
| 77 | * Supported Application-Layer Protocol Negotiation - RFC 7301 | ||
| 78 | * | ||
| 79 | * There are already extensive unit tests for this so this just | ||
| 80 | * tests the state info. | ||
| 81 | */ | ||
| 82 | |||
| 83 | const uint8_t tlsext_alpn_multiple_protos_val[] = { | ||
| 84 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 85 | 0x08, /* len */ | ||
| 86 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 87 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
| 88 | 0x09, /* len */ | ||
| 89 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
| 90 | }; | ||
| 91 | |||
| 92 | const uint8_t tlsext_alpn_multiple_protos[] = { | ||
| 93 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 94 | 0x00, 0x13, /* len of all names */ | ||
| 95 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 96 | 0x08, /* len */ | ||
| 97 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 98 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
| 99 | 0x09, /* len */ | ||
| 100 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
| 101 | }; | ||
| 102 | |||
| 103 | const uint8_t tlsext_alpn_single_proto_val[] = { | ||
| 104 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 105 | 0x08, /* len */ | ||
| 106 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
| 107 | }; | ||
| 108 | |||
| 109 | const uint8_t tlsext_alpn_single_proto_name[] = { | ||
| 110 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* 'http/1.1' */ | ||
| 111 | }; | ||
| 112 | |||
| 113 | const uint8_t tlsext_alpn_single_proto[] = { | ||
| 114 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 115 | 0x00, 0x09, /* len of all names */ | ||
| 116 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 117 | 0x08, /* len */ | ||
| 118 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
| 119 | }; | ||
| 120 | |||
| 121 | static int | ||
| 122 | test_tlsext_alpn_clienthello(void) | ||
| 123 | { | ||
| 124 | SSL_CTX *ssl_ctx = NULL; | ||
| 125 | SSL *ssl = NULL; | ||
| 126 | uint8_t *data = NULL; | ||
| 127 | CBB cbb; | ||
| 128 | CBS cbs; | ||
| 129 | int failure, alert; | ||
| 130 | size_t dlen; | ||
| 131 | |||
| 132 | CBB_init(&cbb, 0); | ||
| 133 | |||
| 134 | failure = 1; | ||
| 135 | |||
| 136 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 137 | errx(1, "failed to create SSL_CTX"); | ||
| 138 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 139 | errx(1, "failed to create SSL"); | ||
| 140 | |||
| 141 | /* By default, we don't need this */ | ||
| 142 | if (tlsext_alpn_clienthello_needs(ssl)) { | ||
| 143 | FAIL("clienthello should not need ALPN by default"); | ||
| 144 | goto err; | ||
| 145 | } | ||
| 146 | |||
| 147 | /* | ||
| 148 | * Prereqs: | ||
| 149 | * 1) Set s->internal->alpn_client_proto_list | ||
| 150 | * - Using SSL_set_alpn_protos() | ||
| 151 | * 2) We have not finished or renegotiated. | ||
| 152 | * - S3I(s)->tmp.finish_md_len == 0 | ||
| 153 | */ | ||
| 154 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_single_proto_val, | ||
| 155 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
| 156 | FAIL("should be able to set ALPN to http/1.1"); | ||
| 157 | goto err; | ||
| 158 | } | ||
| 159 | if (!tlsext_alpn_clienthello_needs(ssl)) { | ||
| 160 | FAIL("clienthello should need ALPN by now"); | ||
| 161 | goto err; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* Make sure we can build the clienthello with a single proto. */ | ||
| 165 | |||
| 166 | if (!tlsext_alpn_clienthello_build(ssl, &cbb)) { | ||
| 167 | FAIL("clienthello failed to build ALPN\n"); | ||
| 168 | goto err; | ||
| 169 | } | ||
| 170 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 171 | errx(1, "failed to finish CBB"); | ||
| 172 | |||
| 173 | if (dlen != sizeof(tlsext_alpn_single_proto)) { | ||
| 174 | FAIL("got clienthello ALPN with length %zu, " | ||
| 175 | "want length %zu\n", dlen, | ||
| 176 | sizeof(tlsext_alpn_single_proto)); | ||
| 177 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
| 178 | sizeof(tlsext_alpn_single_proto)); | ||
| 179 | goto err; | ||
| 180 | } | ||
| 181 | if (memcmp(data, tlsext_alpn_single_proto, dlen) != 0) { | ||
| 182 | FAIL("clienthello ALPN differs:\n"); | ||
| 183 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
| 184 | sizeof(tlsext_alpn_single_proto)); | ||
| 185 | goto err; | ||
| 186 | } | ||
| 187 | |||
| 188 | CBB_cleanup(&cbb); | ||
| 189 | CBB_init(&cbb, 0); | ||
| 190 | free(data); | ||
| 191 | data = NULL; | ||
| 192 | |||
| 193 | /* Make sure we can parse the single proto. */ | ||
| 194 | |||
| 195 | CBS_init(&cbs, tlsext_alpn_single_proto, | ||
| 196 | sizeof(tlsext_alpn_single_proto)); | ||
| 197 | if (!tlsext_alpn_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 198 | FAIL("failed to parse ALPN"); | ||
| 199 | goto err; | ||
| 200 | } | ||
| 201 | if (CBS_len(&cbs) != 0) { | ||
| 202 | FAIL("extension data remaining"); | ||
| 203 | goto err; | ||
| 204 | } | ||
| 205 | |||
| 206 | if (ssl->internal->alpn_client_proto_list_len != | ||
| 207 | sizeof(tlsext_alpn_single_proto_val)) { | ||
| 208 | FAIL("got clienthello ALPN with length %zu, " | ||
| 209 | "want length %zu\n", dlen, | ||
| 210 | sizeof(tlsext_alpn_single_proto_val)); | ||
| 211 | compare_data(ssl->internal->alpn_client_proto_list, | ||
| 212 | ssl->internal->alpn_client_proto_list_len, | ||
| 213 | tlsext_alpn_single_proto_val, | ||
| 214 | sizeof(tlsext_alpn_single_proto_val)); | ||
| 215 | goto err; | ||
| 216 | } | ||
| 217 | if (memcmp(ssl->internal->alpn_client_proto_list, | ||
| 218 | tlsext_alpn_single_proto_val, | ||
| 219 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
| 220 | FAIL("clienthello ALPN differs:\n"); | ||
| 221 | compare_data(data, dlen, tlsext_alpn_single_proto_val, | ||
| 222 | sizeof(tlsext_alpn_single_proto_val)); | ||
| 223 | goto err; | ||
| 224 | } | ||
| 225 | |||
| 226 | /* Make sure we can build the clienthello with multiple entries. */ | ||
| 227 | |||
| 228 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_multiple_protos_val, | ||
| 229 | sizeof(tlsext_alpn_multiple_protos_val)) != 0) { | ||
| 230 | FAIL("should be able to set ALPN to http/1.1"); | ||
| 231 | goto err; | ||
| 232 | } | ||
| 233 | if (!tlsext_alpn_clienthello_needs(ssl)) { | ||
| 234 | FAIL("clienthello should need ALPN by now"); | ||
| 235 | goto err; | ||
| 236 | } | ||
| 237 | |||
| 238 | if (!tlsext_alpn_clienthello_build(ssl, &cbb)) { | ||
| 239 | FAIL("clienthello failed to build ALPN\n"); | ||
| 240 | goto err; | ||
| 241 | } | ||
| 242 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 243 | errx(1, "failed to finish CBB"); | ||
| 244 | |||
| 245 | if (dlen != sizeof(tlsext_alpn_multiple_protos)) { | ||
| 246 | FAIL("got clienthello ALPN with length %zu, " | ||
| 247 | "want length %zu\n", dlen, | ||
| 248 | sizeof(tlsext_alpn_multiple_protos)); | ||
| 249 | compare_data(data, dlen, tlsext_alpn_multiple_protos, | ||
| 250 | sizeof(tlsext_alpn_multiple_protos)); | ||
| 251 | goto err; | ||
| 252 | } | ||
| 253 | if (memcmp(data, tlsext_alpn_multiple_protos, dlen) != 0) { | ||
| 254 | FAIL("clienthello ALPN differs:\n"); | ||
| 255 | compare_data(data, dlen, tlsext_alpn_multiple_protos, | ||
| 256 | sizeof(tlsext_alpn_multiple_protos)); | ||
| 257 | goto err; | ||
| 258 | } | ||
| 259 | |||
| 260 | /* Make sure we can parse multiple protos */ | ||
| 261 | |||
| 262 | CBS_init(&cbs, tlsext_alpn_multiple_protos, | ||
| 263 | sizeof(tlsext_alpn_multiple_protos)); | ||
| 264 | if (!tlsext_alpn_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 265 | FAIL("failed to parse ALPN"); | ||
| 266 | goto err; | ||
| 267 | } | ||
| 268 | if (CBS_len(&cbs) != 0) { | ||
| 269 | FAIL("extension data remaining"); | ||
| 270 | goto err; | ||
| 271 | } | ||
| 272 | |||
| 273 | if (ssl->internal->alpn_client_proto_list_len != | ||
| 274 | sizeof(tlsext_alpn_multiple_protos_val)) { | ||
| 275 | FAIL("got clienthello ALPN with length %zu, " | ||
| 276 | "want length %zu\n", dlen, | ||
| 277 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
| 278 | compare_data(ssl->internal->alpn_client_proto_list, | ||
| 279 | ssl->internal->alpn_client_proto_list_len, | ||
| 280 | tlsext_alpn_multiple_protos_val, | ||
| 281 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
| 282 | goto err; | ||
| 283 | } | ||
| 284 | if (memcmp(ssl->internal->alpn_client_proto_list, | ||
| 285 | tlsext_alpn_multiple_protos_val, | ||
| 286 | sizeof(tlsext_alpn_multiple_protos_val)) != 0) { | ||
| 287 | FAIL("clienthello ALPN differs:\n"); | ||
| 288 | compare_data(data, dlen, tlsext_alpn_multiple_protos_val, | ||
| 289 | sizeof(tlsext_alpn_multiple_protos_val)); | ||
| 290 | goto err; | ||
| 291 | } | ||
| 292 | |||
| 293 | /* Make sure we can remove the list and avoid ALPN */ | ||
| 294 | |||
| 295 | free(ssl->internal->alpn_client_proto_list); | ||
| 296 | ssl->internal->alpn_client_proto_list = NULL; | ||
| 297 | ssl->internal->alpn_client_proto_list_len = 0; | ||
| 298 | |||
| 299 | if (tlsext_alpn_clienthello_needs(ssl)) { | ||
| 300 | FAIL("clienthello should need ALPN by default"); | ||
| 301 | goto err; | ||
| 302 | } | ||
| 303 | |||
| 304 | failure = 0; | ||
| 305 | |||
| 306 | err: | ||
| 307 | CBB_cleanup(&cbb); | ||
| 308 | SSL_CTX_free(ssl_ctx); | ||
| 309 | SSL_free(ssl); | ||
| 310 | free(data); | ||
| 311 | |||
| 312 | return (failure); | ||
| 313 | } | ||
| 314 | |||
| 315 | static int | ||
| 316 | test_tlsext_alpn_serverhello(void) | ||
| 317 | { | ||
| 318 | SSL_CTX *ssl_ctx = NULL; | ||
| 319 | SSL *ssl = NULL; | ||
| 320 | uint8_t *data = NULL; | ||
| 321 | CBB cbb; | ||
| 322 | CBS cbs; | ||
| 323 | int failure, alert; | ||
| 324 | size_t dlen; | ||
| 325 | |||
| 326 | CBB_init(&cbb, 0); | ||
| 327 | |||
| 328 | failure = 1; | ||
| 329 | |||
| 330 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 331 | errx(1, "failed to create SSL_CTX"); | ||
| 332 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 333 | errx(1, "failed to create SSL"); | ||
| 334 | |||
| 335 | /* By default, ALPN isn't needed. */ | ||
| 336 | if (tlsext_alpn_serverhello_needs(ssl)) { | ||
| 337 | FAIL("serverhello should not need ALPN by default\n"); | ||
| 338 | goto err; | ||
| 339 | } | ||
| 340 | |||
| 341 | /* | ||
| 342 | * The server has a single ALPN selection which is set by | ||
| 343 | * SSL_CTX_set_alpn_select_cb() and calls SSL_select_next_proto(). | ||
| 344 | * | ||
| 345 | * This will be a plain name and separate length. | ||
| 346 | */ | ||
| 347 | if ((S3I(ssl)->alpn_selected = malloc(sizeof(tlsext_alpn_single_proto_name))) == NULL) { | ||
| 348 | errx(1, "failed to malloc"); | ||
| 349 | } | ||
| 350 | memcpy(S3I(ssl)->alpn_selected, tlsext_alpn_single_proto_name, | ||
| 351 | sizeof(tlsext_alpn_single_proto_name)); | ||
| 352 | S3I(ssl)->alpn_selected_len = sizeof(tlsext_alpn_single_proto_name); | ||
| 353 | |||
| 354 | if (!tlsext_alpn_serverhello_needs(ssl)) { | ||
| 355 | FAIL("serverhello should need ALPN after a protocol is selected\n"); | ||
| 356 | goto err; | ||
| 357 | } | ||
| 358 | |||
| 359 | /* Make sure we can build a serverhello with one protocol */ | ||
| 360 | |||
| 361 | if (!tlsext_alpn_serverhello_build(ssl, &cbb)) { | ||
| 362 | FAIL("serverhello should be able to build a response"); | ||
| 363 | goto err; | ||
| 364 | } | ||
| 365 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 366 | errx(1, "failed to finish CBB"); | ||
| 367 | |||
| 368 | if (dlen != sizeof(tlsext_alpn_single_proto)) { | ||
| 369 | FAIL("got clienthello ALPN with length %zu, " | ||
| 370 | "want length %zu\n", dlen, | ||
| 371 | sizeof(tlsext_alpn_single_proto)); | ||
| 372 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
| 373 | sizeof(tlsext_alpn_single_proto)); | ||
| 374 | goto err; | ||
| 375 | } | ||
| 376 | if (memcmp(data, tlsext_alpn_single_proto, dlen) != 0) { | ||
| 377 | FAIL("clienthello ALPN differs:\n"); | ||
| 378 | compare_data(data, dlen, tlsext_alpn_single_proto, | ||
| 379 | sizeof(tlsext_alpn_single_proto)); | ||
| 380 | goto err; | ||
| 381 | } | ||
| 382 | |||
| 383 | CBB_cleanup(&cbb); | ||
| 384 | CBB_init(&cbb, 0); | ||
| 385 | free(data); | ||
| 386 | data = NULL; | ||
| 387 | |||
| 388 | /* Make sure we can parse the single proto. */ | ||
| 389 | |||
| 390 | CBS_init(&cbs, tlsext_alpn_single_proto, | ||
| 391 | sizeof(tlsext_alpn_single_proto)); | ||
| 392 | |||
| 393 | /* Shouldn't be able to parse without requesting */ | ||
| 394 | if (tlsext_alpn_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 395 | FAIL("Should only parse serverhello if we requested it"); | ||
| 396 | goto err; | ||
| 397 | } | ||
| 398 | |||
| 399 | /* Should be able to parse once requested. */ | ||
| 400 | if (SSL_set_alpn_protos(ssl, tlsext_alpn_single_proto_val, | ||
| 401 | sizeof(tlsext_alpn_single_proto_val)) != 0) { | ||
| 402 | FAIL("should be able to set ALPN to http/1.1"); | ||
| 403 | goto err; | ||
| 404 | } | ||
| 405 | if (!tlsext_alpn_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 406 | FAIL("Should be able to parse serverhello when we request it"); | ||
| 407 | goto err; | ||
| 408 | } | ||
| 409 | if (CBS_len(&cbs) != 0) { | ||
| 410 | FAIL("extension data remaining"); | ||
| 411 | goto err; | ||
| 412 | } | ||
| 413 | |||
| 414 | if (S3I(ssl)->alpn_selected_len != | ||
| 415 | sizeof(tlsext_alpn_single_proto_name)) { | ||
| 416 | FAIL("got serverhello ALPN with length %zu, " | ||
| 417 | "want length %zu\n", dlen, | ||
| 418 | sizeof(tlsext_alpn_single_proto_name)); | ||
| 419 | compare_data(S3I(ssl)->alpn_selected, | ||
| 420 | S3I(ssl)->alpn_selected_len, | ||
| 421 | tlsext_alpn_single_proto_name, | ||
| 422 | sizeof(tlsext_alpn_single_proto_name)); | ||
| 423 | goto err; | ||
| 424 | } | ||
| 425 | if (memcmp(S3I(ssl)->alpn_selected, | ||
| 426 | tlsext_alpn_single_proto_name, | ||
| 427 | sizeof(tlsext_alpn_single_proto_name)) != 0) { | ||
| 428 | FAIL("serverhello ALPN differs:\n"); | ||
| 429 | compare_data(S3I(ssl)->alpn_selected, | ||
| 430 | S3I(ssl)->alpn_selected_len, | ||
| 431 | tlsext_alpn_single_proto_name, | ||
| 432 | sizeof(tlsext_alpn_single_proto_name)); | ||
| 433 | goto err; | ||
| 434 | } | ||
| 435 | |||
| 436 | /* | ||
| 437 | * We should NOT be able to build a serverhello with multiple | ||
| 438 | * protocol names. However, the existing code did not check for this | ||
| 439 | * case because it is passed in as an encoded value. | ||
| 440 | */ | ||
| 441 | |||
| 442 | /* Make sure we can remove the list and avoid ALPN */ | ||
| 443 | |||
| 444 | free(S3I(ssl)->alpn_selected); | ||
| 445 | S3I(ssl)->alpn_selected = NULL; | ||
| 446 | S3I(ssl)->alpn_selected_len = 0; | ||
| 447 | |||
| 448 | if (tlsext_alpn_serverhello_needs(ssl)) { | ||
| 449 | FAIL("serverhello should need ALPN by default"); | ||
| 450 | goto err; | ||
| 451 | } | ||
| 452 | |||
| 453 | failure = 0; | ||
| 454 | |||
| 455 | err: | ||
| 456 | CBB_cleanup(&cbb); | ||
| 457 | SSL_CTX_free(ssl_ctx); | ||
| 458 | SSL_free(ssl); | ||
| 459 | free(data); | ||
| 460 | |||
| 461 | return (failure); | ||
| 462 | |||
| 463 | } | ||
| 464 | |||
| 465 | /* | ||
| 466 | * Supported Elliptic Curves - RFC 4492 section 5.1.1. | ||
| 467 | * | ||
| 468 | * This extension is only used by the client. | ||
| 469 | */ | ||
| 470 | |||
| 471 | static uint8_t tlsext_supportedgroups_clienthello_default[] = { | ||
| 472 | 0x00, 0x06, | ||
| 473 | 0x00, 0x1d, /* X25519 (29) */ | ||
| 474 | 0x00, 0x17, /* secp256r1 (23) */ | ||
| 475 | 0x00, 0x18 /* secp384r1 (24) */ | ||
| 476 | }; | ||
| 477 | |||
| 478 | static uint16_t tlsext_supportedgroups_clienthello_secp384r1_val[] = { | ||
| 479 | 0x0018 /* tls1_ec_nid2curve_id(NID_secp384r1) */ | ||
| 480 | }; | ||
| 481 | static uint8_t tlsext_supportedgroups_clienthello_secp384r1[] = { | ||
| 482 | 0x00, 0x02, | ||
| 483 | 0x00, 0x18 /* secp384r1 (24) */ | ||
| 484 | }; | ||
| 485 | |||
| 486 | /* Example from RFC 4492 section 5.1.1 */ | ||
| 487 | static uint16_t tlsext_supportedgroups_clienthello_nistp192and224_val[] = { | ||
| 488 | 0x0013, /* tls1_ec_nid2curve_id(NID_X9_62_prime192v1) */ | ||
| 489 | 0x0015 /* tls1_ec_nid2curve_id(NID_secp224r1) */ | ||
| 490 | }; | ||
| 491 | static uint8_t tlsext_supportedgroups_clienthello_nistp192and224[] = { | ||
| 492 | 0x00, 0x04, | ||
| 493 | 0x00, 0x13, /* secp192r1 aka NIST P-192 */ | ||
| 494 | 0x00, 0x15 /* secp224r1 aka NIST P-224 */ | ||
| 495 | }; | ||
| 496 | |||
| 497 | static int | ||
| 498 | test_tlsext_supportedgroups_clienthello(void) | ||
| 499 | { | ||
| 500 | unsigned char *data = NULL; | ||
| 501 | SSL_CTX *ssl_ctx = NULL; | ||
| 502 | SSL *ssl = NULL; | ||
| 503 | size_t dlen; | ||
| 504 | int failure, alert; | ||
| 505 | CBB cbb; | ||
| 506 | CBS cbs; | ||
| 507 | |||
| 508 | failure = 1; | ||
| 509 | |||
| 510 | if (!CBB_init(&cbb, 0)) | ||
| 511 | errx(1, "failed to create CBB"); | ||
| 512 | |||
| 513 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 514 | errx(1, "failed to create SSL_CTX"); | ||
| 515 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 516 | errx(1, "failed to create SSL"); | ||
| 517 | |||
| 518 | /* | ||
| 519 | * Default ciphers include EC so we need it by default. | ||
| 520 | */ | ||
| 521 | if (!tlsext_supportedgroups_clienthello_needs(ssl)) { | ||
| 522 | FAIL("clienthello should need Ellipticcurves for default " | ||
| 523 | "ciphers\n"); | ||
| 524 | goto err; | ||
| 525 | } | ||
| 526 | |||
| 527 | /* | ||
| 528 | * Exclude cipher suites so we can test not including it. | ||
| 529 | */ | ||
| 530 | if (!SSL_set_cipher_list(ssl, "TLSv1.2:!ECDHE:!ECDSA")) { | ||
| 531 | FAIL("clienthello should be able to set cipher list\n"); | ||
| 532 | goto err; | ||
| 533 | } | ||
| 534 | if (tlsext_supportedgroups_clienthello_needs(ssl)) { | ||
| 535 | FAIL("clienthello should not need Ellipticcurves\n"); | ||
| 536 | goto err; | ||
| 537 | } | ||
| 538 | |||
| 539 | /* | ||
| 540 | * Use libtls default for the rest of the testing | ||
| 541 | */ | ||
| 542 | if (!SSL_set_cipher_list(ssl, "TLSv1.2+AEAD+ECDHE")) { | ||
| 543 | FAIL("clienthello should be able to set cipher list\n"); | ||
| 544 | goto err; | ||
| 545 | } | ||
| 546 | if (!tlsext_supportedgroups_clienthello_needs(ssl)) { | ||
| 547 | FAIL("clienthello should need Ellipticcurves\n"); | ||
| 548 | goto err; | ||
| 549 | } | ||
| 550 | |||
| 551 | /* | ||
| 552 | * Test with a session secp384r1. The default is used instead. | ||
| 553 | */ | ||
| 554 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 555 | errx(1, "failed to create session"); | ||
| 556 | |||
| 557 | if ((SSI(ssl)->tlsext_supportedgroups = malloc(sizeof(uint16_t))) | ||
| 558 | == NULL) { | ||
| 559 | FAIL("client could not malloc\n"); | ||
| 560 | goto err; | ||
| 561 | } | ||
| 562 | SSI(ssl)->tlsext_supportedgroups[0] = tls1_ec_nid2curve_id(NID_secp384r1); | ||
| 563 | SSI(ssl)->tlsext_supportedgroups_length = 1; | ||
| 564 | |||
| 565 | if (!tlsext_supportedgroups_clienthello_needs(ssl)) { | ||
| 566 | FAIL("clienthello should need Ellipticcurves\n"); | ||
| 567 | goto err; | ||
| 568 | } | ||
| 569 | |||
| 570 | if (!tlsext_supportedgroups_clienthello_build(ssl, &cbb)) { | ||
| 571 | FAIL("clienthello failed to build Ellipticcurves\n"); | ||
| 572 | goto err; | ||
| 573 | } | ||
| 574 | |||
| 575 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 576 | errx(1, "failed to finish CBB"); | ||
| 577 | |||
| 578 | if (dlen != sizeof(tlsext_supportedgroups_clienthello_default)) { | ||
| 579 | FAIL("got clienthello Ellipticcurves with length %zu, " | ||
| 580 | "want length %zu\n", dlen, | ||
| 581 | sizeof(tlsext_supportedgroups_clienthello_default)); | ||
| 582 | compare_data(data, dlen, tlsext_supportedgroups_clienthello_default, | ||
| 583 | sizeof(tlsext_supportedgroups_clienthello_default)); | ||
| 584 | goto err; | ||
| 585 | } | ||
| 586 | |||
| 587 | if (memcmp(data, tlsext_supportedgroups_clienthello_default, dlen) != 0) { | ||
| 588 | FAIL("clienthello Ellipticcurves differs:\n"); | ||
| 589 | compare_data(data, dlen, tlsext_supportedgroups_clienthello_default, | ||
| 590 | sizeof(tlsext_supportedgroups_clienthello_default)); | ||
| 591 | goto err; | ||
| 592 | } | ||
| 593 | |||
| 594 | /* | ||
| 595 | * Test parsing secp384r1 | ||
| 596 | */ | ||
| 597 | CBB_cleanup(&cbb); | ||
| 598 | CBB_init(&cbb, 0); | ||
| 599 | free(data); | ||
| 600 | data = NULL; | ||
| 601 | |||
| 602 | SSL_SESSION_free(ssl->session); | ||
| 603 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 604 | errx(1, "failed to create session"); | ||
| 605 | |||
| 606 | CBS_init(&cbs, tlsext_supportedgroups_clienthello_secp384r1, | ||
| 607 | sizeof(tlsext_supportedgroups_clienthello_secp384r1)); | ||
| 608 | if (!tlsext_supportedgroups_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 609 | FAIL("failed to parse clienthello Ellipticcurves\n"); | ||
| 610 | goto err; | ||
| 611 | } | ||
| 612 | if (CBS_len(&cbs) != 0) { | ||
| 613 | FAIL("extension data remaining"); | ||
| 614 | goto err; | ||
| 615 | } | ||
| 616 | |||
| 617 | if (SSI(ssl)->tlsext_supportedgroups_length != | ||
| 618 | sizeof(tlsext_supportedgroups_clienthello_secp384r1_val) / sizeof(uint16_t)) { | ||
| 619 | FAIL("no tlsext_ellipticcurves from clienthello " | ||
| 620 | "Ellipticcurves\n"); | ||
| 621 | goto err; | ||
| 622 | } | ||
| 623 | |||
| 624 | if (memcmp(SSI(ssl)->tlsext_supportedgroups, | ||
| 625 | tlsext_supportedgroups_clienthello_secp384r1_val, | ||
| 626 | sizeof(tlsext_supportedgroups_clienthello_secp384r1_val)) != 0) { | ||
| 627 | FAIL("clienthello had an incorrect Ellipticcurves " | ||
| 628 | "entry\n"); | ||
| 629 | compare_data2(SSI(ssl)->tlsext_supportedgroups, | ||
| 630 | SSI(ssl)->tlsext_supportedgroups_length * 2, | ||
| 631 | tlsext_supportedgroups_clienthello_secp384r1_val, | ||
| 632 | sizeof(tlsext_supportedgroups_clienthello_secp384r1_val)); | ||
| 633 | goto err; | ||
| 634 | } | ||
| 635 | |||
| 636 | /* | ||
| 637 | * Use a custom order. | ||
| 638 | */ | ||
| 639 | CBB_cleanup(&cbb); | ||
| 640 | CBB_init(&cbb, 0); | ||
| 641 | |||
| 642 | SSL_SESSION_free(ssl->session); | ||
| 643 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 644 | errx(1, "failed to create session"); | ||
| 645 | |||
| 646 | if ((ssl->internal->tlsext_supportedgroups = malloc(sizeof(uint16_t) * 2)) == NULL) { | ||
| 647 | FAIL("client could not malloc\n"); | ||
| 648 | goto err; | ||
| 649 | } | ||
| 650 | ssl->internal->tlsext_supportedgroups[0] = tls1_ec_nid2curve_id(NID_X9_62_prime192v1); | ||
| 651 | ssl->internal->tlsext_supportedgroups[1] = tls1_ec_nid2curve_id(NID_secp224r1); | ||
| 652 | ssl->internal->tlsext_supportedgroups_length = 2; | ||
| 653 | |||
| 654 | if (!tlsext_supportedgroups_clienthello_needs(ssl)) { | ||
| 655 | FAIL("clienthello should need Ellipticcurves\n"); | ||
| 656 | goto err; | ||
| 657 | } | ||
| 658 | |||
| 659 | if (!tlsext_supportedgroups_clienthello_build(ssl, &cbb)) { | ||
| 660 | FAIL("clienthello failed to build Ellipticcurves\n"); | ||
| 661 | goto err; | ||
| 662 | } | ||
| 663 | |||
| 664 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 665 | errx(1, "failed to finish CBB"); | ||
| 666 | |||
| 667 | if (dlen != sizeof(tlsext_supportedgroups_clienthello_nistp192and224)) { | ||
| 668 | FAIL("got clienthello Ellipticcurves with length %zu, " | ||
| 669 | "want length %zu\n", dlen, | ||
| 670 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224)); | ||
| 671 | fprintf(stderr, "received:\n"); | ||
| 672 | hexdump(data, dlen); | ||
| 673 | fprintf(stderr, "test data:\n"); | ||
| 674 | hexdump(tlsext_supportedgroups_clienthello_nistp192and224, | ||
| 675 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224)); | ||
| 676 | goto err; | ||
| 677 | } | ||
| 678 | |||
| 679 | if (memcmp(data, tlsext_supportedgroups_clienthello_nistp192and224, dlen) != 0) { | ||
| 680 | FAIL("clienthello Ellipticcurves differs:\n"); | ||
| 681 | fprintf(stderr, "received:\n"); | ||
| 682 | hexdump(data, dlen); | ||
| 683 | fprintf(stderr, "test data:\n"); | ||
| 684 | hexdump(tlsext_supportedgroups_clienthello_nistp192and224, | ||
| 685 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224)); | ||
| 686 | goto err; | ||
| 687 | } | ||
| 688 | |||
| 689 | /* | ||
| 690 | * Parse non-default curves to session. | ||
| 691 | */ | ||
| 692 | CBB_cleanup(&cbb); | ||
| 693 | CBB_init(&cbb, 0); | ||
| 694 | free(data); | ||
| 695 | data = NULL; | ||
| 696 | |||
| 697 | SSL_SESSION_free(ssl->session); | ||
| 698 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 699 | errx(1, "failed to create session"); | ||
| 700 | |||
| 701 | /* Reset back to the default list. */ | ||
| 702 | free(ssl->internal->tlsext_supportedgroups); | ||
| 703 | ssl->internal->tlsext_supportedgroups = NULL; | ||
| 704 | ssl->internal->tlsext_supportedgroups_length = 0; | ||
| 705 | |||
| 706 | CBS_init(&cbs, tlsext_supportedgroups_clienthello_nistp192and224, | ||
| 707 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224)); | ||
| 708 | if (!tlsext_supportedgroups_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 709 | FAIL("failed to parse clienthello Ellipticcurves\n"); | ||
| 710 | goto err; | ||
| 711 | } | ||
| 712 | if (CBS_len(&cbs) != 0) { | ||
| 713 | FAIL("extension data remaining"); | ||
| 714 | goto err; | ||
| 715 | } | ||
| 716 | |||
| 717 | if (SSI(ssl)->tlsext_supportedgroups_length != | ||
| 718 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224_val) / sizeof(uint16_t)) { | ||
| 719 | FAIL("no tlsext_ellipticcurves from clienthello " | ||
| 720 | "Ellipticcurves\n"); | ||
| 721 | goto err; | ||
| 722 | } | ||
| 723 | |||
| 724 | if (memcmp(SSI(ssl)->tlsext_supportedgroups, | ||
| 725 | tlsext_supportedgroups_clienthello_nistp192and224_val, | ||
| 726 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224_val)) != 0) { | ||
| 727 | FAIL("clienthello had an incorrect Ellipticcurves entry\n"); | ||
| 728 | compare_data2(SSI(ssl)->tlsext_supportedgroups, | ||
| 729 | SSI(ssl)->tlsext_supportedgroups_length * 2, | ||
| 730 | tlsext_supportedgroups_clienthello_nistp192and224_val, | ||
| 731 | sizeof(tlsext_supportedgroups_clienthello_nistp192and224_val)); | ||
| 732 | goto err; | ||
| 733 | } | ||
| 734 | |||
| 735 | failure = 0; | ||
| 736 | |||
| 737 | err: | ||
| 738 | CBB_cleanup(&cbb); | ||
| 739 | SSL_CTX_free(ssl_ctx); | ||
| 740 | SSL_free(ssl); | ||
| 741 | free(data); | ||
| 742 | |||
| 743 | return (failure); | ||
| 744 | } | ||
| 745 | |||
| 746 | |||
| 747 | /* elliptic_curves is only used by the client so this doesn't test much. */ | ||
| 748 | static int | ||
| 749 | test_tlsext_supportedgroups_serverhello(void) | ||
| 750 | { | ||
| 751 | SSL_CTX *ssl_ctx = NULL; | ||
| 752 | SSL *ssl = NULL; | ||
| 753 | int failure; | ||
| 754 | |||
| 755 | failure = 1; | ||
| 756 | |||
| 757 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 758 | errx(1, "failed to create SSL_CTX"); | ||
| 759 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 760 | errx(1, "failed to create SSL"); | ||
| 761 | |||
| 762 | if (tlsext_supportedgroups_serverhello_needs(ssl)) { | ||
| 763 | FAIL("serverhello should not need elliptic_curves\n"); | ||
| 764 | goto err; | ||
| 765 | } | ||
| 766 | |||
| 767 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 768 | errx(1, "failed to create session"); | ||
| 769 | |||
| 770 | if (tlsext_supportedgroups_serverhello_needs(ssl)) { | ||
| 771 | FAIL("serverhello should not need elliptic_curves\n"); | ||
| 772 | goto err; | ||
| 773 | } | ||
| 774 | |||
| 775 | failure = 0; | ||
| 776 | |||
| 777 | err: | ||
| 778 | SSL_CTX_free(ssl_ctx); | ||
| 779 | SSL_free(ssl); | ||
| 780 | |||
| 781 | return (failure); | ||
| 782 | |||
| 783 | } | ||
| 784 | |||
| 785 | /* | ||
| 786 | * Supported Point Formats - RFC 4492 section 5.1.2. | ||
| 787 | * | ||
| 788 | * Examples are from the RFC. Both client and server have the same build and | ||
| 789 | * parse but the needs differ. | ||
| 790 | */ | ||
| 791 | |||
| 792 | static uint8_t tlsext_ecpf_hello_uncompressed_val[] = { | ||
| 793 | TLSEXT_ECPOINTFORMAT_uncompressed | ||
| 794 | }; | ||
| 795 | static uint8_t tlsext_ecpf_hello_uncompressed[] = { | ||
| 796 | 0x01, | ||
| 797 | 0x00 /* TLSEXT_ECPOINTFORMAT_uncompressed */ | ||
| 798 | }; | ||
| 799 | |||
| 800 | static uint8_t tlsext_ecpf_hello_prime[] = { | ||
| 801 | 0x01, | ||
| 802 | 0x01 /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime */ | ||
| 803 | }; | ||
| 804 | |||
| 805 | static uint8_t tlsext_ecpf_hello_prefer_order_val[] = { | ||
| 806 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime, | ||
| 807 | TLSEXT_ECPOINTFORMAT_uncompressed, | ||
| 808 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 | ||
| 809 | }; | ||
| 810 | static uint8_t tlsext_ecpf_hello_prefer_order[] = { | ||
| 811 | 0x03, | ||
| 812 | 0x01, /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime */ | ||
| 813 | 0x00, /* TLSEXT_ECPOINTFORMAT_uncompressed */ | ||
| 814 | 0x02 /* TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 */ | ||
| 815 | }; | ||
| 816 | |||
| 817 | static int | ||
| 818 | test_tlsext_ecpf_clienthello(void) | ||
| 819 | { | ||
| 820 | uint8_t *data = NULL; | ||
| 821 | SSL_CTX *ssl_ctx = NULL; | ||
| 822 | SSL *ssl = NULL; | ||
| 823 | size_t dlen; | ||
| 824 | int failure, alert; | ||
| 825 | CBB cbb; | ||
| 826 | CBS cbs; | ||
| 827 | |||
| 828 | failure = 1; | ||
| 829 | |||
| 830 | CBB_init(&cbb, 0); | ||
| 831 | |||
| 832 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 833 | errx(1, "failed to create SSL_CTX"); | ||
| 834 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 835 | errx(1, "failed to create SSL"); | ||
| 836 | |||
| 837 | /* | ||
| 838 | * Default ciphers include EC so we need it by default. | ||
| 839 | */ | ||
| 840 | if (!tlsext_ecpf_clienthello_needs(ssl)) { | ||
| 841 | FAIL("clienthello should need ECPointFormats for default " | ||
| 842 | "ciphers\n"); | ||
| 843 | goto err; | ||
| 844 | } | ||
| 845 | |||
| 846 | /* | ||
| 847 | * Exclude EC cipher suites so we can test not including it. | ||
| 848 | */ | ||
| 849 | if (!SSL_set_cipher_list(ssl, "ALL:!ECDHE:!ECDH")) { | ||
| 850 | FAIL("clienthello should be able to set cipher list\n"); | ||
| 851 | goto err; | ||
| 852 | } | ||
| 853 | if (tlsext_ecpf_clienthello_needs(ssl)) { | ||
| 854 | FAIL("clienthello should not need ECPointFormats\n"); | ||
| 855 | goto err; | ||
| 856 | } | ||
| 857 | |||
| 858 | /* | ||
| 859 | * Use libtls default for the rest of the testing | ||
| 860 | */ | ||
| 861 | if (!SSL_set_cipher_list(ssl, "TLSv1.2+AEAD+ECDHE")) { | ||
| 862 | FAIL("clienthello should be able to set cipher list\n"); | ||
| 863 | goto err; | ||
| 864 | } | ||
| 865 | if (!tlsext_ecpf_clienthello_needs(ssl)) { | ||
| 866 | FAIL("clienthello should need ECPointFormats\n"); | ||
| 867 | goto err; | ||
| 868 | } | ||
| 869 | |||
| 870 | /* | ||
| 871 | * The default ECPointFormats should only have uncompressed | ||
| 872 | */ | ||
| 873 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 874 | errx(1, "failed to create session"); | ||
| 875 | |||
| 876 | if (!tlsext_ecpf_clienthello_build(ssl, &cbb)) { | ||
| 877 | FAIL("clienthello failed to build ECPointFormats\n"); | ||
| 878 | goto err; | ||
| 879 | } | ||
| 880 | |||
| 881 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 882 | errx(1, "failed to finish CBB"); | ||
| 883 | |||
| 884 | if (dlen != sizeof(tlsext_ecpf_hello_uncompressed)) { | ||
| 885 | FAIL("got clienthello ECPointFormats with length %zu, " | ||
| 886 | "want length %zu\n", dlen, | ||
| 887 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 888 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
| 889 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 890 | goto err; | ||
| 891 | } | ||
| 892 | |||
| 893 | if (memcmp(data, tlsext_ecpf_hello_uncompressed, dlen) != 0) { | ||
| 894 | FAIL("clienthello ECPointFormats differs:\n"); | ||
| 895 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
| 896 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 897 | goto err; | ||
| 898 | } | ||
| 899 | |||
| 900 | /* | ||
| 901 | * Make sure we can parse the default. | ||
| 902 | */ | ||
| 903 | CBB_cleanup(&cbb); | ||
| 904 | CBB_init(&cbb, 0); | ||
| 905 | free(data); | ||
| 906 | data = NULL; | ||
| 907 | |||
| 908 | SSL_SESSION_free(ssl->session); | ||
| 909 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 910 | errx(1, "failed to create session"); | ||
| 911 | |||
| 912 | CBS_init(&cbs, tlsext_ecpf_hello_uncompressed, | ||
| 913 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 914 | if (!tlsext_ecpf_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 915 | FAIL("failed to parse clienthello ECPointFormats\n"); | ||
| 916 | goto err; | ||
| 917 | } | ||
| 918 | if (CBS_len(&cbs) != 0) { | ||
| 919 | FAIL("extension data remaining"); | ||
| 920 | goto err; | ||
| 921 | } | ||
| 922 | |||
| 923 | if (SSI(ssl)->tlsext_ecpointformatlist_length != | ||
| 924 | sizeof(tlsext_ecpf_hello_uncompressed_val)) { | ||
| 925 | FAIL("no tlsext_ecpointformats from clienthello " | ||
| 926 | "ECPointFormats\n"); | ||
| 927 | goto err; | ||
| 928 | } | ||
| 929 | |||
| 930 | if (memcmp(SSI(ssl)->tlsext_ecpointformatlist, | ||
| 931 | tlsext_ecpf_hello_uncompressed_val, | ||
| 932 | sizeof(tlsext_ecpf_hello_uncompressed_val)) != 0) { | ||
| 933 | FAIL("clienthello had an incorrect ECPointFormats entry\n"); | ||
| 934 | goto err; | ||
| 935 | } | ||
| 936 | |||
| 937 | /* | ||
| 938 | * Test with a custom order. | ||
| 939 | */ | ||
| 940 | CBB_cleanup(&cbb); | ||
| 941 | CBB_init(&cbb, 0); | ||
| 942 | free(data); | ||
| 943 | data = NULL; | ||
| 944 | |||
| 945 | SSL_SESSION_free(ssl->session); | ||
| 946 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 947 | errx(1, "failed to create session"); | ||
| 948 | |||
| 949 | if ((ssl->internal->tlsext_ecpointformatlist = malloc(sizeof(uint8_t) * 3)) == NULL) { | ||
| 950 | FAIL("client could not malloc\n"); | ||
| 951 | goto err; | ||
| 952 | } | ||
| 953 | ssl->internal->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
| 954 | ssl->internal->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_uncompressed; | ||
| 955 | ssl->internal->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
| 956 | ssl->internal->tlsext_ecpointformatlist_length = 3; | ||
| 957 | |||
| 958 | if (!tlsext_ecpf_clienthello_needs(ssl)) { | ||
| 959 | FAIL("clienthello should need ECPointFormats with a custom " | ||
| 960 | "format\n"); | ||
| 961 | goto err; | ||
| 962 | } | ||
| 963 | |||
| 964 | if (!tlsext_ecpf_clienthello_build(ssl, &cbb)) { | ||
| 965 | FAIL("clienthello failed to build ECPointFormats\n"); | ||
| 966 | goto err; | ||
| 967 | } | ||
| 968 | |||
| 969 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 970 | errx(1, "failed to finish CBB"); | ||
| 971 | |||
| 972 | if (dlen != sizeof(tlsext_ecpf_hello_prefer_order)) { | ||
| 973 | FAIL("got clienthello ECPointFormats with length %zu, " | ||
| 974 | "want length %zu\n", dlen, | ||
| 975 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 976 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
| 977 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 978 | goto err; | ||
| 979 | } | ||
| 980 | |||
| 981 | if (memcmp(data, tlsext_ecpf_hello_prefer_order, dlen) != 0) { | ||
| 982 | FAIL("clienthello ECPointFormats differs:\n"); | ||
| 983 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
| 984 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 985 | goto err; | ||
| 986 | } | ||
| 987 | |||
| 988 | /* | ||
| 989 | * Make sure that we can parse this custom order. | ||
| 990 | */ | ||
| 991 | CBB_cleanup(&cbb); | ||
| 992 | CBB_init(&cbb, 0); | ||
| 993 | free(data); | ||
| 994 | data = NULL; | ||
| 995 | |||
| 996 | SSL_SESSION_free(ssl->session); | ||
| 997 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 998 | errx(1, "failed to create session"); | ||
| 999 | |||
| 1000 | /* Reset the custom list so we go back to the default uncompressed. */ | ||
| 1001 | free(ssl->internal->tlsext_ecpointformatlist); | ||
| 1002 | ssl->internal->tlsext_ecpointformatlist = NULL; | ||
| 1003 | ssl->internal->tlsext_ecpointformatlist_length = 0; | ||
| 1004 | |||
| 1005 | CBS_init(&cbs, tlsext_ecpf_hello_prefer_order, | ||
| 1006 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 1007 | if (!tlsext_ecpf_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1008 | FAIL("failed to parse clienthello ECPointFormats\n"); | ||
| 1009 | goto err; | ||
| 1010 | } | ||
| 1011 | if (CBS_len(&cbs) != 0) { | ||
| 1012 | FAIL("extension data remaining"); | ||
| 1013 | goto err; | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | if (SSI(ssl)->tlsext_ecpointformatlist_length != | ||
| 1017 | sizeof(tlsext_ecpf_hello_prefer_order_val)) { | ||
| 1018 | FAIL("no tlsext_ecpointformats from clienthello " | ||
| 1019 | "ECPointFormats\n"); | ||
| 1020 | goto err; | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | if (memcmp(SSI(ssl)->tlsext_ecpointformatlist, | ||
| 1024 | tlsext_ecpf_hello_prefer_order_val, | ||
| 1025 | sizeof(tlsext_ecpf_hello_prefer_order_val)) != 0) { | ||
| 1026 | FAIL("clienthello had an incorrect ECPointFormats entry\n"); | ||
| 1027 | goto err; | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | |||
| 1031 | failure = 0; | ||
| 1032 | |||
| 1033 | err: | ||
| 1034 | CBB_cleanup(&cbb); | ||
| 1035 | SSL_CTX_free(ssl_ctx); | ||
| 1036 | SSL_free(ssl); | ||
| 1037 | free(data); | ||
| 1038 | |||
| 1039 | return (failure); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | static int | ||
| 1043 | test_tlsext_ecpf_serverhello(void) | ||
| 1044 | { | ||
| 1045 | uint8_t *data = NULL; | ||
| 1046 | SSL_CTX *ssl_ctx = NULL; | ||
| 1047 | SSL *ssl = NULL; | ||
| 1048 | size_t dlen; | ||
| 1049 | int failure, alert; | ||
| 1050 | CBB cbb; | ||
| 1051 | CBS cbs; | ||
| 1052 | |||
| 1053 | failure = 1; | ||
| 1054 | |||
| 1055 | CBB_init(&cbb, 0); | ||
| 1056 | |||
| 1057 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 1058 | errx(1, "failed to create SSL_CTX"); | ||
| 1059 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1060 | errx(1, "failed to create SSL"); | ||
| 1061 | |||
| 1062 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1063 | errx(1, "failed to create session"); | ||
| 1064 | |||
| 1065 | /* Setup the state so we can call needs. */ | ||
| 1066 | if ((S3I(ssl)->hs.new_cipher = | ||
| 1067 | ssl3_get_cipher_by_id(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305)) | ||
| 1068 | == NULL) { | ||
| 1069 | FAIL("serverhello cannot find cipher\n"); | ||
| 1070 | goto err; | ||
| 1071 | } | ||
| 1072 | if ((SSI(ssl)->tlsext_ecpointformatlist = malloc(sizeof(uint8_t))) | ||
| 1073 | == NULL) { | ||
| 1074 | FAIL("server could not malloc\n"); | ||
| 1075 | goto err; | ||
| 1076 | } | ||
| 1077 | SSI(ssl)->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
| 1078 | SSI(ssl)->tlsext_ecpointformatlist_length = 1; | ||
| 1079 | |||
| 1080 | if (!tlsext_ecpf_serverhello_needs(ssl)) { | ||
| 1081 | FAIL("serverhello should need ECPointFormats now\n"); | ||
| 1082 | goto err; | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | /* | ||
| 1086 | * The server will ignore the session list and use either a custom | ||
| 1087 | * list or the default (uncompressed). | ||
| 1088 | */ | ||
| 1089 | if (!tlsext_ecpf_serverhello_build(ssl, &cbb)) { | ||
| 1090 | FAIL("serverhello failed to build ECPointFormats\n"); | ||
| 1091 | goto err; | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1095 | errx(1, "failed to finish CBB"); | ||
| 1096 | |||
| 1097 | if (dlen != sizeof(tlsext_ecpf_hello_uncompressed)) { | ||
| 1098 | FAIL("got serverhello ECPointFormats with length %zu, " | ||
| 1099 | "want length %zu\n", dlen, | ||
| 1100 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 1101 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
| 1102 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 1103 | goto err; | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | if (memcmp(data, tlsext_ecpf_hello_uncompressed, dlen) != 0) { | ||
| 1107 | FAIL("serverhello ECPointFormats differs:\n"); | ||
| 1108 | compare_data(data, dlen, tlsext_ecpf_hello_uncompressed, | ||
| 1109 | sizeof(tlsext_ecpf_hello_uncompressed)); | ||
| 1110 | goto err; | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | /* | ||
| 1114 | * Cannot parse a non-default list without at least uncompressed. | ||
| 1115 | */ | ||
| 1116 | CBB_cleanup(&cbb); | ||
| 1117 | CBB_init(&cbb, 0); | ||
| 1118 | free(data); | ||
| 1119 | data = NULL; | ||
| 1120 | |||
| 1121 | SSL_SESSION_free(ssl->session); | ||
| 1122 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1123 | errx(1, "failed to create session"); | ||
| 1124 | |||
| 1125 | CBS_init(&cbs, tlsext_ecpf_hello_prime, | ||
| 1126 | sizeof(tlsext_ecpf_hello_prime)); | ||
| 1127 | if (tlsext_ecpf_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1128 | FAIL("must include uncompressed in serverhello ECPointFormats\n"); | ||
| 1129 | goto err; | ||
| 1130 | } | ||
| 1131 | if (CBS_len(&cbs) != 0) { | ||
| 1132 | FAIL("extension data remaining"); | ||
| 1133 | goto err; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | /* | ||
| 1137 | * Test with a custom order that replaces the default uncompressed. | ||
| 1138 | */ | ||
| 1139 | CBB_cleanup(&cbb); | ||
| 1140 | CBB_init(&cbb, 0); | ||
| 1141 | free(data); | ||
| 1142 | data = NULL; | ||
| 1143 | |||
| 1144 | SSL_SESSION_free(ssl->session); | ||
| 1145 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1146 | errx(1, "failed to create session"); | ||
| 1147 | |||
| 1148 | /* Add a session list even though it will be ignored. */ | ||
| 1149 | if ((SSI(ssl)->tlsext_ecpointformatlist = malloc(sizeof(uint8_t))) | ||
| 1150 | == NULL) { | ||
| 1151 | FAIL("server could not malloc\n"); | ||
| 1152 | goto err; | ||
| 1153 | } | ||
| 1154 | SSI(ssl)->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
| 1155 | SSI(ssl)->tlsext_ecpointformatlist_length = 1; | ||
| 1156 | |||
| 1157 | /* Replace the default list with a custom one. */ | ||
| 1158 | if ((ssl->internal->tlsext_ecpointformatlist = malloc(sizeof(uint8_t) * 3)) == NULL) { | ||
| 1159 | FAIL("server could not malloc\n"); | ||
| 1160 | goto err; | ||
| 1161 | } | ||
| 1162 | ssl->internal->tlsext_ecpointformatlist[0] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
| 1163 | ssl->internal->tlsext_ecpointformatlist[1] = TLSEXT_ECPOINTFORMAT_uncompressed; | ||
| 1164 | ssl->internal->tlsext_ecpointformatlist[2] = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | ||
| 1165 | ssl->internal->tlsext_ecpointformatlist_length = 3; | ||
| 1166 | |||
| 1167 | if (!tlsext_ecpf_serverhello_needs(ssl)) { | ||
| 1168 | FAIL("serverhello should need ECPointFormats\n"); | ||
| 1169 | goto err; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | if (!tlsext_ecpf_serverhello_build(ssl, &cbb)) { | ||
| 1173 | FAIL("serverhello failed to build ECPointFormats\n"); | ||
| 1174 | goto err; | ||
| 1175 | } | ||
| 1176 | |||
| 1177 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1178 | errx(1, "failed to finish CBB"); | ||
| 1179 | |||
| 1180 | if (dlen != sizeof(tlsext_ecpf_hello_prefer_order)) { | ||
| 1181 | FAIL("got serverhello ECPointFormats with length %zu, " | ||
| 1182 | "want length %zu\n", dlen, | ||
| 1183 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 1184 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
| 1185 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 1186 | goto err; | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | if (memcmp(data, tlsext_ecpf_hello_prefer_order, dlen) != 0) { | ||
| 1190 | FAIL("serverhello ECPointFormats differs:\n"); | ||
| 1191 | compare_data(data, dlen, tlsext_ecpf_hello_prefer_order, | ||
| 1192 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 1193 | goto err; | ||
| 1194 | } | ||
| 1195 | |||
| 1196 | /* | ||
| 1197 | * Should be able to parse the custom list into a session list. | ||
| 1198 | */ | ||
| 1199 | CBB_cleanup(&cbb); | ||
| 1200 | CBB_init(&cbb, 0); | ||
| 1201 | free(data); | ||
| 1202 | data = NULL; | ||
| 1203 | |||
| 1204 | SSL_SESSION_free(ssl->session); | ||
| 1205 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1206 | errx(1, "failed to create session"); | ||
| 1207 | |||
| 1208 | /* Reset back to the default (uncompressed) */ | ||
| 1209 | free(ssl->internal->tlsext_ecpointformatlist); | ||
| 1210 | ssl->internal->tlsext_ecpointformatlist = NULL; | ||
| 1211 | ssl->internal->tlsext_ecpointformatlist_length = 0; | ||
| 1212 | |||
| 1213 | CBS_init(&cbs, tlsext_ecpf_hello_prefer_order, | ||
| 1214 | sizeof(tlsext_ecpf_hello_prefer_order)); | ||
| 1215 | if (!tlsext_ecpf_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1216 | FAIL("failed to parse serverhello ECPointFormats\n"); | ||
| 1217 | goto err; | ||
| 1218 | } | ||
| 1219 | if (CBS_len(&cbs) != 0) { | ||
| 1220 | FAIL("extension data remaining"); | ||
| 1221 | goto err; | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | if (SSI(ssl)->tlsext_ecpointformatlist_length != | ||
| 1225 | sizeof(tlsext_ecpf_hello_prefer_order_val)) { | ||
| 1226 | FAIL("no tlsext_ecpointformats from serverhello " | ||
| 1227 | "ECPointFormats\n"); | ||
| 1228 | goto err; | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | if (memcmp(SSI(ssl)->tlsext_ecpointformatlist, | ||
| 1232 | tlsext_ecpf_hello_prefer_order_val, | ||
| 1233 | sizeof(tlsext_ecpf_hello_prefer_order_val)) != 0) { | ||
| 1234 | FAIL("serverhello had an incorrect ECPointFormats entry\n"); | ||
| 1235 | goto err; | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | failure = 0; | ||
| 1239 | |||
| 1240 | err: | ||
| 1241 | CBB_cleanup(&cbb); | ||
| 1242 | SSL_CTX_free(ssl_ctx); | ||
| 1243 | SSL_free(ssl); | ||
| 1244 | free(data); | ||
| 1245 | |||
| 1246 | return (failure); | ||
| 1247 | } | ||
| 1248 | |||
| 1249 | /* | ||
| 1250 | * Renegotiation Indication - RFC 5746. | ||
| 1251 | */ | ||
| 1252 | |||
| 1253 | static unsigned char tlsext_ri_prev_client[] = { | ||
| 1254 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 1255 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 1256 | }; | ||
| 1257 | |||
| 1258 | static unsigned char tlsext_ri_prev_server[] = { | ||
| 1259 | 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, | ||
| 1260 | 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, | ||
| 1261 | }; | ||
| 1262 | |||
| 1263 | static unsigned char tlsext_ri_clienthello[] = { | ||
| 1264 | 0x10, | ||
| 1265 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 1266 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 1267 | }; | ||
| 1268 | |||
| 1269 | static unsigned char tlsext_ri_serverhello[] = { | ||
| 1270 | 0x20, | ||
| 1271 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 1272 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 1273 | 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, | ||
| 1274 | 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, | ||
| 1275 | }; | ||
| 1276 | |||
| 1277 | static int | ||
| 1278 | test_tlsext_ri_clienthello(void) | ||
| 1279 | { | ||
| 1280 | unsigned char *data = NULL; | ||
| 1281 | SSL_CTX *ssl_ctx = NULL; | ||
| 1282 | SSL *ssl = NULL; | ||
| 1283 | int failure; | ||
| 1284 | size_t dlen; | ||
| 1285 | int alert; | ||
| 1286 | CBB cbb; | ||
| 1287 | CBS cbs; | ||
| 1288 | |||
| 1289 | failure = 1; | ||
| 1290 | |||
| 1291 | CBB_init(&cbb, 0); | ||
| 1292 | |||
| 1293 | if ((ssl_ctx = SSL_CTX_new(TLSv1_2_client_method())) == NULL) | ||
| 1294 | errx(1, "failed to create SSL_CTX"); | ||
| 1295 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1296 | errx(1, "failed to create SSL"); | ||
| 1297 | |||
| 1298 | if (tlsext_ri_clienthello_needs(ssl)) { | ||
| 1299 | FAIL("clienthello should not need RI\n"); | ||
| 1300 | goto err; | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | if (!SSL_renegotiate(ssl)) { | ||
| 1304 | FAIL("client failed to set renegotiate\n"); | ||
| 1305 | goto err; | ||
| 1306 | } | ||
| 1307 | |||
| 1308 | if (!tlsext_ri_clienthello_needs(ssl)) { | ||
| 1309 | FAIL("clienthello should need RI\n"); | ||
| 1310 | goto err; | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | memcpy(S3I(ssl)->previous_client_finished, tlsext_ri_prev_client, | ||
| 1314 | sizeof(tlsext_ri_prev_client)); | ||
| 1315 | S3I(ssl)->previous_client_finished_len = sizeof(tlsext_ri_prev_client); | ||
| 1316 | |||
| 1317 | S3I(ssl)->renegotiate_seen = 0; | ||
| 1318 | |||
| 1319 | if (!tlsext_ri_clienthello_build(ssl, &cbb)) { | ||
| 1320 | FAIL("clienthello failed to build RI\n"); | ||
| 1321 | goto err; | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1325 | errx(1, "failed to finish CBB"); | ||
| 1326 | |||
| 1327 | if (dlen != sizeof(tlsext_ri_clienthello)) { | ||
| 1328 | FAIL("got clienthello RI with length %zu, " | ||
| 1329 | "want length %zu\n", dlen, sizeof(tlsext_ri_clienthello)); | ||
| 1330 | goto err; | ||
| 1331 | } | ||
| 1332 | |||
| 1333 | if (memcmp(data, tlsext_ri_clienthello, dlen) != 0) { | ||
| 1334 | FAIL("clienthello RI differs:\n"); | ||
| 1335 | fprintf(stderr, "received:\n"); | ||
| 1336 | hexdump(data, dlen); | ||
| 1337 | fprintf(stderr, "test data:\n"); | ||
| 1338 | hexdump(tlsext_ri_clienthello, sizeof(tlsext_ri_clienthello)); | ||
| 1339 | goto err; | ||
| 1340 | } | ||
| 1341 | |||
| 1342 | CBS_init(&cbs, tlsext_ri_clienthello, sizeof(tlsext_ri_clienthello)); | ||
| 1343 | if (!tlsext_ri_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1344 | FAIL("failed to parse clienthello RI\n"); | ||
| 1345 | goto err; | ||
| 1346 | } | ||
| 1347 | if (CBS_len(&cbs) != 0) { | ||
| 1348 | FAIL("extension data remaining"); | ||
| 1349 | goto err; | ||
| 1350 | } | ||
| 1351 | |||
| 1352 | if (S3I(ssl)->renegotiate_seen != 1) { | ||
| 1353 | FAIL("renegotiate seen not set\n"); | ||
| 1354 | goto err; | ||
| 1355 | } | ||
| 1356 | if (S3I(ssl)->send_connection_binding != 1) { | ||
| 1357 | FAIL("send connection binding not set\n"); | ||
| 1358 | goto err; | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | memset(S3I(ssl)->previous_client_finished, 0, | ||
| 1362 | sizeof(S3I(ssl)->previous_client_finished)); | ||
| 1363 | |||
| 1364 | S3I(ssl)->renegotiate_seen = 0; | ||
| 1365 | |||
| 1366 | CBS_init(&cbs, tlsext_ri_clienthello, sizeof(tlsext_ri_clienthello)); | ||
| 1367 | if (tlsext_ri_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1368 | FAIL("parsed invalid clienthello RI\n"); | ||
| 1369 | failure = 1; | ||
| 1370 | goto err; | ||
| 1371 | } | ||
| 1372 | |||
| 1373 | if (S3I(ssl)->renegotiate_seen == 1) { | ||
| 1374 | FAIL("renegotiate seen set\n"); | ||
| 1375 | goto err; | ||
| 1376 | } | ||
| 1377 | |||
| 1378 | failure = 0; | ||
| 1379 | |||
| 1380 | err: | ||
| 1381 | CBB_cleanup(&cbb); | ||
| 1382 | SSL_CTX_free(ssl_ctx); | ||
| 1383 | SSL_free(ssl); | ||
| 1384 | free(data); | ||
| 1385 | |||
| 1386 | return (failure); | ||
| 1387 | } | ||
| 1388 | |||
| 1389 | static int | ||
| 1390 | test_tlsext_ri_serverhello(void) | ||
| 1391 | { | ||
| 1392 | unsigned char *data = NULL; | ||
| 1393 | SSL_CTX *ssl_ctx = NULL; | ||
| 1394 | SSL *ssl = NULL; | ||
| 1395 | int failure; | ||
| 1396 | size_t dlen; | ||
| 1397 | int alert; | ||
| 1398 | CBB cbb; | ||
| 1399 | CBS cbs; | ||
| 1400 | |||
| 1401 | failure = 1; | ||
| 1402 | |||
| 1403 | CBB_init(&cbb, 0); | ||
| 1404 | |||
| 1405 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 1406 | errx(1, "failed to create SSL_CTX"); | ||
| 1407 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1408 | errx(1, "failed to create SSL"); | ||
| 1409 | |||
| 1410 | if (tlsext_ri_serverhello_needs(ssl)) { | ||
| 1411 | FAIL("serverhello should not need RI\n"); | ||
| 1412 | goto err; | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | S3I(ssl)->send_connection_binding = 1; | ||
| 1416 | |||
| 1417 | if (!tlsext_ri_serverhello_needs(ssl)) { | ||
| 1418 | FAIL("serverhello should need RI\n"); | ||
| 1419 | goto err; | ||
| 1420 | } | ||
| 1421 | |||
| 1422 | memcpy(S3I(ssl)->previous_client_finished, tlsext_ri_prev_client, | ||
| 1423 | sizeof(tlsext_ri_prev_client)); | ||
| 1424 | S3I(ssl)->previous_client_finished_len = sizeof(tlsext_ri_prev_client); | ||
| 1425 | |||
| 1426 | memcpy(S3I(ssl)->previous_server_finished, tlsext_ri_prev_server, | ||
| 1427 | sizeof(tlsext_ri_prev_server)); | ||
| 1428 | S3I(ssl)->previous_server_finished_len = sizeof(tlsext_ri_prev_server); | ||
| 1429 | |||
| 1430 | S3I(ssl)->renegotiate_seen = 0; | ||
| 1431 | |||
| 1432 | if (!tlsext_ri_serverhello_build(ssl, &cbb)) { | ||
| 1433 | FAIL("serverhello failed to build RI\n"); | ||
| 1434 | goto err; | ||
| 1435 | } | ||
| 1436 | |||
| 1437 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1438 | errx(1, "failed to finish CBB"); | ||
| 1439 | |||
| 1440 | if (dlen != sizeof(tlsext_ri_serverhello)) { | ||
| 1441 | FAIL("got serverhello RI with length %zu, " | ||
| 1442 | "want length %zu\n", dlen, sizeof(tlsext_ri_serverhello)); | ||
| 1443 | goto err; | ||
| 1444 | } | ||
| 1445 | |||
| 1446 | if (memcmp(data, tlsext_ri_serverhello, dlen) != 0) { | ||
| 1447 | FAIL("serverhello RI differs:\n"); | ||
| 1448 | fprintf(stderr, "received:\n"); | ||
| 1449 | hexdump(data, dlen); | ||
| 1450 | fprintf(stderr, "test data:\n"); | ||
| 1451 | hexdump(tlsext_ri_serverhello, sizeof(tlsext_ri_serverhello)); | ||
| 1452 | goto err; | ||
| 1453 | } | ||
| 1454 | |||
| 1455 | CBS_init(&cbs, tlsext_ri_serverhello, sizeof(tlsext_ri_serverhello)); | ||
| 1456 | if (!tlsext_ri_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1457 | FAIL("failed to parse serverhello RI\n"); | ||
| 1458 | goto err; | ||
| 1459 | } | ||
| 1460 | if (CBS_len(&cbs) != 0) { | ||
| 1461 | FAIL("extension data remaining"); | ||
| 1462 | goto err; | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | if (S3I(ssl)->renegotiate_seen != 1) { | ||
| 1466 | FAIL("renegotiate seen not set\n"); | ||
| 1467 | goto err; | ||
| 1468 | } | ||
| 1469 | if (S3I(ssl)->send_connection_binding != 1) { | ||
| 1470 | FAIL("send connection binding not set\n"); | ||
| 1471 | goto err; | ||
| 1472 | } | ||
| 1473 | |||
| 1474 | memset(S3I(ssl)->previous_client_finished, 0, | ||
| 1475 | sizeof(S3I(ssl)->previous_client_finished)); | ||
| 1476 | memset(S3I(ssl)->previous_server_finished, 0, | ||
| 1477 | sizeof(S3I(ssl)->previous_server_finished)); | ||
| 1478 | |||
| 1479 | S3I(ssl)->renegotiate_seen = 0; | ||
| 1480 | |||
| 1481 | CBS_init(&cbs, tlsext_ri_serverhello, sizeof(tlsext_ri_serverhello)); | ||
| 1482 | if (tlsext_ri_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1483 | FAIL("parsed invalid serverhello RI\n"); | ||
| 1484 | goto err; | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | if (S3I(ssl)->renegotiate_seen == 1) { | ||
| 1488 | FAIL("renegotiate seen set\n"); | ||
| 1489 | goto err; | ||
| 1490 | } | ||
| 1491 | |||
| 1492 | failure = 0; | ||
| 1493 | |||
| 1494 | err: | ||
| 1495 | CBB_cleanup(&cbb); | ||
| 1496 | SSL_CTX_free(ssl_ctx); | ||
| 1497 | SSL_free(ssl); | ||
| 1498 | free(data); | ||
| 1499 | |||
| 1500 | return (failure); | ||
| 1501 | } | ||
| 1502 | |||
| 1503 | /* | ||
| 1504 | * Signature Algorithms - RFC 5246 section 7.4.1.4.1. | ||
| 1505 | */ | ||
| 1506 | |||
| 1507 | static unsigned char tlsext_sigalgs_clienthello[] = { | ||
| 1508 | 0x00, 0x1a, 0x06, 0x01, 0x06, 0x03, 0xef, 0xef, | ||
| 1509 | 0x05, 0x01, 0x05, 0x03, 0x04, 0x01, 0x04, 0x03, | ||
| 1510 | 0xee, 0xee, 0xed, 0xed, 0x03, 0x01, 0x03, 0x03, | ||
| 1511 | 0x02, 0x01, 0x02, 0x03, | ||
| 1512 | }; | ||
| 1513 | |||
| 1514 | static int | ||
| 1515 | test_tlsext_sigalgs_clienthello(void) | ||
| 1516 | { | ||
| 1517 | unsigned char *data = NULL; | ||
| 1518 | SSL_CTX *ssl_ctx = NULL; | ||
| 1519 | SSL *ssl = NULL; | ||
| 1520 | int failure = 0; | ||
| 1521 | size_t dlen; | ||
| 1522 | int alert; | ||
| 1523 | CBB cbb; | ||
| 1524 | CBS cbs; | ||
| 1525 | |||
| 1526 | CBB_init(&cbb, 0); | ||
| 1527 | |||
| 1528 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 1529 | errx(1, "failed to create SSL_CTX"); | ||
| 1530 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1531 | errx(1, "failed to create SSL"); | ||
| 1532 | |||
| 1533 | ssl->client_version = TLS1_1_VERSION; | ||
| 1534 | |||
| 1535 | if (tlsext_sigalgs_clienthello_needs(ssl)) { | ||
| 1536 | fprintf(stderr, "FAIL: clienthello should not need sigalgs\n"); | ||
| 1537 | failure = 1; | ||
| 1538 | goto done; | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | ssl->client_version = TLS1_2_VERSION; | ||
| 1542 | |||
| 1543 | if (!tlsext_sigalgs_clienthello_needs(ssl)) { | ||
| 1544 | fprintf(stderr, "FAIL: clienthello should need sigalgs\n"); | ||
| 1545 | failure = 1; | ||
| 1546 | goto done; | ||
| 1547 | } | ||
| 1548 | |||
| 1549 | if (!tlsext_sigalgs_clienthello_build(ssl, &cbb)) { | ||
| 1550 | fprintf(stderr, "FAIL: clienthello failed to build sigalgs\n"); | ||
| 1551 | failure = 1; | ||
| 1552 | goto done; | ||
| 1553 | } | ||
| 1554 | |||
| 1555 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1556 | errx(1, "failed to finish CBB"); | ||
| 1557 | |||
| 1558 | if (dlen != sizeof(tlsext_sigalgs_clienthello)) { | ||
| 1559 | fprintf(stderr, "FAIL: got clienthello sigalgs with length %zu, " | ||
| 1560 | "want length %zu\n", dlen, sizeof(tlsext_sigalgs_clienthello)); | ||
| 1561 | failure = 1; | ||
| 1562 | goto done; | ||
| 1563 | } | ||
| 1564 | |||
| 1565 | if (memcmp(data, tlsext_sigalgs_clienthello, dlen) != 0) { | ||
| 1566 | fprintf(stderr, "FAIL: clienthello SNI differs:\n"); | ||
| 1567 | fprintf(stderr, "received:\n"); | ||
| 1568 | hexdump(data, dlen); | ||
| 1569 | fprintf(stderr, "test data:\n"); | ||
| 1570 | hexdump(tlsext_sigalgs_clienthello, sizeof(tlsext_sigalgs_clienthello)); | ||
| 1571 | failure = 1; | ||
| 1572 | goto done; | ||
| 1573 | } | ||
| 1574 | |||
| 1575 | CBS_init(&cbs, tlsext_sigalgs_clienthello, sizeof(tlsext_sigalgs_clienthello)); | ||
| 1576 | if (!tlsext_sigalgs_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1577 | fprintf(stderr, "FAIL: failed to parse clienthello SNI\n"); | ||
| 1578 | failure = 1; | ||
| 1579 | goto done; | ||
| 1580 | } | ||
| 1581 | if (CBS_len(&cbs) != 0) { | ||
| 1582 | FAIL("extension data remaining"); | ||
| 1583 | goto done; | ||
| 1584 | } | ||
| 1585 | |||
| 1586 | if (ssl->cert->pkeys[SSL_PKEY_RSA_SIGN].digest != EVP_sha512()) { | ||
| 1587 | fprintf(stderr, "FAIL: RSA sign digest mismatch\n"); | ||
| 1588 | failure = 1; | ||
| 1589 | goto done; | ||
| 1590 | } | ||
| 1591 | if (ssl->cert->pkeys[SSL_PKEY_RSA_ENC].digest != EVP_sha512()) { | ||
| 1592 | fprintf(stderr, "FAIL: RSA enc digest mismatch\n"); | ||
| 1593 | failure = 1; | ||
| 1594 | goto done; | ||
| 1595 | } | ||
| 1596 | if (ssl->cert->pkeys[SSL_PKEY_ECC].digest != EVP_sha512()) { | ||
| 1597 | fprintf(stderr, "FAIL: ECC digest mismatch\n"); | ||
| 1598 | failure = 1; | ||
| 1599 | goto done; | ||
| 1600 | } | ||
| 1601 | if (ssl->cert->pkeys[SSL_PKEY_GOST01].digest != EVP_streebog512()) { | ||
| 1602 | fprintf(stderr, "FAIL: GOST01 digest mismatch\n"); | ||
| 1603 | failure = 1; | ||
| 1604 | goto done; | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | done: | ||
| 1608 | CBB_cleanup(&cbb); | ||
| 1609 | SSL_CTX_free(ssl_ctx); | ||
| 1610 | SSL_free(ssl); | ||
| 1611 | free(data); | ||
| 1612 | |||
| 1613 | return (failure); | ||
| 1614 | } | ||
| 1615 | |||
| 1616 | static int | ||
| 1617 | test_tlsext_sigalgs_serverhello(void) | ||
| 1618 | { | ||
| 1619 | unsigned char *data = NULL; | ||
| 1620 | SSL_CTX *ssl_ctx = NULL; | ||
| 1621 | SSL *ssl = NULL; | ||
| 1622 | int failure = 0; | ||
| 1623 | size_t dlen; | ||
| 1624 | int alert; | ||
| 1625 | CBB cbb; | ||
| 1626 | CBS cbs; | ||
| 1627 | |||
| 1628 | CBB_init(&cbb, 0); | ||
| 1629 | |||
| 1630 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 1631 | errx(1, "failed to create SSL_CTX"); | ||
| 1632 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1633 | errx(1, "failed to create SSL"); | ||
| 1634 | |||
| 1635 | if (tlsext_sigalgs_serverhello_needs(ssl)) { | ||
| 1636 | fprintf(stderr, "FAIL: serverhello should not need sigalgs\n"); | ||
| 1637 | failure = 1; | ||
| 1638 | goto done; | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | if (tlsext_sigalgs_serverhello_build(ssl, &cbb)) { | ||
| 1642 | fprintf(stderr, "FAIL: serverhello should not build sigalgs\n"); | ||
| 1643 | failure = 1; | ||
| 1644 | goto done; | ||
| 1645 | } | ||
| 1646 | |||
| 1647 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1648 | errx(1, "failed to finish CBB"); | ||
| 1649 | |||
| 1650 | CBS_init(&cbs, tlsext_sigalgs_clienthello, sizeof(tlsext_sigalgs_clienthello)); | ||
| 1651 | if (tlsext_sigalgs_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1652 | fprintf(stderr, "FAIL: serverhello should not parse sigalgs\n"); | ||
| 1653 | failure = 1; | ||
| 1654 | goto done; | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | done: | ||
| 1658 | CBB_cleanup(&cbb); | ||
| 1659 | SSL_CTX_free(ssl_ctx); | ||
| 1660 | SSL_free(ssl); | ||
| 1661 | free(data); | ||
| 1662 | |||
| 1663 | return (failure); | ||
| 1664 | } | ||
| 1665 | |||
| 1666 | /* | ||
| 1667 | * Server Name Indication - RFC 6066 section 3. | ||
| 1668 | */ | ||
| 1669 | |||
| 1670 | #define TEST_SNI_SERVERNAME "www.libressl.org" | ||
| 1671 | |||
| 1672 | static unsigned char tlsext_sni_clienthello[] = { | ||
| 1673 | 0x00, 0x13, 0x00, 0x00, 0x10, 0x77, 0x77, 0x77, | ||
| 1674 | 0x2e, 0x6c, 0x69, 0x62, 0x72, 0x65, 0x73, 0x73, | ||
| 1675 | 0x6c, 0x2e, 0x6f, 0x72, 0x67, | ||
| 1676 | }; | ||
| 1677 | |||
| 1678 | static unsigned char tlsext_sni_serverhello[] = { | ||
| 1679 | }; | ||
| 1680 | |||
| 1681 | static int | ||
| 1682 | test_tlsext_sni_clienthello(void) | ||
| 1683 | { | ||
| 1684 | unsigned char *data = NULL; | ||
| 1685 | SSL_CTX *ssl_ctx = NULL; | ||
| 1686 | SSL *ssl = NULL; | ||
| 1687 | int failure; | ||
| 1688 | size_t dlen; | ||
| 1689 | int alert; | ||
| 1690 | CBB cbb; | ||
| 1691 | CBS cbs; | ||
| 1692 | |||
| 1693 | failure = 1; | ||
| 1694 | |||
| 1695 | CBB_init(&cbb, 0); | ||
| 1696 | |||
| 1697 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 1698 | errx(1, "failed to create SSL_CTX"); | ||
| 1699 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1700 | errx(1, "failed to create SSL"); | ||
| 1701 | |||
| 1702 | if (tlsext_sni_clienthello_needs(ssl)) { | ||
| 1703 | FAIL("clienthello should not need SNI\n"); | ||
| 1704 | goto err; | ||
| 1705 | } | ||
| 1706 | |||
| 1707 | if (!SSL_set_tlsext_host_name(ssl, TEST_SNI_SERVERNAME)) { | ||
| 1708 | FAIL("client failed to set server name\n"); | ||
| 1709 | goto err; | ||
| 1710 | } | ||
| 1711 | |||
| 1712 | if (!tlsext_sni_clienthello_needs(ssl)) { | ||
| 1713 | FAIL("clienthello should need SNI\n"); | ||
| 1714 | goto err; | ||
| 1715 | } | ||
| 1716 | |||
| 1717 | if (!tlsext_sni_clienthello_build(ssl, &cbb)) { | ||
| 1718 | FAIL("clienthello failed to build SNI\n"); | ||
| 1719 | goto err; | ||
| 1720 | } | ||
| 1721 | |||
| 1722 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1723 | errx(1, "failed to finish CBB"); | ||
| 1724 | |||
| 1725 | if (dlen != sizeof(tlsext_sni_clienthello)) { | ||
| 1726 | FAIL("got clienthello SNI with length %zu, " | ||
| 1727 | "want length %zu\n", dlen, sizeof(tlsext_sni_clienthello)); | ||
| 1728 | goto err; | ||
| 1729 | } | ||
| 1730 | |||
| 1731 | if (memcmp(data, tlsext_sni_clienthello, dlen) != 0) { | ||
| 1732 | FAIL("clienthello SNI differs:\n"); | ||
| 1733 | fprintf(stderr, "received:\n"); | ||
| 1734 | hexdump(data, dlen); | ||
| 1735 | fprintf(stderr, "test data:\n"); | ||
| 1736 | hexdump(tlsext_sni_clienthello, sizeof(tlsext_sni_clienthello)); | ||
| 1737 | goto err; | ||
| 1738 | } | ||
| 1739 | |||
| 1740 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1741 | errx(1, "failed to create session"); | ||
| 1742 | |||
| 1743 | ssl->internal->hit = 0; | ||
| 1744 | |||
| 1745 | CBS_init(&cbs, tlsext_sni_clienthello, sizeof(tlsext_sni_clienthello)); | ||
| 1746 | if (!tlsext_sni_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1747 | FAIL("failed to parse clienthello SNI\n"); | ||
| 1748 | goto err; | ||
| 1749 | } | ||
| 1750 | if (CBS_len(&cbs) != 0) { | ||
| 1751 | FAIL("extension data remaining"); | ||
| 1752 | goto err; | ||
| 1753 | } | ||
| 1754 | |||
| 1755 | if (ssl->session->tlsext_hostname == NULL) { | ||
| 1756 | FAIL("no tlsext_hostname from clienthello SNI\n"); | ||
| 1757 | goto err; | ||
| 1758 | } | ||
| 1759 | |||
| 1760 | if (strlen(ssl->session->tlsext_hostname) != strlen(TEST_SNI_SERVERNAME) || | ||
| 1761 | strncmp(ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME, | ||
| 1762 | strlen(TEST_SNI_SERVERNAME)) != 0) { | ||
| 1763 | FAIL("got tlsext_hostname `%s', want `%s'\n", | ||
| 1764 | ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME); | ||
| 1765 | goto err; | ||
| 1766 | } | ||
| 1767 | |||
| 1768 | ssl->internal->hit = 1; | ||
| 1769 | |||
| 1770 | if ((ssl->session->tlsext_hostname = strdup("notthesame.libressl.org")) == | ||
| 1771 | NULL) | ||
| 1772 | errx(1, "failed to strdup tlsext_hostname"); | ||
| 1773 | |||
| 1774 | CBS_init(&cbs, tlsext_sni_clienthello, sizeof(tlsext_sni_clienthello)); | ||
| 1775 | if (tlsext_sni_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1776 | FAIL("parsed clienthello with mismatched SNI\n"); | ||
| 1777 | goto err; | ||
| 1778 | } | ||
| 1779 | |||
| 1780 | failure = 0; | ||
| 1781 | |||
| 1782 | err: | ||
| 1783 | CBB_cleanup(&cbb); | ||
| 1784 | SSL_CTX_free(ssl_ctx); | ||
| 1785 | SSL_free(ssl); | ||
| 1786 | free(data); | ||
| 1787 | |||
| 1788 | return (failure); | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | static int | ||
| 1792 | test_tlsext_sni_serverhello(void) | ||
| 1793 | { | ||
| 1794 | unsigned char *data = NULL; | ||
| 1795 | SSL_CTX *ssl_ctx = NULL; | ||
| 1796 | SSL *ssl = NULL; | ||
| 1797 | int failure; | ||
| 1798 | size_t dlen; | ||
| 1799 | int alert; | ||
| 1800 | CBB cbb; | ||
| 1801 | CBS cbs; | ||
| 1802 | |||
| 1803 | failure = 1; | ||
| 1804 | |||
| 1805 | CBB_init(&cbb, 0); | ||
| 1806 | |||
| 1807 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 1808 | errx(1, "failed to create SSL_CTX"); | ||
| 1809 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1810 | errx(1, "failed to create SSL"); | ||
| 1811 | |||
| 1812 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 1813 | errx(1, "failed to create session"); | ||
| 1814 | |||
| 1815 | if (tlsext_sni_serverhello_needs(ssl)) { | ||
| 1816 | FAIL("serverhello should not need SNI\n"); | ||
| 1817 | goto err; | ||
| 1818 | } | ||
| 1819 | |||
| 1820 | if (!SSL_set_tlsext_host_name(ssl, TEST_SNI_SERVERNAME)) { | ||
| 1821 | FAIL("client failed to set server name\n"); | ||
| 1822 | goto err; | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | if ((ssl->session->tlsext_hostname = strdup(TEST_SNI_SERVERNAME)) == | ||
| 1826 | NULL) | ||
| 1827 | errx(1, "failed to strdup tlsext_hostname"); | ||
| 1828 | |||
| 1829 | if (!tlsext_sni_serverhello_needs(ssl)) { | ||
| 1830 | FAIL("serverhello should need SNI\n"); | ||
| 1831 | goto err; | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | if (!tlsext_sni_serverhello_build(ssl, &cbb)) { | ||
| 1835 | FAIL("serverhello failed to build SNI\n"); | ||
| 1836 | goto err; | ||
| 1837 | } | ||
| 1838 | |||
| 1839 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1840 | errx(1, "failed to finish CBB"); | ||
| 1841 | |||
| 1842 | if (dlen != sizeof(tlsext_sni_serverhello)) { | ||
| 1843 | FAIL("got serverhello SNI with length %zu, " | ||
| 1844 | "want length %zu\n", dlen, sizeof(tlsext_sni_serverhello)); | ||
| 1845 | goto err; | ||
| 1846 | } | ||
| 1847 | |||
| 1848 | if (memcmp(data, tlsext_sni_serverhello, dlen) != 0) { | ||
| 1849 | FAIL("serverhello SNI differs:\n"); | ||
| 1850 | fprintf(stderr, "received:\n"); | ||
| 1851 | hexdump(data, dlen); | ||
| 1852 | fprintf(stderr, "test data:\n"); | ||
| 1853 | hexdump(tlsext_sni_serverhello, sizeof(tlsext_sni_serverhello)); | ||
| 1854 | goto err; | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | free(ssl->session->tlsext_hostname); | ||
| 1858 | ssl->session->tlsext_hostname = NULL; | ||
| 1859 | |||
| 1860 | CBS_init(&cbs, tlsext_sni_serverhello, sizeof(tlsext_sni_serverhello)); | ||
| 1861 | if (!tlsext_sni_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 1862 | FAIL("failed to parse serverhello SNI\n"); | ||
| 1863 | goto err; | ||
| 1864 | } | ||
| 1865 | if (CBS_len(&cbs) != 0) { | ||
| 1866 | FAIL("extension data remaining"); | ||
| 1867 | goto err; | ||
| 1868 | } | ||
| 1869 | |||
| 1870 | if (ssl->session->tlsext_hostname == NULL) { | ||
| 1871 | FAIL("no tlsext_hostname after serverhello SNI\n"); | ||
| 1872 | goto err; | ||
| 1873 | } | ||
| 1874 | |||
| 1875 | if (strlen(ssl->session->tlsext_hostname) != strlen(TEST_SNI_SERVERNAME) || | ||
| 1876 | strncmp(ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME, | ||
| 1877 | strlen(TEST_SNI_SERVERNAME)) != 0) { | ||
| 1878 | FAIL("got tlsext_hostname `%s', want `%s'\n", | ||
| 1879 | ssl->session->tlsext_hostname, TEST_SNI_SERVERNAME); | ||
| 1880 | goto err; | ||
| 1881 | } | ||
| 1882 | |||
| 1883 | failure = 0; | ||
| 1884 | |||
| 1885 | err: | ||
| 1886 | CBB_cleanup(&cbb); | ||
| 1887 | SSL_CTX_free(ssl_ctx); | ||
| 1888 | SSL_free(ssl); | ||
| 1889 | free(data); | ||
| 1890 | |||
| 1891 | return (failure); | ||
| 1892 | } | ||
| 1893 | |||
| 1894 | static unsigned char tls_ocsp_clienthello_default[] = { | ||
| 1895 | 0x01, 0x00, 0x00, 0x00, 0x00 | ||
| 1896 | }; | ||
| 1897 | |||
| 1898 | static int | ||
| 1899 | test_tlsext_ocsp_clienthello(void) | ||
| 1900 | { | ||
| 1901 | unsigned char *data = NULL; | ||
| 1902 | SSL_CTX *ssl_ctx = NULL; | ||
| 1903 | SSL *ssl = NULL; | ||
| 1904 | size_t dlen; | ||
| 1905 | int failure; | ||
| 1906 | int alert; | ||
| 1907 | CBB cbb; | ||
| 1908 | CBS cbs; | ||
| 1909 | |||
| 1910 | failure = 1; | ||
| 1911 | |||
| 1912 | CBB_init(&cbb, 0); | ||
| 1913 | |||
| 1914 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 1915 | errx(1, "failed to create SSL_CTX"); | ||
| 1916 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1917 | errx(1, "failed to create SSL"); | ||
| 1918 | |||
| 1919 | if (tlsext_ocsp_clienthello_needs(ssl)) { | ||
| 1920 | FAIL("clienthello should not need ocsp\n"); | ||
| 1921 | goto err; | ||
| 1922 | } | ||
| 1923 | SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp); | ||
| 1924 | |||
| 1925 | if (!tlsext_ocsp_clienthello_needs(ssl)) { | ||
| 1926 | FAIL("clienthello should need ocsp\n"); | ||
| 1927 | goto err; | ||
| 1928 | } | ||
| 1929 | if (!tlsext_ocsp_clienthello_build(ssl, &cbb)) { | ||
| 1930 | FAIL("clienthello failed to build SNI\n"); | ||
| 1931 | goto err; | ||
| 1932 | } | ||
| 1933 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 1934 | errx(1, "failed to finish CBB"); | ||
| 1935 | |||
| 1936 | if (dlen != sizeof(tls_ocsp_clienthello_default)) { | ||
| 1937 | FAIL("got ocsp clienthello with length %zu, " | ||
| 1938 | "want length %zu\n", dlen, | ||
| 1939 | sizeof(tls_ocsp_clienthello_default)); | ||
| 1940 | goto err; | ||
| 1941 | } | ||
| 1942 | if (memcmp(data, tls_ocsp_clienthello_default, dlen) != 0) { | ||
| 1943 | FAIL("ocsp clienthello differs:\n"); | ||
| 1944 | fprintf(stderr, "received:\n"); | ||
| 1945 | hexdump(data, dlen); | ||
| 1946 | fprintf(stderr, "test data:\n"); | ||
| 1947 | hexdump(tls_ocsp_clienthello_default, | ||
| 1948 | sizeof(tls_ocsp_clienthello_default)); | ||
| 1949 | goto err; | ||
| 1950 | } | ||
| 1951 | CBS_init(&cbs, tls_ocsp_clienthello_default, | ||
| 1952 | sizeof(tls_ocsp_clienthello_default)); | ||
| 1953 | if (!tlsext_ocsp_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 1954 | FAIL("failed to parse ocsp clienthello\n"); | ||
| 1955 | goto err; | ||
| 1956 | } | ||
| 1957 | if (CBS_len(&cbs) != 0) { | ||
| 1958 | FAIL("extension data remaining"); | ||
| 1959 | goto err; | ||
| 1960 | } | ||
| 1961 | |||
| 1962 | failure = 0; | ||
| 1963 | |||
| 1964 | err: | ||
| 1965 | CBB_cleanup(&cbb); | ||
| 1966 | SSL_CTX_free(ssl_ctx); | ||
| 1967 | SSL_free(ssl); | ||
| 1968 | free(data); | ||
| 1969 | |||
| 1970 | return (failure); | ||
| 1971 | } | ||
| 1972 | |||
| 1973 | static int | ||
| 1974 | test_tlsext_ocsp_serverhello(void) | ||
| 1975 | { | ||
| 1976 | unsigned char *data = NULL; | ||
| 1977 | SSL_CTX *ssl_ctx = NULL; | ||
| 1978 | SSL *ssl = NULL; | ||
| 1979 | size_t dlen; | ||
| 1980 | int failure; | ||
| 1981 | CBB cbb; | ||
| 1982 | |||
| 1983 | failure = 1; | ||
| 1984 | |||
| 1985 | CBB_init(&cbb, 0); | ||
| 1986 | |||
| 1987 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 1988 | errx(1, "failed to create SSL_CTX"); | ||
| 1989 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 1990 | errx(1, "failed to create SSL"); | ||
| 1991 | |||
| 1992 | if (tlsext_ocsp_serverhello_needs(ssl)) { | ||
| 1993 | FAIL("serverhello should not need ocsp\n"); | ||
| 1994 | goto err; | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | ssl->internal->tlsext_status_expected = 1; | ||
| 1998 | |||
| 1999 | if (!tlsext_ocsp_serverhello_needs(ssl)) { | ||
| 2000 | FAIL("serverhello should need ocsp\n"); | ||
| 2001 | goto err; | ||
| 2002 | } | ||
| 2003 | if (!tlsext_ocsp_serverhello_build(ssl, &cbb)) { | ||
| 2004 | FAIL("serverhello failed to build ocsp\n"); | ||
| 2005 | goto err; | ||
| 2006 | } | ||
| 2007 | |||
| 2008 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2009 | errx(1, "failed to finish CBB"); | ||
| 2010 | |||
| 2011 | failure = 0; | ||
| 2012 | |||
| 2013 | err: | ||
| 2014 | CBB_cleanup(&cbb); | ||
| 2015 | SSL_CTX_free(ssl_ctx); | ||
| 2016 | SSL_free(ssl); | ||
| 2017 | free(data); | ||
| 2018 | |||
| 2019 | return (failure); | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | /* | ||
| 2023 | * Session ticket - RFC 5077 since no known implementations use 4507. | ||
| 2024 | * | ||
| 2025 | * Session tickets can be length 0 (special case) to 2^16-1. | ||
| 2026 | * | ||
| 2027 | * The state is encrypted by the server so it is opaque to the client. | ||
| 2028 | */ | ||
| 2029 | static uint8_t tlsext_sessionticket_hello_min[1]; | ||
| 2030 | static uint8_t tlsext_sessionticket_hello_max[65535]; | ||
| 2031 | |||
| 2032 | static int | ||
| 2033 | test_tlsext_sessionticket_clienthello(void) | ||
| 2034 | { | ||
| 2035 | unsigned char *data = NULL; | ||
| 2036 | SSL_CTX *ssl_ctx = NULL; | ||
| 2037 | SSL *ssl = NULL; | ||
| 2038 | int failure; | ||
| 2039 | CBB cbb; | ||
| 2040 | size_t dlen; | ||
| 2041 | uint8_t dummy[1234]; | ||
| 2042 | |||
| 2043 | failure = 1; | ||
| 2044 | |||
| 2045 | CBB_init(&cbb, 0); | ||
| 2046 | |||
| 2047 | /* Create fake session tickets with random data. */ | ||
| 2048 | arc4random_buf(tlsext_sessionticket_hello_min, | ||
| 2049 | sizeof(tlsext_sessionticket_hello_min)); | ||
| 2050 | arc4random_buf(tlsext_sessionticket_hello_max, | ||
| 2051 | sizeof(tlsext_sessionticket_hello_max)); | ||
| 2052 | |||
| 2053 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 2054 | errx(1, "failed to create SSL_CTX"); | ||
| 2055 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2056 | errx(1, "failed to create SSL"); | ||
| 2057 | |||
| 2058 | /* Should need a ticket by default. */ | ||
| 2059 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2060 | FAIL("clienthello should need Sessionticket for default " | ||
| 2061 | "ciphers\n"); | ||
| 2062 | goto err; | ||
| 2063 | } | ||
| 2064 | |||
| 2065 | /* Test disabling tickets. */ | ||
| 2066 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
| 2067 | FAIL("Cannot disable tickets in the TLS connection"); | ||
| 2068 | return 0; | ||
| 2069 | } | ||
| 2070 | if (tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2071 | FAIL("clienthello should not need SessionTicket if it was disabled"); | ||
| 2072 | goto err; | ||
| 2073 | } | ||
| 2074 | |||
| 2075 | /* Test re-enabling tickets. */ | ||
| 2076 | if ((SSL_clear_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) != 0) { | ||
| 2077 | FAIL("Cannot re-enable tickets in the TLS connection"); | ||
| 2078 | return 0; | ||
| 2079 | } | ||
| 2080 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2081 | FAIL("clienthello should need SessionTicket if it was disabled"); | ||
| 2082 | goto err; | ||
| 2083 | } | ||
| 2084 | |||
| 2085 | /* Since we don't have a session, we should build an empty ticket. */ | ||
| 2086 | if (!tlsext_sessionticket_clienthello_build(ssl, &cbb)) { | ||
| 2087 | FAIL("Cannot build a ticket"); | ||
| 2088 | goto err; | ||
| 2089 | } | ||
| 2090 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
| 2091 | FAIL("Cannot finish CBB"); | ||
| 2092 | goto err; | ||
| 2093 | } | ||
| 2094 | if (dlen != 0) { | ||
| 2095 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
| 2096 | goto err; | ||
| 2097 | } | ||
| 2098 | |||
| 2099 | CBB_cleanup(&cbb); | ||
| 2100 | CBB_init(&cbb, 0); | ||
| 2101 | free(data); | ||
| 2102 | data = NULL; | ||
| 2103 | |||
| 2104 | /* With a new session (but no ticket), we should still have 0 length */ | ||
| 2105 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 2106 | errx(1, "failed to create session"); | ||
| 2107 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2108 | FAIL("Should still want a session ticket with a new session"); | ||
| 2109 | goto err; | ||
| 2110 | } | ||
| 2111 | if (!tlsext_sessionticket_clienthello_build(ssl, &cbb)) { | ||
| 2112 | FAIL("Cannot build a ticket"); | ||
| 2113 | goto err; | ||
| 2114 | } | ||
| 2115 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
| 2116 | FAIL("Cannot finish CBB"); | ||
| 2117 | goto err; | ||
| 2118 | } | ||
| 2119 | if (dlen != 0) { | ||
| 2120 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
| 2121 | goto err; | ||
| 2122 | } | ||
| 2123 | |||
| 2124 | CBB_cleanup(&cbb); | ||
| 2125 | CBB_init(&cbb, 0); | ||
| 2126 | free(data); | ||
| 2127 | data = NULL; | ||
| 2128 | |||
| 2129 | /* With a new session (and ticket), we should use that ticket */ | ||
| 2130 | SSL_SESSION_free(ssl->session); | ||
| 2131 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 2132 | errx(1, "failed to create session"); | ||
| 2133 | |||
| 2134 | arc4random_buf(&dummy, sizeof(dummy)); | ||
| 2135 | if ((ssl->session->tlsext_tick = malloc(sizeof(dummy))) == NULL) { | ||
| 2136 | errx(1, "failed to malloc"); | ||
| 2137 | } | ||
| 2138 | memcpy(ssl->session->tlsext_tick, dummy, sizeof(dummy)); | ||
| 2139 | ssl->session->tlsext_ticklen = sizeof(dummy); | ||
| 2140 | |||
| 2141 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2142 | FAIL("Should still want a session ticket with a new session"); | ||
| 2143 | goto err; | ||
| 2144 | } | ||
| 2145 | if (!tlsext_sessionticket_clienthello_build(ssl, &cbb)) { | ||
| 2146 | FAIL("Cannot build a ticket"); | ||
| 2147 | goto err; | ||
| 2148 | } | ||
| 2149 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
| 2150 | FAIL("Cannot finish CBB"); | ||
| 2151 | goto err; | ||
| 2152 | } | ||
| 2153 | if (dlen != sizeof(dummy)) { | ||
| 2154 | FAIL("Expected %zu length but found %zu\n", sizeof(dummy), dlen); | ||
| 2155 | goto err; | ||
| 2156 | } | ||
| 2157 | if (memcmp(data, dummy, dlen) != 0) { | ||
| 2158 | FAIL("serverhello SNI differs:\n"); | ||
| 2159 | compare_data(data, dlen, | ||
| 2160 | dummy, sizeof(dummy)); | ||
| 2161 | goto err; | ||
| 2162 | } | ||
| 2163 | |||
| 2164 | CBB_cleanup(&cbb); | ||
| 2165 | CBB_init(&cbb, 0); | ||
| 2166 | free(data); | ||
| 2167 | data = NULL; | ||
| 2168 | free(ssl->session->tlsext_tick); | ||
| 2169 | ssl->session->tlsext_tick = NULL; | ||
| 2170 | ssl->session->tlsext_ticklen = 0; | ||
| 2171 | |||
| 2172 | /* | ||
| 2173 | * Send in NULL to disable session tickets at runtime without going | ||
| 2174 | * through SSL_set_options(). | ||
| 2175 | */ | ||
| 2176 | if (!SSL_set_session_ticket_ext(ssl, NULL, 0)) { | ||
| 2177 | FAIL("Could not set a NULL custom ticket"); | ||
| 2178 | goto err; | ||
| 2179 | } | ||
| 2180 | /* Should not need a ticket in this case */ | ||
| 2181 | if (tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2182 | FAIL("Should not want to use session tickets with a NULL custom"); | ||
| 2183 | goto err; | ||
| 2184 | } | ||
| 2185 | |||
| 2186 | /* | ||
| 2187 | * If you want to remove the tlsext_session_ticket behavior, you have | ||
| 2188 | * to do it manually. | ||
| 2189 | */ | ||
| 2190 | free(ssl->internal->tlsext_session_ticket); | ||
| 2191 | ssl->internal->tlsext_session_ticket = NULL; | ||
| 2192 | |||
| 2193 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2194 | FAIL("Should need a session ticket again when the custom one is removed"); | ||
| 2195 | goto err; | ||
| 2196 | } | ||
| 2197 | |||
| 2198 | /* Test a custom session ticket (not recommended in practice) */ | ||
| 2199 | if (!SSL_set_session_ticket_ext(ssl, tlsext_sessionticket_hello_max, | ||
| 2200 | sizeof(tlsext_sessionticket_hello_max))) { | ||
| 2201 | FAIL("Should be able to set a custom ticket"); | ||
| 2202 | goto err; | ||
| 2203 | } | ||
| 2204 | if (!tlsext_sessionticket_clienthello_needs(ssl)) { | ||
| 2205 | FAIL("Should need a session ticket again when the custom one is not empty"); | ||
| 2206 | goto err; | ||
| 2207 | } | ||
| 2208 | if (!tlsext_sessionticket_clienthello_build(ssl, &cbb)) { | ||
| 2209 | FAIL("Cannot build a ticket with a max length random payload"); | ||
| 2210 | goto err; | ||
| 2211 | } | ||
| 2212 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
| 2213 | FAIL("Cannot finish CBB"); | ||
| 2214 | goto err; | ||
| 2215 | } | ||
| 2216 | if (dlen != sizeof(tlsext_sessionticket_hello_max)) { | ||
| 2217 | FAIL("Expected %zu length but found %zu\n", | ||
| 2218 | sizeof(tlsext_sessionticket_hello_max), dlen); | ||
| 2219 | goto err; | ||
| 2220 | } | ||
| 2221 | if (memcmp(data, tlsext_sessionticket_hello_max, | ||
| 2222 | sizeof(tlsext_sessionticket_hello_max)) != 0) { | ||
| 2223 | FAIL("Expected to get what we passed in"); | ||
| 2224 | compare_data(data, dlen, | ||
| 2225 | tlsext_sessionticket_hello_max, | ||
| 2226 | sizeof(tlsext_sessionticket_hello_max)); | ||
| 2227 | goto err; | ||
| 2228 | } | ||
| 2229 | |||
| 2230 | failure = 0; | ||
| 2231 | |||
| 2232 | err: | ||
| 2233 | CBB_cleanup(&cbb); | ||
| 2234 | SSL_CTX_free(ssl_ctx); | ||
| 2235 | SSL_free(ssl); | ||
| 2236 | free(data); | ||
| 2237 | |||
| 2238 | return (failure); | ||
| 2239 | } | ||
| 2240 | |||
| 2241 | |||
| 2242 | static int | ||
| 2243 | test_tlsext_sessionticket_serverhello(void) | ||
| 2244 | { | ||
| 2245 | SSL_CTX *ssl_ctx = NULL; | ||
| 2246 | SSL *ssl = NULL; | ||
| 2247 | int failure; | ||
| 2248 | uint8_t *data; | ||
| 2249 | size_t dlen; | ||
| 2250 | CBB cbb; | ||
| 2251 | |||
| 2252 | CBB_init(&cbb, 0); | ||
| 2253 | |||
| 2254 | failure = 1; | ||
| 2255 | |||
| 2256 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 2257 | errx(1, "failed to create SSL_CTX"); | ||
| 2258 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2259 | errx(1, "failed to create SSL"); | ||
| 2260 | |||
| 2261 | /* | ||
| 2262 | * By default, should not need a session ticket since the ticket | ||
| 2263 | * is not yet expected. | ||
| 2264 | */ | ||
| 2265 | if (tlsext_sessionticket_serverhello_needs(ssl)) { | ||
| 2266 | FAIL("serverhello should not need SessionTicket by default\n"); | ||
| 2267 | goto err; | ||
| 2268 | } | ||
| 2269 | |||
| 2270 | /* Test disabling tickets. */ | ||
| 2271 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
| 2272 | FAIL("Cannot disable tickets in the TLS connection"); | ||
| 2273 | return 0; | ||
| 2274 | } | ||
| 2275 | if (tlsext_sessionticket_serverhello_needs(ssl)) { | ||
| 2276 | FAIL("serverhello should not need SessionTicket if it was disabled"); | ||
| 2277 | goto err; | ||
| 2278 | } | ||
| 2279 | |||
| 2280 | /* Test re-enabling tickets. */ | ||
| 2281 | if ((SSL_clear_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) != 0) { | ||
| 2282 | FAIL("Cannot re-enable tickets in the TLS connection"); | ||
| 2283 | return 0; | ||
| 2284 | } | ||
| 2285 | if (tlsext_sessionticket_serverhello_needs(ssl)) { | ||
| 2286 | FAIL("serverhello should not need SessionTicket yet"); | ||
| 2287 | goto err; | ||
| 2288 | } | ||
| 2289 | |||
| 2290 | /* Set expected to require it. */ | ||
| 2291 | ssl->internal->tlsext_ticket_expected = 1; | ||
| 2292 | if (!tlsext_sessionticket_serverhello_needs(ssl)) { | ||
| 2293 | FAIL("serverhello should now be required for SessionTicket"); | ||
| 2294 | goto err; | ||
| 2295 | } | ||
| 2296 | |||
| 2297 | /* server hello's session ticket should always be 0 length payload. */ | ||
| 2298 | if (!tlsext_sessionticket_serverhello_build(ssl, &cbb)) { | ||
| 2299 | FAIL("Cannot build a ticket with a max length random payload"); | ||
| 2300 | goto err; | ||
| 2301 | } | ||
| 2302 | if (!CBB_finish(&cbb, &data, &dlen)) { | ||
| 2303 | FAIL("Cannot finish CBB"); | ||
| 2304 | goto err; | ||
| 2305 | } | ||
| 2306 | if (dlen != 0) { | ||
| 2307 | FAIL("Expected 0 length but found %zu\n", dlen); | ||
| 2308 | goto err; | ||
| 2309 | } | ||
| 2310 | |||
| 2311 | failure = 0; | ||
| 2312 | |||
| 2313 | err: | ||
| 2314 | SSL_CTX_free(ssl_ctx); | ||
| 2315 | SSL_free(ssl); | ||
| 2316 | |||
| 2317 | return (failure); | ||
| 2318 | } | ||
| 2319 | |||
| 2320 | #ifndef OPENSSL_NO_SRTP | ||
| 2321 | /* | ||
| 2322 | * Supported Secure Real-time Transport Protocol (RFC 5764 section 4.1.1) | ||
| 2323 | */ | ||
| 2324 | |||
| 2325 | /* Colon separated string values */ | ||
| 2326 | const char *tlsext_srtp_single_profile = "SRTP_AES128_CM_SHA1_80"; | ||
| 2327 | const char *tlsext_srtp_multiple_profiles = "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32"; | ||
| 2328 | |||
| 2329 | const char *tlsext_srtp_aes128cmsha80 = "SRTP_AES128_CM_SHA1_80"; | ||
| 2330 | const char *tlsext_srtp_aes128cmsha32 = "SRTP_AES128_CM_SHA1_32"; | ||
| 2331 | |||
| 2332 | const uint8_t tlsext_srtp_single[] = { | ||
| 2333 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
| 2334 | 0x00, 0x02, /* len */ | ||
| 2335 | 0x00, 0x01, /* SRTP_AES128_CM_SHA1_80 */ | ||
| 2336 | 0x00 /* opaque srtp_mki<0..255> */ | ||
| 2337 | }; | ||
| 2338 | |||
| 2339 | const uint8_t tlsext_srtp_multiple[] = { | ||
| 2340 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
| 2341 | 0x00, 0x04, /* len */ | ||
| 2342 | 0x00, 0x01, /* SRTP_AES128_CM_SHA1_80 */ | ||
| 2343 | 0x00, 0x02, /* SRTP_AES128_CM_SHA1_32 */ | ||
| 2344 | 0x00 /* opaque srtp_mki<0..255> */ | ||
| 2345 | }; | ||
| 2346 | |||
| 2347 | const uint8_t tlsext_srtp_multiple_invalid[] = { | ||
| 2348 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
| 2349 | 0x00, 0x04, /* len */ | ||
| 2350 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
| 2351 | 0x00, 0x09, /* arbitrary value not found in known profiles */ | ||
| 2352 | 0x00 /* opaque srtp_mki<0..255> */ | ||
| 2353 | }; | ||
| 2354 | |||
| 2355 | const uint8_t tlsext_srtp_single_invalid[] = { | ||
| 2356 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
| 2357 | 0x00, 0x02, /* len */ | ||
| 2358 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
| 2359 | 0x00 /* opaque srtp_mki<0..255> */ | ||
| 2360 | }; | ||
| 2361 | |||
| 2362 | const uint8_t tlsext_srtp_multiple_one_valid[] = { | ||
| 2363 | /* SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1> */ | ||
| 2364 | 0x00, 0x04, /* len */ | ||
| 2365 | 0x00, 0x08, /* arbitrary value not found in known profiles */ | ||
| 2366 | 0x00, 0x02, /* SRTP_AES128_CM_SHA1_32 */ | ||
| 2367 | 0x00 /* opaque srtp_mki<0..255> */ | ||
| 2368 | }; | ||
| 2369 | |||
| 2370 | static int | ||
| 2371 | test_tlsext_srtp_clienthello(void) | ||
| 2372 | { | ||
| 2373 | SRTP_PROTECTION_PROFILE *prof; | ||
| 2374 | SSL_CTX *ssl_ctx = NULL; | ||
| 2375 | SSL *ssl = NULL; | ||
| 2376 | uint8_t *data = NULL; | ||
| 2377 | CBB cbb; | ||
| 2378 | CBS cbs; | ||
| 2379 | int failure, alert; | ||
| 2380 | size_t dlen; | ||
| 2381 | |||
| 2382 | CBB_init(&cbb, 0); | ||
| 2383 | |||
| 2384 | failure = 1; | ||
| 2385 | |||
| 2386 | /* SRTP is for DTLS */ | ||
| 2387 | if ((ssl_ctx = SSL_CTX_new(DTLSv1_client_method())) == NULL) | ||
| 2388 | errx(1, "failed to create SSL_CTX"); | ||
| 2389 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2390 | errx(1, "failed to create SSL"); | ||
| 2391 | |||
| 2392 | /* By default, we don't need this */ | ||
| 2393 | if (tlsext_srtp_clienthello_needs(ssl)) { | ||
| 2394 | FAIL("clienthello should not need SRTP by default\n"); | ||
| 2395 | goto err; | ||
| 2396 | } | ||
| 2397 | |||
| 2398 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_single_profile) != 0) { | ||
| 2399 | FAIL("should be able to set a single SRTP\n"); | ||
| 2400 | goto err; | ||
| 2401 | } | ||
| 2402 | if (!tlsext_srtp_clienthello_needs(ssl)) { | ||
| 2403 | FAIL("clienthello should need SRTP\n"); | ||
| 2404 | goto err; | ||
| 2405 | } | ||
| 2406 | |||
| 2407 | /* Make sure we can build the clienthello with a single profile. */ | ||
| 2408 | |||
| 2409 | if (!tlsext_srtp_clienthello_build(ssl, &cbb)) { | ||
| 2410 | FAIL("clienthello failed to build SRTP\n"); | ||
| 2411 | goto err; | ||
| 2412 | } | ||
| 2413 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2414 | errx(1, "failed to finish CBB"); | ||
| 2415 | |||
| 2416 | if (dlen != sizeof(tlsext_srtp_single)) { | ||
| 2417 | FAIL("got clienthello SRTP with length %zu, " | ||
| 2418 | "want length %zu\n", dlen, | ||
| 2419 | sizeof(tlsext_srtp_single)); | ||
| 2420 | compare_data(data, dlen, tlsext_srtp_single, | ||
| 2421 | sizeof(tlsext_srtp_single)); | ||
| 2422 | goto err; | ||
| 2423 | } | ||
| 2424 | if (memcmp(data, tlsext_srtp_single, dlen) != 0) { | ||
| 2425 | FAIL("clienthello SRTP differs:\n"); | ||
| 2426 | compare_data(data, dlen, tlsext_srtp_single, | ||
| 2427 | sizeof(tlsext_srtp_single)); | ||
| 2428 | goto err; | ||
| 2429 | } | ||
| 2430 | |||
| 2431 | CBB_cleanup(&cbb); | ||
| 2432 | CBB_init(&cbb, 0); | ||
| 2433 | free(data); | ||
| 2434 | data = NULL; | ||
| 2435 | |||
| 2436 | /* Make sure we can parse the single profile. */ | ||
| 2437 | |||
| 2438 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
| 2439 | FAIL("SRTP profile should not be set yet\n"); | ||
| 2440 | goto err; | ||
| 2441 | } | ||
| 2442 | |||
| 2443 | CBS_init(&cbs, tlsext_srtp_single, sizeof(tlsext_srtp_single)); | ||
| 2444 | if (!tlsext_srtp_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 2445 | FAIL("failed to parse SRTP\n"); | ||
| 2446 | goto err; | ||
| 2447 | } | ||
| 2448 | if (CBS_len(&cbs) != 0) { | ||
| 2449 | FAIL("extension data remaining"); | ||
| 2450 | goto err; | ||
| 2451 | } | ||
| 2452 | |||
| 2453 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
| 2454 | FAIL("SRTP profile should be set now\n"); | ||
| 2455 | goto err; | ||
| 2456 | } | ||
| 2457 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
| 2458 | FAIL("SRTP profile was not set properly\n"); | ||
| 2459 | goto err; | ||
| 2460 | } | ||
| 2461 | |||
| 2462 | if (!tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2463 | FAIL("should send server extension when profile selected\n"); | ||
| 2464 | goto err; | ||
| 2465 | } | ||
| 2466 | |||
| 2467 | /* Make sure we can build the clienthello with multiple entries. */ | ||
| 2468 | |||
| 2469 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_multiple_profiles) != 0) { | ||
| 2470 | FAIL("should be able to set SRTP to multiple profiles\n"); | ||
| 2471 | goto err; | ||
| 2472 | } | ||
| 2473 | if (!tlsext_srtp_clienthello_needs(ssl)) { | ||
| 2474 | FAIL("clienthello should need SRTP by now\n"); | ||
| 2475 | goto err; | ||
| 2476 | } | ||
| 2477 | |||
| 2478 | if (!tlsext_srtp_clienthello_build(ssl, &cbb)) { | ||
| 2479 | FAIL("clienthello failed to build SRTP\n"); | ||
| 2480 | goto err; | ||
| 2481 | } | ||
| 2482 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2483 | errx(1, "failed to finish CBB"); | ||
| 2484 | |||
| 2485 | if (dlen != sizeof(tlsext_srtp_multiple)) { | ||
| 2486 | FAIL("got clienthello SRTP with length %zu, " | ||
| 2487 | "want length %zu\n", dlen, | ||
| 2488 | sizeof(tlsext_srtp_multiple)); | ||
| 2489 | compare_data(data, dlen, tlsext_srtp_multiple, | ||
| 2490 | sizeof(tlsext_srtp_multiple)); | ||
| 2491 | goto err; | ||
| 2492 | } | ||
| 2493 | if (memcmp(data, tlsext_srtp_multiple, dlen) != 0) { | ||
| 2494 | FAIL("clienthello SRTP differs:\n"); | ||
| 2495 | compare_data(data, dlen, tlsext_srtp_multiple, | ||
| 2496 | sizeof(tlsext_srtp_multiple)); | ||
| 2497 | goto err; | ||
| 2498 | } | ||
| 2499 | |||
| 2500 | CBB_cleanup(&cbb); | ||
| 2501 | CBB_init(&cbb, 0); | ||
| 2502 | free(data); | ||
| 2503 | data = NULL; | ||
| 2504 | |||
| 2505 | /* Make sure we can parse multiple profiles (selects server preferred) */ | ||
| 2506 | |||
| 2507 | ssl->internal->srtp_profile = NULL; | ||
| 2508 | |||
| 2509 | CBS_init(&cbs, tlsext_srtp_multiple, | ||
| 2510 | sizeof(tlsext_srtp_multiple)); | ||
| 2511 | if (!tlsext_srtp_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 2512 | FAIL("failed to parse SRTP\n"); | ||
| 2513 | goto err; | ||
| 2514 | } | ||
| 2515 | if (CBS_len(&cbs) != 0) { | ||
| 2516 | FAIL("extension data remaining"); | ||
| 2517 | goto err; | ||
| 2518 | } | ||
| 2519 | |||
| 2520 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
| 2521 | FAIL("SRTP profile should be set now\n"); | ||
| 2522 | goto err; | ||
| 2523 | } | ||
| 2524 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
| 2525 | FAIL("SRTP profile was not set properly\n"); | ||
| 2526 | goto err; | ||
| 2527 | } | ||
| 2528 | |||
| 2529 | if (!tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2530 | FAIL("should send server extension when profile selected\n"); | ||
| 2531 | goto err; | ||
| 2532 | } | ||
| 2533 | |||
| 2534 | /* | ||
| 2535 | * Make sure we can parse the clienthello with multiple entries | ||
| 2536 | * where one is unknown. | ||
| 2537 | */ | ||
| 2538 | ssl->internal->srtp_profile = NULL; | ||
| 2539 | |||
| 2540 | CBS_init(&cbs, tlsext_srtp_multiple_one_valid, | ||
| 2541 | sizeof(tlsext_srtp_multiple_one_valid)); | ||
| 2542 | if (!tlsext_srtp_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 2543 | FAIL("failed to parse SRTP\n"); | ||
| 2544 | goto err; | ||
| 2545 | } | ||
| 2546 | if (CBS_len(&cbs) != 0) { | ||
| 2547 | FAIL("extension data remaining"); | ||
| 2548 | goto err; | ||
| 2549 | } | ||
| 2550 | |||
| 2551 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
| 2552 | FAIL("SRTP profile should be set now\n"); | ||
| 2553 | goto err; | ||
| 2554 | } | ||
| 2555 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha32) != 0) { | ||
| 2556 | FAIL("SRTP profile was not set properly\n"); | ||
| 2557 | goto err; | ||
| 2558 | } | ||
| 2559 | |||
| 2560 | if (!tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2561 | FAIL("should send server extension when profile selected\n"); | ||
| 2562 | goto err; | ||
| 2563 | } | ||
| 2564 | |||
| 2565 | /* Make sure we fall back to negotiated when none work. */ | ||
| 2566 | |||
| 2567 | ssl->internal->srtp_profile = NULL; | ||
| 2568 | |||
| 2569 | CBS_init(&cbs, tlsext_srtp_multiple_invalid, | ||
| 2570 | sizeof(tlsext_srtp_multiple_invalid)); | ||
| 2571 | if (!tlsext_srtp_clienthello_parse(ssl, &cbs, &alert)) { | ||
| 2572 | FAIL("should be able to fall back to negotiated\n"); | ||
| 2573 | goto err; | ||
| 2574 | } | ||
| 2575 | if (CBS_len(&cbs) != 0) { | ||
| 2576 | FAIL("extension data remaining"); | ||
| 2577 | goto err; | ||
| 2578 | } | ||
| 2579 | |||
| 2580 | /* If we fallback, the server should NOT send the extension. */ | ||
| 2581 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
| 2582 | FAIL("should not have selected a profile when none found\n"); | ||
| 2583 | goto err; | ||
| 2584 | } | ||
| 2585 | if (tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2586 | FAIL("should not send server tlsext when no profile found\n"); | ||
| 2587 | goto err; | ||
| 2588 | } | ||
| 2589 | |||
| 2590 | failure = 0; | ||
| 2591 | |||
| 2592 | err: | ||
| 2593 | CBB_cleanup(&cbb); | ||
| 2594 | SSL_CTX_free(ssl_ctx); | ||
| 2595 | SSL_free(ssl); | ||
| 2596 | free(data); | ||
| 2597 | |||
| 2598 | return (failure); | ||
| 2599 | } | ||
| 2600 | |||
| 2601 | static int | ||
| 2602 | test_tlsext_srtp_serverhello(void) | ||
| 2603 | { | ||
| 2604 | SRTP_PROTECTION_PROFILE *prof; | ||
| 2605 | SSL_CTX *ssl_ctx = NULL; | ||
| 2606 | SSL *ssl = NULL; | ||
| 2607 | uint8_t *data = NULL; | ||
| 2608 | CBB cbb; | ||
| 2609 | CBS cbs; | ||
| 2610 | int failure, alert; | ||
| 2611 | size_t dlen; | ||
| 2612 | |||
| 2613 | CBB_init(&cbb, 0); | ||
| 2614 | |||
| 2615 | failure = 1; | ||
| 2616 | |||
| 2617 | /* SRTP is for DTLS */ | ||
| 2618 | if ((ssl_ctx = SSL_CTX_new(DTLSv1_client_method())) == NULL) | ||
| 2619 | errx(1, "failed to create SSL_CTX"); | ||
| 2620 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2621 | errx(1, "failed to create SSL"); | ||
| 2622 | |||
| 2623 | /* By default, we don't need this */ | ||
| 2624 | if (tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2625 | FAIL("serverhello should not need SRTP by default\n"); | ||
| 2626 | goto err; | ||
| 2627 | } | ||
| 2628 | |||
| 2629 | if (srtp_find_profile_by_name((char *)tlsext_srtp_aes128cmsha80, &prof, | ||
| 2630 | strlen(tlsext_srtp_aes128cmsha80))) { | ||
| 2631 | FAIL("should be able to find the given profile\n"); | ||
| 2632 | goto err; | ||
| 2633 | } | ||
| 2634 | ssl->internal->srtp_profile = prof; | ||
| 2635 | if (!tlsext_srtp_serverhello_needs(ssl)) { | ||
| 2636 | FAIL("serverhello should need SRTP by now\n"); | ||
| 2637 | goto err; | ||
| 2638 | } | ||
| 2639 | |||
| 2640 | /* Make sure we can build the serverhello with a single profile. */ | ||
| 2641 | |||
| 2642 | if (!tlsext_srtp_serverhello_build(ssl, &cbb)) { | ||
| 2643 | FAIL("serverhello failed to build SRTP\n"); | ||
| 2644 | goto err; | ||
| 2645 | } | ||
| 2646 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2647 | errx(1, "failed to finish CBB"); | ||
| 2648 | |||
| 2649 | if (dlen != sizeof(tlsext_srtp_single)) { | ||
| 2650 | FAIL("got serverhello SRTP with length %zu, " | ||
| 2651 | "want length %zu\n", dlen, | ||
| 2652 | sizeof(tlsext_srtp_single)); | ||
| 2653 | compare_data(data, dlen, tlsext_srtp_single, | ||
| 2654 | sizeof(tlsext_srtp_single)); | ||
| 2655 | goto err; | ||
| 2656 | } | ||
| 2657 | if (memcmp(data, tlsext_srtp_single, dlen) != 0) { | ||
| 2658 | FAIL("serverhello SRTP differs:\n"); | ||
| 2659 | compare_data(data, dlen, tlsext_srtp_single, | ||
| 2660 | sizeof(tlsext_srtp_single)); | ||
| 2661 | goto err; | ||
| 2662 | } | ||
| 2663 | |||
| 2664 | CBB_cleanup(&cbb); | ||
| 2665 | CBB_init(&cbb, 0); | ||
| 2666 | free(data); | ||
| 2667 | data = NULL; | ||
| 2668 | |||
| 2669 | /* Make sure we can parse the single profile. */ | ||
| 2670 | ssl->internal->srtp_profile = NULL; | ||
| 2671 | |||
| 2672 | if (SSL_get_selected_srtp_profile(ssl) != NULL) { | ||
| 2673 | FAIL("SRTP profile should not be set yet\n"); | ||
| 2674 | goto err; | ||
| 2675 | } | ||
| 2676 | |||
| 2677 | /* Setup the environment as if a client sent a list of profiles. */ | ||
| 2678 | if (SSL_set_tlsext_use_srtp(ssl, tlsext_srtp_multiple_profiles) != 0) { | ||
| 2679 | FAIL("should be able to set multiple profiles in SRTP\n"); | ||
| 2680 | goto err; | ||
| 2681 | } | ||
| 2682 | |||
| 2683 | CBS_init(&cbs, tlsext_srtp_single, sizeof(tlsext_srtp_single)); | ||
| 2684 | if (!tlsext_srtp_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 2685 | FAIL("failed to parse SRTP\n"); | ||
| 2686 | goto err; | ||
| 2687 | } | ||
| 2688 | if (CBS_len(&cbs) != 0) { | ||
| 2689 | FAIL("extension data remaining"); | ||
| 2690 | goto err; | ||
| 2691 | } | ||
| 2692 | |||
| 2693 | if ((prof = SSL_get_selected_srtp_profile(ssl)) == NULL) { | ||
| 2694 | FAIL("SRTP profile should be set now\n"); | ||
| 2695 | goto err; | ||
| 2696 | } | ||
| 2697 | if (strcmp(prof->name, tlsext_srtp_aes128cmsha80) != 0) { | ||
| 2698 | FAIL("SRTP profile was not set properly\n"); | ||
| 2699 | goto err; | ||
| 2700 | } | ||
| 2701 | |||
| 2702 | /* Make sure we cannot parse multiple profiles */ | ||
| 2703 | ssl->internal->srtp_profile = NULL; | ||
| 2704 | |||
| 2705 | CBS_init(&cbs, tlsext_srtp_multiple, | ||
| 2706 | sizeof(tlsext_srtp_multiple)); | ||
| 2707 | if (tlsext_srtp_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 2708 | FAIL("should not find multiple entries from the server\n"); | ||
| 2709 | goto err; | ||
| 2710 | } | ||
| 2711 | |||
| 2712 | /* Make sure we cannot parse a serverhello with unknown profile */ | ||
| 2713 | ssl->internal->srtp_profile = NULL; | ||
| 2714 | |||
| 2715 | CBS_init(&cbs, tlsext_srtp_single_invalid, | ||
| 2716 | sizeof(tlsext_srtp_single_invalid)); | ||
| 2717 | if (tlsext_srtp_serverhello_parse(ssl, &cbs, &alert)) { | ||
| 2718 | FAIL("should not be able to parse this\n"); | ||
| 2719 | goto err; | ||
| 2720 | } | ||
| 2721 | |||
| 2722 | failure = 0; | ||
| 2723 | |||
| 2724 | err: | ||
| 2725 | CBB_cleanup(&cbb); | ||
| 2726 | SSL_CTX_free(ssl_ctx); | ||
| 2727 | SSL_free(ssl); | ||
| 2728 | free(data); | ||
| 2729 | |||
| 2730 | return (failure); | ||
| 2731 | } | ||
| 2732 | #endif /* OPENSSL_NO_SRTP */ | ||
| 2733 | |||
| 2734 | unsigned char tlsext_clienthello_default[] = { | ||
| 2735 | 0x00, 0x36, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, | ||
| 2736 | 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x1d, | ||
| 2737 | 0x00, 0x17, 0x00, 0x18, 0x00, 0x23, 0x00, 0x00, | ||
| 2738 | 0x00, 0x0d, 0x00, 0x1c, 0x00, 0x1a, 0x06, 0x01, | ||
| 2739 | 0x06, 0x03, 0xef, 0xef, 0x05, 0x01, 0x05, 0x03, | ||
| 2740 | 0x04, 0x01, 0x04, 0x03, 0xee, 0xee, 0xed, 0xed, | ||
| 2741 | 0x03, 0x01, 0x03, 0x03, 0x02, 0x01, 0x02, 0x03, | ||
| 2742 | }; | ||
| 2743 | |||
| 2744 | unsigned char tlsext_clienthello_disabled[] = {}; | ||
| 2745 | |||
| 2746 | static int | ||
| 2747 | test_tlsext_clienthello_build(void) | ||
| 2748 | { | ||
| 2749 | unsigned char *data = NULL; | ||
| 2750 | SSL_CTX *ssl_ctx = NULL; | ||
| 2751 | SSL *ssl = NULL; | ||
| 2752 | size_t dlen; | ||
| 2753 | int failure; | ||
| 2754 | CBB cbb; | ||
| 2755 | |||
| 2756 | failure = 1; | ||
| 2757 | |||
| 2758 | if (!CBB_init(&cbb, 0)) | ||
| 2759 | errx(1, "failed to create CBB"); | ||
| 2760 | |||
| 2761 | if ((ssl_ctx = SSL_CTX_new(TLS_client_method())) == NULL) | ||
| 2762 | errx(1, "failed to create SSL_CTX"); | ||
| 2763 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2764 | errx(1, "failed to create SSL"); | ||
| 2765 | |||
| 2766 | if (!tlsext_clienthello_build(ssl, &cbb)) { | ||
| 2767 | FAIL("failed to build clienthello extensions\n"); | ||
| 2768 | goto err; | ||
| 2769 | } | ||
| 2770 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2771 | errx(1, "failed to finish CBB"); | ||
| 2772 | |||
| 2773 | if (dlen != sizeof(tlsext_clienthello_default)) { | ||
| 2774 | FAIL("got clienthello extensions with length %zu, " | ||
| 2775 | "want length %zu\n", dlen, | ||
| 2776 | sizeof(tlsext_clienthello_default)); | ||
| 2777 | compare_data(data, dlen, tlsext_clienthello_default, | ||
| 2778 | sizeof(tlsext_clienthello_default)); | ||
| 2779 | goto err; | ||
| 2780 | } | ||
| 2781 | if (memcmp(data, tlsext_clienthello_default, dlen) != 0) { | ||
| 2782 | FAIL("clienthello extensions differs:\n"); | ||
| 2783 | compare_data(data, dlen, tlsext_clienthello_default, | ||
| 2784 | sizeof(tlsext_clienthello_default)); | ||
| 2785 | goto err; | ||
| 2786 | } | ||
| 2787 | |||
| 2788 | CBB_cleanup(&cbb); | ||
| 2789 | CBB_init(&cbb, 0); | ||
| 2790 | |||
| 2791 | /* Switch to TLSv1.1, disable EC ciphers and session tickets. */ | ||
| 2792 | ssl->client_version = TLS1_1_VERSION; | ||
| 2793 | if (!SSL_set_cipher_list(ssl, "TLSv1.2:!ECDHE:!ECDSA")) { | ||
| 2794 | FAIL("failed to set cipher list\n"); | ||
| 2795 | goto err; | ||
| 2796 | } | ||
| 2797 | if ((SSL_set_options(ssl, SSL_OP_NO_TICKET) & SSL_OP_NO_TICKET) == 0) { | ||
| 2798 | FAIL("failed to disable session tickets"); | ||
| 2799 | return 0; | ||
| 2800 | } | ||
| 2801 | |||
| 2802 | if (!tlsext_clienthello_build(ssl, &cbb)) { | ||
| 2803 | FAIL("failed to build clienthello extensions\n"); | ||
| 2804 | goto err; | ||
| 2805 | } | ||
| 2806 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2807 | errx(1, "failed to finish CBB"); | ||
| 2808 | |||
| 2809 | if (dlen != sizeof(tlsext_clienthello_disabled)) { | ||
| 2810 | FAIL("got clienthello extensions with length %zu, " | ||
| 2811 | "want length %zu\n", dlen, | ||
| 2812 | sizeof(tlsext_clienthello_disabled)); | ||
| 2813 | compare_data(data, dlen, tlsext_clienthello_disabled, | ||
| 2814 | sizeof(tlsext_clienthello_disabled)); | ||
| 2815 | goto err; | ||
| 2816 | } | ||
| 2817 | if (memcmp(data, tlsext_clienthello_disabled, dlen) != 0) { | ||
| 2818 | FAIL("clienthello extensions differs:\n"); | ||
| 2819 | compare_data(data, dlen, tlsext_clienthello_disabled, | ||
| 2820 | sizeof(tlsext_clienthello_disabled)); | ||
| 2821 | goto err; | ||
| 2822 | } | ||
| 2823 | |||
| 2824 | failure = 0; | ||
| 2825 | |||
| 2826 | err: | ||
| 2827 | CBB_cleanup(&cbb); | ||
| 2828 | SSL_CTX_free(ssl_ctx); | ||
| 2829 | SSL_free(ssl); | ||
| 2830 | free(data); | ||
| 2831 | |||
| 2832 | return (failure); | ||
| 2833 | } | ||
| 2834 | |||
| 2835 | unsigned char tlsext_serverhello_default[] = {}; | ||
| 2836 | |||
| 2837 | unsigned char tlsext_serverhello_enabled[] = { | ||
| 2838 | 0x00, 0x13, 0xff, 0x01, 0x00, 0x01, 0x00, 0x00, | ||
| 2839 | 0x05, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x02, 0x01, | ||
| 2840 | 0x00, 0x00, 0x23, 0x00, 0x00, | ||
| 2841 | }; | ||
| 2842 | |||
| 2843 | static int | ||
| 2844 | test_tlsext_serverhello_build(void) | ||
| 2845 | { | ||
| 2846 | unsigned char *data = NULL; | ||
| 2847 | SSL_CTX *ssl_ctx = NULL; | ||
| 2848 | SSL *ssl = NULL; | ||
| 2849 | size_t dlen; | ||
| 2850 | int failure; | ||
| 2851 | CBB cbb; | ||
| 2852 | |||
| 2853 | failure = 1; | ||
| 2854 | |||
| 2855 | if (!CBB_init(&cbb, 0)) | ||
| 2856 | errx(1, "failed to create CBB"); | ||
| 2857 | |||
| 2858 | if ((ssl_ctx = SSL_CTX_new(TLS_server_method())) == NULL) | ||
| 2859 | errx(1, "failed to create SSL_CTX"); | ||
| 2860 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 2861 | errx(1, "failed to create SSL"); | ||
| 2862 | if ((ssl->session = SSL_SESSION_new()) == NULL) | ||
| 2863 | errx(1, "failed to create session"); | ||
| 2864 | |||
| 2865 | S3I(ssl)->hs.new_cipher = | ||
| 2866 | ssl3_get_cipher_by_id(TLS1_CK_RSA_WITH_AES_128_SHA256); | ||
| 2867 | |||
| 2868 | if (!tlsext_serverhello_build(ssl, &cbb)) { | ||
| 2869 | FAIL("failed to build serverhello extensions\n"); | ||
| 2870 | goto err; | ||
| 2871 | } | ||
| 2872 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2873 | errx(1, "failed to finish CBB"); | ||
| 2874 | |||
| 2875 | if (dlen != sizeof(tlsext_serverhello_default)) { | ||
| 2876 | FAIL("got serverhello extensions with length %zu, " | ||
| 2877 | "want length %zu\n", dlen, | ||
| 2878 | sizeof(tlsext_serverhello_default)); | ||
| 2879 | compare_data(data, dlen, tlsext_serverhello_default, | ||
| 2880 | sizeof(tlsext_serverhello_default)); | ||
| 2881 | goto err; | ||
| 2882 | } | ||
| 2883 | if (memcmp(data, tlsext_serverhello_default, dlen) != 0) { | ||
| 2884 | FAIL("serverhello extensions differs:\n"); | ||
| 2885 | compare_data(data, dlen, tlsext_serverhello_default, | ||
| 2886 | sizeof(tlsext_serverhello_default)); | ||
| 2887 | goto err; | ||
| 2888 | } | ||
| 2889 | |||
| 2890 | CBB_cleanup(&cbb); | ||
| 2891 | CBB_init(&cbb, 0); | ||
| 2892 | |||
| 2893 | /* Turn a few things on so we get extensions... */ | ||
| 2894 | S3I(ssl)->send_connection_binding = 1; | ||
| 2895 | S3I(ssl)->hs.new_cipher = | ||
| 2896 | ssl3_get_cipher_by_id(TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256); | ||
| 2897 | ssl->internal->tlsext_status_expected = 1; | ||
| 2898 | ssl->internal->tlsext_ticket_expected = 1; | ||
| 2899 | if ((SSI(ssl)->tlsext_ecpointformatlist = malloc(1)) == NULL) | ||
| 2900 | errx(1, "malloc failed"); | ||
| 2901 | SSI(ssl)->tlsext_ecpointformatlist_length = 1; | ||
| 2902 | SSI(ssl)->tlsext_ecpointformatlist[0] = | ||
| 2903 | TLSEXT_ECPOINTFORMAT_uncompressed; | ||
| 2904 | |||
| 2905 | if (!tlsext_serverhello_build(ssl, &cbb)) { | ||
| 2906 | FAIL("failed to build serverhello extensions\n"); | ||
| 2907 | goto err; | ||
| 2908 | } | ||
| 2909 | if (!CBB_finish(&cbb, &data, &dlen)) | ||
| 2910 | errx(1, "failed to finish CBB"); | ||
| 2911 | |||
| 2912 | if (dlen != sizeof(tlsext_serverhello_enabled)) { | ||
| 2913 | FAIL("got serverhello extensions with length %zu, " | ||
| 2914 | "want length %zu\n", dlen, | ||
| 2915 | sizeof(tlsext_serverhello_enabled)); | ||
| 2916 | compare_data(data, dlen, tlsext_serverhello_enabled, | ||
| 2917 | sizeof(tlsext_serverhello_enabled)); | ||
| 2918 | goto err; | ||
| 2919 | } | ||
| 2920 | if (memcmp(data, tlsext_serverhello_enabled, dlen) != 0) { | ||
| 2921 | FAIL("serverhello extensions differs:\n"); | ||
| 2922 | compare_data(data, dlen, tlsext_serverhello_enabled, | ||
| 2923 | sizeof(tlsext_serverhello_enabled)); | ||
| 2924 | goto err; | ||
| 2925 | } | ||
| 2926 | |||
| 2927 | failure = 0; | ||
| 2928 | |||
| 2929 | err: | ||
| 2930 | CBB_cleanup(&cbb); | ||
| 2931 | SSL_CTX_free(ssl_ctx); | ||
| 2932 | SSL_free(ssl); | ||
| 2933 | free(data); | ||
| 2934 | |||
| 2935 | return (failure); | ||
| 2936 | } | ||
| 2937 | |||
| 2938 | int | ||
| 2939 | main(int argc, char **argv) | ||
| 2940 | { | ||
| 2941 | int failed = 0; | ||
| 2942 | |||
| 2943 | SSL_library_init(); | ||
| 2944 | SSL_load_error_strings(); | ||
| 2945 | |||
| 2946 | failed |= test_tlsext_alpn_clienthello(); | ||
| 2947 | failed |= test_tlsext_alpn_serverhello(); | ||
| 2948 | |||
| 2949 | failed |= test_tlsext_supportedgroups_clienthello(); | ||
| 2950 | failed |= test_tlsext_supportedgroups_serverhello(); | ||
| 2951 | |||
| 2952 | failed |= test_tlsext_ecpf_clienthello(); | ||
| 2953 | failed |= test_tlsext_ecpf_serverhello(); | ||
| 2954 | |||
| 2955 | failed |= test_tlsext_ri_clienthello(); | ||
| 2956 | failed |= test_tlsext_ri_serverhello(); | ||
| 2957 | |||
| 2958 | failed |= test_tlsext_sigalgs_clienthello(); | ||
| 2959 | failed |= test_tlsext_sigalgs_serverhello(); | ||
| 2960 | |||
| 2961 | failed |= test_tlsext_sni_clienthello(); | ||
| 2962 | failed |= test_tlsext_sni_serverhello(); | ||
| 2963 | |||
| 2964 | failed |= test_tlsext_ocsp_clienthello(); | ||
| 2965 | failed |= test_tlsext_ocsp_serverhello(); | ||
| 2966 | |||
| 2967 | failed |= test_tlsext_sessionticket_clienthello(); | ||
| 2968 | failed |= test_tlsext_sessionticket_serverhello(); | ||
| 2969 | |||
| 2970 | #ifndef OPENSSL_NO_SRTP | ||
| 2971 | failed |= test_tlsext_srtp_clienthello(); | ||
| 2972 | failed |= test_tlsext_srtp_serverhello(); | ||
| 2973 | #else | ||
| 2974 | fprintf(stderr, "Skipping SRTP tests due to OPENSSL_NO_SRTP\n"); | ||
| 2975 | #endif | ||
| 2976 | |||
| 2977 | failed |= test_tlsext_clienthello_build(); | ||
| 2978 | failed |= test_tlsext_serverhello_build(); | ||
| 2979 | |||
| 2980 | return (failed); | ||
| 2981 | } | ||
diff --git a/src/regress/lib/libssl/unit/Makefile b/src/regress/lib/libssl/unit/Makefile deleted file mode 100644 index 6b8a397c07..0000000000 --- a/src/regress/lib/libssl/unit/Makefile +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.9 2017/03/10 15:06:15 jsing Exp $ | ||
| 2 | |||
| 3 | TEST_CASES+= cipher_list | ||
| 4 | TEST_CASES+= ssl_versions | ||
| 5 | TEST_CASES+= tls_ext_alpn | ||
| 6 | TEST_CASES+= tls_prf | ||
| 7 | |||
| 8 | REGRESS_TARGETS= all_tests | ||
| 9 | |||
| 10 | WARNINGS= Yes | ||
| 11 | LDLIBS= ${SSL_INT} -lcrypto | ||
| 12 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
| 13 | CFLAGS+= -I${.CURDIR}/../../../../lib/libssl | ||
| 14 | |||
| 15 | CLEANFILES+= ${TEST_CASES} | ||
| 16 | |||
| 17 | all_tests: ${TEST_CASES} | ||
| 18 | @for test in $>; do \ | ||
| 19 | ./$$test; \ | ||
| 20 | done | ||
| 21 | |||
| 22 | ${TEST_CASES}: ${LIBSSL} ${LIBCRYPTO} | ||
| 23 | |||
| 24 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libssl/unit/cipher_list.c b/src/regress/lib/libssl/unit/cipher_list.c deleted file mode 100644 index 70f547abd6..0000000000 --- a/src/regress/lib/libssl/unit/cipher_list.c +++ /dev/null | |||
| @@ -1,204 +0,0 @@ | |||
| 1 | /* $OpenBSD: cipher_list.c,v 1.9 2018/06/02 16:35:02 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> | ||
| 4 | * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> | ||
| 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 | /* | ||
| 20 | * Test TLS ssl bytes (aka cipher suites) to cipher list and back. | ||
| 21 | * | ||
| 22 | * TLSv1.0 - RFC 2246 section 7.4.1.2 (ClientHello struct) | ||
| 23 | * TLSv1.1 - RFC 4346 section 7.4.1.2 (ClientHello struct) | ||
| 24 | * TLSv1.2 - RFC 5246 section 7.4.1.2 (ClientHello struct) | ||
| 25 | * | ||
| 26 | * In all of these standards, the relevant structures are: | ||
| 27 | * | ||
| 28 | * uint8 CipherSuite[2]; | ||
| 29 | * | ||
| 30 | * struct { | ||
| 31 | * ... | ||
| 32 | * CipherSuite cipher_suites<2..2^16-2> | ||
| 33 | * ... | ||
| 34 | * } ClientHello; | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <openssl/ssl.h> | ||
| 38 | |||
| 39 | #include <stdio.h> | ||
| 40 | #include <string.h> | ||
| 41 | |||
| 42 | #include "ssl_locl.h" | ||
| 43 | |||
| 44 | #include "tests.h" | ||
| 45 | |||
| 46 | static uint8_t cipher_bytes[] = { | ||
| 47 | 0xcc, 0xa8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | ||
| 48 | 0xcc, 0xa9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | ||
| 49 | 0xcc, 0xaa, /* DHE-RSA-CHACHA20-POLY1305 */ | ||
| 50 | 0x00, 0x9c, /* AES128-GCM-SHA256 */ | ||
| 51 | 0x00, 0x3d, /* AES256-SHA256 */ | ||
| 52 | }; | ||
| 53 | |||
| 54 | static uint16_t cipher_values[] = { | ||
| 55 | 0xcca8, /* ECDHE-ECDSA-CHACHA20-POLY1305 */ | ||
| 56 | 0xcca9, /* ECDHE-RSA-CHACHA20-POLY1305 */ | ||
| 57 | 0xccaa, /* DHE-RSA-CHACHA20-POLY1305 */ | ||
| 58 | 0x009c, /* AES128-GCM-SHA256 */ | ||
| 59 | 0x003d, /* AES256-SHA256 */ | ||
| 60 | }; | ||
| 61 | |||
| 62 | #define N_CIPHERS (sizeof(cipher_bytes) / 2) | ||
| 63 | |||
| 64 | static int | ||
| 65 | ssl_bytes_to_list_alloc(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
| 66 | { | ||
| 67 | SSL_CIPHER *cipher; | ||
| 68 | uint16_t value; | ||
| 69 | CBS cbs; | ||
| 70 | int i; | ||
| 71 | |||
| 72 | CBS_init(&cbs, cipher_bytes, sizeof(cipher_bytes)); | ||
| 73 | |||
| 74 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
| 75 | CHECK(*ciphers != NULL); | ||
| 76 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
| 77 | for (i = 0; i < sk_SSL_CIPHER_num(*ciphers); i++) { | ||
| 78 | cipher = sk_SSL_CIPHER_value(*ciphers, i); | ||
| 79 | CHECK(cipher != NULL); | ||
| 80 | value = SSL_CIPHER_get_value(cipher); | ||
| 81 | CHECK(value == cipher_values[i]); | ||
| 82 | } | ||
| 83 | |||
| 84 | return 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int | ||
| 88 | ssl_list_to_bytes_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
| 89 | { | ||
| 90 | CBB cbb; | ||
| 91 | unsigned char *buf = NULL; | ||
| 92 | size_t buflen, outlen; | ||
| 93 | int ret = 0; | ||
| 94 | |||
| 95 | /* Space for cipher bytes, plus reneg SCSV and two spare bytes. */ | ||
| 96 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
| 97 | buflen = sizeof(cipher_bytes) + 2 + 2; | ||
| 98 | CHECK((buf = calloc(1, buflen)) != NULL); | ||
| 99 | |||
| 100 | CHECK(CBB_init_fixed(&cbb, buf, buflen)); | ||
| 101 | CHECK(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | ||
| 102 | CHECK(CBB_finish(&cbb, NULL, &outlen)); | ||
| 103 | |||
| 104 | CHECK_GOTO(outlen > 0 && outlen == buflen - 2); | ||
| 105 | CHECK_GOTO(memcmp(buf, cipher_bytes, sizeof(cipher_bytes)) == 0); | ||
| 106 | CHECK_GOTO(buf[buflen - 4] == 0x00 && buf[buflen - 3] == 0xff); | ||
| 107 | CHECK_GOTO(buf[buflen - 2] == 0x00 && buf[buflen - 1] == 0x00); | ||
| 108 | |||
| 109 | ret = 1; | ||
| 110 | |||
| 111 | err: | ||
| 112 | free(buf); | ||
| 113 | return ret; | ||
| 114 | } | ||
| 115 | |||
| 116 | static int | ||
| 117 | ssl_list_to_bytes_no_scsv(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
| 118 | { | ||
| 119 | CBB cbb; | ||
| 120 | unsigned char *buf = NULL; | ||
| 121 | size_t buflen, outlen; | ||
| 122 | int ret = 0; | ||
| 123 | |||
| 124 | /* Space for cipher bytes and two spare bytes */ | ||
| 125 | CHECK(sk_SSL_CIPHER_num(*ciphers) == N_CIPHERS); | ||
| 126 | buflen = sizeof(cipher_bytes) + 2; | ||
| 127 | CHECK((buf = calloc(1, buflen)) != NULL); | ||
| 128 | buf[buflen - 2] = 0xfe; | ||
| 129 | buf[buflen - 1] = 0xab; | ||
| 130 | |||
| 131 | /* Set renegotiate so it doesn't add SCSV */ | ||
| 132 | s->internal->renegotiate = 1; | ||
| 133 | |||
| 134 | CHECK(CBB_init_fixed(&cbb, buf, buflen)); | ||
| 135 | CHECK(ssl_cipher_list_to_bytes(s, *ciphers, &cbb)); | ||
| 136 | CHECK(CBB_finish(&cbb, NULL, &outlen)); | ||
| 137 | |||
| 138 | CHECK_GOTO(outlen > 0 && outlen == buflen - 2); | ||
| 139 | CHECK_GOTO(memcmp(buf, cipher_bytes, sizeof(cipher_bytes)) == 0); | ||
| 140 | CHECK_GOTO(buf[buflen - 2] == 0xfe && buf[buflen - 1] == 0xab); | ||
| 141 | |||
| 142 | ret = 1; | ||
| 143 | |||
| 144 | err: | ||
| 145 | free(buf); | ||
| 146 | return ret; | ||
| 147 | } | ||
| 148 | |||
| 149 | static int | ||
| 150 | ssl_bytes_to_list_invalid(SSL *s, STACK_OF(SSL_CIPHER) **ciphers) | ||
| 151 | { | ||
| 152 | uint8_t empty_cipher_bytes[] = {0}; | ||
| 153 | CBS cbs; | ||
| 154 | |||
| 155 | sk_SSL_CIPHER_free(*ciphers); | ||
| 156 | |||
| 157 | /* Invalid length: CipherSuite is 2 bytes so it must be even */ | ||
| 158 | CBS_init(&cbs, cipher_bytes, sizeof(cipher_bytes) - 1); | ||
| 159 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
| 160 | CHECK(*ciphers == NULL); | ||
| 161 | |||
| 162 | /* Invalid length: cipher_suites must be at least 2 */ | ||
| 163 | CBS_init(&cbs, empty_cipher_bytes, sizeof(empty_cipher_bytes)); | ||
| 164 | *ciphers = ssl_bytes_to_cipher_list(s, &cbs); | ||
| 165 | CHECK(*ciphers == NULL); | ||
| 166 | |||
| 167 | return 1; | ||
| 168 | } | ||
| 169 | |||
| 170 | int | ||
| 171 | main(void) | ||
| 172 | { | ||
| 173 | STACK_OF(SSL_CIPHER) *ciphers = NULL; | ||
| 174 | SSL_CTX *ctx = NULL; | ||
| 175 | SSL *s = NULL; | ||
| 176 | int rv = 1; | ||
| 177 | |||
| 178 | SSL_library_init(); | ||
| 179 | |||
| 180 | /* Use TLSv1.2 client to get all ciphers. */ | ||
| 181 | CHECK_GOTO((ctx = SSL_CTX_new(TLSv1_2_client_method())) != NULL); | ||
| 182 | CHECK_GOTO((s = SSL_new(ctx)) != NULL); | ||
| 183 | |||
| 184 | if (!ssl_bytes_to_list_alloc(s, &ciphers)) | ||
| 185 | goto err; | ||
| 186 | if (!ssl_list_to_bytes_scsv(s, &ciphers)) | ||
| 187 | goto err; | ||
| 188 | if (!ssl_list_to_bytes_no_scsv(s, &ciphers)) | ||
| 189 | goto err; | ||
| 190 | if (!ssl_bytes_to_list_invalid(s, &ciphers)) | ||
| 191 | goto err; | ||
| 192 | |||
| 193 | rv = 0; | ||
| 194 | |||
| 195 | err: | ||
| 196 | sk_SSL_CIPHER_free(ciphers); | ||
| 197 | SSL_CTX_free(ctx); | ||
| 198 | SSL_free(s); | ||
| 199 | |||
| 200 | if (!rv) | ||
| 201 | printf("PASS %s\n", __FILE__); | ||
| 202 | |||
| 203 | return rv; | ||
| 204 | } | ||
diff --git a/src/regress/lib/libssl/unit/ssl_versions.c b/src/regress/lib/libssl/unit/ssl_versions.c deleted file mode 100644 index 11519c3732..0000000000 --- a/src/regress/lib/libssl/unit/ssl_versions.c +++ /dev/null | |||
| @@ -1,797 +0,0 @@ | |||
| 1 | /* $OpenBSD: ssl_versions.c,v 1.6 2018/11/06 01:40:57 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <openssl/ssl.h> | ||
| 19 | |||
| 20 | #include "ssl_locl.h" | ||
| 21 | |||
| 22 | struct version_range_test { | ||
| 23 | const long options; | ||
| 24 | const uint16_t minver; | ||
| 25 | const uint16_t maxver; | ||
| 26 | const uint16_t want_minver; | ||
| 27 | const uint16_t want_maxver; | ||
| 28 | }; | ||
| 29 | |||
| 30 | static struct version_range_test version_range_tests[] = { | ||
| 31 | { | ||
| 32 | .options = 0, | ||
| 33 | .minver = TLS1_VERSION, | ||
| 34 | .maxver = TLS1_3_VERSION, | ||
| 35 | .want_minver = TLS1_VERSION, | ||
| 36 | .want_maxver = TLS1_3_VERSION, | ||
| 37 | }, | ||
| 38 | { | ||
| 39 | .options = 0, | ||
| 40 | .minver = TLS1_VERSION, | ||
| 41 | .maxver = TLS1_2_VERSION, | ||
| 42 | .want_minver = TLS1_VERSION, | ||
| 43 | .want_maxver = TLS1_2_VERSION, | ||
| 44 | }, | ||
| 45 | { | ||
| 46 | .options = SSL_OP_NO_TLSv1, | ||
| 47 | .minver = TLS1_VERSION, | ||
| 48 | .maxver = TLS1_2_VERSION, | ||
| 49 | .want_minver = TLS1_1_VERSION, | ||
| 50 | .want_maxver = TLS1_2_VERSION, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | .options = SSL_OP_NO_TLSv1_3, | ||
| 54 | .minver = TLS1_VERSION, | ||
| 55 | .maxver = TLS1_3_VERSION, | ||
| 56 | .want_minver = TLS1_VERSION, | ||
| 57 | .want_maxver = TLS1_2_VERSION, | ||
| 58 | }, | ||
| 59 | { | ||
| 60 | .options = SSL_OP_NO_TLSv1_2, | ||
| 61 | .minver = TLS1_VERSION, | ||
| 62 | .maxver = TLS1_2_VERSION, | ||
| 63 | .want_minver = TLS1_VERSION, | ||
| 64 | .want_maxver = TLS1_1_VERSION, | ||
| 65 | }, | ||
| 66 | { | ||
| 67 | .options = SSL_OP_NO_TLSv1_1, | ||
| 68 | .minver = TLS1_VERSION, | ||
| 69 | .maxver = TLS1_2_VERSION, | ||
| 70 | .want_minver = TLS1_VERSION, | ||
| 71 | .want_maxver = TLS1_VERSION, | ||
| 72 | }, | ||
| 73 | { | ||
| 74 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1, | ||
| 75 | .minver = TLS1_VERSION, | ||
| 76 | .maxver = TLS1_2_VERSION, | ||
| 77 | .want_minver = TLS1_2_VERSION, | ||
| 78 | .want_maxver = TLS1_2_VERSION, | ||
| 79 | }, | ||
| 80 | { | ||
| 81 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
| 82 | .minver = TLS1_VERSION, | ||
| 83 | .maxver = TLS1_2_VERSION, | ||
| 84 | .want_minver = TLS1_VERSION, | ||
| 85 | .want_maxver = TLS1_VERSION, | ||
| 86 | }, | ||
| 87 | { | ||
| 88 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_2, | ||
| 89 | .minver = TLS1_VERSION, | ||
| 90 | .maxver = TLS1_2_VERSION, | ||
| 91 | .want_minver = TLS1_1_VERSION, | ||
| 92 | .want_maxver = TLS1_1_VERSION, | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
| 96 | SSL_OP_NO_TLSv1_2, | ||
| 97 | .minver = TLS1_VERSION, | ||
| 98 | .maxver = TLS1_2_VERSION, | ||
| 99 | .want_minver = 0, | ||
| 100 | .want_maxver = 0, | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
| 104 | SSL_OP_NO_TLSv1_2, | ||
| 105 | .minver = TLS1_VERSION, | ||
| 106 | .maxver = TLS1_3_VERSION, | ||
| 107 | .want_minver = TLS1_3_VERSION, | ||
| 108 | .want_maxver = TLS1_3_VERSION, | ||
| 109 | }, | ||
| 110 | { | ||
| 111 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
| 112 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3, | ||
| 113 | .minver = TLS1_VERSION, | ||
| 114 | .maxver = TLS1_3_VERSION, | ||
| 115 | .want_minver = 0, | ||
| 116 | .want_maxver = 0, | ||
| 117 | }, | ||
| 118 | { | ||
| 119 | .options = 0, | ||
| 120 | .minver = TLS1_VERSION, | ||
| 121 | .maxver = TLS1_2_VERSION, | ||
| 122 | .want_minver = TLS1_VERSION, | ||
| 123 | .want_maxver = TLS1_2_VERSION, | ||
| 124 | }, | ||
| 125 | { | ||
| 126 | .options = 0, | ||
| 127 | .minver = TLS1_1_VERSION, | ||
| 128 | .maxver = TLS1_2_VERSION, | ||
| 129 | .want_minver = TLS1_1_VERSION, | ||
| 130 | .want_maxver = TLS1_2_VERSION, | ||
| 131 | }, | ||
| 132 | { | ||
| 133 | .options = 0, | ||
| 134 | .minver = TLS1_2_VERSION, | ||
| 135 | .maxver = TLS1_2_VERSION, | ||
| 136 | .want_minver = TLS1_2_VERSION, | ||
| 137 | .want_maxver = TLS1_2_VERSION, | ||
| 138 | }, | ||
| 139 | { | ||
| 140 | .options = 0, | ||
| 141 | .minver = TLS1_VERSION, | ||
| 142 | .maxver = TLS1_3_VERSION, | ||
| 143 | .want_minver = TLS1_VERSION, | ||
| 144 | .want_maxver = TLS1_3_VERSION, | ||
| 145 | }, | ||
| 146 | { | ||
| 147 | .options = 0, | ||
| 148 | .minver = TLS1_1_VERSION, | ||
| 149 | .maxver = TLS1_3_VERSION, | ||
| 150 | .want_minver = TLS1_1_VERSION, | ||
| 151 | .want_maxver = TLS1_3_VERSION, | ||
| 152 | }, | ||
| 153 | { | ||
| 154 | .options = 0, | ||
| 155 | .minver = TLS1_2_VERSION, | ||
| 156 | .maxver = TLS1_3_VERSION, | ||
| 157 | .want_minver = TLS1_2_VERSION, | ||
| 158 | .want_maxver = TLS1_3_VERSION, | ||
| 159 | }, | ||
| 160 | { | ||
| 161 | .options = 0, | ||
| 162 | .minver = TLS1_3_VERSION, | ||
| 163 | .maxver = TLS1_3_VERSION, | ||
| 164 | .want_minver = TLS1_3_VERSION, | ||
| 165 | .want_maxver = TLS1_3_VERSION, | ||
| 166 | }, | ||
| 167 | { | ||
| 168 | .options = 0, | ||
| 169 | .minver = TLS1_VERSION, | ||
| 170 | .maxver = TLS1_1_VERSION, | ||
| 171 | .want_minver = TLS1_VERSION, | ||
| 172 | .want_maxver = TLS1_1_VERSION, | ||
| 173 | }, | ||
| 174 | { | ||
| 175 | .options = 0, | ||
| 176 | .minver = TLS1_VERSION, | ||
| 177 | .maxver = TLS1_VERSION, | ||
| 178 | .want_minver = TLS1_VERSION, | ||
| 179 | .want_maxver = TLS1_VERSION, | ||
| 180 | }, | ||
| 181 | }; | ||
| 182 | |||
| 183 | #define N_VERSION_RANGE_TESTS \ | ||
| 184 | (sizeof(version_range_tests) / sizeof(*version_range_tests)) | ||
| 185 | |||
| 186 | static int | ||
| 187 | test_ssl_enabled_version_range(void) | ||
| 188 | { | ||
| 189 | struct version_range_test *vrt; | ||
| 190 | uint16_t minver, maxver; | ||
| 191 | SSL_CTX *ssl_ctx = NULL; | ||
| 192 | SSL *ssl = NULL; | ||
| 193 | int failed = 1; | ||
| 194 | size_t i; | ||
| 195 | |||
| 196 | if ((ssl_ctx = SSL_CTX_new(TLS_method())) == NULL) { | ||
| 197 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 198 | goto failure; | ||
| 199 | } | ||
| 200 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 201 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 202 | goto failure; | ||
| 203 | } | ||
| 204 | |||
| 205 | failed = 0; | ||
| 206 | |||
| 207 | for (i = 0; i < N_VERSION_RANGE_TESTS; i++) { | ||
| 208 | vrt = &version_range_tests[i]; | ||
| 209 | |||
| 210 | SSL_clear_options(ssl, SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
| 211 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3); | ||
| 212 | SSL_set_options(ssl, vrt->options); | ||
| 213 | |||
| 214 | minver = maxver = 0xffff; | ||
| 215 | ssl->internal->min_version = vrt->minver; | ||
| 216 | ssl->internal->max_version = vrt->maxver; | ||
| 217 | |||
| 218 | if (ssl_enabled_version_range(ssl, &minver, &maxver) != 1) { | ||
| 219 | if (vrt->want_minver != 0 || vrt->want_maxver != 0) { | ||
| 220 | fprintf(stderr, "FAIL: test %zu - failed but " | ||
| 221 | "wanted non-zero versions\n", i); | ||
| 222 | failed++; | ||
| 223 | } | ||
| 224 | continue; | ||
| 225 | } | ||
| 226 | if (minver != vrt->want_minver) { | ||
| 227 | fprintf(stderr, "FAIL: test %zu - got minver %x, " | ||
| 228 | "want %x\n", i, minver, vrt->want_minver); | ||
| 229 | failed++; | ||
| 230 | } | ||
| 231 | if (maxver != vrt->want_maxver) { | ||
| 232 | fprintf(stderr, "FAIL: test %zu - got maxver %x, " | ||
| 233 | "want %x\n", i, maxver, vrt->want_maxver); | ||
| 234 | failed++; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | failure: | ||
| 239 | SSL_CTX_free(ssl_ctx); | ||
| 240 | SSL_free(ssl); | ||
| 241 | |||
| 242 | return (failed); | ||
| 243 | } | ||
| 244 | |||
| 245 | struct shared_version_test { | ||
| 246 | const SSL_METHOD *(*ssl_method)(void); | ||
| 247 | const long options; | ||
| 248 | const uint16_t minver; | ||
| 249 | const uint16_t maxver; | ||
| 250 | const uint16_t peerver; | ||
| 251 | const uint16_t want_maxver; | ||
| 252 | }; | ||
| 253 | |||
| 254 | static struct shared_version_test shared_version_tests[] = { | ||
| 255 | { | ||
| 256 | .ssl_method = TLS_method, | ||
| 257 | .options = 0, | ||
| 258 | .minver = TLS1_VERSION, | ||
| 259 | .maxver = TLS1_2_VERSION, | ||
| 260 | .peerver = SSL2_VERSION, | ||
| 261 | .want_maxver = 0, | ||
| 262 | }, | ||
| 263 | { | ||
| 264 | .ssl_method = TLS_method, | ||
| 265 | .options = 0, | ||
| 266 | .minver = TLS1_VERSION, | ||
| 267 | .maxver = TLS1_2_VERSION, | ||
| 268 | .peerver = SSL3_VERSION, | ||
| 269 | .want_maxver = 0, | ||
| 270 | }, | ||
| 271 | { | ||
| 272 | .ssl_method = TLS_method, | ||
| 273 | .options = 0, | ||
| 274 | .minver = TLS1_VERSION, | ||
| 275 | .maxver = TLS1_2_VERSION, | ||
| 276 | .peerver = TLS1_VERSION, | ||
| 277 | .want_maxver = TLS1_VERSION, | ||
| 278 | }, | ||
| 279 | { | ||
| 280 | .ssl_method = TLS_method, | ||
| 281 | .options = 0, | ||
| 282 | .minver = TLS1_VERSION, | ||
| 283 | .maxver = TLS1_2_VERSION, | ||
| 284 | .peerver = TLS1_1_VERSION, | ||
| 285 | .want_maxver = TLS1_1_VERSION, | ||
| 286 | }, | ||
| 287 | { | ||
| 288 | .ssl_method = TLS_method, | ||
| 289 | .options = 0, | ||
| 290 | .minver = TLS1_VERSION, | ||
| 291 | .maxver = TLS1_2_VERSION, | ||
| 292 | .peerver = TLS1_2_VERSION, | ||
| 293 | .want_maxver = TLS1_2_VERSION, | ||
| 294 | }, | ||
| 295 | { | ||
| 296 | .ssl_method = TLS_method, | ||
| 297 | .options = 0, | ||
| 298 | .minver = TLS1_VERSION, | ||
| 299 | .maxver = TLS1_2_VERSION, | ||
| 300 | .peerver = TLS1_3_VERSION, | ||
| 301 | .want_maxver = TLS1_2_VERSION, | ||
| 302 | }, | ||
| 303 | { | ||
| 304 | .ssl_method = TLS_method, | ||
| 305 | .options = 0, | ||
| 306 | .minver = TLS1_VERSION, | ||
| 307 | .maxver = TLS1_2_VERSION, | ||
| 308 | .peerver = 0x7f12, | ||
| 309 | .want_maxver = TLS1_2_VERSION, | ||
| 310 | }, | ||
| 311 | { | ||
| 312 | .ssl_method = TLS_method, | ||
| 313 | .options = SSL_OP_NO_TLSv1_2, | ||
| 314 | .minver = TLS1_VERSION, | ||
| 315 | .maxver = TLS1_2_VERSION, | ||
| 316 | .peerver = TLS1_2_VERSION, | ||
| 317 | .want_maxver = TLS1_1_VERSION, | ||
| 318 | }, | ||
| 319 | { | ||
| 320 | .ssl_method = TLS_method, | ||
| 321 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
| 322 | .minver = TLS1_VERSION, | ||
| 323 | .maxver = TLS1_2_VERSION, | ||
| 324 | .peerver = TLS1_2_VERSION, | ||
| 325 | .want_maxver = TLS1_VERSION, | ||
| 326 | }, | ||
| 327 | { | ||
| 328 | .ssl_method = TLS_method, | ||
| 329 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
| 330 | .minver = TLS1_VERSION, | ||
| 331 | .maxver = TLS1_2_VERSION, | ||
| 332 | .peerver = TLS1_2_VERSION, | ||
| 333 | .want_maxver = 0, | ||
| 334 | }, | ||
| 335 | { | ||
| 336 | .ssl_method = TLS_method, | ||
| 337 | .options = SSL_OP_NO_TLSv1, | ||
| 338 | .minver = TLS1_VERSION, | ||
| 339 | .maxver = TLS1_2_VERSION, | ||
| 340 | .peerver = TLS1_1_VERSION, | ||
| 341 | .want_maxver = TLS1_1_VERSION, | ||
| 342 | }, | ||
| 343 | { | ||
| 344 | .ssl_method = TLS_method, | ||
| 345 | .options = SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1, | ||
| 346 | .minver = TLS1_VERSION, | ||
| 347 | .maxver = TLS1_2_VERSION, | ||
| 348 | .peerver = TLS1_1_VERSION, | ||
| 349 | .want_maxver = 0, | ||
| 350 | }, | ||
| 351 | { | ||
| 352 | .ssl_method = TLS_method, | ||
| 353 | .options = SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2, | ||
| 354 | .minver = TLS1_VERSION, | ||
| 355 | .maxver = TLS1_2_VERSION, | ||
| 356 | .peerver = TLS1_1_VERSION, | ||
| 357 | .want_maxver = TLS1_VERSION, | ||
| 358 | }, | ||
| 359 | { | ||
| 360 | .ssl_method = TLS_method, | ||
| 361 | .options = SSL_OP_NO_TLSv1, | ||
| 362 | .minver = TLS1_VERSION, | ||
| 363 | .maxver = TLS1_2_VERSION, | ||
| 364 | .peerver = TLS1_VERSION, | ||
| 365 | .want_maxver = 0, | ||
| 366 | }, | ||
| 367 | { | ||
| 368 | .ssl_method = TLS_method, | ||
| 369 | .options = 0, | ||
| 370 | .minver = TLS1_VERSION, | ||
| 371 | .maxver = TLS1_1_VERSION, | ||
| 372 | .peerver = TLS1_2_VERSION, | ||
| 373 | .want_maxver = TLS1_1_VERSION, | ||
| 374 | }, | ||
| 375 | { | ||
| 376 | .ssl_method = TLS_method, | ||
| 377 | .options = 0, | ||
| 378 | .minver = TLS1_VERSION, | ||
| 379 | .maxver = TLS1_VERSION, | ||
| 380 | .peerver = TLS1_2_VERSION, | ||
| 381 | .want_maxver = TLS1_VERSION, | ||
| 382 | }, | ||
| 383 | { | ||
| 384 | .ssl_method = TLSv1_method, | ||
| 385 | .options = 0, | ||
| 386 | .minver = TLS1_VERSION, | ||
| 387 | .maxver = TLS1_2_VERSION, | ||
| 388 | .peerver = TLS1_VERSION, | ||
| 389 | .want_maxver = TLS1_VERSION, | ||
| 390 | }, | ||
| 391 | { | ||
| 392 | .ssl_method = TLSv1_method, | ||
| 393 | .options = 0, | ||
| 394 | .minver = TLS1_1_VERSION, | ||
| 395 | .maxver = TLS1_2_VERSION, | ||
| 396 | .peerver = TLS1_VERSION, | ||
| 397 | .want_maxver = 0, | ||
| 398 | }, | ||
| 399 | { | ||
| 400 | .ssl_method = TLSv1_1_method, | ||
| 401 | .options = 0, | ||
| 402 | .minver = TLS1_VERSION, | ||
| 403 | .maxver = TLS1_2_VERSION, | ||
| 404 | .peerver = TLS1_1_VERSION, | ||
| 405 | .want_maxver = TLS1_1_VERSION, | ||
| 406 | }, | ||
| 407 | { | ||
| 408 | .ssl_method = DTLSv1_method, | ||
| 409 | .options = 0, | ||
| 410 | .minver = TLS1_VERSION, | ||
| 411 | .maxver = TLS1_2_VERSION, | ||
| 412 | .peerver = DTLS1_VERSION, | ||
| 413 | .want_maxver = DTLS1_VERSION, | ||
| 414 | }, | ||
| 415 | { | ||
| 416 | .ssl_method = DTLSv1_method, | ||
| 417 | .options = 0, | ||
| 418 | .minver = TLS1_VERSION, | ||
| 419 | .maxver = TLS1_2_VERSION, | ||
| 420 | .peerver = TLS1_2_VERSION, | ||
| 421 | .want_maxver = 0, | ||
| 422 | }, | ||
| 423 | }; | ||
| 424 | |||
| 425 | #define N_SHARED_VERSION_TESTS \ | ||
| 426 | (sizeof(shared_version_tests) / sizeof(*shared_version_tests)) | ||
| 427 | |||
| 428 | static int | ||
| 429 | test_ssl_max_shared_version(void) | ||
| 430 | { | ||
| 431 | struct shared_version_test *svt; | ||
| 432 | SSL_CTX *ssl_ctx = NULL; | ||
| 433 | SSL *ssl = NULL; | ||
| 434 | uint16_t maxver; | ||
| 435 | int failed = 0; | ||
| 436 | size_t i; | ||
| 437 | |||
| 438 | failed = 0; | ||
| 439 | |||
| 440 | for (i = 0; i < N_SHARED_VERSION_TESTS; i++) { | ||
| 441 | svt = &shared_version_tests[i]; | ||
| 442 | |||
| 443 | if ((ssl_ctx = SSL_CTX_new(svt->ssl_method())) == NULL) { | ||
| 444 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 445 | return 1; | ||
| 446 | } | ||
| 447 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 448 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 449 | return 1; | ||
| 450 | } | ||
| 451 | |||
| 452 | SSL_clear_options(ssl, SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | | ||
| 453 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3); | ||
| 454 | SSL_set_options(ssl, svt->options); | ||
| 455 | |||
| 456 | maxver = 0; | ||
| 457 | ssl->internal->min_version = svt->minver; | ||
| 458 | ssl->internal->max_version = svt->maxver; | ||
| 459 | |||
| 460 | if (ssl_max_shared_version(ssl, svt->peerver, &maxver) != 1) { | ||
| 461 | if (svt->want_maxver != 0) { | ||
| 462 | fprintf(stderr, "FAIL: test %zu - failed but " | ||
| 463 | "wanted non-zero shared version\n", i); | ||
| 464 | failed++; | ||
| 465 | } | ||
| 466 | continue; | ||
| 467 | } | ||
| 468 | if (maxver != svt->want_maxver) { | ||
| 469 | fprintf(stderr, "FAIL: test %zu - got shared " | ||
| 470 | "version %x, want %x\n", i, maxver, | ||
| 471 | svt->want_maxver); | ||
| 472 | failed++; | ||
| 473 | } | ||
| 474 | |||
| 475 | SSL_CTX_free(ssl_ctx); | ||
| 476 | SSL_free(ssl); | ||
| 477 | } | ||
| 478 | |||
| 479 | return (failed); | ||
| 480 | } | ||
| 481 | |||
| 482 | struct min_max_version_test { | ||
| 483 | const SSL_METHOD *(*ssl_method)(void); | ||
| 484 | const uint16_t minver; | ||
| 485 | const uint16_t maxver; | ||
| 486 | const uint16_t want_minver; | ||
| 487 | const uint16_t want_maxver; | ||
| 488 | }; | ||
| 489 | |||
| 490 | static struct min_max_version_test min_max_version_tests[] = { | ||
| 491 | { | ||
| 492 | .ssl_method = TLS_method, | ||
| 493 | .minver = 0, | ||
| 494 | .maxver = 0, | ||
| 495 | .want_minver = TLS1_VERSION, | ||
| 496 | .want_maxver = TLS1_2_VERSION, | ||
| 497 | }, | ||
| 498 | { | ||
| 499 | .ssl_method = TLS_method, | ||
| 500 | .minver = TLS1_VERSION, | ||
| 501 | .maxver = 0, | ||
| 502 | .want_minver = TLS1_VERSION, | ||
| 503 | .want_maxver = TLS1_2_VERSION, | ||
| 504 | }, | ||
| 505 | { | ||
| 506 | .ssl_method = TLS_method, | ||
| 507 | .minver = 0, | ||
| 508 | .maxver = TLS1_2_VERSION, | ||
| 509 | .want_minver = TLS1_VERSION, | ||
| 510 | .want_maxver = TLS1_2_VERSION, | ||
| 511 | }, | ||
| 512 | { | ||
| 513 | .ssl_method = TLS_method, | ||
| 514 | .minver = 0, | ||
| 515 | .maxver = TLS1_3_VERSION, | ||
| 516 | .want_minver = TLS1_VERSION, | ||
| 517 | .want_maxver = TLS1_2_VERSION, | ||
| 518 | }, | ||
| 519 | { | ||
| 520 | .ssl_method = TLS_method, | ||
| 521 | .minver = TLS1_VERSION, | ||
| 522 | .maxver = TLS1_2_VERSION, | ||
| 523 | .want_minver = TLS1_VERSION, | ||
| 524 | .want_maxver = TLS1_2_VERSION, | ||
| 525 | }, | ||
| 526 | { | ||
| 527 | .ssl_method = TLS_method, | ||
| 528 | .minver = TLS1_1_VERSION, | ||
| 529 | .maxver = 0, | ||
| 530 | .want_minver = TLS1_1_VERSION, | ||
| 531 | .want_maxver = TLS1_2_VERSION, | ||
| 532 | }, | ||
| 533 | { | ||
| 534 | .ssl_method = TLS_method, | ||
| 535 | .minver = TLS1_2_VERSION, | ||
| 536 | .maxver = 0, | ||
| 537 | .want_minver = TLS1_2_VERSION, | ||
| 538 | .want_maxver = TLS1_2_VERSION, | ||
| 539 | }, | ||
| 540 | { | ||
| 541 | .ssl_method = TLS_method, | ||
| 542 | .minver = 0x0300, | ||
| 543 | .maxver = 0, | ||
| 544 | .want_minver = TLS1_VERSION, | ||
| 545 | .want_maxver = TLS1_2_VERSION, | ||
| 546 | }, | ||
| 547 | { | ||
| 548 | .ssl_method = TLS_method, | ||
| 549 | .minver = 0x0305, | ||
| 550 | .maxver = 0, | ||
| 551 | .want_minver = 0, | ||
| 552 | .want_maxver = 0, | ||
| 553 | }, | ||
| 554 | { | ||
| 555 | .ssl_method = TLS_method, | ||
| 556 | .minver = 0, | ||
| 557 | .maxver = 0x0305, | ||
| 558 | .want_minver = TLS1_VERSION, | ||
| 559 | .want_maxver = TLS1_2_VERSION, | ||
| 560 | }, | ||
| 561 | { | ||
| 562 | .ssl_method = TLS_method, | ||
| 563 | .minver = 0, | ||
| 564 | .maxver = TLS1_1_VERSION, | ||
| 565 | .want_minver = TLS1_VERSION, | ||
| 566 | .want_maxver = TLS1_1_VERSION, | ||
| 567 | }, | ||
| 568 | { | ||
| 569 | .ssl_method = TLS_method, | ||
| 570 | .minver = 0, | ||
| 571 | .maxver = TLS1_VERSION, | ||
| 572 | .want_minver = TLS1_VERSION, | ||
| 573 | .want_maxver = TLS1_VERSION, | ||
| 574 | }, | ||
| 575 | { | ||
| 576 | .ssl_method = TLS_method, | ||
| 577 | .minver = 0, | ||
| 578 | .maxver = 0x0300, | ||
| 579 | .want_minver = 0, | ||
| 580 | .want_maxver = 0, | ||
| 581 | }, | ||
| 582 | { | ||
| 583 | .ssl_method = TLS_method, | ||
| 584 | .minver = TLS1_2_VERSION, | ||
| 585 | .maxver = TLS1_1_VERSION, | ||
| 586 | .want_minver = TLS1_2_VERSION, | ||
| 587 | .want_maxver = 0, | ||
| 588 | }, | ||
| 589 | { | ||
| 590 | .ssl_method = TLSv1_1_method, | ||
| 591 | .minver = 0, | ||
| 592 | .maxver = 0, | ||
| 593 | .want_minver = TLS1_1_VERSION, | ||
| 594 | .want_maxver = TLS1_1_VERSION, | ||
| 595 | }, | ||
| 596 | { | ||
| 597 | .ssl_method = TLSv1_1_method, | ||
| 598 | .minver = TLS1_VERSION, | ||
| 599 | .maxver = TLS1_2_VERSION, | ||
| 600 | .want_minver = TLS1_1_VERSION, | ||
| 601 | .want_maxver = TLS1_1_VERSION, | ||
| 602 | }, | ||
| 603 | { | ||
| 604 | .ssl_method = TLSv1_1_method, | ||
| 605 | .minver = TLS1_2_VERSION, | ||
| 606 | .maxver = 0, | ||
| 607 | .want_minver = 0, | ||
| 608 | .want_maxver = 0, | ||
| 609 | }, | ||
| 610 | { | ||
| 611 | .ssl_method = TLSv1_1_method, | ||
| 612 | .minver = 0, | ||
| 613 | .maxver = TLS1_VERSION, | ||
| 614 | .want_minver = 0, | ||
| 615 | .want_maxver = 0, | ||
| 616 | }, | ||
| 617 | { | ||
| 618 | .ssl_method = DTLSv1_method, | ||
| 619 | .minver = 0, | ||
| 620 | .maxver = 0, | ||
| 621 | .want_minver = DTLS1_VERSION, | ||
| 622 | .want_maxver = DTLS1_VERSION, | ||
| 623 | }, | ||
| 624 | { | ||
| 625 | .ssl_method = DTLSv1_method, | ||
| 626 | .minver = DTLS1_VERSION, | ||
| 627 | .maxver = 0, | ||
| 628 | .want_minver = DTLS1_VERSION, | ||
| 629 | .want_maxver = DTLS1_VERSION, | ||
| 630 | }, | ||
| 631 | { | ||
| 632 | .ssl_method = DTLSv1_method, | ||
| 633 | .minver = 0, | ||
| 634 | .maxver = DTLS1_VERSION, | ||
| 635 | .want_minver = DTLS1_VERSION, | ||
| 636 | .want_maxver = DTLS1_VERSION, | ||
| 637 | }, | ||
| 638 | { | ||
| 639 | .ssl_method = DTLSv1_method, | ||
| 640 | .minver = TLS1_VERSION, | ||
| 641 | .maxver = TLS1_2_VERSION, | ||
| 642 | .want_minver = 0, | ||
| 643 | .want_maxver = 0, | ||
| 644 | }, | ||
| 645 | }; | ||
| 646 | |||
| 647 | #define N_MIN_MAX_VERSION_TESTS \ | ||
| 648 | (sizeof(min_max_version_tests) / sizeof(*min_max_version_tests)) | ||
| 649 | |||
| 650 | static int | ||
| 651 | test_ssl_min_max_version(void) | ||
| 652 | { | ||
| 653 | struct min_max_version_test *mmvt; | ||
| 654 | SSL_CTX *ssl_ctx = NULL; | ||
| 655 | SSL *ssl = NULL; | ||
| 656 | int failed = 0; | ||
| 657 | size_t i; | ||
| 658 | |||
| 659 | failed = 0; | ||
| 660 | |||
| 661 | for (i = 0; i < N_SHARED_VERSION_TESTS; i++) { | ||
| 662 | mmvt = &min_max_version_tests[i]; | ||
| 663 | |||
| 664 | if ((ssl_ctx = SSL_CTX_new(mmvt->ssl_method())) == NULL) { | ||
| 665 | fprintf(stderr, "SSL_CTX_new() returned NULL\n"); | ||
| 666 | return 1; | ||
| 667 | } | ||
| 668 | |||
| 669 | if (SSL_CTX_set_min_proto_version(ssl_ctx, mmvt->minver) != 1) { | ||
| 670 | if (mmvt->want_minver != 0) { | ||
| 671 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
| 672 | "SSL_CTX min version\n", i); | ||
| 673 | failed++; | ||
| 674 | } | ||
| 675 | goto next; | ||
| 676 | } | ||
| 677 | if (SSL_CTX_set_max_proto_version(ssl_ctx, mmvt->maxver) != 1) { | ||
| 678 | if (mmvt->want_maxver != 0) { | ||
| 679 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
| 680 | "SSL_CTX min version\n", i); | ||
| 681 | failed++; | ||
| 682 | } | ||
| 683 | goto next; | ||
| 684 | } | ||
| 685 | |||
| 686 | if (mmvt->want_minver == 0) { | ||
| 687 | fprintf(stderr, "FAIL: test %zu - successfully set " | ||
| 688 | "SSL_CTX min version, should have failed\n", i); | ||
| 689 | goto next; | ||
| 690 | } | ||
| 691 | if (mmvt->want_maxver == 0) { | ||
| 692 | fprintf(stderr, "FAIL: test %zu - successfully set " | ||
| 693 | "SSL_CTX max version, should have failed\n", i); | ||
| 694 | goto next; | ||
| 695 | } | ||
| 696 | |||
| 697 | if (SSL_CTX_get_min_proto_version(ssl_ctx) != mmvt->want_minver) { | ||
| 698 | fprintf(stderr, "FAIL: test %zu - got SSL_CTX min " | ||
| 699 | "version 0x%x, want 0x%x\n", i, | ||
| 700 | SSL_CTX_get_min_proto_version(ssl_ctx), mmvt->want_minver); | ||
| 701 | goto next; | ||
| 702 | } | ||
| 703 | if (SSL_CTX_get_max_proto_version(ssl_ctx) != mmvt->want_maxver) { | ||
| 704 | fprintf(stderr, "FAIL: test %zu - got SSL_CTX max " | ||
| 705 | "version 0x%x, want 0x%x\n", i, | ||
| 706 | SSL_CTX_get_max_proto_version(ssl_ctx), mmvt->want_maxver); | ||
| 707 | goto next; | ||
| 708 | } | ||
| 709 | |||
| 710 | if ((ssl = SSL_new(ssl_ctx)) == NULL) { | ||
| 711 | fprintf(stderr, "SSL_new() returned NULL\n"); | ||
| 712 | return 1; | ||
| 713 | } | ||
| 714 | |||
| 715 | if (SSL_get_min_proto_version(ssl) != mmvt->want_minver) { | ||
| 716 | fprintf(stderr, "FAIL: test %zu - initial SSL min " | ||
| 717 | "version 0x%x, want 0x%x\n", i, | ||
| 718 | SSL_get_min_proto_version(ssl), mmvt->want_minver); | ||
| 719 | goto next; | ||
| 720 | } | ||
| 721 | if (SSL_get_max_proto_version(ssl) != mmvt->want_maxver) { | ||
| 722 | fprintf(stderr, "FAIL: test %zu - initial SSL max " | ||
| 723 | "version 0x%x, want 0x%x\n", i, | ||
| 724 | SSL_get_max_proto_version(ssl), mmvt->want_maxver); | ||
| 725 | goto next; | ||
| 726 | } | ||
| 727 | |||
| 728 | if (SSL_set_min_proto_version(ssl, mmvt->minver) != 1) { | ||
| 729 | if (mmvt->want_minver != 0) { | ||
| 730 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
| 731 | "SSL min version\n", i); | ||
| 732 | failed++; | ||
| 733 | } | ||
| 734 | goto next; | ||
| 735 | } | ||
| 736 | if (SSL_set_max_proto_version(ssl, mmvt->maxver) != 1) { | ||
| 737 | if (mmvt->want_maxver != 0) { | ||
| 738 | fprintf(stderr, "FAIL: test %zu - failed to set " | ||
| 739 | "SSL min version\n", i); | ||
| 740 | failed++; | ||
| 741 | } | ||
| 742 | goto next; | ||
| 743 | } | ||
| 744 | |||
| 745 | if (mmvt->want_minver == 0) { | ||
| 746 | fprintf(stderr, "FAIL: test %zu - successfully set SSL " | ||
| 747 | "min version, should have failed\n", i); | ||
| 748 | goto next; | ||
| 749 | } | ||
| 750 | if (mmvt->want_maxver == 0) { | ||
| 751 | fprintf(stderr, "FAIL: test %zu - successfully set SSL " | ||
| 752 | "max version, should have failed\n", i); | ||
| 753 | goto next; | ||
| 754 | } | ||
| 755 | |||
| 756 | if (SSL_get_min_proto_version(ssl) != mmvt->want_minver) { | ||
| 757 | fprintf(stderr, "FAIL: test %zu - got SSL min " | ||
| 758 | "version 0x%x, want 0x%x\n", i, | ||
| 759 | SSL_get_min_proto_version(ssl), mmvt->want_minver); | ||
| 760 | goto next; | ||
| 761 | } | ||
| 762 | if (SSL_get_max_proto_version(ssl) != mmvt->want_maxver) { | ||
| 763 | fprintf(stderr, "FAIL: test %zu - got SSL max " | ||
| 764 | "version 0x%x, want 0x%x\n", i, | ||
| 765 | SSL_get_max_proto_version(ssl), mmvt->want_maxver); | ||
| 766 | goto next; | ||
| 767 | } | ||
| 768 | |||
| 769 | next: | ||
| 770 | SSL_CTX_free(ssl_ctx); | ||
| 771 | SSL_free(ssl); | ||
| 772 | |||
| 773 | ssl_ctx = NULL; | ||
| 774 | ssl = NULL; | ||
| 775 | } | ||
| 776 | |||
| 777 | return (failed); | ||
| 778 | } | ||
| 779 | |||
| 780 | int | ||
| 781 | main(int argc, char **argv) | ||
| 782 | { | ||
| 783 | int failed = 0; | ||
| 784 | |||
| 785 | SSL_library_init(); | ||
| 786 | |||
| 787 | /* XXX - Test ssl_supported_version_range() */ | ||
| 788 | |||
| 789 | failed |= test_ssl_enabled_version_range(); | ||
| 790 | failed |= test_ssl_max_shared_version(); | ||
| 791 | failed |= test_ssl_min_max_version(); | ||
| 792 | |||
| 793 | if (failed == 0) | ||
| 794 | printf("PASS %s\n", __FILE__); | ||
| 795 | |||
| 796 | return (failed); | ||
| 797 | } | ||
diff --git a/src/regress/lib/libssl/unit/tests.h b/src/regress/lib/libssl/unit/tests.h deleted file mode 100644 index 287816946a..0000000000 --- a/src/regress/lib/libssl/unit/tests.h +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 1 | /* $OpenBSD: tests.h,v 1.1 2015/06/27 23:35:52 doug Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef LIBRESSL_REGRESS_TESTS_H__ | ||
| 19 | #define LIBRESSL_REGRESS_TESTS_H__ 1 | ||
| 20 | |||
| 21 | /* Ugly macros that are useful for regression tests. */ | ||
| 22 | |||
| 23 | #define SKIP(a) do { \ | ||
| 24 | printf("Skipping test in %s [%s:%d]\n", __func__, __FILE__, \ | ||
| 25 | __LINE__); \ | ||
| 26 | } while (0) | ||
| 27 | |||
| 28 | #define CHECK(a) do { \ | ||
| 29 | if (!(a)) { \ | ||
| 30 | printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
| 31 | __LINE__); \ | ||
| 32 | return 0; \ | ||
| 33 | } \ | ||
| 34 | } while (0) | ||
| 35 | |||
| 36 | #define CHECK_GOTO(a) do { \ | ||
| 37 | if (!(a)) { \ | ||
| 38 | printf("Error in %s [%s:%d]\n", __func__, __FILE__, \ | ||
| 39 | __LINE__); \ | ||
| 40 | goto err; \ | ||
| 41 | } \ | ||
| 42 | } while (0) | ||
| 43 | |||
| 44 | #endif /* LIBRESSL_REGRESS_TESTS_H__ */ | ||
diff --git a/src/regress/lib/libssl/unit/tls_ext_alpn.c b/src/regress/lib/libssl/unit/tls_ext_alpn.c deleted file mode 100644 index 7dec1bfc51..0000000000 --- a/src/regress/lib/libssl/unit/tls_ext_alpn.c +++ /dev/null | |||
| @@ -1,442 +0,0 @@ | |||
| 1 | /* $OpenBSD: tls_ext_alpn.c,v 1.5 2018/02/08 11:31:00 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2015 Doug Hogan <doug@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * Test TLS extension Application-Layer Protocol Negotiation (RFC 7301). | ||
| 20 | */ | ||
| 21 | #include <stdio.h> | ||
| 22 | #include <openssl/ssl.h> | ||
| 23 | |||
| 24 | #include "ssl_locl.h" | ||
| 25 | #include "ssl_tlsext.h" | ||
| 26 | |||
| 27 | #include "tests.h" | ||
| 28 | |||
| 29 | /* | ||
| 30 | * In the ProtocolNameList, ProtocolNames must not include empty strings and | ||
| 31 | * byte strings must not be truncated. | ||
| 32 | * | ||
| 33 | * This uses some of the IANA approved protocol names from: | ||
| 34 | * http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml | ||
| 35 | */ | ||
| 36 | |||
| 37 | /* Valid for client and server since it only has one name. */ | ||
| 38 | static uint8_t proto_single[] = { | ||
| 39 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 40 | 0x00, 0x0f, /* len */ | ||
| 41 | /* ExtensionType extension_type */ | ||
| 42 | 0x00, 0x10, /* ALPN */ | ||
| 43 | /* opaque extension_data<0..2^16-1> */ | ||
| 44 | 0x00, 0x0b, /* len */ | ||
| 45 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 46 | 0x00, 0x09, /* len of all names */ | ||
| 47 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 48 | 0x08, /* len */ | ||
| 49 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 | ||
| 50 | }; | ||
| 51 | |||
| 52 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
| 53 | static uint8_t proto_multiple1[] = { | ||
| 54 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 55 | 0x00, 0x19, /* len */ | ||
| 56 | /* ExtensionType extension_type */ | ||
| 57 | 0x00, 0x10, /* ALPN */ | ||
| 58 | /* opaque extension_data<0..2^16-1> */ | ||
| 59 | 0x00, 0x15, /* len */ | ||
| 60 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 61 | 0x00, 0x13, /* len of all names */ | ||
| 62 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 63 | 0x08, /* len */ | ||
| 64 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 65 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
| 66 | 0x09, /* len */ | ||
| 67 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
| 68 | }; | ||
| 69 | |||
| 70 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
| 71 | static uint8_t proto_multiple2[] = { | ||
| 72 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 73 | 0x00, 0x1c, /* len */ | ||
| 74 | /* ExtensionType extension_type */ | ||
| 75 | 0x00, 0x10, /* ALPN */ | ||
| 76 | /* opaque extension_data<0..2^16-1> */ | ||
| 77 | 0x00, 0x18, /* len */ | ||
| 78 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 79 | 0x00, 0x16, /* len of all names */ | ||
| 80 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 81 | 0x08, /* len */ | ||
| 82 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 83 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
| 84 | 0x02, /* len */ | ||
| 85 | 0x68, 0x32, | ||
| 86 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
| 87 | 0x09, /* len */ | ||
| 88 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e | ||
| 89 | }; | ||
| 90 | |||
| 91 | /* Valid for client, but NOT server. Server must have exactly one name. */ | ||
| 92 | static uint8_t proto_multiple3[] = { | ||
| 93 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 94 | 0x00, 0x20, /* len */ | ||
| 95 | /* ExtensionType extension_type */ | ||
| 96 | 0x00, 0x10, /* ALPN */ | ||
| 97 | /* opaque extension_data<0..2^16-1> */ | ||
| 98 | 0x00, 0x1c, /* len */ | ||
| 99 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 100 | 0x00, 0x1a, /* len of all names */ | ||
| 101 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 102 | 0x08, /* len */ | ||
| 103 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 104 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
| 105 | 0x02, /* len */ | ||
| 106 | 0x68, 0x32, | ||
| 107 | /* opaque ProtocolName<1..2^8-1> -- 'stun.nat' */ | ||
| 108 | 0x09, /* len */ | ||
| 109 | 0x73, 0x74, 0x75, 0x6e, 0x2e, 0x74, 0x75, 0x72, 0x6e, | ||
| 110 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 111 | 0x03, /* len */ | ||
| 112 | 0x68, 0x32, 0x63 | ||
| 113 | }; | ||
| 114 | |||
| 115 | static uint8_t proto_empty[] = { | ||
| 116 | /* Extension extensions<0..2^16-1> -- All TLS extensions. */ | ||
| 117 | 0x00, 0x00, /* none present. */ | ||
| 118 | }; | ||
| 119 | |||
| 120 | /* Invalid for both client and server. Length is wrong. */ | ||
| 121 | static uint8_t proto_invalid_len1[] = { | ||
| 122 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 123 | 0x00, 0x0a, /* len */ | ||
| 124 | /* ExtensionType extension_type */ | ||
| 125 | 0x00, 0x10, /* ALPN */ | ||
| 126 | /* opaque extension_data<0..2^16-1> */ | ||
| 127 | 0x00, 0x06, /* len */ | ||
| 128 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 129 | 0x00, 0x04, /* len of all names */ | ||
| 130 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 131 | 0x04, /* XXX len too large */ | ||
| 132 | 0x68, 0x32, 0x63 | ||
| 133 | }; | ||
| 134 | static uint8_t proto_invalid_len2[] = { | ||
| 135 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 136 | 0x00, 0x0a, /* len */ | ||
| 137 | /* ExtensionType extension_type */ | ||
| 138 | 0x00, 0x10, /* ALPN */ | ||
| 139 | /* opaque extension_data<0..2^16-1> */ | ||
| 140 | 0x00, 0x06, /* len */ | ||
| 141 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 142 | 0x00, 0x04, /* len of all names */ | ||
| 143 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 144 | 0x02, /* XXX len too small */ | ||
| 145 | 0x68, 0x32, 0x63 | ||
| 146 | }; | ||
| 147 | static uint8_t proto_invalid_len3[] = { | ||
| 148 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 149 | 0x00, 0x0a, /* len */ | ||
| 150 | /* ExtensionType extension_type */ | ||
| 151 | 0x00, 0x10, /* ALPN */ | ||
| 152 | /* opaque extension_data<0..2^16-1> */ | ||
| 153 | 0x00, 0x06, /* len */ | ||
| 154 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 155 | 0x00, 0x03, /* XXX len too small */ | ||
| 156 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 157 | 0x03, /* len */ | ||
| 158 | 0x68, 0x32, 0x63 | ||
| 159 | }; | ||
| 160 | static uint8_t proto_invalid_len4[] = { | ||
| 161 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 162 | 0x00, 0x0a, /* len */ | ||
| 163 | /* ExtensionType extension_type */ | ||
| 164 | 0x00, 0x10, /* ALPN */ | ||
| 165 | /* opaque extension_data<0..2^16-1> */ | ||
| 166 | 0x00, 0x06, /* len */ | ||
| 167 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 168 | 0x00, 0x06, /* XXX len too large */ | ||
| 169 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 170 | 0x03, /* len */ | ||
| 171 | 0x68, 0x32, 0x63 | ||
| 172 | }; | ||
| 173 | static uint8_t proto_invalid_len5[] = { | ||
| 174 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 175 | 0x00, 0x0a, /* len */ | ||
| 176 | /* ExtensionType extension_type */ | ||
| 177 | 0x00, 0x10, /* ALPN */ | ||
| 178 | /* opaque extension_data<0..2^16-1> */ | ||
| 179 | 0x01, 0x08, /* XXX len too large */ | ||
| 180 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 181 | 0x00, 0x04, /* len */ | ||
| 182 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 183 | 0x03, /* len */ | ||
| 184 | 0x68, 0x32, 0x63 | ||
| 185 | }; | ||
| 186 | static uint8_t proto_invalid_len6[] = { | ||
| 187 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 188 | 0x00, 0x0a, /* len */ | ||
| 189 | /* ExtensionType extension_type */ | ||
| 190 | 0x00, 0x10, /* ALPN */ | ||
| 191 | /* opaque extension_data<0..2^16-1> */ | ||
| 192 | 0x00, 0x05, /* XXX len too small */ | ||
| 193 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 194 | 0x00, 0x04, /* len */ | ||
| 195 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 196 | 0x03, /* len */ | ||
| 197 | 0x68, 0x32, 0x63 | ||
| 198 | }; | ||
| 199 | static uint8_t proto_invalid_len7[] = { | ||
| 200 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 201 | 0x00, 0x06, /* XXX len too small */ | ||
| 202 | /* ExtensionType extension_type */ | ||
| 203 | 0x00, 0x10, /* ALPN */ | ||
| 204 | /* opaque extension_data<0..2^16-1> */ | ||
| 205 | 0x00, 0x06, /* len */ | ||
| 206 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 207 | 0x00, 0x04, /* len */ | ||
| 208 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 209 | 0x03, /* len */ | ||
| 210 | 0x68, 0x32, 0x63 | ||
| 211 | }; | ||
| 212 | static uint8_t proto_invalid_len8[] = { | ||
| 213 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 214 | 0x00, 0x0b, /* XXX len too large */ | ||
| 215 | /* ExtensionType extension_type */ | ||
| 216 | 0x00, 0x10, /* ALPN */ | ||
| 217 | /* opaque extension_data<0..2^16-1> */ | ||
| 218 | 0x00, 0x06, /* len */ | ||
| 219 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 220 | 0x00, 0x04, /* len */ | ||
| 221 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 222 | 0x03, /* len */ | ||
| 223 | 0x68, 0x32, 0x63 | ||
| 224 | }; | ||
| 225 | |||
| 226 | /* Invalid for client and server since it is missing data. */ | ||
| 227 | static uint8_t proto_invalid_missing1[] = { | ||
| 228 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 229 | 0x00, 0x0a, /* len */ | ||
| 230 | /* ExtensionType extension_type */ | ||
| 231 | 0x00, 0x10, /* ALPN */ | ||
| 232 | /* opaque extension_data<0..2^16-1> */ | ||
| 233 | 0x00, 0x06, /* len */ | ||
| 234 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 235 | 0x00, 0x04, /* len of all names */ | ||
| 236 | /* opaque ProtocolName<1..2^8-1> -- 'h2c' */ | ||
| 237 | /* XXX missing */ | ||
| 238 | }; | ||
| 239 | static uint8_t proto_invalid_missing2[] = { | ||
| 240 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 241 | 0x00, 0x0a, /* len */ | ||
| 242 | /* ExtensionType extension_type */ | ||
| 243 | 0x00, 0x10, /* ALPN */ | ||
| 244 | /* opaque extension_data<0..2^16-1> */ | ||
| 245 | 0x00, 0x00, /* XXX missing name list */ | ||
| 246 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 247 | }; | ||
| 248 | static uint8_t proto_invalid_missing3[] = { | ||
| 249 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 250 | 0x00, 0x0a, /* len */ | ||
| 251 | /* ExtensionType extension_type */ | ||
| 252 | 0x00, 0x10, /* ALPN */ | ||
| 253 | /* opaque extension_data<0..2^16-1> */ | ||
| 254 | 0x00, 0x02, /* XXX size is sufficient but missing data for name list */ | ||
| 255 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 256 | }; | ||
| 257 | static uint8_t proto_invalid_missing4[] = { | ||
| 258 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 259 | 0x00, 0x0a, /* len */ | ||
| 260 | /* ExtensionType extension_type */ | ||
| 261 | 0x00, 0x10, /* ALPN */ | ||
| 262 | /* opaque extension_data<0..2^16-1> */ | ||
| 263 | /* XXX missing */ | ||
| 264 | }; | ||
| 265 | static uint8_t proto_invalid_missing5[] = { | ||
| 266 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 267 | 0x00, 0x1c, /* len */ | ||
| 268 | /* ExtensionType extension_type */ | ||
| 269 | 0x00, 0x10, /* ALPN */ | ||
| 270 | /* opaque extension_data<0..2^16-1> */ | ||
| 271 | 0x00, 0x18, /* len */ | ||
| 272 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 273 | 0x00, 0x16, /* len of all names */ | ||
| 274 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 275 | 0x08, /* len */ | ||
| 276 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, | ||
| 277 | /* opaque ProtocolName<1..2^8-1> -- 'h2' */ | ||
| 278 | 0x02, /* len */ | ||
| 279 | 0x68, 0x32, | ||
| 280 | /* XXX missing name */ | ||
| 281 | }; | ||
| 282 | static uint8_t proto_invalid_missing6[] = { | ||
| 283 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 284 | 0x00, 0x07, /* len */ | ||
| 285 | /* ExtensionType extension_type */ | ||
| 286 | 0x00, 0x10, /* ALPN */ | ||
| 287 | /* opaque extension_data<0..2^16-1> */ | ||
| 288 | 0x00, 0x03, /* len */ | ||
| 289 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 290 | 0x00, 0x01, /* XXX len must be at least 2 */ | ||
| 291 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 292 | 0x00, /* XXX len cannot be 0 */ | ||
| 293 | }; | ||
| 294 | static uint8_t proto_invalid_missing7[] = { | ||
| 295 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 296 | 0x00, 0x07, /* len */ | ||
| 297 | /* ExtensionType extension_type */ | ||
| 298 | 0x00, 0x10, /* ALPN */ | ||
| 299 | /* opaque extension_data<0..2^16-1> */ | ||
| 300 | 0x00, 0x03, /* len */ | ||
| 301 | /* ProtocolName protocol_name_list<2..2^16-1> -- ALPN names */ | ||
| 302 | 0x00, 0x02, /* XXX len is at least 2 but not correct. */ | ||
| 303 | /* opaque ProtocolName<1..2^8-1> -- 'http/1.1' */ | ||
| 304 | 0x00, /* XXX len cannot be 0 */ | ||
| 305 | }; | ||
| 306 | static uint8_t proto_invalid_missing8[] = { | ||
| 307 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 308 | 0x00, 0x01, /* len */ | ||
| 309 | /* ExtensionType extension_type */ | ||
| 310 | 0x00, /* XXX need a 2 byte type */ | ||
| 311 | }; | ||
| 312 | static uint8_t proto_invalid_missing9[] = { | ||
| 313 | /* Extension extensions<0..2^16-1> -- All TLS extensions */ | ||
| 314 | 0x0a, /* XXX need a 2 byte len */ | ||
| 315 | }; | ||
| 316 | |||
| 317 | |||
| 318 | #define CHECK_BOTH(c_val, s_val, proto) do { \ | ||
| 319 | { \ | ||
| 320 | CBS cbs; \ | ||
| 321 | int al; \ | ||
| 322 | \ | ||
| 323 | CBS_init(&cbs, proto, sizeof(proto)); \ | ||
| 324 | CHECK(c_val == tlsext_clienthello_parse(s, &cbs, &al)); \ | ||
| 325 | CBS_init(&cbs, proto, sizeof(proto)); \ | ||
| 326 | CHECK(s_val == tlsext_serverhello_parse(s, &cbs, &al)); \ | ||
| 327 | } \ | ||
| 328 | } while (0) | ||
| 329 | |||
| 330 | static int dummy_alpn_cb(SSL *ssl, const unsigned char **out, | ||
| 331 | unsigned char *outlen, const unsigned char *in, unsigned int inlen, | ||
| 332 | void *arg); | ||
| 333 | |||
| 334 | static int | ||
| 335 | check_valid_alpn(SSL *s) | ||
| 336 | { | ||
| 337 | const uint8_t str[] = { | ||
| 338 | 0x08, /* len */ | ||
| 339 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* http/1.1 */ | ||
| 340 | }; | ||
| 341 | |||
| 342 | /* Setup in order to test ALPN. */ | ||
| 343 | CHECK(! SSL_set_alpn_protos(s, str, 9)); | ||
| 344 | SSL_CTX_set_alpn_select_cb(s->ctx, dummy_alpn_cb, NULL); | ||
| 345 | |||
| 346 | /* Prerequisites to test these. */ | ||
| 347 | CHECK(s->internal->alpn_client_proto_list != NULL); | ||
| 348 | CHECK(s->ctx->internal->alpn_select_cb != NULL); | ||
| 349 | //CHECK(s->s3->tmp.finish_md_len == 0); | ||
| 350 | |||
| 351 | CHECK_BOTH(1, 1, proto_single); | ||
| 352 | CHECK_BOTH(1, 1, proto_empty); | ||
| 353 | |||
| 354 | /* Multiple protocol names are only valid for client */ | ||
| 355 | CHECK_BOTH(1, 0, proto_multiple1); | ||
| 356 | CHECK_BOTH(1, 0, proto_multiple2); | ||
| 357 | CHECK_BOTH(1, 0, proto_multiple3); | ||
| 358 | |||
| 359 | return 1; | ||
| 360 | } | ||
| 361 | |||
| 362 | /* | ||
| 363 | * Some of the IANA approved IDs from: | ||
| 364 | * http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml | ||
| 365 | */ | ||
| 366 | static int | ||
| 367 | check_invalid_alpn(SSL *s) | ||
| 368 | { | ||
| 369 | const uint8_t str[] = { | ||
| 370 | 0x08, /* len */ | ||
| 371 | 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31 /* http/1.1 */ | ||
| 372 | }; | ||
| 373 | |||
| 374 | /* Setup in order to test ALPN. */ | ||
| 375 | CHECK(! SSL_set_alpn_protos(s, str, 9)); | ||
| 376 | SSL_CTX_set_alpn_select_cb(s->ctx, dummy_alpn_cb, NULL); | ||
| 377 | |||
| 378 | /* Prerequisites to test these. */ | ||
| 379 | CHECK(s->internal->alpn_client_proto_list != NULL); | ||
| 380 | CHECK(s->ctx->internal->alpn_select_cb != NULL); | ||
| 381 | //CHECK(s->s3->tmp.finish_md_len == 0); | ||
| 382 | |||
| 383 | /* None of these are valid for client or server */ | ||
| 384 | CHECK_BOTH(0, 0, proto_invalid_len1); | ||
| 385 | CHECK_BOTH(0, 0, proto_invalid_len2); | ||
| 386 | CHECK_BOTH(0, 0, proto_invalid_len3); | ||
| 387 | CHECK_BOTH(0, 0, proto_invalid_len4); | ||
| 388 | CHECK_BOTH(0, 0, proto_invalid_len5); | ||
| 389 | CHECK_BOTH(0, 0, proto_invalid_len6); | ||
| 390 | CHECK_BOTH(0, 0, proto_invalid_len7); | ||
| 391 | CHECK_BOTH(0, 0, proto_invalid_len8); | ||
| 392 | CHECK_BOTH(0, 0, proto_invalid_missing1); | ||
| 393 | CHECK_BOTH(0, 0, proto_invalid_missing2); | ||
| 394 | CHECK_BOTH(0, 0, proto_invalid_missing3); | ||
| 395 | CHECK_BOTH(0, 0, proto_invalid_missing4); | ||
| 396 | CHECK_BOTH(0, 0, proto_invalid_missing5); | ||
| 397 | CHECK_BOTH(0, 0, proto_invalid_missing6); | ||
| 398 | CHECK_BOTH(0, 0, proto_invalid_missing7); | ||
| 399 | CHECK_BOTH(0, 0, proto_invalid_missing8); | ||
| 400 | CHECK_BOTH(0, 0, proto_invalid_missing9); | ||
| 401 | |||
| 402 | return 1; | ||
| 403 | } | ||
| 404 | |||
| 405 | int | ||
| 406 | dummy_alpn_cb(SSL *ssl __attribute__((unused)), const unsigned char **out, | ||
| 407 | unsigned char *outlen, const unsigned char *in, unsigned int inlen, | ||
| 408 | void *arg __attribute__((unused))) | ||
| 409 | { | ||
| 410 | *out = in; | ||
| 411 | *outlen = (unsigned char)inlen; | ||
| 412 | |||
| 413 | return 0; | ||
| 414 | } | ||
| 415 | |||
| 416 | int | ||
| 417 | main(void) | ||
| 418 | { | ||
| 419 | SSL_CTX *ctx = NULL; | ||
| 420 | SSL *s = NULL; | ||
| 421 | int rv = 1; | ||
| 422 | |||
| 423 | SSL_library_init(); | ||
| 424 | |||
| 425 | CHECK_GOTO((ctx = SSL_CTX_new(TLSv1_2_client_method())) != NULL); | ||
| 426 | CHECK_GOTO((s = SSL_new(ctx)) != NULL); | ||
| 427 | |||
| 428 | if (!check_valid_alpn(s)) | ||
| 429 | goto err; | ||
| 430 | if (!check_invalid_alpn(s)) | ||
| 431 | goto err; | ||
| 432 | |||
| 433 | rv = 0; | ||
| 434 | |||
| 435 | err: | ||
| 436 | SSL_CTX_free(ctx); | ||
| 437 | SSL_free(s); | ||
| 438 | |||
| 439 | if (!rv) | ||
| 440 | printf("PASS %s\n", __FILE__); | ||
| 441 | return rv; | ||
| 442 | } | ||
diff --git a/src/regress/lib/libssl/unit/tls_prf.c b/src/regress/lib/libssl/unit/tls_prf.c deleted file mode 100644 index 2eacb12af3..0000000000 --- a/src/regress/lib/libssl/unit/tls_prf.c +++ /dev/null | |||
| @@ -1,251 +0,0 @@ | |||
| 1 | /* $OpenBSD: tls_prf.c,v 1.4 2017/05/06 22:24:58 beck Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | |||
| 20 | #include "ssl_locl.h" | ||
| 21 | |||
| 22 | int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len, | ||
| 23 | const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len, | ||
| 24 | const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len, | ||
| 25 | const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len); | ||
| 26 | |||
| 27 | #define TLS_PRF_OUT_LEN 128 | ||
| 28 | |||
| 29 | struct tls_prf_test { | ||
| 30 | const unsigned char *desc; | ||
| 31 | const SSL_METHOD *(*ssl_method)(void); | ||
| 32 | const uint16_t cipher_value; | ||
| 33 | const unsigned char out[TLS_PRF_OUT_LEN]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | static struct tls_prf_test tls_prf_tests[] = { | ||
| 37 | { | ||
| 38 | .desc = "MD5+SHA1", | ||
| 39 | .ssl_method = TLSv1_method, | ||
| 40 | .cipher_value = 0x0033, | ||
| 41 | .out = { | ||
| 42 | 0x03, 0xa1, 0xc1, 0x7d, 0x2c, 0xa5, 0x3d, 0xe8, | ||
| 43 | 0x9d, 0x59, 0x5e, 0x30, 0xf5, 0x71, 0xbb, 0x96, | ||
| 44 | 0xde, 0x5c, 0x8e, 0xdc, 0x25, 0x8a, 0x7c, 0x05, | ||
| 45 | 0x9f, 0x7d, 0x35, 0x29, 0x45, 0xae, 0x56, 0xad, | ||
| 46 | 0x9f, 0x57, 0x15, 0x5c, 0xdb, 0x83, 0x3a, 0xac, | ||
| 47 | 0x19, 0xa8, 0x2b, 0x40, 0x72, 0x38, 0x1e, 0xed, | ||
| 48 | 0xf3, 0x25, 0xde, 0x84, 0x84, 0xd8, 0xd1, 0xfc, | ||
| 49 | 0x31, 0x85, 0x81, 0x12, 0x55, 0x4d, 0x12, 0xb5, | ||
| 50 | 0xed, 0x78, 0x5e, 0xba, 0xc8, 0xec, 0x8d, 0x28, | ||
| 51 | 0xa1, 0x21, 0x1e, 0x6e, 0x07, 0xf1, 0xfc, 0xf5, | ||
| 52 | 0xbf, 0xe4, 0x8e, 0x8e, 0x97, 0x15, 0x93, 0x85, | ||
| 53 | 0x75, 0xdd, 0x87, 0x09, 0xd0, 0x4e, 0xe5, 0xd5, | ||
| 54 | 0x9e, 0x1f, 0xd6, 0x1c, 0x3b, 0xe9, 0xad, 0xba, | ||
| 55 | 0xe0, 0x16, 0x56, 0x62, 0x90, 0xd6, 0x82, 0x84, | ||
| 56 | 0xec, 0x8a, 0x22, 0xbe, 0xdc, 0x6a, 0x5e, 0x05, | ||
| 57 | 0x12, 0x44, 0xec, 0x60, 0x61, 0xd1, 0x8a, 0x66, | ||
| 58 | }, | ||
| 59 | }, | ||
| 60 | { | ||
| 61 | .desc = "GOST94", | ||
| 62 | .ssl_method = TLSv1_2_method, | ||
| 63 | .cipher_value = 0x0081, | ||
| 64 | .out = { | ||
| 65 | 0xcc, 0xd4, 0x89, 0x5f, 0x52, 0x08, 0x9b, 0xc7, | ||
| 66 | 0xf9, 0xb5, 0x83, 0x58, 0xe8, 0xc7, 0x71, 0x49, | ||
| 67 | 0x39, 0x99, 0x1f, 0x14, 0x8f, 0x85, 0xbe, 0x64, | ||
| 68 | 0xee, 0x40, 0x5c, 0xe7, 0x5f, 0x68, 0xaf, 0xf2, | ||
| 69 | 0xcd, 0x3a, 0x94, 0x52, 0x33, 0x53, 0x46, 0x7d, | ||
| 70 | 0xb6, 0xc5, 0xe1, 0xb8, 0xa4, 0x04, 0x69, 0x91, | ||
| 71 | 0x0a, 0x9c, 0x88, 0x86, 0xd9, 0x60, 0x63, 0xdd, | ||
| 72 | 0xd8, 0xe7, 0x2e, 0xee, 0xce, 0xe2, 0x20, 0xd8, | ||
| 73 | 0x9a, 0xfa, 0x9c, 0x63, 0x0c, 0x9c, 0xa1, 0x76, | ||
| 74 | 0xed, 0x78, 0x9a, 0x84, 0x70, 0xb4, 0xd1, 0x51, | ||
| 75 | 0x1f, 0xde, 0x44, 0xe8, 0x90, 0x21, 0x3f, 0xeb, | ||
| 76 | 0x05, 0xf4, 0x77, 0x59, 0xf3, 0xad, 0xdd, 0x34, | ||
| 77 | 0x3d, 0x3a, 0x7c, 0xd0, 0x59, 0x40, 0xe1, 0x3f, | ||
| 78 | 0x04, 0x4b, 0x8b, 0xd6, 0x95, 0x46, 0xb4, 0x9e, | ||
| 79 | 0x4c, 0x2d, 0xf7, 0xee, 0xbd, 0xbc, 0xcb, 0x5c, | ||
| 80 | 0x3a, 0x36, 0x0c, 0xd0, 0x27, 0xcb, 0x45, 0x06, | ||
| 81 | }, | ||
| 82 | }, | ||
| 83 | { | ||
| 84 | .desc = "SHA256 (via TLSv1.2)", | ||
| 85 | .ssl_method = TLSv1_2_method, | ||
| 86 | .cipher_value = 0x0033, | ||
| 87 | .out = { | ||
| 88 | 0x37, 0xa7, 0x06, 0x71, 0x6e, 0x19, 0x19, 0xda, | ||
| 89 | 0x23, 0x8c, 0xcc, 0xb4, 0x2f, 0x31, 0x64, 0x9d, | ||
| 90 | 0x05, 0x29, 0x1c, 0x33, 0x7e, 0x09, 0x1b, 0x0c, | ||
| 91 | 0x0e, 0x23, 0xc1, 0xb0, 0x40, 0xcc, 0x31, 0xf7, | ||
| 92 | 0x55, 0x66, 0x68, 0xd9, 0xa8, 0xae, 0x74, 0x75, | ||
| 93 | 0xf3, 0x46, 0xe9, 0x3a, 0x54, 0x9d, 0xe0, 0x8b, | ||
| 94 | 0x7e, 0x6c, 0x63, 0x1c, 0xfa, 0x2f, 0xfd, 0xc9, | ||
| 95 | 0xd3, 0xf1, 0xd3, 0xfe, 0x7b, 0x9e, 0x14, 0x95, | ||
| 96 | 0xb5, 0xd0, 0xad, 0x9b, 0xee, 0x78, 0x8c, 0x83, | ||
| 97 | 0x18, 0x58, 0x7e, 0xa2, 0x23, 0xc1, 0x8b, 0x62, | ||
| 98 | 0x94, 0x12, 0xcb, 0xb6, 0x60, 0x69, 0x32, 0xfe, | ||
| 99 | 0x98, 0x0e, 0x93, 0xb0, 0x8e, 0x5c, 0xfb, 0x6e, | ||
| 100 | 0xdb, 0x9a, 0xc2, 0x9f, 0x8c, 0x5c, 0x43, 0x19, | ||
| 101 | 0xeb, 0x4a, 0x52, 0xad, 0x62, 0x2b, 0xdd, 0x9f, | ||
| 102 | 0xa3, 0x74, 0xa6, 0x96, 0x61, 0x4d, 0x98, 0x40, | ||
| 103 | 0x63, 0xa6, 0xd4, 0xbb, 0x17, 0x11, 0x75, 0xed, | ||
| 104 | }, | ||
| 105 | }, | ||
| 106 | { | ||
| 107 | .desc = "SHA384", | ||
| 108 | .ssl_method = TLSv1_2_method, | ||
| 109 | .cipher_value = 0x009d, | ||
| 110 | .out = { | ||
| 111 | 0x00, 0x93, 0xc3, 0xfd, 0xa7, 0xbb, 0xdc, 0x5b, | ||
| 112 | 0x13, 0x3a, 0xe6, 0x8b, 0x1b, 0xac, 0xf3, 0xfb, | ||
| 113 | 0x3c, 0x9a, 0x78, 0xf6, 0x19, 0xf0, 0x13, 0x0f, | ||
| 114 | 0x0d, 0x01, 0x9d, 0xdf, 0x0a, 0x28, 0x38, 0xce, | ||
| 115 | 0x1a, 0x9b, 0x43, 0xbe, 0x56, 0x12, 0xa7, 0x16, | ||
| 116 | 0x58, 0xe1, 0x8a, 0xe4, 0xc5, 0xbb, 0x10, 0x4c, | ||
| 117 | 0x3a, 0xf3, 0x7f, 0xd3, 0xdb, 0xe4, 0xe0, 0x3d, | ||
| 118 | 0xcc, 0x83, 0xca, 0xf0, 0xf9, 0x69, 0xcc, 0x70, | ||
| 119 | 0x83, 0x32, 0xf6, 0xfc, 0x81, 0x80, 0x02, 0xe8, | ||
| 120 | 0x31, 0x1e, 0x7c, 0x3b, 0x34, 0xf7, 0x34, 0xd1, | ||
| 121 | 0xcf, 0x2a, 0xc4, 0x36, 0x2f, 0xe9, 0xaa, 0x7f, | ||
| 122 | 0x6d, 0x1f, 0x5e, 0x0e, 0x39, 0x05, 0x15, 0xe1, | ||
| 123 | 0xa2, 0x9a, 0x4d, 0x97, 0x8c, 0x62, 0x46, 0xf1, | ||
| 124 | 0x87, 0x65, 0xd8, 0xe9, 0x14, 0x11, 0xa6, 0x48, | ||
| 125 | 0xd7, 0x0e, 0x6e, 0x70, 0xad, 0xfb, 0x3f, 0x36, | ||
| 126 | 0x05, 0x76, 0x4b, 0xe4, 0x28, 0x50, 0x4a, 0xf2, | ||
| 127 | }, | ||
| 128 | }, | ||
| 129 | { | ||
| 130 | .desc = "STREEBOG256", | ||
| 131 | .ssl_method = TLSv1_2_method, | ||
| 132 | .cipher_value = 0xff87, | ||
| 133 | .out = { | ||
| 134 | 0x3e, 0x13, 0xb9, 0xeb, 0x85, 0x8c, 0xb4, 0x21, | ||
| 135 | 0x23, 0x40, 0x9b, 0x73, 0x04, 0x56, 0xe2, 0xff, | ||
| 136 | 0xce, 0x52, 0x1f, 0x82, 0x7f, 0x17, 0x5b, 0x80, | ||
| 137 | 0x23, 0x71, 0xca, 0x30, 0xdf, 0xfc, 0xdc, 0x2d, | ||
| 138 | 0xc0, 0xfc, 0x5d, 0x23, 0x5a, 0x54, 0x7f, 0xae, | ||
| 139 | 0xf5, 0x7d, 0x52, 0x1e, 0x86, 0x95, 0xe1, 0x2d, | ||
| 140 | 0x28, 0xe7, 0xbe, 0xd7, 0xd0, 0xbf, 0xa9, 0x96, | ||
| 141 | 0x13, 0xd0, 0x9c, 0x0c, 0x1c, 0x16, 0x05, 0xbb, | ||
| 142 | 0x26, 0xd7, 0x30, 0x39, 0xb9, 0x53, 0x28, 0x98, | ||
| 143 | 0x4f, 0x1b, 0x83, 0xc3, 0xce, 0x1c, 0x7c, 0x34, | ||
| 144 | 0xa2, 0xc4, 0x7a, 0x54, 0x16, 0xc6, 0xa7, 0x9e, | ||
| 145 | 0xed, 0x4b, 0x7b, 0x83, 0xa6, 0xae, 0xe2, 0x5b, | ||
| 146 | 0x96, 0xf5, 0x6c, 0xad, 0x1f, 0xa3, 0x83, 0xb2, | ||
| 147 | 0x84, 0x32, 0xed, 0xe3, 0x2c, 0xf6, 0xd4, 0x73, | ||
| 148 | 0x30, 0xef, 0x9d, 0xbe, 0xe7, 0x23, 0x9a, 0xbf, | ||
| 149 | 0x4d, 0x1c, 0xe7, 0xef, 0x3d, 0xea, 0x46, 0xe2, | ||
| 150 | }, | ||
| 151 | }, | ||
| 152 | }; | ||
| 153 | |||
| 154 | #define N_TLS_PRF_TESTS \ | ||
| 155 | (sizeof(tls_prf_tests) / sizeof(*tls_prf_tests)) | ||
| 156 | |||
| 157 | #define TLS_PRF_SEED1 "tls prf seed 1" | ||
| 158 | #define TLS_PRF_SEED2 "tls prf seed 2" | ||
| 159 | #define TLS_PRF_SEED3 "tls prf seed 3" | ||
| 160 | #define TLS_PRF_SEED4 "tls prf seed 4" | ||
| 161 | #define TLS_PRF_SEED5 "tls prf seed 5" | ||
| 162 | #define TLS_PRF_SECRET "tls prf secretz" | ||
| 163 | |||
| 164 | static void | ||
| 165 | hexdump(const unsigned char *buf, size_t len) | ||
| 166 | { | ||
| 167 | size_t i; | ||
| 168 | |||
| 169 | for (i = 1; i <= len; i++) | ||
| 170 | fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); | ||
| 171 | |||
| 172 | fprintf(stderr, "\n"); | ||
| 173 | } | ||
| 174 | |||
| 175 | static int | ||
| 176 | do_tls_prf_test(int test_no, struct tls_prf_test *tpt) | ||
| 177 | { | ||
| 178 | unsigned char *out = NULL; | ||
| 179 | const SSL_CIPHER *cipher; | ||
| 180 | SSL_CTX *ssl_ctx = NULL; | ||
| 181 | SSL *ssl = NULL; | ||
| 182 | int failure = 1; | ||
| 183 | int len; | ||
| 184 | |||
| 185 | fprintf(stderr, "Test %i - %s\n", test_no, tpt->desc); | ||
| 186 | |||
| 187 | if ((out = malloc(TLS_PRF_OUT_LEN)) == NULL) | ||
| 188 | errx(1, "failed to allocate out"); | ||
| 189 | |||
| 190 | if ((ssl_ctx = SSL_CTX_new(tpt->ssl_method())) == NULL) | ||
| 191 | errx(1, "failed to create SSL context"); | ||
| 192 | if ((ssl = SSL_new(ssl_ctx)) == NULL) | ||
| 193 | errx(1, "failed to create SSL context"); | ||
| 194 | |||
| 195 | if ((cipher = ssl3_get_cipher_by_value(tpt->cipher_value)) == NULL) { | ||
| 196 | fprintf(stderr, "FAIL: no cipher %hx\n", tpt->cipher_value); | ||
| 197 | goto failure; | ||
| 198 | } | ||
| 199 | |||
| 200 | S3I(ssl)->hs.new_cipher = cipher; | ||
| 201 | |||
| 202 | for (len = 1; len <= TLS_PRF_OUT_LEN; len++) { | ||
| 203 | memset(out, 'A', TLS_PRF_OUT_LEN); | ||
| 204 | |||
| 205 | if (tls1_PRF(ssl, TLS_PRF_SECRET, sizeof(TLS_PRF_SECRET), | ||
| 206 | TLS_PRF_SEED1, sizeof(TLS_PRF_SEED1), TLS_PRF_SEED2, | ||
| 207 | sizeof(TLS_PRF_SEED2), TLS_PRF_SEED3, sizeof(TLS_PRF_SEED3), | ||
| 208 | TLS_PRF_SEED4, sizeof(TLS_PRF_SEED4), TLS_PRF_SEED5, | ||
| 209 | sizeof(TLS_PRF_SEED5), out, len) != 1) { | ||
| 210 | fprintf(stderr, "FAIL: tls_PRF failed for len %i\n", | ||
| 211 | len); | ||
| 212 | goto failure; | ||
| 213 | } | ||
| 214 | |||
| 215 | if (memcmp(out, tpt->out, len) != 0) { | ||
| 216 | fprintf(stderr, "FAIL: tls_PRF output differs for " | ||
| 217 | "len %i\n", len); | ||
| 218 | fprintf(stderr, "output:\n"); | ||
| 219 | hexdump(out, TLS_PRF_OUT_LEN); | ||
| 220 | fprintf(stderr, "test data:\n"); | ||
| 221 | hexdump(tpt->out, TLS_PRF_OUT_LEN); | ||
| 222 | fprintf(stderr, "\n"); | ||
| 223 | goto failure; | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | failure = 0; | ||
| 228 | |||
| 229 | failure: | ||
| 230 | SSL_free(ssl); | ||
| 231 | SSL_CTX_free(ssl_ctx); | ||
| 232 | |||
| 233 | free(out); | ||
| 234 | |||
| 235 | return failure; | ||
| 236 | } | ||
| 237 | |||
| 238 | int | ||
| 239 | main(int argc, char **argv) | ||
| 240 | { | ||
| 241 | int failed = 0; | ||
| 242 | size_t i; | ||
| 243 | |||
| 244 | SSL_library_init(); | ||
| 245 | SSL_load_error_strings(); | ||
| 246 | |||
| 247 | for (i = 0; i < N_TLS_PRF_TESTS; i++) | ||
| 248 | failed |= do_tls_prf_test(i, &tls_prf_tests[i]); | ||
| 249 | |||
| 250 | return failed; | ||
| 251 | } | ||
diff --git a/src/regress/lib/libtls/Makefile b/src/regress/lib/libtls/Makefile deleted file mode 100644 index f522605a90..0000000000 --- a/src/regress/lib/libtls/Makefile +++ /dev/null | |||
| @@ -1,12 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2018/02/08 10:06:52 jsing Exp $ | ||
| 2 | |||
| 3 | SUBDIR= \ | ||
| 4 | config \ | ||
| 5 | keypair \ | ||
| 6 | gotls \ | ||
| 7 | tls \ | ||
| 8 | verify | ||
| 9 | |||
| 10 | install: | ||
| 11 | |||
| 12 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libtls/Makefile.inc b/src/regress/lib/libtls/Makefile.inc deleted file mode 100644 index e693da81b4..0000000000 --- a/src/regress/lib/libtls/Makefile.inc +++ /dev/null | |||
| @@ -1,2 +0,0 @@ | |||
| 1 | # Use this variable when the test needs internal symbols from libtls | ||
| 2 | TLS_INT= -Wl,-Bstatic -ltls -Wl,-Bdynamic | ||
diff --git a/src/regress/lib/libtls/config/Makefile b/src/regress/lib/libtls/config/Makefile deleted file mode 100644 index 02c36c5d93..0000000000 --- a/src/regress/lib/libtls/config/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2018/02/08 10:05:43 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= configtest | ||
| 4 | LDADD= -lcrypto -lssl -ltls | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} | ||
| 6 | |||
| 7 | WARNINGS= Yes | ||
| 8 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libtls/config/configtest.c b/src/regress/lib/libtls/config/configtest.c deleted file mode 100644 index 61474aa85c..0000000000 --- a/src/regress/lib/libtls/config/configtest.c +++ /dev/null | |||
| @@ -1,171 +0,0 @@ | |||
| 1 | /* $OpenBSD: configtest.c,v 1.1 2017/12/09 16:43:09 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | |||
| 22 | #include <tls.h> | ||
| 23 | |||
| 24 | struct parse_protocols_test { | ||
| 25 | const char *protostr; | ||
| 26 | int want_return; | ||
| 27 | uint32_t want_protocols; | ||
| 28 | }; | ||
| 29 | |||
| 30 | struct parse_protocols_test parse_protocols_tests[] = { | ||
| 31 | { | ||
| 32 | .protostr = NULL, | ||
| 33 | .want_return = 0, | ||
| 34 | .want_protocols = TLS_PROTOCOLS_DEFAULT, | ||
| 35 | }, | ||
| 36 | { | ||
| 37 | .protostr = "default", | ||
| 38 | .want_return = 0, | ||
| 39 | .want_protocols = TLS_PROTOCOLS_DEFAULT, | ||
| 40 | }, | ||
| 41 | { | ||
| 42 | .protostr = "secure", | ||
| 43 | .want_return = 0, | ||
| 44 | .want_protocols = TLS_PROTOCOLS_DEFAULT, | ||
| 45 | }, | ||
| 46 | { | ||
| 47 | .protostr = "all", | ||
| 48 | .want_return = 0, | ||
| 49 | .want_protocols = TLS_PROTOCOLS_ALL, | ||
| 50 | }, | ||
| 51 | { | ||
| 52 | .protostr = "tlsv1", | ||
| 53 | .want_return = 0, | ||
| 54 | .want_protocols = TLS_PROTOCOL_TLSv1, | ||
| 55 | }, | ||
| 56 | { | ||
| 57 | .protostr = "tlsv1.2", | ||
| 58 | .want_return = 0, | ||
| 59 | .want_protocols = TLS_PROTOCOL_TLSv1_2, | ||
| 60 | }, | ||
| 61 | { | ||
| 62 | .protostr = "", | ||
| 63 | .want_return = -1, | ||
| 64 | .want_protocols = 0, | ||
| 65 | }, | ||
| 66 | { | ||
| 67 | .protostr = "tlsv1.0:tlsv1.1:tlsv1.2", | ||
| 68 | .want_return = 0, | ||
| 69 | .want_protocols = TLS_PROTOCOL_TLSv1_0 | TLS_PROTOCOL_TLSv1_1 | | ||
| 70 | TLS_PROTOCOL_TLSv1_2, | ||
| 71 | }, | ||
| 72 | { | ||
| 73 | .protostr = "tlsv1.0,tlsv1.1,tlsv1.2", | ||
| 74 | .want_return = 0, | ||
| 75 | .want_protocols = TLS_PROTOCOL_TLSv1_0 | TLS_PROTOCOL_TLSv1_1 | | ||
| 76 | TLS_PROTOCOL_TLSv1_2, | ||
| 77 | }, | ||
| 78 | { | ||
| 79 | .protostr = "tlsv1.1,tlsv1.2,tlsv1.0", | ||
| 80 | .want_return = 0, | ||
| 81 | .want_protocols = TLS_PROTOCOL_TLSv1_0 | TLS_PROTOCOL_TLSv1_1 | | ||
| 82 | TLS_PROTOCOL_TLSv1_2, | ||
| 83 | }, | ||
| 84 | { | ||
| 85 | .protostr = "tlsv1.1,tlsv1.2,tlsv1.1", | ||
| 86 | .want_return = 0, | ||
| 87 | .want_protocols = TLS_PROTOCOL_TLSv1_1 | TLS_PROTOCOL_TLSv1_2, | ||
| 88 | }, | ||
| 89 | { | ||
| 90 | .protostr = "tlsv1.1,tlsv1.2,!tlsv1.1", | ||
| 91 | .want_return = 0, | ||
| 92 | .want_protocols = TLS_PROTOCOL_TLSv1_2, | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | .protostr = "unknown", | ||
| 96 | .want_return = -1, | ||
| 97 | .want_protocols = 0, | ||
| 98 | }, | ||
| 99 | { | ||
| 100 | .protostr = "all,!unknown", | ||
| 101 | .want_return = -1, | ||
| 102 | .want_protocols = 0, | ||
| 103 | }, | ||
| 104 | { | ||
| 105 | .protostr = "sslv3,tlsv1.0,tlsv1.1,tlsv1.2", | ||
| 106 | .want_return = -1, | ||
| 107 | .want_protocols = 0, | ||
| 108 | }, | ||
| 109 | { | ||
| 110 | .protostr = "all,!tlsv1.0", | ||
| 111 | .want_return = 0, | ||
| 112 | .want_protocols = TLS_PROTOCOL_TLSv1_1 | TLS_PROTOCOL_TLSv1_2, | ||
| 113 | }, | ||
| 114 | { | ||
| 115 | .protostr = "!tlsv1.0", | ||
| 116 | .want_return = 0, | ||
| 117 | .want_protocols = TLS_PROTOCOL_TLSv1_1 | TLS_PROTOCOL_TLSv1_2, | ||
| 118 | }, | ||
| 119 | { | ||
| 120 | .protostr = "!tlsv1.0,!tlsv1.1", | ||
| 121 | .want_return = 0, | ||
| 122 | .want_protocols = TLS_PROTOCOL_TLSv1_2, | ||
| 123 | }, | ||
| 124 | { | ||
| 125 | .protostr = "!tlsv1.0,!tlsv1.1,tlsv1.2", | ||
| 126 | .want_return = 0, | ||
| 127 | .want_protocols = TLS_PROTOCOL_TLSv1_2, | ||
| 128 | }, | ||
| 129 | }; | ||
| 130 | |||
| 131 | #define N_PARSE_PROTOCOLS_TESTS \ | ||
| 132 | (sizeof(parse_protocols_tests) / sizeof(*parse_protocols_tests)) | ||
| 133 | |||
| 134 | static int | ||
| 135 | do_parse_protocols_test(int test_no, struct parse_protocols_test *ppt) | ||
| 136 | { | ||
| 137 | uint32_t protocols = 0; | ||
| 138 | int failed = 1; | ||
| 139 | int rv; | ||
| 140 | |||
| 141 | rv = tls_config_parse_protocols(&protocols, ppt->protostr); | ||
| 142 | if (rv != ppt->want_return) { | ||
| 143 | fprintf(stderr, "FAIL: test %i - tls_config_parse_protocols() " | ||
| 144 | "returned %i, want %i\n", test_no, rv, ppt->want_return); | ||
| 145 | goto done; | ||
| 146 | } | ||
| 147 | if (protocols != ppt->want_protocols) { | ||
| 148 | fprintf(stderr, "FAIL: test %i - got protocols 0x%x, " | ||
| 149 | "want 0x%x\n", test_no, protocols, ppt->want_protocols); | ||
| 150 | goto done; | ||
| 151 | } | ||
| 152 | |||
| 153 | failed = 0; | ||
| 154 | |||
| 155 | done: | ||
| 156 | return (failed); | ||
| 157 | } | ||
| 158 | |||
| 159 | int | ||
| 160 | main(int argc, char **argv) | ||
| 161 | { | ||
| 162 | int failed = 0; | ||
| 163 | size_t i; | ||
| 164 | |||
| 165 | tls_init(); | ||
| 166 | |||
| 167 | for (i = 0; i < N_PARSE_PROTOCOLS_TESTS; i++) | ||
| 168 | failed += do_parse_protocols_test(i, &parse_protocols_tests[i]); | ||
| 169 | |||
| 170 | return (failed); | ||
| 171 | } | ||
diff --git a/src/regress/lib/libtls/gotls/Makefile b/src/regress/lib/libtls/gotls/Makefile deleted file mode 100644 index 404aa79caa..0000000000 --- a/src/regress/lib/libtls/gotls/Makefile +++ /dev/null | |||
| @@ -1,16 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2016/09/02 21:30:34 bluhm Exp $ | ||
| 2 | |||
| 3 | GO_VERSION != sh -c "(go version) 2>/dev/null || true" | ||
| 4 | |||
| 5 | .if empty(GO_VERSION) | ||
| 6 | regress: | ||
| 7 | @echo package go is required for this regress | ||
| 8 | @echo SKIPPED | ||
| 9 | .endif | ||
| 10 | |||
| 11 | REGRESS_TARGETS=regress-gotls | ||
| 12 | |||
| 13 | regress-gotls: | ||
| 14 | cd ${.CURDIR} && go test -test.v . | ||
| 15 | |||
| 16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libtls/gotls/tls.go b/src/regress/lib/libtls/gotls/tls.go deleted file mode 100644 index be75e71f4f..0000000000 --- a/src/regress/lib/libtls/gotls/tls.go +++ /dev/null | |||
| @@ -1,341 +0,0 @@ | |||
| 1 | // Package tls provides a Go interface to the libtls library. | ||
| 2 | package tls | ||
| 3 | |||
| 4 | /* | ||
| 5 | #cgo LDFLAGS: -ltls -lssl -lcrypto | ||
| 6 | |||
| 7 | #include <stdlib.h> | ||
| 8 | |||
| 9 | #include <tls.h> | ||
| 10 | |||
| 11 | typedef void *tls; | ||
| 12 | */ | ||
| 13 | import "C" | ||
| 14 | |||
| 15 | import ( | ||
| 16 | "errors" | ||
| 17 | "fmt" | ||
| 18 | "time" | ||
| 19 | "unsafe" | ||
| 20 | ) | ||
| 21 | |||
| 22 | var ( | ||
| 23 | errWantPollIn = errors.New("want poll in") | ||
| 24 | errWantPollOut = errors.New("want poll out") | ||
| 25 | ) | ||
| 26 | |||
| 27 | // ProtocolVersion represents a TLS protocol version. | ||
| 28 | type ProtocolVersion uint32 | ||
| 29 | |||
| 30 | // String returns the string representation of a protocol version. | ||
| 31 | func (pv ProtocolVersion) String() string { | ||
| 32 | name, ok := protocolNames[pv] | ||
| 33 | if !ok { | ||
| 34 | return fmt.Sprintf("unknown protocol version %x", uint32(pv)) | ||
| 35 | } | ||
| 36 | return name | ||
| 37 | } | ||
| 38 | |||
| 39 | const ( | ||
| 40 | ProtocolTLSv10 ProtocolVersion = C.TLS_PROTOCOL_TLSv1_0 | ||
| 41 | ProtocolTLSv11 ProtocolVersion = C.TLS_PROTOCOL_TLSv1_1 | ||
| 42 | ProtocolTLSv12 ProtocolVersion = C.TLS_PROTOCOL_TLSv1_2 | ||
| 43 | ProtocolsAll ProtocolVersion = C.TLS_PROTOCOLS_ALL | ||
| 44 | ) | ||
| 45 | |||
| 46 | var protocolNames = map[ProtocolVersion]string{ | ||
| 47 | ProtocolTLSv10: "TLSv1", | ||
| 48 | ProtocolTLSv11: "TLSv1.1", | ||
| 49 | ProtocolTLSv12: "TLSv1.2", | ||
| 50 | ProtocolsAll: "all", | ||
| 51 | } | ||
| 52 | |||
| 53 | // ProtocolVersionFromString returns the protocol version with the given name. | ||
| 54 | func ProtocolVersionFromString(version string) (ProtocolVersion, error) { | ||
| 55 | for proto, name := range protocolNames { | ||
| 56 | if version == name { | ||
| 57 | return proto, nil | ||
| 58 | } | ||
| 59 | } | ||
| 60 | return 0, fmt.Errorf("unknown protocol version %q", version) | ||
| 61 | } | ||
| 62 | |||
| 63 | // TLSConfig provides configuration options for a TLS context. | ||
| 64 | type TLSConfig struct { | ||
| 65 | tlsCfg *C.struct_tls_config | ||
| 66 | } | ||
| 67 | |||
| 68 | // TLS encapsulates the TLS context. | ||
| 69 | type TLS struct { | ||
| 70 | cfg *TLSConfig | ||
| 71 | ctx *C.struct_tls | ||
| 72 | } | ||
| 73 | |||
| 74 | // Init initialises the TLS library. | ||
| 75 | func Init() error { | ||
| 76 | if C.tls_init() != 0 { | ||
| 77 | return errors.New("initialisation failed") | ||
| 78 | } | ||
| 79 | return nil | ||
| 80 | } | ||
| 81 | |||
| 82 | // NewConfig returns a new TLS configuration. | ||
| 83 | func NewConfig() (*TLSConfig, error) { | ||
| 84 | cfg := C.tls_config_new() | ||
| 85 | if cfg == nil { | ||
| 86 | return nil, errors.New("failed to allocate config") | ||
| 87 | } | ||
| 88 | return &TLSConfig{ | ||
| 89 | tlsCfg: cfg, | ||
| 90 | }, nil | ||
| 91 | } | ||
| 92 | |||
| 93 | // Error returns the error message from the TLS configuration. | ||
| 94 | func (c *TLSConfig) Error() error { | ||
| 95 | if msg := C.tls_config_error(c.tlsCfg); msg != nil { | ||
| 96 | return errors.New(C.GoString(msg)) | ||
| 97 | } | ||
| 98 | return errors.New("unknown error") | ||
| 99 | } | ||
| 100 | |||
| 101 | // SetCAFile sets the CA file to be used for connections. | ||
| 102 | func (c *TLSConfig) SetCAFile(filename string) error { | ||
| 103 | caFile := C.CString(filename) | ||
| 104 | defer C.free(unsafe.Pointer(caFile)) | ||
| 105 | if C.tls_config_set_ca_file(c.tlsCfg, caFile) != 0 { | ||
| 106 | return c.Error() | ||
| 107 | } | ||
| 108 | return nil | ||
| 109 | } | ||
| 110 | |||
| 111 | // SetCiphers sets the cipher suites enabled for the connection. | ||
| 112 | func (c *TLSConfig) SetCiphers(ciphers string) error { | ||
| 113 | cipherStr := C.CString(ciphers) | ||
| 114 | defer C.free(unsafe.Pointer(cipherStr)) | ||
| 115 | if C.tls_config_set_ciphers(c.tlsCfg, cipherStr) != 0 { | ||
| 116 | return c.Error() | ||
| 117 | } | ||
| 118 | return nil | ||
| 119 | } | ||
| 120 | |||
| 121 | // SetProtocols sets the protocol versions enabled for the connection. | ||
| 122 | func (c *TLSConfig) SetProtocols(proto ProtocolVersion) error { | ||
| 123 | if C.tls_config_set_protocols(c.tlsCfg, C.uint32_t(proto)) != 0 { | ||
| 124 | return c.Error() | ||
| 125 | } | ||
| 126 | return nil | ||
| 127 | } | ||
| 128 | |||
| 129 | // InsecureNoVerifyCert disables certificate verification for the connection. | ||
| 130 | func (c *TLSConfig) InsecureNoVerifyCert() { | ||
| 131 | C.tls_config_insecure_noverifycert(c.tlsCfg) | ||
| 132 | } | ||
| 133 | |||
| 134 | // InsecureNoVerifyName disables server name verification for the connection. | ||
| 135 | func (c *TLSConfig) InsecureNoVerifyName() { | ||
| 136 | C.tls_config_insecure_noverifyname(c.tlsCfg) | ||
| 137 | } | ||
| 138 | |||
| 139 | // SetSecure enables verification for the connection. | ||
| 140 | func (c *TLSConfig) SetVerify() { | ||
| 141 | C.tls_config_verify(c.tlsCfg) | ||
| 142 | } | ||
| 143 | |||
| 144 | // Free frees resources associated with the TLS configuration. | ||
| 145 | func (c *TLSConfig) Free() { | ||
| 146 | if c.tlsCfg == nil { | ||
| 147 | return | ||
| 148 | } | ||
| 149 | C.tls_config_free(c.tlsCfg) | ||
| 150 | c.tlsCfg = nil | ||
| 151 | } | ||
| 152 | |||
| 153 | // NewClient returns a new TLS client context, using the optional configuration. | ||
| 154 | // If no configuration is specified the default configuration will be used. | ||
| 155 | func NewClient(config *TLSConfig) (*TLS, error) { | ||
| 156 | var sslCfg *C.struct_tls_config | ||
| 157 | if config != nil { | ||
| 158 | sslCfg = config.tlsCfg | ||
| 159 | } | ||
| 160 | ctx := C.tls_client() | ||
| 161 | if ctx == nil { | ||
| 162 | return nil, errors.New("tls client failed") | ||
| 163 | } | ||
| 164 | if C.tls_configure(ctx, sslCfg) != 0 { | ||
| 165 | return nil, errors.New("tls configure failed") | ||
| 166 | } | ||
| 167 | return &TLS{ | ||
| 168 | cfg: config, | ||
| 169 | ctx: ctx, | ||
| 170 | }, nil | ||
| 171 | } | ||
| 172 | |||
| 173 | // Error returns the error message from the TLS context. | ||
| 174 | func (t *TLS) Error() error { | ||
| 175 | if msg := C.tls_error(t.ctx); msg != nil { | ||
| 176 | return errors.New(C.GoString(msg)) | ||
| 177 | } | ||
| 178 | return errors.New("unknown error") | ||
| 179 | } | ||
| 180 | |||
| 181 | // PeerCertProvided returns whether the peer provided a certificate. | ||
| 182 | func (t *TLS) PeerCertProvided() bool { | ||
| 183 | return C.tls_peer_cert_provided(t.ctx) == 1 | ||
| 184 | } | ||
| 185 | |||
| 186 | // PeerCertContainsName checks whether the peer certificate contains | ||
| 187 | // the specified name. | ||
| 188 | func (t *TLS) PeerCertContainsName(name string) bool { | ||
| 189 | n := C.CString(name) | ||
| 190 | defer C.free(unsafe.Pointer(n)) | ||
| 191 | return C.tls_peer_cert_contains_name(t.ctx, n) == 1 | ||
| 192 | } | ||
| 193 | |||
| 194 | // PeerCertIssuer returns the issuer of the peer certificate. | ||
| 195 | func (t *TLS) PeerCertIssuer() (string, error) { | ||
| 196 | issuer := C.tls_peer_cert_issuer(t.ctx) | ||
| 197 | if issuer == nil { | ||
| 198 | return "", errors.New("no issuer returned") | ||
| 199 | } | ||
| 200 | return C.GoString(issuer), nil | ||
| 201 | } | ||
| 202 | |||
| 203 | // PeerCertSubject returns the subject of the peer certificate. | ||
| 204 | func (t *TLS) PeerCertSubject() (string, error) { | ||
| 205 | subject := C.tls_peer_cert_subject(t.ctx) | ||
| 206 | if subject == nil { | ||
| 207 | return "", errors.New("no subject returned") | ||
| 208 | } | ||
| 209 | return C.GoString(subject), nil | ||
| 210 | } | ||
| 211 | |||
| 212 | // PeerCertHash returns a hash of the peer certificate. | ||
| 213 | func (t *TLS) PeerCertHash() (string, error) { | ||
| 214 | hash := C.tls_peer_cert_hash(t.ctx) | ||
| 215 | if hash == nil { | ||
| 216 | return "", errors.New("no hash returned") | ||
| 217 | } | ||
| 218 | return C.GoString(hash), nil | ||
| 219 | } | ||
| 220 | |||
| 221 | // PeerCertNotBefore returns the notBefore time from the peer | ||
| 222 | // certificate. | ||
| 223 | func (t *TLS) PeerCertNotBefore() (time.Time, error) { | ||
| 224 | notBefore := C.tls_peer_cert_notbefore(t.ctx) | ||
| 225 | if notBefore == -1 { | ||
| 226 | return time.Time{}, errors.New("no notBefore time returned") | ||
| 227 | } | ||
| 228 | return time.Unix(int64(notBefore), 0), nil | ||
| 229 | } | ||
| 230 | |||
| 231 | // PeerCertNotAfter returns the notAfter time from the peer | ||
| 232 | // certificate. | ||
| 233 | func (t *TLS) PeerCertNotAfter() (time.Time, error) { | ||
| 234 | notAfter := C.tls_peer_cert_notafter(t.ctx) | ||
| 235 | if notAfter == -1 { | ||
| 236 | return time.Time{}, errors.New("no notAfter time") | ||
| 237 | } | ||
| 238 | return time.Unix(int64(notAfter), 0), nil | ||
| 239 | } | ||
| 240 | |||
| 241 | // ConnVersion returns the protocol version of the connection. | ||
| 242 | func (t *TLS) ConnVersion() (ProtocolVersion, error) { | ||
| 243 | ver := C.tls_conn_version(t.ctx) | ||
| 244 | if ver == nil { | ||
| 245 | return 0, errors.New("no connection version") | ||
| 246 | } | ||
| 247 | return ProtocolVersionFromString(C.GoString(ver)) | ||
| 248 | } | ||
| 249 | |||
| 250 | // ConnCipher returns the cipher suite used for the connection. | ||
| 251 | func (t *TLS) ConnCipher() (string, error) { | ||
| 252 | cipher := C.tls_conn_cipher(t.ctx) | ||
| 253 | if cipher == nil { | ||
| 254 | return "", errors.New("no connection cipher") | ||
| 255 | } | ||
| 256 | return C.GoString(cipher), nil | ||
| 257 | } | ||
| 258 | |||
| 259 | // Connect attempts to establish an TLS connection to the specified host on | ||
| 260 | // the given port. The host may optionally contain a colon separated port | ||
| 261 | // value if the port string is specified as an empty string. | ||
| 262 | func (t *TLS) Connect(host, port string) error { | ||
| 263 | h := C.CString(host) | ||
| 264 | var p *C.char | ||
| 265 | if port != "" { | ||
| 266 | p = C.CString(port) | ||
| 267 | } | ||
| 268 | defer C.free(unsafe.Pointer(h)) | ||
| 269 | defer C.free(unsafe.Pointer(p)) | ||
| 270 | if C.tls_connect(t.ctx, h, p) != 0 { | ||
| 271 | return t.Error() | ||
| 272 | } | ||
| 273 | return nil | ||
| 274 | } | ||
| 275 | |||
| 276 | // Handshake attempts to complete the TLS handshake. | ||
| 277 | func (t *TLS) Handshake() error { | ||
| 278 | ret := C.tls_handshake(t.ctx) | ||
| 279 | switch { | ||
| 280 | case ret == C.TLS_WANT_POLLIN: | ||
| 281 | return errWantPollIn | ||
| 282 | case ret == C.TLS_WANT_POLLOUT: | ||
| 283 | return errWantPollOut | ||
| 284 | case ret != 0: | ||
| 285 | return t.Error() | ||
| 286 | } | ||
| 287 | return nil | ||
| 288 | } | ||
| 289 | |||
| 290 | // Read reads data the TLS connection into the given buffer. | ||
| 291 | func (t *TLS) Read(buf []byte) (int, error) { | ||
| 292 | ret := C.tls_read(t.ctx, unsafe.Pointer(&buf[0]), C.size_t(len(buf))) | ||
| 293 | switch { | ||
| 294 | case ret == C.TLS_WANT_POLLIN: | ||
| 295 | return -1, errWantPollIn | ||
| 296 | case ret == C.TLS_WANT_POLLOUT: | ||
| 297 | return -1, errWantPollOut | ||
| 298 | case ret < 0: | ||
| 299 | return -1, t.Error() | ||
| 300 | } | ||
| 301 | return int(ret), nil | ||
| 302 | } | ||
| 303 | |||
| 304 | // Write writes the given data to the TLS connection. | ||
| 305 | func (t *TLS) Write(buf []byte) (int, error) { | ||
| 306 | p := C.CString(string(buf)) | ||
| 307 | defer C.free(unsafe.Pointer(p)) | ||
| 308 | ret := C.tls_write(t.ctx, unsafe.Pointer(p), C.size_t(len(buf))) | ||
| 309 | switch { | ||
| 310 | case ret == C.TLS_WANT_POLLIN: | ||
| 311 | return -1, errWantPollIn | ||
| 312 | case ret == C.TLS_WANT_POLLOUT: | ||
| 313 | return -1, errWantPollOut | ||
| 314 | case ret < 0: | ||
| 315 | return -1, t.Error() | ||
| 316 | } | ||
| 317 | return int(ret), nil | ||
| 318 | } | ||
| 319 | |||
| 320 | // Close closes the TLS connection. | ||
| 321 | func (t *TLS) Close() error { | ||
| 322 | ret := C.tls_close(t.ctx) | ||
| 323 | switch { | ||
| 324 | case ret == C.TLS_WANT_POLLIN: | ||
| 325 | return errWantPollIn | ||
| 326 | case ret == C.TLS_WANT_POLLOUT: | ||
| 327 | return errWantPollOut | ||
| 328 | case ret != 0: | ||
| 329 | return t.Error() | ||
| 330 | } | ||
| 331 | return nil | ||
| 332 | } | ||
| 333 | |||
| 334 | // Free frees resources associated with the TLS context. | ||
| 335 | func (t *TLS) Free() { | ||
| 336 | if t.ctx == nil { | ||
| 337 | return | ||
| 338 | } | ||
| 339 | C.tls_free(t.ctx) | ||
| 340 | t.ctx = nil | ||
| 341 | } | ||
diff --git a/src/regress/lib/libtls/gotls/tls_test.go b/src/regress/lib/libtls/gotls/tls_test.go deleted file mode 100644 index 077dd86e82..0000000000 --- a/src/regress/lib/libtls/gotls/tls_test.go +++ /dev/null | |||
| @@ -1,421 +0,0 @@ | |||
| 1 | package tls | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "crypto/tls" | ||
| 5 | "encoding/pem" | ||
| 6 | "fmt" | ||
| 7 | "io/ioutil" | ||
| 8 | "net/http" | ||
| 9 | "net/http/httptest" | ||
| 10 | "net/url" | ||
| 11 | "os" | ||
| 12 | "strings" | ||
| 13 | "testing" | ||
| 14 | "time" | ||
| 15 | ) | ||
| 16 | |||
| 17 | const ( | ||
| 18 | httpContent = "Hello, TLS!" | ||
| 19 | |||
| 20 | certHash = "SHA256:448f628a8a65aa18560e53a80c53acb38c51b427df0334082349141147dc9bf6" | ||
| 21 | ) | ||
| 22 | |||
| 23 | var ( | ||
| 24 | certNotBefore = time.Unix(0, 0) | ||
| 25 | certNotAfter = certNotBefore.Add(1000000 * time.Hour) | ||
| 26 | ) | ||
| 27 | |||
| 28 | type handshakeError string | ||
| 29 | |||
| 30 | func (he handshakeError) Error() string { | ||
| 31 | return string(he) | ||
| 32 | } | ||
| 33 | |||
| 34 | // createCAFile writes a PEM encoded version of the certificate out to a | ||
| 35 | // temporary file, for use by libtls. | ||
| 36 | func createCAFile(cert []byte) (string, error) { | ||
| 37 | f, err := ioutil.TempFile("", "tls") | ||
| 38 | if err != nil { | ||
| 39 | return "", fmt.Errorf("failed to create file: %v", err) | ||
| 40 | } | ||
| 41 | defer f.Close() | ||
| 42 | block := &pem.Block{ | ||
| 43 | Type: "CERTIFICATE", | ||
| 44 | Bytes: cert, | ||
| 45 | } | ||
| 46 | if err := pem.Encode(f, block); err != nil { | ||
| 47 | return "", fmt.Errorf("failed to encode certificate: %v", err) | ||
| 48 | } | ||
| 49 | return f.Name(), nil | ||
| 50 | } | ||
| 51 | |||
| 52 | func newTestServer(tlsCfg *tls.Config) (*httptest.Server, *url.URL, string, error) { | ||
| 53 | ts := httptest.NewUnstartedServer( | ||
| 54 | http.HandlerFunc( | ||
| 55 | func(w http.ResponseWriter, r *http.Request) { | ||
| 56 | fmt.Fprintln(w, httpContent) | ||
| 57 | }, | ||
| 58 | ), | ||
| 59 | ) | ||
| 60 | ts.TLS = tlsCfg | ||
| 61 | ts.StartTLS() | ||
| 62 | |||
| 63 | u, err := url.Parse(ts.URL) | ||
| 64 | if err != nil { | ||
| 65 | return nil, nil, "", fmt.Errorf("failed to parse URL %q: %v", ts.URL, err) | ||
| 66 | } | ||
| 67 | |||
| 68 | caFile, err := createCAFile(ts.TLS.Certificates[0].Certificate[0]) | ||
| 69 | if err != nil { | ||
| 70 | return nil, nil, "", fmt.Errorf("failed to create CA file: %v", err) | ||
| 71 | } | ||
| 72 | |||
| 73 | return ts, u, caFile, nil | ||
| 74 | } | ||
| 75 | |||
| 76 | func handshakeVersionTest(tlsCfg *tls.Config) (ProtocolVersion, error) { | ||
| 77 | ts, u, caFile, err := newTestServer(tlsCfg) | ||
| 78 | if err != nil { | ||
| 79 | return 0, fmt.Errorf("failed to start test server: %v", err) | ||
| 80 | } | ||
| 81 | defer os.Remove(caFile) | ||
| 82 | defer ts.Close() | ||
| 83 | |||
| 84 | if err := Init(); err != nil { | ||
| 85 | return 0, err | ||
| 86 | } | ||
| 87 | |||
| 88 | cfg, err := NewConfig() | ||
| 89 | if err != nil { | ||
| 90 | return 0, err | ||
| 91 | } | ||
| 92 | defer cfg.Free() | ||
| 93 | if err := cfg.SetCAFile(caFile); err != nil { | ||
| 94 | return 0, err | ||
| 95 | } | ||
| 96 | if err := cfg.SetCiphers("compat"); err != nil { | ||
| 97 | return 0, err | ||
| 98 | } | ||
| 99 | if err := cfg.SetProtocols(ProtocolsAll); err != nil { | ||
| 100 | return 0, err | ||
| 101 | } | ||
| 102 | |||
| 103 | tls, err := NewClient(cfg) | ||
| 104 | if err != nil { | ||
| 105 | return 0, err | ||
| 106 | } | ||
| 107 | defer tls.Free() | ||
| 108 | |||
| 109 | if err := tls.Connect(u.Host, ""); err != nil { | ||
| 110 | return 0, err | ||
| 111 | } | ||
| 112 | if err := tls.Handshake(); err != nil { | ||
| 113 | return 0, handshakeError(err.Error()) | ||
| 114 | } | ||
| 115 | version, err := tls.ConnVersion() | ||
| 116 | if err != nil { | ||
| 117 | return 0, err | ||
| 118 | } | ||
| 119 | if err := tls.Close(); err != nil { | ||
| 120 | return 0, err | ||
| 121 | } | ||
| 122 | return version, nil | ||
| 123 | } | ||
| 124 | |||
| 125 | func TestTLSBasic(t *testing.T) { | ||
| 126 | ts, u, caFile, err := newTestServer(nil) | ||
| 127 | if err != nil { | ||
| 128 | t.Fatalf("Failed to start test server: %v", err) | ||
| 129 | } | ||
| 130 | defer os.Remove(caFile) | ||
| 131 | defer ts.Close() | ||
| 132 | |||
| 133 | if err := Init(); err != nil { | ||
| 134 | t.Fatal(err) | ||
| 135 | } | ||
| 136 | |||
| 137 | cfg, err := NewConfig() | ||
| 138 | if err != nil { | ||
| 139 | t.Fatal(err) | ||
| 140 | } | ||
| 141 | defer cfg.Free() | ||
| 142 | if err := cfg.SetCAFile(caFile); err != nil { | ||
| 143 | t.Fatal(err) | ||
| 144 | } | ||
| 145 | |||
| 146 | tls, err := NewClient(cfg) | ||
| 147 | if err != nil { | ||
| 148 | t.Fatal(err) | ||
| 149 | } | ||
| 150 | defer tls.Free() | ||
| 151 | |||
| 152 | t.Logf("Connecting to %s", u.Host) | ||
| 153 | |||
| 154 | if err := tls.Connect(u.Host, ""); err != nil { | ||
| 155 | t.Fatal(err) | ||
| 156 | } | ||
| 157 | defer func() { | ||
| 158 | if err := tls.Close(); err != nil { | ||
| 159 | t.Fatalf("Close failed: %v", err) | ||
| 160 | } | ||
| 161 | }() | ||
| 162 | |||
| 163 | n, err := tls.Write([]byte("GET / HTTP/1.0\n\n")) | ||
| 164 | if err != nil { | ||
| 165 | t.Fatal(err) | ||
| 166 | } | ||
| 167 | t.Logf("Wrote %d bytes...", n) | ||
| 168 | |||
| 169 | buf := make([]byte, 1024) | ||
| 170 | n, err = tls.Read(buf) | ||
| 171 | if err != nil { | ||
| 172 | t.Fatal(err) | ||
| 173 | } | ||
| 174 | t.Logf("Read %d bytes...", n) | ||
| 175 | |||
| 176 | if !strings.Contains(string(buf), httpContent) { | ||
| 177 | t.Errorf("Response does not contain %q", httpContent) | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | func TestTLSVersions(t *testing.T) { | ||
| 182 | tests := []struct { | ||
| 183 | minVersion uint16 | ||
| 184 | maxVersion uint16 | ||
| 185 | wantVersion ProtocolVersion | ||
| 186 | wantHandshakeErr bool | ||
| 187 | }{ | ||
| 188 | {tls.VersionSSL30, tls.VersionTLS12, ProtocolTLSv12, false}, | ||
| 189 | {tls.VersionTLS10, tls.VersionTLS12, ProtocolTLSv12, false}, | ||
| 190 | {tls.VersionTLS11, tls.VersionTLS12, ProtocolTLSv12, false}, | ||
| 191 | {tls.VersionSSL30, tls.VersionTLS11, ProtocolTLSv11, false}, | ||
| 192 | {tls.VersionSSL30, tls.VersionTLS10, ProtocolTLSv10, false}, | ||
| 193 | {tls.VersionSSL30, tls.VersionSSL30, 0, true}, | ||
| 194 | {tls.VersionTLS10, tls.VersionTLS10, ProtocolTLSv10, false}, | ||
| 195 | {tls.VersionTLS11, tls.VersionTLS11, ProtocolTLSv11, false}, | ||
| 196 | {tls.VersionTLS12, tls.VersionTLS12, ProtocolTLSv12, false}, | ||
| 197 | } | ||
| 198 | for i, test := range tests { | ||
| 199 | t.Logf("Testing handshake with protocols %x:%x", test.minVersion, test.maxVersion) | ||
| 200 | tlsCfg := &tls.Config{ | ||
| 201 | MinVersion: test.minVersion, | ||
| 202 | MaxVersion: test.maxVersion, | ||
| 203 | } | ||
| 204 | version, err := handshakeVersionTest(tlsCfg) | ||
| 205 | switch { | ||
| 206 | case test.wantHandshakeErr && err == nil: | ||
| 207 | t.Errorf("Test %d - handshake %x:%x succeeded, want handshake error", | ||
| 208 | i, test.minVersion, test.maxVersion) | ||
| 209 | case test.wantHandshakeErr && err != nil: | ||
| 210 | if _, ok := err.(handshakeError); !ok { | ||
| 211 | t.Errorf("Test %d - handshake %x:%x; got unknown error, want handshake error: %v", | ||
| 212 | i, test.minVersion, test.maxVersion, err) | ||
| 213 | } | ||
| 214 | case !test.wantHandshakeErr && err != nil: | ||
| 215 | t.Errorf("Test %d - handshake %x:%x failed: %v", i, test.minVersion, test.maxVersion, err) | ||
| 216 | case !test.wantHandshakeErr && err == nil: | ||
| 217 | if got, want := version, test.wantVersion; got != want { | ||
| 218 | t.Errorf("Test %d - handshake %x:%x; got protocol version %v, want %v", | ||
| 219 | i, test.minVersion, test.maxVersion, got, want) | ||
| 220 | } | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | |||
| 225 | func TestTLSSingleByteReadWrite(t *testing.T) { | ||
| 226 | ts, u, caFile, err := newTestServer(nil) | ||
| 227 | if err != nil { | ||
| 228 | t.Fatalf("Failed to start test server: %v", err) | ||
| 229 | } | ||
| 230 | defer os.Remove(caFile) | ||
| 231 | defer ts.Close() | ||
| 232 | |||
| 233 | if err := Init(); err != nil { | ||
| 234 | t.Fatal(err) | ||
| 235 | } | ||
| 236 | |||
| 237 | cfg, err := NewConfig() | ||
| 238 | if err != nil { | ||
| 239 | t.Fatal(err) | ||
| 240 | } | ||
| 241 | defer cfg.Free() | ||
| 242 | if err := cfg.SetCAFile(caFile); err != nil { | ||
| 243 | t.Fatal(err) | ||
| 244 | } | ||
| 245 | |||
| 246 | tls, err := NewClient(cfg) | ||
| 247 | if err != nil { | ||
| 248 | t.Fatal(err) | ||
| 249 | } | ||
| 250 | defer tls.Free() | ||
| 251 | |||
| 252 | t.Logf("Connecting to %s", u.Host) | ||
| 253 | |||
| 254 | if err := tls.Connect(u.Host, ""); err != nil { | ||
| 255 | t.Fatal(err) | ||
| 256 | } | ||
| 257 | defer func() { | ||
| 258 | if err := tls.Close(); err != nil { | ||
| 259 | t.Fatalf("Close failed: %v", err) | ||
| 260 | } | ||
| 261 | }() | ||
| 262 | |||
| 263 | for _, b := range []byte("GET / HTTP/1.0\n\n") { | ||
| 264 | n, err := tls.Write([]byte{b}) | ||
| 265 | if err != nil { | ||
| 266 | t.Fatal(err) | ||
| 267 | } | ||
| 268 | if n != 1 { | ||
| 269 | t.Fatalf("Wrote byte %v, got length %d, want 1", b, n) | ||
| 270 | } | ||
| 271 | } | ||
| 272 | |||
| 273 | var body []byte | ||
| 274 | for { | ||
| 275 | buf := make([]byte, 1) | ||
| 276 | n, err := tls.Read(buf) | ||
| 277 | if err != nil { | ||
| 278 | t.Fatal(err) | ||
| 279 | } | ||
| 280 | if n == 0 { | ||
| 281 | break | ||
| 282 | } | ||
| 283 | if n != 1 { | ||
| 284 | t.Fatalf("Read single byte, got length %d, want 1", n) | ||
| 285 | } | ||
| 286 | body = append(body, buf...) | ||
| 287 | } | ||
| 288 | |||
| 289 | if !strings.Contains(string(body), httpContent) { | ||
| 290 | t.Errorf("Response does not contain %q", httpContent) | ||
| 291 | } | ||
| 292 | } | ||
| 293 | |||
| 294 | func TestTLSInfo(t *testing.T) { | ||
| 295 | ts, u, caFile, err := newTestServer(nil) | ||
| 296 | if err != nil { | ||
| 297 | t.Fatalf("Failed to start test server: %v", err) | ||
| 298 | } | ||
| 299 | defer os.Remove(caFile) | ||
| 300 | defer ts.Close() | ||
| 301 | |||
| 302 | if err := Init(); err != nil { | ||
| 303 | t.Fatal(err) | ||
| 304 | } | ||
| 305 | |||
| 306 | cfg, err := NewConfig() | ||
| 307 | if err != nil { | ||
| 308 | t.Fatal(err) | ||
| 309 | } | ||
| 310 | defer cfg.Free() | ||
| 311 | if err := cfg.SetCAFile(caFile); err != nil { | ||
| 312 | t.Fatal(err) | ||
| 313 | } | ||
| 314 | |||
| 315 | tls, err := NewClient(cfg) | ||
| 316 | if err != nil { | ||
| 317 | t.Fatal(err) | ||
| 318 | } | ||
| 319 | defer tls.Free() | ||
| 320 | |||
| 321 | t.Logf("Connecting to %s", u.Host) | ||
| 322 | |||
| 323 | if err := tls.Connect(u.Host, ""); err != nil { | ||
| 324 | t.Fatal(err) | ||
| 325 | } | ||
| 326 | defer func() { | ||
| 327 | if err := tls.Close(); err != nil { | ||
| 328 | t.Fatalf("Close failed: %v", err) | ||
| 329 | } | ||
| 330 | }() | ||
| 331 | |||
| 332 | // All of these should fail since the handshake has not completed. | ||
| 333 | if _, err := tls.ConnVersion(); err == nil { | ||
| 334 | t.Error("ConnVersion() return nil error, want error") | ||
| 335 | } | ||
| 336 | if _, err := tls.ConnCipher(); err == nil { | ||
| 337 | t.Error("ConnCipher() return nil error, want error") | ||
| 338 | } | ||
| 339 | |||
| 340 | if got, want := tls.PeerCertProvided(), false; got != want { | ||
| 341 | t.Errorf("PeerCertProvided() = %v, want %v", got, want) | ||
| 342 | } | ||
| 343 | for _, name := range []string{"127.0.0.1", "::1", "example.com"} { | ||
| 344 | if got, want := tls.PeerCertContainsName(name), false; got != want { | ||
| 345 | t.Errorf("PeerCertContainsName(%q) = %v, want %v", name, got, want) | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | if _, err := tls.PeerCertIssuer(); err == nil { | ||
| 350 | t.Error("PeerCertIssuer() returned nil error, want error") | ||
| 351 | } | ||
| 352 | if _, err := tls.PeerCertSubject(); err == nil { | ||
| 353 | t.Error("PeerCertSubject() returned nil error, want error") | ||
| 354 | } | ||
| 355 | if _, err := tls.PeerCertHash(); err == nil { | ||
| 356 | t.Error("PeerCertHash() returned nil error, want error") | ||
| 357 | } | ||
| 358 | if _, err := tls.PeerCertNotBefore(); err == nil { | ||
| 359 | t.Error("PeerCertNotBefore() returned nil error, want error") | ||
| 360 | } | ||
| 361 | if _, err := tls.PeerCertNotAfter(); err == nil { | ||
| 362 | t.Error("PeerCertNotAfter() returned nil error, want error") | ||
| 363 | } | ||
| 364 | |||
| 365 | // Complete the handshake... | ||
| 366 | if err := tls.Handshake(); err != nil { | ||
| 367 | t.Fatalf("Handshake failed: %v", err) | ||
| 368 | } | ||
| 369 | |||
| 370 | if version, err := tls.ConnVersion(); err != nil { | ||
| 371 | t.Errorf("ConnVersion() return error: %v", err) | ||
| 372 | } else { | ||
| 373 | t.Logf("Protocol version: %v", version) | ||
| 374 | } | ||
| 375 | if cipher, err := tls.ConnCipher(); err != nil { | ||
| 376 | t.Errorf("ConnCipher() return error: %v", err) | ||
| 377 | } else { | ||
| 378 | t.Logf("Cipher: %v", cipher) | ||
| 379 | } | ||
| 380 | |||
| 381 | if got, want := tls.PeerCertProvided(), true; got != want { | ||
| 382 | t.Errorf("PeerCertProvided() = %v, want %v", got, want) | ||
| 383 | } | ||
| 384 | for _, name := range []string{"127.0.0.1", "::1", "example.com"} { | ||
| 385 | if got, want := tls.PeerCertContainsName(name), true; got != want { | ||
| 386 | t.Errorf("PeerCertContainsName(%q) = %v, want %v", name, got, want) | ||
| 387 | } | ||
| 388 | } | ||
| 389 | |||
| 390 | if issuer, err := tls.PeerCertIssuer(); err != nil { | ||
| 391 | t.Errorf("PeerCertIssuer() returned error: %v", err) | ||
| 392 | } else { | ||
| 393 | t.Logf("Issuer: %v", issuer) | ||
| 394 | } | ||
| 395 | if subject, err := tls.PeerCertSubject(); err != nil { | ||
| 396 | t.Errorf("PeerCertSubject() returned error: %v", err) | ||
| 397 | } else { | ||
| 398 | t.Logf("Subject: %v", subject) | ||
| 399 | } | ||
| 400 | if hash, err := tls.PeerCertHash(); err != nil { | ||
| 401 | t.Errorf("PeerCertHash() returned error: %v", err) | ||
| 402 | } else if hash != certHash { | ||
| 403 | t.Errorf("Got cert hash %q, want %q", hash, certHash) | ||
| 404 | } else { | ||
| 405 | t.Logf("Hash: %v", hash) | ||
| 406 | } | ||
| 407 | if notBefore, err := tls.PeerCertNotBefore(); err != nil { | ||
| 408 | t.Errorf("PeerCertNotBefore() returned error: %v", err) | ||
| 409 | } else if !certNotBefore.Equal(notBefore) { | ||
| 410 | t.Errorf("Got cert notBefore %v, want %v", notBefore.UTC(), certNotBefore.UTC()) | ||
| 411 | } else { | ||
| 412 | t.Logf("NotBefore: %v", notBefore.UTC()) | ||
| 413 | } | ||
| 414 | if notAfter, err := tls.PeerCertNotAfter(); err != nil { | ||
| 415 | t.Errorf("PeerCertNotAfter() returned error: %v", err) | ||
| 416 | } else if !certNotAfter.Equal(notAfter) { | ||
| 417 | t.Errorf("Got cert notAfter %v, want %v", notAfter.UTC(), certNotAfter.UTC()) | ||
| 418 | } else { | ||
| 419 | t.Logf("NotAfter: %v", notAfter.UTC()) | ||
| 420 | } | ||
| 421 | } | ||
diff --git a/src/regress/lib/libtls/keypair/Makefile b/src/regress/lib/libtls/keypair/Makefile deleted file mode 100644 index d06109a26b..0000000000 --- a/src/regress/lib/libtls/keypair/Makefile +++ /dev/null | |||
| @@ -1,20 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2018/02/08 10:06:52 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= keypairtest | ||
| 4 | LDADD= -lcrypto -lssl ${TLS_INT} | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} | ||
| 6 | |||
| 7 | WARNINGS= Yes | ||
| 8 | CFLAGS+= -DLIBRESSL_INTERNAL -Wall -Wundef -Werror | ||
| 9 | CFLAGS+= -I${.CURDIR}/../../../../lib/libtls | ||
| 10 | |||
| 11 | REGRESS_TARGETS= \ | ||
| 12 | regress-keypairtest | ||
| 13 | |||
| 14 | regress-keypairtest: ${PROG} | ||
| 15 | ./keypairtest \ | ||
| 16 | ${.CURDIR}/../../libssl/certs/ca.pem \ | ||
| 17 | ${.CURDIR}/../../libssl/certs/server.pem \ | ||
| 18 | ${.CURDIR}/../../libssl/certs/server.pem | ||
| 19 | |||
| 20 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libtls/keypair/keypairtest.c b/src/regress/lib/libtls/keypair/keypairtest.c deleted file mode 100644 index 732464af00..0000000000 --- a/src/regress/lib/libtls/keypair/keypairtest.c +++ /dev/null | |||
| @@ -1,211 +0,0 @@ | |||
| 1 | /* $OpenBSD: keypairtest.c,v 1.4 2018/04/07 16:42:17 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/stat.h> | ||
| 19 | |||
| 20 | #include <err.h> | ||
| 21 | #include <fcntl.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | #include <openssl/x509.h> | ||
| 27 | |||
| 28 | #include <tls.h> | ||
| 29 | #include <tls_internal.h> | ||
| 30 | |||
| 31 | #define PUBKEY_HASH \ | ||
| 32 | "SHA256:858d0f94beb0a08eb4f13871ba57bf0a2e081287d0efbaeb3bbac59dd8f1a8e5" | ||
| 33 | |||
| 34 | char *cert_file, *key_file, *ocsp_staple_file; | ||
| 35 | |||
| 36 | static void | ||
| 37 | load_file(const char *filename, const uint8_t **data, size_t *data_len) | ||
| 38 | { | ||
| 39 | struct stat sb; | ||
| 40 | uint8_t *buf; | ||
| 41 | size_t len; | ||
| 42 | ssize_t n; | ||
| 43 | int fd; | ||
| 44 | |||
| 45 | if ((fd = open(filename, O_RDONLY)) == -1) | ||
| 46 | err(1, "failed to open '%s'", filename); | ||
| 47 | if ((fstat(fd, &sb)) == -1) | ||
| 48 | err(1, "failed to stat '%s'", filename); | ||
| 49 | if (sb.st_size < 0) | ||
| 50 | err(1, "file size invalid for '%s'", filename); | ||
| 51 | len = (size_t)sb.st_size; | ||
| 52 | if ((buf = malloc(len)) == NULL) | ||
| 53 | err(1, "out of memory"); | ||
| 54 | n = read(fd, buf, len); | ||
| 55 | if (n < 0 || (size_t)n != len) | ||
| 56 | err(1, "failed to read '%s'", filename); | ||
| 57 | close(fd); | ||
| 58 | |||
| 59 | *data = buf; | ||
| 60 | *data_len = len; | ||
| 61 | } | ||
| 62 | |||
| 63 | static int | ||
| 64 | compare_mem(char *label, const uint8_t *data1, size_t data1_len, | ||
| 65 | const uint8_t *data2, size_t data2_len) | ||
| 66 | { | ||
| 67 | if (data1_len != data2_len) { | ||
| 68 | fprintf(stderr, "FAIL: %s length mismatch (%zu != %zu)\n", | ||
| 69 | label, data1_len, data2_len); | ||
| 70 | return -1; | ||
| 71 | } | ||
| 72 | if (data1 == data2) { | ||
| 73 | fprintf(stderr, "FAIL: %s comparing same memory (%p == %p)\n", | ||
| 74 | label, data1, data2); | ||
| 75 | return -1; | ||
| 76 | } | ||
| 77 | if (memcmp(data1, data2, data1_len) != 0) { | ||
| 78 | fprintf(stderr, "FAIL: %s data mismatch\n", label); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | static int | ||
| 85 | do_keypair_tests(void) | ||
| 86 | { | ||
| 87 | size_t cert_len, key_len, ocsp_staple_len; | ||
| 88 | const uint8_t *cert, *key, *ocsp_staple; | ||
| 89 | X509 *x509_cert = NULL; | ||
| 90 | struct tls_keypair *kp; | ||
| 91 | struct tls_error err; | ||
| 92 | char *hash = NULL; | ||
| 93 | int failed = 1; | ||
| 94 | |||
| 95 | load_file(cert_file, &cert, &cert_len); | ||
| 96 | load_file(key_file, &key, &key_len); | ||
| 97 | load_file(ocsp_staple_file, &ocsp_staple, &ocsp_staple_len); | ||
| 98 | |||
| 99 | if ((kp = tls_keypair_new()) == NULL) { | ||
| 100 | fprintf(stderr, "FAIL: failed to create keypair\n"); | ||
| 101 | goto done; | ||
| 102 | } | ||
| 103 | |||
| 104 | if (tls_keypair_set_cert_file(kp, &err, cert_file) == -1) { | ||
| 105 | fprintf(stderr, "FAIL: failed to load cert file: %s\n", | ||
| 106 | err.msg); | ||
| 107 | goto done; | ||
| 108 | } | ||
| 109 | if (tls_keypair_set_key_file(kp, &err, key_file) == -1) { | ||
| 110 | fprintf(stderr, "FAIL: failed to load key file: %s\n", err.msg); | ||
| 111 | goto done; | ||
| 112 | } | ||
| 113 | if (tls_keypair_set_ocsp_staple_file(kp, &err, ocsp_staple_file) == -1) { | ||
| 114 | fprintf(stderr, "FAIL: failed to load ocsp staple file: %s\n", | ||
| 115 | err.msg); | ||
| 116 | goto done; | ||
| 117 | } | ||
| 118 | |||
| 119 | if (compare_mem("certificate", cert, cert_len, kp->cert_mem, | ||
| 120 | kp->cert_len) == -1) | ||
| 121 | goto done; | ||
| 122 | if (compare_mem("key", key, key_len, kp->key_mem, kp->cert_len) == -1) | ||
| 123 | goto done; | ||
| 124 | if (compare_mem("ocsp staple", ocsp_staple, ocsp_staple_len, | ||
| 125 | kp->ocsp_staple, kp->ocsp_staple_len) == -1) | ||
| 126 | goto done; | ||
| 127 | if (strcmp(kp->pubkey_hash, PUBKEY_HASH) != 0) { | ||
| 128 | fprintf(stderr, "FAIL: got pubkey hash '%s', want '%s'", | ||
| 129 | hash, PUBKEY_HASH); | ||
| 130 | goto done; | ||
| 131 | } | ||
| 132 | |||
| 133 | tls_keypair_clear_key(kp); | ||
| 134 | |||
| 135 | if (kp->key_mem != NULL || kp->key_len != 0) { | ||
| 136 | fprintf(stderr, "FAIL: key not cleared (mem %p, len %zu)", | ||
| 137 | kp->key_mem, kp->key_len); | ||
| 138 | goto done; | ||
| 139 | } | ||
| 140 | |||
| 141 | if (tls_keypair_set_cert_mem(kp, &err, cert, cert_len) == -1) { | ||
| 142 | fprintf(stderr, "FAIL: failed to load cert: %s\n", err.msg); | ||
| 143 | goto done; | ||
| 144 | } | ||
| 145 | if (tls_keypair_set_key_mem(kp, &err, key, key_len) == -1) { | ||
| 146 | fprintf(stderr, "FAIL: failed to load key: %s\n", err.msg); | ||
| 147 | goto done; | ||
| 148 | } | ||
| 149 | if (tls_keypair_set_ocsp_staple_mem(kp, &err, ocsp_staple, | ||
| 150 | ocsp_staple_len) == -1) { | ||
| 151 | fprintf(stderr, "FAIL: failed to load ocsp staple: %s\n", err.msg); | ||
| 152 | goto done; | ||
| 153 | } | ||
| 154 | if (compare_mem("certificate", cert, cert_len, kp->cert_mem, | ||
| 155 | kp->cert_len) == -1) | ||
| 156 | goto done; | ||
| 157 | if (compare_mem("key", key, key_len, kp->key_mem, kp->cert_len) == -1) | ||
| 158 | goto done; | ||
| 159 | if (compare_mem("ocsp staple", ocsp_staple, ocsp_staple_len, | ||
| 160 | kp->ocsp_staple, kp->ocsp_staple_len) == -1) | ||
| 161 | goto done; | ||
| 162 | if (strcmp(kp->pubkey_hash, PUBKEY_HASH) != 0) { | ||
| 163 | fprintf(stderr, "FAIL: got pubkey hash '%s', want '%s'", | ||
| 164 | hash, PUBKEY_HASH); | ||
| 165 | goto done; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (tls_keypair_load_cert(kp, &err, &x509_cert) == -1) { | ||
| 169 | fprintf(stderr, "FAIL: failed to load X509 certificate: %s\n", | ||
| 170 | err.msg); | ||
| 171 | goto done; | ||
| 172 | } | ||
| 173 | |||
| 174 | tls_keypair_clear_key(kp); | ||
| 175 | |||
| 176 | if (kp->key_mem != NULL || kp->key_len != 0) { | ||
| 177 | fprintf(stderr, "FAIL: key not cleared (mem %p, len %zu)", | ||
| 178 | kp->key_mem, kp->key_len); | ||
| 179 | goto done; | ||
| 180 | } | ||
| 181 | |||
| 182 | tls_keypair_free(kp); | ||
| 183 | |||
| 184 | failed = 0; | ||
| 185 | |||
| 186 | done: | ||
| 187 | X509_free(x509_cert); | ||
| 188 | free(hash); | ||
| 189 | |||
| 190 | return (failed); | ||
| 191 | } | ||
| 192 | |||
| 193 | int | ||
| 194 | main(int argc, char **argv) | ||
| 195 | { | ||
| 196 | int failure = 0; | ||
| 197 | |||
| 198 | if (argc != 4) { | ||
| 199 | fprintf(stderr, "usage: %s ocspstaplefile certfile keyfile\n", | ||
| 200 | argv[0]); | ||
| 201 | return (1); | ||
| 202 | } | ||
| 203 | |||
| 204 | ocsp_staple_file = argv[1]; | ||
| 205 | cert_file = argv[2]; | ||
| 206 | key_file = argv[3]; | ||
| 207 | |||
| 208 | failure |= do_keypair_tests(); | ||
| 209 | |||
| 210 | return (failure); | ||
| 211 | } | ||
diff --git a/src/regress/lib/libtls/tls/Makefile b/src/regress/lib/libtls/tls/Makefile deleted file mode 100644 index 0fbd78481b..0000000000 --- a/src/regress/lib/libtls/tls/Makefile +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.2 2017/05/06 21:56:43 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= tlstest | ||
| 4 | LDADD= -lcrypto -lssl -ltls | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} | ||
| 6 | |||
| 7 | WARNINGS= Yes | ||
| 8 | CFLAGS+= -Werror | ||
| 9 | |||
| 10 | REGRESS_TARGETS= \ | ||
| 11 | regress-tlstest | ||
| 12 | |||
| 13 | regress-tlstest: ${PROG} | ||
| 14 | ./tlstest \ | ||
| 15 | ${.CURDIR}/../../libssl/certs/ca.pem \ | ||
| 16 | ${.CURDIR}/../../libssl/certs/server.pem \ | ||
| 17 | ${.CURDIR}/../../libssl/certs/server.pem | ||
| 18 | |||
| 19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libtls/tls/tlstest.c b/src/regress/lib/libtls/tls/tlstest.c deleted file mode 100644 index 8a4d5dbb38..0000000000 --- a/src/regress/lib/libtls/tls/tlstest.c +++ /dev/null | |||
| @@ -1,450 +0,0 @@ | |||
| 1 | /* $OpenBSD: tlstest.c,v 1.10 2018/03/19 16:36:12 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <sys/socket.h> | ||
| 19 | |||
| 20 | #include <err.h> | ||
| 21 | #include <fcntl.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | #include <tls.h> | ||
| 27 | |||
| 28 | #define CIRCULAR_BUFFER_SIZE 512 | ||
| 29 | |||
| 30 | unsigned char client_buffer[CIRCULAR_BUFFER_SIZE]; | ||
| 31 | unsigned char *client_readptr, *client_writeptr; | ||
| 32 | |||
| 33 | unsigned char server_buffer[CIRCULAR_BUFFER_SIZE]; | ||
| 34 | unsigned char *server_readptr, *server_writeptr; | ||
| 35 | |||
| 36 | char *cafile, *certfile, *keyfile; | ||
| 37 | |||
| 38 | int debug = 0; | ||
| 39 | |||
| 40 | static void | ||
| 41 | circular_init(void) | ||
| 42 | { | ||
| 43 | client_readptr = client_writeptr = client_buffer; | ||
| 44 | server_readptr = server_writeptr = server_buffer; | ||
| 45 | } | ||
| 46 | |||
| 47 | static ssize_t | ||
| 48 | circular_read(char *name, unsigned char *buf, size_t bufsize, | ||
| 49 | unsigned char **readptr, unsigned char *writeptr, | ||
| 50 | unsigned char *outbuf, size_t outlen) | ||
| 51 | { | ||
| 52 | unsigned char *nextptr = *readptr; | ||
| 53 | size_t n = 0; | ||
| 54 | |||
| 55 | while (n < outlen) { | ||
| 56 | if (nextptr == writeptr) | ||
| 57 | break; | ||
| 58 | *outbuf++ = *nextptr++; | ||
| 59 | if ((size_t)(nextptr - buf) >= bufsize) | ||
| 60 | nextptr = buf; | ||
| 61 | *readptr = nextptr; | ||
| 62 | n++; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (debug && n > 0) | ||
| 66 | fprintf(stderr, "%s buffer: read %zi bytes\n", name, n); | ||
| 67 | |||
| 68 | return (n > 0 ? (ssize_t)n : TLS_WANT_POLLIN); | ||
| 69 | } | ||
| 70 | |||
| 71 | static ssize_t | ||
| 72 | circular_write(char *name, unsigned char *buf, size_t bufsize, | ||
| 73 | unsigned char *readptr, unsigned char **writeptr, | ||
| 74 | const unsigned char *inbuf, size_t inlen) | ||
| 75 | { | ||
| 76 | unsigned char *nextptr = *writeptr; | ||
| 77 | unsigned char *prevptr; | ||
| 78 | size_t n = 0; | ||
| 79 | |||
| 80 | while (n < inlen) { | ||
| 81 | prevptr = nextptr++; | ||
| 82 | if ((size_t)(nextptr - buf) >= bufsize) | ||
| 83 | nextptr = buf; | ||
| 84 | if (nextptr == readptr) | ||
| 85 | break; | ||
| 86 | *prevptr = *inbuf++; | ||
| 87 | *writeptr = nextptr; | ||
| 88 | n++; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (debug && n > 0) | ||
| 92 | fprintf(stderr, "%s buffer: wrote %zi bytes\n", name, n); | ||
| 93 | |||
| 94 | return (n > 0 ? (ssize_t)n : TLS_WANT_POLLOUT); | ||
| 95 | } | ||
| 96 | |||
| 97 | static ssize_t | ||
| 98 | client_read(struct tls *ctx, void *buf, size_t buflen, void *cb_arg) | ||
| 99 | { | ||
| 100 | return circular_read("client", client_buffer, sizeof(client_buffer), | ||
| 101 | &client_readptr, client_writeptr, buf, buflen); | ||
| 102 | } | ||
| 103 | |||
| 104 | static ssize_t | ||
| 105 | client_write(struct tls *ctx, const void *buf, size_t buflen, void *cb_arg) | ||
| 106 | { | ||
| 107 | return circular_write("server", server_buffer, sizeof(server_buffer), | ||
| 108 | server_readptr, &server_writeptr, buf, buflen); | ||
| 109 | } | ||
| 110 | |||
| 111 | static ssize_t | ||
| 112 | server_read(struct tls *ctx, void *buf, size_t buflen, void *cb_arg) | ||
| 113 | { | ||
| 114 | return circular_read("server", server_buffer, sizeof(server_buffer), | ||
| 115 | &server_readptr, server_writeptr, buf, buflen); | ||
| 116 | } | ||
| 117 | |||
| 118 | static ssize_t | ||
| 119 | server_write(struct tls *ctx, const void *buf, size_t buflen, void *cb_arg) | ||
| 120 | { | ||
| 121 | return circular_write("client", client_buffer, sizeof(client_buffer), | ||
| 122 | client_readptr, &client_writeptr, buf, buflen); | ||
| 123 | } | ||
| 124 | |||
| 125 | static int | ||
| 126 | do_tls_handshake(char *name, struct tls *ctx) | ||
| 127 | { | ||
| 128 | int rv; | ||
| 129 | |||
| 130 | rv = tls_handshake(ctx); | ||
| 131 | if (rv == 0) | ||
| 132 | return (1); | ||
| 133 | if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT) | ||
| 134 | return (0); | ||
| 135 | |||
| 136 | errx(1, "%s handshake failed: %s", name, tls_error(ctx)); | ||
| 137 | } | ||
| 138 | |||
| 139 | static int | ||
| 140 | do_tls_close(char *name, struct tls *ctx) | ||
| 141 | { | ||
| 142 | int rv; | ||
| 143 | |||
| 144 | rv = tls_close(ctx); | ||
| 145 | if (rv == 0) | ||
| 146 | return (1); | ||
| 147 | if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT) | ||
| 148 | return (0); | ||
| 149 | |||
| 150 | errx(1, "%s close failed: %s", name, tls_error(ctx)); | ||
| 151 | } | ||
| 152 | |||
| 153 | static int | ||
| 154 | do_client_server_handshake(char *desc, struct tls *client, | ||
| 155 | struct tls *server_cctx) | ||
| 156 | { | ||
| 157 | int i, client_done, server_done; | ||
| 158 | |||
| 159 | i = client_done = server_done = 0; | ||
| 160 | do { | ||
| 161 | if (client_done == 0) | ||
| 162 | client_done = do_tls_handshake("client", client); | ||
| 163 | if (server_done == 0) | ||
| 164 | server_done = do_tls_handshake("server", server_cctx); | ||
| 165 | } while (i++ < 100 && (client_done == 0 || server_done == 0)); | ||
| 166 | |||
| 167 | if (client_done == 0 || server_done == 0) { | ||
| 168 | printf("FAIL: %s TLS handshake did not complete\n", desc); | ||
| 169 | return (1); | ||
| 170 | } | ||
| 171 | |||
| 172 | return (0); | ||
| 173 | } | ||
| 174 | |||
| 175 | static int | ||
| 176 | do_client_server_close(char *desc, struct tls *client, struct tls *server_cctx) | ||
| 177 | { | ||
| 178 | int i, client_done, server_done; | ||
| 179 | |||
| 180 | i = client_done = server_done = 0; | ||
| 181 | do { | ||
| 182 | if (client_done == 0) | ||
| 183 | client_done = do_tls_close("client", client); | ||
| 184 | if (server_done == 0) | ||
| 185 | server_done = do_tls_close("server", server_cctx); | ||
| 186 | } while (i++ < 100 && (client_done == 0 || server_done == 0)); | ||
| 187 | |||
| 188 | if (client_done == 0 || server_done == 0) { | ||
| 189 | printf("FAIL: %s TLS close did not complete\n", desc); | ||
| 190 | return (1); | ||
| 191 | } | ||
| 192 | |||
| 193 | return (0); | ||
| 194 | } | ||
| 195 | |||
| 196 | static int | ||
| 197 | do_client_server_test(char *desc, struct tls *client, struct tls *server_cctx) | ||
| 198 | { | ||
| 199 | if (do_client_server_handshake(desc, client, server_cctx) != 0) | ||
| 200 | return (1); | ||
| 201 | |||
| 202 | printf("INFO: %s TLS handshake completed successfully\n", desc); | ||
| 203 | |||
| 204 | /* XXX - Do some reads and writes... */ | ||
| 205 | |||
| 206 | if (do_client_server_close(desc, client, server_cctx) != 0) | ||
| 207 | return (1); | ||
| 208 | |||
| 209 | printf("INFO: %s TLS close completed successfully\n", desc); | ||
| 210 | |||
| 211 | return (0); | ||
| 212 | } | ||
| 213 | |||
| 214 | static int | ||
| 215 | test_tls_cbs(struct tls *client, struct tls *server) | ||
| 216 | { | ||
| 217 | struct tls *server_cctx; | ||
| 218 | int failure; | ||
| 219 | |||
| 220 | circular_init(); | ||
| 221 | |||
| 222 | if (tls_accept_cbs(server, &server_cctx, server_read, server_write, | ||
| 223 | NULL) == -1) | ||
| 224 | errx(1, "failed to accept: %s", tls_error(server)); | ||
| 225 | |||
| 226 | if (tls_connect_cbs(client, client_read, client_write, NULL, | ||
| 227 | "test") == -1) | ||
| 228 | errx(1, "failed to connect: %s", tls_error(client)); | ||
| 229 | |||
| 230 | failure = do_client_server_test("callback", client, server_cctx); | ||
| 231 | |||
| 232 | tls_free(server_cctx); | ||
| 233 | |||
| 234 | return (failure); | ||
| 235 | } | ||
| 236 | |||
| 237 | static int | ||
| 238 | test_tls_fds(struct tls *client, struct tls *server) | ||
| 239 | { | ||
| 240 | struct tls *server_cctx; | ||
| 241 | int cfds[2], sfds[2]; | ||
| 242 | int failure; | ||
| 243 | |||
| 244 | if (pipe2(cfds, O_NONBLOCK) == -1) | ||
| 245 | err(1, "failed to create pipe"); | ||
| 246 | if (pipe2(sfds, O_NONBLOCK) == -1) | ||
| 247 | err(1, "failed to create pipe"); | ||
| 248 | |||
| 249 | if (tls_accept_fds(server, &server_cctx, sfds[0], cfds[1]) == -1) | ||
| 250 | errx(1, "failed to accept: %s", tls_error(server)); | ||
| 251 | |||
| 252 | if (tls_connect_fds(client, cfds[0], sfds[1], "test") == -1) | ||
| 253 | errx(1, "failed to connect: %s", tls_error(client)); | ||
| 254 | |||
| 255 | failure = do_client_server_test("file descriptor", client, server_cctx); | ||
| 256 | |||
| 257 | tls_free(server_cctx); | ||
| 258 | |||
| 259 | close(cfds[0]); | ||
| 260 | close(cfds[1]); | ||
| 261 | close(sfds[0]); | ||
| 262 | close(sfds[1]); | ||
| 263 | |||
| 264 | return (failure); | ||
| 265 | } | ||
| 266 | |||
| 267 | static int | ||
| 268 | test_tls_socket(struct tls *client, struct tls *server) | ||
| 269 | { | ||
| 270 | struct tls *server_cctx; | ||
| 271 | int failure; | ||
| 272 | int sv[2]; | ||
| 273 | |||
| 274 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, PF_UNSPEC, | ||
| 275 | sv) == -1) | ||
| 276 | err(1, "failed to create socketpair"); | ||
| 277 | |||
| 278 | if (tls_accept_socket(server, &server_cctx, sv[0]) == -1) | ||
| 279 | errx(1, "failed to accept: %s", tls_error(server)); | ||
| 280 | |||
| 281 | if (tls_connect_socket(client, sv[1], "test") == -1) | ||
| 282 | errx(1, "failed to connect: %s", tls_error(client)); | ||
| 283 | |||
| 284 | failure = do_client_server_test("socket", client, server_cctx); | ||
| 285 | |||
| 286 | tls_free(server_cctx); | ||
| 287 | |||
| 288 | close(sv[0]); | ||
| 289 | close(sv[1]); | ||
| 290 | |||
| 291 | return (failure); | ||
| 292 | } | ||
| 293 | |||
| 294 | static int | ||
| 295 | do_tls_tests(void) | ||
| 296 | { | ||
| 297 | struct tls_config *client_cfg, *server_cfg; | ||
| 298 | struct tls *client, *server; | ||
| 299 | int failure = 0; | ||
| 300 | |||
| 301 | if ((client = tls_client()) == NULL) | ||
| 302 | errx(1, "failed to create tls client"); | ||
| 303 | if ((client_cfg = tls_config_new()) == NULL) | ||
| 304 | errx(1, "failed to create tls client config"); | ||
| 305 | tls_config_insecure_noverifyname(client_cfg); | ||
| 306 | if (tls_config_set_ca_file(client_cfg, cafile) == -1) | ||
| 307 | errx(1, "failed to set ca: %s", tls_config_error(client_cfg)); | ||
| 308 | |||
| 309 | if ((server = tls_server()) == NULL) | ||
| 310 | errx(1, "failed to create tls server"); | ||
| 311 | if ((server_cfg = tls_config_new()) == NULL) | ||
| 312 | errx(1, "failed to create tls server config"); | ||
| 313 | if (tls_config_set_keypair_file(server_cfg, certfile, keyfile) == -1) | ||
| 314 | errx(1, "failed to set keypair: %s", | ||
| 315 | tls_config_error(server_cfg)); | ||
| 316 | |||
| 317 | tls_reset(client); | ||
| 318 | if (tls_configure(client, client_cfg) == -1) | ||
| 319 | errx(1, "failed to configure client: %s", tls_error(client)); | ||
| 320 | tls_reset(server); | ||
| 321 | if (tls_configure(server, server_cfg) == -1) | ||
| 322 | errx(1, "failed to configure server: %s", tls_error(server)); | ||
| 323 | |||
| 324 | failure |= test_tls_cbs(client, server); | ||
| 325 | |||
| 326 | tls_reset(client); | ||
| 327 | if (tls_configure(client, client_cfg) == -1) | ||
| 328 | errx(1, "failed to configure client: %s", tls_error(client)); | ||
| 329 | tls_reset(server); | ||
| 330 | if (tls_configure(server, server_cfg) == -1) | ||
| 331 | errx(1, "failed to configure server: %s", tls_error(server)); | ||
| 332 | |||
| 333 | failure |= test_tls_fds(client, server); | ||
| 334 | |||
| 335 | tls_reset(client); | ||
| 336 | if (tls_configure(client, client_cfg) == -1) | ||
| 337 | errx(1, "failed to configure client: %s", tls_error(client)); | ||
| 338 | tls_reset(server); | ||
| 339 | if (tls_configure(server, server_cfg) == -1) | ||
| 340 | errx(1, "failed to configure server: %s", tls_error(server)); | ||
| 341 | |||
| 342 | tls_config_free(client_cfg); | ||
| 343 | tls_config_free(server_cfg); | ||
| 344 | |||
| 345 | failure |= test_tls_socket(client, server); | ||
| 346 | |||
| 347 | tls_free(client); | ||
| 348 | tls_free(server); | ||
| 349 | |||
| 350 | return (failure); | ||
| 351 | } | ||
| 352 | |||
| 353 | static int | ||
| 354 | do_tls_ordering_tests(void) | ||
| 355 | { | ||
| 356 | struct tls *client = NULL, *server = NULL, *server_cctx = NULL; | ||
| 357 | struct tls_config *client_cfg, *server_cfg; | ||
| 358 | int failure = 0; | ||
| 359 | |||
| 360 | circular_init(); | ||
| 361 | |||
| 362 | if ((client = tls_client()) == NULL) | ||
| 363 | errx(1, "failed to create tls client"); | ||
| 364 | if ((client_cfg = tls_config_new()) == NULL) | ||
| 365 | errx(1, "failed to create tls client config"); | ||
| 366 | tls_config_insecure_noverifyname(client_cfg); | ||
| 367 | if (tls_config_set_ca_file(client_cfg, cafile) == -1) | ||
| 368 | errx(1, "failed to set ca: %s", tls_config_error(client_cfg)); | ||
| 369 | |||
| 370 | if ((server = tls_server()) == NULL) | ||
| 371 | errx(1, "failed to create tls server"); | ||
| 372 | if ((server_cfg = tls_config_new()) == NULL) | ||
| 373 | errx(1, "failed to create tls server config"); | ||
| 374 | if (tls_config_set_keypair_file(server_cfg, certfile, keyfile) == -1) | ||
| 375 | errx(1, "failed to set keypair: %s", | ||
| 376 | tls_config_error(server_cfg)); | ||
| 377 | |||
| 378 | if (tls_configure(client, client_cfg) == -1) | ||
| 379 | errx(1, "failed to configure client: %s", tls_error(client)); | ||
| 380 | if (tls_configure(server, server_cfg) == -1) | ||
| 381 | errx(1, "failed to configure server: %s", tls_error(server)); | ||
| 382 | |||
| 383 | tls_config_free(client_cfg); | ||
| 384 | tls_config_free(server_cfg); | ||
| 385 | |||
| 386 | if (tls_handshake(client) != -1) { | ||
| 387 | printf("FAIL: TLS handshake succeeded on unconnnected " | ||
| 388 | "client context\n"); | ||
| 389 | failure = 1; | ||
| 390 | goto done; | ||
| 391 | } | ||
| 392 | |||
| 393 | if (tls_accept_cbs(server, &server_cctx, server_read, server_write, | ||
| 394 | NULL) == -1) | ||
| 395 | errx(1, "failed to accept: %s", tls_error(server)); | ||
| 396 | |||
| 397 | if (tls_connect_cbs(client, client_read, client_write, NULL, | ||
| 398 | "test") == -1) | ||
| 399 | errx(1, "failed to connect: %s", tls_error(client)); | ||
| 400 | |||
| 401 | if (do_client_server_handshake("ordering", client, server_cctx) != 0) { | ||
| 402 | failure = 1; | ||
| 403 | goto done; | ||
| 404 | } | ||
| 405 | |||
| 406 | if (tls_handshake(client) != -1) { | ||
| 407 | printf("FAIL: TLS handshake succeeded twice\n"); | ||
| 408 | failure = 1; | ||
| 409 | goto done; | ||
| 410 | } | ||
| 411 | |||
| 412 | if (tls_handshake(server_cctx) != -1) { | ||
| 413 | printf("FAIL: TLS handshake succeeded twice\n"); | ||
| 414 | failure = 1; | ||
| 415 | goto done; | ||
| 416 | } | ||
| 417 | |||
| 418 | if (do_client_server_close("ordering", client, server_cctx) != 0) { | ||
| 419 | failure = 1; | ||
| 420 | goto done; | ||
| 421 | } | ||
| 422 | |||
| 423 | done: | ||
| 424 | tls_free(client); | ||
| 425 | tls_free(server); | ||
| 426 | tls_free(server_cctx); | ||
| 427 | |||
| 428 | return (failure); | ||
| 429 | } | ||
| 430 | |||
| 431 | int | ||
| 432 | main(int argc, char **argv) | ||
| 433 | { | ||
| 434 | int failure = 0; | ||
| 435 | |||
| 436 | if (argc != 4) { | ||
| 437 | fprintf(stderr, "usage: %s cafile certfile keyfile\n", | ||
| 438 | argv[0]); | ||
| 439 | return (1); | ||
| 440 | } | ||
| 441 | |||
| 442 | cafile = argv[1]; | ||
| 443 | certfile = argv[2]; | ||
| 444 | keyfile = argv[3]; | ||
| 445 | |||
| 446 | failure |= do_tls_tests(); | ||
| 447 | failure |= do_tls_ordering_tests(); | ||
| 448 | |||
| 449 | return (failure); | ||
| 450 | } | ||
diff --git a/src/regress/lib/libtls/verify/Makefile b/src/regress/lib/libtls/verify/Makefile deleted file mode 100644 index f8e445b7fc..0000000000 --- a/src/regress/lib/libtls/verify/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.3 2017/01/09 12:34:03 jsing Exp $ | ||
| 2 | |||
| 3 | PROG= verifytest | ||
| 4 | LDADD= -lcrypto -lssl ${TLS_INT} | ||
| 5 | DPADD= ${LIBCRYPTO} ${LIBSSL} ${LIBTLS} | ||
| 6 | |||
| 7 | WARNINGS= Yes | ||
| 8 | CFLAGS+= -Werror | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libtls/verify/verifytest.c b/src/regress/lib/libtls/verify/verifytest.c deleted file mode 100644 index b41b62fcfb..0000000000 --- a/src/regress/lib/libtls/verify/verifytest.c +++ /dev/null | |||
| @@ -1,524 +0,0 @@ | |||
| 1 | /* $OpenBSD: verifytest.c,v 1.7 2017/04/30 03:53:31 jsing Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | |||
| 22 | #include <openssl/x509v3.h> | ||
| 23 | #include <tls.h> | ||
| 24 | |||
| 25 | extern int tls_check_name(struct tls *ctx, X509 *cert, const char *name, | ||
| 26 | int *match); | ||
| 27 | |||
| 28 | struct alt_name { | ||
| 29 | const char name[128]; | ||
| 30 | int name_len; | ||
| 31 | int name_type; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct verify_test { | ||
| 35 | const char common_name[128]; | ||
| 36 | int common_name_len; | ||
| 37 | struct alt_name alt_name1; | ||
| 38 | struct alt_name alt_name2; | ||
| 39 | struct alt_name alt_name3; | ||
| 40 | const char name[128]; | ||
| 41 | int want_return; | ||
| 42 | int want_match; | ||
| 43 | }; | ||
| 44 | |||
| 45 | struct verify_test verify_tests[] = { | ||
| 46 | { | ||
| 47 | /* CN without SANs - matching. */ | ||
| 48 | .common_name = "www.openbsd.org", | ||
| 49 | .common_name_len = -1, | ||
| 50 | .name = "www.openbsd.org", | ||
| 51 | .want_return = 0, | ||
| 52 | .want_match = 1, | ||
| 53 | }, | ||
| 54 | { | ||
| 55 | /* Zero length name - non-matching. */ | ||
| 56 | .common_name = "www.openbsd.org", | ||
| 57 | .common_name_len = -1, | ||
| 58 | .name = "", | ||
| 59 | .want_return = 0, | ||
| 60 | .want_match = 0, | ||
| 61 | }, | ||
| 62 | { | ||
| 63 | /* CN wildcard without SANs - matching. */ | ||
| 64 | .common_name = "*.openbsd.org", | ||
| 65 | .common_name_len = -1, | ||
| 66 | .name = "www.openbsd.org", | ||
| 67 | .want_return = 0, | ||
| 68 | .want_match = 1, | ||
| 69 | }, | ||
| 70 | { | ||
| 71 | /* CN without SANs - non-matching. */ | ||
| 72 | .common_name = "www.openbsdfoundation.org", | ||
| 73 | .common_name_len = -1, | ||
| 74 | .name = "www.openbsd.org", | ||
| 75 | .want_return = 0, | ||
| 76 | .want_match = 0, | ||
| 77 | }, | ||
| 78 | { | ||
| 79 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 80 | .common_name = "w*.openbsd.org", | ||
| 81 | .common_name_len = -1, | ||
| 82 | .name = "www.openbsd.org", | ||
| 83 | .want_return = 0, | ||
| 84 | .want_match = 0, | ||
| 85 | }, | ||
| 86 | { | ||
| 87 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 88 | .common_name = "www.*.org", | ||
| 89 | .common_name_len = -1, | ||
| 90 | .name = "www.openbsd.org", | ||
| 91 | .want_return = 0, | ||
| 92 | .want_match = 0, | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 96 | .common_name = "www.openbsd.*", | ||
| 97 | .common_name_len = -1, | ||
| 98 | .name = "www.openbsd.org", | ||
| 99 | .want_return = 0, | ||
| 100 | .want_match = 0, | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 104 | .common_name = "*", | ||
| 105 | .common_name_len = -1, | ||
| 106 | .name = "www.openbsd.org", | ||
| 107 | .want_return = 0, | ||
| 108 | .want_match = 0, | ||
| 109 | }, | ||
| 110 | { | ||
| 111 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 112 | .common_name = "*.org", | ||
| 113 | .common_name_len = -1, | ||
| 114 | .name = "www.openbsd.org", | ||
| 115 | .want_return = 0, | ||
| 116 | .want_match = 0, | ||
| 117 | }, | ||
| 118 | { | ||
| 119 | /* CN wildcard without SANs - invalid CN wildcard. */ | ||
| 120 | .common_name = "*.org", | ||
| 121 | .common_name_len = -1, | ||
| 122 | .name = "openbsd.org", | ||
| 123 | .want_return = 0, | ||
| 124 | .want_match = 0, | ||
| 125 | }, | ||
| 126 | { | ||
| 127 | /* CN IPv4 without SANs - matching. */ | ||
| 128 | .common_name = "1.2.3.4", | ||
| 129 | .common_name_len = -1, | ||
| 130 | .name = "1.2.3.4", | ||
| 131 | .want_return = 0, | ||
| 132 | .want_match = 1, | ||
| 133 | }, | ||
| 134 | { | ||
| 135 | /* CN IPv4 wildcard without SANS - invalid IP wildcard. */ | ||
| 136 | .common_name = "*.2.3.4", | ||
| 137 | .common_name_len = -1, | ||
| 138 | .name = "1.2.3.4", | ||
| 139 | .want_return = 0, | ||
| 140 | .want_match = 0, | ||
| 141 | }, | ||
| 142 | { | ||
| 143 | /* CN IPv6 without SANs - matching. */ | ||
| 144 | .common_name = "cafe::beef", | ||
| 145 | .common_name_len = -1, | ||
| 146 | .name = "cafe::beef", | ||
| 147 | .want_return = 0, | ||
| 148 | .want_match = 1, | ||
| 149 | }, | ||
| 150 | { | ||
| 151 | /* CN without SANs - error due to embedded NUL in CN. */ | ||
| 152 | .common_name = { | ||
| 153 | 0x77, 0x77, 0x77, 0x2e, 0x6f, 0x70, 0x65, 0x6e, | ||
| 154 | 0x62, 0x73, 0x64, 0x2e, 0x6f, 0x72, 0x67, 0x00, | ||
| 155 | 0x6e, 0x61, 0x73, 0x74, 0x79, 0x2e, 0x6f, 0x72, | ||
| 156 | 0x67, | ||
| 157 | }, | ||
| 158 | .common_name_len = 25, | ||
| 159 | .name = "www.openbsd.org", | ||
| 160 | .want_return = -1, | ||
| 161 | .want_match = 0, | ||
| 162 | }, | ||
| 163 | { | ||
| 164 | /* CN wildcard without SANs - invalid non-matching name. */ | ||
| 165 | .common_name = "*.openbsd.org", | ||
| 166 | .common_name_len = -1, | ||
| 167 | .name = ".openbsd.org", | ||
| 168 | .want_return = 0, | ||
| 169 | .want_match = 0, | ||
| 170 | }, | ||
| 171 | { | ||
| 172 | /* CN with SANs - matching on first SAN. */ | ||
| 173 | .common_name = "www.openbsd.org", | ||
| 174 | .common_name_len = -1, | ||
| 175 | .alt_name1 = { | ||
| 176 | .name = "www.openbsd.org", | ||
| 177 | .name_len = -1, | ||
| 178 | .name_type = GEN_DNS, | ||
| 179 | }, | ||
| 180 | .alt_name2 = { | ||
| 181 | .name = "ftp.openbsd.org", | ||
| 182 | .name_len = -1, | ||
| 183 | .name_type = GEN_DNS, | ||
| 184 | }, | ||
| 185 | .name = "www.openbsd.org", | ||
| 186 | .want_return = 0, | ||
| 187 | .want_match = 1, | ||
| 188 | }, | ||
| 189 | { | ||
| 190 | /* SANs only - matching on first SAN. */ | ||
| 191 | .common_name_len = 0, | ||
| 192 | .alt_name1 = { | ||
| 193 | .name = "www.openbsd.org", | ||
| 194 | .name_len = -1, | ||
| 195 | .name_type = GEN_DNS, | ||
| 196 | }, | ||
| 197 | .alt_name2 = { | ||
| 198 | .name = "ftp.openbsd.org", | ||
| 199 | .name_len = -1, | ||
| 200 | .name_type = GEN_DNS, | ||
| 201 | }, | ||
| 202 | .name = "www.openbsd.org", | ||
| 203 | .want_return = 0, | ||
| 204 | .want_match = 1, | ||
| 205 | }, | ||
| 206 | { | ||
| 207 | /* SANs only - matching on second SAN. */ | ||
| 208 | .common_name_len = 0, | ||
| 209 | .alt_name1 = { | ||
| 210 | .name = "www.openbsd.org", | ||
| 211 | .name_len = -1, | ||
| 212 | .name_type = GEN_DNS, | ||
| 213 | }, | ||
| 214 | .alt_name2 = { | ||
| 215 | .name = "ftp.openbsd.org", | ||
| 216 | .name_len = -1, | ||
| 217 | .name_type = GEN_DNS, | ||
| 218 | }, | ||
| 219 | .name = "ftp.openbsd.org", | ||
| 220 | .want_return = 0, | ||
| 221 | .want_match = 1, | ||
| 222 | }, | ||
| 223 | { | ||
| 224 | /* SANs only - non-matching. */ | ||
| 225 | .common_name_len = 0, | ||
| 226 | .alt_name1 = { | ||
| 227 | .name = "www.openbsd.org", | ||
| 228 | .name_len = -1, | ||
| 229 | .name_type = GEN_DNS, | ||
| 230 | }, | ||
| 231 | .alt_name2 = { | ||
| 232 | .name = "ftp.openbsd.org", | ||
| 233 | .name_len = -1, | ||
| 234 | .name_type = GEN_DNS, | ||
| 235 | }, | ||
| 236 | .name = "mail.openbsd.org", | ||
| 237 | .want_return = 0, | ||
| 238 | .want_match = 0, | ||
| 239 | }, | ||
| 240 | { | ||
| 241 | /* CN with SANs - matching on second SAN. */ | ||
| 242 | .common_name = "www.openbsd.org", | ||
| 243 | .common_name_len = -1, | ||
| 244 | .alt_name1 = { | ||
| 245 | .name = "www.openbsd.org", | ||
| 246 | .name_len = -1, | ||
| 247 | .name_type = GEN_DNS, | ||
| 248 | }, | ||
| 249 | .alt_name2 = { | ||
| 250 | .name = "ftp.openbsd.org", | ||
| 251 | .name_len = -1, | ||
| 252 | .name_type = GEN_DNS, | ||
| 253 | }, | ||
| 254 | .name = "ftp.openbsd.org", | ||
| 255 | .want_return = 0, | ||
| 256 | .want_match = 1, | ||
| 257 | }, | ||
| 258 | { | ||
| 259 | /* CN with SANs - matching on wildcard second SAN. */ | ||
| 260 | .common_name = "www.openbsdfoundation.org", | ||
| 261 | .common_name_len = -1, | ||
| 262 | .alt_name1 = { | ||
| 263 | .name = "www.openbsdfoundation.org", | ||
| 264 | .name_len = -1, | ||
| 265 | .name_type = GEN_DNS, | ||
| 266 | }, | ||
| 267 | .alt_name2 = { | ||
| 268 | .name = "*.openbsd.org", | ||
| 269 | .name_len = -1, | ||
| 270 | .name_type = GEN_DNS, | ||
| 271 | }, | ||
| 272 | .name = "www.openbsd.org", | ||
| 273 | .want_return = 0, | ||
| 274 | .want_match = 1, | ||
| 275 | }, | ||
| 276 | { | ||
| 277 | /* CN with SANs - non-matching invalid wildcard. */ | ||
| 278 | .common_name = "www.openbsdfoundation.org", | ||
| 279 | .common_name_len = -1, | ||
| 280 | .alt_name1 = { | ||
| 281 | .name = "www.openbsdfoundation.org", | ||
| 282 | .name_len = -1, | ||
| 283 | .name_type = GEN_DNS, | ||
| 284 | }, | ||
| 285 | .alt_name2 = { | ||
| 286 | .name = "*.org", | ||
| 287 | .name_len = -1, | ||
| 288 | .name_type = GEN_DNS, | ||
| 289 | }, | ||
| 290 | .name = "www.openbsd.org", | ||
| 291 | .want_return = 0, | ||
| 292 | .want_match = 0, | ||
| 293 | }, | ||
| 294 | { | ||
| 295 | /* CN with SANs - non-matching IPv4 due to GEN_DNS SAN. */ | ||
| 296 | .common_name = "www.openbsd.org", | ||
| 297 | .common_name_len = -1, | ||
| 298 | .alt_name1 = { | ||
| 299 | .name = "www.openbsd.org", | ||
| 300 | .name_len = -1, | ||
| 301 | .name_type = GEN_DNS, | ||
| 302 | }, | ||
| 303 | .alt_name2 = { | ||
| 304 | .name = "1.2.3.4", | ||
| 305 | .name_len = -1, | ||
| 306 | .name_type = GEN_DNS, | ||
| 307 | }, | ||
| 308 | .name = "1.2.3.4", | ||
| 309 | .want_return = 0, | ||
| 310 | .want_match = 0, | ||
| 311 | }, | ||
| 312 | { | ||
| 313 | /* CN with SANs - matching IPv4 on GEN_IPADD SAN. */ | ||
| 314 | .common_name = "www.openbsd.org", | ||
| 315 | .common_name_len = -1, | ||
| 316 | .alt_name1 = { | ||
| 317 | .name = "www.openbsd.org", | ||
| 318 | .name_len = -1, | ||
| 319 | .name_type = GEN_DNS, | ||
| 320 | }, | ||
| 321 | .alt_name2 = { | ||
| 322 | .name = {0x01, 0x02, 0x03, 0x04}, | ||
| 323 | .name_len = 4, | ||
| 324 | .name_type = GEN_IPADD, | ||
| 325 | }, | ||
| 326 | .name = "1.2.3.4", | ||
| 327 | .want_return = 0, | ||
| 328 | .want_match = 1, | ||
| 329 | }, | ||
| 330 | { | ||
| 331 | /* CN with SANs - matching IPv6 on GEN_IPADD SAN. */ | ||
| 332 | .common_name = "www.openbsd.org", | ||
| 333 | .common_name_len = -1, | ||
| 334 | .alt_name1 = { | ||
| 335 | .name = "www.openbsd.org", | ||
| 336 | .name_len = -1, | ||
| 337 | .name_type = GEN_DNS, | ||
| 338 | }, | ||
| 339 | .alt_name2 = { | ||
| 340 | .name = { | ||
| 341 | 0xca, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 342 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0xef, | ||
| 343 | }, | ||
| 344 | .name_len = 16, | ||
| 345 | .name_type = GEN_IPADD, | ||
| 346 | }, | ||
| 347 | .name = "cafe::beef", | ||
| 348 | .want_return = 0, | ||
| 349 | .want_match = 1, | ||
| 350 | }, | ||
| 351 | { | ||
| 352 | /* CN with SANs - error due to embedded NUL in GEN_DNS. */ | ||
| 353 | .common_name = "www.openbsd.org.nasty.org", | ||
| 354 | .common_name_len = -1, | ||
| 355 | .alt_name1 = { | ||
| 356 | .name = "www.openbsd.org.nasty.org", | ||
| 357 | .name_len = -1, | ||
| 358 | .name_type = GEN_DNS, | ||
| 359 | }, | ||
| 360 | .alt_name2 = { | ||
| 361 | .name = { | ||
| 362 | 0x77, 0x77, 0x77, 0x2e, 0x6f, 0x70, 0x65, 0x6e, | ||
| 363 | 0x62, 0x73, 0x64, 0x2e, 0x6f, 0x72, 0x67, 0x00, | ||
| 364 | 0x6e, 0x61, 0x73, 0x74, 0x79, 0x2e, 0x6f, 0x72, | ||
| 365 | 0x67, | ||
| 366 | }, | ||
| 367 | .name_len = 25, | ||
| 368 | .name_type = GEN_DNS, | ||
| 369 | }, | ||
| 370 | .name = "www.openbsd.org", | ||
| 371 | .want_return = -1, | ||
| 372 | .want_match = 0, | ||
| 373 | }, | ||
| 374 | { | ||
| 375 | /* CN with SAN - non-matching due to non-matching SAN. */ | ||
| 376 | .common_name = "www.openbsd.org", | ||
| 377 | .common_name_len = -1, | ||
| 378 | .alt_name1 = { | ||
| 379 | .name = "ftp.openbsd.org", | ||
| 380 | .name_len = -1, | ||
| 381 | .name_type = GEN_DNS, | ||
| 382 | }, | ||
| 383 | .name = "www.openbsd.org", | ||
| 384 | .want_return = 0, | ||
| 385 | .want_match = 0, | ||
| 386 | }, | ||
| 387 | { | ||
| 388 | /* CN with SAN - error due to illegal dNSName. */ | ||
| 389 | .common_name = "www.openbsd.org", | ||
| 390 | .common_name_len = -1, | ||
| 391 | .alt_name1 = { | ||
| 392 | .name = " ", | ||
| 393 | .name_len = -1, | ||
| 394 | .name_type = GEN_DNS, | ||
| 395 | }, | ||
| 396 | .name = "www.openbsd.org", | ||
| 397 | .want_return = -1, | ||
| 398 | .want_match = 0, | ||
| 399 | }, | ||
| 400 | }; | ||
| 401 | |||
| 402 | #define N_VERIFY_TESTS \ | ||
| 403 | (sizeof(verify_tests) / sizeof(*verify_tests)) | ||
| 404 | |||
| 405 | static void | ||
| 406 | alt_names_add(STACK_OF(GENERAL_NAME) *alt_name_stack, struct alt_name *alt) | ||
| 407 | { | ||
| 408 | ASN1_STRING *alt_name_str; | ||
| 409 | GENERAL_NAME *alt_name; | ||
| 410 | |||
| 411 | if ((alt_name = GENERAL_NAME_new()) == NULL) | ||
| 412 | errx(1, "failed to malloc GENERAL_NAME"); | ||
| 413 | alt_name->type = alt->name_type; | ||
| 414 | |||
| 415 | if ((alt_name_str = ASN1_STRING_new()) == NULL) | ||
| 416 | errx(1, "failed to malloc alt name"); | ||
| 417 | if (ASN1_STRING_set(alt_name_str, alt->name, alt->name_len) == 0) | ||
| 418 | errx(1, "failed to set alt name"); | ||
| 419 | |||
| 420 | switch (alt_name->type) { | ||
| 421 | case GEN_DNS: | ||
| 422 | alt_name->d.dNSName = alt_name_str; | ||
| 423 | break; | ||
| 424 | case GEN_IPADD: | ||
| 425 | alt_name->d.iPAddress = alt_name_str; | ||
| 426 | break; | ||
| 427 | default: | ||
| 428 | errx(1, "unknown alt name type (%i)", alt_name->type); | ||
| 429 | } | ||
| 430 | |||
| 431 | if (sk_GENERAL_NAME_push(alt_name_stack, alt_name) == 0) | ||
| 432 | errx(1, "failed to push alt_name"); | ||
| 433 | } | ||
| 434 | |||
| 435 | static void | ||
| 436 | cert_add_alt_names(X509 *cert, struct verify_test *vt) | ||
| 437 | { | ||
| 438 | STACK_OF(GENERAL_NAME) *alt_name_stack = NULL; | ||
| 439 | |||
| 440 | if (vt->alt_name1.name_type == 0) | ||
| 441 | return; | ||
| 442 | |||
| 443 | if ((alt_name_stack = sk_GENERAL_NAME_new_null()) == NULL) | ||
| 444 | errx(1, "failed to malloc sk_GENERAL_NAME"); | ||
| 445 | |||
| 446 | if (vt->alt_name1.name_type != 0) | ||
| 447 | alt_names_add(alt_name_stack, &vt->alt_name1); | ||
| 448 | if (vt->alt_name2.name_type != 0) | ||
| 449 | alt_names_add(alt_name_stack, &vt->alt_name2); | ||
| 450 | if (vt->alt_name3.name_type != 0) | ||
| 451 | alt_names_add(alt_name_stack, &vt->alt_name3); | ||
| 452 | |||
| 453 | if (X509_add1_ext_i2d(cert, NID_subject_alt_name, | ||
| 454 | alt_name_stack, 0, 0) == 0) | ||
| 455 | errx(1, "failed to set subject alt name"); | ||
| 456 | |||
| 457 | sk_GENERAL_NAME_pop_free(alt_name_stack, GENERAL_NAME_free); | ||
| 458 | } | ||
| 459 | |||
| 460 | static int | ||
| 461 | do_verify_test(int test_no, struct verify_test *vt) | ||
| 462 | { | ||
| 463 | struct tls *tls; | ||
| 464 | X509_NAME *name; | ||
| 465 | X509 *cert; | ||
| 466 | int failed = 1; | ||
| 467 | int match; | ||
| 468 | |||
| 469 | /* Build certificate structure. */ | ||
| 470 | if ((cert = X509_new()) == NULL) | ||
| 471 | errx(1, "failed to malloc X509"); | ||
| 472 | |||
| 473 | if (vt->common_name_len != 0) { | ||
| 474 | if ((name = X509_NAME_new()) == NULL) | ||
| 475 | errx(1, "failed to malloc X509_NAME"); | ||
| 476 | if (X509_NAME_add_entry_by_NID(name, NID_commonName, | ||
| 477 | MBSTRING_ASC, (unsigned char *)vt->common_name, | ||
| 478 | vt->common_name_len, -1, 0) == 0) | ||
| 479 | errx(1, "failed to add name entry"); | ||
| 480 | if (X509_set_subject_name(cert, name) == 0) | ||
| 481 | errx(1, "failed to set subject name"); | ||
| 482 | X509_NAME_free(name); | ||
| 483 | } | ||
| 484 | |||
| 485 | if ((tls = tls_client()) == NULL) | ||
| 486 | errx(1, "failed to malloc tls_client"); | ||
| 487 | |||
| 488 | cert_add_alt_names(cert, vt); | ||
| 489 | |||
| 490 | match = 1; | ||
| 491 | |||
| 492 | if (tls_check_name(tls, cert, vt->name, &match) != vt->want_return) { | ||
| 493 | fprintf(stderr, "FAIL: test %i failed for check name '%s': " | ||
| 494 | "%s\n", test_no, vt->name, tls_error(tls)); | ||
| 495 | goto done; | ||
| 496 | } | ||
| 497 | if (match != vt->want_match) { | ||
| 498 | fprintf(stderr, "FAIL: test %i failed to match name '%s'\n", | ||
| 499 | test_no, vt->name); | ||
| 500 | goto done; | ||
| 501 | } | ||
| 502 | |||
| 503 | failed = 0; | ||
| 504 | |||
| 505 | done: | ||
| 506 | X509_free(cert); | ||
| 507 | tls_free(tls); | ||
| 508 | |||
| 509 | return (failed); | ||
| 510 | } | ||
| 511 | |||
| 512 | int | ||
| 513 | main(int argc, char **argv) | ||
| 514 | { | ||
| 515 | int failed = 0; | ||
| 516 | size_t i; | ||
| 517 | |||
| 518 | tls_init(); | ||
| 519 | |||
| 520 | for (i = 0; i < N_VERIFY_TESTS; i++) | ||
| 521 | failed += do_verify_test(i, &verify_tests[i]); | ||
| 522 | |||
| 523 | return (failed); | ||
| 524 | } | ||
