Unverified Commit d2362afb authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #1513 from uniqueNullptr2/seed-cipher

Seed cipher
parents 7c18edef 90174f9d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ jobs:
      - uses: actions/checkout@v2
      - uses: sfackler/actions/rustup@master
        with:
          version: 1.36.0
          version: 1.46.0
      - run: echo "::set-output name=version::$(rustc --version)"
        id: rust-version
      - uses: actions/cache@v1
+4 −0
Original line number Diff line number Diff line
@@ -94,3 +94,7 @@ RUST_CONF_OPENSSL_NO_SM3
#ifdef OPENSSL_NO_DEPRECATED_3_0
RUST_CONF_OPENSSL_NO_DEPRECATED_3_0
#endif

#ifdef OPENSSL_NO_SEED
RUST_CONF_OPENSSL_NO_SEED
#endif
+8 −0
Original line number Diff line number Diff line
@@ -363,6 +363,14 @@ extern "C" {
    pub fn EVP_chacha20() -> *const ::EVP_CIPHER;
    #[cfg(ossl110)]
    pub fn EVP_chacha20_poly1305() -> *const ::EVP_CIPHER;
    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn EVP_seed_cbc() -> *const EVP_CIPHER;
    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn EVP_seed_cfb128() -> *const EVP_CIPHER;
    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn EVP_seed_ecb() -> *const EVP_CIPHER;
    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn EVP_seed_ofb() -> *const EVP_CIPHER;

    #[cfg(not(ossl110))]
    pub fn OPENSSL_add_all_algorithms_noconf();
+62 −0
Original line number Diff line number Diff line
@@ -290,6 +290,26 @@ impl Cipher {
        unsafe { Cipher(ffi::EVP_chacha20_poly1305()) }
    }

    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn seed_cbc() -> Cipher {
        unsafe { Cipher(ffi::EVP_seed_cbc()) }
    }

    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn seed_cfb128() -> Cipher {
        unsafe { Cipher(ffi::EVP_seed_cfb128()) }
    }

    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn seed_ecb() -> Cipher {
        unsafe { Cipher(ffi::EVP_seed_ecb()) }
    }

    #[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
    pub fn seed_ofb() -> Cipher {
        unsafe { Cipher(ffi::EVP_seed_ofb()) }
    }

    /// Creates a `Cipher` from a raw pointer to its OpenSSL type.
    ///
    /// # Safety
@@ -1560,4 +1580,46 @@ mod tests {
        .unwrap();
        assert_eq!(pt, hex::encode(out));
    }

    #[test]
    #[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
    fn test_seed_cbc() {
        let pt = "5363686f6b6f6c6164656e6b756368656e0a";
        let ct = "c2edf0fb2eb11bf7b2f39417a8528896d34b24b6fd79e5923b116dfcd2aba5a4";
        let key = "41414141414141414141414141414141";
        let iv = "41414141414141414141414141414141";

        cipher_test(super::Cipher::seed_cbc(), pt, ct, key, iv);
    }

    #[test]
    #[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
    fn test_seed_cfb128() {
        let pt = "5363686f6b6f6c6164656e6b756368656e0a";
        let ct = "71d4d25fc1750cb7789259e7f34061939a41";
        let key = "41414141414141414141414141414141";
        let iv = "41414141414141414141414141414141";

        cipher_test(super::Cipher::seed_cfb128(), pt, ct, key, iv);
    }
    #[test]
    #[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
    fn test_seed_ecb() {
        let pt = "5363686f6b6f6c6164656e6b756368656e0a";
        let ct = "0263a9cd498cf0edb0ef72a3231761d00ce601f7d08ad19ad74f0815f2c77f7e";
        let key = "41414141414141414141414141414141";
        let iv = "41414141414141414141414141414141";

        cipher_test(super::Cipher::seed_ecb(), pt, ct, key, iv);
    }
    #[test]
    #[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
    fn test_seed_ofb() {
        let pt = "5363686f6b6f6c6164656e6b756368656e0a";
        let ct = "71d4d25fc1750cb7789259e7f34061930afd";
        let key = "41414141414141414141414141414141";
        let iv = "41414141414141414141414141414141";

        cipher_test(super::Cipher::seed_ofb(), pt, ct, key, iv);
    }
}