Slashdot Mirror


Security Review Summary of NIST SHA-3 Round 1

FormOfActionBanana writes "The security firm Fortify Software has undertaken an automated code review of the NIST SHA-3 round 1 contestants (previously Slashdotted) reference implementations. After a followup audit, the team is now reporting summary results. According to the blog entry, 'This just emphasizes what we already knew about C, even the most careful, security conscious developer messes up memory management.' Of particular interest, Professor Ron Rivest's (the "R" in RSA) MD6 team has already corrected a buffer overflow pointed out by the Fortify review. Bruce Schneier's Skein, also previously Slashdotted, came through defect-free."

97 of 146 comments (clear)

  1. ANSI C by chill · · Score: 4, Insightful

    That is what they get for mandating the code be in ANSI C. How about allowing reference implementation in SPARK, ADA or something else using design-by-contract. After all, isn't something as critical as a international standard for a hash function the type of software d-b-c was meant for?

    --
    Learning HOW to think is more important than learning WHAT to think.
    1. Re:ANSI C by RichardJenkins · · Score: 3, Interesting

      Why do they even have a reference implementation for a hash function in a programming language? Wouldn't just defining the function mathematically be less error prone and just as effective?

    2. Re:ANSI C by Anonymous Coward · · Score: 1, Informative

      1. Because we, rank and file developers, have to use it afterward (and some of us write in C or C-derived languages, like oh, I don't know, pretty much all applications on your desktop?)

      2. Because it is impossible to compare performance of cryptographic algorithms if they are not written in a same language (preferably directly convertable to machine code)

    3. Re:ANSI C by Anonymous Coward · · Score: 1, Insightful

      Ummmm... because it wouldn't be a reference implementation if it wasn't actually implemented?

    4. Re:ANSI C by John+Hasler · · Score: 4, Insightful

      Presumably one of the things they want to evaluate is performance.

      --
      Warning: this article may contain humor, sarcasm, parody, and perhaps even irony. Read at your own risk.
    5. Re:ANSI C by IversenX · · Score: 4, Insightful

      Because you can't compile a mathematical definition.

      If we imagine that the hash function came only as a mathematical definition, how would your test your new implementation in LangOfTheWeek is correct?

      Well, you have 2 options. One, you can prove that your program behaves, in every important way, the same as the definition. This is long, tedious work, and most programmers don't even have the necessary skills for this. Two, you can make a reference implemention in some other language, and compare the outputs.

      Now, given, say, 100 programmers each working on their own functions, we should have 1 resulting behaviour. This will mean that everybody implemented the algorithm 100% correctly. However, the actual number will be between 1 and 100, depending on the skills of the programmers, and the care they've taken in implementing the functions.

      Now, what's the result here? (no pun intended). It's likely to be chaos.

      That's why it's very convenient to have a single reference source.

      --
      With great numbers come great responsibility!
    6. Re:ANSI C by Anonymous Coward · · Score: 5, Insightful

      What did they get? You realize this is just an ad for Fortify, right? Out of 42 projects, they found 5 with memory management issues using their tool. Maybe instead of switching to SPARK, the 5 teams that fucked up could ask the 37 that didn't for some tips on how to write correct C.

    7. Re:ANSI C by xquark · · Score: 2, Informative

      Mathematically anything is feasible, however if you place a real-world constraint such as it requiring an implementation then that greatly narrows the field down.

      Furthermore one of the judging factors is the speed and portability of the algorithm upon a wide variety of commonly used platforms - it doesn't make sense to come up with a super-cool hash function that only works well on say an x86.

      The short of it is that people make mistakes from time to time, and it is true that perfection is an important factor in crypto-code so the submitters should have been more thorough, From the article it seems that the overwhelming majority of them were - which is a positive.

      --
      Arash Partow's Philosophy: Be a person who knows what they don't know, and not a person who doesn't know.
    8. Re:ANSI C by thue · · Score: 2, Insightful

      An implementation in a programming language is the a way to define a function mathematically.

      That is what a programming language is - a way to precisely define an algorithm.

      But C is a low-level language, and therefore maybe a bad choice for function definitions. Instead, in my experience, implementing an algorithm in a high-level functional language like Haskell will often result in a beautiful and readable mathematical function definition.

    9. Re:ANSI C by OrangeTide · · Score: 4, Insightful

      That is what they get for mandating the code be in ANSI C.

      Because most of the systems out there use C for the performance sensitive bits. (and when asm optimization is done, people generally use a C implementation as a reference since C and asm are similar in many ways).

      When they start doing Linux and Windows and other popular systems primarily in Ada you can start going WTF over people posting ANSI C code. Until Java, Ruby and Python aren't dependent on C/C++ implementations for their functionality we'll just have to suffer with C.

      --
      “Common sense is not so common.” — Voltaire
    10. Re:ANSI C by FormOfActionBanana · · Score: 1

      Oh, interesting. VALGRIND looks like dynamic analysis. The results in the article are from static analysis. Each is really useful, but they tend to find different sorts of problems.

      If you'd like to download the five problematic submissions and run VALGRIND against them, please email me the results. I'd be interested to see what is actually detected.

      --
      Take off every 'sig' !!
    11. Re:ANSI C by nedlohs · · Score: 1

      Because you want vendors to just use the reference code, without screwing it up by implementing their own C version from the ADA reference code.

    12. Re:ANSI C by xOneca · · Score: 1

      No, because one of those programmers it's me! ;)

    13. Re:ANSI C by Anonymous Coward · · Score: 3, Insightful

      That is what they get for mandating the code be in ANSI C. How about allowing reference implementation in SPARK, ADA or something else using design-by-contract. After all, isn't something as critical as a international standard for a hash function the type of software d-b-c was meant for?

      C is the lowest common denominator. Once you have a library in C that's compiled to native code, you can link just about any other language to that library: Perl, Python, Ruby, Java, Lisp, etc., all have foreign function interfaces to C.

      C also can compile to just about any processor out there: x86, SPARC, POWER, ARM, etc. Over the decades it's become very portable and optimized.

      C is also know by a large subset of the programmers out there, so if people want to re-write the algorithm in another language, they can start with the C code directly, or with the formal specification and then use the C as a comparative reference.

    14. Re:ANSI C by ion.simon.c · · Score: 1

      If you'd like to download the five problematic submissions and run VALGRIND against them, please email me the results. I'd be interested to see what is actually detected.

      *seconds the request*
      $MY_SLASHDOT_USERNAME at gmail

    15. Re:ANSI C by DamnStupidElf · · Score: 1

      What if they need one of those pesky algorithms for that?

      Look up bootstrapping. Most modern compilers can compile themselves using a stage or two of simpler compilers, built with either an existing compiler, an assembler, or maybe some hand written machine code. All the important parts of the compiler (parser, optimizer, etc.) can be written in the same language that the compiler can compile.

    16. Re:ANSI C by swillden · · Score: 3, Insightful

      After all, isn't something as critical as a international standard for a hash function the type of software d-b-c was meant for?

      No.

      The key desirable characteristics of a good secure hash function are (in this order):

      1. Security (collision resistance, uniformity)
      2. Performance
      3. Ease of implementation

      If the NIST AES contest is any example, what we'll find is that nearly all of the functions will be secure. That's not surprising since all of the creators are serious cryptographers well-versed in the known methods of attacking hash functions, so unless a new attack comes out during the contest, all of the functions will be resistant to all known attack methods.

      With security out of the way, the most important criterion that will be used to choose the winner is performance. This means that every team putting forth a candidate will want to make it as fast as possible, but it still has to run on a few different kinds of machines. The closer you get to the machine, the faster you can make your code -- and this kind of code consists of lots of tight loops where every cycle counts. But assembler isn't an option because it needs to run on different machines.

      That leaves C as the best choice. It's the portable assembler.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    17. Re:ANSI C by Hurricane78 · · Score: 1

      Nooo... Itsa mee... MAARIOOO!!

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    18. Re:ANSI C by caramelcarrot · · Score: 1

      Write it in ML.

    19. Re:ANSI C by setagllib · · Score: 2, Insightful

      C is a bad choice for mathematical function definitions, but it's a fantastic choice for integrating into virtually any stage of a software project. It can be used in an OS kernel, a standard portable crypto library (e.g. OpenSSL), embedded firmware, what have you. All of this with NO more library dependencies than the bare minimum memory management, and most crypto/hash functions don't need those because their state fits in a fixed-size structure. So you can have the mythical 100% standalone C code that fits in any context.

      Implementing the algorithm in C from the start also makes it easy to port to C-like languages like Java and C#.

      --
      Sam ty sig.
    20. Re:ANSI C by setagllib · · Score: 2, Interesting

      I hate to have to repeat it for the thousandth time, but Java's so-called virtualization comes crashing right down if you have even a single threading bug. Let me explain how it works.

      Java gets compiled to machine code at runtime. Unlike machine code made from C code, the machine code really does have some nice protections from address and type confusion, with a generally acceptable performance penalty.

      However it does NOT have ANY protections from threaded race conditions, so if you make any mistake in this, all bets are off as the results are completely undefined. It could be as simple as a missed increment, or it could cause an internal JVM data structure to be corrupted, either in the Java or C++ components.

      At least with C you see and control all of the code that gets run at runtime, all with debug symbols right down to the system calls, and can largely detect and sometimes even trace problems, but with the monstrously large JVM running under your code, you'd be lucky to get a meaningful stack trace.

      The same applies right back to security. Threading bugs are generally much more difficult to diagnose and solve than memory management bugs, so if a developer gets memory wrong, they'll get threading wrong too. In a kernel it's worst of all. A Java kernel does little to solve this, and in fact would include a lot of JVM code which must also be debugged.

      --
      Sam ty sig.
    21. Re:ANSI C by OrangeTide · · Score: 1

      memory leaks are not a security issue. You're thinking of buffer overflows.

      Why Java and not Haskell, Erlang, or Lisp? which also have these features and then some?

      I would take DbC as an important language feature over some "ultra secure" memory idea that seems to have little real world value.

      --
      “Common sense is not so common.” — Voltaire
    22. Re:ANSI C by master_p · · Score: 1

      Could not it be done with Haskell? Haskell creates code equal to C especially for math problems (or so they say).

    23. Re:ANSI C by TheTurtlesMoves · · Score: 1

      Indeed. This is usually what defines the winner over the loser. A secure (we hope) hash that is faster/cheaper in cpu cycles will get used more.

      --
      The Grey Goo disaster happened 3 billion years ago. This rock is covered in self replicating machines!
    24. Re:ANSI C by profplump · · Score: 1

      Call me when your real-world JVM isn't written in C. Until then you're just shifting the burden of resource management to someone else, and you could do that just as easily with C libraries as you could with Java libraries.

    25. Re:ANSI C by sqlrob · · Score: 1

      memory leaks are not a security issue.

      Yes, they are. What happens to the program when it leaks all of the available memory space?

    26. Re:ANSI C by swillden · · Score: 2, Interesting

      With security out of the way, the most important criterion that will be used to choose the winner is performance.

      Probably no one will ever see this self-reply, but I just noticed that the Skein site makes a good argument that the paring down of the candidate list should (will?) happen in the other order.

      The idea is that since it's a huge amount of work to cryptanalyze a hash function, and since it's easy to measure performance (in time and space), the thing to do is to first toss out all of the slow and/or memory-hungry candidates. Obviously, if all of the fast and tight candidates were found to have security flaws, then the field would have to be widened to again include some of the slower candidates.

      In all probability, though, the fast candidates will provide good security, so there's no need to even bother looking at the slow ones.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    27. Re:ANSI C by OrangeTide · · Score: 1

      Yes, they are. What happens to the program when it leaks all of the available memory space?

      Do you count denial of service a "security issue"? if the answer is Yes then I will concede your point.

      --
      “Common sense is not so common.” — Voltaire
    28. Re:ANSI C by setagllib · · Score: 1

      "Just Works"? How much Java have you actually used? For the space of SEVERAL MONTHS, the official "production-quality" Sun JVM had 64-bit JIT bugs that made it crash very often on very popular projects like Eclipse. They and their users had to wait for months for the JVM to be fixed upstream, and for those fixes to trickle down into their managed environments, which often takes another few months of testing. Don't talk to me about "Just Works", Java is software just like any other, and far from the highest quality.

      --
      Sam ty sig.
  2. Re:SHA-3 Is Cracked. by Anonymous Coward · · Score: 1, Funny

    If you step into my heap one more time with your fucking malloc, I'm going to derefernce your null pointer bitch!

    -Christian Bale

  3. The reason is in the summary... by pathological+liar · · Score: 5, Insightful

    ... because implementation is where people screw up.

    1. Re:The reason is in the summary... by ORBAT · · Score: 1

      Because you can't screw up an implementation of an algorithm when you're using functional languages? Man, I must be doing something wrong, then.

  4. Re:SHA-3 Is Cracked. by gavron · · Score: 1, Troll

    Your null pointer bitch derefernced[sic] herself and crashed, or I'll take out your fucking lights. How would you like that?

  5. Reference implementation by rgmoore · · Score: 4, Informative

    In a word, no. A reference implementation is supposed to be a working version of the code, not just a mathematical description. With a working version, it's possible to do things like test its real world performance or cut and paste directly into a program that needs to use the function. That's obviously only possible if you have a version that works on real-world processors.

    Consider Skein as an example. One of the things that Bruce Schneier described as a major goal of its design is that it uses functions that are highly optimized in real-world processors. That means that it's possible to make a version that's both very fast and straightforward to program, an important criterion for low-powered embedded applications. You won't discover that kind of detail until you implement it.

    --

    There's no point in questioning authority if you aren't going to listen to the answers.

    1. Re:Reference implementation by certain+death · · Score: 1

      We all know why Bruce's code came out clean...he is actually the Messiah!!! Or at least in the circles I run in he is! :o) Queue the Chuck Norris jokes with Bruce in stead of Chuck.

      --
      "My immediate reaction is "WTF? What kind of moron doesn't make things 64-bit safe to begin with?" Linus
  6. Re:this is why... by sakdoctor · · Score: 1

    I just read that as unmangled code.

    I'm really behind on the latest programming paradigms.

  7. Disclaimer by FormOfActionBanana · · Score: 2, Interesting

    I should add that I work for Fortify and that I initiated the SHA-3 review in my spare time as a private project. The Slashdot article on December 21 caught my interest.

    --
    Take off every 'sig' !!
    1. Re:Disclaimer by Compholio · · Score: 1
      I think that since only 5 of the 42 projects garnered your attention that a better quote to include in the summary would have been:

      We were impressed with the overall quality of the code, but we did find significant issues in a few projects, including buffer overflows in two of the projects.

      If the other 37 projects didn't have any signficant flaws on the first round of this contest then that doesn't say to me "well, obviously no-one can do memory management properly" - it says that people make mistakes.

    2. Re:Disclaimer by Rayban · · Score: 1

      So which of the vulnerabilities did you hold back on so that you can exploit it in a couple of years? ;)

      --
      æeee!
    3. Re:Disclaimer by FormOfActionBanana · · Score: 3, Interesting

      Yeah, both very good points.

      People do make mistakes. Even geniuses, when they're trying really hard to be careful. Personally, I see recognizing that as a validation for code review (including the automated code review that I do).

      I want the winning entry for this competition to be flawless to the extent that's feasible. Right now, my job includes finding SHA-1 for cryptographic key generation, and telling people to replace that with something better. I don't want to be pulling out SHA-3 in a couple years, too.

      --
      Take off every 'sig' !!
    4. Re:Disclaimer by jd · · Score: 1

      I think that was the article I submitted, expressly with the intent that it would catch the attention of people like yourself who could contribute to the auditing. This improves the quality of the submissions, perhaps identifies flaws in algorithms, and in general leads to a better contest between better competing implementations.

      Personally, I'm gloating a little because the functions I considered to have such cool names (eg: Blue Midnight Wish) all came through clean and are also listed on the SHA3 Zoo as clean - for now. On the other hand, the ones listed on one or both sites as flawed have boring names.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    5. Re:Disclaimer by FormOfActionBanana · · Score: 1

      Yes, it was yours. Thank you very much for the inspiration. I'm glad to help in what little way I can.

      I'm really in awe of the people (whoever they are) who are actually evaluating the algorithms themselves.

      --
      Take off every 'sig' !!
    6. Re:Disclaimer by FormOfActionBanana · · Score: 1

      ...the people (whoever they are) who are actually evaluating the algorithms themselves.

      I figured out who they are.

      --
      Take off every 'sig' !!
  8. Who's this Bruce Shneieier guy? by Anonymous Coward · · Score: 5, Funny

    "... because implementation is where people screw up."
    "Bruce Schneier's Skein, ... came through defect-free."

    So by deductive logic, Bruce is a robot. Also previously slashdotted.

    1. Re:Who's this Bruce Shneieier guy? by jd · · Score: 1

      No, all it proves is that he's not a person. This leaves all advanced alien lifeforms, artificial intelligences and supernatural phenomena as possibilities.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    2. Re:Who's this Bruce Shneieier guy? by shish · · Score: 1

      Bruce is a robot

      And that's not all...

      --
      I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
  9. Re:this is why... by SoapBox17 · · Score: 2, Funny

    Yes, I can't wait for managed Linux to come out. That sounds like a great idea....

  10. Hardly "memory management" by SoapBox17 · · Score: 3, Insightful
    From TFA (and TFS):

    This just emphasizes what we already knew about C, even the most careful, security conscious developer messes up memory management.

    This doesn't follow from TFA. The blog points out two instances of buffer overflows. The first one you could argue they messed up "memory management" because they used the wrong bounds for their array in several places... but they don't sound very "careful" or "security conscious" since checking to make sure you understand the bounds of the array you're using is pretty basic.

    But that's not what bothered me. The second example is a typo where TFA says someone entered a "3" instead of a "2". In what dimension is mis-typing something "messing up memory management"? That just doesn't follow.

    1. Re:Hardly "memory management" by drinkypoo · · Score: 1

      In what dimension is mis-typing something "messing up memory management"? That just doesn't follow.

      I haven't evaluated the code in question, because math scares me, but if someone makes a fencepost error (or just a typo - but fenceposting is a common cause of off-by-one errors) it's entirely possible to be mucking with memory that is a byte or a page off from the memory you think you're working on. So that's an example of how mis-typing something could cause an error in memory management (if in one function you have it right, and in another you have it wrong... you can't even get it right by getting lucky. although getting it right by getting lucky is the kind of thing that causes strange transient failures in other parts of the program way down the road somewhere.)

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    2. Re:Hardly "memory management" by FormOfActionBanana · · Score: 1

      drinkypoo the math is as easy as 3 >= 3. See here:

      // deal with the length update first
                      bcount = ss.sourceDataLength; // previous length
                      ss.sourceDataLength = bcount + databitlen; // new length
                      if (ss.sourceDataLength < (bcount | databitlen)) // overflow
                                      if (++ss.sourceDataLength2[0] == 0) // increment higher order count
                                                      if (++ss.sourceDataLength2[1] == 0) // and the next higher order
                                                                      ++ss.sourceDataLength2[3]; // and the next one, etc.

      And the problem (in Blender.c:1808) is because of here, in the array's declaration:


                      DataLength sourceDataLength2[3]; // high order parts of data length // note: the array size determines the maximum length supported

      In C, the array blah[3] has three elements: blah[0], blah[1] and blah[2]. Accessing blah[3] is just random memory and might actually be in use for something else.

      --
      Take off every 'sig' !!
    3. Re:Hardly "memory management" by FormOfActionBanana · · Score: 1

      One reply deep in comment 26951319 I demonstrate that typing the "3" instead of "2" improperly access memory space that may or may not be allocated. This type of out-of-bounds access is mismanaging memory.

      --
      Take off every 'sig' !!
  11. Re:this is why... by Cyberax · · Score: 2, Interesting
  12. In defense of C by phantomfive · · Score: 4, Insightful

    The summary is kind of a troll, since most of the submissions actually managed to get through without ANY buffer overflows.

    Buffer overflows are not hard to avoid, they are just something that must be tested. If you don't test, you are going to make a mistake, but they are easy to find with a careful test plan or an automated tool. Apparently those authors who had buffer overflows in their code didn't really check for them.

    C is just a tool, like any other, and it has tradeoffs. The fact that you are going to have to check for buffer overflows is just something you have to add to the final estimate of how long your project will take. But C gives you other advantages that make up for it. Best tool for the job, etc.

    --
    Qxe4
    1. Re:In defense of C by Kjella · · Score: 3, Insightful

      Buffer overflows are not hard to avoid, they are just something that must be tested.

      No, they're a huge pain in the ass 99% of the time, what's worst is that pointers work even when they absolutely shouldn't. I recently worked with some code that instead of making a copy of the data just kept a void pointer to it instead. Since that code was passed just a temporary variable that was gone right after being passed into it, it should error out on any sane system, but the problem is it worked - when it was called later, using the pointer to a temp that's alreday gone it would just read the value out of unallocated memory anyway, and since the temp hadn't been overwritten it worked! Only reason it came up was that when called twice it'd show the last data twice, since both would be pointing to the same unallocated memory location. It's so WTF that you can't believe it. Personally I prefer to work with some sort of system (Java, C#, C++/Qt, anything) that'll give you some head's up that will tell you're out of bounds or otherwise just pointing at nothing.

      --
      Live today, because you never know what tomorrow brings
    2. Re:In defense of C by owlstead · · Score: 1

      I don't think the performance estimate will change much. You only have to check the input, and the complexity is within the rounds of the underlying block cipher/sponge function or whatever is used to get the bits distributed as they should be.

      I blame the bugs on tight time schedules and inexperienced programmers/insufficient review. Basically, cryptographers are mathematicians at heart. There is a rather large likelyhood that C implementations are not their common playing field.

    3. Re:In defense of C by drspliff · · Score: 2, Informative

      Which is why tools like Valgrind or Numega BoundsChecker exist, they provide much more granular information about how memory's being used and abused, the problem you just described would flag up instantly as writing to previously free'd data along with a few source code locations relevant to where it was allocated/free'd.

  13. PS: by Anonymous Coward · · Score: 1, Funny

    The alternative was supposed to be throwing money at Fortify by the way. If your conclusion is to switch to SPARK then Fortify needs to work on their PR, *cough*, I mean blogging.

  14. probably wouldn't be bad for a lot of applications by Trepidity · · Score: 1

    At the very least, using a C-like language with safety, like Cyclone, would be a reasonable performance/safety tradeoff for a lot of users compared to the current tradeoffs (which leave quite a bit to be desired). I'm guessing the main stumbling block would be reimplementation overhead (Linux already exists in C, has a lot of code, and is a fairly quickly moving target) and lack of interest on the part of kernel hackers (who have little interest in using non-C languages), rather than performance of the resulting system.

  15. C isn't the problem, it is really... by MobyDisk · · Score: 3, Insightful

    I suspect the problem is related to the poor coding practices used in academia. I see college professors who write code that barely compiles in GCC without a bunch of warnings about anachronistic syntax. Some of the C code used constructs that are unrecognizable to someone who learned the language within the past 10 years, and is completely type unsafe.

    I can't tell much from the code on the link, but I do see #define used for constants which is no longer appropriate (yet is EXTREMELY common to see). C99 had the const keyword in it, probably even before that.

    1. Re:C isn't the problem, it is really... by FearForWings · · Score: 2, Insightful

      I suspect the problem is related to the poor coding practices used in academia. I see college professors who write code that barely compiles in GCC without a bunch of warnings about anachronistic syntax.

      You know you'll learn a lot in a class when, after being told at the very least his c++ code is using deprecated includes, the professor tells you to just use '-Wno-deprecated'. I've basically come to the conclusion that I am just paying the school for a piece of paper, and I will learn little outside my personal study.

      --
      I don't know about angles, but it's fear that gives men wings. -Max Payne
    2. Re:C isn't the problem, it is really... by stinerman · · Score: 1

      Oh those were the days. At least my prof explained the difference.

      With a #define, the preprocessor picks up the constant while using const delays it to the compiler. Of course, he said they were equally good, just a matter of style.

      We never did learn why we had to put

      using namespace std;

      near the top of the program other than because we were supposed to use the standard namespace. I never bothered to ask or find out because by that time I had realized I'm an atrocious programmer and wouldn't be doing that for a living.

    3. Re:C isn't the problem, it is really... by Nigel+Stepp · · Score: 1

      That depends, what is the class for? If it's a class teaching how to use C++, then you have a point.

      If it's just about any other CS class, however, probably the language you are using doesn't matter so much, but rather what you are using the language to do.

      I'm guessing that in this instance, the fact that the professor is using some wacky set of C constructs is not nearly as important as what is actually being taught, e.g. an algorithm. That is, ignore the deprecated stuff because that's not what is important.

      Of course, yes, it could just be a really bad professor :)

      --
      4096R/EF7BAFA6 79E1 DF98 D09D 898F 9A11 F6F0 DDDC 23FA EF7B AFA6
    4. Re:C isn't the problem, it is really... by jgrahn · · Score: 2, Informative

      I can't tell much from the code on the link, but I do see #define used for constants which is no longer appropriate (yet is EXTREMELY common to see). C99 had the const keyword in it, probably even before that.

      C got const much earlier; it was there in 1989. And at least in the past, a static const int FOO was less useful than #define FOO, it wasn't "constant enough" to define the size of an array. But yes, you see macros too often.

    5. Re:C isn't the problem, it is really... by locofungus · · Score: 1

      I can't tell much from the code on the link, but I do see #define used for constants which is no longer appropriate (yet is EXTREMELY common to see). C99 had the const keyword in it, probably even before that.

      I don't know where to start here.

      const has been in C since c89.


      const int SIZE=4;
      int data[SIZE];

      is fine in C++ and does the same as using a #define for SIZE.

      It doesn't work in C prior to C99.

      In C99 it defines a VLA - i.e. it's identical to using int SIZE=4; and not using const for the array parameter.

      Tim.

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    6. Re:C isn't the problem, it is really... by MobyDisk · · Score: 1

      n C99 it defines a VLA

      Really? Is that required by the standard, or is that be up to the compiler? I would expect the compiler to treat that example as a fixed-length array.

      (I'll have to go try this in GCC when I get home...)

    7. Re:C isn't the problem, it is really... by locofungus · · Score: 1

      #include <stdio.h>
       
      const int size = 5;
       
      int main(void)
      {
        int data[size] = {0};
       
        printf("%d\n", (int)sizeof data);
       
        return 0;
      }

      $ gcc -std=c99 -o test test.c
      test.c: In function `main':
      test.c:7: error: variable-sized object may not be initialized
      test.c:7: warning: excess elements in array initializer
      test.c:7: warning: (near initialization for `data')
      $ g++ -o test test.c
      $

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    8. Re:C isn't the problem, it is really... by MobyDisk · · Score: 1

      Thanks, wow... so, doesn't that mean they broke functionality that worked in previous revisions of C?

    9. Re:C isn't the problem, it is really... by locofungus · · Score: 1

      Thanks, wow... so, doesn't that mean they broke functionality that worked in previous revisions of C?

      ?

      No functionality broken. You can't use a const int to define an array size in C prior to C99 at all. (That's where this entire subthread started - someone was commenting about the use of #define rather than const int which is a reasonable criticism of C++ code but not C code)

      It is an(other) area where C and C++ will forever behave differently (I assume).


      $ cat compiler.c
      #include

      struct c { char c[2]; };

      int test(void)
      {
              struct s { struct c { char c[1]; } s; };
              struct c t;
              return 1//**/2
                                          +sizeof t.c;
      }

      int main(void)
      {
              switch(test())
              {
                  case 1: printf("c89\n"); break;
                  case 2: printf("c99\n"); break;
                  case 3: printf("c++\n"); break;
                  default: printf("Unknown\n"); break;
              }
              return 0;
      }

      $ gcc -ansi -o c89 compiler.c
      $ gcc -std=c99 -o c99 compiler.c
      $ g++ -o c++ compiler.c
      $ ./c89
      c89
      $ ./c99
      c99
      $ ./c++
      c++
      $

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    10. Re:C isn't the problem, it is really... by locofungus · · Score: 1

      Gaaah. the <stdio.h> is obviously missing. I even previewed that post :-(

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    11. Re:C isn't the problem, it is really... by MobyDisk · · Score: 1

      Heh, the "somebody" was me :) And you assume correctly about C++. Since I code in C++ not C, I took it for granted that const int worked in C since it works in C++. ugh.

      Thanks for the detailed replies.

  16. cryptol by jefu · · Score: 3, Interesting

    But that just raises the question of how to define a hash function mathematically? The lambda calculus, Godel Numbers? Things like cryptographic hash functions don't tend to be nice algebraic thingies like f(x)=x*x+7, especially since they're usually iterative and deliberately messy - the pretty functions are likely to be less secure.

    On the other hand, there are things like cryptol in which you may be able to specify hash functions more mathematically. For example, here is a cryptol implementation of skein.

  17. dandelion orchard by epine · · Score: 3, Insightful

    This just emphasizes what we already knew about C, even the most careful, security conscious developer messes up memory management.

    I know nothing of the sort. How about asking some developers who have a history of getting both the security and the memory management correct which intellectual challenge they lose the most sleep over?

    The OpenBSD team has a history of strength in both areas. I suspect most of these developers would laugh out loud at the intellectual challenge of the memory management required to implement a hash function. It's about a hundred thousand lines of code short of where the OpenBSD team gets grey hair over memory management problems in the C language.

    I was just having an intense conversation about restrictive land covenants with my GF. If the economic cycle tips downward, the covenant holder (often a not-for-profit manila file folder which is legally distinct from the insolvent main entity) ceases to afford regular maintenance. Suddenly it turns into a dandelion orchard, and everyone in the community is dead certain that every dandelion on every lawn originated from this single source, whereupon some soon to be re-elected politico harpoons the legal infrastructure that permitted these things to flourish in the first place.

    "What we know about C" and "what we know about dandelions" are surprisingly equivalent.

    I wouldn't hire a programmer who can't get memory management right to take on any significant intellectual challenge. It's just a way to feel good about yourself without having the aptitude to cut your way out of a wet paper bag.

    90% of software development projects are not aptitude driven. Let's stop fooling ourselves into thinking that the languages that work well in those contexts having anything to offer those of us dealing with the other 10%

    Memory management is a subcase of resource management with a particularly harsh way of delivering the news: you suck. A memory managed language deprives the environment of so many golden opportunities to deliver this message, despite the fact that you still suck. By the time you don't suck, you've ceased to regard unmanaged memory as a core intellectual challenge, and trained yourself to work within an idiom where you hardly ever get it wrong anyway.

    The C string functions that cause the worst of the grief were widely known to be a bad idea by the mid 1980s. They originated a point in history where linking sprintf() was sometimes considered a luxury you couldn't afford. In the microcontroller world, it's still common that an environment provides three different versions of printf/sprintf: basic, basic plus more of the format options and maybe long integers, and then the full version which also includes floating point. The middle option is the beer budget. The first option is for when you can't even afford beer. These micros are not so different that the mini-computers on which C and Unix were originally created.

    Furthermore the efficiency of the string functions tends to ripple outward, as they tend to carry the torch for the platform's memory subsystem performance in most C code bases. What do the Z80, 6809, and 8086 all have in common? Instruction set tweaks to make zipping along a string of bytes a lot zippier.

    These tricks are then rolled into vendor optimized string libraries and made available to the developer via the ratified ANSI C string functions.

    It's unfortunate that all this industry of tweaking toward core performance was consolidated under a string API whose modern legacy is to have informed so many programmers that "you suck" that the general sentiment is to vote it off the island, as if such a thing is possible with a cockroach or a rat or dandelion dandruff.

    1. Re:dandelion orchard by Luke+has+no+name · · Score: 3, Insightful

      What I get out of this:

      "We're going to give you more shit to think about by making you use C. if you can't deal with all the stupid shit C throws at you, you suck."

      Which is a shit argument. Just use a better language that gives people less to worry about, and develop from there. Having to debug the shit out of a program for obscure memory management issues shouldn't be a test of your competence. You should be able to focus on the task at hand, nothing else.

  18. uhh, lint... by mevets · · Score: 3, Informative

    $ cat bo.c
    int a[3];
    void f()
    {
                    a[3] = 1;
    }

    $ lint bo.c
    bo.c:4: warning: array subscript cannot be > 2: 3

    Lint is so basic, I can't imagine not using it....

    1. Re:uhh, lint... by Anonymous Coward · · Score: 1, Insightful

      static int a[3], b = 3;
      void f(void)
      {
        a[b] = 1;
      }

      Lint isn't magic.

    2. Re:uhh, lint... by mevets · · Score: 1

      no lint is basic, so basic there is no good reason to not always use it. (bo.c) is equivalent to the only flaw described in the published summary. Dynamic analyzers (required to catch your example) are just stuck in the shadow of the halting problem.

    3. Re:uhh, lint... by Random+Walk · · Score: 1

      It's splint these days (at least on Linux). And using splint on any nontrivial large code base will bury you in tons of mostly irrelevant warnings. If you dare to attempt cleaning up the mess, you'll find that you have to annotate your code. And then you have the problem that splint will only spit out correct warnings if your annotations are correct, so you have just doubled the potential sources of error (now it's annotations+code instead of just code).

      Tools like splint just don't understand the flow of control in a program, which makes them next to useless. Static checking must be implemented in the compiler. Gcc is actually quite good already in that respect, and constantly improving - the version that ships with Ubuntu 8.10 detects the array overflow:

      $; gcc -O2 -Wall -c -o bo.o bo.c
      bo.c: In function 'f':
      bo.c:4: warning: array subscript is above array bounds

    4. Re:uhh, lint... by Vintermann · · Score: 1

      Most lints I've seen have atrocious false positive rates.

      I tried to write a minimal program that would give no warnings, I couldn't do it. If my main didn't have a return statement, it complained about that. If it had one that was not reachable, it complained about unreachable code. If it had one that COULD be reached, it complained that return could be called from main.

      --
      xkcd is not in the sudoers file. This incident will be reported.
  19. Re:SHA-3 Is Cracked. by Hurricane78 · · Score: 1

    What's a "null pointer bitch"?

    --
    Any sufficiently advanced intelligence is indistinguishable from stupidity.
  20. Difference between "program" and "mathematics"? by tepples · · Score: 1

    Because you can't compile a mathematical definition.

    If you've read the works of E.W. Dijkstra (start with Cruelty), you'd understand that a programming language isn't much more than a formal system for expressing mathematical definitions. Perhaps Haskell or another purely functional language might fit your intuitive understanding of a "mathematical definition" better than a procedural language like C, C++, P*, or Java.

  21. Trusting trust by tepples · · Score: 1

    Look up bootstrapping. Most modern compilers can compile themselves using a stage or two of simpler compilers

    Look up trusting trust. Defects in the compiler, whether intentional or unintentional, can propagate themselves to the compiled work, even if the compiled work is the compiler itself.

    1. Re:Trusting trust by iwein · · Score: 1

      Look up trusting trust. Defects in the compiler, whether intentional or unintentional, can propagate themselves to the compiled work, even if the compiled work is the compiler itself.

      This always gets me though: why doesn't this apply to C?

      --
      Show a man some news, distract him for an hour. Show a man some mod points, distract him for the rest of his life.
    2. Re:Trusting trust by DamnStupidElf · · Score: 1

      Unless you manually prove all the basic results of set theory for yourself (as well as philosophically agreeing that zf is a good choice of a set theory) and then build mathematics from it and derive formal languages from that, you probably shouldn't trust any code on any computer. Even then you can't trust the hardware, or even the wetware in your head.

      I was just explaining how to bootstrap a compiler, not the finer points of epistemology.

  22. Re:SHA-3 Is Cracked. by Mozk · · Score: 1

    One of those female pointer dogs, but one that doesn't actually exist.

    --
    No existe.
  23. Where is lint? by tepples · · Score: 1

    Lint is so basic, I can't imagine not using it....

    Lint is not found in Ubuntu. Did you mean Splint? And can you recommend anything analogous for C++ programs, for which Splint has no front-end?

    1. Re:Where is lint? by Random+Walk · · Score: 1

      See above - get the most recent version of gcc, use 'gcc -O2 -Wall'.

  24. Re:this is why... by tepples · · Score: 3, Insightful

    If you're still writing unmanaged code, you get what you deserve. It's 2009, not 1989.

    Try running managed code in the 4 MB RAM of a widely deployed handheld computer. Now try making that managed code time-competitive and space-competitive with an equivalent program in C++ compiled to a native binary.

  25. Other SHA-3 news: conference starts this week! by secmartin · · Score: 1

    In other news, the first SHA-3 conference will be held in Belgium this week. The NIST hopes to be able to reduce the amount of contestants for the SHA-3 contest to a more manageable level by the end of that; for more info read on here.

  26. Previously Slashdotted by dimethylxanthine · · Score: 1

    Are they ready for Round 2??

  27. DJB threw his hash in the ring, too by tyler_larson · · Score: 2, Interesting

    MD6 by Rivest and Skein by Schneier et. al. seem to be getting a lot of attention, but another celebrity cryptographer, Dan J. Bernstein, also has a hash in this race, called "CubeHash."

    DJB continued his tradition of offering cash rewards for people to find security problems with his code, giving out (so far) monthly prizes of 100 Euros to the most interesting cryptanalysis of CubeHash.

    So far, the primary criticism of CubeHash is that it's slow, running some 10 to 20 times slower than many of the others in the competition. Dan brushes off this criticism by stating on his site: "for most applications of hash functions, speed simply doesn't matter."

    To be honest, when compared efforts like MD6 and Skein, with their mathematic proofs of security, VHDL and other in-hardware reference implementations, and their amazing optimizations in both speed and efficiency (Skein can process half a GByte of data per second on modern hardware, and consumes only 100 bytes) -- entries like CubeHash seem to have that longshot underdog appeal, like a New Zealand soccer World Cup team.

    --
    "With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea...."
    RFC 1925
    1. Re:DJB threw his hash in the ring, too by Kjella · · Score: 1

      So far, the primary criticism of CubeHash is that it's slow, running some 10 to 20 times slower than many of the others in the competition. Dan brushes off this criticism by stating on his site: "for most applications of hash functions, speed simply doesn't matter."

      That dude must have missed out on the small thing called "P2P", since most of them rely on making tons of hash checks per block, per file and whatever. And yes, they do need the properties of a good hash not just a checksum so it can't be poisoned with bad data. Any kind of backend processing lots of signed messages? Usuaully you hash the message to check it against the digest, then check the signature of the digest. What about mobile devices with low battery and CPU capacity? I'm not buying it.

      --
      Live today, because you never know what tomorrow brings
  28. void *? That's cutting edge by Nicolas+MONNET · · Score: 1

    I've had to work on an app where the main developer didn't know / didn't care about void *, and used char * everywhere instead. In fact he used char* even when the type was unique, and type cast at every call, and at the beginning of the called function.

    When I called him on it, he said that I was doing philosophy and that he had real work to do.

  29. Re:this is why... by Vintermann · · Score: 1

    My phone has a Java runtime. It works, and it's in fact a very sensible choice for the application (where security and binary portability matters more than performance). Even today, many embedded devices are powerful enough to run bytecode-interpreted languages, and this will only become more true in the future.

    --
    xkcd is not in the sudoers file. This incident will be reported.
  30. Re:this is why... by swillden · · Score: 1

    it's in fact a very sensible choice for the application (where security and binary portability matters more than performance)

    Except that binary portability doesn't matter, and while security is an absolute requirement, performance must be as high as possible.

    Many applications hash huge volumes of data. SHA-256 can hash around 60 MBps on a ~2Ghz core, and that's too slow for many applications. WAY too slow. I have an application where I'd like to be able to hash over 20 MBps on an XScale processor. The rest of the system can easily sustain this data rate, but the hash is the bottleneck. The hash should not be the bottleneck.

    Performance is a critically-important characteristic of a secure hash function and it will likely be the factor that decides the winner, as it was with AES.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  31. Re:this is why... by Just+Some+Guy · · Score: 1

    unmanaged code is dead.

    Yes, because it warms my heart to think of reference crypto code that would crash if it wasn't running in a sandbox.

    --
    Dewey, what part of this looks like authorities should be involved?
  32. Re:this is why... by tepples · · Score: 1

    Wait, why is this managed code not compiled to native binaries and optimized?

    Because the device uses different digital signing keys for managed and unmanaged code, and end users don't have the unmanaged one.

  33. Languages with diverse vs. single-source compilers by tepples · · Score: 1

    This always gets me though: why doesn't [the trusting trust attack] apply to C?

    Bruce Schneier pointed out that one can bootstrap a compiler using a different implementation of the language as a (probabilistic) measure against defects introduced by trusting trust. Build it on systems with different compilers, bit-compare the binaries generated on each system, and if they match, you can be reasonably sure that there is no such defect. But unlike C, which has implementations from GNU, Borland, Watcom, M$, Green Hills, and numerous other vendors, a lot of the managed languages lack multiple widely used complete implementations. For example, there really isn't an alternative to Sun Java.