@@ -116,14 +116,13 @@ This allows the key in the key slot to be used for RSA signing.
116
116
int key_slot = 1;
117
117
unsigned char key[] = "RSA_KEY";
118
118
unsigned char payload[] = "ASYMMETRIC_INPUT_FOR_SIGN";
119
- psa_key_policy_t policy;
119
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT ;
120
120
unsigned char signature[PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE] = {0};
121
121
size_t signature_length;
122
122
123
123
status = psa_crypto_init();
124
124
125
125
/* Import the key */
126
- psa_key_policy_init(&policy);
127
126
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_SIGN,
128
127
PSA_ALG_RSA_PKCS1V15_SIGN_RAW);
129
128
status = psa_set_key_policy(key_slot, &policy);
@@ -343,7 +342,7 @@ At this point the derived key slot holds a new 128-bit AES-CTR encryption key de
343
342
```C
344
343
psa_key_slot_t base_key = 1;
345
344
psa_key_slot_t derived_key = 2;
346
- psa_key_policy_t policy;
345
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT ;
347
346
348
347
unsigned char key[] = {
349
348
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
@@ -358,14 +357,14 @@ At this point the derived key slot holds a new 128-bit AES-CTR encryption key de
358
357
0xf7, 0xf8, 0xf9 };
359
358
360
359
psa_algorithm_t alg = PSA_ALG_HKDF(PSA_ALG_SHA_256);
360
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
361
361
psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT;
362
362
size_t derived_bits = 128;
363
363
size_t capacity = PSA_BITS_TO_BYTES(derived_bits);
364
364
365
365
status = psa_crypto_init();
366
366
367
367
/* Import a key for use in key derivation, if such a key has already been imported you can skip this part */
368
- psa_key_policy_init(&policy);
369
368
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_DERIVE, alg);
370
369
status = psa_set_key_policy(base_key, &policy);
371
370
@@ -416,12 +415,12 @@ To authenticate and encrypt a message:
416
415
size_t output_size = 0;
417
416
size_t output_length = 0;
418
417
size_t tag_length = 16;
418
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
419
419
420
420
output_size = sizeof(input_data) + tag_length;
421
421
output_data = malloc(output_size);
422
422
status = psa_crypto_init();
423
423
424
- psa_key_policy_init (&policy);
425
424
psa_key_policy_set_usage (&policy, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CCM);
426
425
status = psa_set_key_policy(slot, &policy);
427
426
@@ -463,12 +462,12 @@ To authenticate and decrypt a message:
463
462
unsigned char *output_data = NULL;
464
463
size_t output_size = 0;
465
464
size_t output_length = 0;
465
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
466
466
467
467
output_size = sizeof(input_data);
468
468
output_data = malloc(output_size);
469
469
status = psa_crypto_init();
470
470
471
- psa_key_policy_init(&policy);
472
471
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CCM);
473
472
status = psa_set_key_policy(slot, &policy);
474
473
@@ -503,10 +502,10 @@ Generate a piece of random 128-bit AES data:
503
502
size_t exported_size = bits;
504
503
size_t exported_length = 0 ;
505
504
uint8_t *exported = malloc(exported_size);
505
+ psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
506
506
507
507
psa_crypto_init ();
508
508
509
- psa_key_policy_init (&policy);
510
509
psa_key_policy_set_usage (&policy, PSA_KEY_USAGE_EXPORT, PSA_ALG_GCM);
511
510
psa_set_key_policy(slot, &policy);
512
511
0 commit comments