Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
crypto
poly1305.h
Go to the documentation of this file.
1
// Copyright (c) 2019-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_CRYPTO_POLY1305_H
6
#define BITCOIN_CRYPTO_POLY1305_H
7
8
#include <
span.h
>
9
10
#include <cassert>
11
#include <cstddef>
12
#include <cstdint>
13
#include <span>
14
15
#define POLY1305_BLOCK_SIZE 16
16
17
namespace
poly1305_donna
{
18
19
// Based on the public domain implementation by Andrew Moon
20
// poly1305-donna-32.h from https://github.com/floodyberry/poly1305-donna
21
22
typedef
struct
{
23
uint32_t
r
[5];
24
uint32_t
h
[5];
25
uint32_t
pad
[4];
26
size_t
leftover
;
27
unsigned
char
buffer
[
POLY1305_BLOCK_SIZE
];
28
unsigned
char
final
;
29
}
poly1305_context
;
30
31
void
poly1305_init
(
poly1305_context
*st,
const
unsigned
char
key[32])
noexcept
;
32
void
poly1305_update
(
poly1305_context
*st,
const
unsigned
char
*
m
,
size_t
bytes)
noexcept
;
33
void
poly1305_finish
(
poly1305_context
*st,
unsigned
char
mac[16])
noexcept
;
34
35
}
// namespace poly1305_donna
36
38
class
Poly1305
39
{
40
poly1305_donna::poly1305_context
m_ctx
;
41
42
public
:
44
static
constexpr
unsigned
TAGLEN
{16};
45
47
static
constexpr
unsigned
KEYLEN
{32};
48
50
Poly1305
(std::span<const std::byte> key)
noexcept
51
{
52
assert
(key.size() ==
KEYLEN
);
53
poly1305_donna::poly1305_init
(&
m_ctx
,
UCharCast
(key.data()));
54
}
55
57
Poly1305
&
Update
(std::span<const std::byte> msg)
noexcept
58
{
59
poly1305_donna::poly1305_update
(&
m_ctx
,
UCharCast
(msg.data()), msg.size());
60
return
*
this
;
61
}
62
64
void
Finalize
(std::span<std::byte> out)
noexcept
65
{
66
assert
(out.size() ==
TAGLEN
);
67
poly1305_donna::poly1305_finish
(&
m_ctx
,
UCharCast
(out.data()));
68
}
69
};
70
71
#endif
// BITCOIN_CRYPTO_POLY1305_H
Poly1305::Poly1305
Poly1305(std::span< const std::byte > key) noexcept
Construct a Poly1305 object with a given 32-byte key.
Definition
poly1305.h:50
Poly1305::Finalize
void Finalize(std::span< std::byte > out) noexcept
Write authentication tag to 16-byte out.
Definition
poly1305.h:64
Poly1305::m_ctx
poly1305_donna::poly1305_context m_ctx
Definition
poly1305.h:40
Poly1305::Update
Poly1305 & Update(std::span< const std::byte > msg) noexcept
Process message bytes.
Definition
poly1305.h:57
Poly1305::KEYLEN
static constexpr unsigned KEYLEN
Length of the keys expected by the constructor.
Definition
poly1305.h:47
Poly1305::TAGLEN
static constexpr unsigned TAGLEN
Length of the output produced by Finalize().
Definition
poly1305.h:44
poly1305_donna
Definition
poly1305.cpp:8
poly1305_donna::poly1305_update
void poly1305_update(poly1305_context *st, const unsigned char *m, size_t bytes) noexcept
Definition
poly1305.cpp:184
poly1305_donna::poly1305_init
void poly1305_init(poly1305_context *st, const unsigned char key[32]) noexcept
Definition
poly1305.cpp:13
poly1305_donna::poly1305_finish
void poly1305_finish(poly1305_context *st, unsigned char mac[16]) noexcept
Definition
poly1305.cpp:98
POLY1305_BLOCK_SIZE
#define POLY1305_BLOCK_SIZE
Definition
poly1305.h:15
span.h
UCharCast
unsigned char * UCharCast(char *c)
Definition
span.h:95
ByteUnit::m
@ m
Definition
strencodings.h:48
poly1305_donna::poly1305_context
Definition
poly1305.h:22
poly1305_donna::poly1305_context::h
uint32_t h[5]
Definition
poly1305.h:24
poly1305_donna::poly1305_context::pad
uint32_t pad[4]
Definition
poly1305.h:25
poly1305_donna::poly1305_context::leftover
size_t leftover
Definition
poly1305.h:26
poly1305_donna::poly1305_context::buffer
unsigned char buffer[POLY1305_BLOCK_SIZE]
Definition
poly1305.h:27
poly1305_donna::poly1305_context::r
uint32_t r[5]
Definition
poly1305.h:23
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0