summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/rc2
diff options
context:
space:
mode:
authormiod <>2014-04-15 18:01:18 +0000
committermiod <>2014-04-15 18:01:18 +0000
commitf385533fd495dad9242f2eded4a9017f658ee678 (patch)
tree861cdfe8fca12990e76c301d0853c2ab45705858 /src/regress/lib/libcrypto/rc2
parentfea4fc3d16f04ff054803f9276895492961ab5e2 (diff)
downloadopenbsd-f385533fd495dad9242f2eded4a9017f658ee678.tar.gz
openbsd-f385533fd495dad9242f2eded4a9017f658ee678.tar.bz2
openbsd-f385533fd495dad9242f2eded4a9017f658ee678.zip
Import the OpenSSL libcrypto tests in a form suitable for our rergress
infrastructure. The following tests have not been imported, for their code lacks a licence: asn1, rsa, sha256, sha512, wp.
Diffstat (limited to 'src/regress/lib/libcrypto/rc2')
-rw-r--r--src/regress/lib/libcrypto/rc2/Makefile7
-rw-r--r--src/regress/lib/libcrypto/rc2/rc2test.c138
2 files changed, 145 insertions, 0 deletions
diff --git a/src/regress/lib/libcrypto/rc2/Makefile b/src/regress/lib/libcrypto/rc2/Makefile
new file mode 100644
index 0000000000..5681e0c923
--- /dev/null
+++ b/src/regress/lib/libcrypto/rc2/Makefile
@@ -0,0 +1,7 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2014/04/15 18:01:17 miod Exp $
2
3PROG= rc2test
4LDADD= -lcrypto
5DPADD= ${LIBCRYPTO}
6
7.include <bsd.regress.mk>
diff --git a/src/regress/lib/libcrypto/rc2/rc2test.c b/src/regress/lib/libcrypto/rc2/rc2test.c
new file mode 100644
index 0000000000..80e1b3035f
--- /dev/null
+++ b/src/regress/lib/libcrypto/rc2/rc2test.c
@@ -0,0 +1,138 @@
1/* crypto/rc2/rc2test.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/* 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
68static 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
79static 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
86static 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
94int 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 }