/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 (index > 0) |
61 | 0 | { |
62 | | /* Try to fill partial block */ |
63 | 0 | MD_FILL_OR_RETURN_INDEX (POLY1305_BLOCK_SIZE, block, index, |
64 | 0 | length, m); |
65 | 0 | _nettle_poly1305_block(ctx, block, 1); |
66 | 0 | } |
67 | 0 | #if HAVE_NATIVE_poly1305_blocks |
68 | 0 | m = _nettle_poly1305_blocks (ctx, length >> 4, m); |
69 | 0 | length &= 15; |
70 | | #else |
71 | | for (; length >= POLY1305_BLOCK_SIZE; |
72 | | length -= POLY1305_BLOCK_SIZE, m += POLY1305_BLOCK_SIZE) |
73 | | _nettle_poly1305_block (ctx, m, 1); |
74 | | #endif |
75 | |
|
76 | 0 | memcpy (block, m, length); |
77 | 0 | return length; |
78 | 0 | } |