mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2025-01-03 02:28:53 +00:00
mock: Remove unused code
https://bugzilla.gnome.org/show_bug.cgi?id=761834
This commit is contained in:
parent
847dd055e4
commit
7da8c2b70e
@ -11,8 +11,6 @@
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
# http://www.apache.org/licenses/
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
import math
|
||||
|
||||
def append_PKCS7_padding(s):
|
||||
@ -587,62 +585,6 @@ class AESModeOfOperation(object):
|
||||
return bytes(result)
|
||||
|
||||
|
||||
def encryptData(key, data, mode=AESModeOfOperation.modeOfOperation["CBC"]):
|
||||
"""encrypt `data` using `key`
|
||||
|
||||
`key` should be a string of bytes.
|
||||
|
||||
returned cipher is a string of bytes prepended with the initialization
|
||||
vector.
|
||||
|
||||
"""
|
||||
key = map(ord, key)
|
||||
if mode == AESModeOfOperation.modeOfOperation["CBC"]:
|
||||
data = append_PKCS7_padding(data)
|
||||
keysize = len(key)
|
||||
assert keysize in AES.keySize.values(), 'invalid key size: %s' % keysize
|
||||
# create a new iv using random data
|
||||
iv = [ord(i) for i in os.urandom(16)]
|
||||
moo = AESModeOfOperation()
|
||||
(mode, length, ciph) = moo.encrypt(data, mode, key, keysize, iv)
|
||||
# With padding, the original length does not need to be known. It's a bad
|
||||
# idea to store the original message length.
|
||||
# prepend the iv.
|
||||
return ''.join(map(chr, iv)) + ''.join(map(chr, ciph))
|
||||
|
||||
def decryptData(key, data, mode=AESModeOfOperation.modeOfOperation["CBC"]):
|
||||
"""decrypt `data` using `key`
|
||||
|
||||
`key` should be a string of bytes.
|
||||
|
||||
`data` should have the initialization vector prepended as a string of
|
||||
ordinal values.
|
||||
|
||||
"""
|
||||
|
||||
key = map(ord, key)
|
||||
keysize = len(key)
|
||||
assert keysize in AES.keySize.values(), 'invalid key size: %s' % keysize
|
||||
# iv is first 16 bytes
|
||||
iv = map(ord, data[:16])
|
||||
data = map(ord, data[16:])
|
||||
moo = AESModeOfOperation()
|
||||
decr = moo.decrypt(data, None, mode, key, keysize, iv)
|
||||
if mode == AESModeOfOperation.modeOfOperation["CBC"]:
|
||||
decr = strip_PKCS7_padding(decr)
|
||||
return decr
|
||||
|
||||
def generateRandomKey(keysize):
|
||||
"""Generates a key from random data of length `keysize`.
|
||||
|
||||
The returned key is a string of bytes.
|
||||
|
||||
"""
|
||||
if keysize not in (16, 24, 32):
|
||||
emsg = 'Invalid keysize, %s. Should be one of (16, 24, 32).'
|
||||
raise ValueError(emsg % keysize)
|
||||
return os.urandom(keysize)
|
||||
|
||||
if __name__ == "__main__":
|
||||
moo = AESModeOfOperation()
|
||||
cleartext = "This is a test!"
|
||||
|
@ -18,8 +18,6 @@
|
||||
# system libcryptopp.
|
||||
|
||||
import hashlib, hmac
|
||||
import math
|
||||
from binascii import a2b_hex, b2a_hex
|
||||
|
||||
class HKDF(object):
|
||||
def __init__(self, ikm, L, salt=None, info=None, digestmod = None):
|
||||
@ -50,19 +48,9 @@ class HKDF(object):
|
||||
|
||||
#expand PRK
|
||||
def expand(self):
|
||||
N = math.ceil(float(self.keylen)/self.hashlen)
|
||||
T = b""
|
||||
temp = b""
|
||||
i=0x01
|
||||
'''while len(T)<2*self.keylen :
|
||||
msg = temp
|
||||
msg += self.info
|
||||
msg += b2a_hex(chr(i))
|
||||
h = hmac.new(self.prk, a2b_hex(msg), self.digest_cons)
|
||||
temp = b2a_hex(h.digest())
|
||||
i += 1
|
||||
T += temp
|
||||
'''
|
||||
while len(T)<self.keylen :
|
||||
msg = temp
|
||||
msg += self.info
|
||||
@ -80,5 +68,5 @@ def new(ikm, L, salt=None, info="", digestmod = None):
|
||||
|
||||
def hkdf(ikm, length, salt=None, info=""):
|
||||
hk = HKDF(ikm, length ,salt,info)
|
||||
computedprk = hk.extract()
|
||||
hk.extract()
|
||||
return hk.expand()
|
@ -15,7 +15,6 @@ import getopt
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from mock import aes, dh, hkdf
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user