pub unsafe fn ykpiv_util_get_derived_mgm(
    state: *mut YubiKey,
    pin: *const u8,
    pin_len: usize,
    mgm: *mut YkPivMgm,
) -> ErrorKind {
    let mut data = [0u8; YKPIV_OBJ_MAX_SIZE];
    let mut cb_data: usize = data.len();
    let mut p_item: *mut u8 = ptr::null_mut();
    let mut cb_item: usize = 0;
    let mut res: ErrorKind = ErrorKind::Ok;

    if state.is_null() {
        return ErrorKind::GenericError;
    }

    if pin.is_null() || pin_len == 0 || mgm.is_null() {
        return ErrorKind::GenericError;
    }

    if _ykpiv_begin_transaction(state) != ErrorKind::Ok {
        return ErrorKind::PcscError;
    }

    if _ykpiv_ensure_application_selected(state) == ErrorKind::Ok {
        res = _read_metadata(state, 0x80u8, data.as_mut_ptr(), &mut cb_data);

        if res == ErrorKind::Ok {
            res = _get_metadata_item(
                data.as_mut_ptr(),
                cb_data,
                0x82u8,
                &mut p_item,
                &mut cb_item,
            );

            if res == ErrorKind::Ok {
                if cb_item != 16usize {
                    if (*state).verbose != 0 {
                        eprintln!(
                            "derived mgm salt exists, but is incorrect size = {}",
                            cb_item,
                        );
                    }
                    res = ErrorKind::GenericError;
                } else {
                    let p5rc = pkcs5_pbkdf2_sha1(
                        pin,
                        pin_len,
                        p_item,
                        cb_item,
                        10000,
                        (*mgm).0.as_mut_ptr(),
                        (*mgm).0.len(),
                    );

                    if p5rc != Pkcs5ErrorKind::Ok {
                        if (*state).verbose != 0 {
                            eprintln!("pbkdf2 failure, err = {:?}", p5rc);
                        }

                        res = ErrorKind::GenericError;
                    }
                }
            }
        }
    }

    _ykpiv_end_transaction(state);
    res
}
/// Get derived management key (MGM)
Get derived management key (MGM)
Get derived management key ( MGM )
pub unsafe fn ykpiv_util_get_derived_mgm(
    state: *mut YubiKey,
    pin: *const u8,
    pin_len: usize,
    mgm: *mut YkPivMgm,
) -> ErrorKind {
    let mut data = [0u8; YKPIV_OBJ_MAX_SIZE];
    let mut cb_data: usize = data.len();
    let mut p_item: *mut u8 = ptr::null_mut();
    let mut cb_item: usize = 0;
    let mut res: ErrorKind = ErrorKind::Ok;
    if state.is_null() {
        return ErrorKind::GenericError;
    }
    if pin.is_null() || pin_len == 0 || mgm.is_null() {
        return ErrorKind::GenericError;
    }
    if _ykpiv_begin_transaction(state) != ErrorKind::Ok {
        return ErrorKind::PcscError;
    }
    if _ykpiv_ensure_application_selected(state) == ErrorKind::Ok {
        res = _read_metadata(state, 0x80u8, data.as_mut_ptr(), &mut cb_data);
        if res == ErrorKind::Ok {
            res = _get_metadata_item(
                data.as_mut_ptr(),
                cb_data,
                0x82u8,
                &mut p_item,
                &mut cb_item,
            );
            if res == ErrorKind::Ok {
                if cb_item != 16usize {
                    if (*state).verbose != 0 {
                        eprintln!(
                            "derived mgm salt exists, but is incorrect size = {}",
                            cb_item,
                        );
                    }
                    res = ErrorKind::GenericError;
                } else {
                    let p5rc = pkcs5_pbkdf2_sha1(
                        pin,
                        pin_len,
                        p_item,
                        cb_item,
                        10000,
                        (*mgm).0.as_mut_ptr(),
                        (*mgm).0.len(),
                    );
                    if p5rc != Pkcs5ErrorKind::Ok {
                        if (*state).verbose != 0 {
                            eprintln!("pbkdf2 failure, err = {:?}", p5rc);
                        }
                        res = ErrorKind::GenericError;
                    }
                }
            }
        }
    }
    _ykpiv_end_transaction(state);
    res
}
pub unsafe fn ykpiv_util_get_derived_mgm ( state : * mut YubiKey , pin : * const u8 , pin_len : usize , mgm : * mut YkPivMgm , ) -> ErrorKind { let mut data = [ 0u8 ; YKPIV_OBJ_MAX_SIZE ] ; let mut cb_data : usize = data . len ( ) ; let mut p_item : * mut u8 = ptr :: null_mut ( ) ; let mut cb_item : usize = 0 ; let mut res : ErrorKind = ErrorKind :: Ok ; if state . is_null ( ) { return ErrorKind :: GenericError ; } if pin . is_null ( ) || pin_len == 0 || mgm . is_null ( ) { return ErrorKind :: GenericError ; } if _ykpiv_begin_transaction ( state ) != ErrorKind :: Ok { return ErrorKind :: PcscError ; } if _ykpiv_ensure_application_selected ( state ) == ErrorKind :: Ok { res = _read_metadata ( state , 0x80u8 , data . as_mut_ptr ( ) , & mut cb_data ) ; if res == ErrorKind :: Ok { res = _get_metadata_item ( data . as_mut_ptr ( ) , cb_data , 0x82u8 , & mut p_item , & mut cb_item , ) ; if res == ErrorKind :: Ok { if cb_item != 16usize { if ( * state ) . verbose != 0 { eprintln ! ( " " cb_item ) ; } res = ErrorKind :: GenericError ; } else { let p5rc = pkcs5_pbkdf2_sha1 ( pin , pin_len , p_item , cb_item , 10000 , ( * mgm ) . 0 . as_mut_ptr ( ) , ( * mgm ) . 0 . len ( ) , ) ; if p5rc != Pkcs5ErrorKind :: Ok { if ( * state ) . verbose != 0 { eprintln ! ( " " p5rc ) ; } res = ErrorKind :: GenericError ; } } } } } _ykpiv_end_transaction ( state ) ; res }
Get derived management key (MGM)
Get derived management key ( MGM )
state
*mut YubiKey
pin
*const u8
pin_len
usize
mgm
*mut YkPivMgm