| 200 | } philox_state; |
| 201 | |
| 202 | static inline uint64_t philox_next(philox_state *state) { |
| 203 | uint64_t out; |
| 204 | int i; |
| 205 | philox4x64_ctr_t ct; |
| 206 | |
| 207 | if (state->buffer_pos < PHILOX_BUFFER_SIZE) { |
| 208 | out = state->buffer[state->buffer_pos]; |
| 209 | state->buffer_pos++; |
| 210 | return out; |
| 211 | } |
| 212 | /* generate 4 new uint64_t */ |
| 213 | state->ctr->v[0]++; |
| 214 | /* Handle carry */ |
| 215 | if (state->ctr->v[0] == 0) { |
| 216 | state->ctr->v[1]++; |
| 217 | if (state->ctr->v[1] == 0) { |
| 218 | state->ctr->v[2]++; |
| 219 | if (state->ctr->v[2] == 0) { |
| 220 | state->ctr->v[3]++; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | ct = philox4x64_R(philox4x64_rounds, *state->ctr, *state->key); |
| 225 | for (i = 0; i < 4; i++) { |
| 226 | state->buffer[i] = ct.v[i]; |
| 227 | } |
| 228 | state->buffer_pos = 1; |
| 229 | return state->buffer[0]; |
| 230 | } |
| 231 | |
| 232 | static inline uint64_t philox_next64(philox_state *state) { |
| 233 | return philox_next(state); |
no test coverage detected