1pass.c
changeset 56 a573346e6f7b
parent 46 fe4f59680246
equal deleted inserted replaced
55:0aaf56a96d21 56:a573346e6f7b
    16 #include "aes.h"
    16 #include "aes.h"
    17 #include "base64.h"
    17 #include "base64.h"
    18 #include "md5.h"
    18 #include "md5.h"
    19 #include "sha256.h"
    19 #include "sha256.h"
    20 #include "keyhook.h"
    20 #include "keyhook.h"
       
    21 #include "otp.h"
    21 
    22 
    22 #include <gtk/gtk.h>
    23 #include <gtk/gtk.h>
    23 #include <gdk/gdk.h>
    24 #include <gdk/gdk.h>
    24 #include <gdk/gdkx.h>
    25 #include <gdk/gdkx.h>
    25 #include <gdk/gdkkeysyms.h>
    26 #include <gdk/gdkkeysyms.h>
   362     free(dataptr);
   363     free(dataptr);
   363     return 1;
   364     return 1;
   364 } // decryptBase64UsingKey
   365 } // decryptBase64UsingKey
   365 
   366 
   366 
   367 
       
   368 static int decryptTopt(lua_State *L)
       
   369 {
       
   370     const char *base32_secret = luaL_checkstring(L, 1);
       
   371     char otpstr[16];
       
   372     const int rc = totp(base32_secret, otpstr, sizeof (otpstr));
       
   373     return retvalString(L, (rc == -1) ? NULL : otpstr);
       
   374 } // decryptTopt
       
   375 
       
   376 
   367 static void calcSha256(const BYTE *buf, const size_t len, BYTE *hash)
   377 static void calcSha256(const BYTE *buf, const size_t len, BYTE *hash)
   368 {
   378 {
   369     SHA256_CTX sha256;
   379     SHA256_CTX sha256;
   370     sha256_init(&sha256);
   380     sha256_init(&sha256);
   371     sha256_update(&sha256, buf, len);
   381     sha256_update(&sha256, buf, len);
   764     luaL_openlibs(luaState);
   774     luaL_openlibs(luaState);
   765 
   775 
   766     // Set up initial C functions, etc we want to expose to Lua code...
   776     // Set up initial C functions, etc we want to expose to Lua code...
   767     luaSetCFunc(luaState, decryptUsingPBKDF2, "decryptUsingPBKDF2");
   777     luaSetCFunc(luaState, decryptUsingPBKDF2, "decryptUsingPBKDF2");
   768     luaSetCFunc(luaState, decryptBase64UsingKey, "decryptBase64UsingKey");
   778     luaSetCFunc(luaState, decryptBase64UsingKey, "decryptBase64UsingKey");
       
   779     luaSetCFunc(luaState, decryptTopt, "decryptTopt");
   769     luaSetCFunc(luaState, giveControlToGui, "giveControlToGui");
   780     luaSetCFunc(luaState, giveControlToGui, "giveControlToGui");
   770     luaSetCFunc(luaState, runGuiPasswordPrompt, "runGuiPasswordPrompt");
   781     luaSetCFunc(luaState, runGuiPasswordPrompt, "runGuiPasswordPrompt");
   771     luaSetCFunc(luaState, copyToClipboard, "copyToClipboard");
   782     luaSetCFunc(luaState, copyToClipboard, "copyToClipboard");
   772     luaSetCFunc(luaState, setPowermateLED_Lua, "setPowermateLED");
   783     luaSetCFunc(luaState, setPowermateLED_Lua, "setPowermateLED");
   773     luaSetCFunc(luaState, calcSha256_Lua, "calcSha256");
   784     luaSetCFunc(luaState, calcSha256_Lua, "calcSha256");