Gee! Yeah! I am a C++-programmer :-/

 

I’ve seen enough code where I only turned away. Colleagues used cin and cout to sell their stuff as object oriented…..

But obviously I haven’t seen everything, yet. Recently I saw an award winning piece of code – well, it wasn’t the code, it was the algorithm that was awarded. The designers of the algorithm published a sample implementation in C++

/********************
 * I found this code at https://github.com/khovratovich/Argon2/blob/master/Argon2d/opt-sse/argon2d-opt-sse.cpp
 * The site that hosts the project is at https://github.com/khovratovich/Argon2
 ********************/
/********************** and now the real thing *************************/
/*****Argon2d optimized implementation (SSE3)*
* Code written by Daniel Dinu and Dmitry Khovratovich
* khovratovich@gmail.com
**/

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#if defined(_MSC_VER) // ADDED
#else
#include <sys/time.h>
#include <unistd.h>
#endif

#include <vector>
#include <thread>
using namespace std;

// Intrinsics
#if defined(_MSC_VER) // ADDED
#else
#include <x86intrin.h>
#include <string.h>
#endif
// BLAKE2 round
#include "blake2-round.h"
#include "blake2.h"

// Constants
# include "argon2d.h"

// The block size in bytes
#ifndef BLOCK_SIZE
#define BLOCK_SIZE 1024
#endif

#define MEASURE

struct info {
 uint64_t pass;
 uint64_t slice;
 uint64_t lane;
};

__m128i t0, t1;
const __m128i r16 = _mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9);
const __m128i r24 = _mm_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10);

//#define BLOCK_OFFSET(l,s) {}

void allocate_memory(uint8_t **memory,uint32_t m_cost)
{
 *memory = (uint8_t *) _mm_malloc((size_t)m_cost<<10, ALIGN_ARGON);
 if(!*memory)
 {
 printf("Could not allocate the requested memory!\n");
 exit(1);
 }
}
......... and so forth

To make sure you find the code sample, I also placed a copy here:  argon2d-opt-sse.cpp.gz

If this is C++-code, then I am a gifted C++-programmer!

I want to make it very clear, that most of the C++-code I’ve seen is nothing but C-Code in files with a cpp-extension compiled with a C++ compiler. I prefer to be honest with you, but if you insist I will not hesitate and lie to you: okay, okay, I am a C++programmer.