Skip to content

Commit 50e52d0

Browse files
karel-msjaeckel
authored andcommitted
poly1305 doc
1 parent 11827fe commit 50e52d0

1 file changed

Lines changed: 59 additions & 11 deletions

File tree

doc/crypt.tex

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,21 +3282,69 @@ \subsection{F9--MAC Functions}
32823282
This will return \textbf{CRYPT\_OK} on success. This requires the AES or Rijndael descriptor be previously registered, otherwise, it will return
32833283
\textbf{CRYPT\_NOP}.
32843284

3285-
\mysection{Poly1305 MAC}
3285+
\mysection{Poly1305--MAC}
32863286

3287-
XXX-TODO see \url{https://en.wikipedia.org/wiki/Poly1305}
3287+
The Poly1305--MAC is a cryptographic message authentication code created by Daniel J. Bernstein.
3288+
More info at \url{https://en.wikipedia.org/wiki/Poly1305}.
32883289

3289-
\begin{small}
3290+
\subsection{Poly1305--MAC Functions}
3291+
3292+
A Poly1305--MAC state is initialized with the following function:
3293+
\index{poly1305\_init()}
32903294
\begin{verbatim}
3291-
int poly1305_init(poly1305_state *st, const unsigned char *key, unsigned long keylen);
3292-
int poly1305_process(poly1305_state *st, const unsigned char *in, unsigned long inlen);
3293-
int poly1305_done(poly1305_state *st, unsigned char *mac, unsigned long *maclen);
3294-
int poly1305_test(void);
3295-
int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
3296-
int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...);
3297-
int poly1305_file(const char *fname, const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen);
3295+
int poly1305_init( poly1305_state *st,
3296+
const unsigned char *key,
3297+
unsigned long keylen);
32983298
\end{verbatim}
3299-
\end{small}
3299+
This will initialize the Poly1305--MAC state \textit{st}, with the key specified in \textit{key} of length \textit{keylen} octets (always 32).
3300+
3301+
To process data through Poly1305--MAC use the following function:
3302+
\index{poly1305\_process()}
3303+
\begin{verbatim}
3304+
int poly1305_process( poly1305_state *st,
3305+
const unsigned char *in,
3306+
unsigned long inlen);
3307+
\end{verbatim}
3308+
3309+
This will add the message octets pointed to by \textit{in} of length \textit{inlen} to the Poly1305--MAC state pointed to by \textit{st}.
3310+
3311+
To compute the MAC tag value use the following function:
3312+
\index{poly1305\_done()}
3313+
\begin{verbatim}
3314+
int poly1305_done(poly1305_state *st,
3315+
unsigned char *mac,
3316+
unsigned long *maclen);
3317+
\end{verbatim}
3318+
3319+
This will retrieve the Poly1305--MAC tag from the state pointed to by \textit{st}, and store it in the array pointed to by \textit{mac}.
3320+
The \textit{maclen} parameter specifies the maximum size of the destination buffer, and is updated to hold the final size of the tag when
3321+
the function returns.
3322+
3323+
Helper functions are provided to make parsing memory buffers and files easier. The following functions are provided:
3324+
\index{poly1305\_memory()}
3325+
\begin{verbatim}
3326+
int poly1305_memory(const unsigned char *key,
3327+
unsigned long keylen,
3328+
const unsigned char *in,
3329+
unsigned long inlen,
3330+
unsigned char *mac,
3331+
unsigned long *maclen);
3332+
\end{verbatim}
3333+
This will compute the Poly1305--MAC of \textit{inlen} bytes of \textit{in}, using the key \textit{key} of length \textit{keylen} bytes.
3334+
It will store the MAC in \textit{mac} with the same rules as poly1305\_done().
3335+
3336+
To Poly1305--MAC a file use
3337+
\index{poly1305\_file()}
3338+
\begin{verbatim}
3339+
int poly1305_file( const char *fname,
3340+
const unsigned char *key,
3341+
unsigned long keylen,
3342+
unsigned char *mac,
3343+
unsigned long *maclen);
3344+
\end{verbatim}
3345+
3346+
Which will Poly1305--MAC the entire contents of the file specified by \textit{fname} using the key \textit{key} of
3347+
length \textit{keylen} bytes. It will store the MAC in \textit{mac} with the same rules as poly1305\_done().
33003348

33013349
\mysection{BLAKE2s + BLAKE2b MAC}
33023350

0 commit comments

Comments
 (0)