From 0109d64e545f5c2d124c2aff4e5691b46fb3ace3 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Sun, 27 Jan 2013 14:03:26 -0500 Subject: [PATCH] added encryption_mode() support to perl FKO module --- perl/FKO/FKO.xs | 21 +++++++++++++++++++++ perl/FKO/lib/FKO.pm | 16 ++++++++++++++++ perl/FKO/lib/FKO_Constants.pl | 23 +++++++++++++++++++++++ test/test-fwknop.pl | 1 + 4 files changed, 61 insertions(+) diff --git a/perl/FKO/FKO.xs b/perl/FKO/FKO.xs index f62ae7dc..aba683be 100644 --- a/perl/FKO/FKO.xs +++ b/perl/FKO/FKO.xs @@ -157,6 +157,27 @@ _get_encryption_type(ctx, val) val RETVAL +int +_set_encryption_mode(ctx, encryption_mode) + INPUT: + fko_ctx_t ctx; + short encryption_mode; + CODE: + RETVAL = fko_set_spa_encryption_mode(ctx, encryption_mode); + OUTPUT: + RETVAL + +int +_get_encryption_mode(ctx, val) + INPUT: + fko_ctx_t ctx; + short val + CODE: + RETVAL = fko_get_spa_encryption_mode(ctx, &val); + OUTPUT: + val + RETVAL + int _set_hmac_mode(ctx, hmac_mode) INPUT: diff --git a/perl/FKO/lib/FKO.pm b/perl/FKO/lib/FKO.pm index f919e528..c941f985 100644 --- a/perl/FKO/lib/FKO.pm +++ b/perl/FKO/lib/FKO.pm @@ -27,6 +27,7 @@ our ( @DIGEST_TYPES, @HMAC_DIGEST_TYPES, @ENCRYPTION_TYPES, + @ENCRYPTION_MODES, @ERROR_CODES ); @@ -39,6 +40,7 @@ our %EXPORT_TAGS = ( 'digest_types' => \@DIGEST_TYPES, 'hmac_digest_types' => \@HMAC_DIGEST_TYPES, 'encryption_types' => \@ENCRYPTION_TYPES, + 'encryption_modes' => \@ENCRYPTION_MODES, 'errors' => \@ERROR_CODES, 'types' => [ @MSG_TYPES, @@ -50,6 +52,7 @@ our %EXPORT_TAGS = ( @MSG_TYPES, @HMAC_DIGEST_TYPES, @ENCRYPTION_TYPES, + @ENCRYPTION_MODES, @ERROR_CODES ] ); @@ -176,6 +179,19 @@ sub encryption_type { return($self->_check_return_val($val)); } +sub encryption_mode { + my $self = shift; + my $val = shift; + + return FKO::_set_encryption_mode($self->{_ctx}, $val) + if(defined($val)); + + $val = -1; + $self->{_err} = FKO::_get_encryption_mode($self->{_ctx}, $val); + + return($self->_check_return_val($val)); +} + sub username { my $self = shift; my $val = shift; diff --git a/perl/FKO/lib/FKO_Constants.pl b/perl/FKO/lib/FKO_Constants.pl index 25e34687..868bc281 100644 --- a/perl/FKO/lib/FKO_Constants.pl +++ b/perl/FKO/lib/FKO_Constants.pl @@ -48,6 +48,19 @@ our @ENCRYPTION_TYPES = qw( FKO_ENCRYPTION_GPG ); +# Encryption modes tag list. +# +our @ENCRYPTION_MODES = qw( + FKO_ENC_MODE_ECB + FKO_ENC_MODE_CBC + FKO_ENC_MODE_CFB + FKO_ENC_MODE_PCBC + FKO_ENC_MODE_OFB + FKO_ENC_MODE_CTR + FKO_ENC_MODE_ASYMMETRIC + FKO_ENC_MODE_CBC_LEGACY_IV +); + # Error codes tag list. # our @ERROR_CODES = qw( @@ -131,6 +144,16 @@ use constant { FKO_ENCRYPTION_RIJNDAEL => 1, FKO_ENCRYPTION_GPG => 2, + # Encryption modes + FKO_ENC_MODE_ECB => 1, + FKO_ENC_MODE_CBC => 2, + FKO_ENC_MODE_CFB => 3, + FKO_ENC_MODE_PCBC => 4, + FKO_ENC_MODE_OFB => 5, + FKO_ENC_MODE_CTR => 6, + FKO_ENC_MODE_ASYMMETRIC => 7, + FKO_ENC_MODE_CBC_LEGACY_IV => 8, + # FKO error codes FKO_SUCCESS => 0, FKO_ERROR_CTX_NOT_INITIALIZED => 1, diff --git a/test/test-fwknop.pl b/test/test-fwknop.pl index 8ae830f7..498a02f7 100755 --- a/test/test-fwknop.pl +++ b/test/test-fwknop.pl @@ -4870,6 +4870,7 @@ sub perl_fko_module_full_fuzzing_packets() { $curr_test_file); return 0; } + $fko_obj->encryption_mode(FKO->FKO_ENC_MODE_CBC_LEGACY_IV); $fko_obj->spa_data($encrypted_spa_pkt); my $status = $fko_obj->decrypt_spa_data($fuzzing_key, length($fuzzing_key));