samples/crypto: Use sys_log properly
Sys log already break a line after each line, by default, so removing the '\n' on log messages. Enabling support for sys log colors. Change-Id: Ica3a601aba0bbbd2d9438b41fb7bca0aad9c05f4 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
50151db3c5
commit
fcb4ea1383
@ -10,4 +10,5 @@ CONFIG_CRYPTO=y
|
||||
CONFIG_CRYPTO_TINYCRYPT_SHIM=y
|
||||
CONFIG_SYS_LOG_CRYPTO_LEVEL=4
|
||||
CONFIG_SYS_LOG=y
|
||||
CONFIG_ASSERT=y
|
||||
CONFIG_SYS_LOG_SHOW_COLOR=y
|
||||
CONFIG_ASSERT=y
|
||||
|
||||
@ -51,19 +51,19 @@ int validate_hw_compatibility(struct device *dev)
|
||||
flags = cipher_query_hwcaps(dev);
|
||||
if ((flags & CAP_RAW_KEY) == 0) {
|
||||
SYS_LOG_INF(" Please provision the key separately "
|
||||
"as the module doesnt support a raw key\n");
|
||||
"as the module doesnt support a raw key");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flags & CAP_SYNC_OPS) == 0) {
|
||||
SYS_LOG_ERR("The app assumes sync semantics. "
|
||||
"Please rewrite the app accordingly before proceeding\n");
|
||||
"Please rewrite the app accordingly before proceeding");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((flags & CAP_SEPARATE_IO_BUFS) == 0) {
|
||||
SYS_LOG_ERR("The app assumes distinct IO buffers. "
|
||||
"Please rewrite the app accordingly before proceeding\n");
|
||||
"Please rewrite the app accordingly before proceeding");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -82,16 +82,16 @@ void cbc_mode(void)
|
||||
u8_t encrypted[80];
|
||||
u8_t decrypted[64];
|
||||
|
||||
SYS_LOG_INF("CBC Mode\n");
|
||||
SYS_LOG_INF("CBC Mode");
|
||||
|
||||
dev = device_get_binding(CONFIG_CRYPTO_TINYCRYPT_SHIM_DRV_NAME);
|
||||
if (!dev) {
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found\n");
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (validate_hw_compatibility(dev)) {
|
||||
SYS_LOG_ERR("Incompatible h/w\n");
|
||||
SYS_LOG_ERR("Incompatible h/w");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -114,11 +114,11 @@ void cbc_mode(void)
|
||||
|
||||
if (memcmp(encrpt.out_buf, ciphertext, sizeof(ciphertext))) {
|
||||
SYS_LOG_ERR("cbc mode ENCRYPT - Mismatch between expected and "
|
||||
"returned cipher text\n");
|
||||
"returned cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("cbc mode ENCRYPT - Match\n");
|
||||
SYS_LOG_INF("cbc mode ENCRYPT - Match");
|
||||
cipher_free_session(dev, &ini);
|
||||
|
||||
if (cipher_begin_session(dev, &ini, CRYPTO_CIPHER_ALGO_AES,
|
||||
@ -137,11 +137,11 @@ void cbc_mode(void)
|
||||
|
||||
if (memcmp(decrypt.out_buf, plaintext, sizeof(plaintext))) {
|
||||
SYS_LOG_ERR("cbc mode DECRYPT - Mismatch between plaintext and "
|
||||
"decrypted cipher text\n");
|
||||
"decrypted cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("cbc mode DECRYPT - Match\n");
|
||||
SYS_LOG_INF("cbc mode DECRYPT - Match");
|
||||
out:
|
||||
cipher_free_session(dev, &ini);
|
||||
}
|
||||
@ -170,16 +170,16 @@ void ctr_mode(void)
|
||||
0xf8, 0xf9, 0xfa, 0xfb
|
||||
};
|
||||
|
||||
SYS_LOG_INF("CTR Mode\n");
|
||||
SYS_LOG_INF("CTR Mode");
|
||||
|
||||
dev = device_get_binding(CONFIG_CRYPTO_TINYCRYPT_SHIM_DRV_NAME);
|
||||
if (!dev) {
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found\n");
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (validate_hw_compatibility(dev)) {
|
||||
SYS_LOG_ERR("Incompatible h/w\n");
|
||||
SYS_LOG_ERR("Incompatible h/w");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -205,11 +205,11 @@ void ctr_mode(void)
|
||||
|
||||
if (memcmp(encrpt.out_buf, ctr_ciphertext, sizeof(ctr_ciphertext))) {
|
||||
SYS_LOG_ERR("ctr mode ENCRYPT - Mismatch between expected "
|
||||
"and returned cipher text\n");
|
||||
"and returned cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("ctr mode ENCRYPT - Match\n");
|
||||
SYS_LOG_INF("ctr mode ENCRYPT - Match");
|
||||
cipher_free_session(dev, &ini);
|
||||
|
||||
if (cipher_begin_session(dev, &ini, CRYPTO_CIPHER_ALGO_AES,
|
||||
@ -228,11 +228,11 @@ void ctr_mode(void)
|
||||
|
||||
if (memcmp(decrypt.out_buf, plaintext, sizeof(plaintext))) {
|
||||
SYS_LOG_ERR("ctr mode DECRYPT - Mismatch between plaintext "
|
||||
"and decypted cipher text\n");
|
||||
"and decypted cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("ctr mode DECRYPT - Match\n");
|
||||
SYS_LOG_INF("ctr mode DECRYPT - Match");
|
||||
out:
|
||||
cipher_free_session(dev, &ini);
|
||||
}
|
||||
@ -269,16 +269,16 @@ void ccm_mode(void)
|
||||
u8_t encrypted[50];
|
||||
u8_t decrypted[25];
|
||||
|
||||
SYS_LOG_INF("CCM Mode\n");
|
||||
SYS_LOG_INF("CCM Mode");
|
||||
|
||||
dev = device_get_binding(CONFIG_CRYPTO_TINYCRYPT_SHIM_DRV_NAME);
|
||||
if (!dev) {
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found\n");
|
||||
SYS_LOG_ERR("TinyCrypt pseudo device not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (validate_hw_compatibility(dev)) {
|
||||
SYS_LOG_ERR("Incompatible h/w\n");
|
||||
SYS_LOG_ERR("Incompatible h/w");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -307,11 +307,11 @@ void ccm_mode(void)
|
||||
|
||||
if (memcmp(encrpt.out_buf, ccm_expected, sizeof(ccm_expected))) {
|
||||
SYS_LOG_ERR("CCM mode ENCRYPT - Mismatch between expected "
|
||||
"and returned cipher text\n");
|
||||
"and returned cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("CCM mode ENCRYPT - Match\n");
|
||||
SYS_LOG_INF("CCM mode ENCRYPT - Match");
|
||||
cipher_free_session(dev, &ini);
|
||||
|
||||
if (cipher_begin_session(dev, &ini, CRYPTO_CIPHER_ALGO_AES,
|
||||
@ -334,18 +334,18 @@ void ccm_mode(void)
|
||||
|
||||
if (memcmp(decrypt.out_buf, ccm_data, sizeof(ccm_data))) {
|
||||
SYS_LOG_ERR("CCM mode DECRYPT - Mismatch between plaintext "
|
||||
"and decrypted cipher text\n");
|
||||
"and decrypted cipher text");
|
||||
goto out;
|
||||
}
|
||||
|
||||
SYS_LOG_INF("CCM mode DECRYPT - Match\n");
|
||||
SYS_LOG_INF("CCM mode DECRYPT - Match");
|
||||
out:
|
||||
cipher_free_session(dev, &ini);
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
SYS_LOG_INF("Cipher Sample\n");
|
||||
SYS_LOG_INF("Cipher Sample");
|
||||
cbc_mode();
|
||||
ctr_mode();
|
||||
ccm_mode();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user