mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Create SafeComparisonOfHash.py
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
@Desc :preventing timing attack Against Hash
|
||||||
|
"""
|
||||||
|
import hmac
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
key = "e179017a-62b0-4996-8a38-e91aa9f1"
|
||||||
|
msg = "Test"
|
||||||
|
|
||||||
|
def sign(pre_key, imsg, alg):
|
||||||
|
return hmac.new(pre_key, msg, alg).digest()
|
||||||
|
|
||||||
|
def verify(msg, sig):
|
||||||
|
return hmac.compare_digest(sig, sign(key, msg, hashlib.sha256)) #good
|
||||||
Reference in New Issue
Block a user