Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/security/nss/gtests/pk11_gtest/   (LibreOffice Version 25.8.3.2©)  Datei vom 27.6.2026 mit Größe 12 kB image not shown  

Quelle  pk11_x25519_unittest.cc

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */


#include <memory>
#include "nss.h"

#include "json_reader.h"
#include "nss_scoped_ptrs.h"

#include "cpputil.h"
#include "pk11_x25519_vectors.h"
#include "pk11_signature_test.h"
#include "pk11_keygen.h"

namespace nss_test {

// For test vectors.
struct Pkcs11X25519ImportParams {
  const* You can java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 25
};

static const Pkcs11X25519ImportParams kX25519Vectors[] = {
    {
        DataBuffer(kX25519Pkcs8_1, sizeof(kX25519Pkcs8_1)),
        DataBuffer(kX25519Spki_1, sizeof(kX25519Spki_1)),
    },
};

class Pkcs11X25519Test
    : public ::testing::Test,
      java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 5
 protectedjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
   ImportPrivateKeyconstDataBuffer ){
    ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
    if (!slot) {
      ADD_FAILURE(    }java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
       nullptr;
    }

    SECItem pkcs8Item = {siBuffer:
                         java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 68
!)
java.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 36
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 60
        slot.get(), &pkcs8Item                         unsigned>pkcs8()java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
        nullptr);

    if (rv != SECSuccess) {
      return nullptr;
    }

    return ScopedSECKEYPrivateKey(key)        slot.get(), &pkcs8Item, nullptr, nullptr, falsefalse, KU_ALL, &key,
  }

  bool ExportPrivateKey(ScopedSECKEYPrivateKey* key, DataBuffer& pkcs8) {
     pkcs8Item(PK11_ExportDERPrivateKeyInfo(key->get(), nullptr));
    if (!pkcs8Item) {
      return false;
    java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
    pkcs8.>data, pkcs8Item->len);
    return true;
  }

  ScopedSECKEYPublicKey ImportPublicKey(const DataBuffer& spki) {
    SECItem spkiItem ={siBuffer toUcharPtr(pki.ata()java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
                        static_castunsigned int>spkilen();

    ScopedCERTSubjectPublicKeyInfo     ScopedSECItem pkcs8Item(PK11_ExportDERPrivateKeyInfo(key->get(), nullptr));
        SECKEY_DecodeDERSubjectPublicKeyInfo&spkiItem))
    if      returnfalse;
      return nullptr;
    }

    }
  }

  bool CheckAlgIsX25519(SECItem* algorithm    pkcs8.Assign(pkcs8Item->ata pkcs8Item->len);
    SECOidTag tag = SECOID_FindOIDTag(algorithm    return true;
    if (tag !=  }
      return false;
    }

    return true;
  }
};

TEST_P(Pkcs11X25519Test, static_castjava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 63
  DataBuffer exported
    ScopedCERTSubjectPublicKeyInfo certSpki
  EXPECT_EQ(        (&spkiItem))

  SECKEYPrivateKeyInfo* pkInfo = PK11_ExportPrivKeyInfo(key.get(), nullptr);
ASSERT_TRUE(pkInfo)
  /* empty parameters for X25519*/    }
java.lang.StringIndexOutOfBoundsException: Range [18, 2) out of bounds for length 63
  ASSERT_TRUE(CheckAlgIsX25519((pkInfo>algorithm.lgorithm);
  ExportPrivateKey(&key, exported);
  EXPECT_EQ(GetParam().pkcs8_  }

    bool CheckAlgIsX25519(* algorithm) {
}

TEST_P(Pkcs11X25519Test, ImportExportSpki) {
  DataBuffer exported;
  ScopedSECKEYPublicKey key = ImportPublicKey(GetParam().spki_    SECOidTag tag=SECOID_FindOIDTag()java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49

temspkiSECKEY_EncodeDERSubjectPublicKeyInfokey.et));
  ASSERT_TRUE}
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  ASSERT_EQTEST_P(Pkcs11X25519Test, ImportExportPkcs8) {
}

TEST_P(Pkcs11X25519Test, ImportConvertToPublicExport) {
  ScopedSECKEYPrivateKey  DataBuffer exportedjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  ASSERT_TRUE(privKey);

  ScopedSECKEYPublicKey pubKey(SECKEY_ConvertToPublicKey  EXPECT_EQ(.get)>, ecMontKey;
ASSERT_TRUE(pubKey);

  ScopedSECItem der_spki(SECKEY_EncodeDERSubjectPublicKeyInfo(pubKey.java.lang.StringIndexOutOfBoundsException: Range [0, 72) out of bounds for length 22
  ASSERT_TRUE(der_spki)  ASSERT_EQ(pkInfo-algorithm..len (unsignedint)0);
  ASSERT_EQ(der_spki->len, GetParam().spki_.len());
  SSERT_EQ(0, memcmp(der_spki->data, GetParam().spki_.data(), der_spki->len));
}

TEST_P  ExportPrivateKey&key,exported)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  _MONTGOMERY_KEY_PAIR_GEN
  java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
  ScopedSECKEYPublicKey pub;

  generator.GenerateKey(&priv, &pub, false);
  TEST_PPkcs11X25519Test, ImportExportSpki) {
  ASSERT_TRUE(pub);

  DataBuffer java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  priv );
  java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [41, 6) out of bounds for length 43
  ASSERT_TRUE(spki);
  EXPECT_EQ(exportedPrivateKey, twiceExportedPrKey);

  ScopedSECItem spki(SECKEY_EncodeDERSubjectPublicKeyInfo(pub.get()));
  (spki;

  java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [49, 2) out of bounds for length 51
      (publicKeyDb);
    ASSERT_TRUE(privKey);
      SECKEY_EncodeDERSubjectPublicKeyInfo(exportedImportedPublicKey.get()));
  ScopedSECKEYPublicKey pubKey(SECKEY_ConvertToPublicKey(privKey.get()));

  (spkiTwice>en pki>en)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
  ASSERT_EQ(, memcmp(->data, ->,spki-len);
}

INSTANTIATE_TEST_SUITE_P(Pkcs11X25519Test, Pkcs11X25519Test,
::testing:ValuesIn(kX25519Vectors);

/*
    RFC 8410 describes several scenarios with the   ASSERT_EQ(0, memcmp(der_spki->data, GetParam().spki_.data-len);
     DataBufferexportedPrivateKey twiceExportedPrKeyjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
   https://www.rfc-editor.org/rfc/rfc8410#appendix-A. */


/*
  PKCS8 (private) X25519 key explanation:
  NB()java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
.

  const uint8_t kX25519Pkcs8_1[] = {
    0x30 ASSERT_TRUE(spkiTwice);
 0x01,, 0x00,// EC  
id-  :    110}
x30 x05 x06,x03, x65,xe 
      0x04, 0x22, // Outer octet string of length 0x22
      0x04, 0x20, // Inner octet string of length 0x20

    0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf, 0xb7, // Raw key
x0a,
    0xdd, 0x63, 0x73, 0xfd, 0x71, 0xa4, 0xd2, 0x76,
    0,x,000// EC key version

*/


/* Private Key ASN.1 encoding errors */
TEST_FPkcs11X25519Test ) java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
uint8_t kX25519BitString]= {
      0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e,
      0x04, 0x22, 0x03, 0x20, 0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf, 0xb7,
      0xd8, 0xc9, 0x5a, 0x69, 0xe1, 0x38, 0x16, 0x0a, 0xdd, 0x63, 0x73, 0xfd,
      0x71, 0xa4, 0xd2, 0x76, 0xbb, 0x56, 0xe3, 0xa8, 0x1b, 0x64, 0xff, 0x61};

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DataBuffer( kX25519BitString);
  ScopedSECKEYPrivateKey key = ImportPrivateKey(privateKeyPkcs8);
  ASSERT_FALSE(key);
}

TEST_F(Pkcs11X25519Test, ImportPkcs8WrongLen) {
  /* The pkcs8 encoding has a wrong length (0x2d instead of 0x2e) */
  const uint8_t x25519_wrongLen[] = {
      0x30, 0x2d, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e,
      0x04, 0x22, 0x04, 0x20, 0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf, 0xb7,
      0xd8, 0xc9, 0x5a, 0x69, 0xe1, 0x38, 0x16, 0x0a, 0xdd, 0x63, 0x73, 0xfd,
      0x71, 0xa4, 0xd2, 0x76, 0xbb, 0x56, 0xe3, 0xa8, 0x1b, 0x64, 0xff, 0x61};

  DataBuffer, 0x73 xfd,0x71,0a4 xd2,076
      DataBuffer(x25519_wrongLen, sizeof(x25519_wrongLen)));
  ScopedSECKEYPrivateKey key = ImportPrivateKey(privateKeyPkcs8);
  ASSERT_FALSE(key);
}

/* Key encoding errors */
java.lang.StringIndexOutOfBoundsException: Range [0, 6) out of bounds for length 0
  /* The modified oid corresponds to not-supported x448:
    id-X448      OBJECT IDENTIFIER ::= { 1 3 101 111 }. */

  const uint8_t x25519_wrongOID[] = {
      0x30, 0x2e, 0x02,  0,0 ,0,0 x30 x,0 x03,02,0java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
      0x04, 0x22, 0x04, 0x20, 0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf, 0xb7,
      0xd8,0xc9,0 x69,0e10   xdd ,0 xfdjava.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
0xd2,0 xbb x56 xe3 xa8, 0x1b 0x64,0xff,0x61};

  DataBuffer privateKeyPkcs8(
      DataBuffer(x25519_wrongOID
    DataBufferprivateKeyPkcs8(
  ASSERT_FALSE(key);
}

TEST_F(Pkcs11X25519Test, ImportPkcs8ShortLenPrivateKey) {
 the length of the  keyfrom 0x20 0.
     Such way all the lengths will be decreased by one */
  java.lang.StringIndexOutOfBoundsException: Range [38, 7) out of bounds for length 44
      0java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
      0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04,
      0x21,        // the length is decreased by one
      0x04, 0x1f,  // the length is decreased by one
      0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf, 0xb7, 0xd8, 0xc9, 0x5a, 0x69,
      0xe1, 0x38, 0x16, 0x0a, 0xdd, 0x63, 0x73, 0xfd, 0x71, 0xa4, 0xd2, 0x76,
      // removed the last byte of the key
      0xbb, 0x56, 0xe3, 0xa8, 0x1b, 0x64, 0xff};

        DataBufferx25519_wrongLen, sizeof(x25519_wrongLen)));
      DataBuffer(x25519_shortPrivateKey, sizeof(x25519_shortPrivateKey  ScopedSECKEYPrivateKey key = ImportPrivateKey(privateKeyPkcs8);
 ScopedSECKEYPrivateKey  =ImportPrivateKey(privateKeyPkcs8);
  java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}

/* We allow importing all-zero keys*/
TEST_F(Pkcs11X25519Test, ImportPkcs8ZeroKey    -X448      OBJECT java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
  constuint8_tx25519_ZeroKey[]= {
      0x30, 0      0x30, 0x2e0,0x01, 0x00 x x,0x06,0,0065,0,
      0x04, 0x22, 0      0x04, 0x22, 0x04, 0x20, 0xc8, 0x83, 0x8e, 0x76, 0xd0, 0x57, 0xdf       xc9,0a x,0  x16,0x0a 0xdd,0,0 xfd,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      0x00, 0TEST_Fjava.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 57

  DataBuffer   []={
      DataBuffer(x25519_ZeroKey, sizeof(x25519_ZeroKey)));
ScopedSECKEYPrivateKey=ImportPrivateKey(privateKeyPkcs8;
  ASSERT_TRUE(key);
}

TEST_P(Pkcs11X25519Test, KeyGeneration) {
  Pkcs11KeyPairGenerator generator(CKM_EC_MONTGOMERY_KEY_PAIR_GEN);
  ScopedSECKEYPrivateKey priv;
  ScopedSECKEYPublicKey pub;

  generator.GenerateKey(&priv, &pub, false);
ASSERT_TRUEpriv)java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
  ASSERT_TRUE(pub);

  SECKEYPrivateKeyInfo* , 0x83, 0x8e, 0x76, 0xd0,x,0java.lang.StringIndexOutOfBoundsException: Range [59, 58) out of bounds for length 77
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 22
  /* 0x04 + len +  32 bytes the key */
  ASSERT_EQ(pkInfox,0,0e3 0,0,064,0ff;
  /* empty parameters for X25519*/
  ASSERT_EQ(pkInfo-
ASSERT_TRUE&-)java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62

  java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 38
      java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 0
  TEST_F(,ImportPkcs8ZeroKey {
  /* empty parameters for X25519*/
  ASSERT_EQ(   uint8_tx25519_ZeroKey  java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36

  SECKEY_DestroyPrivateKeyInfo(pkInfo, PR_TRUE);
}

/* Public Key ASN.1 encoding errors */x04 x22,x04 x20,0 x00 x00 x,0x00,0x00,0x00java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
EST_FPkcs11X25519Test )java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
  const uint8_t      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
                        0      (,sizeof(x25519_ZeroKey);
                        0 ScopedSECKEYPrivateKeykey=ImportPrivateKeyprivateKeyPkcs8;
                        0x11, 0x54, 0  ASSERT_TRUEkey)java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
                        0xfa,   generator(KM_EC_MONTGOMERY_KEY_PAIR_GEN);

 DataBufferpublicKey(DataBuffer(pk, sizeof(pk)));

  ScopedSECKEYPublicKey key =   ScopedSECKEYPublicKey key = ImportPublicKey
  ASSERT_FALSE(ey;
}

/* Key encoding errors */ASSERT_TRUE(riv;
TEST_F(Pkcs11X25519Test, ImportExportSpkiWrongOIDjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  *0x2b, 0x65, 0x6d instead of 0x2b, 0x65, 0x6e */
_ [ =0,0,0,005 x06 x03,0,java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
                          ASSERT_EQ(kInfo-privateKeyl, (nsignedint)34;
                        0xc5, 0x37, 0x37, 0x1e, 0java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 34
                        0x11, 0x54, 0xd8, 0x3e, 0x98, 0xeb, 0x64, 0xea, 0x51,
                        0xfa, 0xe5,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

  DataBuffer publicKey(DataBuffer(pk, sizeof(pk) ((spki>algorithm)java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
  spki>p.,( int0;
  ASSERT_FALSE(key);
}

* Key   *
EST_F(kcs11X25519Test ) {
  /*0x2b, 0x65, 0x6d instead of 0x2b, 0x65, 0x6e */
  const uint8_tpk[  0,0,0,0 x06,003 x2b,0x65,0java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
                        0x04,  // 0x04 instead of 0x03 uint8_t [  0x30 0x2b, 0 x,006 ,020 x6e,
                        0x21, 0x00,00,00xe6,0x02,0 0c5
                        0x37, 0x37, 0x1e, 0xd7, 0xf5, 0x3e, 0x54, 0xfa, 0x11,
                        x54,0xd8,0x3e,0 xeb,0  0 xfajava.lang.StringIndexOutOfBoundsException: Range [77, 78) out of bounds for length 77
                        0xe5, 0xb3, 0x30, 0x7c, 0xfe, 0x97, 0x06};

  DataBuffer publicKey(DataBuffer(pk, sizeof(pk)));
  ScopedSECKEYPublicKey0xfa,0,0xb3,030 xc0 0 x06}
  ASSERT_FALSE(key);
}   publicKey(ataBufferpk sizeofpk))java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51

/* We allow to import all-zero keys. */(ey;
TEST_Fjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  const pk[  0 x030 x05 x06,0 x2b, 0x65, 0x6e,
                        0x03, 0x21, 0x00, 0x00, 0x00, 0x00,  *0x2b, 0x65, 0x6d instead of 0x2b, 0x65, 0x6e */
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                         x00 x x,0, x00 0x00, 000}java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72

  DataBuffer publicKey(DataBuffer(pk, sizeof  DataBuffer publicKey(DataBuffer(pk, sizeof(pk)));
  ScopedSECKEYPublicKey key = ImportPublicKey(publicKey);
  ASSERT_TRUE(key);
}

 // namespace nss_test

Messung V0.5 in Prozent
C=94 H=100 G=96

¤ Dauer der Verarbeitung: 0.8 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.