本文整理匯總了Python中Crypto.Util._counter._newBE方法的典型用法代碼示例。如果您正苦於以下問題:Python _counter._newBE方法的具體用法?Python _counter._newBE怎麽用?Python _counter._newBE使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crypto.Util._counter
的用法示例。
在下文中一共展示了_counter._newBE方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: aes_sng
# 需要導入模塊: from Crypto.Util import _counter [as 別名]
# 或者: from Crypto.Util._counter import _newBE [as 別名]
def aes_sng(key, ivector):
ctr = counter._newBE(b'', b'', ivector, allow_wraparound=False)
return AES.new(key, mode=AES.MODE_CTR, counter=ctr)
示例2: new
# 需要導入模塊: from Crypto.Util import _counter [as 別名]
# 或者: from Crypto.Util._counter import _newBE [as 別名]
def new(nbits, prefix=b(""), suffix=b(""), initial_value=1, overflow=0, little_endian=False, allow_wraparound=False, disable_shortcut=False):
"""Create a stateful counter block function suitable for CTR encryption modes.
Each call to the function returns the next counter block.
Each counter block is made up by three parts::
prefix || counter value || postfix
The counter value is incremented by one at each call.
:Parameters:
nbits : integer
Length of the desired counter, in bits. It must be a multiple of 8.
prefix : byte string
The constant prefix of the counter block. By default, no prefix is
used.
suffix : byte string
The constant postfix of the counter block. By default, no suffix is
used.
initial_value : integer
The initial value of the counter. Default value is 1.
little_endian : boolean
If True, the counter number will be encoded in little endian format.
If False (default), in big endian format.
allow_wraparound : boolean
If True, the function will raise an *OverflowError* exception as soon
as the counter wraps around. If False (default), the counter will
simply restart from zero.
disable_shortcut : boolean
If True, do not make ciphers from `Crypto.Cipher` bypass the Python
layer when invoking the counter block function.
If False (default), bypass the Python layer.
:Returns:
The counter block function.
"""
# Sanity-check the message size
(nbytes, remainder) = divmod(nbits, 8)
if remainder != 0:
# In the future, we might support arbitrary bit lengths, but for now we don't.
raise ValueError("nbits must be a multiple of 8; got %d" % (nbits,))
if nbytes < 1:
raise ValueError("nbits too small")
elif nbytes > 0xffff:
raise ValueError("nbits too large")
initval = _encode(initial_value, nbytes, little_endian)
if little_endian:
return _counter._newLE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)
else:
return _counter._newBE(bstr(prefix), bstr(suffix), initval, allow_wraparound=allow_wraparound, disable_shortcut=disable_shortcut)