Skip to content

Commit be221a1

Browse files
authored
Merge pull request #12 from k-stachowiak/psa-key-registration
Psa key registration adjustment to new PSA API
2 parents 0f7c760 + 8c0459e commit be221a1

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

atecc608a/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ psa_key_slot_number_t atecc608a_public_key_slot = 9;
9696
enum {
9797
key_type = PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
9898
keypair_type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
99-
key_bits = 256,
99+
priv_bits = PSA_BYTES_TO_BITS(32),
100+
pub_bits = PSA_BYTES_TO_BITS(64),
100101
hash_alg = PSA_ALG_SHA_256,
101102
alg = PSA_ALG_ECDSA(hash_alg),
102-
sig_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg),
103-
pubkey_size = PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits),
103+
sig_size = PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, priv_bits, alg),
104+
pubkey_size = PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(priv_bits),
104105
hash_size = PSA_HASH_SIZE(hash_alg),
105106
};
106107

@@ -348,13 +349,14 @@ void setup_key_attributes(psa_key_attributes_t *attributes,
348349
psa_set_key_id(attributes, slot);
349350
psa_set_key_lifetime(attributes, PSA_ATECC608A_LIFETIME);
350351
psa_set_key_algorithm(attributes, alg);
351-
psa_set_key_bits(attributes, key_bits);
352352

353353
if (is_private) {
354+
psa_set_key_bits(attributes, priv_bits);
354355
psa_set_key_usage_flags(attributes, PSA_KEY_USAGE_SIGN);
355356
psa_set_key_type(attributes,
356357
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1));
357358
} else {
359+
psa_set_key_bits(attributes, pub_bits);
358360
psa_set_key_usage_flags(attributes, PSA_KEY_USAGE_VERIFY);
359361
psa_set_key_type(attributes,
360362
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1));

atecc608a/mbed_app.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"cryptoauthlib.i2c_scl": "PA09"
1515
}
1616
},
17-
"macros": ["ATCAPRINTF"]
17+
"macros": [
18+
"ATCAPRINTF",
19+
"MBEDTLS_USER_CONFIG_FILE=\"mbedtls_user_config.h\""
20+
]
1821
}

atecc608a/mbedtls_user_config.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2006-2019, Arm Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* This file is part of Mbed TLS (https://tls.mbed.org)
18+
*/
19+
20+
/* Enable PSA APIs, which this example depends on. */
21+
#if !defined(MBEDTLS_PSA_CRYPTO_C)
22+
# define MBEDTLS_PSA_CRYPTO_C
23+
#endif
24+
25+
/* Enable PSA use of secure elements. */
26+
#if !defined(MBEDTLS_PSA_CRYPTO_SE_C)
27+
# define MBEDTLS_PSA_CRYPTO_SE_C
28+
#endif

0 commit comments

Comments
 (0)