Skip to content

Commit

Permalink
Rename DEBUG to SS_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Feb 13, 2017
1 parent 889079e commit 8a34b3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
14 changes: 1 addition & 13 deletions src/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@
*
*/

#ifdef DEBUG
static void
dump(char *tag, char *text, int len)
{
int i;
printf("%s: ", tag);
for (i = 0; i < len; i++)
printf("0x%02x ", (uint8_t)text[i]);
printf("\n");
}
#endif

const char *supported_aead_ciphers[AEAD_CIPHER_NUM] = {
"aes-128-gcm",
"aes-192-gcm",
Expand Down Expand Up @@ -356,7 +344,7 @@ aead_cipher_ctx_init(cipher_ctx_t *cipher_ctx, int method, int enc)
FATAL("Cannot initialize mbed TLS cipher context");
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("KEY", (char *)cipher_ctx->cipher->key, cipher_ctx->cipher->key_len);
#endif
}
Expand Down
14 changes: 13 additions & 1 deletion src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ crypto_parse_key(const char *base64, uint8_t *key, size_t key_len)
out_len = base64_decode(out, base64, out_len);
if (out_len > 0 && out_len >= key_len) {
memcpy(key, out, key_len);
#ifdef DEBUG
#ifdef SS_DEBUG
dump("KEY", (char*)key, key_len);
#endif
return key_len;
Expand All @@ -339,3 +339,15 @@ crypto_parse_key(const char *base64, uint8_t *key, size_t key_len)
FATAL("Please use the key above or input a valid key");
return key_len;
}

#ifdef SS_DEBUG
void
dump(char *tag, char *text, int len)
{
int i;
printf("%s: ", tag);
for (i = 0; i < len; i++)
printf("0x%02x ", (uint8_t)text[i]);
printf("\n");
}
#endif
3 changes: 3 additions & 0 deletions src/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ int crypto_hkdf_extract(const mbedtls_md_info_t *md, const unsigned char *salt,
int crypto_hkdf_expand(const mbedtls_md_info_t *md, const unsigned char *prk,
int prk_len, const unsigned char *info, int info_len,
unsigned char *okm, int okm_len);
#ifdef SS_DEBUG
void dump(char *tag, char *text, int len);
#endif

extern struct cache *nonce_cache;
extern const char *supported_stream_ciphers[];
Expand Down
23 changes: 5 additions & 18 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ crypto_stream_xor_ic(uint8_t *c, const uint8_t *m, uint64_t mlen,
return 0;
}

#ifdef DEBUG
void
dump(char *tag, char *text, int len)
{
int i;
printf("%s: ", tag);
for (i = 0; i < len; i++)
printf("0x%02x ", (uint8_t)text[i]);
printf("\n");
}

#endif

int
cipher_nonce_size(const cipher_t *cipher)
{
Expand Down Expand Up @@ -285,7 +272,7 @@ cipher_ctx_set_nonce(cipher_ctx_t *cipher_ctx, uint8_t *nonce, size_t nonce_len,
FATAL("Cannot finalize mbed TLS cipher context");
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("NONCE", (char *)nonce, nonce_len);
dump("KEY", (char *)true_key, 32);
#endif
Expand Down Expand Up @@ -335,7 +322,7 @@ stream_encrypt_all(buffer_t *plaintext, cipher_t *cipher, size_t capacity)
return CRYPTO_ERROR;
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("PLAIN", plaintext->data, plaintext->len);
dump("CIPHER", ciphertext->data + nonce_len, ciphertext->len);
dump("NONCE", ciphertext->data, nonce_len);
Expand Down Expand Up @@ -406,7 +393,7 @@ stream_encrypt(buffer_t *plaintext, cipher_ctx_t *cipher_ctx, size_t capacity)
}
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("PLAIN", plaintext->data, plaintext->len);
dump("CIPHER", ciphertext->data + nonce_len, ciphertext->len);
#endif
Expand Down Expand Up @@ -457,7 +444,7 @@ stream_decrypt_all(buffer_t *ciphertext, cipher_t *cipher, size_t capacity)
return CRYPTO_ERROR;
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("PLAIN", plaintext->data, plaintext->len);
dump("CIPHER", ciphertext->data + nonce_len, ciphertext->len - nonce_len);
dump("NONCE", ciphertext->data, nonce_len);
Expand Down Expand Up @@ -562,7 +549,7 @@ stream_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx, size_t capacity)
return CRYPTO_ERROR;
}

#ifdef DEBUG
#ifdef SS_DEBUG
dump("PLAIN", plaintext->data, plaintext->len);
dump("CIPHER", ciphertext->data, ciphertext->len);
#endif
Expand Down

0 comments on commit 8a34b3e

Please sign in to comment.