This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: crypto: Add secure/insecure_hash functions
Remove usages of hashlib throughout the codebase to make auditing easier. Fixes: #297
- Loading branch information
1 parent
cfadbd0
commit 2174a51
Showing
12 changed files
with
103 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
""" | ||
import abc | ||
import json | ||
import hashlib | ||
import pathlib | ||
from typing import AsyncIterator, Optional | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
All hashing originates in this file for easier auditing. | ||
""" | ||
import hashlib | ||
|
||
|
||
SECURE_HASH_ALGORITHM = hashlib.sha384 | ||
INSECURE_HASH_ALGORITHM = hashlib.md5 | ||
|
||
|
||
def secure_hash(string, algorithm) -> str: | ||
if isinstance(string, str): | ||
string = string.encode("utf-8") | ||
return SECURE_HASH_ALGORITHM(string).hexdigest() | ||
|
||
|
||
def insecure_hash(string) -> str: | ||
if isinstance(string, str): | ||
string = string.encode("utf-8") | ||
return INSECURE_HASH_ALGORITHM(string).hexdigest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
""" | ||
import os | ||
import abc | ||
import hashlib | ||
import inspect | ||
import pathlib | ||
|
||
|
Oops, something went wrong.