PK.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2020, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #ifndef KERNEL
  9. # include <AK/ByteString.h>
  10. #endif
  11. namespace Crypto::PK {
  12. // FIXME: Fixing name up for grabs
  13. template<typename PrivKeyT, typename PubKeyT>
  14. class PKSystem {
  15. public:
  16. using PublicKeyType = PubKeyT;
  17. using PrivateKeyType = PrivKeyT;
  18. PKSystem(PublicKeyType& pubkey, PrivateKeyType& privkey)
  19. : m_public_key(pubkey)
  20. , m_private_key(privkey)
  21. {
  22. }
  23. PKSystem() = default;
  24. virtual void encrypt(ReadonlyBytes in, Bytes& out) = 0;
  25. virtual void decrypt(ReadonlyBytes in, Bytes& out) = 0;
  26. virtual void sign(ReadonlyBytes in, Bytes& out) = 0;
  27. virtual void verify(ReadonlyBytes in, Bytes& out) = 0;
  28. #ifndef KERNEL
  29. virtual ByteString class_name() const = 0;
  30. #endif
  31. virtual size_t output_size() const = 0;
  32. protected:
  33. virtual ~PKSystem() = default;
  34. PublicKeyType m_public_key;
  35. PrivateKeyType m_private_key;
  36. };
  37. }