jhjin/OpenAES

Use gettimeofday() instead of ftime()

tuxillo opened this issue · 1 comments

Hi,

Is there any reason why ftime() is used instead of gettimeofday() in oaes_lib.c ?
As far as I know ftime() is deprecated.

Best regards,
Antonio Huete

As ftime() is now deprecated, I have rewritten the function as follows:

static uint32_t oaes_get_seed() {
    struct timespec timer;
    struct tm *gmTimer;
    char *_test = NULL;
    uint32_t _ret = 0;

    clock_gettime(CLOCK_REALTIME, &timer);
    timer.tv_nsec = (long int)((double)timer.tv_nsec / 1.0E+6);

    gmTimer = gmtime(&timer.tv_sec);
    _test = (char *)calloc(sizeof(char), timer.tv_nsec);
    _ret = gmTimer->tm_year + 1900 + gmTimer->tm_mon + 1 + gmTimer->tm_mday;
    _ret += gmTimer->tm_hour + gmTimer->tm_min + gmTimer->tm_sec + timer.tv_nsec;
    _ret += (uint64_t)(_test + timer.tv_nsec) + getpid();

    if (_test) free(_test);

    return _ret;
}

Hope to help someone to get rid of deprecation warning.