File: bcrypt.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#' Bcrypt PWKDF
#'
#' Password based key derivation function with bcrypt. This is not
#' part of openssl. It is needed to parse private key files which are
#' encoded in the [new openssh format](https://cvsweb.openbsd.org/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD).
#'
#' @export
#' @rdname pbkdf
#' @useDynLib openssl R_bcrypt_pbkdf
#' @param password string or raw vector with password
#' @param salt raw vector with (usually 16) bytes
#' @param rounds number of hashing rounds
#' @param size desired length of the output key
bcrypt_pbkdf <- function(password, salt, rounds = 16L, size = 32L){
  if(is.character(password))
    password <- charToRaw(password)
  stopifnot(is.raw(password))
  stopifnot(is.raw(salt))
  stopifnot(is.integer(rounds))
  stopifnot(is.integer(size))
  .Call(R_bcrypt_pbkdf, password, salt, rounds, size)
}