{"action":"created","issue":{"url":"https://api.github.com/repos/jedisct1/libsodium/issues/435","repository_url":"https://api.github.com/repos/jedisct1/libsodium","labels_url":"https://api.github.com/repos/jedisct1/libsodium/issues/435/labels{/name}","comments_url":"https://api.github.com/repos/jedisct1/libsodium/issues/435/comments","events_url":"https://api.github.com/repos/jedisct1/libsodium/issues/435/events","html_url":"https://github.com/jedisct1/libsodium/issues/435","id":185063715,"number":435,"title":"clarification on the platform independence of sodium_memcmp","user":{"login":"cjdelisle","id":509047,"avatar_url":"https://avatars.githubusercontent.com/u/509047?v=3","gravatar_id":"","url":"https://api.github.com/users/cjdelisle","html_url":"https://github.com/cjdelisle","followers_url":"https://api.github.com/users/cjdelisle/followers","following_url":"https://api.github.com/users/cjdelisle/following{/other_user}","gists_url":"https://api.github.com/users/cjdelisle/gists{/gist_id}","starred_url":"https://api.github.com/users/cjdelisle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjdelisle/subscriptions","organizations_url":"https://api.github.com/users/cjdelisle/orgs","repos_url":"https://api.github.com/users/cjdelisle/repos","events_url":"https://api.github.com/users/cjdelisle/events{/privacy}","received_events_url":"https://api.github.com/users/cjdelisle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-25T09:25:23Z","updated_at":"2016-10-25T10:07:41Z","closed_at":null,"body":"I have a question on the platform compatibility of sodium_memcmp() as per:\r\nhttps://github.com/jedisct1/libsodium/blob/aff4aaeabf406044e90954593b3d378fc088020a/src/libsodium/sodium/utils.c#L131\r\n\r\nI observe `d` is an `unsigned char` which is guaranteed in C99 to have 8 bits, then I see in the comparison `return (1 & ((d - 1) >> 8)) - 1;` that we shift `d-1` by 8 bits.\r\n\r\nIt appears that the `d-1` computation is being done on a 32 bit ALU and so when it is shifted, \"bit 9\" does exist. However, I am wondering if this could compile on a machine with a true 8 bit ALU wherein (d - 1) becomes 0xff and shifting by 8 reliably produces zero.\r\n\r\nI observe that in djb's constant time comparison, he uses \"int\" which should always be at least 16 bits on any sane machine. https://github.com/cjdelisle/cjdns/blob/master/node_build/dependencies/cnacl/crypto_verify/32/ref/verify.c\r\n\r\nSorry to be the C standard rules-lawyer but I would like some background as to why this decision was taken and how it is defended."},"comment":{"url":"https://api.github.com/repos/jedisct1/libsodium/issues/comments/255993492","html_url":"https://github.com/jedisct1/libsodium/issues/435#issuecomment-255993492","issue_url":"https://api.github.com/repos/jedisct1/libsodium/issues/435","id":255993492,"user":{"login":"jedisct1","id":124872,"avatar_url":"https://avatars.githubusercontent.com/u/124872?v=3","gravatar_id":"","url":"https://api.github.com/users/jedisct1","html_url":"https://github.com/jedisct1","followers_url":"https://api.github.com/users/jedisct1/followers","following_url":"https://api.github.com/users/jedisct1/following{/other_user}","gists_url":"https://api.github.com/users/jedisct1/gists{/gist_id}","starred_url":"https://api.github.com/users/jedisct1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedisct1/subscriptions","organizations_url":"https://api.github.com/users/jedisct1/orgs","repos_url":"https://api.github.com/users/jedisct1/repos","events_url":"https://api.github.com/users/jedisct1/events{/privacy}","received_events_url":"https://api.github.com/users/jedisct1/received_events","type":"User","site_admin":false},"created_at":"2016-10-25T10:07:41Z","updated_at":"2016-10-25T10:07:41Z","body":"The `-` operation on a `char` value promotes it to an `int`."}}
{"actor":{"display_login":"jedisct1"}}