Karl Zhang | 3de5ab1 | 2021-05-31 11:45:48 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019-2020, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "class_forwards.hpp" |
| 9 | |
| 10 | #include "boilerplate.hpp" |
| 11 | #include "randomization.hpp" |
| 12 | #include "gibberish.hpp" |
| 13 | #include "compute.hpp" |
| 14 | #include "data_blocks.hpp" |
| 15 | #include "psa_asset.hpp" |
| 16 | #include "find_or_create_asset.hpp" |
| 17 | #include "template_line.hpp" |
| 18 | #include "tf_fuzz.hpp" |
| 19 | #include "crypto_asset.hpp" |
| 20 | #include "psa_call.hpp" |
| 21 | |
| 22 | |
| 23 | |
| 24 | /********************************************************************************** |
| 25 | Methods of class crypto_asset follow: |
| 26 | **********************************************************************************/ |
| 27 | |
| 28 | crypto_asset::crypto_asset (void) // (default constructor) |
| 29 | { |
| 30 | return; // just to have something to pin a breakpoint onto |
| 31 | } |
| 32 | |
| 33 | |
| 34 | crypto_asset::~crypto_asset (void) // (destructor) |
| 35 | { |
| 36 | return; // just to have something to pin a breakpoint onto |
| 37 | } |
| 38 | |
| 39 | /********************************************************************************** |
| 40 | End of methods of class crypto_asset. |
| 41 | **********************************************************************************/ |
| 42 | |
| 43 | |
| 44 | /********************************************************************************** |
| 45 | Methods of class policy_asset follow: |
| 46 | **********************************************************************************/ |
| 47 | |
| 48 | policy_asset::policy_asset (void) // (default constructor) |
| 49 | { |
| 50 | // Randomize key-policy usage and algorithm: |
| 51 | policy_usage = rand_key_usage(); |
| 52 | policy_algorithm = rand_key_algorithm(); |
| 53 | // keys: Should automatically come up as empby. |
| 54 | } |
| 55 | |
| 56 | |
| 57 | policy_asset::~policy_asset (void) // (destructor) |
| 58 | { |
| 59 | return; // just to have something to pin a breakpoint onto |
| 60 | } |
| 61 | |
| 62 | /********************************************************************************** |
| 63 | End of methods of class policy_asset. |
| 64 | **********************************************************************************/ |
| 65 | |
| 66 | |
| 67 | /********************************************************************************** |
| 68 | Methods of class key_asset follow: |
| 69 | **********************************************************************************/ |
| 70 | |
| 71 | bool key_asset::set_key_id (int id_n) |
| 72 | { |
| 73 | key_id = id_n; |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | key_asset::key_asset (void) |
| 79 | { |
| 80 | // Note: Similar random initialization for asset and template |
| 81 | // Randomize handle: |
| 82 | // TODO: Key handles appear to be a lot more complex a question than the below |
| 83 | gibberish *gib = new gibberish; |
| 84 | char buffer[256]; |
| 85 | char *end; |
| 86 | int buf_len = 5ULL + (uint64_t) (rand() % 10); |
| 87 | end = gib->word (false, buffer, buffer + buf_len); |
| 88 | *end = '\0'; |
| 89 | buffer[buf_len] = '\0'; |
| 90 | handle_str = buffer; |
| 91 | // Randomize key type: |
| 92 | key_type = rand_key_type(); |
| 93 | // Randomize lifetime: |
| 94 | lifetime_str = ((rand() % 2) == 1)? |
| 95 | "PSA_KEY_LIFETIME_VOLATILE" : "PSA_KEY_LIFETIME_PERSISTENT"; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | key_asset::~key_asset (void) |
| 100 | { |
| 101 | return; // just to have something to pin a breakpoint onto |
| 102 | } |
| 103 | |
| 104 | /********************************************************************************** |
| 105 | End of methods of class key_asset. |
| 106 | **********************************************************************************/ |