aes_gcm_encrypt.h 952 B

1234567891011121314151617181920212223242526
  1. #pragma once
  2. #include <cstddef>
  3. #include <span>
  4. #include "aes_gcm_decrypt.h"
  5. namespace sunrise::middleware::crypto::aes_gcm {
  6. /**
  7. * Encrypts one buffer and returns its tag apart from the ciphertext.
  8. * There is no additional authenticated data. The tag covers the ciphertext only.
  9. * @param key AES-128 key.
  10. * @param nonce 12-byte nonce.
  11. * @param plaintext Bytes to encrypt.
  12. * @param output Destination of at least the plaintext size.
  13. * @param tag Receives the full 16-byte authentication tag.
  14. * @return True only when the whole transform succeeds.
  15. */
  16. [[nodiscard]] bool encrypt(std::span<const std::byte, kKeySize> key,
  17. std::span<const std::byte, kNonceSize> nonce,
  18. std::span<const std::byte> plaintext,
  19. std::span<std::byte> output,
  20. std::span<std::byte, kTagSize> tag) noexcept;
  21. } // namespace sunrise::middleware::crypto::aes_gcm