AES/GCM (AES-128-GCM) authentication-tag differs in C# and Ruby -


i'm trying generate authentication-tag in c# generated in ruby (for testing purposes). results different, far can see,the inputs equal.

in ruby 2.0 using openssl 1.0.1c (ubuntu 13.04):

require 'openssl' require 'base64' iv = base64.decode64('kewio77t7qwdytribumrxa==') key = base64.decode64('fnuoizvbuzc1q/rn5wmi7q==') aad = base64.decode64('/ttp07spkox8gah60eh89w==') cipher = openssl::cipher.new('aes-128-gcm').encrypt cipher.iv = iv cipher.key = key cipher.auth_data = aad cipher.final tag = base64.strict_encode64(cipher.auth_tag) 

the resulting (encoded) tag ie74xtwtslnad0bkdrhvmq==

in c# using bouncycastle (snippet):

var iv = convert.frombase64string("kewio77t7qwdytribumrxa=="); var key = convert.frombase64string("fnuoizvbuzc1q/rn5wmi7q=="); var aad = convert.frombase64string("/ttp07spkox8gah60eh89w=="); var cipher = new gcmblockcipher(new aesfastengine()); var parameters = new aeadparameters(new keyparameter(passkey), 128, iv, aad); cipher.init(true, parameters); var ciphertext = new byte[cipher.getoutputsize(0)]; cipher.dofinal(ciphertext, 0); var tag = convert.tobase64string(cipher.getmac()); 

the resulting tag in c# sawccwm1t8sgl5y6vt0cha==

what doing wrong here? in advance response!

okay, installed ruby 2.0.0 , did tests.

first of all, replicate original output "ie74xtwtslnad0bkdrhvmq==" in c#, set iv in c# "new byte[12]".

the reason works, in ruby code setting cipher.key clears whatever iv set, effective iv default all-zeroes of default length (96 bits gcm). should set iv after key.

if change ruby code that, output changes "d1taj6js94tsupnbds0ejw=="; still not match. reproduce value in c#, truncate iv 12 bytes, i.e. "kewio77t7qwdytri", , output matches.

from infer openssl/evp truncating iv give it. shouldn't strictly necessary, gcm support longer ivs, 96 bits in sense "preferred" length; i'm not sure policy being enforced here.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -