1*900bf7c6SYuichi Sugiyama /* SPDX-License-Identifier: BSD-2-Clause */ 2*900bf7c6SYuichi Sugiyama /* 3*900bf7c6SYuichi Sugiyama * Copyright (C) 2024, Institute of Information Security (IISEC) 4*900bf7c6SYuichi Sugiyama */ 5*900bf7c6SYuichi Sugiyama 6*900bf7c6SYuichi Sugiyama #ifndef PTA_VERAISON_ATTESTATION_SIGN_H 7*900bf7c6SYuichi Sugiyama #define PTA_VERAISON_ATTESTATION_SIGN_H 8*900bf7c6SYuichi Sugiyama 9*900bf7c6SYuichi Sugiyama #include <stddef.h> 10*900bf7c6SYuichi Sugiyama #include <stdint.h> 11*900bf7c6SYuichi Sugiyama #include <tee_api_types.h> 12*900bf7c6SYuichi Sugiyama 13*900bf7c6SYuichi Sugiyama /** 14*900bf7c6SYuichi Sugiyama * Sign a message with ECDSA w/ SHA-256 15*900bf7c6SYuichi Sugiyama * @param msg The message to sign 16*900bf7c6SYuichi Sugiyama * @param msg_len The length of the message to sign 17*900bf7c6SYuichi Sugiyama * @param sig [out] Where to store the signature. The signature format 18*900bf7c6SYuichi Sugiyama * follows the specifications in RFC 7518 Section 3.4. This 19*900bf7c6SYuichi Sugiyama * means the signature will be output in a 'plain signature' 20*900bf7c6SYuichi Sugiyama * format, diverging from the traditional ASN.1 DER encoding. 21*900bf7c6SYuichi Sugiyama * In this context, 'plain signature' refers to the direct 22*900bf7c6SYuichi Sugiyama * concatenation of the r and s values of the ECDSA signature, 23*900bf7c6SYuichi Sugiyama * each occupying exactly half of the signature space. When 24*900bf7c6SYuichi Sugiyama * using a 256-bit ECDSA key, r and s are each 32 bytes long. 25*900bf7c6SYuichi Sugiyama * In a plain signature, these values are simply concatenated 26*900bf7c6SYuichi Sugiyama * to produce a total signature of 64 bytes. 27*900bf7c6SYuichi Sugiyama * @param sig_len [in/out] The max size and resulting size of the signature. 28*900bf7c6SYuichi Sugiyama * It is important to ensure that the provided buffer is 29*900bf7c6SYuichi Sugiyama * sufficiently large to hold the signature in its specified 30*900bf7c6SYuichi Sugiyama * format. The resulting size will indicate the actual size of 31*900bf7c6SYuichi Sugiyama * the signature in bytes. 32*900bf7c6SYuichi Sugiyama * @return TEE_SUCCESS if successful 33*900bf7c6SYuichi Sugiyama */ 34*900bf7c6SYuichi Sugiyama TEE_Result sign_ecdsa_sha256(const uint8_t *msg, size_t msg_len, uint8_t *sig, 35*900bf7c6SYuichi Sugiyama size_t *sig_len); 36*900bf7c6SYuichi Sugiyama 37*900bf7c6SYuichi Sugiyama #endif /*PTA_VERAISON_ATTESTATION_SIGN_H*/ 38