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