diff options
author | erikdejong <erikdejong@gmail.com> | 2017-03-06 22:01:39 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2017-03-10 02:54:51 +0000 |
commit | fe285c640b6279fdb9920bb79b0494ac87cb0e32 (patch) | |
tree | 85d71f80358f486494368fab9fde765562363eb9 /wsutil/wsgcrypt.c | |
parent | 9e0251f2187388ce03b4afde91df2528e313afd8 (diff) |
Replace aes.c and des.c by Libgcrypt
Follow-up of https://code.wireshark.org/review/20095
Rewritten functions:
- crypt_des_ecb
crypt_des_ecb verified against previous crypt_des_ecb implementation with
4294967295 random keys and input buffers from /dev/random as I cannot find a
suitable pcap which uses DES
Change-Id: I21ec2572451e0ded4299ffadd8dd687817bc6318
Reviewed-on: https://code.wireshark.org/review/20429
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'wsutil/wsgcrypt.c')
-rw-r--r-- | wsutil/wsgcrypt.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/wsutil/wsgcrypt.c b/wsutil/wsgcrypt.c index 09753f72a7..869111a214 100644 --- a/wsutil/wsgcrypt.c +++ b/wsutil/wsgcrypt.c @@ -43,6 +43,34 @@ gcry_error_t ws_hmac_buffer(int algo, void *digest, const void *buffer, size_t l return GPG_ERR_NO_ERROR; } +void crypt_des_ecb(guint8 *output, const guint8 *buffer, const guint8 *key56) +{ + guint8 key64[8]; + gcry_cipher_hd_t handle; + + memset(output, 0x00, 8); + + /* Transform 56 bits key into 64 bits DES key */ + key64[0] = key56[0]; + key64[1] = (key56[0] << 7) | (key56[1] >> 1); + key64[2] = (key56[1] << 6) | (key56[2] >> 2); + key64[3] = (key56[2] << 5) | (key56[3] >> 3); + key64[4] = (key56[3] << 4) | (key56[4] >> 4); + key64[5] = (key56[4] << 3) | (key56[5] >> 5); + key64[6] = (key56[5] << 2) | (key56[6] >> 6); + key64[7] = (key56[6] << 1); + + if (gcry_cipher_open(&handle, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0)) { + return; + } + if (gcry_cipher_setkey(handle, key64, 8)) { + gcry_cipher_close(handle); + return; + } + gcry_cipher_encrypt(handle, output, 8, buffer, 8); + gcry_cipher_close(handle); +} + /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * |