MCCI TweetNaCl
TweetNaCl library adapted for embedded use
mcci_tweetnacl_onetimeauth.h
Go to the documentation of this file.
1 /*
2 
3 Module: mcci_tweetnacl_onetimeauth.h
4 
5 Function:
6  MCCI TweetNaCl equivalent of "crypto_onetimeauth.h"
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  fullname, MCCI Corporation March 2021
19 
20 */
21 
22 #ifndef _mcci_tweetnacl_onetimeauth_h_
23 #define _mcci_tweetnacl_onetimeauth_h_ /* prevent multiple includes */
24 
25 #pragma once
26 
27 #include "mcci_tweetnacl.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /****************************************************************************\
34 |
35 | Meta
36 |
37 \****************************************************************************/
38 
39 /// \addtogroup secret-key-crypto Secret-key cryptography
40 /// @{
41 /// \addtogroup crypto-stream One-time authentication
42 /// @{
43 
44 /****************************************************************************\
45 |
46 | Forward types
47 |
48 \****************************************************************************/
49 
50 /// \brief abstract type for crypto keys
51 typedef struct
52  {
53  /// the bytes of the key
54  unsigned char bytes[32];
56 
57 /// \brief abstract type for crypto authenticators
58 typedef struct
59  {
60  /// bytes of the authenticator
61  unsigned char bytes[16];
63 
64 ///
65 /// \brief Generate one-time authenticator for a given message and secret key
66 ///
67 /// \param[out] pAuth set to the authenticator code.
68 /// \param[in] pMessage the message to be authenticated.
69 /// \param[in] nMessage number of bytes in the message.
70 /// \param[in] pKey the secret key
71 ///
72 /// \see https://nacl.cr.yp.to/onetimeauth.html
73 ///
74 static inline void
77  const unsigned char *pMessage,
78  size_t nMessage,
80  )
81  {
82  extern int crypto_onetimeauth_poly1305_tweet(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
83  (void) crypto_onetimeauth_poly1305_tweet(
84  pAuth->bytes,
85  pMessage,
86  nMessage,
87  pKey->bytes
88  );
89  }
90 
91 ///
92 /// \brief Verify message given one-time authenticator and secret key
93 ///
94 /// \param[out] pAuth set to the authenticator code.
95 /// \param[in] pMessage the message to be authenticated.
96 /// \param[in] nMessage number of bytes in the message.
97 /// \param[in] pKey the secret key
98 ///
99 /// \returns zero if valid, non-zero otherwise.
100 ///
101 /// \see https://nacl.cr.yp.to/onetimeauth.html
102 ///
103 static inline mcci_tweetnacl_result_t
106  const unsigned char *pMessage,
107  size_t nMessage,
109  )
110  {
111  extern int crypto_onetimeauth_poly1305_tweet_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
112  return crypto_onetimeauth_poly1305_tweet_verify(
113  pAuth->bytes,
114  pMessage,
115  nMessage,
116  pKey->bytes
117  );
118  }
119 
120 /****************************************************************************\
121 |
122 | Post-Meta
123 |
124 \****************************************************************************/
125 
126 //--- close groups ---
127 /// @}
128 /// @}
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* _mcci_tweetnacl_onetimeauth_h_ */
mcci_tweetnacl_result_t
int mcci_tweetnacl_result_t
symbolic type for result of TweetNaCl primitives
Definition: mcci_tweetnacl.h:92
mcci_tweetnacl_onetimeauth_authenticator_t::bytes
unsigned char bytes[16]
bytes of the authenticator
Definition: mcci_tweetnacl_onetimeauth.h:61
mcci_tweetnacl_onetimeauth_authenticator_t
abstract type for crypto authenticators
Definition: mcci_tweetnacl_onetimeauth.h:59
mcci_tweetnacl_onetimeauth
static void mcci_tweetnacl_onetimeauth(mcci_tweetnacl_onetimeauth_authenticator_t *pAuth, const unsigned char *pMessage, size_t nMessage, const mcci_tweetnacl_onetimeauth_key_t *pKey)
Generate one-time authenticator for a given message and secret key.
Definition: mcci_tweetnacl_onetimeauth.h:75
mcci_tweetnacl_onetimeauth_key_t::bytes
unsigned char bytes[32]
the bytes of the key
Definition: mcci_tweetnacl_onetimeauth.h:54
mcci_tweetnacl.h
mcci_tweetnacl_onetimeauth_verify
static mcci_tweetnacl_result_t mcci_tweetnacl_onetimeauth_verify(const mcci_tweetnacl_onetimeauth_authenticator_t *pAuth, const unsigned char *pMessage, size_t nMessage, const mcci_tweetnacl_onetimeauth_key_t *pKey)
Verify message given one-time authenticator and secret key.
Definition: mcci_tweetnacl_onetimeauth.h:104
mcci_tweetnacl_onetimeauth_key_t
abstract type for crypto keys
Definition: mcci_tweetnacl_onetimeauth.h:52