No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / external / bsd / openssh / dist / cipher-bf1.c
blobc9a293e8b60f61fda7df8405432b2d42a6cbafd5
1 /* $NetBSD: cipher-bf1.c,v 1.2 2009/06/07 22:38:46 christos Exp $ */
2 /* $OpenBSD: cipher-bf1.c,v 1.5 2006/08/03 03:34:42 deraadt Exp $ */
3 /*
4 * Copyright (c) 2003 Markus Friedl. All rights reserved.
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.
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
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "includes.h"
28 __RCSID("$NetBSD: cipher-bf1.c,v 1.2 2009/06/07 22:38:46 christos Exp $");
29 #include <sys/types.h>
31 #include <openssl/evp.h>
33 #include <string.h>
35 #include "xmalloc.h"
36 #include "log.h"
38 * SSH1 uses a variation on Blowfish, all bytes must be swapped before
39 * and after encryption/decryption. Thus the swap_bytes stuff (yuk).
42 const EVP_CIPHER * evp_ssh1_bf(void);
44 static void
45 swap_bytes(const u_char *src, u_char *dst, int n)
47 u_char c[4];
49 /* Process 4 bytes every lap. */
50 for (n = n / 4; n > 0; n--) {
51 c[3] = *src++;
52 c[2] = *src++;
53 c[1] = *src++;
54 c[0] = *src++;
56 *dst++ = c[0];
57 *dst++ = c[1];
58 *dst++ = c[2];
59 *dst++ = c[3];
63 static int (*orig_bf)(EVP_CIPHER_CTX *, u_char *, const u_char *, size_t) = NULL;
65 static int
66 bf_ssh1_cipher(EVP_CIPHER_CTX *ctx, u_char *out, const u_char *in, size_t len)
68 int ret;
70 swap_bytes(in, out, len);
71 ret = (*orig_bf)(ctx, out, out, len);
72 swap_bytes(out, out, len);
73 return (ret);
76 const EVP_CIPHER *
77 evp_ssh1_bf(void)
79 static EVP_CIPHER ssh1_bf;
81 memcpy(&ssh1_bf, EVP_bf_cbc(), sizeof(EVP_CIPHER));
82 orig_bf = ssh1_bf.do_cipher;
83 ssh1_bf.nid = NID_undef;
84 ssh1_bf.do_cipher = bf_ssh1_cipher;
85 ssh1_bf.key_len = 32;
86 return (&ssh1_bf);