Commit 7203ca09 authored by Niels Möller's avatar Niels Möller

Delete old libdes/openssl compatibility interface.

parent a1f6f7c9
2019-05-12 Niels Möller <nisse@lysator.liu.se>
Delete old libdes/openssl compatibility interface.
* des-compat.c: Delete file.
* des-compat.h: Delete file.
* testsuite/des-compat-test.c: Delete file.
* nettle.texinfo (Compatibility functions): Delete mention in documentation.
2019-05-11 Niels Möller <nisse@lysator.liu.se>
* NEWS: More updates for Nettle-3.5.
......
......@@ -93,7 +93,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
chacha-crypt.c chacha-core-internal.c \
chacha-poly1305.c chacha-poly1305-meta.c \
chacha-set-key.c chacha-set-nonce.c \
ctr.c ctr16.c des.c des3.c des-compat.c \
ctr.c ctr16.c des.c des3.c \
eax.c eax-aes128.c eax-aes128-meta.c \
gcm.c gcm-aes.c \
gcm-aes128.c gcm-aes128-meta.c \
......@@ -193,7 +193,7 @@ OPT_SOURCES = fat-x86_64.c fat-arm.c mini-gmp.c
HEADERS = aes.h arcfour.h arctwo.h asn1.h blowfish.h \
base16.h base64.h bignum.h buffer.h camellia.h cast128.h \
cbc.h ccm.h cfb.h chacha.h chacha-poly1305.h ctr.h \
curve25519.h des.h des-compat.h dsa.h dsa-compat.h eax.h \
curve25519.h des.h dsa.h dsa-compat.h eax.h \
ecc-curve.h ecc.h ecdsa.h eddsa.h \
gcm.h gosthash94.h hmac.h \
knuth-lfib.h hkdf.h \
......
/* des-compat.c
The des block cipher, old libdes/openssl-style interface.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle 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
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "des-compat.h"
#include "cbc.h"
#include "macros.h"
#include "memxor.h"
struct des_compat_des3 { const struct des_ctx *keys[3]; };
static void
des_compat_des3_encrypt(struct des_compat_des3 *ctx,
size_t length, uint8_t *dst, const uint8_t *src)
{
nettle_des_encrypt(ctx->keys[0], length, dst, src);
nettle_des_decrypt(ctx->keys[1], length, dst, dst);
nettle_des_encrypt(ctx->keys[2], length, dst, dst);
}
static void
des_compat_des3_decrypt(struct des_compat_des3 *ctx,
size_t length, uint8_t *dst, const uint8_t *src)
{
nettle_des_decrypt(ctx->keys[2], length, dst, src);
nettle_des_encrypt(ctx->keys[1], length, dst, dst);
nettle_des_decrypt(ctx->keys[0], length, dst, dst);
}
void
des_ecb3_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3, int enc)
{
struct des_compat_des3 keys;
keys.keys[0] = k1;
keys.keys[1] = k2;
keys.keys[2] = k3;
((enc == DES_ENCRYPT) ? des_compat_des3_encrypt : des_compat_des3_decrypt)
(&keys, DES_BLOCK_SIZE, *dst, *src);
}
/* If input is not a integral number of blocks, the final block is
padded with zeros, no length field or anything like that. That's
pretty broken, since it means that "$100" and "$100\0" always have
the same checksum, but I think that's how it's supposed to work. */
uint32_t
des_cbc_cksum(const uint8_t *src, des_cblock *dst,
long length, des_key_schedule ctx,
const_des_cblock *iv)
{
/* FIXME: I'm not entirely sure how this function is supposed to
* work, in particular what it should return, and if iv can be
* modified. */
uint8_t block[DES_BLOCK_SIZE];
memcpy(block, *iv, DES_BLOCK_SIZE);
while (length >= DES_BLOCK_SIZE)
{
memxor(block, src, DES_BLOCK_SIZE);
nettle_des_encrypt(ctx, DES_BLOCK_SIZE, block, block);
src += DES_BLOCK_SIZE;
length -= DES_BLOCK_SIZE;
}
if (length > 0)
{
memxor(block, src, length);
nettle_des_encrypt(ctx, DES_BLOCK_SIZE, block, block);
}
memcpy(*dst, block, DES_BLOCK_SIZE);
return LE_READ_UINT32(block + 4);
}
void
des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, des_cblock *iv,
int enc)
{
switch (enc)
{
case DES_ENCRYPT:
nettle_cbc_encrypt(ctx, (nettle_cipher_func *) des_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
nettle_cbc_decrypt(ctx,
(nettle_cipher_func *) des_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
default:
abort();
}
}
void
des_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, const_des_cblock *civ,
int enc)
{
des_cblock iv;
memcpy(iv, civ, DES_BLOCK_SIZE);
des_ncbc_encrypt(src, dst, length, ctx, &iv, enc);
}
void
des_ecb_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule ctx,
int enc)
{
((enc == DES_ENCRYPT) ? nettle_des_encrypt : nettle_des_decrypt)
(ctx, DES_BLOCK_SIZE, *dst, *src);
}
void
des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3,
des_cblock *iv,
int enc)
{
struct des_compat_des3 keys;
keys.keys[0] = k1;
keys.keys[1] = k2;
keys.keys[2] = k3;
switch (enc)
{
case DES_ENCRYPT:
nettle_cbc_encrypt(&keys, (nettle_cipher_func *) des_compat_des3_encrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
case DES_DECRYPT:
nettle_cbc_decrypt(&keys, (nettle_cipher_func *) des_compat_des3_decrypt,
DES_BLOCK_SIZE, *iv,
length, *dst, *src);
break;
default:
abort();
}
}
int
des_set_odd_parity(des_cblock *key)
{
nettle_des_fix_parity(DES_KEY_SIZE, *key, *key);
/* FIXME: What to return? */
return 0;
}
/* If des_check_key is non-zero, returns
*
* 0 for ok, -1 for bad parity, and -2 for weak keys.
*
* If des_check_key is zero (the default), always returns zero.
*/
int des_check_key = 0;
int
des_key_sched(const_des_cblock *key, des_key_schedule ctx)
{
if (des_check_key && !des_check_parity (DES_KEY_SIZE, *key))
/* Bad parity */
return -1;
if (!nettle_des_set_key(ctx, *key) && des_check_key)
/* Weak key */
return -2;
return 0;
}
int
des_is_weak_key(const_des_cblock *key)
{
struct des_ctx ctx;
return !nettle_des_set_key(&ctx, *key);
}
/* des-compat.h
The des block cipher, old libdes/openssl-style interface.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle 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
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#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. */
/* NOTE: This is quite experimental, and not all functions are
* implemented. Contributions, in particular test cases are welcome. */
#include "des.h"
#ifdef __cplusplus
extern "C" {
#endif
/* We use some name mangling, to avoid collisions with either other
* nettle functions or with libcrypto. */
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
#define des_check_key nettle_openssl_des_check_key
#define des_key_sched nettle_openssl_des_key_sched
#define des_is_weak_key nettle_openssl_des_is_weak_key
/* An extra alias */
#undef des_set_key
#define des_set_key nettle_openssl_des_key_sched
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
/* Types */
typedef uint32_t DES_LONG;
/* Note: Typedef:ed arrays should be avoided, but they're used here
* for compatibility. */
typedef struct des_ctx des_key_schedule[1];
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
/* Note: The proper definition,
typedef const uint8_t const_des_cblock[DES_BLOCK_SIZE];
would have worked, *if* all the prototypes had used arguments like
foo(const_des_cblock src, des_cblock dst), letting argument arrays
"decay" into pointers of type uint8_t * and const uint8_t *.
But since openssl's prototypes use *pointers* const_des_cblock *src,
des_cblock *dst, this ends up in type conflicts, and the workaround
is to not use const at all.
*/
#define const_des_cblock des_cblock
/* Aliases */
#define des_ecb2_encrypt(i,o,k1,k2,e) \
des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
/* Global flag */
extern int des_check_key;
/* Prototypes */
/* Typing is a little confusing. Since both des_cblock and
des_key_schedule are typedef:ed arrays, it automatically decay to
a pointers.
But the functions are declared taking pointers to des_cblock, i.e.
pointers to arrays. And on the other hand, they take plain
des_key_schedule arguments, which is equivalent to pointers to
struct des_ctx. */
void
des_ecb3_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3, int enc);
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
* latter half of the output block, using little endian byte order. */
uint32_t
des_cbc_cksum(const uint8_t *src, des_cblock *dst,
long length, des_key_schedule ctx,
const_des_cblock *iv);
/* NOTE: Doesn't update iv. */
void
des_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, const_des_cblock *iv,
int enc);
/* Similar, but updates iv. */
void
des_ncbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule ctx, des_cblock *iv,
int enc);
void
des_ecb_encrypt(const_des_cblock *src, des_cblock *dst,
des_key_schedule ctx, int enc);
void
des_ede3_cbc_encrypt(const_des_cblock *src, des_cblock *dst, long length,
des_key_schedule k1,
des_key_schedule k2,
des_key_schedule k3,
des_cblock *iv,
int enc);
int
des_set_odd_parity(des_cblock *key);
int
des_key_sched(const_des_cblock *key, des_key_schedule ctx);
int
des_is_weak_key(const_des_cblock *key);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */
......@@ -5512,18 +5512,6 @@ Nettle defines a compatible interface to MD5 in
@code{MD5_CTX}, and declares the functions @code{MD5Init}, @code{MD5Update} and
@code{MD5Final}.
Eric Young's ``libdes'' (also part of OpenSSL) is a quite popular DES
implementation. Nettle includes a subset if its interface in
@file{<nettle/des-compat.h>}. This file defines the typedefs
@code{des_key_schedule} and @code{des_cblock}, two constants
@code{DES_ENCRYPT} and @code{DES_DECRYPT}, and declares one global
variable @code{des_check_key}, and the functions @code{des_cbc_cksum}
@code{des_cbc_encrypt}, @code{des_ecb2_encrypt},
@code{des_ecb3_encrypt}, @code{des_ecb_encrypt},
@code{des_ede2_cbc_encrypt}, @code{des_ede3_cbc_encrypt},
@code{des_is_weak_key}, @code{des_key_sched}, @code{des_ncbc_encrypt}
@code{des_set_key}, and @code{des_set_odd_parity}.
@node Nettle soup, Installation, Reference, Top
@comment node-name, next, previous, up
@chapter Traditional Nettle Soup
......
......@@ -19,7 +19,6 @@
/ctr-test
/curve25519-dh-test
/cxx-test
/des-compat-test
/des-test
/des3-test
/dlopen-test
......
......@@ -34,9 +34,6 @@ des-test$(EXEEXT): des-test.$(OBJEXT)
des3-test$(EXEEXT): des3-test.$(OBJEXT)
$(LINK) des3-test.$(OBJEXT) $(TEST_OBJS) -o des3-test$(EXEEXT)
des-compat-test$(EXEEXT): des-compat-test.$(OBJEXT)
$(LINK) des-compat-test.$(OBJEXT) $(TEST_OBJS) -o des-compat-test$(EXEEXT)
md2-test$(EXEEXT): md2-test.$(OBJEXT)
$(LINK) md2-test.$(OBJEXT) $(TEST_OBJS) -o md2-test$(EXEEXT)
......
......@@ -15,7 +15,7 @@ TS_NETTLE_SOURCES = aes-test.c arcfour-test.c arctwo-test.c \
base16-test.c base64-test.c \
camellia-test.c chacha-test.c \
cnd-memcpy-test.c \
des-test.c des3-test.c des-compat-test.c \
des-test.c des3-test.c \
md2-test.c md4-test.c md5-test.c md5-compat-test.c \
memeql-test.c memxor-test.c gosthash94-test.c \
ripemd160-test.c hkdf-test.c \
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment