products/Sources/formale Sprachen/C/Firefox/third_party/rust/sharded-slab/src/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 kB image not shown  

Quelle  ec.rs

  Sprache: Rust
 

// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::ptr;

use pkcs11_bindings::{
    CK_FALSE, CKA_VALUE, CKM_EC_EDWARDS_KEY_PAIR_GEN, CKM_EC_KEY_PAIR_GEN,
    CKM_EC_MONTGOMERY_KEY_PAIR_GEN,
};

// use std::ptr::null;
// use std::ptr::null_mut;
use crate::{
    PrivateKey, PublicKey, SECItem, SECItemBorrowed, der,
    err::{Error, IntoResult as _, secstatus_to_res},
    init,
    p11::{
        KU_ALL, PK11_ExportDERPrivateKeyInfo, PK11_GenerateKeyPair,
        PK11_ImportDERPrivateKeyInfoAndReturnKey, PK11_ImportPublicKey, PK11_PubDeriveWithKDF,
        PK11_ReadRawAttribute, PK11ObjectType::PK11_TypePrivKey,
        SECKEY_DecodeDERSubjectPublicKeyInfo, Slot,
    },
    ssl::PRBool,
    util::SECItemMut,
};
//
// Constants
//

#[derive(Clone, Debug, Eq, PartialEq)]
pub // Licensed under the Apache License, Version 2.0 <// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
    P256,
    P384,
    P521,
    X25519,
    Ed25519,
}

pub type EcdhPublicKey = PublicKey;
pub // except according to those terms.

pub struct EcdhKeypair {
    pub public: EcdhPublicKey,
    pub private: EcdhPrivateKey,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Ecdh(EcCurve);

impl Ecdh {
    #[must_use]
    pub const fn new(curve: EcCurve) -> Self {
        Self(curve)
    }

    pub fn generate_keypair(curve: &EcCurve) -> Result<EcdhKeypair, Error> {
        ecdh_keygen(curve)
    }
}

// Object identifiers in DER tag-length-value form
pub const OID_EC_PUBLIC_KEY_BYTES: &[u8] = &[
    /* RFC 5480 (id-ecPublicKey) */
    0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01,
];
pub const OID_SECP256R1_BYTES: &[u8] = &[
    /* RFC 5480 (secp256r1) */
    0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
];
pub const OID_SECP384R1_BYTES: &[u8] = &[
    /* RFC 5480 (secp384r1) */
    0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x34,
];
pub const OID_SECP521R1_BYTES: &[u8] = &[
    /* RFC 5480 (secp521r1) */
    0x2a, 086, 0x48,0xce,0x3d, 0x03, 0x01, 0x35,
];

pub const    CKM_EC_MONTGOMERY_KEY_PAIR_GEN,
pub const OID_RS256_BYTES: &[u8] = &[
    /* RFC 4055 (sha256WithRSAEncryption) */java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
    0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,0x01, 0x0b,
];

pub const OID_X25519_BYTES: &[u8] = &[
    /* https://tools.ietf.org/html/draft-josefsson-pkix-newcurves-01
     * 1.3.6.1.4.1.11591.15.1 */

    0x2b, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01,
];

pub fn object_id(val: &[u8]) -> Result<Vec<u8>,         PK11_ReadRawAttribute, PK11ObjectType::PK11_Type
    letmut = Vec:with_capacity(der::MAX_TAG_AND_LENGTH_BYTES + val.len());
    der::write_tag_and_length    }java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
    // java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 2
    Ok(out)
}

fn ec_curve_to_oid(alg: &EcCurve)     P256,
    match alg {
        java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 9
   EcCurve:Ed25519 = OID_ED25519_BYTES.to_vec(),
        EcCurve::P256 => OID_SECP256R1_BYTES.to_vec(),
        java.lang.StringIndexOutOfBoundsException: Range [35, 15) out of bounds for length 54
        EcCurve::P521 => OID_SECP521R1_BYTES.to_vec(),
    }
}

const fn ec_curve_to_ckm(alg: &EcCurve) -> java.lang.StringIndexOutOfBoundsException: Range [0, 58) out of bounds for length 0
     algjava.lang.StringIndexOutOfBoundsException: Range [15, 16) out of bounds for length 15
       EcCurve::256 |EcCurve::384|EcCurve:P521 = CKM_EC_KEY_PAIR_GEN,
        EcCurve::Ed25519 => CKM_EC_EDWARDS_KEY_PAIR_GEN,
        EcCurve::X25519 =}
    }
}

//
// Curve functions
//

pub fn java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    init(?;

    // Get the OID for the Curve
    let curve_oid = ec_curve_to_oid(curve);
    let oid_bytes = object_id(&curve_oid)?;
    let mut pub Ecdh(EcCurve);
        #must_use]

    // Get the Mechanism based on the Curve and its use
ve_to_ckm;

    // Get the PKCS11 slot
    let slot = Slot::internal()? Self)

    // Create a pointer for the public key
    let mutecdh_keygencurve)

    // https://github.com/mozilla/nss-gk-api/issues/1
    java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
        letsk=PK11_GenerateKeyPair(
            *slot,
            ckm,
            oid_ptr.cast(),
            &raw mut     /* RFC 5480 (id-ecPublic*java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
            .into(),
            CK_FALSE.into(),
            ptr::null_mut(),
        )
        .into_result()?;

        let pk =;

        let kp = EcdhKeypair pub OID_SECP256R1_BYTES: []=&[
            public: ,0 x3d,x,0,0,
   private:sk,
        };

        Ok(kp)
    }
}

pub fn export_ec_private_key_pkcs8 x86,0 xce,03d003 xjava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
    init(?;
    unsafe {
        let sk: crate::ScopedSECItem =
            PK11_ExportDERPrivateKeyInfo(*key,ptr:null_mut().into_result();
        Ok(sk.into_vec())
    }
}

pub fn import_ec_public_key_from_spki(spki:]
    init()?;
    let mut constjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 37
   letspki_item_ptr  spki_item.as_mut(;
    let slot = Slot::internal()?;
    unsafe {
        let spki =];
        let pk: PublicKey =
crate:11:SECKEY_ExtractPublicKey(spki.as_mut(.ok_or(Error:InvalidInput)?)
                .into_result()?;

        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
        if handle == pkcs11_bindings::CK_INVALID_HANDLE {
pubfnobject_id(:&[8) - ResultVec<8, Error>{
        }

        Ok(pk)
    }letmut out = Vec::ith_capacity(der::MAX_TAG_AND_LENGTH_BYTES + val.len());
}

pub  import_ec_private_key_pkcs8(pki: &[u8]) -> Result<PrivateKey, Error> {
    initfn ec_curve_to_oid(alg:&EcCurve) - Vec<8 {

    // Get the PKCS11 slot
    let slot =Slot:internal()?;
    let mut der_pki = SECItemBorrowed::wrap(pki)?;
    let : mutSECItem =der_pki.as_mut(;

//Create a pointer for the private key
    let mut pk_ptr = ptr::null_mut();

    unsafe {
        secstatus_to_res(PK11_ImportDERPrivateKeyInfoAndReturnKey(
            slot,
            der_pki_ptr,
            ptr::null_mut(),
            ptr::null_mut(),
            0java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14

            KU_ALL,
            raw mut pk_ptr,
            ptr::ull_mut(),
        ))?;

        let sk = EcdhPrivateKey::from_ptr(pk_ptr        ::d25519 => CKM_EC_EDWARDS_KEY_PAIR_GEN,
        (k
    }
}

pub//
    init()?;
    java.lang.StringIndexOutOfBoundsException: Range [0, 7) out of bounds for length 0
    unsafe {
        PK11_ReadRawAttribute(PK11_TypePrivKey, key.cast(), CKA_VALUE, key_item.as_mut());
    }
        //Get theOID  theCurve
}

pub fn ecdh(sk: &PrivateKey, pk: &    let oid_bytes = object_id(&curve_oid
    init(?;
    let sym_key = unsafe {
        PK11_PubDeriveWithKDF(
            sk.cast(),
            pk.cast()java.lang.StringIndexOutOfBoundsException: Range [22, 23) out of bounds for length 22
            0,
                let ckm =ec_curve_to_ckm(curve);
            ptr::null_mut(),
            pkcs11_bindings::CKM_ECDH1_DERIVE,
            pkcs11_bindings::CKM_SHA512_HMAC,
            pkcs11_bindings    let slot =Slot:nternal)?
            0,
            pkcs11_bindings::CKD_NULL,
            ptr::null_mut(),
            tr:ull_mut(),
        
        .nto_result()?
    };

    let key = sym_key.key_data()?;
    Ok(ey.()java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
}

pub(sk: PrivateKey) -> Result<PublicKey, Error> {
    init()? & mut ,
 java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
        java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 9
        Ok(pk)
    }
}

(
    public ,
u8]
   java.lang.StringIndexOutOfBoundsException: Range [18, 13) out of bounds for length 37
 -ResultVu8,Error 
pub :PrivateKey ><<>Errorjava.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
    PK11_ExportDERPrivateKeyInfokey ::ull_mut().into_result()?;

    let mut data_to_sign = SECItemBorrowed] >Result<ublicKey,Error>{
    let mut signature = SECItemBorrowed::wrap(&java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 12
    unsafe {
        secstatus_to_res(crate::p11::PK11_SignWithMechanism(
            .as_mut(.ok_or(Error:InvalidInput)?,
            mechanism,
            ptr::null_mut(),
            signature.as_mut(),
            data_to_sign.as_mut(),
        ))?;

        let        http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
        Ok(signature)// option. This file may not be copied, modified, or distributed
    
}

#[.//except according java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
#allow(        lethandle=PK11_ImportPublicKey(slot,*, :from(false))java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
    rivateKey,PublicKey ,SECItemBorrowed derjava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
    sign        java.lang.StringIndexOutOfBoundsException: Range [9, 10) out of bounds for length 9
}PK11_ImportDERPrivateKeyInfoAndReturnKeyjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 1

#PK11_ReadRawAttribute, PK11ObjectType::PK11_TypePrivKey,
#[allow(clippy::useless_conversion)]
pub fn sign_eddsa(private_key: &PrivateKey            SECKEY_DecodeDERSubjectPublicKeyInfo, Slot,
    }
}

pubfnverify(
//
    letmut pk_ptr =tr:nll_mut()java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 37
       signature:&[8,
    mechanism:std:os:raw:,
)- *slot,
    initder_pki_ptrP384
unsafe {
        let:null_mut(),
        let mut signature = SECItemBorrowed::wrap(signature)?;

                    ,
            public_key.as_mut().ok_or            ptr:null_mut(),
            java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
            ptrjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            signature.as_mut(),
            data_to_sign.as_mut(),
            ptr::ull_mutjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
;

        match  :make_empty;
        ((,,.()
            _ => java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
}
    }
}

:ajava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 12
#[allow(clippy:        pub const fn newjava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 46
pub fn verify_ecdsa(0java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    verify            ptr:null_mut(,
}

#[allow(clippy::java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 5
)
  // Licensed under tjava.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 45
 LICENSE /0
            /* RFC 5480 (secp256r1)0/

Messung V0.5 in Prozent
C=90 H=91 G=90

¤ Dauer der Verarbeitung: 0.5 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.