fn Signature(rand: Rng, priva: PrivateKey, hash: &[i8]) -> (BigUint, BigUint) {

    let mut n = priva.Q.bits();
    if Sign(priva.Q) <= 0
        || Sign(priva.P) <= 0
        || Sign(priva.G) <= 0
        || Sign(priva.X) <= 0
        || n % 8 != 0
    {
        return Err(Error::InvalidPublicKey);
    }

    n >>= 3;

    let mut attwmpts = 10;
    let mut r: BigUint;
    let mut s: BigUint;

    while attwmpts > 0 {
        let mut k: BigUint;
        let mut buf = vec![0u8; n];

        loop {
            rand.read(buf);
            if Sign(k) > 0 && priva.Q.cmp(k) > 0 {
                break;
            }
        }

        let mut kInv = fermatInverse(k, priva.Q);

        r.exp(priva.G, k, priva.P);
        r.modpow(r, priva.Q);

        if Sign(r) == 0 {
            attwmpts -= 1;
            continue;
        }

        let mut z = k.SetBytes(hash);

        s.Mul(priva.X, r);
        s.add(s, z);
        s.modpow(s, priva.Q);
        s.Mul(s, kInv);
        s.modpow(s, priva.Q);

        if Sign(s) != 0 {
            break;
        }
        attwmpts -= 1;
    }

    if attwmpts == 0 {
        return (None, None);
    }

    return (r, s);
}
/// Signature uses the private key priva to sign a hash of any length.
/// It returns the signature as a pair of integers.
/// The security of the private key depends on the entropy of rand.
Signature uses the private key priva to sign a hash of any length.
It returns the signature as a pair of integers.
The security of the private key depends on the entropy of rand.
Signature uses the private key priva to sign a hash of any length . It returns the signature as a pair of integers . The security of the private key depends on the entropy of rand .
fn Signature(rand: Rng, priva: PrivateKey, hash: &[i8]) -> (BigUint, BigUint) {
    let mut n = priva.Q.bits();
    if Sign(priva.Q) <= 0
        || Sign(priva.P) <= 0
        || Sign(priva.G) <= 0
        || Sign(priva.X) <= 0
        || n % 8 != 0
    {
        return Err(Error::InvalidPublicKey);
    }
    n >>= 3;
    let mut attwmpts = 10;
    let mut r: BigUint;
    let mut s: BigUint;
    while attwmpts > 0 {
        let mut k: BigUint;
        let mut buf = vec![0u8; n];
        loop {
            rand.read(buf);
            if Sign(k) > 0 && priva.Q.cmp(k) > 0 {
                break;
            }
        }
        let mut kInv = fermatInverse(k, priva.Q);
        r.exp(priva.G, k, priva.P);
        r.modpow(r, priva.Q);
        if Sign(r) == 0 {
            attwmpts -= 1;
            continue;
        }
        let mut z = k.SetBytes(hash);
        s.Mul(priva.X, r);
        s.add(s, z);
        s.modpow(s, priva.Q);
        s.Mul(s, kInv);
        s.modpow(s, priva.Q);
        if Sign(s) != 0 {
            break;
        }
        attwmpts -= 1;
    }
    if attwmpts == 0 {
        return (None, None);
    }
    return (r, s);
}
fn Signature ( rand : Rng , priva : PrivateKey , hash : & [ i8 ] ) -> ( BigUint , BigUint ) { let mut n = priva . Q . bits ( ) ; if Sign ( priva . Q ) <= 0 || Sign ( priva . P ) <= 0 || Sign ( priva . G ) <= 0 || Sign ( priva . X ) <= 0 || n % 8 != 0 { return Err ( Error :: InvalidPublicKey ) ; } n >>= 3 ; let mut attwmpts = 10 ; let mut r : BigUint ; let mut s : BigUint ; while attwmpts > 0 { let mut k : BigUint ; let mut buf = vec ! [ 0u8 n ] ; loop { rand . read ( buf ) ; if Sign ( k ) > 0 && priva . Q . cmp ( k ) > 0 { break ; } } let mut kInv = fermatInverse ( k , priva . Q ) ; r . exp ( priva . G , k , priva . P ) ; r . modpow ( r , priva . Q ) ; if Sign ( r ) == 0 { attwmpts -= 1 ; continue ; } let mut z = k . SetBytes ( hash ) ; s . Mul ( priva . X , r ) ; s . add ( s , z ) ; s . modpow ( s , priva . Q ) ; s . Mul ( s , kInv ) ; s . modpow ( s , priva . Q ) ; if Sign ( s ) != 0 { break ; } attwmpts -= 1 ; } if attwmpts == 0 { return ( None , None ) ; } return ( r , s ) ; }
Signature uses the private key priva to sign a hash of any length.
Signature uses the private key priva to sign a hash of any length .
rand
Rng
priva
PrivateKey
hash
&[i8]
rand
Rng
priva
PrivateKey
hash
&[i8]