des-compat.h 2.67 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/* des-compat.h
 *
 * The des block cipher, libdes/openssl-style interface.
 */

/* nettle, low-level cryptographics library
 *
 * Copyright (C) 2001 Niels Möller
 *  
 * The nettle library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * The nettle library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */

#ifndef NETTLE_DES_COMPAT_H_INCLUDED
#define NETTLE_DES_COMPAT_H_INCLUDED

/* According to Assar, des_set_key, des_set_key_odd_parity,
 * des_is_weak_key, plus the encryption functions (des_*_encrypt and
 * des_cbc_cksum) would be a pretty useful subset. */

Niels Möller's avatar
Niels Möller committed
33 34 35
/* NOTE: This is quite experimental, and not all functions are
 * implemented. Contributions, in particular test cases are welcome. */

36 37
#include "des.h"

38
/* Some names collides with nettle, so we'll need some ugly symbol
39 40
 * munging */

Niels Möller's avatar
Niels Möller committed
41
#define des_set_key des_key_sched
42 43 44

enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };

45 46 47 48
void des_ecb3_encrypt(const uint8_t *src, uint8_t *dst,
		      struct des_ctx *k1, struct des_ctx *k2,
		      struct des_ctx *k3, int enc);

Niels Möller's avatar
Niels Möller committed
49 50 51 52 53
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
 * latter half of the output block, in some byte order. For now, lets
 * just hope nobody uses thet feature, and return void instead. */
void
des_cbc_cksum(const uint8_t *src, uint8_t *dst,
54 55 56 57 58 59 60 61 62 63
	      long length, struct des_ctx *ctx,
	      uint8_t *iv);

void
des_cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
		struct des_ctx *ctx, uint8_t *iv,
		int enc);

void
des_3cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
64
		 struct des_ctx * k1, struct des_ctx *k2, 
65 66 67 68 69
		 uint8_t *iv1, uint8_t *iv2,
		 int enc);

void
des_ecb_encrypt(const uint8_t *src, uint8_t *dst, long length,
70
		struct des_ctx *ctx, int enc);
71 72 73 74 75 76 77 78 79 80 81 82 83
void
des_ede3_cbc_encrypt(const uint8_t *src, uint8_t *dst, long length,
		     struct des_ctx * k1,struct des_ctx *k2, struct des_ctx *k3,
		     uint8_t *iv,
		     int enc);

int
des_set_odd_parity(uint8_t *key);

int
des_key_sched(const uint8_t *key, struct des_ctx *ctx);

int
84
des_is_weak_key(const uint8_t *key);
85

Niels Möller's avatar
Niels Möller committed
86
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */