password-scheme-rpa.c revision a4ac325c2802693c6b761e5a8fda961e5d7490ea
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "lib.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "buffer.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "md5.h"
203bb272804e4394ae07103cdc8ce67041ba21a1Aki Tuomi#include "hex-binary.h"
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen#include "safe-memset.h"
5d60e31c7b701b606067a20bc88dcc8a6de7bbd6Timo Sirainen#include "password-scheme.h"
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenvoid *ucs2be_str(pool_t pool, const char *str, size_t *size);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen/*
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen * Convert string to big-endian ucs2.
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen */
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainenvoid *ucs2be_str(pool_t pool, const char *str, size_t *size)
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen{
9dd1c256910f1fb42823116a641e7edb3ad11970Timo Sirainen buffer_t *buf = buffer_create_dynamic(pool, 32, (size_t)-1);
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen while (*str) {
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen buffer_append_c(buf, '\0');
daa7e7459749ae8f82cd3eed9c44522d81c609a3Timo Sirainen buffer_append_c(buf, *str++);
46ec5983bf4519ea42dbfcae3d7c62be0d8ef95fTimo Sirainen }
bbadd5331f534017cf62d5183003b3d9fdad079eTimo Sirainen
6523f54d1521edf894880f2d45e75cef5dd31c3dTimo Sirainen *size = buffer_get_used_size(buf);
72f5f2c5c6905b5d3f389b424313e2c450dfad96Timo Sirainen return buffer_free_without_data(buf);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen}
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenconst char *password_generate_rpa(const char *pw)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen{
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen unsigned char hash[16];
373492be949e159fda651807b3acda2c5c077027Timo Sirainen unsigned char *ucs2be_pw;
bbadd5331f534017cf62d5183003b3d9fdad079eTimo Sirainen size_t size;
ab90f702ceedb7ba445a9a592be0b213b27cbafaStephan Bosch
ab90f702ceedb7ba445a9a592be0b213b27cbafaStephan Bosch ucs2be_pw = ucs2be_str(unsafe_data_stack_pool, pw, &size);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen md5_get_digest(ucs2be_pw, size, hash);
da7f1a07f583df8905684a7b78469960afd7c78dPhil Carmody
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen safe_memset(ucs2be_pw, 0, size);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen return binary_to_hex(hash, sizeof(hash));
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen}
7bafda1813454621e03615e83d55bccfa7cc56bdTimo Sirainen