Update some demos

This commit is contained in:
Zhi Guan
2018-11-01 11:21:14 +08:00
parent 676076278d
commit d58931925b
18 changed files with 492 additions and 30 deletions

View File

@@ -61,6 +61,16 @@
#include <openssl/is_gmssl.h>
static void print_buf(const char *s, const unsigned char *buf, size_t buflen)
{
int i;
printf("%s = ", s);
for (i = 0; i < buflen; i++) {
printf("%02X", buf[i]);
}
printf("\n");
}
int main(int argc, char **argv)
{
sms4_key_t sms4;
@@ -76,17 +86,8 @@ int main(int argc, char **argv)
}
#endif
printf("key = ");
for (i = 0; i < sizeof(key); i++) {
printf("%02X", key[i]);
}
printf("\n");
printf("plaintext block = ");
for (i = 0; i < sizeof(block); i++) {
printf("%02X", block[i]);
}
printf("\n");
print_buf("key", key, sizeof(key));
print_buf("plaintext block", block, sizeof(block));
/* expand key for encryption */
sms4_set_encrypt_key(&sms4, key);
@@ -94,11 +95,7 @@ int main(int argc, char **argv)
/* encrypt a block */
sms4_encrypt(block, block, &sms4);
printf("ciphertext block = ");
for (i = 0; i < sizeof(block); i++) {
printf("%02X", block[i]);
}
printf("\n");
print_buf("ciphertext block", block, sizeof(block));
/* expand key for decryption */
sms4_set_decrypt_key(&sms4, key);
@@ -106,11 +103,7 @@ int main(int argc, char **argv)
/* decrypt a block */
sms4_decrypt(block, block, &sms4);
printf("decrypted block = ");
for (i = 0; i < sizeof(block); i++) {
printf("%02X", block[i]);
}
printf("\n");
print_buf("decrypted block", block, sizeof(block));
return 0;
}