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 $ */
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
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.
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>
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);
45 swap_bytes(const u_char
*src
, u_char
*dst
, int n
)
49 /* Process 4 bytes every lap. */
50 for (n
= n
/ 4; n
> 0; n
--) {
63 static int (*orig_bf
)(EVP_CIPHER_CTX
*, u_char
*, const u_char
*, size_t) = NULL
;
66 bf_ssh1_cipher(EVP_CIPHER_CTX
*ctx
, u_char
*out
, const u_char
*in
, size_t len
)
70 swap_bytes(in
, out
, len
);
71 ret
= (*orig_bf
)(ctx
, out
, out
, len
);
72 swap_bytes(out
, out
, len
);
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
;