chromium/third_party/anonymous_tokens/src/anonymous_tokens/cpp/crypto/crypto_utils.cc

// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "anonymous_tokens/cpp/crypto/crypto_utils.h"

#include <stddef.h>
#include <stdint.h>

#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "anonymous_tokens/cpp/crypto/constants.h"
#include "anonymous_tokens/cpp/shared/status_utils.h"
#include <openssl/base.h>
#include <openssl/bytestring.h>
#include <openssl/digest.h>
#include <openssl/err.h>
#include <openssl/hkdf.h>
#include <openssl/mem.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>

namespace anonymous_tokens {

namespace internal {

// Approximation of sqrt(2) taken from
// //depot/google3/third_party/openssl/boringssl/src/crypto/fipsmodule/rsa/rsa_impl.c;l=997
constexpr uint32_t kBoringSSLRSASqrtTwo[] =;

absl::StatusOr<bssl::UniquePtr<BIGNUM>> PublicMetadataHashWithHKDF(
    absl::string_view public_metadata, absl::string_view rsa_modulus_str,
    size_t out_len_bytes) {}

}  // namespace internal

namespace {

// Marshals an RSA public key in the DER format.
absl::StatusOr<std::string> MarshalRsaPublicKey(const RSA* rsa) {}

}  // namespace

absl::StatusOr<BnCtxPtr> GetAndStartBigNumCtx() {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> NewBigNum() {}

absl::StatusOr<std::string> BignumToString(const BIGNUM& big_num,
                                           const size_t output_len) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> StringToBignum(
    const absl::string_view input_str) {}

std::string GetSslErrors() {}

std::string MaskMessageConcat(absl::string_view mask,
                              absl::string_view message) {}

std::string EncodeMessagePublicMetadata(absl::string_view message,
                                        absl::string_view public_metadata) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> GetRsaSqrtTwo(int x) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> ComputePowerOfTwo(int x) {}

absl::StatusOr<std::string> ComputeHash(absl::string_view input,
                                        const EVP_MD& hasher) {}

absl::StatusOr<bssl::UniquePtr<RSA>> CreatePrivateKeyRSA(
    const absl::string_view rsa_modulus,
    const absl::string_view public_exponent,
    const absl::string_view private_exponent, const absl::string_view p,
    const absl::string_view q, const absl::string_view dp,
    const absl::string_view dq, const absl::string_view crt) {}

absl::StatusOr<bssl::UniquePtr<RSA>> CreatePublicKeyRSA(
    const absl::string_view rsa_modulus,
    const absl::string_view public_exponent) {}

absl::StatusOr<bssl::UniquePtr<RSA>> CreatePublicKeyRSAWithPublicMetadata(
    const BIGNUM& rsa_modulus, const BIGNUM& public_exponent,
    absl::string_view public_metadata, const bool use_rsa_public_exponent) {}

absl::StatusOr<bssl::UniquePtr<RSA>> CreatePublicKeyRSAWithPublicMetadata(
    const absl::string_view rsa_modulus,
    const absl::string_view public_exponent,
    const absl::string_view public_metadata,
    const bool use_rsa_public_exponent) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> ComputeCarmichaelLcm(
    const BIGNUM& phi_p, const BIGNUM& phi_q, BN_CTX& bn_ctx) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>> ComputeExponentWithPublicMetadata(
    const BIGNUM& n, absl::string_view public_metadata) {}

absl::StatusOr<bssl::UniquePtr<BIGNUM>>
ComputeExponentWithPublicMetadataAndPublicExponent(
    const BIGNUM& n, const BIGNUM& e, absl::string_view public_metadata) {}

absl::Status RsaBlindSignatureVerify(const int salt_length,
                                     const EVP_MD* sig_hash,
                                     const EVP_MD* mgf1_hash,
                                     const absl::string_view signature,
                                     const absl::string_view message,
                                     RSA* rsa_public_key) {}

absl::StatusOr<std::string> RsaSsaPssPublicKeyToDerEncoding(const RSA* rsa) {}

absl::StatusOr<bool> PrivacyPassTruncatedTokenKeyIdCollision(
    const RSA* public_key, const RSA* other_public_key) {}

}  // namespace anonymous_tokens