pub fn new(log_n: u8, r: u32, p: u32) -> ScryptParams {
        assert!(r > 0);
        assert!(p > 0);
        assert!(log_n > 0);
        assert!((log_n as uint) < size_of::<uint>() * 8);

        let n = 1u32 << log_n as uint;

        let rp = match r.checked_mul(&p) {
            Some(x) => x,
            None => fail!("Invalid Scrypt parameters.")
        };

        let rp128 = match rp.checked_mul(&128) {
            Some(x) => x,
            None => fail!("Invalid Scrypt parameters.")
        };

        let nr128 = match n.checked_mul(&r) {
            Some(x) => match x.checked_mul(&128) {
                Some(y) => y,
                None => fail!("Invalid Scrypt parameters.")
            },
            None => fail!("Invalid Scrypt parameters.")
        };

        // Check that we won't attempt to allocate too much memory or get an integer overflow.
        // These checks guarantee that we can cast these values safely to uints and perform all the
        // math that we need to on them. This guarantees that the values r and p can both fit within
        // a uint as well.
        assert!(rp128.to_uint().is_some());
        assert!(nr128.to_uint().is_some());

        // This check required by Scrypt:
        // check: n < 2^(128 * r / 8)
        // r * 16 won't overflow since rp128 didn't above
        assert!((log_n as u32) < r * 16);

        // This check required by Scrypt:
        // check: p <= ((2^32-1) * 32) / (128 * r)
        // It takes a bit of re-arranging to get the check above into this form, but, it is indeed
        // the same.
        assert!(rp < 0x40000000);

        return ScryptParams {
            log_n: log_n,
            r: r,
            p: p
        };
    }
/**
     * Create a new instance of ScryptParams.
     *
     * # Arguments
     *
     * * log_n - The log2 of the Scrypt parameter N
     * * r - The Scrypt parameter r
     * * p - The Scrypt parameter p
     *
     */
Create a new instance of ScryptParams.
# Arguments

The log2 of the Scrypt parameter N
r - The Scrypt parameter r
p - The Scrypt parameter p
Create a new instance of ScryptParams . # Arguments The log2 of the Scrypt parameter N r - The Scrypt parameter r p - The Scrypt parameter p
pub fn new(log_n: u8, r: u32, p: u32) -> ScryptParams {
        assert!(r > 0);
        assert!(p > 0);
        assert!(log_n > 0);
        assert!((log_n as uint) < size_of::<uint>() * 8);
        let n = 1u32 << log_n as uint;
        let rp = match r.checked_mul(&p) {
            Some(x) => x,
            None => fail!("Invalid Scrypt parameters.")
        };
        let rp128 = match rp.checked_mul(&128) {
            Some(x) => x,
            None => fail!("Invalid Scrypt parameters.")
        };
        let nr128 = match n.checked_mul(&r) {
            Some(x) => match x.checked_mul(&128) {
                Some(y) => y,
                None => fail!("Invalid Scrypt parameters.")
            },
            None => fail!("Invalid Scrypt parameters.")
        };
        // Check that we won't attempt to allocate too much memory or get an integer overflow.
        // These checks guarantee that we can cast these values safely to uints and perform all the
        // math that we need to on them. This guarantees that the values r and p can both fit within
        // a uint as well.
        assert!(rp128.to_uint().is_some());
        assert!(nr128.to_uint().is_some());
        // This check required by Scrypt:
        // check: n < 2^(128 * r / 8)
        // r * 16 won't overflow since rp128 didn't above
        assert!((log_n as u32) < r * 16);
        // This check required by Scrypt:
        // check: p <= ((2^32-1) * 32) / (128 * r)
        // It takes a bit of re-arranging to get the check above into this form, but, it is indeed
        // the same.
        assert!(rp < 0x40000000);
        return ScryptParams {
            log_n: log_n,
            r: r,
            p: p
        };
    }
pub fn new ( log_n : u8 , r : u32 , p : u32 ) -> ScryptParams { assert ! ( r 0 ) ; assert ! ( p 0 ) ; assert ! ( log_n 0 ) ; assert ! ( ( log_n as uint ) size_of uint ( ) 8 ) ; let n = 1u32 << log_n as uint ; let rp = match r . checked_mul ( & p ) { Some ( x ) => x , None => fail ! ( " " ) } ; let rp128 = match rp . checked_mul ( & 128 ) { Some ( x ) => x , None => fail ! ( " " ) } ; let nr128 = match n . checked_mul ( & r ) { Some ( x ) => match x . checked_mul ( & 128 ) { Some ( y ) => y , None => fail ! ( " " ) } , None => fail ! ( " " ) } ; // Check that we won't attempt to allocate too much memory or get an integer overflow. // These checks guarantee that we can cast these values safely to uints and perform all the // math that we need to on them. This guarantees that the values r and p can both fit within // a uint as well. assert ! ( rp128 to_uint ( ) is_some ( ) ) ; assert ! ( nr128 to_uint ( ) is_some ( ) ) ; // This check required by Scrypt: // check: n < 2^(128 * r / 8) // r * 16 won't overflow since rp128 didn't above assert ! ( ( log_n as u32 ) r 16 ) ; // This check required by Scrypt: // check: p <= ((2^32-1) * 32) / (128 * r) // It takes a bit of re-arranging to get the check above into this form, but, it is indeed // the same. assert ! ( rp 0x40000000 ) ; return ScryptParams { log_n : log_n , r : r , p : p } ; }
Create a new instance of ScryptParams.
Create a new instance of ScryptParams .
log_n
u8
r
u32
p
u32
log_n
u8
r
u32
p
u32