C/C++ API Reference
Loading...
Searching...
No Matches
chacha20.h
1// Copyright 2026 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#pragma once
16
17#include <cstddef>
18#include <cstdint>
19
20#include "pw_bytes/span.h"
21#include "pw_crypto/chacha20_backend.h"
22#include "pw_status/status.h"
23
24namespace pw::crypto {
25
30namespace chacha20 {
31
32inline constexpr size_t kKeySizeBytes = 32; // 256 bits
33inline constexpr size_t kNonceSizeBytes = 12; // 96 bits
34
53 span<std::byte> output) {
54 if (key.size() != kKeySizeBytes) {
56 }
57 if (nonce.size() != kNonceSizeBytes) {
59 }
60 if (output.size() < input.size()) {
62 }
63
64 return backend::DoChaCha20Crypt(key, nonce, input, output);
65}
66
67} // namespace chacha20
68} // namespace pw::crypto
Definition: status.h:120
static constexpr Status InvalidArgument()
Definition: status.h:164
Definition: span_impl.h:235
Status Crypt(span< const std::byte > key, span< const std::byte > nonce, span< const std::byte > input, span< std::byte > output)
Definition: chacha20.h:50
Cryptography library.
Definition: chacha20.h:24