Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:14

0001 /* chacha-poly1305.h
0002 
0003    AEAD mechanism based on chacha and poly1305.
0004    See draft-agl-tls-chacha20poly1305-04.
0005 
0006    Copyright (C) 2014 Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034 
0035 #ifndef NETTLE_CHACHA_POLY1305_H_INCLUDED
0036 #define NETTLE_CHACHA_POLY1305_H_INCLUDED
0037 
0038 #include "chacha.h"
0039 #include "poly1305.h"
0040 
0041 #ifdef __cplusplus
0042 extern "C" {
0043 #endif
0044 
0045 /* Name mangling */
0046 #define chacha_poly1305_set_key nettle_chacha_poly1305_set_key
0047 #define chacha_poly1305_set_nonce nettle_chacha_poly1305_set_nonce
0048 #define chacha_poly1305_update nettle_chacha_poly1305_update
0049 #define chacha_poly1305_decrypt nettle_chacha_poly1305_decrypt
0050 #define chacha_poly1305_encrypt nettle_chacha_poly1305_encrypt
0051 #define chacha_poly1305_digest nettle_chacha_poly1305_digest
0052 
0053 #define CHACHA_POLY1305_BLOCK_SIZE 64
0054 /* FIXME: Any need for 128-bit variant? */
0055 #define CHACHA_POLY1305_KEY_SIZE 32
0056 #define CHACHA_POLY1305_NONCE_SIZE CHACHA_NONCE96_SIZE
0057 #define CHACHA_POLY1305_DIGEST_SIZE 16
0058 
0059 struct chacha_poly1305_ctx
0060 {
0061   struct chacha_ctx chacha;
0062   struct poly1305_ctx poly1305;
0063   union nettle_block16 s;
0064   uint64_t auth_size;
0065   uint64_t data_size;
0066   /* poly1305 block */
0067   uint8_t block[POLY1305_BLOCK_SIZE];
0068   unsigned index;
0069 };
0070 
0071 void
0072 chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
0073              const uint8_t *key);
0074 void
0075 chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
0076                const uint8_t *nonce);
0077 
0078 void
0079 chacha_poly1305_update (struct chacha_poly1305_ctx *ctx,
0080             size_t length, const uint8_t *data);
0081 
0082 void
0083 chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
0084              size_t length, uint8_t *dst, const uint8_t *src);
0085              
0086 void
0087 chacha_poly1305_decrypt (struct chacha_poly1305_ctx *ctx,
0088              size_t length, uint8_t *dst, const uint8_t *src);
0089              
0090 void
0091 chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
0092             size_t length, uint8_t *digest);
0093 
0094 #ifdef __cplusplus
0095 }
0096 #endif
0097 
0098 #endif /* NETTLE_CHACHA_POLY1305_H_INCLUDED */