Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Saturday December 02 2017, @01:48PM   Printer-friendly
from the see-what-we-did-there? dept.

https://www.cossacklabs.com/blog/macros-in-crypto-c-code.html

Like death and taxes, one thing that you can be sure of is that using C macros in a modern software project will cause a debate. While for some macros remain a convenient and efficient way of achieving particular programming goals, for others they are opaque, introduce the unnecessary risk of coding errors, and reduce readability.

The criticism of macros is particularly acute in the wider security community. Among Cossack Labs' engineers and the core Themis crypto library contributors there are people who previously worked on auditing cryptographic implementations of critical code. Their typical knee-jerk reaction to macros was always "kill it with fire and never use it again". Taking no sides, we would like to assess both pros and cons of using such dangerous things as macros in security code (as we faced the issue when developing Themis) and suggest some techniques for lowering the accompanying risks.

We'll also discuss a custom "for-audit" build target for Themis designed specifically to generate source code that exposes the macros to inspection because we appreciate the need for security software to be subject to detailed source code scrutiny.


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by maxwell demon on Saturday December 02 2017, @06:14PM (1 child)

    by maxwell demon (1608) on Saturday December 02 2017, @06:14PM (#604337) Journal

    The problem with C macros is that they are a rather blunt tool. In most cases, the use of macros results in the code equivalent of driving a screw in with a hammer.

    Note that the problem is not with the concept of macros as such, it's with the specific way macros are implemented in C, namely using a preprocessor which knows very little about the structure of C programs.

    --
    The Tao of math: The numbers you can count are not the real numbers.
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by coolgopher on Sunday December 03 2017, @12:25AM

    by coolgopher (1157) on Sunday December 03 2017, @12:25AM (#604479)

    For all its bluntness, I miss the C-preprocessor whenever I'm in a language that doesn't support pre-processing (and doesn't lend itself to pre-processing via `make`). Commonly I also miss the relative type safety of C then.

    A point maybe worth mentioning is that it's typically possible to use whatever pre-processor you want, it doesn't have to be /usr/bin/cpp. The stuff done in TFA could be implemented in that manner for example.

    Gcc doesn't make it overly easy, though this post [stackoverflow.com] lists a way. I remember one compiler I used many moons ago had a simple -cpp switch with which you specify the pre-processor you wanted. It *might* have been the SunOS C compiler, but don't quote me on that please :)