base-files: move xor() from caldata extraction to functions.sh
[openwrt/staging/rmilecki.git] / package / base-files / files / lib / functions.sh
index 860fc045100f15a0725e47a38f28f9855835291a..81176431d16588aceef3e30e4c8d885368c04635 100755 (executable)
@@ -17,6 +17,22 @@ NO_EXPORT=1
 LOAD_STATE=1
 LIST_SEP=" "
 
+# xor multiple hex values of the same length
+xor() {
+       local val
+       local ret="0x$1"
+       local retlen=${#1}
+
+       shift
+       while [ -n "$1" ]; do
+               val="0x$1"
+               ret=$((ret ^ val))
+               shift
+       done
+
+       printf "%0${retlen}x" "$ret"
+}
+
 append() {
        local var="$1"
        local value="$2"