OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #include <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 #include <limits.h> | 9 #include <limits.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 * of least significant byte depends upon whether we are running on | 26 * of least significant byte depends upon whether we are running on |
27 * a big-endian or little-endian machine. | 27 * a big-endian or little-endian machine. |
28 * | 28 * |
29 * Does this mean the least signicant bytes are the most significant | 29 * Does this mean the least signicant bytes are the most significant |
30 * to us? :-) | 30 * to us? :-) |
31 */ | 31 */ |
32 | 32 |
33 static size_t CopyLowBits(void *dst, size_t dstlen, void *src, size_t srclen) | 33 static size_t CopyLowBits(void *dst, size_t dstlen, void *src, size_t srclen) |
34 { | 34 { |
35 union endianness { | 35 union endianness { |
36 » int32 i; | 36 » PRInt32 i; |
37 char c[4]; | 37 char c[4]; |
38 } u; | 38 } u; |
39 | 39 |
40 if (srclen <= dstlen) { | 40 if (srclen <= dstlen) { |
41 memcpy(dst, src, srclen); | 41 memcpy(dst, src, srclen); |
42 return srclen; | 42 return srclen; |
43 } | 43 } |
44 u.i = 0x01020304; | 44 u.i = 0x01020304; |
45 if (u.c[0] == 0x01) { | 45 if (u.c[0] == 0x01) { |
46 /* big-endian case */ | 46 /* big-endian case */ |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 594 } |
595 #endif /* sinix */ | 595 #endif /* sinix */ |
596 | 596 |
597 | 597 |
598 #ifdef BEOS | 598 #ifdef BEOS |
599 #include <be/kernel/OS.h> | 599 #include <be/kernel/OS.h> |
600 | 600 |
601 static size_t | 601 static size_t |
602 GetHighResClock(void *buf, size_t maxbytes) | 602 GetHighResClock(void *buf, size_t maxbytes) |
603 { | 603 { |
604 bigtime_t bigtime; /* Actually an int64 */ | 604 bigtime_t bigtime; /* Actually a int64 */ |
605 | 605 |
606 bigtime = real_time_clock_usecs(); | 606 bigtime = real_time_clock_usecs(); |
607 return CopyLowBits(buf, maxbytes, &bigtime, sizeof(bigtime)); | 607 return CopyLowBits(buf, maxbytes, &bigtime, sizeof(bigtime)); |
608 } | 608 } |
609 | 609 |
610 static void | 610 static void |
611 GiveSystemInfo(void) | 611 GiveSystemInfo(void) |
612 { | 612 { |
613 system_info *info = NULL; | 613 system_info *info = NULL; |
614 int32 val; | 614 PRInt32 val; |
615 get_system_info(info); | 615 get_system_info(info); |
616 if (info) { | 616 if (info) { |
617 val = info->boot_time; | 617 val = info->boot_time; |
618 RNG_RandomUpdate(&val, sizeof(val)); | 618 RNG_RandomUpdate(&val, sizeof(val)); |
619 val = info->used_pages; | 619 val = info->used_pages; |
620 RNG_RandomUpdate(&val, sizeof(val)); | 620 RNG_RandomUpdate(&val, sizeof(val)); |
621 val = info->used_ports; | 621 val = info->used_ports; |
622 RNG_RandomUpdate(&val, sizeof(val)); | 622 RNG_RandomUpdate(&val, sizeof(val)); |
623 val = info->used_threads; | 623 val = info->used_threads; |
624 RNG_RandomUpdate(&val, sizeof(val)); | 624 RNG_RandomUpdate(&val, sizeof(val)); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 fileBytes += bytes; | 1142 fileBytes += bytes; |
1143 buffer += bytes; | 1143 buffer += bytes; |
1144 } | 1144 } |
1145 fclose(file); | 1145 fclose(file); |
1146 if (fileBytes != maxLen) { | 1146 if (fileBytes != maxLen) { |
1147 PORT_SetError(SEC_ERROR_NEED_RANDOM); /* system RNG failed */ | 1147 PORT_SetError(SEC_ERROR_NEED_RANDOM); /* system RNG failed */ |
1148 fileBytes = 0; | 1148 fileBytes = 0; |
1149 } | 1149 } |
1150 return fileBytes; | 1150 return fileBytes; |
1151 } | 1151 } |
OLD | NEW |