diff --git a/src/aead.c b/src/aead.c index f1c837c8..3196880a 100644 --- a/src/aead.c +++ b/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 } diff --git a/src/crypto.c b/src/crypto.c index ab3ea2ca..8ad31943 100644 --- a/src/crypto.c +++ b/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 diff --git a/src/crypto.h b/src/crypto.h index ee25e986..2bfad654 100644 --- a/src/crypto.h +++ b/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[]; diff --git a/src/stream.c b/src/stream.c index e3883857..335deb61 100644 --- a/src/stream.c +++ b/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