Blame include/libssh/blf.h

Packit 6c0a39
/* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */
Packit 6c0a39
/*
Packit 6c0a39
 * Blowfish - a fast block cipher designed by Bruce Schneier
Packit 6c0a39
 *
Packit 6c0a39
 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
Packit 6c0a39
 * All rights reserved.
Packit 6c0a39
 *
Packit 6c0a39
 * Redistribution and use in source and binary forms, with or without
Packit 6c0a39
 * modification, are permitted provided that the following conditions
Packit 6c0a39
 * are met:
Packit 6c0a39
 * 1. Redistributions of source code must retain the above copyright
Packit 6c0a39
 *    notice, this list of conditions and the following disclaimer.
Packit 6c0a39
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 6c0a39
 *    notice, this list of conditions and the following disclaimer in the
Packit 6c0a39
 *    documentation and/or other materials provided with the distribution.
Packit 6c0a39
 * 3. All advertising materials mentioning features or use of this software
Packit 6c0a39
 *    must display the following acknowledgement:
Packit 6c0a39
 *      This product includes software developed by Niels Provos.
Packit 6c0a39
 * 4. The name of the author may not be used to endorse or promote products
Packit 6c0a39
 *    derived from this software without specific prior written permission.
Packit 6c0a39
 *
Packit 6c0a39
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit 6c0a39
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit 6c0a39
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit 6c0a39
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 6c0a39
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit 6c0a39
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 6c0a39
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 6c0a39
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 6c0a39
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit 6c0a39
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
#ifndef _BLF_H_
Packit 6c0a39
#define _BLF_H_
Packit 6c0a39
Packit 6c0a39
//#include "includes.h"
Packit 6c0a39
Packit 6c0a39
#if !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H)
Packit 6c0a39
Packit 6c0a39
/* Schneier specifies a maximum key length of 56 bytes.
Packit 6c0a39
 * This ensures that every key bit affects every cipher
Packit 6c0a39
 * bit.  However, the subkeys can hold up to 72 bytes.
Packit 6c0a39
 * Warning: For normal blowfish encryption only 56 bytes
Packit 6c0a39
 * of the key affect all cipherbits.
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
#define BLF_N	16			/* Number of Subkeys */
Packit 6c0a39
#define BLF_MAXKEYLEN ((BLF_N-2)*4)	/* 448 bits */
Packit 6c0a39
#define BLF_MAXUTILIZED ((BLF_N+2)*4)	/* 576 bits */
Packit 6c0a39
Packit 6c0a39
/* Blowfish context */
Packit 6c0a39
typedef struct BlowfishContext {
Packit 6c0a39
	uint32_t S[4][256];	/* S-Boxes */
Packit 6c0a39
	uint32_t P[BLF_N + 2];	/* Subkeys */
Packit 6c0a39
} ssh_blf_ctx;
Packit 6c0a39
Packit 6c0a39
/* Raw access to customized Blowfish
Packit 6c0a39
 *	blf_key is just:
Packit 6c0a39
 *	Blowfish_initstate( state )
Packit 6c0a39
 *	Blowfish_expand0state( state, key, keylen )
Packit 6c0a39
 */
Packit 6c0a39
Packit 6c0a39
void Blowfish_encipher(ssh_blf_ctx *, uint32_t *, uint32_t *);
Packit 6c0a39
void Blowfish_decipher(ssh_blf_ctx *, uint32_t *, uint32_t *);
Packit 6c0a39
void Blowfish_initstate(ssh_blf_ctx *);
Packit 6c0a39
void Blowfish_expand0state(ssh_blf_ctx *, const uint8_t *, uint16_t);
Packit 6c0a39
void Blowfish_expandstate
Packit 6c0a39
(ssh_blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
Packit 6c0a39
Packit 6c0a39
/* Standard Blowfish */
Packit 6c0a39
Packit 6c0a39
void ssh_blf_key(ssh_blf_ctx *, const uint8_t *, uint16_t);
Packit 6c0a39
void ssh_blf_enc(ssh_blf_ctx *, uint32_t *, uint16_t);
Packit 6c0a39
void ssh_blf_dec(ssh_blf_ctx *, uint32_t *, uint16_t);
Packit 6c0a39
Packit 6c0a39
void ssh_blf_ecb_encrypt(ssh_blf_ctx *, uint8_t *, uint32_t);
Packit 6c0a39
void ssh_blf_ecb_decrypt(ssh_blf_ctx *, uint8_t *, uint32_t);
Packit 6c0a39
Packit 6c0a39
void ssh_blf_cbc_encrypt(ssh_blf_ctx *, uint8_t *, uint8_t *, uint32_t);
Packit 6c0a39
void ssh_blf_cbc_decrypt(ssh_blf_ctx *, uint8_t *, uint8_t *, uint32_t);
Packit 6c0a39
Packit 6c0a39
/* Converts uint8_t to uint32_t */
Packit 6c0a39
uint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
Packit 6c0a39
Packit 6c0a39
#endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */
Packit 6c0a39
#endif /* _BLF_H */