Browse Source

Rename DEBUG to SS_DEBUG

pull/1246/head
Max Lv 7 years ago
parent
commit
8a34b3ea0b
4 changed files with 22 additions and 32 deletions
  1. 14
      src/aead.c
  2. 14
      src/crypto.c
  3. 3
      src/crypto.h
  4. 23
      src/stream.c

14
src/aead.c

@ -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",
@ -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
}

14
src/crypto.c

@ -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;
@ -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
src/crypto.h

@ -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[];

23
src/stream.c

@ -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)
{
@ -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
@ -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);
@ -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
@ -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);
@ -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

Loading…
Cancel
Save