Fix #10408 Implement bitwise rotations correctly (#11508)

This commit is contained in:
Neven Sajko 2018-09-13 11:00:02 +02:00 committed by radare
parent c6e8b09352
commit 8ee4c902fb
2 changed files with 18 additions and 18 deletions

View File

@ -3,7 +3,9 @@
#include <r_lib.h>
#include <r_crypto.h>
#define MAX_rol_KEY_SIZE 32768
#define NAME "rol"
enum { MAX_rol_KEY_SIZE = 32768 };
struct rol_state {
ut8 key[MAX_rol_KEY_SIZE];
@ -25,7 +27,9 @@ static bool rol_init(struct rol_state *const state, const ut8 *key, int keylen)
static void rol_crypt(struct rol_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen) {
int i;
for (i = 0; i < buflen; i++) {
outbuf[i] = inbuf[i] << state->key[i%state->key_size];
ut8 count = state->key[i % state->key_size] & 7;
ut8 inByte = inbuf[i];
outbuf[i] = (inByte << count) | (inByte >> ((8 - count) & 7));
}
}
@ -42,7 +46,7 @@ static int rol_get_key_size(RCrypto *cry) {
}
static bool rol_use(const char *algo) {
return !strcmp (algo, "rol");
return !strcmp (algo, NAME);
}
static bool update(RCrypto *cry, const ut8 *buf, int len) {
@ -60,17 +64,13 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) {
return true;
}
static bool final(RCrypto *cry, const ut8 *buf, int len) {
return update (cry, buf, len);
}
RCryptoPlugin r_crypto_plugin_rol = {
.name = "rol",
.name = NAME,
.set_key = rol_set_key,
.get_key_size = rol_get_key_size,
.use = rol_use,
.update = update,
.final = final
.final = update,
};
#ifndef CORELIB

View File

@ -1,7 +1,9 @@
#include <r_lib.h>
#include <r_crypto.h>
#define MAX_ror_KEY_SIZE 32768
#define NAME "ror"
enum { MAX_ror_KEY_SIZE = 32768 };
struct ror_state {
ut8 key[MAX_ror_KEY_SIZE];
@ -23,7 +25,9 @@ static bool ror_init(struct ror_state *const state, const ut8 *key, int keylen)
static void ror_crypt(struct ror_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen) {
int i;
for (i = 0; i < buflen; i++) {
outbuf[i] = inbuf[i] >> state->key[i%state->key_size];
ut8 count = state->key[i % state->key_size] & 7;
ut8 inByte = inbuf[i];
outbuf[i] = (inByte >> count) | (inByte << ((8 - count) & 7));
}
}
@ -40,7 +44,7 @@ static int ror_get_key_size(RCrypto *cry) {
}
static bool ror_use(const char *algo) {
return !strcmp (algo, "ror");
return !strcmp (algo, NAME);
}
static bool update(RCrypto *cry, const ut8 *buf, int len) {
@ -58,17 +62,13 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) {
return true;
}
static bool final(RCrypto *cry, const ut8 *buf, int len) {
return update (cry, buf, len);
}
RCryptoPlugin r_crypto_plugin_ror = {
.name = "ror",
.name = NAME,
.set_key = ror_set_key,
.get_key_size = ror_get_key_size,
.use = ror_use,
.update = update,
.final = final
.final = update,
};
#ifndef CORELIB