catch up with openssl's abi change. do_cipher length changed from u_int to size_t.diff -r1.2 -r1.3 src/crypto/external/bsd/openssh/dist/cipher-3des1.c
(christos)
--- src/crypto/external/bsd/openssh/dist/Attic/cipher-3des1.c 2009/06/07 22:38:46 1.2
+++ src/crypto/external/bsd/openssh/dist/Attic/cipher-3des1.c 2009/07/20 15:33:44 1.3
@@ -1,166 +1,166 @@ | @@ -1,166 +1,166 @@ | |||
1 | /* $NetBSD: cipher-3des1.c,v 1.2 2009/06/07 22:38:46 christos Exp $ */ | 1 | /* $NetBSD: cipher-3des1.c,v 1.3 2009/07/20 15:33:44 christos Exp $ */ | |
2 | /* $OpenBSD: cipher-3des1.c,v 1.6 2006/08/03 03:34:42 deraadt Exp $ */ | 2 | /* $OpenBSD: cipher-3des1.c,v 1.6 2006/08/03 03:34:42 deraadt Exp $ */ | |
3 | /* | 3 | /* | |
4 | * Copyright (c) 2003 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2003 Markus Friedl. All rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | */ | 25 | */ | |
26 | 26 | |||
27 | #include "includes.h" | 27 | #include "includes.h" | |
28 | __RCSID("$NetBSD: cipher-3des1.c,v 1.2 2009/06/07 22:38:46 christos Exp $"); | 28 | __RCSID("$NetBSD: cipher-3des1.c,v 1.3 2009/07/20 15:33:44 christos Exp $"); | |
29 | #include <sys/types.h> | 29 | #include <sys/types.h> | |
30 | 30 | |||
31 | #include <openssl/evp.h> | 31 | #include <openssl/evp.h> | |
32 | 32 | |||
33 | #include <string.h> | 33 | #include <string.h> | |
34 | 34 | |||
35 | #include "xmalloc.h" | 35 | #include "xmalloc.h" | |
36 | #include "log.h" | 36 | #include "log.h" | |
37 | 37 | |||
38 | /* | 38 | /* | |
39 | * This is used by SSH1: | 39 | * This is used by SSH1: | |
40 | * | 40 | * | |
41 | * What kind of triple DES are these 2 routines? | 41 | * What kind of triple DES are these 2 routines? | |
42 | * | 42 | * | |
43 | * Why is there a redundant initialization vector? | 43 | * Why is there a redundant initialization vector? | |
44 | * | 44 | * | |
45 | * If only iv3 was used, then, this would till effect have been | 45 | * If only iv3 was used, then, this would till effect have been | |
46 | * outer-cbc. However, there is also a private iv1 == iv2 which | 46 | * outer-cbc. However, there is also a private iv1 == iv2 which | |
47 | * perhaps makes differential analysis easier. On the other hand, the | 47 | * perhaps makes differential analysis easier. On the other hand, the | |
48 | * private iv1 probably makes the CRC-32 attack ineffective. This is a | 48 | * private iv1 probably makes the CRC-32 attack ineffective. This is a | |
49 | * result of that there is no longer any known iv1 to use when | 49 | * result of that there is no longer any known iv1 to use when | |
50 | * choosing the X block. | 50 | * choosing the X block. | |
51 | */ | 51 | */ | |
52 | struct ssh1_3des_ctx | 52 | struct ssh1_3des_ctx | |
53 | { | 53 | { | |
54 | EVP_CIPHER_CTX k1, k2, k3; | 54 | EVP_CIPHER_CTX k1, k2, k3; | |
55 | }; | 55 | }; | |
56 | 56 | |||
57 | const EVP_CIPHER * evp_ssh1_3des(void); | 57 | const EVP_CIPHER * evp_ssh1_3des(void); | |
58 | void ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int); | 58 | void ssh1_3des_iv(EVP_CIPHER_CTX *, int, u_char *, int); | |
59 | 59 | |||
60 | static int | 60 | static int | |
61 | ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | 61 | ssh1_3des_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | |
62 | int enc) | 62 | int enc) | |
63 | { | 63 | { | |
64 | struct ssh1_3des_ctx *c; | 64 | struct ssh1_3des_ctx *c; | |
65 | u_char *k1, *k2, *k3; | 65 | u_char *k1, *k2, *k3; | |
66 | 66 | |||
67 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | 67 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | |
68 | c = xmalloc(sizeof(*c)); | 68 | c = xmalloc(sizeof(*c)); | |
69 | EVP_CIPHER_CTX_set_app_data(ctx, c); | 69 | EVP_CIPHER_CTX_set_app_data(ctx, c); | |
70 | } | 70 | } | |
71 | if (key == NULL) | 71 | if (key == NULL) | |
72 | return (1); | 72 | return (1); | |
73 | if (enc == -1) | 73 | if (enc == -1) | |
74 | enc = ctx->encrypt; | 74 | enc = ctx->encrypt; | |
75 | k1 = k2 = k3 = (u_char *) key; | 75 | k1 = k2 = k3 = (u_char *) key; | |
76 | k2 += 8; | 76 | k2 += 8; | |
77 | if (EVP_CIPHER_CTX_key_length(ctx) >= 16+8) { | 77 | if (EVP_CIPHER_CTX_key_length(ctx) >= 16+8) { | |
78 | if (enc) | 78 | if (enc) | |
79 | k3 += 16; | 79 | k3 += 16; | |
80 | else | 80 | else | |
81 | k1 += 16; | 81 | k1 += 16; | |
82 | } | 82 | } | |
83 | EVP_CIPHER_CTX_init(&c->k1); | 83 | EVP_CIPHER_CTX_init(&c->k1); | |
84 | EVP_CIPHER_CTX_init(&c->k2); | 84 | EVP_CIPHER_CTX_init(&c->k2); | |
85 | EVP_CIPHER_CTX_init(&c->k3); | 85 | EVP_CIPHER_CTX_init(&c->k3); | |
86 | if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 || | 86 | if (EVP_CipherInit(&c->k1, EVP_des_cbc(), k1, NULL, enc) == 0 || | |
87 | EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 || | 87 | EVP_CipherInit(&c->k2, EVP_des_cbc(), k2, NULL, !enc) == 0 || | |
88 | EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) { | 88 | EVP_CipherInit(&c->k3, EVP_des_cbc(), k3, NULL, enc) == 0) { | |
89 | memset(c, 0, sizeof(*c)); | 89 | memset(c, 0, sizeof(*c)); | |
90 | xfree(c); | 90 | xfree(c); | |
91 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | 91 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | |
92 | return (0); | 92 | return (0); | |
93 | } | 93 | } | |
94 | return (1); | 94 | return (1); | |
95 | } | 95 | } | |
96 | 96 | |||
97 | static int | 97 | static int | |
98 | ssh1_3des_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, u_int len) | 98 | ssh1_3des_cbc(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, size_t len) | |
99 | { | 99 | { | |
100 | struct ssh1_3des_ctx *c; | 100 | struct ssh1_3des_ctx *c; | |
101 | 101 | |||
102 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | 102 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | |
103 | error("ssh1_3des_cbc: no context"); | 103 | error("ssh1_3des_cbc: no context"); | |
104 | return (0); | 104 | return (0); | |
105 | } | 105 | } | |
106 | if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 || | 106 | if (EVP_Cipher(&c->k1, dest, (u_char *)src, len) == 0 || | |
107 | EVP_Cipher(&c->k2, dest, dest, len) == 0 || | 107 | EVP_Cipher(&c->k2, dest, dest, len) == 0 || | |
108 | EVP_Cipher(&c->k3, dest, dest, len) == 0) | 108 | EVP_Cipher(&c->k3, dest, dest, len) == 0) | |
109 | return (0); | 109 | return (0); | |
110 | return (1); | 110 | return (1); | |
111 | } | 111 | } | |
112 | 112 | |||
113 | static int | 113 | static int | |
114 | ssh1_3des_cleanup(EVP_CIPHER_CTX *ctx) | 114 | ssh1_3des_cleanup(EVP_CIPHER_CTX *ctx) | |
115 | { | 115 | { | |
116 | struct ssh1_3des_ctx *c; | 116 | struct ssh1_3des_ctx *c; | |
117 | 117 | |||
118 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) { | 118 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) { | |
119 | EVP_CIPHER_CTX_cleanup(&c->k1); | 119 | EVP_CIPHER_CTX_cleanup(&c->k1); | |
120 | EVP_CIPHER_CTX_cleanup(&c->k2); | 120 | EVP_CIPHER_CTX_cleanup(&c->k2); | |
121 | EVP_CIPHER_CTX_cleanup(&c->k3); | 121 | EVP_CIPHER_CTX_cleanup(&c->k3); | |
122 | memset(c, 0, sizeof(*c)); | 122 | memset(c, 0, sizeof(*c)); | |
123 | xfree(c); | 123 | xfree(c); | |
124 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | 124 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | |
125 | } | 125 | } | |
126 | return (1); | 126 | return (1); | |
127 | } | 127 | } | |
128 | 128 | |||
129 | void | 129 | void | |
130 | ssh1_3des_iv(EVP_CIPHER_CTX *evp, int doset, u_char *iv, int len) | 130 | ssh1_3des_iv(EVP_CIPHER_CTX *evp, int doset, u_char *iv, int len) | |
131 | { | 131 | { | |
132 | struct ssh1_3des_ctx *c; | 132 | struct ssh1_3des_ctx *c; | |
133 | 133 | |||
134 | if (len != 24) | 134 | if (len != 24) | |
135 | fatal("%s: bad 3des iv length: %d", __func__, len); | 135 | fatal("%s: bad 3des iv length: %d", __func__, len); | |
136 | if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL) | 136 | if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL) | |
137 | fatal("%s: no 3des context", __func__); | 137 | fatal("%s: no 3des context", __func__); | |
138 | if (doset) { | 138 | if (doset) { | |
139 | debug3("%s: Installed 3DES IV", __func__); | 139 | debug3("%s: Installed 3DES IV", __func__); | |
140 | memcpy(c->k1.iv, iv, 8); | 140 | memcpy(c->k1.iv, iv, 8); | |
141 | memcpy(c->k2.iv, iv + 8, 8); | 141 | memcpy(c->k2.iv, iv + 8, 8); | |
142 | memcpy(c->k3.iv, iv + 16, 8); | 142 | memcpy(c->k3.iv, iv + 16, 8); | |
143 | } else { | 143 | } else { | |
144 | debug3("%s: Copying 3DES IV", __func__); | 144 | debug3("%s: Copying 3DES IV", __func__); | |
145 | memcpy(iv, c->k1.iv, 8); | 145 | memcpy(iv, c->k1.iv, 8); | |
146 | memcpy(iv + 8, c->k2.iv, 8); | 146 | memcpy(iv + 8, c->k2.iv, 8); | |
147 | memcpy(iv + 16, c->k3.iv, 8); | 147 | memcpy(iv + 16, c->k3.iv, 8); | |
148 | } | 148 | } | |
149 | } | 149 | } | |
150 | 150 | |||
151 | const EVP_CIPHER * | 151 | const EVP_CIPHER * | |
152 | evp_ssh1_3des(void) | 152 | evp_ssh1_3des(void) | |
153 | { | 153 | { | |
154 | static EVP_CIPHER ssh1_3des; | 154 | static EVP_CIPHER ssh1_3des; | |
155 | 155 | |||
156 | memset(&ssh1_3des, 0, sizeof(EVP_CIPHER)); | 156 | memset(&ssh1_3des, 0, sizeof(EVP_CIPHER)); | |
157 | ssh1_3des.nid = NID_undef; | 157 | ssh1_3des.nid = NID_undef; | |
158 | ssh1_3des.block_size = 8; | 158 | ssh1_3des.block_size = 8; | |
159 | ssh1_3des.iv_len = 0; | 159 | ssh1_3des.iv_len = 0; | |
160 | ssh1_3des.key_len = 16; | 160 | ssh1_3des.key_len = 16; | |
161 | ssh1_3des.init = ssh1_3des_init; | 161 | ssh1_3des.init = ssh1_3des_init; | |
162 | ssh1_3des.cleanup = ssh1_3des_cleanup; | 162 | ssh1_3des.cleanup = ssh1_3des_cleanup; | |
163 | ssh1_3des.do_cipher = ssh1_3des_cbc; | 163 | ssh1_3des.do_cipher = ssh1_3des_cbc; | |
164 | ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH; | 164 | ssh1_3des.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH; | |
165 | return (&ssh1_3des); | 165 | return (&ssh1_3des); | |
166 | } | 166 | } |
--- src/crypto/external/bsd/openssh/dist/Attic/cipher-bf1.c 2009/06/07 22:38:46 1.2
+++ src/crypto/external/bsd/openssh/dist/Attic/cipher-bf1.c 2009/07/20 15:33:44 1.3
@@ -1,87 +1,87 @@ | @@ -1,87 +1,87 @@ | |||
1 | /* $NetBSD: cipher-bf1.c,v 1.2 2009/06/07 22:38:46 christos Exp $ */ | 1 | /* $NetBSD: cipher-bf1.c,v 1.3 2009/07/20 15:33:44 christos Exp $ */ | |
2 | /* $OpenBSD: cipher-bf1.c,v 1.5 2006/08/03 03:34:42 deraadt Exp $ */ | 2 | /* $OpenBSD: cipher-bf1.c,v 1.5 2006/08/03 03:34:42 deraadt Exp $ */ | |
3 | /* | 3 | /* | |
4 | * Copyright (c) 2003 Markus Friedl. All rights reserved. | 4 | * Copyright (c) 2003 Markus Friedl. All rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 | */ | 25 | */ | |
26 | 26 | |||
27 | #include "includes.h" | 27 | #include "includes.h" | |
28 | __RCSID("$NetBSD: cipher-bf1.c,v 1.2 2009/06/07 22:38:46 christos Exp $"); | 28 | __RCSID("$NetBSD: cipher-bf1.c,v 1.3 2009/07/20 15:33:44 christos Exp $"); | |
29 | #include <sys/types.h> | 29 | #include <sys/types.h> | |
30 | 30 | |||
31 | #include <openssl/evp.h> | 31 | #include <openssl/evp.h> | |
32 | 32 | |||
33 | #include <string.h> | 33 | #include <string.h> | |
34 | 34 | |||
35 | #include "xmalloc.h" | 35 | #include "xmalloc.h" | |
36 | #include "log.h" | 36 | #include "log.h" | |
37 | /* | 37 | /* | |
38 | * SSH1 uses a variation on Blowfish, all bytes must be swapped before | 38 | * SSH1 uses a variation on Blowfish, all bytes must be swapped before | |
39 | * and after encryption/decryption. Thus the swap_bytes stuff (yuk). | 39 | * and after encryption/decryption. Thus the swap_bytes stuff (yuk). | |
40 | */ | 40 | */ | |
41 | 41 | |||
42 | const EVP_CIPHER * evp_ssh1_bf(void); | 42 | const EVP_CIPHER * evp_ssh1_bf(void); | |
43 | 43 | |||
44 | static void | 44 | static void | |
45 | swap_bytes(const u_char *src, u_char *dst, int n) | 45 | swap_bytes(const u_char *src, u_char *dst, int n) | |
46 | { | 46 | { | |
47 | u_char c[4]; | 47 | u_char c[4]; | |
48 | 48 | |||
49 | /* Process 4 bytes every lap. */ | 49 | /* Process 4 bytes every lap. */ | |
50 | for (n = n / 4; n > 0; n--) { | 50 | for (n = n / 4; n > 0; n--) { | |
51 | c[3] = *src++; | 51 | c[3] = *src++; | |
52 | c[2] = *src++; | 52 | c[2] = *src++; | |
53 | c[1] = *src++; | 53 | c[1] = *src++; | |
54 | c[0] = *src++; | 54 | c[0] = *src++; | |
55 | 55 | |||
56 | *dst++ = c[0]; | 56 | *dst++ = c[0]; | |
57 | *dst++ = c[1]; | 57 | *dst++ = c[1]; | |
58 | *dst++ = c[2]; | 58 | *dst++ = c[2]; | |
59 | *dst++ = c[3]; | 59 | *dst++ = c[3]; | |
60 | } | 60 | } | |
61 | } | 61 | } | |
62 | 62 | |||
63 | static int (*orig_bf)(EVP_CIPHER_CTX *, u_char *, const u_char *, u_int) = NULL; | 63 | static int (*orig_bf)(EVP_CIPHER_CTX *, u_char *, const u_char *, size_t) = NULL; | |
64 | 64 | |||
65 | static int | 65 | static int | |
66 | bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, u_int len) | 66 | bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, size_t len) | |
67 | { | 67 | { | |
68 | int ret; | 68 | int ret; | |
69 | 69 | |||
70 | swap_bytes(in, out, len); | 70 | swap_bytes(in, out, len); | |
71 | ret = (*orig_bf)(ctx, out, out, len); | 71 | ret = (*orig_bf)(ctx, out, out, len); | |
72 | swap_bytes(out, out, len); | 72 | swap_bytes(out, out, len); | |
73 | return (ret); | 73 | return (ret); | |
74 | } | 74 | } | |
75 | 75 | |||
76 | const EVP_CIPHER * | 76 | const EVP_CIPHER * | |
77 | evp_ssh1_bf(void) | 77 | evp_ssh1_bf(void) | |
78 | { | 78 | { | |
79 | static EVP_CIPHER ssh1_bf; | 79 | static EVP_CIPHER ssh1_bf; | |
80 | 80 | |||
81 | memcpy(&ssh1_bf, EVP_bf_cbc(), sizeof(EVP_CIPHER)); | 81 | memcpy(&ssh1_bf, EVP_bf_cbc(), sizeof(EVP_CIPHER)); | |
82 | orig_bf = ssh1_bf.do_cipher; | 82 | orig_bf = ssh1_bf.do_cipher; | |
83 | ssh1_bf.nid = NID_undef; | 83 | ssh1_bf.nid = NID_undef; | |
84 | ssh1_bf.do_cipher = bf_ssh1_cipher; | 84 | ssh1_bf.do_cipher = bf_ssh1_cipher; | |
85 | ssh1_bf.key_len = 32; | 85 | ssh1_bf.key_len = 32; | |
86 | return (&ssh1_bf); | 86 | return (&ssh1_bf); | |
87 | } | 87 | } |
--- src/crypto/external/bsd/openssh/dist/Attic/cipher-ctr.c 2009/06/07 22:38:46 1.2
+++ src/crypto/external/bsd/openssh/dist/Attic/cipher-ctr.c 2009/07/20 15:33:44 1.3
@@ -1,139 +1,139 @@ | @@ -1,139 +1,139 @@ | |||
1 | /* $NetBSD: cipher-ctr.c,v 1.2 2009/06/07 22:38:46 christos Exp $ */ | 1 | /* $NetBSD: cipher-ctr.c,v 1.3 2009/07/20 15:33:44 christos Exp $ */ | |
2 | /* $OpenBSD: cipher-ctr.c,v 1.10 2006/08/03 03:34:42 deraadt Exp $ */ | 2 | /* $OpenBSD: cipher-ctr.c,v 1.10 2006/08/03 03:34:42 deraadt Exp $ */ | |
3 | /* | 3 | /* | |
4 | * Copyright (c) 2003 Markus Friedl <markus@openbsd.org> | 4 | * Copyright (c) 2003 Markus Friedl <markus@openbsd.org> | |
5 | * | 5 | * | |
6 | * Permission to use, copy, modify, and distribute this software for any | 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 | 7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | 8 | * copyright notice and this permission notice appear in all copies. | |
9 | * | 9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 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 | 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 | */ | 17 | */ | |
18 | 18 | |||
19 | #include "includes.h" | 19 | #include "includes.h" | |
20 | __RCSID("$NetBSD: cipher-ctr.c,v 1.2 2009/06/07 22:38:46 christos Exp $"); | 20 | __RCSID("$NetBSD: cipher-ctr.c,v 1.3 2009/07/20 15:33:44 christos Exp $"); | |
21 | #include <sys/types.h> | 21 | #include <sys/types.h> | |
22 | 22 | |||
23 | #include <string.h> | 23 | #include <string.h> | |
24 | 24 | |||
25 | #include <openssl/evp.h> | 25 | #include <openssl/evp.h> | |
26 | #include <openssl/aes.h> | 26 | #include <openssl/aes.h> | |
27 | 27 | |||
28 | #include "xmalloc.h" | 28 | #include "xmalloc.h" | |
29 | #include "log.h" | 29 | #include "log.h" | |
30 | 30 | |||
31 | const EVP_CIPHER *evp_aes_128_ctr(void); | 31 | const EVP_CIPHER *evp_aes_128_ctr(void); | |
32 | void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); | 32 | void ssh_aes_ctr_iv(EVP_CIPHER_CTX *, int, u_char *, size_t); | |
33 | 33 | |||
34 | struct ssh_aes_ctr_ctx | 34 | struct ssh_aes_ctr_ctx | |
35 | { | 35 | { | |
36 | AES_KEY aes_ctx; | 36 | AES_KEY aes_ctx; | |
37 | u_char aes_counter[AES_BLOCK_SIZE]; | 37 | u_char aes_counter[AES_BLOCK_SIZE]; | |
38 | }; | 38 | }; | |
39 | 39 | |||
40 | /* | 40 | /* | |
41 | * increment counter 'ctr', | 41 | * increment counter 'ctr', | |
42 | * the counter is of size 'len' bytes and stored in network-byte-order. | 42 | * the counter is of size 'len' bytes and stored in network-byte-order. | |
43 | * (LSB at ctr[len-1], MSB at ctr[0]) | 43 | * (LSB at ctr[len-1], MSB at ctr[0]) | |
44 | */ | 44 | */ | |
45 | static void | 45 | static void | |
46 | ssh_ctr_inc(u_char *ctr, u_int len) | 46 | ssh_ctr_inc(u_char *ctr, size_t len) | |
47 | { | 47 | { | |
48 | int i; | 48 | int i; | |
49 | 49 | |||
50 | for (i = len - 1; i >= 0; i--) | 50 | for (i = len - 1; i >= 0; i--) | |
51 | if (++ctr[i]) /* continue on overflow */ | 51 | if (++ctr[i]) /* continue on overflow */ | |
52 | return; | 52 | return; | |
53 | } | 53 | } | |
54 | 54 | |||
55 | static int | 55 | static int | |
56 | ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, | 56 | ssh_aes_ctr(EVP_CIPHER_CTX *ctx, u_char *dest, const u_char *src, | |
57 | u_int len) | 57 | size_t len) | |
58 | { | 58 | { | |
59 | struct ssh_aes_ctr_ctx *c; | 59 | struct ssh_aes_ctr_ctx *c; | |
60 | u_int n = 0; | 60 | size_t n = 0; | |
61 | u_char buf[AES_BLOCK_SIZE]; | 61 | u_char buf[AES_BLOCK_SIZE]; | |
62 | 62 | |||
63 | if (len == 0) | 63 | if (len == 0) | |
64 | return (1); | 64 | return (1); | |
65 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) | 65 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) | |
66 | return (0); | 66 | return (0); | |
67 | 67 | |||
68 | while ((len--) > 0) { | 68 | while ((len--) > 0) { | |
69 | if (n == 0) { | 69 | if (n == 0) { | |
70 | AES_encrypt(c->aes_counter, buf, &c->aes_ctx); | 70 | AES_encrypt(c->aes_counter, buf, &c->aes_ctx); | |
71 | ssh_ctr_inc(c->aes_counter, AES_BLOCK_SIZE); | 71 | ssh_ctr_inc(c->aes_counter, AES_BLOCK_SIZE); | |
72 | } | 72 | } | |
73 | *(dest++) = *(src++) ^ buf[n]; | 73 | *(dest++) = *(src++) ^ buf[n]; | |
74 | n = (n + 1) % AES_BLOCK_SIZE; | 74 | n = (n + 1) % AES_BLOCK_SIZE; | |
75 | } | 75 | } | |
76 | return (1); | 76 | return (1); | |
77 | } | 77 | } | |
78 | 78 | |||
79 | static int | 79 | static int | |
80 | ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | 80 | ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv, | |
81 | int enc) | 81 | int enc) | |
82 | { | 82 | { | |
83 | struct ssh_aes_ctr_ctx *c; | 83 | struct ssh_aes_ctr_ctx *c; | |
84 | 84 | |||
85 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | 85 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) { | |
86 | c = xmalloc(sizeof(*c)); | 86 | c = xmalloc(sizeof(*c)); | |
87 | EVP_CIPHER_CTX_set_app_data(ctx, c); | 87 | EVP_CIPHER_CTX_set_app_data(ctx, c); | |
88 | } | 88 | } | |
89 | if (key != NULL) | 89 | if (key != NULL) | |
90 | AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, | 90 | AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8, | |
91 | &c->aes_ctx); | 91 | &c->aes_ctx); | |
92 | if (iv != NULL) | 92 | if (iv != NULL) | |
93 | memcpy(c->aes_counter, iv, AES_BLOCK_SIZE); | 93 | memcpy(c->aes_counter, iv, AES_BLOCK_SIZE); | |
94 | return (1); | 94 | return (1); | |
95 | } | 95 | } | |
96 | 96 | |||
97 | static int | 97 | static int | |
98 | ssh_aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) | 98 | ssh_aes_ctr_cleanup(EVP_CIPHER_CTX *ctx) | |
99 | { | 99 | { | |
100 | struct ssh_aes_ctr_ctx *c; | 100 | struct ssh_aes_ctr_ctx *c; | |
101 | 101 | |||
102 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) { | 102 | if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) != NULL) { | |
103 | memset(c, 0, sizeof(*c)); | 103 | memset(c, 0, sizeof(*c)); | |
104 | xfree(c); | 104 | xfree(c); | |
105 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | 105 | EVP_CIPHER_CTX_set_app_data(ctx, NULL); | |
106 | } | 106 | } | |
107 | return (1); | 107 | return (1); | |
108 | } | 108 | } | |
109 | 109 | |||
110 | void | 110 | void | |
111 | ssh_aes_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, u_int len) | 111 | ssh_aes_ctr_iv(EVP_CIPHER_CTX *evp, int doset, u_char * iv, size_t len) | |
112 | { | 112 | { | |
113 | struct ssh_aes_ctr_ctx *c; | 113 | struct ssh_aes_ctr_ctx *c; | |
114 | 114 | |||
115 | if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL) | 115 | if ((c = EVP_CIPHER_CTX_get_app_data(evp)) == NULL) | |
116 | fatal("ssh_aes_ctr_iv: no context"); | 116 | fatal("ssh_aes_ctr_iv: no context"); | |
117 | if (doset) | 117 | if (doset) | |
118 | memcpy(c->aes_counter, iv, len); | 118 | memcpy(c->aes_counter, iv, len); | |
119 | else | 119 | else | |
120 | memcpy(iv, c->aes_counter, len); | 120 | memcpy(iv, c->aes_counter, len); | |
121 | } | 121 | } | |
122 | 122 | |||
123 | const EVP_CIPHER * | 123 | const EVP_CIPHER * | |
124 | evp_aes_128_ctr(void) | 124 | evp_aes_128_ctr(void) | |
125 | { | 125 | { | |
126 | static EVP_CIPHER aes_ctr; | 126 | static EVP_CIPHER aes_ctr; | |
127 | 127 | |||
128 | memset(&aes_ctr, 0, sizeof(EVP_CIPHER)); | 128 | memset(&aes_ctr, 0, sizeof(EVP_CIPHER)); | |
129 | aes_ctr.nid = NID_undef; | 129 | aes_ctr.nid = NID_undef; | |
130 | aes_ctr.block_size = AES_BLOCK_SIZE; | 130 | aes_ctr.block_size = AES_BLOCK_SIZE; | |
131 | aes_ctr.iv_len = AES_BLOCK_SIZE; | 131 | aes_ctr.iv_len = AES_BLOCK_SIZE; | |
132 | aes_ctr.key_len = 16; | 132 | aes_ctr.key_len = 16; | |
133 | aes_ctr.init = ssh_aes_ctr_init; | 133 | aes_ctr.init = ssh_aes_ctr_init; | |
134 | aes_ctr.cleanup = ssh_aes_ctr_cleanup; | 134 | aes_ctr.cleanup = ssh_aes_ctr_cleanup; | |
135 | aes_ctr.do_cipher = ssh_aes_ctr; | 135 | aes_ctr.do_cipher = ssh_aes_ctr; | |
136 | aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | | 136 | aes_ctr.flags = EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH | | |
137 | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV; | 137 | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CUSTOM_IV; | |
138 | return (&aes_ctr); | 138 | return (&aes_ctr); | |
139 | } | 139 | } |