Software APIs
ecdsa_p256_key.h
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_ECDSA_P256_KEY_H_
6#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_ECDSA_P256_KEY_H_
7
8#include <stdint.h>
9
11
12#ifdef __cplusplus
13extern "C" {
14#endif // __cplusplus
15
16enum {
17 /**
18 * Size of a coordinate for an attestation public key in bits.
19 */
20 kEcdsaP256PublicKeyCoordBits = 256,
21 /**
22 * Size of a coordinate for an attestation public key in bytes.
23 */
24 kEcdsaP256PublicKeyCoordBytes = kEcdsaP256PublicKeyCoordBits / 8,
25 /**
26 * Size of a coordinate for an attestation public key in 32b words.
27 */
28 kEcdsaP256PublicKeyCoordWords =
29 kEcdsaP256PublicKeyCoordBytes / sizeof(uint32_t),
30 /**
31 * Size of an attestation signature component in bits.
32 */
33 kEcdsaP256SignatureComponentBits = 256,
34 /**
35 * Size of an attestation signature component in bytes.
36 */
37 kEcdsaP256SignatureComponentBytes = kEcdsaP256SignatureComponentBits / 8,
38 /**
39 * Size of an attestation signature component in 32b words.
40 */
41 kEcdsaP256SignatureComponentWords =
42 kEcdsaP256SignatureComponentBytes / sizeof(uint32_t),
43 /**
44 * Size of an attestation signature in bits.
45 */
46 kAttestationSignatureBits = kEcdsaP256SignatureComponentBits * 2,
47 /**
48 * Size of an attestation signature in bytes.
49 */
50 kAttestationSignatureBytes = kAttestationSignatureBits / 8,
51 /**
52 * Size of an attestation signature in 32b words.
53 */
54 kAttestationSignatureWords = kAttestationSignatureBytes / sizeof(uint32_t),
55};
56
57/**
58 * Holds an attestation public key (ECDSA-P256).
59 */
60typedef struct ecdsa_p256_public_key {
61 /**
62 * Affine x-coordinate of the point.
63 */
64 uint32_t x[kEcdsaP256PublicKeyCoordWords];
65 /**
66 * Affine y-coordinate of the point.
67 */
68 uint32_t y[kEcdsaP256PublicKeyCoordWords];
69} ecdsa_p256_public_key_t;
70
71/**
72 * Holds an attestation signature (ECDSA-P256).
73 */
74typedef struct ecdsa_p256_signature {
75 uint32_t r[kEcdsaP256SignatureComponentWords];
76 uint32_t s[kEcdsaP256SignatureComponentWords];
77} ecdsa_p256_signature_t;
78
79/**
80 * Gets the ID of an ECDSA public key.
81 *
82 * ID of a key is the least significant word of its key buffer.
83 * Callers must make sure that `pub_key` is valid before calling this function.
84 *
85 * @param key An ECDSA P256 public key.
86 * @return ID of the key.
87 */
89inline uint32_t sigverify_ecdsa_p256_key_id_get(
90 const ecdsa_p256_public_key_t *pub_key) {
91 return pub_key->x[0];
92}
93
94#ifdef __cplusplus
95} // extern "C"
96#endif // __cplusplus
97
98#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_ECDSA_P256_KEY_H_