1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ANONYMOUS_TOKENS_CPP_CRYPTO_ANONYMOUS_TOKENS_PB_OPENSSL_CONVERTERS_H_
16 #define ANONYMOUS_TOKENS_CPP_CRYPTO_ANONYMOUS_TOKENS_PB_OPENSSL_CONVERTERS_H_
17 
18 #include <string>
19 
20 #include "absl/status/statusor.h"
21 #include "anonymous_tokens/proto/anonymous_tokens.pb.h"
22 #include <openssl/base.h>
23 
24 namespace anonymous_tokens {
25 
26 // Generate a message mask. For more details, see
27 // https://datatracker.ietf.org/doc/draft-irtf-cfrg-rsa-blind-signatures/
28 absl::StatusOr<std::string> GenerateMask(
29     const RSABlindSignaturePublicKey& public_key);
30 
31 // Converts the AnonymousTokens proto hash type to the equivalent EVP digest.
32 absl::StatusOr<const EVP_MD*>
33 ProtoHashTypeToEVPDigest(HashType hash_type);
34 
35 // Converts the AnonymousTokens proto hash type for mask generation function to
36 // the equivalent EVP digest.
37 absl::StatusOr<const EVP_MD*>
38 ProtoMaskGenFunctionToEVPDigest(MaskGenFunction mgf);
39 
40 // Converts AnonymousTokens::RSAPrivateKey to bssl::UniquePtr<RSA> without
41 // public metadata augmentation.
42 absl::StatusOr<bssl::UniquePtr<RSA>>
43 AnonymousTokensRSAPrivateKeyToRSA(const RSAPrivateKey& private_key);
44 
45 // Converts AnonymousTokens::RSAPublicKey to bssl::UniquePtr<RSA> without
46 // public metadata augmentation.
47 absl::StatusOr<bssl::UniquePtr<RSA>>
48 AnonymousTokensRSAPublicKeyToRSA(const RSAPublicKey& public_key);
49 
50 }  // namespace anonymous_tokens
51 
52 #endif  // ANONYMOUS_TOKENS_CPP_CRYPTO_ANONYMOUS_TOKENS_PB_OPENSSL_CONVERTERS_H_
53