Annotation of src/usr.bin/ssh/cipher-bf1.c, Revision 1.7
1.7 ! markus 1: /* $OpenBSD: cipher-bf1.c,v 1.6 2010/10/01 23:05:32 djm Exp $ */
1.1 markus 2: /*
3: * Copyright (c) 2003 Markus Friedl. All rights reserved.
4: *
1.7 ! markus 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.
1.1 markus 8: *
9: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
10: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
11: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
12: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
13: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
14: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
18: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19: */
20:
1.5 deraadt 21: #include <sys/types.h>
1.7 ! markus 22: #include <string.h>
1.1 markus 23: #include <openssl/evp.h>
1.4 stevesk 24:
1.1 markus 25: /*
26: * SSH1 uses a variation on Blowfish, all bytes must be swapped before
27: * and after encryption/decryption. Thus the swap_bytes stuff (yuk).
28: */
29:
30: const EVP_CIPHER * evp_ssh1_bf(void);
31:
32: static void
33: swap_bytes(const u_char *src, u_char *dst, int n)
34: {
35: u_char c[4];
36:
37: /* Process 4 bytes every lap. */
38: for (n = n / 4; n > 0; n--) {
39: c[3] = *src++;
40: c[2] = *src++;
41: c[1] = *src++;
42: c[0] = *src++;
43:
44: *dst++ = c[0];
45: *dst++ = c[1];
46: *dst++ = c[2];
47: *dst++ = c[3];
48: }
49: }
50:
1.6 djm 51: static int (*orig_bf)(EVP_CIPHER_CTX *, u_char *,
52: const u_char *, size_t) = NULL;
1.1 markus 53:
54: static int
1.6 djm 55: bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, size_t len)
1.1 markus 56: {
57: int ret;
58:
59: swap_bytes(in, out, len);
60: ret = (*orig_bf)(ctx, out, out, len);
61: swap_bytes(out, out, len);
62: return (ret);
63: }
64:
65: const EVP_CIPHER *
66: evp_ssh1_bf(void)
67: {
68: static EVP_CIPHER ssh1_bf;
69:
70: memcpy(&ssh1_bf, EVP_bf_cbc(), sizeof(EVP_CIPHER));
71: orig_bf = ssh1_bf.do_cipher;
72: ssh1_bf.nid = NID_undef;
73: ssh1_bf.do_cipher = bf_ssh1_cipher;
74: ssh1_bf.key_len = 32;
75: return (&ssh1_bf);
76: }