Botan 3.14.1
Crypto and TLS for C&
p11_sig_stream.h
Go to the documentation of this file.
1/*
2* PKCS#11 Signature Streaming
3* (C) 2026 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_P11_SIG_STREAM_H_
9#define BOTAN_P11_SIG_STREAM_H_
10
11#include <botan/p11_mechanism.h>
12#include <botan/p11_object.h>
13#include <span>
14#include <vector>
15
16namespace Botan::PKCS11 {
17
18/**
19* Maps the streaming update() interface of a signature or verification
20* operation onto the PKCS #11 single and multiple part functions.
21*
22* Input is buffered until a second nonempty update() call so that the common case
23* of a single update() uses C_Sign/C_Verify. Mechanisms which only support
24* single part operations (such as CKM_ECDSA) always buffer the entire input.
25*
26* The token operation is only initialized once it is actually needed, and an
27* abandoned multiple part operation is terminated on destruction so the
28* session remains usable.
29*/
30class Signature_Stream final {
31 public:
32 enum class Direction : uint8_t { Sign, Verify };
33
34 /**
35 * @param direction whether signatures are created or verified
36 * @param key the key object; must outlive this object
37 * @param mechanism the mechanism; must outlive this object
38 */
39 Signature_Stream(Direction direction, const Object& key, const MechanismWrapper& mechanism);
40
41 ~Signature_Stream() noexcept;
42
44 Signature_Stream& operator=(const Signature_Stream&) = delete;
46 Signature_Stream& operator=(Signature_Stream&&) = delete;
47
48 void update(std::span<const uint8_t> input);
49
50 /// Only valid for Direction::Sign
51 std::vector<uint8_t> sign();
52
53 /// Only valid for Direction::Verify
54 bool verify(std::span<const uint8_t> signature);
55
56 private:
57 void init();
58 void update_token(std::span<const uint8_t> input);
59
60 const Direction m_direction;
61 const Object& m_key;
62 const MechanismWrapper& m_mechanism;
63 const bool m_single_part_only;
64 secure_vector<uint8_t> m_buffer;
65 bool m_multipart_active = false;
66};
67
68} // namespace Botan::PKCS11
69
70#endif
Signature_Stream(Direction direction, const Object &key, const MechanismWrapper &mechanism)
void update(std::span< const uint8_t > input)
bool verify(std::span< const uint8_t > signature)
Only valid for Direction::Verify.
std::vector< uint8_t > sign()
Only valid for Direction::Sign.
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128