Browse the docs

silk.crypto.p384.

Verify ECDSA signatures on the NIST P-384 curve (secp384r1) with SHA-384.

When to use#

Use EcdsaP384Sha384 to verify a P-384 signature, for example in a certificate chain or a JSON Web Token with ES384. This module cannot sign and has no key agreement.

Details#

Public keys are 97 bytes in uncompressed SEC1 form: 0x04, then the X and Y coordinates, each 48 bytes big-endian. Signatures are in DER form. The functions hash the message with SHA-384. Nothing allocates.

Errors#

Gotchas#

A valid signature proves only that the holder of the private key signed the message. It does not prove that you can trust the key. To check a certificate chain, use the silk.tls.trust_* modules.

Examples#

Verify a signature#

silk
import silk.crypto.p384 { EcdsaP384Sha384, P384SignatureError }
import silk.core.result { Result }

pub fn main() -> i32 {
  // A public key and a signature of "hello" that another program made.
  let publicKey: [u8; 97] = [
    0x04,
    0xe8,
    0x6b,
    0x99,
    0x5e,
    0x35,
    0x0e,
    0x4d,
    0x31,
    0x2a,
    0x95,
    0xa6,
    0xb7,
    0xd5,
    0xd8,
    0xcd,
    0xcd,
    0xb4,
    0x68,
    0x2f,
    0x58,
    0x88,
    0x00,
    0xa1,
    0xcd,
    0x6c,
    0x97,
    0x2e,
    0x1d,
    0xcb,
    0x2a,
    0x5a,
    0xc3,
    0x8d,
    0x90,
    0x04,
    0x69,
    0x51,
    0xb0,
    0x3c,
    0xcb,
    0x3b,
    0x17,
    0x9a,
    0x89,
    0xfd,
    0xa8,
    0x8b,
    0x1b,
    0x48,
    0x5b,
    0x9f,
    0x2c,
    0x1f,
    0x44,
    0xb0,
    0xdd,
    0x41,
    0xce,
    0x6e,
    0x3c,
    0x3a,
    0x69,
    0x0b,
    0xbf,
    0xaa,
    0xbe,
    0xc1,
    0xe1,
    0xff,
    0x4a,
    0xef,
    0xb2,
    0x46,
    0x1f,
    0xdd,
    0xa6,
    0x62,
    0x9b,
    0xec,
    0xbd,
    0x43,
    0xcf,
    0x74,
    0xc1,
    0x3d,
    0x8c,
    0x1a,
    0x16,
    0x25,
    0x61,
    0x22,
    0x43,
    0xf0,
    0x04,
    0x61,
    0x48
  ]
  let signature: [u8; 104] = [
    0x30,
    0x66,
    0x02,
    0x31,
    0x00,
    0xb2,
    0x11,
    0x52,
    0x9f,
    0xfe,
    0x5e,
    0xf2,
    0x0c,
    0x08,
    0x48,
    0xbc,
    0x09,
    0xf5,
    0x2d,
    0x3a,
    0xb4,
    0xb8,
    0x79,
    0x2e,
    0x6a,
    0xe4,
    0x2d,
    0xb3,
    0x33,
    0xea,
    0x25,
    0xed,
    0x22,
    0x8e,
    0x3d,
    0x73,
    0x35,
    0x9d,
    0x59,
    0xac,
    0xaa,
    0x65,
    0xe0,
    0x98,
    0x57,
    0xd1,
    0x34,
    0x4f,
    0x37,
    0x9f,
    0x7f,
    0x6c,
    0xd3,
    0x02,
    0x31,
    0x00,
    0xd6,
    0x17,
    0x87,
    0xa8,
    0x8f,
    0xf1,
    0xdd,
    0x7f,
    0xbf,
    0x45,
    0x5d,
    0x3a,
    0x2b,
    0xf0,
    0x16,
    0x49,
    0xed,
    0xe6,
    0x4b,
    0xc2,
    0x3e,
    0xbe,
    0x12,
    0x6c,
    0x61,
    0x01,
    0xd2,
    0xea,
    0x73,
    0xc4,
    0x70,
    0xd0,
    0x22,
    0x30,
    0x6f,
    0x42,
    0x32,
    0xeb,
    0x6f,
    0x7b,
    0x84,
    0x9a,
    0x61,
    0x66,
    0x56,
    0xa6,
    0x50,
    0xd8
  ]
  match EcdsaP384Sha384.verify(&publicKey, b"hello", &signature) {
    Result<(), P384SignatureError>.Success { value: _ } => {}
    Result<(), P384SignatureError>.Failure { error: _ } => {
      return 1
    }
  }

  // The same signature does not match another message.
  return match EcdsaP384Sha384.verify(&publicKey, b"hellp", &signature) {
    Result<(), P384SignatureError>.Failure { error: P384SignatureError.AuthenticationFailed } => 0
    _ => 1
  }
}

Import as EcdsaP384Sha384 with import silk.crypto.p384 { EcdsaP384Sha384 }.

Public declarations: 2.

P384SignatureError#

silk
pub enum P384SignatureError

The reason that an ECDSA P-384 verification failed.

InvalidKey#

silk
InvalidKey

The public key is not a valid uncompressed P-384 key.

InvalidEncoding#

silk
InvalidEncoding

The signature is not strict DER, or r or s is not between 1 and the order of the curve.

UnsupportedAlgorithm#

silk
UnsupportedAlgorithm

A certificate names a key or signature algorithm other than ECDSA P-384 with SHA-384.

InvalidParameters#

silk
InvalidParameters

A certificate has wrong algorithm parameters, or a BIT STRING with unused bits.

AuthenticationFailed#

silk
AuthenticationFailed

The inputs are valid, but the signature does not match the message and the key.

Implementation Debug for P384SignatureError#

silk
impl Debug for P384SignatureError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as InvalidKey.

EcdsaP384Sha384#

silk
pub struct EcdsaP384Sha384

Functions that verify ECDSA signatures on P-384 with SHA-384.

When to use#

Use it to verify a P-384 signature, for example in a certificate chain or a JSON Web Token with ES384. It cannot sign and has no key agreement.

Details#

Public keys are 97 bytes in uncompressed SEC1 form: 0x04, then the X and Y coordinates, each 48 bytes big-endian. Signatures are in DER form. Nothing allocates.

Gotchas#

A valid signature proves only that the holder of the private key signed the message. It does not prove that you can trust the key. To check a certificate chain, use the silk.tls.trust_* modules.

Implementation EcdsaP384Sha384#

silk
impl EcdsaP384Sha384

Associated function validatePublicKey#

silk
pub fn validatePublicKey(publicKey: &[u8]) -> Result<(), P384SignatureError>

Checks that publicKey is a valid uncompressed P-384 public key.

It must be 97 bytes: 0x04, then X and Y, each 48 bytes big-endian and less than the field prime, and the point must be on the curve.

Errors#

  • InvalidKey if it is not valid.

Associated function verify#

silk
pub fn verify(publicKey: &[u8], message: &[u8], signature: &[u8]) -> Result<
    (),
    P384SignatureError,
  >

Checks that signature is a valid signature of message by publicKey.

publicKey is 97 bytes, uncompressed. signature is DER. The function hashes message with SHA-384, so give the message, not its digest. Both high and low s values are accepted.

Errors#

  • InvalidKey or InvalidEncoding for input that is not valid.

  • AuthenticationFailed if the signature does not match.

Associated function verifyCertificate#

silk
pub fn verifyCertificate<'key, 'sig>(
    keyAlgorithm: &AlgorithmView<'key>,
    publicKey: &BitStringView<'key>,
    message: &[u8],
    signatureAlgorithm: &AlgorithmView<'sig>,
    signature: &BitStringView<'sig>,
  ) -> Result<(), P384SignatureError>

Verifies a certificate signature from the parts that silk.tls.certificate reads.

message is the signed part of the certificate (the TBSCertificate DER). The key algorithm must be id-ecPublicKey with the curve secp384r1, and the signature algorithm must be ecdsa-with-SHA384 with no parameters.

Errors#

  • UnsupportedAlgorithm or InvalidParameters if the algorithms do not match.

  • InvalidKey or InvalidEncoding if the key or the signature is not valid.

  • AuthenticationFailed if the signature does not match.

Gotchas#

It checks only this one signature. It does not check the chain, the dates, or the names.

Category: Cryptography.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page