import lilliput_ae_1 import lilliput_ae_2 N_BYTES = 15 def _checkInputs(key, nonce): valid_key_lengths = (128, 192, 256) if len(key)*8 not in valid_key_lengths: raise ValueError('invalid key size: {} not in {}'.format(len(key)*8, valid_key_lengths)) if len(nonce) != N_BYTES: raise ValueError('nonce must be {}-byte long'.format(N_BYTES)) def mainEnc(plaintext, adata, key, nonce, mode): _checkInputs(key, nonce) A = adata M = plaintext N = nonce if(mode == 1) : return lilliput_ae_1.OCB3Enc(A, M, N, key) if(mode == 2) : return lilliput_ae_2.SCT2Enc(A, M, N, key) def mainDec(ciphertext, tag, adata, key, nonce, mode): _checkInputs(key, nonce) A = adata C = ciphertext N = nonce tag = list(tag) if(mode == 1) : return lilliput_ae_1.OCB3Dec(A, C, N, tag, key) if(mode == 2) : return lilliput_ae_2.SCT2Dec(A, C, N, tag, key)