projects
/
platform
/
upstream
/
glib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
wip junk
[platform/upstream/glib.git]
/
glib
/
ghmac.c
diff --git
a/glib/ghmac.c
b/glib/ghmac.c
index
20e8fcd
..
a5ac705
100644
(file)
--- a/
glib/ghmac.c
+++ b/
glib/ghmac.c
@@
-13,9
+13,7
@@
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Stef Walter <stefw@collabora.co.uk>
*/
*
* Author: Stef Walter <stefw@collabora.co.uk>
*/
@@
-28,6
+26,7
@@
#include "glib/galloca.h"
#include "gatomic.h"
#include "glib/galloca.h"
#include "gatomic.h"
+#include "gslice.h"
#include "gmem.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
#include "gmem.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
@@
-38,18
+37,20
@@
/**
* SECTION:hmac
* @title: Secure HMAC Digests
/**
* SECTION:hmac
* @title: Secure HMAC Digests
- * @short_description:
C
omputes the HMAC for data
+ * @short_description:
c
omputes the HMAC for data
*
* HMACs should be used when producing a cookie or hash based on data
* and a key. Simple mechanisms for using SHA1 and other algorithms to
* digest a key and data together are vulnerable to various security
*
* HMACs should be used when producing a cookie or hash based on data
* and a key. Simple mechanisms for using SHA1 and other algorithms to
* digest a key and data together are vulnerable to various security
- * issues. <ulink url="http://en.wikipedia.org/wiki/HMAC">HMAC</ulink>
+ * issues.
+ * [HMAC](http://en.wikipedia.org/wiki/HMAC)
* uses algorithms like SHA1 in a secure way to produce a digest of a
* key and data.
*
* Both the key and data are arbitrary byte arrays of bytes or characters.
*
* uses algorithms like SHA1 in a secure way to produce a digest of a
* key and data.
*
* Both the key and data are arbitrary byte arrays of bytes or characters.
*
- * Support for HMAC Digests has been added in GLib 2.30.
+ * Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512
+ * in GLib 2.42.
*/
struct _GHmac
*/
struct _GHmac
@@
-80,7
+81,9
@@
struct _GHmac
* will be closed and it won't be possible to call g_hmac_update()
* on it anymore.
*
* will be closed and it won't be possible to call g_hmac_update()
* on it anymore.
*
- * Return value: the newly created #GHmac, or %NULL.
+ * Support for digests of type %G_CHECKSUM_SHA512 has been added in GLib 2.42.
+ *
+ * Returns: the newly created #GHmac, or %NULL.
* Use g_hmac_unref() to free the memory allocated by it.
*
* Since: 2.30
* Use g_hmac_unref() to free the memory allocated by it.
*
* Since: 2.30
@@
-107,7
+110,10
@@
g_hmac_new (GChecksumType digest_type,
block_size = 64; /* RFC 2104 */
break;
case G_CHECKSUM_SHA256:
block_size = 64; /* RFC 2104 */
break;
case G_CHECKSUM_SHA256:
- block_size = 64; /* RFC draft-kelly-ipsec-ciph-sha2-01 */
+ block_size = 64; /* RFC 4868 */
+ break;
+ case G_CHECKSUM_SHA512:
+ block_size = 128; /* RFC 4868 */
break;
default:
g_return_val_if_reached (NULL);
break;
default:
g_return_val_if_reached (NULL);
@@
-160,7
+166,7
@@
g_hmac_new (GChecksumType digest_type,
* g_hmac_get_string() or g_hmac_get_digest(), the copied
* HMAC will be closed as well.
*
* g_hmac_get_string() or g_hmac_get_digest(), the copied
* HMAC will be closed as well.
*
- * Return
value
: the copy of the passed #GHmac. Use g_hmac_unref()
+ * Return
s
: the copy of the passed #GHmac. Use g_hmac_unref()
* when finished using it.
*
* Since: 2.30
* when finished using it.
*
* Since: 2.30
@@
-173,6
+179,7
@@
g_hmac_copy (const GHmac *hmac)
g_return_val_if_fail (hmac != NULL, NULL);
copy = g_slice_new (GHmac);
g_return_val_if_fail (hmac != NULL, NULL);
copy = g_slice_new (GHmac);
+ copy->ref_count = 1;
copy->digest_type = hmac->digest_type;
copy->digesti = g_checksum_copy (hmac->digesti);
copy->digesto = g_checksum_copy (hmac->digesto);
copy->digest_type = hmac->digest_type;
copy->digesti = g_checksum_copy (hmac->digesti);
copy->digesto = g_checksum_copy (hmac->digesto);
@@
-188,7
+195,7
@@
g_hmac_copy (const GHmac *hmac)
*
* This function is MT-safe and may be called from any thread.
*
*
* This function is MT-safe and may be called from any thread.
*
- * Return
value
: the passed in #GHmac.
+ * Return
s
: the passed in #GHmac.
*
* Since: 2.30
**/
*
* Since: 2.30
**/
@@
-263,7
+270,7
@@
g_hmac_update (GHmac *hmac,
*
* The hexadecimal characters will be lower case.
*
*
* The hexadecimal characters will be lower case.
*
- * Return
value
: the hexadecimal representation of the HMAC. The
+ * Return
s
: the hexadecimal representation of the HMAC. The
* returned string is owned by the HMAC and should not be modified
* or freed.
*
* returned string is owned by the HMAC and should not be modified
* or freed.
*
@@
-278,9
+285,13
@@
g_hmac_get_string (GHmac *hmac)
g_return_val_if_fail (hmac != NULL, NULL);
digest_len = g_checksum_type_get_length (hmac->digest_type);
g_return_val_if_fail (hmac != NULL, NULL);
digest_len = g_checksum_type_get_length (hmac->digest_type);
- buffer = g_
malloc
(digest_len);
+ buffer = g_
alloca
(digest_len);
+ /* This is only called for its side-effect of updating hmac->digesto... */
g_hmac_get_digest (hmac, buffer, &digest_len);
g_hmac_get_digest (hmac, buffer, &digest_len);
+ /* ... because we get the string from the checksum rather than
+ * stringifying buffer ourselves
+ */
return g_checksum_get_string (hmac->digesto);
}
return g_checksum_get_string (hmac->digesto);
}
@@
-331,7
+342,7
@@
g_hmac_get_digest (GHmac *hmac,
*
* The hexadecimal string returned will be in lower case.
*
*
* The hexadecimal string returned will be in lower case.
*
- * Return
value
: the HMAC of the binary data as a string in hexadecimal.
+ * Return
s
: the HMAC of the binary data as a string in hexadecimal.
* The returned string should be freed with g_free() when done using it.
*
* Since: 2.30
* The returned string should be freed with g_free() when done using it.
*
* Since: 2.30
@@
-371,7
+382,7
@@
g_compute_hmac_for_data (GChecksumType digest_type,
*
* The hexadecimal string returned will be in lower case.
*
*
* The hexadecimal string returned will be in lower case.
*
- * Return
value
: the HMAC as a hexadecimal string.
+ * Return
s
: the HMAC as a hexadecimal string.
* The returned string should be freed with g_free()
* when done using it.
*
* The returned string should be freed with g_free()
* when done using it.
*