From d36293c57a813783a7ae5e0fc810028bbb7583b4 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Sun, 18 Aug 2024 17:19:57 -0600 Subject: [PATCH] yescrypt: remove dead code (#516) Removes translations of the reference yescrypt C implementation which are not currently exposed through the public API (but could potentially be in the future). This reduces the total surface of code to clean up and turn into idiomatic Rust to just the code used by `yescrypt_kdf`. --- yescrypt/src/lib.rs | 839 +------------------------------------------- 1 file changed, 2 insertions(+), 837 deletions(-) diff --git a/yescrypt/src/lib.rs b/yescrypt/src/lib.rs index 2f4f10e4..e0e4be96 100644 --- a/yescrypt/src/lib.rs +++ b/yescrypt/src/lib.rs @@ -56,10 +56,7 @@ mod salsa20; mod sha256; use crate::{ - common::{ - atoi64, blkcpy, blkxor, decode64, decode64_uint32, decode64_uint32_fixed, encode64, - encode64_uint32, encrypt, integerify, le32dec, le32enc, p2floor, wrap, N2log2, - }, + common::{blkcpy, blkxor, integerify, le32dec, le32enc, p2floor, wrap}, sha256::{HMAC_SHA256_Buf, SHA256_Buf, PBKDF2_SHA256}, }; use alloc::{vec, vec::Vec}; @@ -67,7 +64,7 @@ use core::{ mem::{self, size_of}, ptr, }; -use libc::{free, malloc, memcpy, memset, strlen, strncmp, strrchr}; +use libc::{free, malloc, memcpy}; type uint8_t = libc::c_uchar; type uint32_t = libc::c_uint; @@ -118,8 +115,6 @@ struct PwxformCtx { } const DEC: encrypt_dir_t = -1; -#[allow(dead_code)] -const ENC: encrypt_dir_t = 1; /// yescrypt Key Derivation Function (KDF) pub fn yescrypt_kdf( @@ -166,252 +161,6 @@ pub fn yescrypt_kdf( dst } -#[allow(dead_code)] -unsafe fn yescrypt(mut passwd: *const uint8_t, mut setting: *const uint8_t) -> *mut uint8_t { - static mut buf: [uint8_t; 140] = [0; 140]; - let mut local: Local = Local { - base: 0 as *mut libc::c_void, - aligned: 0 as *mut libc::c_void, - base_size: 0, - aligned_size: 0, - }; - let mut retval: *mut uint8_t = 0 as *mut uint8_t; - if yescrypt_init_local(&mut local) != 0 { - return 0 as *mut uint8_t; - } - retval = yescrypt_r( - 0 as *const Shared, - &mut local, - passwd, - strlen(passwd as *mut libc::c_char), - setting, - 0 as *const Binary, - buf.as_mut_ptr(), - size_of::<[uint8_t; 140]>(), - ); - if yescrypt_free_local(&mut local) != 0 { - return 0 as *mut uint8_t; - } - return retval; -} - -#[allow(dead_code)] -unsafe fn yescrypt_r( - mut shared: *const Shared, - mut local: *mut Local, - mut passwd: *const uint8_t, - mut passwdlen: size_t, - mut setting: *const uint8_t, - mut key: *const Binary, - mut buf: *mut uint8_t, - mut buflen: size_t, -) -> *mut uint8_t { - let mut current_block: u64; - let mut saltbin: [libc::c_uchar; 64] = [0; 64]; - let mut hashbin: [libc::c_uchar; 32] = [0; 32]; - let mut src: *const uint8_t = 0 as *const uint8_t; - let mut saltstr: *const uint8_t = 0 as *const uint8_t; - let mut salt: *const uint8_t = 0 as *const uint8_t; - let mut dst: *mut uint8_t = 0 as *mut uint8_t; - let mut need: usize = 0; - let mut prefixlen: usize = 0; - let mut saltstrlen: usize = 0; - let mut saltlen: size_t = 0; - let mut params: Params = Params { - flags: 0, - N: 0, - r: 0, - p: 1, - t: 0, - g: 0, - NROM: 0, - }; - if *setting.offset(0 as libc::c_int as isize) as libc::c_int != '$' as i32 - || *setting.offset(1 as libc::c_int as isize) as libc::c_int != '7' as i32 - && *setting.offset(1 as libc::c_int as isize) as libc::c_int != 'y' as i32 - || *setting.offset(2 as libc::c_int as isize) as libc::c_int != '$' as i32 - { - return 0 as *mut uint8_t; - } - src = setting.offset(3 as libc::c_int as isize); - if *setting.offset(1 as libc::c_int as isize) as libc::c_int == '7' as i32 { - let fresh14 = src; - src = src.offset(1); - let mut N_log2: uint32_t = atoi64(*fresh14); - if N_log2 < 1 as libc::c_int as libc::c_uint || N_log2 > 63 as libc::c_int as libc::c_uint { - return 0 as *mut uint8_t; - } - params.N = (1 as libc::c_int as uint64_t) << N_log2; - src = decode64_uint32_fixed(&mut params.r, 30 as libc::c_int as uint32_t, src); - if src.is_null() { - return 0 as *mut uint8_t; - } - src = decode64_uint32_fixed(&mut params.p, 30 as libc::c_int as uint32_t, src); - if src.is_null() { - return 0 as *mut uint8_t; - } - if !key.is_null() { - return 0 as *mut uint8_t; - } - } else { - let mut flavor: uint32_t = 0; - let mut N_log2_0: uint32_t = 0; - src = decode64_uint32(&mut flavor, src, 0 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - if flavor < 0x2 as libc::c_int as libc::c_uint { - params.flags = flavor; - } else if flavor - <= (0x2 as libc::c_int + (0x3fc as libc::c_int >> 2 as libc::c_int)) as libc::c_uint - { - params.flags = (0x2 as libc::c_int as libc::c_uint).wrapping_add( - flavor.wrapping_sub(0x2 as libc::c_int as libc::c_uint) << 2 as libc::c_int, - ); - } else { - return 0 as *mut uint8_t; - } - src = decode64_uint32(&mut N_log2_0, src, 1 as libc::c_int as uint32_t); - if src.is_null() || N_log2_0 > 63 as libc::c_int as libc::c_uint { - return 0 as *mut uint8_t; - } - params.N = (1 as libc::c_int as uint64_t) << N_log2_0; - src = decode64_uint32(&mut params.r, src, 1 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - if *src as libc::c_int != '$' as i32 { - let mut have: uint32_t = 0; - src = decode64_uint32(&mut have, src, 1 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - if have & 1 as libc::c_int as libc::c_uint != 0 { - src = decode64_uint32(&mut params.p, src, 2 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - } - if have & 2 as libc::c_int as libc::c_uint != 0 { - src = decode64_uint32(&mut params.t, src, 1 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - } - if have & 4 as libc::c_int as libc::c_uint != 0 { - src = decode64_uint32(&mut params.g, src, 1 as libc::c_int as uint32_t); - if src.is_null() { - return 0 as *mut uint8_t; - } - } - if have & 8 as libc::c_int as libc::c_uint != 0 { - let mut NROM_log2: uint32_t = 0; - src = decode64_uint32(&mut NROM_log2, src, 1 as libc::c_int as uint32_t); - if src.is_null() || NROM_log2 > 63 as libc::c_int as libc::c_uint { - return 0 as *mut uint8_t; - } - params.NROM = (1 as libc::c_int as uint64_t) << NROM_log2; - } - } - let fresh15 = src; - src = src.offset(1); - if *fresh15 as libc::c_int != '$' as i32 { - return 0 as *mut uint8_t; - } - } - prefixlen = src.offset_from(setting) as usize; - saltstr = src; - src = strrchr(saltstr as *mut libc::c_char, '$' as i32) as *mut uint8_t; - if !src.is_null() { - saltstrlen = src.offset_from(saltstr) as usize; - } else { - saltstrlen = strlen(saltstr as *mut libc::c_char); - } - if *setting.offset(1 as libc::c_int as isize) as libc::c_int == '7' as i32 { - salt = saltstr; - saltlen = saltstrlen as size_t; - current_block = 1623252117315916725; - } else { - let mut saltend: *const uint8_t = 0 as *const uint8_t; - saltlen = size_of::<[libc::c_uchar; 64]>() as size_t; - saltend = decode64( - saltbin.as_mut_ptr(), - &mut saltlen, - saltstr, - saltstrlen as size_t, - ); - if saltend.is_null() || saltend.offset_from(saltstr) as usize != saltstrlen { - current_block = 3736434875406665187; - } else { - salt = saltbin.as_mut_ptr(); - if !key.is_null() { - encrypt(saltbin.as_mut_ptr(), saltlen, key, ENC); - } - current_block = 1623252117315916725; - } - } - match current_block { - 1623252117315916725 => { - need = prefixlen - .wrapping_add(saltstrlen) - .wrapping_add(1) - .wrapping_add( - (size_of::()) - .wrapping_mul(8) - .wrapping_add(5) - .wrapping_div(6), - ) - .wrapping_add(1); - if !(need > buflen || need < saltstrlen) { - if !(yescrypt_kdf_inner( - shared, - local, - passwd, - passwdlen, - salt, - saltlen, - &mut params, - hashbin.as_mut_ptr(), - size_of::<[libc::c_uchar; 32]>(), - ) != 0) - { - if !key.is_null() { - encrypt( - hashbin.as_mut_ptr(), - size_of::<[libc::c_uchar; 32]>(), - key, - ENC, - ); - } - dst = buf; - memcpy( - dst as *mut libc::c_void, - setting as *const libc::c_void, - prefixlen.wrapping_add(saltstrlen), - ); - dst = dst.offset(prefixlen.wrapping_add(saltstrlen) as isize); - let fresh16 = dst; - dst = dst.offset(1); - *fresh16 = '$' as i32 as uint8_t; - dst = encode64( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - hashbin.as_mut_ptr(), - size_of::<[libc::c_uchar; 32]>(), - ); - if dst.is_null() || dst >= buf.offset(buflen as isize) { - return 0 as *mut uint8_t; - } - *dst = 0 as libc::c_int as uint8_t; - return buf; - } - } - } - _ => {} - } - return 0 as *mut uint8_t; -} - unsafe fn yescrypt_kdf_inner( mut shared: *const Shared, mut local: *mut Local, @@ -468,441 +217,6 @@ unsafe fn yescrypt_kdf_inner( ); } -#[allow(dead_code)] -unsafe fn yescrypt_init_shared( - mut shared: *mut Shared, - mut seed: *const uint8_t, - mut seedlen: size_t, - mut params: *const Params, -) -> libc::c_int { - let mut current_block: u64; - let mut flags: Flags = (*params).flags; - let mut N: uint64_t = (*params).NROM; - let mut r: uint32_t = (*params).r; - let mut p: uint32_t = (*params).p; - let mut t: uint32_t = (*params).t; - let mut half1: Shared = Shared { - base: 0 as *mut libc::c_void, - aligned: 0 as *mut libc::c_void, - base_size: 0, - aligned_size: 0, - }; - let mut half2: Shared = Shared { - base: 0 as *mut libc::c_void, - aligned: 0 as *mut libc::c_void, - base_size: 0, - aligned_size: 0, - }; - let mut salt: [uint8_t; 32] = [0; 32]; - let mut tag: *mut uint32_t = 0 as *mut uint32_t; - if (*params).flags & 0x2 as libc::c_int as libc::c_uint == 0 - || (*params).N != 0 - || (*params).g != 0 - { - return -(1 as libc::c_int); - } - if flags & 0x10000 as libc::c_int as libc::c_uint != 0 { - if ((*shared).aligned).is_null() || (*shared).aligned_size == 0 { - return -(1 as libc::c_int); - } - tag = ((*shared).aligned as *mut uint8_t) - .offset((*shared).aligned_size as isize) - .offset(-(48 as libc::c_int as isize)) as *mut uint32_t; - memset(tag as *mut libc::c_void, 0, 48); - current_block = 2968425633554183086; - } else { - (*shared).aligned = 0 as *mut libc::c_void; - (*shared).base = (*shared).aligned; - (*shared).aligned_size = 0 as libc::c_int as size_t; - (*shared).base_size = (*shared).aligned_size; - if yescrypt_kdf_body( - 0 as *const Shared, - shared, - 0 as *const uint8_t, - 0 as libc::c_int as size_t, - 0 as *const uint8_t, - 0 as libc::c_int as size_t, - flags - | 0x1000000 as libc::c_int as libc::c_uint - | 0x8000000 as libc::c_int as libc::c_uint, - N, - r, - p, - t, - 0 as libc::c_int as uint64_t, - 0 as *mut uint8_t, - 0 as libc::c_int as size_t, - ) != -(2 as libc::c_int) - || ((*shared).aligned).is_null() - { - current_block = 13608846184267058342; - } else { - current_block = 2968425633554183086; - } - } - match current_block { - 2968425633554183086 => { - half2 = *shared; - half1 = half2; - half1.aligned_size = (half1.aligned_size as libc::c_ulong) - .wrapping_div(2 as libc::c_int as libc::c_ulong) - as size_t as size_t; - half2.aligned = (half2.aligned as *mut uint8_t).offset(half1.aligned_size as isize) - as *mut libc::c_void; - half2.aligned_size = half1.aligned_size; - N = (N as libc::c_ulong).wrapping_div(2 as libc::c_int as libc::c_ulong) as uint64_t - as uint64_t; - if !(yescrypt_kdf_body( - 0 as *const Shared, - &mut half1, - seed, - seedlen, - b"yescrypt-ROMhash\0" as *const u8 as *const libc::c_char as *const uint8_t, - 16 as libc::c_int as size_t, - flags | 0x1000000 as libc::c_int as libc::c_uint, - N, - r, - p, - t, - 0 as libc::c_int as uint64_t, - salt.as_mut_ptr(), - size_of::<[uint8_t; 32]>(), - ) != 0) - { - if !(yescrypt_kdf_body( - &mut half1, - &mut half2, - seed, - seedlen, - salt.as_mut_ptr(), - size_of::<[uint8_t; 32]>(), - flags | 0x1000000 as libc::c_int as libc::c_uint, - N, - r, - p, - t, - N, - salt.as_mut_ptr(), - size_of::<[uint8_t; 32]>(), - ) != 0) - { - if !(yescrypt_kdf_body( - &mut half2, - &mut half1, - seed, - seedlen, - salt.as_mut_ptr(), - size_of::<[uint8_t; 32]>(), - flags | 0x1000000 as libc::c_int as libc::c_uint, - N, - r, - p, - t, - N, - salt.as_mut_ptr(), - size_of::<[uint8_t; 32]>(), - ) != 0) - { - tag = ((*shared).aligned as *mut uint8_t) - .offset((*shared).aligned_size as isize) - .offset(-(48 as libc::c_int as isize)) - as *mut uint32_t; - *tag.offset(0 as libc::c_int as isize) = (0x7470797263736579 - as libc::c_ulonglong - & 0xffffffff as libc::c_uint as libc::c_ulonglong) - as uint32_t; - *tag.offset(1 as libc::c_int as isize) = - (0x7470797263736579 as libc::c_ulonglong >> 32 as libc::c_int) - as uint32_t; - *tag.offset(2 as libc::c_int as isize) = (0x687361684d4f522d - as libc::c_ulonglong - & 0xffffffff as libc::c_uint as libc::c_ulonglong) - as uint32_t; - *tag.offset(3 as libc::c_int as isize) = - (0x687361684d4f522d as libc::c_ulonglong >> 32 as libc::c_int) - as uint32_t; - *tag.offset(4 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr() as *const libc::c_void); - *tag.offset(5 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(4 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(6 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(8 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(7 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(12 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(8 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(16 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(9 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(20 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(10 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(24 as libc::c_int as isize) - as *const libc::c_void); - *tag.offset(11 as libc::c_int as isize) = - le32dec(salt.as_mut_ptr().offset(28 as libc::c_int as isize) - as *const libc::c_void); - return 0 as libc::c_int; - } - } - } - } - _ => {} - } - if flags & 0x10000 as libc::c_int as libc::c_uint == 0 { - free((*shared).base); - } - return -(1 as libc::c_int); -} - -#[allow(dead_code)] -unsafe fn yescrypt_digest_shared(mut shared: *mut Shared) -> Binary { - static mut digest: Binary = Binary { uc: [0; 32] }; - let mut tag: *mut uint32_t = 0 as *mut uint32_t; - let mut tag1: uint64_t = 0; - let mut tag2: uint64_t = 0; - if (*shared).aligned_size < 48 { - return digest; - } - tag = ((*shared).aligned as *mut uint8_t) - .offset((*shared).aligned_size as isize) - .offset(-(48 as libc::c_int as isize)) as *mut uint32_t; - tag1 = ((*tag.offset(1 as libc::c_int as isize) as uint64_t) << 32 as libc::c_int) - .wrapping_add(*tag.offset(0 as libc::c_int as isize) as libc::c_ulong); - tag2 = ((*tag.offset(3 as libc::c_int as isize) as uint64_t) << 32 as libc::c_int) - .wrapping_add(*tag.offset(2 as libc::c_int as isize) as libc::c_ulong); - if tag1 as libc::c_ulonglong != 0x7470797263736579 as libc::c_ulonglong - || tag2 as libc::c_ulonglong != 0x687361684d4f522d as libc::c_ulonglong - { - return digest; - } - le32enc( - (digest.uc).as_mut_ptr() as *mut libc::c_void, - *tag.offset(4 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(4 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(5 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(8 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(6 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(12 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(7 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(16 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(8 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(20 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(9 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(24 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(10 as libc::c_int as isize), - ); - le32enc( - (digest.uc).as_mut_ptr().offset(28 as libc::c_int as isize) as *mut libc::c_void, - *tag.offset(11 as libc::c_int as isize), - ); - - return digest; -} - -#[allow(dead_code)] -unsafe fn yescrypt_encode_params( - mut params: *const Params, - mut src: *const uint8_t, - mut srclen: size_t, -) -> *mut uint8_t { - static mut buf: [uint8_t; 96] = [0; 96]; - return yescrypt_encode_params_r( - params, - src, - srclen, - buf.as_mut_ptr(), - size_of::<[uint8_t; 96]>(), - ); -} - -unsafe fn yescrypt_encode_params_r( - mut params: *const Params, - mut src: *const uint8_t, - mut srclen: size_t, - mut buf: *mut uint8_t, - mut buflen: size_t, -) -> *mut uint8_t { - let mut flavor: uint32_t = 0; - let mut N_log2: uint32_t = 0; - let mut NROM_log2: uint32_t = 0; - let mut have: uint32_t = 0; - let mut dst: *mut uint8_t = 0 as *mut uint8_t; - if srclen > usize::MAX / 16 { - return 0 as *mut uint8_t; - } - if (*params).flags < 0x2 as libc::c_int as libc::c_uint { - flavor = (*params).flags; - } else if (*params).flags & 0x3 as libc::c_int as libc::c_uint - == 0x2 as libc::c_int as libc::c_uint - && (*params).flags <= (0x2 as libc::c_int | 0x3fc as libc::c_int) as libc::c_uint - { - flavor = - (0x2 as libc::c_int as libc::c_uint).wrapping_add((*params).flags >> 2 as libc::c_int); - } else { - return 0 as *mut uint8_t; - } - N_log2 = N2log2((*params).N); - if N_log2 == 0 { - return 0 as *mut uint8_t; - } - NROM_log2 = N2log2((*params).NROM); - if (*params).NROM != 0 && NROM_log2 == 0 { - return 0 as *mut uint8_t; - } - if ((*params).r as uint64_t).wrapping_mul((*params).p as uint64_t) - >= ((1 as libc::c_uint) << 30 as libc::c_int) as libc::c_ulong - { - return 0 as *mut uint8_t; - } - dst = buf; - let fresh17 = dst; - dst = dst.offset(1); - *fresh17 = '$' as i32 as uint8_t; - let fresh18 = dst; - dst = dst.offset(1); - *fresh18 = 'y' as i32 as uint8_t; - let fresh19 = dst; - dst = dst.offset(1); - *fresh19 = '$' as i32 as uint8_t; - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - flavor, - 0 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - N_log2, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - (*params).r, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - have = 0 as libc::c_int as uint32_t; - if (*params).p != 1 as libc::c_int as libc::c_uint { - have |= 1 as libc::c_int as libc::c_uint; - } - if (*params).t != 0 { - have |= 2 as libc::c_int as libc::c_uint; - } - if (*params).g != 0 { - have |= 4 as libc::c_int as libc::c_uint; - } - if NROM_log2 != 0 { - have |= 8 as libc::c_int as libc::c_uint; - } - if have != 0 { - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - have, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - } - if (*params).p != 1 as libc::c_int as libc::c_uint { - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - (*params).p, - 2 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - } - if (*params).t != 0 { - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - (*params).t, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - } - if (*params).g != 0 { - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - (*params).g, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - } - if NROM_log2 != 0 { - dst = encode64_uint32( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - NROM_log2, - 1 as libc::c_int as uint32_t, - ); - if dst.is_null() { - return 0 as *mut uint8_t; - } - } - if dst >= buf.offset(buflen as isize) { - return 0 as *mut uint8_t; - } - let fresh20 = dst; - dst = dst.offset(1); - *fresh20 = '$' as i32 as uint8_t; - dst = encode64( - dst, - buflen.wrapping_sub(dst.offset_from(buf) as usize), - src, - srclen, - ); - if dst.is_null() || dst >= buf.offset(buflen as isize) { - return 0 as *mut uint8_t; - } - *dst = 0 as libc::c_int as uint8_t; - return buf; -} - -#[allow(dead_code)] -unsafe fn yescrypt_free_shared(mut shared: *mut Shared) -> libc::c_int { - free((*shared).base); - (*shared).aligned = 0 as *mut libc::c_void; - (*shared).base = (*shared).aligned; - (*shared).aligned_size = 0 as libc::c_int as size_t; - (*shared).base_size = (*shared).aligned_size; - return 0 as libc::c_int; -} - unsafe fn yescrypt_init_local(mut local: *mut Local) -> libc::c_int { (*local).aligned = 0 as *mut libc::c_void; (*local).base = (*local).aligned; @@ -911,155 +225,6 @@ unsafe fn yescrypt_init_local(mut local: *mut Local) -> libc::c_int { return 0 as libc::c_int; } -unsafe fn yescrypt_free_local(_local: *mut Local) -> libc::c_int { - return 0 as libc::c_int; -} - -#[allow(dead_code)] -unsafe fn yescrypt_reencrypt( - mut hash: *mut uint8_t, - mut from_key: *const Binary, - mut to_key: *const Binary, -) -> *mut uint8_t { - let mut current_block: u64; - let mut retval: *mut uint8_t = 0 as *mut uint8_t; - let mut saltstart: *mut uint8_t = 0 as *mut uint8_t; - let mut hashstart: *mut uint8_t = 0 as *mut uint8_t; - let mut hashend: *const uint8_t = 0 as *const uint8_t; - let mut saltbin: [libc::c_uchar; 64] = [0; 64]; - let mut hashbin: [libc::c_uchar; 32] = [0; 32]; - let mut saltstrlen: size_t = 0; - let mut saltlen: size_t = 0 as libc::c_int as size_t; - let mut hashlen: size_t = 0; - if strncmp( - hash as *mut libc::c_char, - b"$y$\0" as *const u8 as *const libc::c_char, - 3, - ) != 0 - { - return 0 as *mut uint8_t; - } - saltstart = 0 as *mut uint8_t; - hashstart = strrchr(hash as *mut libc::c_char, '$' as i32) as *mut uint8_t; - if !hashstart.is_null() { - if hashstart > hash { - saltstart = hashstart.offset(-(1 as libc::c_int as isize)); - while *saltstart as libc::c_int != '$' as i32 && saltstart > hash { - saltstart = saltstart.offset(-1); - saltstart; - } - if *saltstart as libc::c_int == '$' as i32 { - saltstart = saltstart.offset(1); - saltstart; - } - } - hashstart = hashstart.offset(1); - hashstart; - } else { - hashstart = hash; - } - saltstrlen = (if !saltstart.is_null() { - hashstart - .offset(-(1 as libc::c_int as isize)) - .offset_from(saltstart) as libc::c_long - } else { - 0 as libc::c_int as libc::c_long - }) as size_t; - if saltstrlen > ((64 * 8 + 5) / 6) - || strlen(hashstart as *mut libc::c_char) - != (size_of::()) - .wrapping_mul(8) - .wrapping_add(5) - .wrapping_div(6) - { - return 0 as *mut uint8_t; - } - if saltstrlen != 0 { - let mut saltend: *const uint8_t = 0 as *const uint8_t; - saltlen = size_of::<[libc::c_uchar; 64]>(); - saltend = decode64(saltbin.as_mut_ptr(), &mut saltlen, saltstart, saltstrlen); - if saltend.is_null() - || *saltend as libc::c_int != '$' as i32 - || !(1..=64).contains(&saltlen) - { - current_block = 11385396242402735691; - } else { - if !from_key.is_null() { - encrypt(saltbin.as_mut_ptr(), saltlen, from_key, ENC); - } - if !to_key.is_null() { - encrypt(saltbin.as_mut_ptr(), saltlen, to_key, DEC); - } - current_block = 14401909646449704462; - } - } else { - current_block = 14401909646449704462; - } - match current_block { - 14401909646449704462 => { - hashlen = size_of::<[libc::c_uchar; 32]>(); - hashend = decode64( - hashbin.as_mut_ptr(), - &mut hashlen, - hashstart, - (size_of::()) - .wrapping_mul(8) - .wrapping_add(5) - .wrapping_div(6), - ); - if !(hashend.is_null() - || *hashend as libc::c_int != 0 - || hashlen != size_of::<[libc::c_uchar; 32]>()) - { - if !from_key.is_null() { - encrypt(hashbin.as_mut_ptr(), hashlen, from_key, DEC); - } - if !to_key.is_null() { - encrypt(hashbin.as_mut_ptr(), hashlen, to_key, ENC); - } - if saltstrlen != 0 { - if (encode64( - saltstart, - saltstrlen.wrapping_add(1), - saltbin.as_mut_ptr(), - saltlen, - )) - .is_null() - { - current_block = 11385396242402735691; - } else { - *saltstart.offset(saltstrlen as isize) = '$' as i32 as uint8_t; - current_block = 17281240262373992796; - } - } else { - current_block = 17281240262373992796; - } - match current_block { - 11385396242402735691 => {} - _ => { - if !(encode64( - hashstart, - (size_of::()) - .wrapping_mul(8) - .wrapping_add(5) - .wrapping_div(6) - .wrapping_add(1), - hashbin.as_mut_ptr(), - hashlen, - )) - .is_null() - { - retval = hash; - } - } - } - } - } - _ => {} - } - return retval; -} - unsafe fn yescrypt_kdf_body( mut shared: *const Shared, mut local: *mut Local,