projects
/
tfcrypt.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3da9e27
)
tfstream: add separate xor_block function
author
Andrey Rys
<rys@lynxlynx.ru>
Sat, 15 Jan 2022 15:22:11 +0000
(16:22 +0100)
committer
Andrey Rys
<rys@lynxlynx.ru>
Sat, 15 Jan 2022 15:22:11 +0000
(16:22 +0100)
VERSION
patch
|
blob
|
history
tfstream.c
patch
|
blob
|
history
diff --git
a/VERSION
b/VERSION
index b1e7d265fcc1d93320d7446fa1755892417f1f90..a8fa06e1be7da01425d2be19da24595de2fa02c2 100644
(file)
--- a/
VERSION
+++ b/
VERSION
@@
-1
+1
@@
-6
1
+6
2
diff --git
a/tfstream.c
b/tfstream.c
index b64d4d9243b8ae090b6af613f05e9a405267975d..014b5c12f4ee9f7e2f8b49926a80199096c00299 100644
(file)
--- a/
tfstream.c
+++ b/
tfstream.c
@@
-2,21
+2,20
@@
#include "tfdef.h"
#include "tfe.h"
#include "tfdef.h"
#include "tfe.h"
-
void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in
, size_t sz)
+
static inline void xor_block(void *dst, const void *src
, size_t sz)
{
{
- const
TF_UNIT_TYPE *uin = in
;
-
TF_UNIT_TYPE *uout = out
;
-
const TF_BYTE_TYPE *uuin = in
;
- TF_BYTE_TYPE *u
uout = ou
t;
- size_t
n, z, x
;
+ const
size_t *sx = (const size_t *)src
;
+
const TF_BYTE_TYPE *usx = (const TF_BYTE_TYPE *)src
;
+
size_t *dx = (size_t *)dst
;
+ TF_BYTE_TYPE *u
dx = (TF_BYTE_TYPE *)ds
t;
+ size_t
sl = sz
;
- switch (TF_SIZE_UNIT) {
- case 2: n = 1; break;
- case 4: n = 2; break;
- case 8: n = 3; break;
- }
+ for (sl = 0; sl < (sz / sizeof(size_t)); sl++) dx[sl] ^= sx[sl];
+ if (sz - (sl * sizeof(size_t))) for (sl *= sizeof(size_t); sl < sz; sl++) udx[sl] ^= usx[sl];
+}
+void tf_stream_crypt(struct tfe_stream *tfe, void *out, const void *in, size_t sz)
+{
tfe_emit(out, sz, tfe);
tfe_emit(out, sz, tfe);
- for (z = 0; z < (sz >> n); z++) uout[z] ^= uin[z];
- if (sz - (z << n)) for (x = (z << n); x < sz; x++) uuout[x] ^= uuin[x];
+ xor_block(out, in, sz);
}
}