Thursday, December 20, 2018

Digest for comp.lang.c++@googlegroups.com - 13 updates in 2 topics

"Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid>: Dec 20 03:18PM -0800

On 12/20/2018 1:02 PM, Robert Wessel wrote:
 
> While true, in many cryptographic applications it's required that the
> CSPRNG is sufficiently unpredictably seeded. Which just moves the
> issue to the seeding mechanism
 
Agreed. Fwiw, the multi-part secret key, or seed, in my encryption
scheme advises the user to create a large HMAC password derived from a TRNG.
 
http://funwithfractals.atspace.cc/ct_cipher
 
Section 2
_________________________
2. The Secret Key
 
Both properties of my cipher rely on a good cryptographic hash function.
HMAC is an abstract layer on top of a hash algorithm that allows for a
secret key. Let us refer to this HMAC key as SK.hmac_key from now on. We
also need to allow Alice and Bob to choose a hash to use with HMAC. Let
us refer to this as SK.hash_algo. The size of HMAC's digest in bytes is
based on the digest size of SK.hash_algo. For example, SHA-256 has
32-byte digests.
 
Another aspect involves prepending random bytes from a TRNG to the front
of a plaintext. Let us refer to the number of these random bytes as
SK.rand_n. Okay, the secret key SK used by Alice and Bob is comprised of:
_________________________________
SK.hmac_key = Key for HMAC.
SK.hash_algo = The Hash Algorithm.
SK.rand_n = The Number of TRNG bytes.
_________________________________
 
SK.hmac_key must be a cryptographically secure password, e.g. comprised
of 1024 bytes from a TRNG.
 
SK.hash_algo must be a cryptographically secure hash, e.g. SHA-384.
 
SK.rand_n must be equal to, or ideally larger than the digest size of
SK.hash_algo.
_________________________
 
 
If _all_ of those rules are followed, my HMAC cipher should produce
crypto safe streams.
Bart <bc@freeuk.com>: Dec 20 09:58PM

On 20/12/2018 21:21, Keith Thompson wrote:
> correct token sequence.
 
> Macro expansion doesn't paste tokens together unless you tell it to
> using the ## operator.
 
I'm not suggesting that. I was showing how sometimes two consecutive ~
operators can occur in C code, even if no one would ever write them
directly as ~~ or ~ ~.
 
Therefore support for a double ~ operation is still needed, even if any
compiler will turn it into a no-op.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 01:39PM -0500

On 12/20/2018 12:57 PM, James Kuyper wrote:
>> ~~ would be a separate token from ~(~x) as it is today. It would be
>> like + and ++.
 
> What does "as it is today" refer to? "~~" is NOT a separate token today. It parses as two consecutive "~" tokens.
 
I am not aware of that operator as two consecutive ~~ characters. I
did a search for it for C or C++ and didn't find it. Only the single
~ character.
 
What does ~~ do today?
 
And if the syntax it uses today is different than the syntax that I
propose, such that there is no legal use of ~~ in the syntax I pro-
pose today, then why would it matter? It would be parsed as two dif-
ferent uses of the same operator, like << and << for one use to bit
shift, one use to direct / pipe as with cout.
 
--
Rick C. Hodgin
David Brown <david.brown@hesbynett.no>: Dec 20 11:03PM +0100

On 20/12/2018 20:05, Rick C. Hodgin wrote:
 
>> !! is often used, but !! is two ! tokens one after the other.
 
> I've seen that before and I've seen it's been explained here, but I
> still don't know what it does.  I've seen it in Linux source code.
 
!! is two ! tokens after each other. !x turns 0 into 1, and non-zero
into 0. So applying that twice, means !!x turns 0 into 0, and non-zero
into 1. So in usage, !!x means "normalise x as a 0/1 boolean value".
It is not often necessary in C99, where you have proper booleans, and
was more common in C90 code. I've used it a few times myself.
 
 
> I still don't see where ~~ is an operator.  I'd like to see a project
> that uses that functionality.  I find Javascript references to it
> online, but none for C or C++.
 
~~ is not an operator - it is two operators, after each other.
 
The issue here is not that someone might intentionally use ~~ (though it
might turn up due to macros). Nor will you find any code that looks
like "a~~b", as it would be a syntax error (unless "a" is a macro of
some sort).
 
The issue is the way C defines the rules for parsing and lexical
analysis. If you want a set of characters to be treated as a single
token - such as "~~" - then it will /always/ be treated as that token.
That is fine for your new use, for "a~~b". And the old "~" operator
will usually work as before - "x = ~y".
 
However, if someone were to write "x = ~~y;", then in normal C this will
be treated as "x = ~(~y);" because there is no "~~" token. With your
extension, it would now be parsed as "x" "assignment operator"
"shorthand pointer operator" "y". That would be meaningless, but code
that used to be valid C is now invalid.
 
Does this actually matter? Probably not, in this case - you are
unlikely ever to come across C code like "x = ~~y;", even allowing for
odd macros. I don't think it should stop you using this operator. (I
don't like the operator suggestion for other reasons, but that is beside
the point here.)
 
C++ had to deal with this situation when trying to allow ">>" to be the
same as "> >" for closing two template declarations. It was
surprisingly difficult, and broke the way tokenising worked, but it
neatened the language for users.
 
If your CAlive language has a different kind of parsing and tokenising,
then only you can tell if it is a problem or not. In these groups, we
can only tell you how it relates to C and C++.
 
 
> Show me where it's used in SQLite, or Blender or some open source
> software of significance.
 
Almost certainly never, which is why I would say it is only a
theoretical issue and should not stop you. But you ought to understand
the issue so that you can make an informed decision.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 01:48PM -0500

On 12/20/2018 1:39 PM, Rick C. Hodgin wrote:
> pose today, then why would it matter?  It would be parsed as two dif-
> ferent uses of the same operator, like << and << for one use to bit
> shift, one use to direct / pipe as with cout.
 
I don't see it listed:
 
https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
 
And when I do a test using:
 
unsigned int i, j;
j = 5;
i = ~~j;
 
It appears to be doing:
 
i = ~(~j);
 
Which is the same as:
 
i = j;
 
--
Rick C. Hodgin
Bart <bc@freeuk.com>: Dec 20 06:59PM

On 20/12/2018 18:39, Rick C. Hodgin wrote:
> pose today, then why would it matter?  It would be parsed as two dif-
> ferent uses of the same operator, like << and << for one use to bit
> shift, one use to direct / pipe as with cout.
 
!! is often used, but !! is two ! tokens one after the other.
 
You proposal would either mean processing ~~ as one new brand-new token,
or introducing a new binary operator that consists of two ~ tokens.
 
In the first case, that means dismissing the current use of ~~x. Even
though it is very rare (and not useful), it effectively means you are
removing it from the language, or need special rules to still allow it
(eg. requiring white space or parentheses).
 
In the second case, it means you can write "a~ ~b" as well as "a~~b",
which you probably don't want.
 
(BTW here's another case of ambiguity:
 
a ~~ b ~~ c
 
assuming successive ~~ ops are allowed.)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 02:05PM -0500

On 12/20/2018 1:59 PM, Bart wrote:
>> ferent uses of the same operator, like << and << for one use to bit
>> shift, one use to direct / pipe as with cout.
 
> !! is often used, but !! is two ! tokens one after the other.
 
I've seen that before and I've seen it's been explained here, but I
still don't know what it does. I've seen it in Linux source code.
 
> You proposal would either mean processing ~~ as one new brand-new token, or
> introducing a new binary operator that consists of two ~ tokens.
 
I still don't see where ~~ is an operator. I'd like to see a project
that uses that functionality. I find Javascript references to it
online, but none for C or C++.
 
Show me where it's used in SQLite, or Blender or some open source
software of significance.
 
> white space or parentheses).
 
> In the second case, it means you can write "a~   ~b" as well as "a~~b", which
> you probably don't want.
 
The syntax I propose would be exactly:
 
[ptr name][~~][member name]
 
No whitespaces in there, and it would be distinct from other valid
syntaxes that may use ~~ as an operator in C or C++.
 
> (BTW here's another case of ambiguity:
 
>     a ~~ b ~~ c
 
> assuming successive ~~ ops are allowed.)
 
No ambiguity if there is a->i->j->b->k->l->c... it would take a~~b as
the first run, bypassing i and j, and then b~~c as the second run,
bypassing k and l.
 
--
Rick C. Hodgin
Bart <bc@freeuk.com>: Dec 20 07:04PM

On 20/12/2018 18:48, Rick C. Hodgin wrote:
 
>     i = ~(~j);
 
> Which is the same as:
 
>     i = j;
 
You might see it used like this:
 
#define M(x) ~x
~M(5);
 
The result after preprocessing is ~~5. Although it is a no-op, it would
be expected to work as a no-op, using two ~ tokens with no intervening
space.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 02:08PM -0500

On 12/20/2018 2:04 PM, Bart wrote:
>     ~M(5);
 
> The result after preprocessing is ~~5. Although it is a no-op, it would be
> expected to work as a no-op, using two ~ tokens with no intervening space.
 
It would still be a separate and distinct syntax. It would preprocess
out as:
 
~M(5);
~~5;
5;
 
It would not be the same syntax as:
 
ptr~~member;
 
Even though it might use the same ~~ symbol, it's used differently, like
the way << and >> are used in C++ differently than when they're used as
i = j << 2; A completely different meaning from cout << 2;
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 02:10PM -0500

On 12/20/2018 1:48 PM, Rick C. Hodgin wrote:
>> shift, one use to direct / pipe as with cout.
 
> I don't see it listed:
 
> https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
 
I don't find any references to ~~ here either:
 
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
 
I searched for "tilde" and found one reference, and ~ and found 14
references, but none for ~~.
 
I'd like to know what this operator does so I can add support for
it in CAlive.
 
--
Rick C. Hodgin
Bart <bc@freeuk.com>: Dec 20 07:34PM

On 20/12/2018 19:08, Rick C. Hodgin wrote:
 
>     ~M(5);
>     ~~5;
>     5;
 
No, it would preprocess as ~~5 not 5. Try ~~"A"; or ~~3.4; and you will
see that ~~ does make it out of the preprocessor. (Just use -E option on
most compilers.)
 
And at this point, a normal C parser expects to see two successive ~ tokens.
 
I think my example is legitimate, but it is hard to search for. It's not
hard however to imagine a constant macro K defined as an expression that
starts with ~, and for ~K to appear in code. Or even for another
constant L defined as ~K, and for ~L (requiring ~~~) to be used somewhere.
 
 
> Even though it might use the same ~~ symbol, it's used differently, like
> the way << and >> are used in C++ differently than when they're used as
> i = j << 2;  A completely different meaning from cout << 2;
 
But "<<" is always the same single token. It's not like it's a "<" token
followed by another "<" in one context, and a single "<<" in another.
 
This is not a big deal, but in C, you /will/ be messing about with how
"~" is normally treated.
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 02:39PM -0500

On 12/20/2018 2:29 PM, James Kuyper wrote:
>> What does ~~ do today?
> "~~x" does the same thing that "~(~x)" does, an expression you've
> already used, so I assume that you're familiar with it.
 
That's what I thought.
 
> parsing of C or C++, and a clue to that way can be found in the
> preceding paragraph - but I'll let you figure it out, if you care (which
> I doubt).
 
I don't see how the maximal munch rule would have any issue whatsoever
here because absorbing ~~ in one stroke would still require there be
an operator based on its surrounding syntax. If you tried to do "~~;"
it would fail, for example. It's looking for some value there to oper-
ate on after identifying the operator.
 
With "ptr~~member" it would be able to recgonize ~~ as a single thing,
and then identify how it's used there by examining the left and right
to determine what's going on.
 
It doesn't seem to be any conflict whatsoever. It seems like there's
a huge mountain being made out of a non-existent mole hill.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Dec 20 02:48PM -0500

On 12/20/2018 2:34 PM, Bart wrote:
>>      ~~5;
>>      5;
 
> No, it would preprocess as ~~5 not 5.
 
I think in the case of the constant, it would go ahead and perform the
operation on it at compile-time. But, I'll grant you the premise. :-)
 
> followed by another "<" in one context, and a single "<<" in another.
 
> This is not a big deal, but in C, you /will/ be messing about with how "~" is
> normally treated.
 
Of course. It's an add-on. The parser would now need to look for
the context because more than one use of ~~ exists.
 
FWIW, ~~ in CAlive today is a syntax error. :-) It may not be that
way tomorrow ... if I ever figure out exactly what ~~ is supposed to
do, and why it's allowed to exist that way.
 
--
Rick C. Hodgin
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: