aboutsummaryrefslogtreecommitdiffstats
path: root/lib/crypto/c_src/math.c
diff options
context:
space:
mode:
authorDoug Hogan <[email protected]>2018-12-20 02:08:56 -0800
committerDoug Hogan <[email protected]>2018-12-20 02:30:55 -0800
commit121efebb92f81ac4136c63de79fa88b2b6cedfa2 (patch)
treea4b70742dd75fe545c21d7e159008fee21096830 /lib/crypto/c_src/math.c
parent492c9ec58cb906c36d11a2664002e616a142ca06 (diff)
downloadotp-121efebb92f81ac4136c63de79fa88b2b6cedfa2.tar.gz
otp-121efebb92f81ac4136c63de79fa88b2b6cedfa2.tar.bz2
otp-121efebb92f81ac4136c63de79fa88b2b6cedfa2.zip
Move xor functionality to a new file
Diffstat (limited to 'lib/crypto/c_src/math.c')
-rw-r--r--lib/crypto/c_src/math.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/crypto/c_src/math.c b/lib/crypto/c_src/math.c
new file mode 100644
index 0000000000..ae0de56720
--- /dev/null
+++ b/lib/crypto/c_src/math.c
@@ -0,0 +1,23 @@
+#include "math.h"
+
+ERL_NIF_TERM do_exor(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{/* (Data1, Data2) */
+ ErlNifBinary d1, d2;
+ unsigned char* ret_ptr;
+ int i;
+ ERL_NIF_TERM ret;
+
+ if (!enif_inspect_iolist_as_binary(env,argv[0], &d1)
+ || !enif_inspect_iolist_as_binary(env,argv[1], &d2)
+ || d1.size != d2.size) {
+ return enif_make_badarg(env);
+ }
+ ret_ptr = enif_make_new_binary(env, d1.size, &ret);
+
+ for (i=0; i<d1.size; i++) {
+ ret_ptr[i] = d1.data[i] ^ d2.data[i];
+ }
+ CONSUME_REDS(env,d1);
+ return ret;
+}
+