view src/auth/password-scheme-rpa.c @ 2708:f1e9f3ec8135 HEAD

Buffer API change: we no longer support limited sized buffers where writes past limit wouldn't kill the process. They weren't used hardly anywhere, they could have hidden bugs and the code for handling them was too complex. This also changed base64 and hex-binary APIs.
author Timo Sirainen <tss@iki.fi>
date Fri, 08 Oct 2004 20:51:47 +0300
parents abef2ac8843a
children 47add4b664af
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);
}

const char *password_generate_rpa(const char *pw)
{
	unsigned char hash[16];
	unsigned char *ucs2be_pw;
	size_t size;

	ucs2be_pw = ucs2be_str(unsafe_data_stack_pool, pw, &size);

	md5_get_digest(ucs2be_pw, size, hash);

	safe_memset(ucs2be_pw, 0, size);

	return binary_to_hex(hash, sizeof(hash));
}