trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaveBirdsall <...@git.apache.org>
Subject [GitHub] incubator-trafodion pull request #813: [TRAFODION-2229] add Hashing function...
Date Thu, 03 Nov 2016 17:57:31 GMT
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/813#discussion_r86404501
  
    --- Diff: core/sql/exp/exp_function.cpp ---
    @@ -7900,6 +7936,114 @@ ex_expr::exp_return_type ExFunctionInetNtoa::eval(char * op_data[],
        return ex_expr::EXPR_OK;
     }
     
    +ex_expr::exp_return_type ExFunctionCrc32::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +  Attributes *resultAttr   = getOperand(0);
    +  Attributes *srcAttr   = getOperand(1);
    +
    +  Lng32 slen = srcAttr->getLength(op_data[-MAX_OPERANDS+1]);
    +  Lng32 rlen = resultAttr->getLength();
    +
    +  *(ULng32*)op_data[0] = 0; 
    +  ULng32 crc = crc32(0L, Z_NULL, 0);
    +  crc = crc32 (crc, (const Bytef*)op_data[1], slen);
    +  *(ULng32*)op_data[0] = crc; 
    +  return ex_expr::EXPR_OK;
    +}
    +
    +//only support SHA 256 for this version
    +//TBD: add 224 and 384, 512 in next version
    +ex_expr::exp_return_type ExFunctionSha2::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +
    +  unsigned char sha[SHA256_DIGEST_LENGTH+ 1]={0};  
    +
    +  Attributes *resultAttr   = getOperand(0);
    +  Attributes *srcAttr   = getOperand(1);
    +
    +  Lng32 slen = srcAttr->getLength(op_data[-MAX_OPERANDS+1]);
    +  Lng32 rlen = resultAttr->getLength();
    +
    +  memset(op_data[0], 0, rlen);
    +
    +  SHA256_CTX  sha_ctx;
    +
    +  SHA256_Init(&sha_ctx);  
    +  SHA256_Update(&sha_ctx, op_data[1], slen);
    +  SHA256_Final((unsigned char*) sha,&sha_ctx); 
    +  char tmp[2];
    +  for(int i=0; i < SHA256_DIGEST_LENGTH; i++ )
    +  {
    +    tmp[0]=tmp[1]='0';
    +    sprintf(tmp, "%.2x", (int)sha[i]);
    +    memcpy(op_data[0]+i*2, tmp, 2);
    +  }
    +   
    +  return ex_expr::EXPR_OK;
    +}
    +
    +ex_expr::exp_return_type ExFunctionSha::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +
    +  unsigned char sha[SHA_DIGEST_LENGTH + 1]={0};  
    +
    +  Attributes *resultAttr   = getOperand(0);
    +  Attributes *srcAttr   = getOperand(1);
    +  Lng32 slen = srcAttr->getLength(op_data[-MAX_OPERANDS+1]);
    +  Lng32 rlen = resultAttr->getLength();
    +  memset(op_data[0], 0, rlen);
    +
    +  SHA_CTX  sha_ctx;
    +
    +  SHA1_Init(&sha_ctx);  
    +  SHA1_Update(&sha_ctx, op_data[1], slen);
    +  SHA1_Final((unsigned char*) sha,&sha_ctx); 
    +  char tmp[2];
    +  for(int i=0; i < SHA_DIGEST_LENGTH ; i++ )
    +  {
    +    tmp[0]=tmp[1]='0';
    +    sprintf(tmp, "%.2x", (int)sha[i]);
    +    memcpy(op_data[0]+i*2, tmp, 2);
    +  }
    +   
    +  return ex_expr::EXPR_OK;
    +}
    +
    +ex_expr::exp_return_type ExFunctionMd5::eval(char * op_data[],
    +                                                        CollHeap *heap,
    +                                                        ComDiagsArea **diags)
    +{
    +  unsigned char md5[17]={0};  
    +
    +  Attributes *resultAttr   = getOperand(0);
    +  Attributes *srcAttr   = getOperand(1);
    +
    +  Lng32 slen = srcAttr->getLength(op_data[-MAX_OPERANDS+1]);
    +  Lng32 rlen = resultAttr->getLength();
    +
    +  memset(op_data[0], 0, rlen);
    +  MD5_CTX  md5_ctx;
    +
    +  MD5_Init(&md5_ctx);  
    +  MD5_Update(&md5_ctx, op_data[1], slen);
    +  MD5_Final((unsigned char*) md5,&md5_ctx); 
    +  char tmp[2];
    --- End diff --
    
    This buffer is too short.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message