aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--include/string.h14
-rw-r--r--src/string/memfrob.c39
3 files changed, 52 insertions, 2 deletions
diff --git a/TODO b/TODO
index f10d3ed..4f893ff 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
functions to lock and unlock pages (3.4.3 p76)
character class determination for wide characters (4.3 p82)
collation functions (5.6 p109)
-trivial encryption (5.10 p124)
encode binary data (5.11 p125)
argz and envz vectors (5.12 p127)
characer-set handling (6 p133)
diff --git a/include/string.h b/include/string.h
index 68a0134..c43b41d 100644
--- a/include/string.h
+++ b/include/string.h
@@ -1100,7 +1100,19 @@ char* __gnu_basename(const char*)
* @param anagram An anagram of the output, will be modified.
* @retrun The string, which will `== anagram`.
*/
-char* strfry(char* anagram);
+char* strfry(char*);
+
+/**
+ * Performs an inplace bitwise XOR:ing of
+ * a memory segment. The pattern is 00101010.
+ *
+ * This is a GNU extension.
+ *
+ * @param segment The memory segment.
+ * @param size The size of the memory segment.
+ * @return `segment` is returned
+ */
+char* memfrob(char*, size_t);
#endif
diff --git a/src/string/memfrob.c b/src/string/memfrob.c
new file mode 100644
index 0000000..e43496a
--- /dev/null
+++ b/src/string/memfrob.c
@@ -0,0 +1,39 @@
+/**
+ * slibc — Yet another C library
+ * Copyright © 2015 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <string.h>
+#include <stddef.h>
+
+
+
+/**
+ * Performs an inplace bitwise XOR:ing of
+ * a memory segment. The pattern is 00101010.
+ *
+ * This is a GNU extension.
+ *
+ * @param segment The memory segment.
+ * @param size The size of the memory segment.
+ * @return `segment` is returned
+ */
+char* memfrob(char* segment, size_t size)
+{
+ while (--size)
+ segment[size] ^= 0x2A;
+ return segment;
+}
+