view src/auth/password-scheme-rpa.c @ 19604:c996bc091c6b

master: Do not close stdout if going foreground This lets one to use /dev/stdout for logging. Mainly useful for testing purposes where we can generate log output to stdout and use tee to write it to a file for later examination.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Mon, 18 Jan 2016 15:50:23 +0200
parents a6a49d5efc59
children 8f33680c6722
line wrap: on
line source


#include "lib.h"
#include "buffer.h"
#include "md5.h"
#include "hex-binary.h"
#include "safe-memset.h"
#include "password-scheme.h"

void *ucs2be_str(pool_t pool, const char *str, size_t *size);

/*
 * Convert string to big-endian ucs2.
 */
void *ucs2be_str(pool_t pool, const char *str, size_t *size)
{
	buffer_t *buf = buffer_create_dynamic(pool, 32);

	while (*str) {
		buffer_append_c(buf, '\0');
		buffer_append_c(buf, *str++);
	}

	*size = buffer_get_used_size(buf);
	return buffer_free_without_data(&buf);
}

void password_generate_rpa(const char *pw, unsigned char result[])
{
	unsigned char *ucs2be_pw;
	size_t size;

	ucs2be_pw = ucs2be_str(unsafe_data_stack_pool, pw, &size);
	md5_get_digest(ucs2be_pw, size, result);
	safe_memset(ucs2be_pw, 0, size);
}