From 08c9cc0938d6cad9e059a920e9a4bcbecae810b9 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 29 Mar 2013 20:42:44 -0400 Subject: [PATCH] HMAC function rename for consistency Make sure that HMAC function names conform to previously established get_*, set_* naming convention. --- client/fwknop.c | 2 +- lib/fko.h | 4 ++-- lib/fko_funcs.c | 2 +- lib/fko_hmac.c | 6 +++--- perl/FKO/FKO.xs | 6 +++--- perl/FKO/lib/FKO.pm | 6 +++--- python/fko.py | 8 ++++---- python/fkomodule.c | 16 +++++++-------- server/utils.c | 2 +- test/fko-python.py | 37 ++++++++++++++++++++++++++++++++++ test/fko-wrapper/fko_wrapper.c | 2 +- 11 files changed, 64 insertions(+), 27 deletions(-) create mode 100755 test/fko-python.py diff --git a/client/fwknop.c b/client/fwknop.c index 8c0a312c..9f0aa79a 100644 --- a/client/fwknop.c +++ b/client/fwknop.c @@ -1175,7 +1175,7 @@ display_ctx(fko_ctx_t ctx) fko_get_spa_encryption_type(ctx, &encryption_type); fko_get_spa_encryption_mode(ctx, &encryption_mode); fko_get_encoded_data(ctx, &enc_data); - fko_get_hmac_data(ctx, &hmac_data); + fko_get_spa_hmac(ctx, &hmac_data); fko_get_spa_digest(ctx, &spa_digest); fko_get_spa_data(ctx, &spa_data); diff --git a/lib/fko.h b/lib/fko.h index ded984ce..f9bb7988 100644 --- a/lib/fko.h +++ b/lib/fko.h @@ -282,9 +282,9 @@ DLL_API int fko_decrypt_spa_data(fko_ctx_t ctx, const char * const dec_key, const int dec_key_len); DLL_API int fko_verify_hmac(fko_ctx_t ctx, const char * const hmac_key, const int hmac_key_len); -DLL_API int fko_calculate_hmac(fko_ctx_t ctx, const char * const hmac_key, +DLL_API int fko_set_spa_hmac(fko_ctx_t ctx, const char * const hmac_key, const int hmac_key_len); -DLL_API int fko_get_hmac_data(fko_ctx_t ctx, char **enc_data); +DLL_API int fko_get_spa_hmac(fko_ctx_t ctx, char **enc_data); DLL_API int fko_get_encoded_data(fko_ctx_t ctx, char **enc_data); diff --git a/lib/fko_funcs.c b/lib/fko_funcs.c index 72b99924..351ad0fc 100644 --- a/lib/fko_funcs.c +++ b/lib/fko_funcs.c @@ -458,7 +458,7 @@ fko_spa_data_final(fko_ctx_t ctx, if (res == FKO_SUCCESS && ctx->hmac_type != FKO_HMAC_UNKNOWN && hmac_key != NULL) { - res = fko_calculate_hmac(ctx, hmac_key, hmac_key_len); + res = fko_set_spa_hmac(ctx, hmac_key, hmac_key_len); if (res == FKO_SUCCESS) { diff --git a/lib/fko_hmac.c b/lib/fko_hmac.c index 4069c4ea..aa38561a 100644 --- a/lib/fko_hmac.c +++ b/lib/fko_hmac.c @@ -112,7 +112,7 @@ int fko_verify_hmac(fko_ctx_t ctx, res = fko_set_spa_hmac_type(ctx, ctx->hmac_type); if(res == FKO_SUCCESS) { - res = fko_calculate_hmac(ctx, hmac_key, hmac_key_len); + res = fko_set_spa_hmac(ctx, hmac_key, hmac_key_len); if(res == FKO_SUCCESS) { @@ -131,7 +131,7 @@ int fko_verify_hmac(fko_ctx_t ctx, /* Return the fko HMAC data */ int -fko_get_hmac_data(fko_ctx_t ctx, char **hmac_data) +fko_get_spa_hmac(fko_ctx_t ctx, char **hmac_data) { /* Must be initialized */ @@ -178,7 +178,7 @@ fko_get_spa_hmac_type(fko_ctx_t ctx, short *hmac_type) return(FKO_SUCCESS); } -int fko_calculate_hmac(fko_ctx_t ctx, +int fko_set_spa_hmac(fko_ctx_t ctx, const char * const hmac_key, const int hmac_key_len) { unsigned char hmac[SHA512_DIGEST_STR_LEN] = {0}; diff --git a/perl/FKO/FKO.xs b/perl/FKO/FKO.xs index 7549a6e4..5f60ea8e 100644 --- a/perl/FKO/FKO.xs +++ b/perl/FKO/FKO.xs @@ -393,7 +393,7 @@ _get_spa_hmac(ctx, val) fko_ctx_t ctx; char *val; CODE: - RETVAL = fko_get_hmac_data(ctx, &val); + RETVAL = fko_get_spa_hmac(ctx, &val); OUTPUT: val RETVAL @@ -639,13 +639,13 @@ _verify_hmac(ctx, hmac_key, hmac_key_len) RETVAL int -_calculate_hmac(ctx, hmac_key, hmac_key_len) +_set_spa_hmac(ctx, hmac_key, hmac_key_len) INPUT: fko_ctx_t ctx; char* hmac_key; int hmac_key_len; CODE: - RETVAL = fko_calculate_hmac(ctx, hmac_key, hmac_key_len); + RETVAL = fko_set_spa_hmac(ctx, hmac_key, hmac_key_len); OUTPUT: RETVAL diff --git a/perl/FKO/lib/FKO.pm b/perl/FKO/lib/FKO.pm index 0cddf279..0b516b91 100644 --- a/perl/FKO/lib/FKO.pm +++ b/perl/FKO/lib/FKO.pm @@ -323,7 +323,7 @@ sub spa_hmac { my $val = ''; - return FKO::_calculate_hmac($self->{_ctx}) + return FKO::_set_spa_hmac($self->{_ctx}) if($recompute and $hmac_key and $hmac_key_len); $self->{_err} = FKO::_get_spa_hmac($self->{_ctx}, $val); @@ -518,12 +518,12 @@ sub verify_hmac { return FKO::_verify_hmac($self->{_ctx}, $hmac_key, $hmac_key_len) } -sub calculate_hmac { +sub set_spa_hmac { my $self = shift; my $hmac_key = shift || ''; my $hmac_key_len = shift || 0; - return FKO::_calculate_hmac($self->{_ctx}, $hmac_key, $hmac_key_len) + return FKO::_set_spa_hmac($self->{_ctx}, $hmac_key, $hmac_key_len) } sub DESTROY { diff --git a/python/fko.py b/python/fko.py index 3e6a3f04..be3e95b1 100644 --- a/python/fko.py +++ b/python/fko.py @@ -591,15 +591,15 @@ class Fko: """ _fko.verify_hmac(self.ctx, hmac_key) - def calculate_hmac(self, hmac_key): + def set_spa_hmac(self, hmac_key): """Calculate the HMAC for the given data """ - _fko.calculate_hmac(self.ctx, hmac_key) + _fko.set_spa_hmac(self.ctx, hmac_key) - def get_hmac_data(self): + def get_spa_hmac(self): """Return the HMAC for the data in the current context """ - _fko.get_hmac_data(self.ctx) + _fko.get_spa_hmac(self.ctx) # GPG-related functions. diff --git a/python/fkomodule.c b/python/fkomodule.c index 954b543b..c4087e5c 100644 --- a/python/fkomodule.c +++ b/python/fkomodule.c @@ -76,8 +76,8 @@ static PyObject * key_gen(PyObject *self, PyObject *args); static PyObject * base64_encode(PyObject *self, PyObject *args); static PyObject * base64_decode(PyObject *self, PyObject *args); static PyObject * verify_hmac(PyObject *self, PyObject *args); -static PyObject * calculate_hmac(PyObject *self, PyObject *args); -static PyObject * get_hmac_data(PyObject *self, PyObject *args); +static PyObject * set_spa_hmac(PyObject *self, PyObject *args); +static PyObject * get_spa_hmac(PyObject *self, PyObject *args); /* FKO GPG-related Functions. */ @@ -206,9 +206,9 @@ static PyMethodDef FKOMethods[] = { "Base64 decode function"}, {"verify_hmac", verify_hmac, METH_VARARGS, "Generate HMAC for the data and verify it against the HMAC included with the data"}, - {"calculate_hmac", calculate_hmac, METH_VARARGS, + {"set_spa_hmac", set_spa_hmac, METH_VARARGS, "Calculate the HMAC for the given data"}, - {"get_hmac_data", get_hmac_data, METH_VARARGS, + {"get_spa_hmac", get_spa_hmac, METH_VARARGS, "Return the HMAC for the data in the current context"}, {"get_gpg_recipient", get_gpg_recipient, METH_VARARGS, @@ -1330,7 +1330,7 @@ verify_hmac(PyObject *self, PyObject *args) } static PyObject * -calculate_hmac(PyObject *self, PyObject *args) +set_spa_hmac(PyObject *self, PyObject *args) { fko_ctx_t ctx; char *hmac_key; @@ -1340,7 +1340,7 @@ calculate_hmac(PyObject *self, PyObject *args) if(!PyArg_ParseTuple(args, "ks#", &ctx, &hmac_key, &hmac_key_len)) return NULL; - res = fko_calculate_hmac(ctx, hmac_key, hmac_key_len); + res = fko_set_spa_hmac(ctx, hmac_key, hmac_key_len); if(res != FKO_SUCCESS) { @@ -1352,7 +1352,7 @@ calculate_hmac(PyObject *self, PyObject *args) } static PyObject * -get_hmac_data(PyObject *self, PyObject *args) +get_spa_hmac(PyObject *self, PyObject *args) { fko_ctx_t ctx; char *enc_data; @@ -1361,7 +1361,7 @@ get_hmac_data(PyObject *self, PyObject *args) if(!PyArg_ParseTuple(args, "k", &ctx)) return NULL; - res = fko_get_hmac_data(ctx, &enc_data); + res = fko_get_spa_hmac(ctx, &enc_data); if(res != FKO_SUCCESS) { diff --git a/server/utils.c b/server/utils.c index 9a05d2cf..3a6e2ffd 100644 --- a/server/utils.c +++ b/server/utils.c @@ -115,7 +115,7 @@ dump_ctx(fko_ctx_t ctx) fko_get_spa_encryption_type(ctx, &encryption_type); fko_get_spa_encryption_mode(ctx, &encryption_mode); fko_get_encoded_data(ctx, &enc_data); - fko_get_hmac_data(ctx, &hmac_data); + fko_get_spa_hmac(ctx, &hmac_data); fko_get_spa_digest(ctx, &spa_digest); fko_get_spa_data(ctx, &spa_data); diff --git a/test/fko-python.py b/test/fko-python.py new file mode 100755 index 00000000..096a20ab --- /dev/null +++ b/test/fko-python.py @@ -0,0 +1,37 @@ +#!/usr/bin/python + +# +# Import the Fko class and all constants. +# +from fko import * + +# Create an Fko instance with an empty context. +# +fko = Fko() + +fko.hmac_type(FKO_HMAC_SHA512) + +# Set the SPA message (Note: Access request is default if not specified). +# +fko.spa_message("0.0.0.0,tcp/22") + +# Create the final SPA data message string. +# +fko.spa_data_final("testtest", "blah") + +# print the spa message. +# +print fko.spa_data() + +# Print some of the data: +# +print "Version:", fko.version() +print "Timestamp:", fko.timestamp() +print "Username:", fko.username() +print "Digest Type (value):", fko.digest_type() +print "Digest Type (string):", fko.digest_type_str() +print "Digest:", fko.spa_digest() +print "HMAC Type (value):", fko.hmac_type() +print "HMAC Type (string):", fko.hmac_type_str() +print "HMAC:", fko.get_spa_hmac() +print "SPA Message:", fko.spa_message() diff --git a/test/fko-wrapper/fko_wrapper.c b/test/fko-wrapper/fko_wrapper.c index fe88bffa..2b710152 100644 --- a/test/fko-wrapper/fko_wrapper.c +++ b/test/fko-wrapper/fko_wrapper.c @@ -166,7 +166,7 @@ display_ctx(fko_ctx_t ctx) fko_get_spa_hmac_type(ctx, &hmac_type); fko_get_spa_encryption_mode(ctx, &encryption_mode); fko_get_encoded_data(ctx, &enc_data); - fko_get_hmac_data(ctx, &hmac_data); + fko_get_spa_hmac(ctx, &hmac_data); fko_get_spa_digest(ctx, &spa_digest); fko_get_spa_data(ctx, &spa_data);