Skip to content

Commit

Permalink
Cleaned up crypto API
Browse files Browse the repository at this point in the history
  • Loading branch information
akallabeth committed May 11, 2021
1 parent b494a19 commit d4ebf85
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
26 changes: 13 additions & 13 deletions include/freerdp/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ extern "C"
extern const BYTE tssk_privateExponent[];
extern const BYTE tssk_exponent[];

FREERDP_API int crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* exponent,
BYTE* output);
FREERDP_API int crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* exponent,
BYTE* output);
FREERDP_API int crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* private_exponent,
BYTE* output);
FREERDP_API int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* private_exponent,
BYTE* output);
FREERDP_API void crypto_reverse(BYTE* data, int length);
FREERDP_API SSIZE_T crypto_rsa_public_encrypt(const BYTE* input, size_t length,
size_t key_length, const BYTE* modulus,
const BYTE* exponent, BYTE* output);
FREERDP_API SSIZE_T crypto_rsa_public_decrypt(const BYTE* input, size_t length,
size_t key_length, const BYTE* modulus,
const BYTE* exponent, BYTE* output);
FREERDP_API SSIZE_T crypto_rsa_private_encrypt(const BYTE* input, size_t length,
size_t key_length, const BYTE* modulus,
const BYTE* private_exponent, BYTE* output);
FREERDP_API SSIZE_T crypto_rsa_private_decrypt(const BYTE* input, size_t length,
size_t key_length, const BYTE* modulus,
const BYTE* private_exponent, BYTE* output);
FREERDP_API void crypto_reverse(BYTE* data, size_t length);

FREERDP_API char* crypto_base64_encode(const BYTE* data, size_t length);
FREERDP_API void crypto_base64_decode(const char* enc_data, size_t length, BYTE** dec_data,
Expand Down
46 changes: 21 additions & 25 deletions libfreerdp/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey, DWORD* Public
return status;
}

static int crypto_rsa_common(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* exponent, int exponent_size, BYTE* output)
static SSIZE_T crypto_rsa_common(const BYTE* input, size_t length, UINT32 key_length,
const BYTE* modulus, const BYTE* exponent, size_t exponent_size,
BYTE* output)
{
BN_CTX* ctx = NULL;
int output_length = -1;
Expand All @@ -107,7 +108,7 @@ static int crypto_rsa_common(const BYTE* input, int length, UINT32 key_length, c
BIGNUM* y = NULL;
size_t bufferSize;

if (!input || (length < 0) || (exponent_size < 0) || !modulus || !exponent || !output)
if (!input || !modulus || !exponent || !output)
return -1;

if ((size_t)exponent_size > SIZE_MAX / 2)
Expand Down Expand Up @@ -181,59 +182,54 @@ static int crypto_rsa_common(const BYTE* input, int length, UINT32 key_length, c
return output_length;
}

static int crypto_rsa_public(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* exponent, BYTE* output)
static int crypto_rsa_public(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* exponent, BYTE* output)
{
return crypto_rsa_common(input, length, key_length, modulus, exponent, EXPONENT_MAX_SIZE,
output);
}

static int crypto_rsa_private(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* private_exponent, BYTE* output)
static int crypto_rsa_private(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{
return crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length,
output);
}

int crypto_rsa_public_encrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* exponent, BYTE* output)
SSIZE_T crypto_rsa_public_encrypt(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* exponent, BYTE* output)
{
return crypto_rsa_public(input, length, key_length, modulus, exponent, output);
}

int crypto_rsa_public_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* exponent, BYTE* output)
SSIZE_T crypto_rsa_public_decrypt(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* exponent, BYTE* output)
{
return crypto_rsa_public(input, length, key_length, modulus, exponent, output);
}

int crypto_rsa_private_encrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
SSIZE_T crypto_rsa_private_encrypt(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{
return crypto_rsa_private(input, length, key_length, modulus, private_exponent, output);
}

int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 key_length,
const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
SSIZE_T crypto_rsa_private_decrypt(const BYTE* input, size_t length, size_t key_length,
const BYTE* modulus, const BYTE* private_exponent, BYTE* output)
{
return crypto_rsa_private(input, length, key_length, modulus, private_exponent, output);
}

static int crypto_rsa_decrypt(const BYTE* input, int length, UINT32 key_length, const BYTE* modulus,
const BYTE* private_exponent, BYTE* output)
void crypto_reverse(BYTE* data, size_t length)
{
return crypto_rsa_common(input, length, key_length, modulus, private_exponent, key_length,
output);
}
size_t i, j;

void crypto_reverse(BYTE* data, int length)
{
int i, j;
BYTE temp;
if (length < 1)
return;

for (i = 0, j = length - 1; i < j; i++, j--)
{
temp = data[i];
const BYTE temp = data[i];
data[i] = data[j];
data[j] = temp;
}
Expand Down
1 change: 0 additions & 1 deletion winpr/libwinpr/synch/test/TestSynchAPC.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ int TestSynchAPC(int argc, char* argv[])
{
HANDLE thread = NULL;
UserApcArg userApcArg;
UncleanCloseData uncleanCloseData;

userApcArg.error = FALSE;
userApcArg.called = FALSE;
Expand Down

0 comments on commit d4ebf85

Please sign in to comment.