DES_READ_PW(3) | Library Functions Manual | DES_READ_PW(3)

# NAME

`EVP_read_pw_string`, `EVP_read_pw_string_min`, `EVP_set_pw_prompt`, `EVP_get_pw_prompt` — compatibility user interface functions

# SYNOPSIS

library “libcrypto”
`#include <openssl/evp.h>`

int
`EVP_read_pw_string`(char *buf, int length, const char *prompt, int verify);

int
`EVP_read_pw_string_min`(char *buf, int min_length, int length, const char *prompt, int verify);

void
`EVP_set_pw_prompt`(const char *default_prompt);

char *
`EVP_get_pw_prompt`(void);

# DESCRIPTION

`EVP_read_pw_string`() writes the prompt to /dev/tty, or, if that could not be opened, to standard output, turns echo off, and reads an input string from /dev/tty, or, if that could not be opened, from standard input. The string is returned in buf, which must have space for at least length bytes. If the length argument exceeds `BUFSIZ`, `BUFSIZ` is used instead. If verify is set, the user is asked for the password twice and unless the two copies match, an error is returned.

`EVP_read_pw_string_min`() additionally checks that the password is at least min_length bytes long.

`EVP_set_pw_prompt`() sets a default prompt to a copy of default_prompt, or clears the default prompt if the default_prompt argument is `NULL` or an empty string. If the default_prompt argument is longer than 79 bytes, the copy is silently truncated to a string length of 79 bytes.

As long as a default prompt is set, `EVP_read_pw_string`() and `EVP_read_pw_string_min`() can be called with a prompt argument of `NULL`, in which case the default prompt is used instead.

# RETURN VALUES

`EVP_read_pw_string`() and `EVP_read_pw_string_min`() return 0 on success or a negative value on failure.

They return -1 if length is less than or equal to zero or on memory allocation failure. They return -1 or -2 if the internal call to UI_process(3) fails.

In addition, EVP_read_pw_string_min returns -1 if min_length is negative, if length is less than or equal to min_length, or if the user entered a password shorter than min_length.

`EVP_get_pw_prompt`() returns an internal pointer to static memory containing the default prompt, or `NULL` if no default prompt is set.

# SEE ALSO

UI_new(3)

# HISTORY

`EVP_read_pw_string`() first appeared in SSLeay 0.5.1 and `EVP_set_pw_prompt`() and `EVP_get_pw_prompt`() in SSLeay 0.6.0. These functions have been available since OpenBSD 2.4.

`EVP_read_pw_string_min`() first appeared in OpenSSL 1.0.0 and has been available since OpenBSD 4.9.

June 8, 2025 | Debian