我正在Go中为SQRL客户端实施EnScrypt.该函数需要运行,直到它使用最少的CPU时间.我的Python代码如下所示:
def enscrypt_time(salt, password, seconds, n=9, r=256):
N = 1 << n
start = time.process_time()
end = start + seconds
data = acc = scrypt.hash(password, salt, N, r, 1, 32)
i = 1
while time.process_time() < end:
data = scrypt.hash(password, data, N, r, 1, 32)
acc = xor_bytes(acc, data)
i += 1
return i, time.process_time() - start, acc
Run Code Online (Sandbox Code Playgroud)
除了process_time函数之外,将其转换为Go非常简单.我不能使用time.Time/ Timer因为那些测量挂钟时间(受到系统上可能运行的其他所有内容的影响).我需要实际使用的CPU时间,理想情况是函数,或者至少需要运行的线程或进程.
什么是Go相当于process_time?
https://docs.python.org/3/library/time.html#time.process_time