Struct ed25519_dalek::Context
source · pub struct Context<'k, 'v, K> { /* private fields */ }
digest
only.Expand description
Ed25519 contexts as used by Ed25519ph.
Contexts are domain separator strings that can be used to isolate uses of the algorithm between different protocols (which is very hard to reliably do otherwise) and between different uses within the same protocol.
To create a context, call either of the following:
For more information, see RFC8032 § 8.3.
§Example
use ed25519_dalek::{Signature, SigningKey, VerifyingKey, Sha512};
use ed25519_dalek::{DigestSigner, DigestVerifier};
let context_str = b"Local Channel 3";
let prehashed_message = Sha512::default().chain_update(b"Stay tuned for more news at 7");
// Signer
let signing_context = signing_key.with_context(context_str).unwrap();
let signature = signing_context.sign_digest(prehashed_message.clone());
// Verifier
let verifying_context = verifying_key.with_context(context_str).unwrap();
let verified: bool = verifying_context
.verify_digest(prehashed_message, &signature)
.is_ok();
Implementations§
Trait Implementations§
source§impl<D> DigestSigner<D, Signature> for Context<'_, '_, SigningKey>
impl<D> DigestSigner<D, Signature> for Context<'_, '_, SigningKey>
Equivalent to SigningKey::sign_prehashed
with context
set to Some
containing self.value()
.
§Note
The RFC only permits SHA-512 to be used for prehashing. This function technically works, and is
probably safe to use, with any secure hash function with 512-bit digests, but anything outside
of SHA-512 is NOT specification-compliant. We expose crate::Sha512
for user convenience.
source§fn try_sign_digest(&self, msg_digest: D) -> Result<Signature, SignatureError>
fn try_sign_digest(&self, msg_digest: D) -> Result<Signature, SignatureError>
Digest
, returning a
digital signature on success, or an error if something went wrong.source§fn sign_digest(&self, digest: D) -> S
fn sign_digest(&self, digest: D) -> S
source§impl<MsgDigest> DigestVerifier<MsgDigest, Signature> for Context<'_, '_, VerifyingKey>
impl<MsgDigest> DigestVerifier<MsgDigest, Signature> for Context<'_, '_, VerifyingKey>
Equivalent to VerifyingKey::verify_prehashed
with context
set to Some
containing self.value()
.
source§fn verify_digest(
&self,
msg_digest: MsgDigest,
signature: &Signature
) -> Result<(), SignatureError>
fn verify_digest( &self, msg_digest: MsgDigest, signature: &Signature ) -> Result<(), SignatureError>
Digest
output.