Module: sip-router Branch: master Commit: b6bd830ea93024324354dc3fb5eceaddbd8d20a3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b6bd830e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Thu Aug 14 11:14:10 2014 +0200
lib/srutils: new files with wrappers around sha256 and other hashing functions
---
lib/srutils/shautils.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/srutils/shautils.h | 36 +++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 0 deletions(-)
diff --git a/lib/srutils/shautils.c b/lib/srutils/shautils.c new file mode 100644 index 0000000..25f9e38 --- /dev/null +++ b/lib/srutils/shautils.c @@ -0,0 +1,63 @@ +/* + * sha and other hashing utilities + * + * Copyright (C) 2014 1&1 Germany + * + * This file is part of Kamailio, a free SIP server. + * + * Kamailio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * Kamailio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "../../md5.h" +#include "../../ut.h" +#include "shautils.h" + +/*! \brief Compute MD5 checksum */ +void compute_md5(char *dst, char *src, int src_len) +{ + MD5_CTX context; + unsigned char digest[16]; + MD5Init (&context); + MD5Update (&context, src, src_len); + U_MD5Final (digest, &context); + string2hex(digest, 16, dst); +} + +/*! \brief Compute SHA256 checksum */ +void compute_sha256(char *dst, u_int8_t *src, int src_len) +{ + SHA256_CTX ctx256; + SHA256_Init(&ctx256); + SHA256_Update(&ctx256, src, src_len); + SHA256_End(&ctx256, dst); +} + +/*! \brief Compute SHA384 checksum */ +void compute_sha384(char *dst, u_int8_t *src, int src_len) +{ + SHA384_CTX ctx384; + SHA384_Init(&ctx384); + SHA384_Update(&ctx384, src, src_len); + SHA384_End(&ctx384, dst); +} + +/*! \brief Compute SHA512 checksum */ +void compute_sha512(char *dst, u_int8_t *src, int src_len) +{ + SHA512_CTX ctx512; + SHA512_Init(&ctx512); + SHA512_Update(&ctx512, src, src_len); + SHA512_End(&ctx512, dst); +} diff --git a/lib/srutils/shautils.h b/lib/srutils/shautils.h new file mode 100644 index 0000000..1d7b0e4 --- /dev/null +++ b/lib/srutils/shautils.h @@ -0,0 +1,36 @@ +/* + * sha and other hashing utilities + * + * Copyright (C) 2014 1&1 Germany + * + * This file is part of Kamailio, a free SIP server. + * + * Kamailio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * Kamailio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _SHAUTILS_H_ +#define _SHAUTILS_H_ + +#include "sha256.h" + +void compute_md5(char *dst, char *src, int src_len); + +void compute_sha256(char *dst, u_int8_t *src, int src_len); + +void compute_sha384(char *dst, u_int8_t *src, int src_len); + +void compute_sha512(char *dst, u_int8_t *src, int src_len); + +#endif