diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-04-04 10:04:34 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-04-11 02:28:23 -0400 |
| commit | 4fec57161a42914fae59f931879678c79470d49b (patch) | |
| tree | 51ae07b71b97996c3788cc3c1aafa8be1eaa3aed /openstack/common/utils.py | |
| parent | c2bcf4bd9420e413bb2be7c4b17e8c7686eeea1e (diff) | |
| download | oslo-4fec57161a42914fae59f931879678c79470d49b.tar.gz oslo-4fec57161a42914fae59f931879678c79470d49b.tar.xz oslo-4fec57161a42914fae59f931879678c79470d49b.zip | |
Move auth_str_equal() to a new authutils module.
This patch moves auth_str_utils() to a new module, authutils, for
helper functions related to authentication.
Change-Id: I83f174486269701deed3500f890832a71ff3e315
Diffstat (limited to 'openstack/common/utils.py')
| -rw-r--r-- | openstack/common/utils.py | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/openstack/common/utils.py b/openstack/common/utils.py index d3d01fa..f9dfe73 100644 --- a/openstack/common/utils.py +++ b/openstack/common/utils.py @@ -158,27 +158,3 @@ def import_object(import_str): return sys.modules[import_str] except ImportError: return import_class(import_str) - - -def auth_str_equal(provided, known): - """Constant-time string comparison. - - :params provided: the first string - :params known: the second string - - :return: True if the strings are equal. - - This function takes two strings and compares them. It is intended to be - used when doing a comparison for authentication purposes to help guard - against timing attacks. When using the function for this purpose, always - provide the user-provided password as the first argument. The time this - function will take is always a factor of the length of this string. - """ - result = 0 - p_len = len(provided) - k_len = len(known) - for i in xrange(p_len): - a = ord(provided[i]) if i < p_len else 0 - b = ord(known[i]) if i < k_len else 0 - result |= a ^ b - return (p_len == k_len) & (result == 0) |
