ai_v/venv/Lib/site-packages/Cryptodome/Util/Counter.py
公司git 67f2621a69 feat(payment): 集成支付宝支付与订单管理功能
- 在应用中注册支付蓝图(payment_bp)以支持支付接口
- 配置支付宝相关秘钥、回调地址及环境选项
- 新增订单模型(Order),支持订单数据存储与管理
- 管理后台接口添加订单列表查询功能,支持超级管理员访问
- 购买页面与表单修改,支持不同套餐的购买提交
- 支付成功页面提示,显示订单编号及积分到账信息
- 移除买积分按钮禁用逻辑,开放购买功能
2026-01-14 17:00:43 +08:00

80 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
#
# Util/Counter.py : Fast counter for use with CTR-mode ciphers
#
# Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
#
# ===================================================================
# The contents of this file are dedicated to the public domain. To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ===================================================================
def new(nbits, prefix=b"", suffix=b"", initial_value=1, little_endian=False, allow_wraparound=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 1 at each call.
Args:
nbits (integer):
Length of the desired counter value, 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.
Its length in bits must not exceed the argument ``nbits``.
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):
This parameter is ignored.
An ``OverflowError`` exception is always raised when the counter wraps
around to zero.
Returns:
An object that can be passed with the :data:`counter` parameter to a CTR mode
cipher.
It must hold that *len(prefix) + nbits//8 + len(suffix)* matches the
block size of the underlying block cipher.
"""
if (nbits % 8) != 0:
raise ValueError("'nbits' must be a multiple of 8")
iv_bl = initial_value.bit_length()
if iv_bl > nbits:
raise ValueError("Initial value takes %d bits but it is longer than "
"the counter (%d bits)" %
(iv_bl, nbits))
# Ignore wraparound
return {"counter_len": nbits // 8,
"prefix": prefix,
"suffix": suffix,
"initial_value": initial_value,
"little_endian": little_endian
}