| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 1996, David Mazieres <dm@uun.org> | 2 * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| 3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org> | 3 * Copyright (c) 2008, Damien Miller <djm@openbsd.org> |
| 4 * | 4 * |
| 5 * Permission to use, copy, modify, and distribute this software for any | 5 * Permission to use, copy, modify, and distribute this software for any |
| 6 * purpose with or without fee is hereby granted, provided that the above | 6 * purpose with or without fee is hereby granted, provided that the above |
| 7 * copyright notice and this permission notice appear in all copies. | 7 * copyright notice and this permission notice appear in all copies. |
| 8 * | 8 * |
| 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include "config.h" | 18 #include "config.h" |
| 19 #include "wtf/CryptographicallyRandomNumber.h" | 19 #include "wtf/CryptographicallyRandomNumber.h" |
| 20 | 20 |
| 21 namespace WTF { | 21 namespace WTF { |
| 22 | 22 |
| 23 static RandomNumberSource sourceFunction; | 23 static RandomNumberSource sourceFunction; |
| 24 | 24 |
| 25 void setRandomSource(RandomNumberSource source) | 25 void setRandomSource(RandomNumberSource source) { |
| 26 { | 26 sourceFunction = source; |
| 27 sourceFunction = source; | |
| 28 } | 27 } |
| 29 | 28 |
| 30 uint32_t cryptographicallyRandomNumber() | 29 uint32_t cryptographicallyRandomNumber() { |
| 31 { | 30 uint32_t result; |
| 32 uint32_t result; | 31 cryptographicallyRandomValues(&result, sizeof(result)); |
| 33 cryptographicallyRandomValues(&result, sizeof(result)); | 32 return result; |
| 34 return result; | |
| 35 } | 33 } |
| 36 | 34 |
| 37 void cryptographicallyRandomValues(void* buffer, size_t length) | 35 void cryptographicallyRandomValues(void* buffer, size_t length) { |
| 38 { | 36 (*sourceFunction)(reinterpret_cast<unsigned char*>(buffer), length); |
| 39 (*sourceFunction)(reinterpret_cast<unsigned char*>(buffer), length); | |
| 40 } | 37 } |
| 41 | |
| 42 } | 38 } |
| OLD | NEW |