19557f192d37cd54a1a090a8a26d9d47265e4413Aki Tuomi * OTP hash generation.
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen * Copyright (c) 2006 Andrey Panin <pazke@donpac.ru>
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen * This software is released under the MIT license.
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen void (*update)(void *ctx, const void *data, const size_t size);
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenstatic void md4_fold(struct md4_context *ctx, void *res)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenstatic void md5_fold(struct md5_context *ctx, void *res)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen * Sometimes I simply can't look at code generated by gcc.
4081894c16e50f37639d9826ebca4394b398c35eTimo Sirainenstatic inline uint32_t swab_uint32(uint32_t val)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen asm("xchgb %b0, %h0\n"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen "rorl $16, %0\n"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen "xchgb %b0, %h0\n"
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen val = ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen ((val & 0xff0000) >> 8) | ((val >> 24) & 0xff);
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenstatic void sha1_fold(struct sha1_ctxt *ctx, void *res)
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody#define F_INIT(name) ((void (*)(void *)) (name))
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody#define F_UPDATE(name) ((void (*)(void *, const void *, size_t)) (name))
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody#define F_FINAL(name) ((void (*)(void *, void *)) (name))
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody#define F_FOLD(name) ((void (*)(void *, void *)) (name))
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody { "md4", F_INIT(md4_init), F_UPDATE(md4_update), F_FINAL(md4_final), F_FOLD(md4_fold) },
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody { "md5", F_INIT(md5_init), F_UPDATE(md5_update), F_FINAL(md5_final), F_FOLD(md5_fold) },
8e018b1e83a6e22d8c520186e3e74a4d9fcb8888Phil Carmody { "sha1", F_INIT(sha1_init), F_UPDATE(sha1_loop), F_FINAL(sha1_result), F_FOLD(sha1_fold) },
fd1f0e9ef52b3e157cfd1a01c464c2ac7458ab17Timo Sirainen unsigned int i;
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainenvoid digest_init(struct digest_context *ctx, const unsigned int algo)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenvoid digest_update(struct digest_context *ctx, const void *data,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenvoid digest_final(struct digest_context *ctx, unsigned char *result)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenvoid digest_otp_final(struct digest_context *ctx, unsigned char *result)
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenvoid otp_hash(unsigned int algo, const char *seed, const char *passphrase,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen digest_update(&ctx, passphrase, strlen(passphrase));
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen while (step-- > 0) {
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainenvoid otp_next_hash(unsigned int algo, const unsigned char *prev,
e9e2d23e1ea5a149a7d8828d2a45b9f2313c3785Timo Sirainen unsigned char *result)