lkml.org 
[lkml]   [2012]   [Jan]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch 2/4] [RFC] syscalls, x86: Add __NR_kcmp syscall v4
On 01/23/2012 06:20 AM, Cyrill Gorcunov wrote:
> +
> +static unsigned long cookies[KCMP_TYPES][2] __read_mostly;
> +
> +static long kptr_obfuscate(long v, int type)
> +{
> + return (v + cookies[type][0]) ^ cookies[type][1];
> +}
> +

Arf... when I said to use xor I meant instead of the add, not instead of
the multiply, so:

return (v ^ cookies[type][0]) * cookies[type][1];

Otherwise you have absolutely no source of diffusion at all (symmetric
cryptography is about combinations of diffusion -- spreading the content
-- and confusion -- scrambling individual bits of content.)

+ for (i = 0; i < KCMP_TYPES; i++) {
+ for (j = 0; j < 2; j++) {
+ get_random_bytes(&cookies[i][j],
+ sizeof(cookies[i][j]));
+ cookies[i][j] |= (~(~0UL >> 1) | 1);
+ }
+ }
Only cookies[1] -- being used as a multiplicative constant -- needs the OR.

-hpa

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.



\
 
 \ /
  Last update: 2012-01-23 19:53    [from the cache]
©2003-2011 Jasper Spaans