Exemple #1
0
size32_t aesEncryptWithRSAEncryptedKey(MemoryBuffer &out, size32_t inSz, const void *inBytes, const CLoadedKey &publicKey)
{
    // create random AES key and IV
    char randomAesKey[aesMaxKeySize];
    char randomIV[aesBlockSize];
    fillRandomData(aesMaxKeySize, randomAesKey);
    fillRandomData(aesBlockSize, randomIV);

    size32_t startSz = out.length();
    DelayedSizeMarker mark(out);
    publicKeyEncrypt(out, aesMaxKeySize, randomAesKey, publicKey);
    mark.write();
    out.append(aesBlockSize, randomIV);

    DelayedSizeMarker aesSz(out);
    aesEncrypt(out, inSz, inBytes, aesMaxKeySize, randomAesKey, randomIV);
    aesSz.write();
    return out.length()-startSz;
}
int main(int argc, char* argv[]) {
  Matrix matrix;
  /*Read in height and width*/
  parseArguments(argc, argv, &matrix);
  /*Allocate matrix on the heap*/
  initMatrix(&matrix);
  /*Fill with random unsigned chars*/
  fillRandomData(&matrix);
  /*Start timer*/
  double start,mid1, mid2, end;
  start = (double) clock();
  /*Differentiate*/
  int** dx = differentiateX(&matrix);
  mid1 = (double) clock();
  int** dy = differentiateY(&matrix);
  mid2 = (double) clock();
  /*Compute min and max*/
  printf("The max and min for dx are: %d and %d\n", max(dx, matrix.width, matrix.height), min(dx, matrix.width, matrix.height));
  printf("The max and min for dy are: %d and %d\n", max(dy, matrix.width, matrix.height), min(dy, matrix.width, matrix.height));
  /*End timer*/
  end = (double) clock();
  printf("Total time taken: %.4f msec\n", (end-start) / CLOCKS_PER_MSEC);
  printf("dx takes %f, dy takes %f msec\n", (mid1 - start) / CLOCKS_PER_MSEC, (mid2 - mid1) / CLOCKS_PER_MSEC);
  /*Print*/
  /*printMatrix(&matrix);*/
  /*printArray(dx, matrix.width, matrix.height);*/
  /*printArray(dy, matrix.width, matrix.height);*/
  /*Free everything*/
  for (int x = 0; x < matrix.width; x++) {
    free(matrix.data[x]);
    free(dx[x]);
    free(dy[x]);
  }
  free(matrix.data);
  free(dx);
  free(dy);
  return 0;
}