get_memory(char* p,int num) 续

根据前面我们总结出一条"真理", 进入函数内部的参数不可改变,可以改变的是其指向的内容,

 

那么前面的分配内存的函数可以这样写

 

void get_memory(char** p,int num)
{
     *p=(char*)malloc(num*sizeof(char));

}

 

 指向指针的指针,指针不变,指针指向的内容改变

 

如何使用呢

 

 get_memory(&str,12);

 

 

结果正确。

 

 

意外发现,malloc 分配内存,内存数据为

 

cd cd cd cd cd cd cd cd cd cd cd cd

 

free 内存,内存数据为

ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee fe ee 

 

这是一条rule ???

 

 

防止传值的做法还有用引用,如

void change(int& i)
{
    i=100;
}

 

 int i=10;
 cout<<i<<endl;

 change(i);
 cout<<i<<endl;

 

后一个就是100

 

 

可以给出详细的注释吗 。包括原理,参数等等,我是初学者,/****************************************************************************** * * Copyright (c) 2023 TP-LINK Technologies CO.,LTD. * All rights reserved. * * FILE NAME : at_utils.c * VERSION : 1.0 * DESCRIPTION : AT命令解析工具. * * AUTHOR : tangqilin (tangqilin@tp-link.com.hk) * CREATE DATE : 03/25/2023 * * HISTORY : * 01 03/25/2023 Tang Qilin Create. * ******************************************************************************/ #include "at_utils.h" #include <string.h> #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <stdarg.h> #include <sys/types.h> #include <arpa/inet.h> #include <sys/socket.h> /** * Starts tokenizing an AT response string * returns -1 if this is not a valid response string, 0 on success. * updates *p_cur with current position */ S32 at_tok_start(char **p_cur) { if(*p_cur == NULL) { return -1; } // skip prefix // consume "^[^:]:" *p_cur = strchr(*p_cur, ':'); if(*p_cur == NULL) { return -1; } (*p_cur)++; return 0; } /** return 1 if line starts with prefix, 0 if it does not */ S32 strStarwith(const char *line, const char *prefix) { for( ; *line != '\0' && *prefix != '\0' ; line++, prefix++) { if(*line != *prefix) { return 0; } } return *prefix == '\0'; } S32 at_tok_nextlonglong(char **p_cur, long long *p_out) { return at_tok_nextlonglong_base(p_cur, p_out, 10, 0); } S32 at_tok_nextlonglong_base(char **p_cur, long long *p_out, int base, int uns) { char *ret; if(*p_cur == NULL) { return -1; } ret = nextTok(p_cur); if(ret == NULL) { return -1; }else { long long l; char *end; if(uns) { l = strtoull(ret, &end, base); }else { l = strtoll(ret, &end, base); } *p_out = (long long)l; if(end == ret) { return -1; } } return 0; } /** * Parses the next base 10 integer in the AT response line * and places it in *p_out * returns 0 on success and -1 on fail * updates *p_cur */ S32 at_tok_nextint(char **p_cur, int *p_out) { return at_tok_nextint_base(p_cur, p_out, 10, 0); } /** * Parses the next integer in the AT response line and places it in *p_out * returns 0 on success and -1 on fail * updates *p_cur * "base" is the same as the base param in strtol */ S32 at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns) { char *ret; if(*p_cur == NULL) { return -1; } ret = nextTok(p_cur); if(ret == NULL) { return -1; }else { long l; char *end; if(uns) { l = strtoul(ret, &end, base); }else { l = strtol(ret, &end, base); } *p_out = (int)l; if(end == ret) { return -1; } } return 0; } void skipWhiteSpace(char **p_cur) { if (*p_cur == NULL)return; while(**p_cur != '\0' && isspace(**p_cur)) { (*p_cur)++; } } /** * Parses the next base 16 integer in the AT response line * and places it in *p_out * returns 0 on success and -1 on fail * updates *p_cur */ S32 at_tok_nexthexint(char** p_cur, int* p_out) { return at_tok_nextint_base(p_cur, p_out, 16, 1); } S32 at_tok_nextbool(char** p_cur, char* p_out) { int ret; int result; ret = at_tok_nextint(p_cur, &result); if (ret < 0) { return -1; } // booleans should be 0 or 1 if (!(result == 0 || result == 1)) { return -1; } if (p_out != NULL) { *p_out = (char)result; } return ret; } /** returns 1 on "has more tokens" and 0 if no */ S32 at_tok_hasmore(char** p_cur) { return !(*p_cur == NULL || **p_cur == '\0'); } S32 at_tok_count(const char* in_line) { int commas = 0; const char* p; if (!in_line) return 0; for (p = in_line; *p != '\0'; p++) { if (*p == ',') commas++; } return commas; } //fmt: d ~ int, x ~ hexint, b ~ bool, s ~ str S32 at_tok_scanf(const char* in_line, const char* fmt, ...) { int n = 0; int err; va_list ap; const char* p = fmt; void* d; void* dump; static char s_line[1024]; char* line = s_line; if (!in_line) return 0; strncpy(s_line, in_line, sizeof(s_line)); va_start(ap, fmt); err = at_tok_start(&line); if (err < 0) goto error; for (; *p; p++) { if (*p == ',' || *p == ' ') continue; if (*p != '%') { goto error; } p++; d = va_arg(ap, void*); if (!d) d = &dump; if (!at_tok_hasmore(&line)) break; if (*line == '-' && *(line + 1) == ',') { line += 2; n++; if (*p == 'd') * (int*)d = -1; continue; } switch (*p) { case 'd': err = at_tok_nextint(&line, (int*)d); if (err < 0) goto error; break; case 'x': err = at_tok_nexthexint(&line, (int*)d); if (err < 0) goto error; break; case 'b': err = at_tok_nextbool(&line, (char*)d); if (err < 0) goto error; break; case 's': err = at_tok_nextstr(&line, (char**)d); //if strdup(line), here return free memory to caller if (err < 0) goto error; break; case 'l': err = at_tok_nextlonglong(&line, (long long*)d); if(err < 0) goto error; break; default: goto error; break; } n++; } va_end(ap); error: //free(line); return n; } void skipNextComma(char **p_cur) { if(*p_cur == NULL) return; while(**p_cur != '\0' && **p_cur != ',') { (*p_cur)++; } if(**p_cur == ',') { (*p_cur)++; } } char *nextTok(char **p_cur) { char *ret = NULL; skipWhiteSpace(p_cur); if(*p_cur == NULL) { ret = NULL; } else if(**p_cur == '"') { (*p_cur)++; ret = strsep(p_cur, "\""); skipNextComma(p_cur); }else { ret = strsep(p_cur, ","); } return ret; } S32 at_tok_nextstr(char **p_cur, char **p_out) { if(*p_cur == NULL) { return -1; } *p_out = nextTok(p_cur); return 0; } char* skipLFCR(char *str) { char *p = NULL; int len = 0; int start = 0; if(NULL == str) { return NULL; } p = str; len = strlen(str); while (start < len) { if ('\r' == *p || '\n' == *p) { p++; start++; } else { break; } } if (start == len) { return NULL; } return p; } /* dot num ipv4 3 ipv4+mask 7 ipv6 15 ipv6+mask 31 */ int get_ip_mask(char *ip_and_mask, char* ip, char* mask) { int len = 0; int i = 0; int dot_num = 0; if(ip_and_mask == NULL || ip == NULL || mask == NULL) { return -1; } len = strlen(ip_and_mask); for(i = 0; i < len; i++) { if(ip_and_mask[i] == '.') { dot_num++; } } if(dot_num == 31) { dot_num = 0; for(i = 0; i < len; i++) { if(ip_and_mask[i] == '.') { dot_num++; if(dot_num == 16) { break; } } } memcpy(ip, ip_and_mask, i); memcpy(mask, &ip_and_mask[i+1], len-i-1); } else if(dot_num == 15) { memcpy(ip, ip_and_mask, strlen(ip_and_mask)); } else if(dot_num == 7) { dot_num = 0; for(i = 0; i < len; i++) { if(ip_and_mask[i] == '.') { dot_num ++; if(dot_num == 4) { break; } } } memcpy(ip, ip_and_mask, i); memcpy(mask, &ip_and_mask[i+1], len-i-1); } else if(dot_num == 3) { memcpy(ip, ip_and_mask, strlen(ip_and_mask)); } else { return -1; } return 0; } int is_ipv4(char *ip) { int len = 0; int i = 0; char *str = NULL; int dot_num = 0; if(ip == NULL) { return -1; } str = ip; for(i = 0, len = strlen(str); i < len; i++) { if(str[i] == '.') { dot_num ++; } } if(dot_num == 3) { return 1; } else if(dot_num == 15) { return 0; } else { return -1; } } int get_ipv4_gw(char * ip, char * gw) { int len =0; int i =0; char * str = NULL; int dot_num = 0; if(ip == NULL) { return -1; } str = ip; for( i = 0, len = strlen(str); i < len; i++) { if(str[i]=='.') { dot_num++; if(dot_num == 3) { i++; break; } } } if (dot_num != 3) { return -1; } int last_num = atoi(str+i); if (last_num < 0 || last_num > 255) { return -1; } memcpy(gw, str, len); memset(gw+i, 0, 4); /* 如果获取的IP地址最后一字节为255,则将网关的最后一字节设置为1 */ if(255 - last_num == 0) { snprintf(gw+i, 4, "%d", 1); }else { snprintf(gw+i, 4, "%d", 255-last_num); } return 0; } #ifdef CONFIG_IPV6 int charCountInStr(const char* str, char ch) { int i; int num = 0; for (i=0; str[i] != '\0'; i++) { if (str[i] == ch) { num ++; } } return num; } /* return 1 success * return 0 failed */ int convertDotNotation2Ipv4Uint (const char *source, unsigned int *addr, unsigned int *mask) { int i; int count = charCountInStr(source, '.'); char * end; for (i = 0; i <= count; i++) { if (i < 4) { addr[0] |= strtoul(source, &end, 10) << i * 8; } else if (i < 8) { mask[0] |= strtoul(source, &end, 10) << (i - 4) * 8; } if (i == count || *end == '\0') { //RLOGI(convertDotNotation2Ipv4Uint, "%s, count=%d", __FUNCTION__, count); //LOG_I( "%s, count=%d", "convertDotNotation2Ipv6Uint", count); return 1; } else if (*end != '.') { return 0; } source = end + 1; } return 0; } /* return 1 success * return 0 failed */ int convertDotNotation2Ipv6Uint (const char *source, unsigned int *addr, unsigned int *mask) { int i; int count = charCountInStr(source, '.'); char * end; for (i = 0; i <= count; i++) { if (i < 4) { addr[0] |= strtoul(source, &end, 10) << i * 8; } else if (i < 8) { addr[1] |= strtoul(source, &end, 10) << (i - 4) * 8; } else if (i < 12) { addr[2] |= strtoul(source, &end, 10) << (i - 8) * 8; } else if (i < 16) { addr[3] |= strtoul(source, &end, 10) << (i - 12) * 8; } else if (i < 20) { mask[0] |= strtoul(source, &end, 10) << (i - 16) * 8; } else if (i < 24) { mask[1] |= strtoul(source, &end, 10) << (i - 20) * 8; } else if (i < 28) { mask[2] |= strtoul(source, &end, 10) << (i - 24) * 8; } else if (i < 32) { mask[3] |= strtoul(source, &end, 10) << (i - 28) * 8; } if (i == count || *end == '\0') { //RLOGI(convertDotNotation2Ipv6Uint, "%s, count=%d", __FUNCTION__, count); //LOG_I( "%s, count=%d", "convertDotNotation2Ipv6Uint", count); return 1; } else if (*end != '.') { return 0; } source = end + 1; } return 0; } /* return 1 success * return 0 failed */ int convertDotNotation2IpUint(int af, const char *source, unsigned int *addr, unsigned int *mask) { if (af == AF_INET) { return convertDotNotation2Ipv4Uint(source, addr, mask); } else { return convertDotNotation2Ipv6Uint(source, addr, mask); } } /* return address family */ int convertDotNotation2IpString(const char *source, char *ipaddress, char *ipmask) { unsigned int addr[4]; unsigned int mask[4]; int af; int ret; int count = charCountInStr(source, '.'); memset(addr, 0, sizeof(addr)); memset(mask, 0, sizeof(mask)); if (count < 8) { af = AF_INET; } else if (count < 32) { af = AF_INET6; } else { return -1; } ret = convertDotNotation2IpUint(af, source, addr, mask); if (ret > 0) { if (ipaddress != NULL) { inet_ntop(af, addr, ipaddress, INET6_ADDRSTRLEN); } if (ipmask != NULL) { inet_ntop(af, mask, ipmask,INET6_ADDRSTRLEN); } } else { printf("%s, covert failed", "convertDotNotation2IpString"); return -1; } return af; } #endif
09-17
bool HierSgmCudaImpl::Init(const ste_opt1_t& option) { const int width = option.width; const int height = option.height; const int min_disp = option.min_disp; const int max_disp = option.max_disp; const int num_layers = option.num_layers; if (width == 0 || height == 0) { return false; } is_print_timing_ = false; Release(); width_ = width; height_ = height; //ÿһ������ݷ��䡢�������㡢ƥ�����ʼ�� num_layers_ = std::max(1, num_layers); vision_stereo_ = new StereoCuda * [num_layers_](); layer_bytes_left_ = new unsigned char* [num_layers_](); layer_bytes_right_ = new unsigned char* [num_layers_](); layer_initial_disps_ = new short* [num_layers_](); layer_disps_left_ = new float* [num_layers_](); layer_disps_right_ = new float* [num_layers_](); layer_width_ = new int[num_layers_](); layer_height_ = new int[num_layers_](); for (int i = 0; i < num_layers_; i++) { vision_stereo_[i] = new StereoCuda; const int scale = static_cast<int>(pow(2.0, static_cast<double>(i))); const auto w = layer_width_[i] = width_ / scale; const auto h = layer_height_[i] = height_ / scale; #ifdef USING_PAGE_LOCKED_MEMORY StereoCuda::MallocPageLockedPtr(reinterpret_cast<void**>(&layer_bytes_left_[i]), w * h * sizeof(unsigned char)); StereoCuda::MallocPageLockedPtr(reinterpret_cast<void**>(&layer_bytes_right_[i]), w * h * sizeof(unsigned char)); if (i > 0) { StereoCuda::MallocPageLockedPtr(reinterpret_cast<void**>(&layer_disps_left_[i]), w * h * sizeof(float)); StereoCuda::MallocPageLockedPtr(reinterpret_cast<void**>(&layer_disps_right_[i]), w * h * sizeof(float)); } if (i < num_layers_ - 1) { StereoCuda::MallocPageLockedPtr(reinterpret_cast<void**>(&layer_initial_disps_[i]), w * h * sizeof(short)); } #else layer_bytes_left_[i] = new unsigned char[w * h](); layer_bytes_right_[i] = new unsigned char[w * h](); if (i > 0) { layer_disps_left_[i] = new float[w * h](); layer_disps_right_[i] = new float[w * h](); } if (i < num_layers_ - 1) { layer_initial_disps_[i] = new short[w * h](); } #endif CuSGMOption sgm_param; SetSgmParameters(option.do_lr_check,option.do_rm_peaks,option.do_smooth, sgm_param, i, num_layers_); if (!sgm_param.using_constant_p2) { sgm_param.p1 = 10; sgm_param.p2_init = 150; } //�����ӲΧ int disparity_min = min_disp / scale, disparity_max = max_disp / scale; int disparity_range = 32; if (i == num_layers_ - 1) { disparity_range = disparity_max - disparity_min; int k = 6; while (pow(2, k) < disparity_range) { k++; } disparity_range = pow(2, k); if (disparity_range > 2 * width) { disparity_range /= 2; } if (disparity_min >= width) { disparity_min = width - disparity_range; if (disparity_min < -width) { disparity_min = -width; } } } else { disparity_min = 0.0; disparity_max = StereoCuda::get_level_range(); disparity_range = StereoCuda::get_level_range(); } if (!vision_stereo_[i]->Init(layer_width_[i], layer_height_[i], disparity_min, disparity_range, sgm_param, is_print_timing_)) { return false; } } return true; } 注释上述代码
09-25
补充上个问题的信息:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <libubox/md5.h> #include "common.h" #include "ubus.h" #include "worker.h" #include "relay.h" #include "minor_stream.h" #include "double_talk.h" #include "chime_ctrl.h" #include "alarm.h" #include "preview.h" #include "cookie.h" #include "device.h" #include "iot_info.h" #include "snapshot.h" #include "tapocare.h" #include "ring.h" #include "storage.h" #ifdef HARDDISK_STORAGE #include "face_control.h" #endif #ifdef HUB_WEBRTC #include "webrtc.h" #endif #ifdef AI_ENHANCE #include "image_transmit.h" #endif #ifdef SDCARD_VIDEO_DOWNLOAD_SUPPORT #include "storage_local_download.h" #endif #ifdef PROTOCOL_SECURE #define HTTP_DIGEST_PWD_MD5 "1" #define HTTP_DIGEST_PWD_RSA "2" #define HTTP_DIGEST_PWD_SHA "3" #endif char tapo_user[128] = {0}; char tapo_passwd[128] = {0}; char tapo_nonce[128] = {0}; const int RELAY_CONSUMER_MAX_NUM[] = {0, 34, 26, 18, 20}; int relay_consumer_cur_max_num = 0; int relay_consumer_cur_left_num = 0; static unsigned char tapo_key[16] = {0}; static unsigned char tapo_iv[16] = {0}; static struct tpsocket_aes_key tapo_aes_key = {{0}}; static struct tpsocket_aes_key tapo_aes_dec_key = {{0}}; #ifdef HTTP_HMAC_HKDF_SUPPORT unsigned char tapo_key_hkdf[16] = {0}; unsigned char tapo_key_hkdf_hmac[16] = {0}; char tapo_salt[32 + 1] = {0}; struct tpsocket_aes_key tapo_aes_key_hkdf = {{0}}; struct tpsocket_aes_key tapo_aes_dec_key_hkdf = {{0}}; char *tapo_vod_get_salt() { return tapo_salt; } void generate_iv_nonce(unsigned char *nonce, int len) { int i = 0; for (i = 0; i < len; ++i) { nonce[i] = (unsigned char)(rand() % 256); } } int tapo_vod_hkdf_hamc_verify_decrypt(unsigned char *in, int inputlen, unsigned char *out, int *outputlen, unsigned char *iv_nonce, char *XHmac) { unsigned char hmac[32] = {0}; char base64_hmac[32*2] = {0}; int ret = 0; tpsocket_sha256_hmac(tapo_key_hkdf_hmac, 16, in, inputlen, hmac); tpsocket_base64_encode(hmac, sizeof(hmac), (unsigned char *)base64_hmac); if (!strncmp(base64_hmac, XHmac, strlen(base64_hmac))) { ret = tpsocket_aes_cbc_encrypt(in, out, inputlen, &tapo_aes_dec_key_hkdf, iv_nonce, 0); if (ret != 0) { DBG_ERR("tpsocket_aes_cbc_encrypt failed\n"); *outputlen = 0; goto exit; } *outputlen = inputlen; } else { DBG_ERR("Hmac verification failed\n"); *outputlen = 0; goto exit; } exit: return ret; } int tapo_vod_hkdf_hamc_encrypt(unsigned char *in, unsigned char *out, unsigned int len, unsigned char *iv_str, unsigned char *base64_hmac) { unsigned char iv_nonce[16] = {0}; unsigned char hmac[32] = {0}; int ret = 0; generate_iv_nonce(iv_nonce, 16); tpsocket_hex_encode(iv_nonce, 16, iv_str, 0); ret = tpsocket_aes_cbc_encrypt(in, out, len, &tapo_aes_key_hkdf, iv_nonce, 1); if (ret != 0) { DBG_ERR("Error happens on encrypting.\n"); ret = 0 ; goto exit; } tpsocket_sha256_hmac(tapo_key_hkdf_hmac, 16, out, len, hmac); tpsocket_base64_encode(hmac, sizeof(hmac), base64_hmac); exit: return len; } bool tapo_vod_get_hkdf_hamc(struct list_head *buf, char *XHmac, unsigned char *iv_nonce) { char *XHmac_tmp = NULL; char *XNonce = NULL; if ((XHmac_tmp = common_find_key_from_buf(buf, "X-Data-Hmac")) != NULL) { memset(XHmac, 0, HKDF_HMAC_LEN); memcpy(XHmac, XHmac_tmp, HKDF_HMAC_LEN); //DBG_ERR("X-Data-Hmac:%s\n", XHmac); free(XHmac_tmp); if ((XNonce = common_find_key_from_buf(buf, "X-Nonce")) != NULL) { tpsocket_hex_decode((const unsigned char *)XNonce, HKDF_IV_LEN * 2, iv_nonce); //DBG_ERR("X-Nonce:%s\n", XNonce); free(XNonce); return true; } } return false; } #endif static void _ubus_get_result( struct ubus_app *app, struct blob_attr *msg, int ret, void *priv) { if (msg && priv) { struct blob_buf *bBuf = (struct blob_buf *)priv; struct blob_attr *cur = NULL; int rem; blob_for_each_attr(cur, msg, rem) { blobmsg_add_blob(bBuf, cur); } } } #ifdef TAPO_CAMERA static MEDIA_ENCRYPT_STATUS gEncryptStatus = MEDIA_ENCRYPT_INVALID; //Note: indicate validation of encrypt key void set_media_encrypt_status(MEDIA_ENCRYPT_STATUS ENCRYPT_STATUS) { if (gEncryptStatus != ENCRYPT_STATUS) { gEncryptStatus = ENCRYPT_STATUS; } } MEDIA_ENCRYPT_STATUS get_media_encrypt_status() { return gEncryptStatus; } int get_media_encrypt_key(char *aes_key, char *aes_iv, int size) { if (!aes_key || !aes_iv || size < (2*MD5_HEX_LEN+1)) { return -1; } if (get_media_encrypt_status() != MEDIA_ENCRYPT_VALID) { return -1; } tpsocket_hex_encode(tapo_key, MD5_HEX_LEN, (unsigned char *)aes_key, 0); tpsocket_hex_encode(tapo_iv, MD5_HEX_LEN, (unsigned char *)aes_iv, 0); return 0; } #endif static void send_clip_start_event(ALARM_PRODUCER *producer) { struct blob_buf b = {0}; blobmsg_buf_init(&b); if (producer) { DEV_INFO *dev_info = get_dev_info((MEDIACENTER_CTX *)get_top_ctx(), producer->dev_id, producer->dev_ip); if (dev_info) { blobmsg_add_string(&b, "deviceId", dev_info->dev_id); ubus_app_event((struct ubus_app *)ubus_get_ubus_app(), "clip_start_timing", b.head); } } blob_buf_free(&b); } static inline void work_tapo_refresh_encrypt_key(void) { md5_ctx_t md5_ctx; char tmp[64] = {0}; //DBG_DBG("tapo_nonce: %s\n", tapo_nonce); //DBG_DBG("tapo_passwd: %s\n", tapo_passwd); md5_begin(&md5_ctx); md5_hash(tapo_nonce, strlen(tapo_nonce), &md5_ctx); md5_hash(":", strlen(":"), &md5_ctx); md5_hash(tapo_passwd, strlen(tapo_passwd), &md5_ctx); md5_end(tapo_key, &md5_ctx); md5_begin(&md5_ctx); md5_hash(tapo_user, strlen(tapo_user), &md5_ctx); md5_hash(":", strlen(":"), &md5_ctx); md5_hash(tapo_nonce, strlen(tapo_nonce), &md5_ctx); md5_end(tapo_iv, &md5_ctx); tpsocket_hex_encode(tapo_key, sizeof(tapo_key), (unsigned char *)tmp, 0); //DBG_DBG("tapo_key: %s\n", tmp); tpsocket_hex_encode(tapo_iv, sizeof(tapo_iv), (unsigned char *)tmp, 0); //DBG_DBG("tapo_iv: %s\n", tmp); tpsocket_aes_set_encrypt_key((unsigned char *)tapo_key, 128, &tapo_aes_key); tpsocket_aes_set_decrypt_key((unsigned char *)tapo_key, 128, &tapo_aes_dec_key); } void work_tapo_aec_encrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { unsigned char tmpiv[16]; memcpy(tmpiv, tapo_iv, sizeof(tapo_iv)); if (tpsocket_aes_cbc_encrypt(inputbuf, outbuf, inputlen, &tapo_aes_key, tmpiv, 1) == 0) *outputlen = inputlen; else *outputlen = 0; } static inline void work_tapo_aec_decrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { unsigned char tmpiv[16]; memcpy(tmpiv, tapo_iv, sizeof(tapo_iv)); if (tpsocket_aes_cbc_encrypt(inputbuf, outbuf, inputlen, &tapo_aes_dec_key, tmpiv, 0) == 0) *outputlen = inputlen; else *outputlen = 0; } #ifdef TAPO_CAMERA void work_tapo_refresh_nonce() { tpsocket_hex_random((unsigned char *)tapo_nonce, 32, 0); work_tapo_refresh_encrypt_key(); set_media_encrypt_status(MEDIA_ENCRYPT_VALID); } #endif char *tapo_vod_get_user() { return tapo_user; } char *tapo_vod_get_nonce() { return tapo_nonce; } void tapo_vod_aec_encrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_vod_aec_encrypt param error\n"); return; } return work_tapo_aec_encrypt(inputbuf, inputlen, outbuf, outputlen); } void tapo_vod_aec_decrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_vod_aec_decrypt param error\n"); return; } return work_tapo_aec_decrypt(inputbuf, inputlen, outbuf, outputlen); } void tapo_talk_aec_decrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_talk_aec_decrypt param error\n"); return; } return work_tapo_aec_decrypt(inputbuf, inputlen, outbuf, outputlen); } void tapo_img_trans_aec_encrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_img_trans_aec_encrypt param error, inputlen: %d, inbuf: %p, outbuf: %p, outlen: %p\n", inputlen, inputbuf, outbuf, outputlen); return; } return work_tapo_aec_encrypt(inputbuf, inputlen, outbuf, outputlen); } void tapo_img_trans_aec_decrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_img_trans_aec_decrypt param error\n"); return; } return work_tapo_aec_decrypt(inputbuf, inputlen, outbuf, outputlen); } void tapo_log_aec_decrypt(unsigned char *inputbuf, int inputlen, unsigned char *outbuf, int *outputlen) { if(!inputbuf || inputlen <= 0 || !outbuf || !outputlen) { DBG_ERR("tapo_log_aec_decrypt param error\n"); return; } return work_tapo_aec_decrypt(inputbuf, inputlen, outbuf, outputlen); }
最新发布
10-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值