mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 18:45:46 +01:00
Fix duplicate variable name in getting_started.md
Rename the key id variables to not clash with the raw key data.
This was introduced in cf56a0a3
.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
parent
1d7f7a7c6e
commit
f236bbb735
@ -76,7 +76,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
|||||||
{
|
{
|
||||||
psa_status_t status;
|
psa_status_t status;
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Import an AES key...\t");
|
printf("Import an AES key...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -95,7 +95,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
|||||||
psa_set_key_bits(&attributes, 128);
|
psa_set_key_bits(&attributes, 128);
|
||||||
|
|
||||||
/* Import the key */
|
/* Import the key */
|
||||||
status = psa_import_key(&attributes, key, key_len, &key);
|
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to import key\n");
|
printf("Failed to import key\n");
|
||||||
return;
|
return;
|
||||||
@ -106,7 +106,7 @@ void import_a_key(const uint8_t *key, size_t key_len)
|
|||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
|||||||
0xa9, 0xe8, 0xcc, 0xac, 0xd0, 0xf6, 0x54, 0x5c};
|
0xa9, 0xe8, 0xcc, 0xac, 0xd0, 0xf6, 0x54, 0x5c};
|
||||||
uint8_t signature[PSA_SIGNATURE_MAX_SIZE] = {0};
|
uint8_t signature[PSA_SIGNATURE_MAX_SIZE] = {0};
|
||||||
size_t signature_length;
|
size_t signature_length;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Sign a message...\t");
|
printf("Sign a message...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -154,14 +154,14 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
|||||||
psa_set_key_bits(&attributes, 1024);
|
psa_set_key_bits(&attributes, 1024);
|
||||||
|
|
||||||
/* Import the key */
|
/* Import the key */
|
||||||
status = psa_import_key(&attributes, key, key_len, &key);
|
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to import key\n");
|
printf("Failed to import key\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sign message using the key */
|
/* Sign message using the key */
|
||||||
status = psa_sign_hash(key, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
|
status = psa_sign_hash(key_id, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
|
||||||
hash, sizeof(hash),
|
hash, sizeof(hash),
|
||||||
signature, sizeof(signature),
|
signature, sizeof(signature),
|
||||||
&signature_length);
|
&signature_length);
|
||||||
@ -176,7 +176,7 @@ void sign_a_message_using_rsa(const uint8_t *key, size_t key_len)
|
|||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
size_t iv_len;
|
size_t iv_len;
|
||||||
uint8_t output[block_size];
|
uint8_t output[block_size];
|
||||||
size_t output_len;
|
size_t output_len;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
|
||||||
|
|
||||||
printf("Encrypt with cipher...\t");
|
printf("Encrypt with cipher...\t");
|
||||||
@ -232,7 +232,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_set_key_algorithm(&attributes, alg);
|
psa_set_key_algorithm(&attributes, alg);
|
||||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||||
psa_set_key_bits(&attributes, 128);
|
psa_set_key_bits(&attributes, 128);
|
||||||
status = psa_import_key(&attributes, key, key_len, &key);
|
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to import a key\n");
|
printf("Failed to import a key\n");
|
||||||
return;
|
return;
|
||||||
@ -240,7 +240,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Encrypt the plaintext */
|
/* Encrypt the plaintext */
|
||||||
status = psa_cipher_encrypt_setup(&operation, key, alg);
|
status = psa_cipher_encrypt_setup(&operation, key_id, alg);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to begin cipher operation\n");
|
printf("Failed to begin cipher operation\n");
|
||||||
return;
|
return;
|
||||||
@ -268,7 +268,7 @@ void encrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_cipher_abort(&operation);
|
psa_cipher_abort(&operation);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
uint8_t iv[block_size] = ENCRYPTED_WITH_IV;
|
uint8_t iv[block_size] = ENCRYPTED_WITH_IV;
|
||||||
uint8_t output[block_size];
|
uint8_t output[block_size];
|
||||||
size_t output_len;
|
size_t output_len;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Decrypt with cipher...\t");
|
printf("Decrypt with cipher...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -316,7 +316,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_set_key_algorithm(&attributes, alg);
|
psa_set_key_algorithm(&attributes, alg);
|
||||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||||
psa_set_key_bits(&attributes, 128);
|
psa_set_key_bits(&attributes, 128);
|
||||||
status = psa_import_key(&attributes, key, key_len, &key);
|
status = psa_import_key(&attributes, key, key_len, &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to import a key\n");
|
printf("Failed to import a key\n");
|
||||||
return;
|
return;
|
||||||
@ -324,7 +324,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Decrypt the ciphertext */
|
/* Decrypt the ciphertext */
|
||||||
status = psa_cipher_decrypt_setup(&operation, key, alg);
|
status = psa_cipher_decrypt_setup(&operation, key_id, alg);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to begin cipher operation\n");
|
printf("Failed to begin cipher operation\n");
|
||||||
return;
|
return;
|
||||||
@ -352,7 +352,7 @@ void decrypt_with_symmetric_ciphers(const uint8_t *key, size_t key_len)
|
|||||||
psa_cipher_abort(&operation);
|
psa_cipher_abort(&operation);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
}
|
}
|
||||||
@ -702,7 +702,7 @@ This example shows how to authenticate and encrypt a message:
|
|||||||
size_t output_length = 0;
|
size_t output_length = 0;
|
||||||
size_t tag_length = 16;
|
size_t tag_length = 16;
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Authenticate encrypt...\t");
|
printf("Authenticate encrypt...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -726,11 +726,11 @@ This example shows how to authenticate and encrypt a message:
|
|||||||
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
||||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||||
psa_set_key_bits(&attributes, 128);
|
psa_set_key_bits(&attributes, 128);
|
||||||
status = psa_import_key(&attributes, key, sizeof(key), &key);
|
status = psa_import_key(&attributes, key, sizeof(key), &key_id);
|
||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Authenticate and encrypt */
|
/* Authenticate and encrypt */
|
||||||
status = psa_aead_encrypt(key, PSA_ALG_CCM,
|
status = psa_aead_encrypt(key_id, PSA_ALG_CCM,
|
||||||
nonce, sizeof(nonce),
|
nonce, sizeof(nonce),
|
||||||
additional_data, sizeof(additional_data),
|
additional_data, sizeof(additional_data),
|
||||||
input_data, sizeof(input_data),
|
input_data, sizeof(input_data),
|
||||||
@ -747,7 +747,7 @@ This example shows how to authenticate and encrypt a message:
|
|||||||
free(output_data);
|
free(output_data);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
```
|
```
|
||||||
@ -773,7 +773,7 @@ This example shows how to authenticate and decrypt a message:
|
|||||||
size_t output_size = 0;
|
size_t output_size = 0;
|
||||||
size_t output_length = 0;
|
size_t output_length = 0;
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Authenticate decrypt...\t");
|
printf("Authenticate decrypt...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -797,7 +797,7 @@ This example shows how to authenticate and decrypt a message:
|
|||||||
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
psa_set_key_algorithm(&attributes, PSA_ALG_CCM);
|
||||||
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
|
||||||
psa_set_key_bits(&attributes, 128);
|
psa_set_key_bits(&attributes, 128);
|
||||||
status = psa_import_key(&attributes, key_data, sizeof(key_data), &key);
|
status = psa_import_key(&attributes, key_data, sizeof(key_data), &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to import a key\n");
|
printf("Failed to import a key\n");
|
||||||
return;
|
return;
|
||||||
@ -805,7 +805,7 @@ This example shows how to authenticate and decrypt a message:
|
|||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
/* Authenticate and decrypt */
|
/* Authenticate and decrypt */
|
||||||
status = psa_aead_decrypt(key, PSA_ALG_CCM,
|
status = psa_aead_decrypt(key_id, PSA_ALG_CCM,
|
||||||
nonce, sizeof(nonce),
|
nonce, sizeof(nonce),
|
||||||
additional_data, sizeof(additional_data),
|
additional_data, sizeof(additional_data),
|
||||||
input_data, sizeof(input_data),
|
input_data, sizeof(input_data),
|
||||||
@ -822,7 +822,7 @@ This example shows how to authenticate and decrypt a message:
|
|||||||
free(output_data);
|
free(output_data);
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
```
|
```
|
||||||
@ -848,7 +848,7 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
|||||||
size_t exported_length = 0;
|
size_t exported_length = 0;
|
||||||
static uint8_t exported[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits)];
|
static uint8_t exported[PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits)];
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
psa_key_id_t key;
|
psa_key_id_t key_id;
|
||||||
|
|
||||||
printf("Generate a key pair...\t");
|
printf("Generate a key pair...\t");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -867,14 +867,14 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
|||||||
psa_set_key_type(&attributes,
|
psa_set_key_type(&attributes,
|
||||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
|
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
|
||||||
psa_set_key_bits(&attributes, key_bits);
|
psa_set_key_bits(&attributes, key_bits);
|
||||||
status = psa_generate_key(&attributes, &key);
|
status = psa_generate_key(&attributes, &key_id);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to generate key\n");
|
printf("Failed to generate key\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
psa_reset_key_attributes(&attributes);
|
psa_reset_key_attributes(&attributes);
|
||||||
|
|
||||||
status = psa_export_public_key(key, exported, sizeof(exported),
|
status = psa_export_public_key(key_id, exported, sizeof(exported),
|
||||||
&exported_length);
|
&exported_length);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
printf("Failed to export public key %ld\n", status);
|
printf("Failed to export public key %ld\n", status);
|
||||||
@ -884,7 +884,7 @@ Mbed Crypto provides a simple way to generate a key or key pair.
|
|||||||
printf("Exported a public key\n");
|
printf("Exported a public key\n");
|
||||||
|
|
||||||
/* Destroy the key */
|
/* Destroy the key */
|
||||||
psa_destroy_key(key);
|
psa_destroy_key(key_id);
|
||||||
|
|
||||||
mbedtls_psa_crypto_free();
|
mbedtls_psa_crypto_free();
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user