+ /* Add RI if renegotiating */
+ if (s->renegotiate)
+ {
+ int el;
+
+ if(!ssl_add_clienthello_renegotiate_ext(s, 0, &el, 0))
+ {
+ SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+ return NULL;
+ }
+
+ if((limit - p - 4 - el) < 0) return NULL;
+
+ s2n(TLSEXT_TYPE_renegotiate,ret);
+ s2n(el,ret);
+
+ if(!ssl_add_clienthello_renegotiate_ext(s, ret, &el, el))
+ {
+ SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+ return NULL;
+ }
+
+ ret += el;
+ }
+
+#ifndef OPENSSL_NO_SRP
+#define MIN(x,y) (((x)<(y))?(x):(y))
+ /* we add SRP username the first time only if we have one! */
+ if (s->srp_ctx.login != NULL)
+ {/* Add TLS extension SRP username to the Client Hello message */
+ int login_len = MIN(strlen(s->srp_ctx.login) + 1, 255);
+ long lenmax;
+
+ if ((lenmax = limit - ret - 5) < 0) return NULL;
+ if (login_len > lenmax) return NULL;
+ if (login_len > 255)
+ {
+ SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);
+ return NULL;
+ }
+ s2n(TLSEXT_TYPE_srp,ret);
+ s2n(login_len+1,ret);
+
+ (*ret++) = (unsigned char) MIN(strlen(s->srp_ctx.login), 254);
+ memcpy(ret, s->srp_ctx.login, MIN(strlen(s->srp_ctx.login), 254));
+ ret+=login_len;
+ }
+#endif
+