MCCI TweetNaCl
TweetNaCl library adapted for embedded use
mcci_tweetnacl_auth.h
Go to the documentation of this file.
1 /*
2 
3 Module: mcci_tweetnacl_auth.h
4 
5 Function:
6  Like NaCl "crypto_auth.h" for MCCI TweetNaCl
7 
8 Copyright and License:
9  This file copyright (C) 2021 by
10 
11  MCCI Corporation
12  3520 Krums Corners Road
13  Ithaca, NY 14850
14 
15  See accompanying LICENSE file for copyright and license information.
16 
17 Author:
18  Terry Moore, MCCI Corporation March 2021
19 
20 */
21 
22 #ifndef _mcci_tweetnacl_auth_h_
23 #define _mcci_tweetnacl_auth_h_ /* prevent multiple includes */
24 
25 #pragma once
26 
27 #ifndef _mcci_tweetnacl_h_
28 # include "mcci_tweetnacl.h"
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /****************************************************************************\
36 |
37 | Meta
38 |
39 \****************************************************************************/
40 
41 /// \addtogroup secret-key-crypto Secret-key cryptography
42 /// @{
43 /// \addtogroup crypto-auth Authentication
44 /// @{
45 
46 /****************************************************************************\
47 |
48 | Forward types
49 |
50 \****************************************************************************/
51 
52 /// \brief abstract type for auth keys
53 typedef struct mcci_tweetnacl_auth_key_s mcci_tweetnacl_auth_key_t;
55  {
56  /// the private key for generating auth keys.
57  unsigned char bytes[32];
58  };
59 
60 /// \brief abstract type for authenticators
61 typedef struct mcci_tweetnacl_auth_authenticator_s
62  {
63  unsigned char bytes[64];
65 
66 /****************************************************************************\
67 |
68 | APIs
69 |
70 \****************************************************************************/
71 
72 ///
73 /// \brief Secret-key message authentication: generate authenticator (HMAC)
74 ///
75 /// \param[out] pAuth is set to the authenticator
76 /// \param[in] pMessage is the message to be hashed
77 /// \param[in] nMessage is the length of the message in bytes
78 /// \param[in] pKey is the secret key to be used for generating the authenticator.
79 ///
80 /// \see https://nacl.cr.yp.to/auth.html
81 ///
82 static inline void
85  const unsigned char *pMessage,
86  size_t nMessage,
87  const mcci_tweetnacl_auth_key_t *pKey
88  )
89  {
90  extern int crypto_auth_hmacsha512256_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
91  (void) crypto_auth_hmacsha512256_tweet(
92  pAuth->bytes,
93  pMessage,
94  nMessage,
95  pKey->bytes
96  );
97  }
98 
99 ///
100 /// \brief Secret-key message authentication: verify authenticity (HMAC)
101 ///
102 /// \param[in] pAuth is the authenticator
103 /// \param[in] pMessage is the message to be checked
104 /// \param[in] nMessage is the length of the message in bytes
105 /// \param[in] pKey is the secret key that was used to generate the authenticator.
106 ///
107 /// \returns zero if message passes the test, -1 otherwise.
108 ///
109 /// \see https://nacl.cr.yp.to/auth.html
110 ///
111 static inline mcci_tweetnacl_result_t
114  const unsigned char *pMessage,
115  size_t nMessage,
116  const mcci_tweetnacl_auth_key_t *pKey
117  )
118  {
119  extern int crypto_auth_hmacsha512256_tweet_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
120  return crypto_auth_hmacsha512256_tweet_verify(
121  pAuth->bytes,
122  pMessage,
123  nMessage,
124  pKey->bytes
125  );
126  }
127 
128 /****************************************************************************\
129 |
130 | Post-Meta
131 |
132 \****************************************************************************/
133 
134 //--- close groups ---
135 /// @}
136 /// @}
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* _mcci_tweetnacl_auth_h_ */
mcci_tweetnacl_result_t
int mcci_tweetnacl_result_t
symbolic type for result of TweetNaCl primitives
Definition: mcci_tweetnacl.h:92
mcci_tweetnacl_auth_key_s::bytes
unsigned char bytes[32]
the private key for generating auth keys.
Definition: mcci_tweetnacl_auth.h:57
mcci_tweetnacl_auth_key_s
abstract type for auth keys
Definition: mcci_tweetnacl_auth.h:55
mcci_tweetnacl_auth_authenticator_t
abstract type for authenticators
Definition: mcci_tweetnacl_auth.h:62
mcci_tweetnacl_auth
static void mcci_tweetnacl_auth(mcci_tweetnacl_auth_authenticator_t *pAuth, const unsigned char *pMessage, size_t nMessage, const mcci_tweetnacl_auth_key_t *pKey)
Secret-key message authentication: generate authenticator (HMAC)
Definition: mcci_tweetnacl_auth.h:83
mcci_tweetnacl_auth_authenticator_t::bytes
unsigned char bytes[64]
Definition: mcci_tweetnacl_auth.h:63
mcci_tweetnacl.h
mcci_tweetnacl_auth_verify
static mcci_tweetnacl_result_t mcci_tweetnacl_auth_verify(const mcci_tweetnacl_auth_authenticator_t *pAuth, const unsigned char *pMessage, size_t nMessage, const mcci_tweetnacl_auth_key_t *pKey)
Secret-key message authentication: verify authenticity (HMAC)
Definition: mcci_tweetnacl_auth.h:112