HSMLPF3Utility.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*!****************************************************************************
34  * @file HSMLPF3Utility.h
35  *
36  * @brief Interface for helper functions for HSM-related operations
37  *
38  */
39 
40 #include <stdint.h>
41 
42 /* Defines */
43 #define HSM_ASYM_DATA_VHEADER (4U)
44 #define HSM_WORD_LENGTH (4U)
45 #define HSM_SIGNATURE_VCOUNT (2U)
46 
47 #define BITS_TO_BYTES(bits) (((size_t)(bits) + 7U) / 8U)
48 
54 static inline uint32_t HSM_ASYM_DATA_SIZE_B2W(const size_t x)
55 {
56  return (uint32_t)((x + 31U) / 32U);
57 }
58 
64 static inline uint32_t HSM_ASYM_DATA_SIZE_B2WB(const size_t x)
65 {
66  return (uint32_t)(HSM_WORD_LENGTH * (HSM_ASYM_DATA_SIZE_B2W(x)));
67 }
68 
74 static inline uint32_t HSM_ASYM_DATA_SIZE_VWB(const size_t x)
75 {
76  return (uint32_t)(HSM_ASYM_DATA_VHEADER + HSM_ASYM_DATA_SIZE_B2WB(x));
77 }
78 
84 static inline uint32_t HSMLPF3_getOutputBufferLength(const uint32_t inputLength)
85 {
86 #ifdef VEX_CHECK_DMA_WITH_TOKEN_ID
87  /* 32-bit alignment + extra size for the TokenID */
88  return (((inputLength + 3U) & (size_t)~3UL) + sizeof(size_t));
89 #else
90  /* 32-bit alignment */
91  return ((inputLength + 3U) & (size_t)~3UL);
92 #endif
93 }
94 
103 void HSMLPF3_asymDsaSignatureFromHW(const uint8_t *const in,
104  const size_t modulusSizeBits,
105  uint8_t *out_r,
106  uint8_t *out_s);
107 
116 void HSMLPF3_asymDsaSignatureToHW(const uint8_t *const Signature_r,
117  const uint8_t *const Signature_s,
118  const size_t modulusSizeBits,
119  uint8_t *const blob);
120 
129 void HSMLPF3_asymDsaPubKeyToHW(const uint8_t *const pubKey,
130  const size_t modulusSizeBits,
131  const uint8_t domainId,
132  uint8_t *const blob);
133 
142 void HSMLPF3_asymDsaPriKeyToHW(const uint8_t *const pubKey,
143  const size_t modulusSizeBits,
144  const uint8_t domainId,
145  uint8_t *const blob);
static uint32_t HSM_ASYM_DATA_SIZE_VWB(const size_t x)
Definition: HSMLPF3Utility.h:74
static uint32_t HSMLPF3_getOutputBufferLength(const uint32_t inputLength)
Returns 32-bit aligned adjusted input length.
Definition: HSMLPF3Utility.h:84
static uint32_t HSM_ASYM_DATA_SIZE_B2W(const size_t x)
Definition: HSMLPF3Utility.h:54
static uint32_t HSM_ASYM_DATA_SIZE_B2WB(const size_t x)
Definition: HSMLPF3Utility.h:64
#define HSM_WORD_LENGTH
Definition: HSMLPF3Utility.h:44
void HSMLPF3_asymDsaSignatureToHW(const uint8_t *const Signature_r, const uint8_t *const Signature_s, const size_t modulusSizeBits, uint8_t *const blob)
Constructs a vector component consistent with HSM format to hold the signature.
void HSMLPF3_asymDsaPubKeyToHW(const uint8_t *const pubKey, const size_t modulusSizeBits, const uint8_t domainId, uint8_t *const blob)
Constructs a vector component consistent with HSM format to hold a verify operation&#39;s public key...
void HSMLPF3_asymDsaPriKeyToHW(const uint8_t *const pubKey, const size_t modulusSizeBits, const uint8_t domainId, uint8_t *const blob)
Constructs a vector component consistent with HSM format to hold a sign operation&#39;s private key...
#define HSM_ASYM_DATA_VHEADER
Definition: HSMLPF3Utility.h:43
void HSMLPF3_asymDsaSignatureFromHW(const uint8_t *const in, const size_t modulusSizeBits, uint8_t *out_r, uint8_t *out_s)
Extracts the signature from HSM-formatted output.
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale