Include support for an add_lock callback to tiny FIPS locking API.
[openssl.git] / fips / utl / fips_lck.c
index 47168af233b3a242d2893692a7d3dc986f915955..7cb10bc0d2170e155f9cb1d3a17268e759cc7f4d 100644 (file)
  * ====================================================================
  */
 
-#define OPENSSL_FIPSEVP
+#define OPENSSL_FIPSAPI
 
 #include <openssl/evp.h>
 #include <openssl/fips.h>
 
 /* FIPS locking callbacks */
 
-void (*fips_lck_cb)(int mode, int type,const char *file,int line) = 0;
+static void (*fips_lck_cb)(int mode, int type,const char *file,int line) = 0;
+static int (*fips_add_cb)(int *pointer, int amount, int type, const char *file,
+            int line);
 
 void FIPS_lock(int mode, int type,const char *file,int line)
        {
@@ -66,8 +68,20 @@ void FIPS_lock(int mode, int type,const char *file,int line)
                fips_lck_cb(mode, type, file, line);
        }
 
-void FIPS_set_locking_callback (void (*func)(int mode, int type,
-                               const char *file,int line))
+void FIPS_set_locking_callbacks(void (*func)(int mode, int type,
+                               const char *file,int line),
+                               int (*add_cb)(int *pointer, int amount,
+                                       int type, const char *file, int line))
        {
        fips_lck_cb = func;
+       fips_add_cb = add_cb;
+       }
+
+int FIPS_add_lock(int *pointer, int amount, int type, const char *file,
+            int line)
+       {
+       if (fips_add_cb)
+               return fips_add_cb(pointer, amount, type, file, line);
+       *pointer += amount;
+       return *pointer;
        }