/src/nettle/poly1305-update.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* poly1305-update.c  | 
2  |  |  | 
3  |  |    Copyright (C) 2022 Niels Möller  | 
4  |  |  | 
5  |  |    This file is part of GNU Nettle.  | 
6  |  |  | 
7  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
8  |  |    modify it under the terms of either:  | 
9  |  |  | 
10  |  |      * the GNU Lesser General Public License as published by the Free  | 
11  |  |        Software Foundation; either version 3 of the License, or (at your  | 
12  |  |        option) any later version.  | 
13  |  |  | 
14  |  |    or  | 
15  |  |  | 
16  |  |      * the GNU General Public License as published by the Free  | 
17  |  |        Software Foundation; either version 2 of the License, or (at your  | 
18  |  |        option) any later version.  | 
19  |  |  | 
20  |  |    or both in parallel, as here.  | 
21  |  |  | 
22  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
23  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
24  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
25  |  |    General Public License for more details.  | 
26  |  |  | 
27  |  |    You should have received copies of the GNU General Public License and  | 
28  |  |    the GNU Lesser General Public License along with this program.  If  | 
29  |  |    not, see http://www.gnu.org/licenses/.  | 
30  |  | */  | 
31  |  |  | 
32  |  | #if HAVE_CONFIG_H  | 
33  |  | #include "config.h"  | 
34  |  | #endif  | 
35  |  |  | 
36  |  | #include "poly1305.h"  | 
37  |  | #include "poly1305-internal.h"  | 
38  |  | #include "md-internal.h"  | 
39  |  |  | 
40  |  | #if HAVE_NATIVE_fat_poly1305_blocks  | 
41  |  | const uint8_t *  | 
42  |  | _nettle_poly1305_blocks_c(struct poly1305_ctx *ctx,  | 
43  |  |          size_t blocks, const uint8_t *m);  | 
44  |  |  | 
45  |  | const uint8_t *  | 
46  |  | _nettle_poly1305_blocks_c(struct poly1305_ctx *ctx,  | 
47  |  |          size_t blocks, const uint8_t *m)  | 
48  |  | { | 
49  |  |   for (; blocks; blocks--, m += POLY1305_BLOCK_SIZE)  | 
50  |  |     _nettle_poly1305_block(ctx, m, 1);  | 
51  |  |   return m;  | 
52  |  | }  | 
53  |  | #endif  | 
54  |  |  | 
55  |  | unsigned  | 
56  |  | _nettle_poly1305_update (struct poly1305_ctx *ctx,  | 
57  |  |        uint8_t *block, unsigned index,  | 
58  |  |        size_t length, const uint8_t *m)  | 
59  | 0  | { | 
60  | 0  |   if (!length)  | 
61  | 0  |     return index;  | 
62  |  |  | 
63  | 0  |   if (index > 0)  | 
64  | 0  |     { | 
65  |  |       /* Try to fill partial block */  | 
66  | 0  |       MD_FILL_OR_RETURN_INDEX (POLY1305_BLOCK_SIZE, block, index,  | 
67  | 0  |              length, m);  | 
68  | 0  |       _nettle_poly1305_block(ctx, block, 1);  | 
69  | 0  |     }  | 
70  |  | #if HAVE_NATIVE_poly1305_blocks  | 
71  |  |   m = _nettle_poly1305_blocks (ctx, length >> 4, m);  | 
72  |  |   length &= 15;  | 
73  |  | #else  | 
74  | 0  |   for (; length >= POLY1305_BLOCK_SIZE;  | 
75  | 0  |        length -= POLY1305_BLOCK_SIZE, m += POLY1305_BLOCK_SIZE)  | 
76  | 0  |     _nettle_poly1305_block (ctx, m, 1);  | 
77  | 0  | #endif  | 
78  |  | 
  | 
79  | 0  |   memcpy (block, m, length);  | 
80  | 0  |   return length;  | 
81  | 0  | }  |