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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 [0,2^16] distributed random number
71 * @retval On Success, it returns the random value, otherwise -1 for error.
73 uint16_t OCGetRandomTwoByte(void);
76 * Generate a uniformly distributed 8-bit (byte) array random numbers
77 * @param[out] location
78 * memory location to start filling with random bytes
80 * length of array to be filled with random bytes
82 void OCFillRandomMem(uint8_t * location, uint16_t len);
85 * Generate a uniformly distributed number on the defined bounded range
86 * @param[in] firstBound
87 * the first bound of the range
88 * @param[in] secondBound
89 * the second bound of the range
91 uint32_t OCGetRandomRange(uint32_t firstBound, uint32_t secondBound);
94 * Generate a Uniformly Unique Identifier based on RFC4122 and
95 * provide it as a 16 byte byte-array
98 * the 16 byte array to fill with the UUID data
101 * @retval RAND_UUID_OK for success, otherwise an error value
103 OCRandomUuidResult OCGenerateUuid(uint8_t uuid[UUID_SIZE]);
106 * Generate a Uniformly Unique Identifier based on RFC4122 and
107 * provide it as a C style string.
109 * @param[out] uuidString
110 * a 37-byte length string to fill with the string
111 * representation of a new UUID. Size is 32 chars
112 * for the hex data, 4 for '-' characters, and 1
113 * for the NULL terminator
115 * @retval RAND_UUID_OK for success, otherwise an error value
117 OCRandomUuidResult OCGenerateUuidString(char uuidString[UUID_STRING_SIZE]);
120 * Convert a UUID generated by OCGenerateUuid to a C style string
124 * The 16 byte array filled with UUID data by OCGenerateUuid
125 * @param[out] uuidString
126 * a 37 byte length string to fill with the string
127 * representation of the passed UUID.
128 * @retval RAND_UUID_OK for success, otherwise an error value
130 OCRandomUuidResult OCConvertUuidToString(const uint8_t uuid[UUID_SIZE],
131 char uuidString[UUID_STRING_SIZE]);
134 * Convert a C style string to a UUID based on RFC 4122
136 * @param[in] uuidString
137 * a 37 byte length string to fill with the string
138 * representation of the passed UUID.
140 * The 16 byte array filled with UUID data
141 * @retval RAND_UUID_OK for success, otherwise an error value
143 OCRandomUuidResult OCConvertStringToUuid(const char uuidString[UUID_STRING_SIZE],
144 uint8_t uuid[UUID_SIZE]);
150 #endif // OC_RANDOM_H