HMAC function rename for consistency
Make sure that HMAC function names conform to previously established get_*, set_* naming convention.
This commit is contained in:
+1
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+1
-1
@@ -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)
|
||||
{
|
||||
|
||||
+3
-3
@@ -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};
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
|
||||
+3
-3
@@ -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 {
|
||||
|
||||
+4
-4
@@ -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.
|
||||
|
||||
+8
-8
@@ -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)
|
||||
{
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
Executable
+37
@@ -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()
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user