Apply clang-format code style to all source files
This commit is contained in:
+58
-52
@@ -7,10 +7,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char vista_prov[]
|
||||
= "Microsoft Enhanced RSA and AES Cryptographic Provider";
|
||||
static const char winxp_prov[]
|
||||
= "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)";
|
||||
static const char vista_prov[] =
|
||||
"Microsoft Enhanced RSA and AES Cryptographic Provider";
|
||||
static const char winxp_prov[] =
|
||||
"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)";
|
||||
|
||||
static int init_count;
|
||||
static HCRYPTPROV prov;
|
||||
@@ -36,10 +36,10 @@ void crypto_init(void)
|
||||
prov_name = vista_prov;
|
||||
}
|
||||
|
||||
if (!CryptAcquireContext(&prov, NULL, prov_name, PROV_RSA_AES,
|
||||
CRYPT_VERIFYCONTEXT)) {
|
||||
log_fatal("CryptAcquireContext failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
if (!CryptAcquireContext(
|
||||
&prov, NULL, prov_name, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
|
||||
log_fatal(
|
||||
"CryptAcquireContext failed: %08x", (unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +57,16 @@ void crypto_fini(void)
|
||||
log_misc("Shutting down win32 crypto wrappers");
|
||||
|
||||
if (!CryptReleaseContext(prov, 0)) {
|
||||
log_fatal("CryptReleaseContext failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"CryptReleaseContext failed: %08x", (unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void md5_compute(const void *in_bytes, size_t in_nbytes, uint8_t *out_bytes,
|
||||
size_t out_nbytes)
|
||||
void md5_compute(
|
||||
const void *in_bytes,
|
||||
size_t in_nbytes,
|
||||
uint8_t *out_bytes,
|
||||
size_t out_nbytes)
|
||||
{
|
||||
struct md5 md5;
|
||||
|
||||
@@ -75,16 +78,16 @@ void md5_compute(const void *in_bytes, size_t in_nbytes, uint8_t *out_bytes,
|
||||
void md5_init(struct md5 *md5)
|
||||
{
|
||||
if (!CryptCreateHash(prov, CALG_MD5, 0, 0, &md5->hash)) {
|
||||
log_fatal("CryptCreateHash(CALG_MD5) failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"CryptCreateHash(CALG_MD5) failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
void md5_append(struct md5 *md5, const void *bytes, size_t nbytes)
|
||||
{
|
||||
if (!CryptHashData(md5->hash, bytes, nbytes, 0)) {
|
||||
log_fatal("CryptHashData failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal("CryptHashData failed: %08x", (unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,18 +101,22 @@ void md5_fini(struct md5 *md5, uint8_t *output, size_t nbytes)
|
||||
|
||||
if (output != NULL) {
|
||||
if (!CryptGetHashParam(md5->hash, HP_HASHVAL, output, &tmp, 0)) {
|
||||
log_fatal("Error getting MD5 result: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"Error getting MD5 result: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
if (!CryptDestroyHash(md5->hash)) {
|
||||
log_fatal("CryptDestroyHash failed: %08x",
|
||||
(unsigned int) GetLastError());
|
||||
log_fatal(
|
||||
"CryptDestroyHash failed: %08x", (unsigned int) GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
#define SWAP(x, y, tmp) tmp = x; x = y; y = tmp
|
||||
#define SWAP(x, y, tmp) \
|
||||
tmp = x; \
|
||||
x = y; \
|
||||
y = tmp
|
||||
|
||||
void arc4_init(struct arc4 *arc4, const uint8_t *key, size_t key_nbytes)
|
||||
{
|
||||
@@ -120,13 +127,13 @@ void arc4_init(struct arc4 *arc4, const uint8_t *key, size_t key_nbytes)
|
||||
arc4->i = 0;
|
||||
arc4->j = 0;
|
||||
|
||||
for (i = 0 ; i < 256 ; i++) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
arc4->S[i] = (uint8_t) i;
|
||||
}
|
||||
|
||||
j = 0;
|
||||
|
||||
for (i = 0 ; i < 256 ; i++) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
j = j + arc4->S[i] + key[i % key_nbytes];
|
||||
SWAP(arc4->S[i], arc4->S[j], tmp);
|
||||
}
|
||||
@@ -137,38 +144,37 @@ void arc4_apply(struct arc4 *arc4, uint8_t *bytes, size_t nbytes)
|
||||
size_t i;
|
||||
uint8_t tmp;
|
||||
|
||||
for (i = 0 ; i < nbytes ; i++) {
|
||||
for (i = 0; i < nbytes; i++) {
|
||||
arc4->i += 1;
|
||||
arc4->j += arc4->S[arc4->i];
|
||||
|
||||
SWAP(arc4->S[arc4->i], arc4->S[arc4->j], tmp);
|
||||
|
||||
bytes[i] ^= arc4->S[(uint8_t) (arc4->S[arc4->i] + arc4->S[arc4->j])];
|
||||
bytes[i] ^= arc4->S[(uint8_t)(arc4->S[arc4->i] + arc4->S[arc4->j])];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint32_t blowfish_F(struct blowfish* blowfish, uint32_t x)
|
||||
static uint32_t blowfish_F(struct blowfish *blowfish, uint32_t x)
|
||||
{
|
||||
unsigned short a, b, c, d;
|
||||
uint32_t y;
|
||||
unsigned short a, b, c, d;
|
||||
uint32_t y;
|
||||
|
||||
d = x & 0x00FF;
|
||||
x >>= 8;
|
||||
c = x & 0x00FF;
|
||||
x >>= 8;
|
||||
b = x & 0x00FF;
|
||||
x >>= 8;
|
||||
a = x & 0x00FF;
|
||||
d = x & 0x00FF;
|
||||
x >>= 8;
|
||||
c = x & 0x00FF;
|
||||
x >>= 8;
|
||||
b = x & 0x00FF;
|
||||
x >>= 8;
|
||||
a = x & 0x00FF;
|
||||
|
||||
y = blowfish->S[0][a] + blowfish->S[1][b];
|
||||
y = y ^ blowfish->S[2][c];
|
||||
y = y + blowfish->S[3][d];
|
||||
return y;
|
||||
y = blowfish->S[0][a] + blowfish->S[1][b];
|
||||
y = y ^ blowfish->S[2][c];
|
||||
y = y + blowfish->S[3][d];
|
||||
return y;
|
||||
}
|
||||
|
||||
void blowfish_init(struct blowfish* blowfish, const uint8_t* key,
|
||||
size_t key_length)
|
||||
void blowfish_init(
|
||||
struct blowfish *blowfish, const uint8_t *key, size_t key_length)
|
||||
{
|
||||
int i, j, k;
|
||||
uint32_t data, datal, datar;
|
||||
@@ -205,12 +211,12 @@ void blowfish_init(struct blowfish* blowfish, const uint8_t* key,
|
||||
}
|
||||
}
|
||||
|
||||
void blowfish_encrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr)
|
||||
void blowfish_encrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr)
|
||||
{
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
|
||||
Xl = *xl;
|
||||
Xr = *xr;
|
||||
@@ -232,12 +238,12 @@ void blowfish_encrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr)
|
||||
*xr = Xr;
|
||||
}
|
||||
|
||||
void blowfish_decrypt(struct blowfish* blowfish, uint32_t* xl, uint32_t* xr)
|
||||
void blowfish_decrypt(struct blowfish *blowfish, uint32_t *xl, uint32_t *xr)
|
||||
{
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
|
||||
Xl = *xl;
|
||||
Xr = *xr;
|
||||
|
||||
Reference in New Issue
Block a user