1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Crypto Component                                                 */
17 /**                                                                       */
18 /**   Elliptic Curve Digital Signature Algorithm (ECDSA)                  */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    nx_crypto_ecdsa.h                                    PORTABLE C     */
29 /*                                                           6.1          */
30 /*                                                                        */
31 /*  AUTHOR                                                                */
32 /*                                                                        */
33 /*    Timothy Stapko, Microsoft Corporation                               */
34 /*                                                                        */
35 /*  DESCRIPTION                                                           */
36 /*                                                                        */
37 /*    This file defines the basic Application Interface (API) to the      */
38 /*    NetX ECDSA module.                                                  */
39 /*                                                                        */
40 /*    It is assumed that nx_api.h and nx_port.h have already been         */
41 /*    included.                                                           */
42 /*                                                                        */
43 /*  RELEASE HISTORY                                                       */
44 /*                                                                        */
45 /*    DATE              NAME                      DESCRIPTION             */
46 /*                                                                        */
47 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
48 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
49 /*                                            resulting in version 6.1    */
50 /*                                                                        */
51 /**************************************************************************/
52 
53 #ifndef  NX_ECDSA_H
54 #define  NX_ECDSA_H
55 
56 
57 /* Determine if a C++ compiler is being used.  If so, ensure that standard
58    C is used to process the API information.  */
59 #ifdef __cplusplus
60 
61 /* Yes, C++ compiler is present.  Use standard C.  */
62 extern   "C" {
63 
64 #endif
65 
66 #include "nx_crypto.h"
67 #include "nx_crypto_huge_number.h"
68 #include "nx_crypto_ec.h"
69 
70 
71 #ifndef NX_CRYPTO_ECDSA_SCRATCH_BUFFER_SIZE
72 #define NX_CRYPTO_ECDSA_SCRATCH_BUFFER_SIZE 3016
73 #endif /* NX_CRYPTO_ECDSA_SCRATCH_BUFFER_SIZE */
74 
75 
76 /* ECDSA signature structure. */
77 typedef struct NX_CRYPTO_ECDSA
78 {
79     NX_CRYPTO_EC *nx_crypto_ecdsa_curve;
80     NX_CRYPTO_METHOD *nx_crypto_ecdsa_hash_method;
81     HN_UBASE      nx_crypto_ecdsa_scratch_buffer[NX_CRYPTO_ECDSA_SCRATCH_BUFFER_SIZE >> HN_SIZE_SHIFT];
82 } NX_CRYPTO_ECDSA;
83 
84 /* Define the function prototypes for ECDSA.  */
85 
86 UINT _nx_crypto_ecdsa_sign(NX_CRYPTO_EC *curve,
87                            UCHAR *hash,
88                            UINT hash_length,
89                            UCHAR *private_key,
90                            UINT private_key_length,
91                            UCHAR *signature,
92                            ULONG signature_length,
93                            ULONG *actual_signature_length,
94                            HN_UBASE *scratch);
95 
96 UINT _nx_crypto_ecdsa_verify(NX_CRYPTO_EC *curve,
97                              UCHAR *hash,
98                              UINT hash_length,
99                              UCHAR *public_key,
100                              UINT public_key_length,
101                              UCHAR *signature,
102                              UINT signature_length,
103                              HN_UBASE *scratch);
104 
105 UINT _nx_crypto_method_ecdsa_init(struct  NX_CRYPTO_METHOD_STRUCT *method,
106                                   UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
107                                   VOID  **handle,
108                                   VOID  *crypto_metadata,
109                                   ULONG crypto_metadata_size);
110 
111 UINT _nx_crypto_method_ecdsa_cleanup(VOID *crypto_metadata);
112 
113 UINT _nx_crypto_method_ecdsa_operation(UINT op,
114                                        VOID *handle,
115                                        struct NX_CRYPTO_METHOD_STRUCT *method,
116                                        UCHAR *key, NX_CRYPTO_KEY_SIZE key_size_in_bits,
117                                        UCHAR *input, ULONG input_length_in_byte,
118                                        UCHAR *iv_ptr,
119                                        UCHAR *output, ULONG output_length_in_byte,
120                                        VOID *crypto_metadata, ULONG crypto_metadata_size,
121                                        VOID *packet_ptr,
122                                        VOID (*nx_crypto_hw_process_callback)(VOID *, UINT));
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 #endif
128 
129