1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32 #if defined(__ANDROID__) || defined(__linux__)
35 // MEGA has 16 input pins whereas Due has only 12 input pins
36 #define ANALOG_IN (10)
39 #define UUID_SIZE (16)
40 // The characters are 36 long, 37 for the null-term
41 #define UUID_STRING_SIZE (37)
46 RAND_UUID_INVALID_PARAM = -1,
47 RAND_UUID_READ_ERROR = -2,
48 RAND_UUID_CONVERT_ERROR = -3
51 * Seed the random number generator. Seeding depends on platform.
52 * Android and Linux uses current time. Arduino uses Analog reading on pin ANALOG_IN
53 * @retval 0 for Success, otherwise some error value
55 int8_t OCSeedRandom();
58 * Generate a uniformly [0,2^32] distributed random number
59 * @retval On Success, it returns the random value.
61 uint32_t OCGetRandom();
64 * Generate a uniformly [0,2^8] distributed random number
65 * @retval On Success, it returns the random value, otherwise -1 for error.
67 uint8_t OCGetRandomByte(void);
70 * Generate a uniformly distributed 8-bit (byte) array random numbers
71 * @param[out] location
72 * memory location to start filling with random bytes
74 * length of array to be filled with random bytes
76 void OCFillRandomMem(uint8_t * location, uint16_t len);
79 * Generate a uniformly distributed number on the defined bounded range
80 * @param[in] firstBound
81 * the first bound of the range
82 * @param[in] secondBound
83 * the second bound of the range
85 uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound);
88 * Generate a Uniformly Unique Identifier based on RFC4122 and
89 * provide it as a 16 byte byte-array
92 * the 16 byte array to fill with the UUID data
95 * @retval RAND_UUID_OK for success, otherwise an error value
97 OCRandomUuidResult OCGenerateUuid(uint8_t uuid[UUID_SIZE]);
100 * Generate a Uniformly Unique Identifier based on RFC4122 and
101 * provide it as a C style string.
103 * @param[out] uuidString
104 * a 37-byte length string to fill with the string
105 * representation of a new UUID. Size is 32 chars
106 * for the hex data, 4 for '-' characters, and 1
107 * for the NULL terminator
109 * @retval RAND_UUID_OK for success, otherwise an error value
111 OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]);
114 * Convert a UUID generated by OCGenerateUuid to a C style string
118 * The 16 byte array filled with UUID data by OCGenerateUuid
119 * @param[out] uuidString
120 * a 37 byte length string to fill with the string
121 * representation of the passed UUID.
122 * @retval RAND_UUID_OK for success, otherwise an error value
124 OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE],
125 char uuidString[UUID_STRING_SIZE]);
131 #endif // OC_RANDOM_H