Skip to content

Commit

Permalink
Add totp_next for timestep + 1 code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
tilkinsc committed Aug 22, 2024
1 parent ff21a94 commit c86d7ad
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cotp.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ COTPRESULT totp_at(OTPData* data, uint64_t for_time, int64_t offset, char* out_s
}

/*
Generates a OTP key using the totp algorithm with
the current, unsecure time in seconds.
Generates an OTP key using the totp algorithm with
the current timestep.
out_str is the null-terminated output string already allocated
Expand All @@ -291,6 +291,21 @@ COTPRESULT totp_now(OTPData* data, char* out_str)
return otp_generate(data, totp_timecode(data, data->time()), out_str);
}

/*
Generates an OTP key using the totp algorithm with
the current timestep + 1.
out_str is the null-terminated output string already allocated
Returns
1 if otp key was successfully generated
error, 0
*/
COTPRESULT totp_next(OTPData* data, char* out_str)
{
return otp_generate(data, totp_timecode(data, data->time()) + 1, out_str);
}

/*
Compares a key against a generated key for multiple
timeblocks before and after a specific time.
Expand Down Expand Up @@ -355,7 +370,7 @@ uint64_t totp_timecode(OTPData* data, uint64_t for_time)
if (data->interval <= 0)
return OTP_ERROR;

return for_time/data->interval;
return for_time / data->interval;
}


Expand Down

0 comments on commit c86d7ad

Please sign in to comment.