src/third_party/boringssl/src/crypto/evp/evp_test.cc
static bool SetupContext(FileTest *t, KeyMap *key_map, EVP_PKEY_CTX *ctx) {
  if (t->HasAttribute("RSAPadding")) {
    int padding;
    if (!GetRSAPadding(t, &padding, t->GetAttributeOrDie("RSAPadding")) ||
        !EVP_PKEY_CTX_set_rsa_padding(ctx, padding)) {
      return false;
    }
  }
  if (t->HasAttribute("PSSSaltLength") &&
      !EVP_PKEY_CTX_set_rsa_pss_saltlen(
          ctx, atoi(t->GetAttributeOrDie("PSSSaltLength").c_str()))) {
    return false;
  }
  if (t->HasAttribute("MGF1Digest")) {
    const EVP_MD *digest = GetDigest(t, t->GetAttributeOrDie("MGF1Digest"));
    if (digest == nullptr || !EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, digest)) {
      return false;
    }
  }
  if (t->HasAttribute("OAEPDigest")) {
    const EVP_MD *digest = GetDigest(t, t->GetAttributeOrDie("OAEPDigest"));
    if (digest == nullptr || !EVP_PKEY_CTX_set_rsa_oaep_md(ctx, digest)) {
      return false;
    }
  }
  if (t->HasAttribute("OAEPLabel")) {
    std::vector<uint8_t> label;
    if (!t->GetBytes(&label, "OAEPLabel")) {
      return false;
    }
    // For historical reasons, |EVP_PKEY_CTX_set0_rsa_oaep_label| expects to be
    // take ownership of the input.
    bssl::UniquePtr<uint8_t> buf(reinterpret_cast<uint8_t *>(
        OPENSSL_memdup(label.data(), label.size())));
    if (!buf ||
        !EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, buf.get(), label.size())) {
      return false;
    }
    buf.release();
  }
  if (t->HasAttribute("DerivePeer")) {
    std::string derive_peer = t->GetAttributeOrDie("DerivePeer");
    if (key_map->count(derive_peer) == 0) {
      ADD_FAILURE() << "Could not find key " << derive_peer;
      return false;
    }
    EVP_PKEY *derive_peer_key = (*key_map)[derive_peer].get();
    if (!EVP_PKEY_derive_set_peer(ctx, derive_peer_key)) {
      return false;
    }
  }
  return true;
}
// SetupContext configures |ctx| based on attributes in |t|, with the exception
// of the signing digest which must be configured externally.
SetupContext configures |ctx| based on attributes in |t|, with the exception
of the signing digest which must be configured externally.
SetupContext configures |ctx| based on attributes in |t| with the exception of the signing digest which must be configured externally .
static bool SetupContext(FileTest *t, KeyMap *key_map, EVP_PKEY_CTX *ctx) {
  if (t->HasAttribute("RSAPadding")) {
    int padding;
    if (!GetRSAPadding(t, &padding, t->GetAttributeOrDie("RSAPadding")) ||
        !EVP_PKEY_CTX_set_rsa_padding(ctx, padding)) {
      return false;
    }
  }
  if (t->HasAttribute("PSSSaltLength") &&
      !EVP_PKEY_CTX_set_rsa_pss_saltlen(
          ctx, atoi(t->GetAttributeOrDie("PSSSaltLength").c_str()))) {
    return false;
  }
  if (t->HasAttribute("MGF1Digest")) {
    const EVP_MD *digest = GetDigest(t, t->GetAttributeOrDie("MGF1Digest"));
    if (digest == nullptr || !EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, digest)) {
      return false;
    }
  }
  if (t->HasAttribute("OAEPDigest")) {
    const EVP_MD *digest = GetDigest(t, t->GetAttributeOrDie("OAEPDigest"));
    if (digest == nullptr || !EVP_PKEY_CTX_set_rsa_oaep_md(ctx, digest)) {
      return false;
    }
  }
  if (t->HasAttribute("OAEPLabel")) {
    std::vector<uint8_t> label;
    if (!t->GetBytes(&label, "OAEPLabel")) {
      return false;
    }
    bssl::UniquePtr<uint8_t> buf(reinterpret_cast<uint8_t *>(
        OPENSSL_memdup(label.data(), label.size())));
    if (!buf ||
        !EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, buf.get(), label.size())) {
      return false;
    }
    buf.release();
  }
  if (t->HasAttribute("DerivePeer")) {
    std::string derive_peer = t->GetAttributeOrDie("DerivePeer");
    if (key_map->count(derive_peer) == 0) {
      ADD_FAILURE() << "Could not find key " << derive_peer;
      return false;
    }
    EVP_PKEY *derive_peer_key = (*key_map)[derive_peer].get();
    if (!EVP_PKEY_derive_set_peer(ctx, derive_peer_key)) {
      return false;
    }
  }
  return true;
}
static bool SetupContext ( FileTest * t , KeyMap * key_map , EVP_PKEY_CTX * ctx ) { if ( t -> HasAttribute ( " " ) ) { int padding ; if ( ! GetRSAPadding ( t , & padding , t -> GetAttributeOrDie ( " " ) ) || ! EVP_PKEY_CTX_set_rsa_padding ( ctx , padding ) ) { return false ; } } if ( t -> HasAttribute ( " " ) && ! EVP_PKEY_CTX_set_rsa_pss_saltlen ( ctx , atoi ( t -> GetAttributeOrDie ( " " ) . c_str ( ) ) ) ) { return false ; } if ( t -> HasAttribute ( " " ) ) { const EVP_MD * digest = GetDigest ( t , t -> GetAttributeOrDie ( " " ) ) ; if ( digest == nullptr || ! EVP_PKEY_CTX_set_rsa_mgf1_md ( ctx , digest ) ) { return false ; } } if ( t -> HasAttribute ( " " ) ) { const EVP_MD * digest = GetDigest ( t , t -> GetAttributeOrDie ( " " ) ) ; if ( digest == nullptr || ! EVP_PKEY_CTX_set_rsa_oaep_md ( ctx , digest ) ) { return false ; } } if ( t -> HasAttribute ( " " ) ) { std :: vector < uint8_t > label ; if ( ! t -> GetBytes ( & label , " " ) ) { return false ; } bssl :: UniquePtr < uint8_t > buf ( reinterpret_cast < uint8_t * > ( OPENSSL_memdup ( label . data ( ) , label . size ( ) ) ) ) ; if ( ! buf || ! EVP_PKEY_CTX_set0_rsa_oaep_label ( ctx , buf . get ( ) , label . size ( ) ) ) { return false ; } buf . release ( ) ; } if ( t -> HasAttribute ( " " ) ) { std :: string derive_peer = t -> GetAttributeOrDie ( " " ) ; if ( key_map -> count ( derive_peer ) == 0 ) { ADD_FAILURE ( ) << " " << derive_peer ; return false ; } EVP_PKEY * derive_peer_key = ( * key_map ) [ derive_peer ] . get ( ) ; if ( ! EVP_PKEY_derive_set_peer ( ctx , derive_peer_key ) ) { return false ; } } return true ; }
SetupContext configures |ctx| based on attributes in |t|, with the exception
of the signing digest which must be configured externally.
SetupContext configures |ctx| based on attributes in |t| with the exception of the signing digest which must be configured externally .
// For historical reasons, |EVP_PKEY_CTX_set0_rsa_oaep_label| expects to be // take ownership of the input.